-
Notifications
You must be signed in to change notification settings - Fork 26
/
action_test.go
68 lines (58 loc) · 1.49 KB
/
action_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
// Copyright 2014 Wandoujia Inc. All Rights Reserved.
// Licensed under the MIT (MIT-LICENSE.txt) license.
package models
import (
"encoding/json"
"fmt"
"testing"
"github.com/juju/errors"
"github.com/ngaut/zkhelper"
"github.com/ledisdb/xcodis/utils"
)
var (
productName = "unit_test"
)
func TestNewAction(t *testing.T) {
fakeZkConn := zkhelper.NewConn()
err := NewAction(fakeZkConn, productName, ACTION_TYPE_SLOT_CHANGED, nil, "desc", false)
if err != nil {
t.Error(errors.ErrorStack(err))
}
prefix := GetWatchActionPath(productName)
if exist, _, err := fakeZkConn.Exists(prefix); !exist {
t.Error(errors.ErrorStack(err))
}
d, _, err := fakeZkConn.Get(prefix + "/action_0000000001")
if err != nil {
t.Error(errors.ErrorStack(err))
}
var action Action
json.Unmarshal(d, &action)
if action.Desc != "desc" || action.Type != ACTION_TYPE_SLOT_CHANGED {
t.Error("create action error")
}
}
func TestForceRemoveLock(t *testing.T) {
fakeZkConn := zkhelper.NewConn()
zkLock := utils.GetZkLock(fakeZkConn, productName)
if zkLock == nil {
t.Error("create lock error")
}
zkLock.Lock("force remove lock")
zkPath := fmt.Sprintf("/zk/codis/db_%s/LOCK", productName)
children, _, err := fakeZkConn.Children(zkPath)
if err != nil {
t.Error(err)
}
if len(children) == 0 {
t.Error("create lock error")
}
ForceRemoveLock(fakeZkConn, productName)
children, _, err = fakeZkConn.Children(zkPath)
if err != nil {
t.Error(err)
}
if len(children) != 0 {
t.Error("remove lock error")
}
}