-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb_test.go
53 lines (49 loc) · 1003 Bytes
/
db_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
package locker_client
import (
"net/http"
"sync"
"testing"
)
var testUrl = "http://127.0.0.1:33000"
func TestMultiGoroutineWrite(_ *testing.T) {
wg := sync.WaitGroup{}
for i := 0; i < 100; i++ {
wg.Add(1)
go func(index int) {
db := CloudLockerClient{
Client: http.DefaultClient,
Url: testUrl,
}
for j := 0; j < 1000; j++ {
key := []byte{byte(index)}
value := []byte{byte(j % 100)}
_ = db.Set(key, value)
}
wg.Done()
}(i)
}
wg.Wait()
db := CloudLockerClient{
Client: http.DefaultClient,
Url: testUrl,
}
for i := 0; i < 100; i++ {
v, _ := db.Get([]byte{byte(i)})
if len(v) == 0 || v[0] != 99 {
panic("v should be 99")
}
}
}
func TestBasics(t *testing.T) {
db := CloudLockerClient{
Client: http.DefaultClient,
Url: testUrl,
}
for i := 0; i < 100; i++ {
_ = db.Set([]byte{byte(i)}, []byte{byte(i + 1)})
v, _ := db.Get([]byte{byte(i)})
if len(v) == 0 || v[0] != byte(i+1) {
panic("value not set exactly")
}
}
}