-
Notifications
You must be signed in to change notification settings - Fork 0
/
jac_test.go
74 lines (67 loc) · 1.37 KB
/
jac_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
package jac
import (
"encoding/json"
"fmt"
"strconv"
"testing"
"time"
)
type testData struct {
Id string `json:"id"`
Flag1 bool `json:"flag1"`
Value int `json:"value"`
Flag2 bool `json:"flag2"`
}
//goland:noinspection GoNilness
func Test_jac(t *testing.T) {
const (
Tries = 100
Keep = true
)
if err := Initialise(true, nil); err != IllegalParameter && err != nil {
t.Errorf(err.Error())
}
println("create")
bucket, e := NewBucket("test", 180*time.Second)
if e != nil {
t.Errorf(e.Error())
}
for i := 0; i < Tries; i++ {
tmp := testData{
Id: strconv.Itoa(i),
Flag1: false,
Value: i,
Flag2: false,
}
if msg, er := json.Marshal(tmp); er == nil {
bucket.Set(strconv.Itoa(i), string(msg), 180*time.Second, true)
}
time.Sleep(50 * time.Millisecond)
}
time.Sleep(2 * time.Second)
bucket.Close(true)
time.Sleep(2 * time.Second)
println("verify")
bucket, e = NewBucket("test", 180*time.Second)
if e != nil {
t.Errorf(e.Error())
}
for i := 0; i < Tries; i++ {
msg, found := bucket.Get(strconv.Itoa(i))
if !found {
t.Errorf("missing data")
} else {
var entry testData
if err := json.Unmarshal([]byte(msg), &entry); err == nil {
fmt.Println(entry)
if entry.Value != i {
t.Errorf("wrong data")
}
}
}
}
time.Sleep(90 * time.Second)
bucket.Close(Keep)
Terminate()
time.Sleep(2 * time.Second)
}