-
Notifications
You must be signed in to change notification settings - Fork 0
/
snglegorutine_cache_test.go
64 lines (51 loc) · 1.82 KB
/
snglegorutine_cache_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
package gcache
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestGorCache_Purge(t *testing.T) {
as := assert.New(t)
c := NewGorCache(defaultConfig())
c.SetOrUpdate("first", []byte(`zaza`), DefaultExpirationMarker)
c.Get("aa")
as.Equal(int64(1), c.Statistic().ItemsCount)
c.Purge()
as.Equal(int64(0), c.Statistic().ItemsCount)
as.Equal(int64(1), c.Statistic().DeleteCount)
c.Dead() //Cleanup
}
func TestGorCache_Get(t *testing.T) {
as := assert.New(t)
c := NewGorCache(defaultConfig())
c.SetOrUpdate("first", []byte(`zaza`), DefaultExpirationMarker)
c.SetOrUpdate("second", []byte(`azaz`), DefaultExpirationMarker)
as.Nil(c.Get("irst"))
as.Equal(int64(2), c.Statistic().ItemsCount)
as.Equal([]byte(`zaza`), c.Get("first"))
as.Equal([]byte(`azaz`), c.Get("second"))
as.Equal(int64(2), c.Statistic().ItemsCount)
as.Equal(int64(2), c.Statistic().GetSuccessNumber)
as.Equal(int64(1), c.Statistic().GetErrorNumber)
as.Equal(int64(2), c.Statistic().ItemsCount)
c.Dead() //Cleanup
}
func TestGorCache_SetOrUpdate(t *testing.T) {
as := assert.New(t)
c := NewGorCache(defaultConfig())
c.SetOrUpdate("first", []byte(`zaza`), DefaultExpirationMarker)
c.SetOrUpdate("second", []byte(`azaz`), DefaultExpirationMarker)
as.Nil(c.Get("irst"))
as.Equal(int64(2), c.Statistic().ItemsCount)
as.Equal([]byte(`zaza`), c.Get("first"))
as.Equal([]byte(`azaz`), c.Get("second"))
c.SetOrUpdate("second", []byte(`zara`), DefaultExpirationMarker)
as.Equal(int64(2), c.Statistic().ItemsCount)
as.Equal([]byte(`zara`), c.Get("second"))
as.Equal(int64(3), c.Statistic().SetOrReplaceCount)
as.Equal(int64(3), c.Statistic().GetSuccessNumber)
as.Equal(int64(1), c.Statistic().GetErrorNumber)
as.Equal(int64(2), c.Statistic().ItemsCount)
c.Dead() //Cleanup
}
//TODO check expiration time
//TODO check timeouts and isKeep...