-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstats_test.go
68 lines (61 loc) · 1.71 KB
/
stats_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
package lru
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Stats", func() {
Context("Stats", func() {
It("should retrieve the current stats", func() {
l := newDefaultLRU()
defer closeBoltDB(l)
setTestStats(l)
s := l.Stats()
verifyTestStats(s)
})
It("should reset the stats and return the stats before the reset", func() {
l := newDefaultLRU()
defer closeBoltDB(l)
setTestStats(l)
s := l.ResetStats()
verifyTestStats(s)
s = l.Stats()
Ω(s.StartTime.IsZero()).Should(BeFalse())
Ω(s.Uptime).Should(BeNumerically(">", 0))
Ω(s.Hits).Should(Equal(int64(0)))
Ω(s.Misses).Should(Equal(int64(0)))
Ω(s.GetBytes).Should(Equal(int64(0)))
Ω(s.Puts).Should(Equal(int64(0)))
Ω(s.PutBytes).Should(Equal(int64(0)))
Ω(s.Evicted).Should(Equal(int64(0)))
Ω(s.EvictedBytes).Should(Equal(int64(0)))
Ω(s.Size).Should(Equal(int64(600)))
Ω(s.Capacity).Should(Equal(int64(1000)))
Ω(s.NumItems).Should(Equal(int64(2)))
})
})
})
func setTestStats(l *LRU) {
l.lru.PutOnStartup([]byte("1"), 400)
l.lru.PutOnStartup([]byte("2"), 200)
l.hits = 1
l.misses = 2
l.bget = 3
l.puts = 4
l.bput = 5
l.evicted = 6
l.bevicted = 7
}
func verifyTestStats(s Stats) {
Ω(s.StartTime.IsZero()).Should(BeFalse())
Ω(s.Uptime).Should(BeNumerically(">", 0))
Ω(s.Hits).Should(Equal(int64(1)))
Ω(s.Misses).Should(Equal(int64(2)))
Ω(s.GetBytes).Should(Equal(int64(3)))
Ω(s.Puts).Should(Equal(int64(4)))
Ω(s.PutBytes).Should(Equal(int64(5)))
Ω(s.Evicted).Should(Equal(int64(6)))
Ω(s.EvictedBytes).Should(Equal(int64(7)))
Ω(s.Size).Should(Equal(int64(600)))
Ω(s.Capacity).Should(Equal(int64(1000)))
Ω(s.NumItems).Should(Equal(int64(2)))
}