-
Notifications
You must be signed in to change notification settings - Fork 1
/
sharded_concurrent_multi_map_test.go
61 lines (45 loc) · 1.47 KB
/
sharded_concurrent_multi_map_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package maps
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestShardedConcurrentMultiMap(t *testing.T) {
concurrentMap := NewShardedConcurrentMultiMap(WithNumberOfShards(16))
concurrentMap.Set("names", []interface{}{"Raed Shomali"})
concurrentMap.Append("names", "Dwayne Johnson")
ok := concurrentMap.ContainsKey("names")
assert.True(t, ok)
ok = concurrentMap.ContainsEntry("name", "Raed Shomali")
assert.False(t, ok)
size := concurrentMap.Size()
assert.Equal(t, size, 1)
isEmpty := concurrentMap.IsEmpty()
assert.False(t, isEmpty)
keys := concurrentMap.Keys()
assert.Equal(t, keys, []string{"names"})
value, ok := concurrentMap.Get("names")
assert.True(t, ok)
assert.Equal(t, value, []interface{}{"Raed Shomali", "Dwayne Johnson"})
value, ok = concurrentMap.Get("unknown")
assert.False(t, ok)
assert.Nil(t, value)
concurrentMap.Remove("names")
value, ok = concurrentMap.Get("names")
assert.False(t, ok)
assert.Nil(t, value)
concurrentMap.Append("names", "Raed Shomali")
concurrentMap.Clear()
value, ok = concurrentMap.Get("names")
assert.False(t, ok)
assert.Nil(t, value)
size = concurrentMap.Size()
assert.Equal(t, size, 0)
isEmpty = concurrentMap.IsEmpty()
assert.True(t, isEmpty)
keys = concurrentMap.Keys()
assert.Equal(t, keys, []string{})
}
func TestShardedConcurrentMultiMap_InvalidShards(t *testing.T) {
concurrentMap := NewShardedConcurrentMultiMap(WithNumberOfShards(0))
assert.Equal(t, concurrentMap.shards, uint32(16))
}