-
Notifications
You must be signed in to change notification settings - Fork 0
/
store_evict_key_latest_test.go
93 lines (79 loc) · 1.88 KB
/
store_evict_key_latest_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package dm
import (
"fmt"
"testing"
"git.100tal.com/wangxiao_xesbiz_operation/gently-utils/utils"
)
func TestKeyLatestStore_Set(t *testing.T) {
type A struct {
X int
Y int
Z string
}
limit := 5
size := 20
store := NewKeyLatestStore(ENGINE_NOGC_MAP, A{}, limit)
keys := make([]KeyType, 0, size)
for i := 0; i < size; i++ {
keys = append(keys, i)
}
// ID打乱
shuffle := utils.SliceReverse(keys).([]int)
fmt.Printf("shuffle:%+v\n", shuffle)
for _, v := range shuffle {
a := A{
X: v,
Y: v + 1,
Z: fmt.Sprintf("A%d", v),
}
err := store.Set(v, &a)
if err != nil {
panic(err)
}
}
fmt.Printf("store size:%+v\n", store.Size())
err := store.Iterator(func(key KeyType, value interface{}) bool {
fmt.Printf("key:%d %+v\n", key, value)
return true
})
if err != nil {
panic(err)
}
}
func TestKeyLatestStore_Set_Shuffle(t *testing.T) {
type A struct {
X int
Y int
Z string
}
limit := 5
size := 20
store := NewKeyLatestStore(ENGINE_NOGC_MAP, A{}, limit)
keys := make([]KeyType, 0, size)
for i := 0; i < size; i++ {
keys = append(keys, i)
}
// ID打乱
shuffle := utils.SliceShuffle(keys)
fmt.Printf("shuffle:%+v\n", shuffle)
for _, item := range shuffle {
v := item.(KeyType)
a := A{
X: v,
Y: v + 1,
Z: fmt.Sprintf("A%d", v),
}
err := store.Set(v, &a)
if err != nil {
panic(err)
}
}
fmt.Printf("store size:%+v\n", store.Size())
err := store.Iterator(func(key KeyType, value interface{}) bool {
fmt.Printf("key:%d %+v\n", key, value)
return true
})
if err != nil {
panic(err)
}
}