forked from vinllen/redis-go-cluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcluster_test.go
69 lines (56 loc) · 1.64 KB
/
cluster_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
package redis
import (
"testing"
"fmt"
"time"
"strings"
"github.com/stretchr/testify/assert"
)
const (
addr = "100.81.164.186:40991;100.81.164.186:40992;100.81.164.186:40993"
)
func TestChooseNodeWithCmd(t *testing.T) {
// test ChooseNodeWithCmd
var nr int
// simple test
{
fmt.Printf("TestChooseNodeWithCmd case %d.\n", nr)
nr++
cluster, err := NewCluster(
&Options{
StartNodes: strings.Split(addr, ";"),
ConnTimeout: 5 * time.Second,
KeepAlive: 32,
AliveTime: 10 * time.Second,
})
assert.Equal(t, nil, err, "should be equal")
node, err := cluster.ChooseNodeWithCmd("set", "a", 1)
assert.Equal(t, nil, err, "should be equal")
expect, err := cluster.getNodeByKey("a")
assert.Equal(t, nil, err, "should be equal")
assert.Equal(t, node, expect, "should be equal")
}
// test mset
{
fmt.Printf("TestChooseNodeWithCmd case %d.\n", nr)
nr++
cluster, err := NewCluster(
&Options{
StartNodes: strings.Split(addr, ";"),
ConnTimeout: 5 * time.Second,
KeepAlive: 32,
AliveTime: 10 * time.Second,
})
assert.Equal(t, nil, err, "should be equal")
node, err := cluster.ChooseNodeWithCmd("mset", "a", 1, "a", 2)
assert.Equal(t, nil, err, "should be equal")
expect, err := cluster.getNodeByKey("a")
assert.Equal(t, nil, err, "should be equal")
assert.Equal(t, node, expect, "should be equal")
node, err = cluster.ChooseNodeWithCmd("mset", "a", 1, "b", 2)
assert.NotEqual(t, nil, err, "should be equal")
node, err = cluster.ChooseNodeWithCmd("mset", "a", 1, "d", 2)
assert.Equal(t, nil, err, "should be equal")
assert.Equal(t, node, expect, "should be equal")
}
}