forked from tecbot/gorocksdb
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cow_test.go
48 lines (43 loc) · 868 Bytes
/
cow_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
package gorocksdb
import (
"fmt"
"sync"
"testing"
"github.com/facebookgo/ensure"
)
func TestCOWList(t *testing.T) {
cl := NewCOWList()
cl.Append("hello")
cl.Append("world")
cl.Append("!")
ensure.DeepEqual(t, cl.Get(0), "hello")
ensure.DeepEqual(t, cl.Get(1), "world")
ensure.DeepEqual(t, cl.Get(2), "!")
}
func TestCOWListMT(t *testing.T) {
cl := NewCOWList()
expectedRes := make([]int, 3)
var wg sync.WaitGroup
for i := 0; i < 3; i++ {
wg.Add(1)
go func(v int) {
defer wg.Done()
index := cl.Append(v)
expectedRes[index] = v
}(i)
}
wg.Wait()
for i, v := range expectedRes {
ensure.DeepEqual(t, cl.Get(i), v)
}
}
func BenchmarkCOWList_Get(b *testing.B) {
cl := NewCOWList()
for i := 0; i < 10; i++ {
cl.Append(fmt.Sprintf("helloworld%d", i))
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = cl.Get(i % 10).(string)
}
}