-
Notifications
You must be signed in to change notification settings - Fork 26
/
slots_test.go
76 lines (59 loc) · 1.37 KB
/
slots_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
// Copyright 2014 Wandoujia Inc. All Rights Reserved.
// Licensed under the MIT (MIT-LICENSE.txt) license.
package models
import (
"testing"
"github.com/ngaut/zkhelper"
)
func TestSlots(t *testing.T) {
fakeZkConn := zkhelper.NewConn()
path := GetSlotBasePath(productName)
children, _, _ := fakeZkConn.Children(path)
if len(children) != 0 {
t.Error("slot is no empty")
}
err := InitSlotSet(fakeZkConn, productName, 1024)
if err != nil {
t.Error(err)
}
children, _, _ = fakeZkConn.Children(path)
if len(children) != 1024 {
t.Error("init slots error")
}
s, err := GetSlot(fakeZkConn, productName, 1)
if err != nil {
t.Error(err)
}
if s.GroupId != -1 {
t.Error("init slots error")
}
g := NewServerGroup(productName, 1)
g.Create(fakeZkConn)
// test create new group
_, err = ServerGroups(fakeZkConn, productName)
if err != nil {
t.Error(err)
}
ok, err := g.Exists(fakeZkConn)
if !ok || err != nil {
t.Error("create group error")
}
err = SetSlotRange(fakeZkConn, productName, 0, 1023, 1, SLOT_STATUS_ONLINE)
if err != nil {
t.Error(err)
}
s, err = GetSlot(fakeZkConn, productName, 1)
if err != nil {
t.Error(err)
}
if s.GroupId != 1 {
t.Error("range set error")
}
err = s.SetMigrateStatus(fakeZkConn, 1, 2)
if err != nil {
t.Error(err)
}
if s.GroupId != 2 || s.State.Status != SLOT_STATUS_MIGRATE {
t.Error("migrate error")
}
}