| 12 | ) |
| 13 | |
| 14 | func TestEntriesIterator(t *testing.T) { |
| 15 | t.Parallel() |
| 16 | |
| 17 | // given |
| 18 | keysCount := 1000 |
| 19 | cache, _ := New(context.Background(), Config{ |
| 20 | Shards: 8, |
| 21 | LifeWindow: 6 * time.Second, |
| 22 | MaxEntriesInWindow: 1, |
| 23 | MaxEntrySize: 256, |
| 24 | }) |
| 25 | value := []byte("value") |
| 26 | |
| 27 | for i := 0; i < keysCount; i++ { |
| 28 | cache.Set(fmt.Sprintf("key%d", i), value) |
| 29 | } |
| 30 | |
| 31 | // when |
| 32 | keys := make(map[string]struct{}) |
| 33 | iterator := cache.Iterator() |
| 34 | |
| 35 | for iterator.SetNext() { |
| 36 | current, err := iterator.Value() |
| 37 | |
| 38 | if err == nil { |
| 39 | keys[current.Key()] = struct{}{} |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | // then |
| 44 | assertEqual(t, keysCount, len(keys)) |
| 45 | } |
| 46 | |
| 47 | func TestEntriesIteratorWithMostShardsEmpty(t *testing.T) { |
| 48 | t.Parallel() |