-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathssdb_test.go
102 lines (90 loc) · 1.94 KB
/
ssdb_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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package ssdb
import (
"encoding/base64"
"fmt"
"sync"
"testing"
"time"
)
var pool *Pool
var poolErr error
func init() {
pool, poolErr = NewPool(
&Options{
Addr: "localhost:8888",
Network: "tcp",
PoolSize: 16,
ConnectTimeout: time.Duration(time.Second),
ReadTimeout: time.Duration(time.Second * 3),
WriteTimeout: time.Duration(time.Second * 2),
IdleTimeout: time.Duration(time.Second * 60),
OnConnEvent: func(msg string) {
fmt.Println(msg)
},
})
if poolErr != nil {
panic(poolErr)
}
}
func TestData(t *testing.T) {
var (
reply *Reply
)
reply = pool.Do("hset", "aaaaa", 1000, 1000)
t.Log(reply.String())
data := []byte("hello world")
wData := make([]byte, len(data)*1000)
s := len(data)
for i := 0; i < 2; i++ {
j := i * s
copy(wData[j:j+s], data)
}
for i := 0; i < 10; i++ {
reply = pool.Do("hset", "bbbbb", i, wData)
t.Log(reply.String())
}
reply = pool.Do("hclear", "aaaaa")
t.Log(reply.String())
reply = pool.Do("hclear", "bbbbb")
t.Log(reply.String())
}
var routineWait = &sync.WaitGroup{}
func doTimes(size int) {
if size > 1 {
for i := 0; i < size; i++ {
pool.Do("set", "test", "test")
}
} else {
pool.Do("set", "test", "test")
}
routineWait.Done()
}
func TestGoroutine(t *testing.T) {
size := 30
routineWait.Add(size)
for i := 0; i < size; i++ {
go doTimes(1000)
}
routineWait.Wait()
fmt.Println("Routine is OK")
}
func TestMulti_Get_Order(t *testing.T) {
for i := 0; i < 100; i++ {
pool.Do("hset", "test", i, i)
}
target := make([]string, 100)
for i := 0; i < 100; i++ {
target[i] = fmt.Sprintf("%d", i)
}
reply := pool.Do("multi_hget", "test", target)
strs := reply.Strings()
for i := 0; i < len(strs); i += 2 {
t.Log("Result", strs[i], strs[i+1])
}
pool.Do("hclear", "test")
}
func TestAAA(t *testing.T) {
reply := pool.Do("hget", "player:base:info", 1001)
t.Log(base64.StdEncoding.EncodeToString(reply.Bytes()))
pool.Release()
}