-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatomic_uint64_test.go
More file actions
77 lines (55 loc) · 1.49 KB
/
atomic_uint64_test.go
File metadata and controls
77 lines (55 loc) · 1.49 KB
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
package supervisor
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestAtomicUint64SetGet(t *testing.T) {
assert := assert.New(t)
client := NewClient(
SetZookeeperNodes("127.0.0.1"),
)
if err := client.Connect(); err != nil {
fmt.Println(err.Error())
}
vint64 := NewAtomicUint64(client, "/supervisor/test/atomic/uint64/var01")
assert.Equal(vint64.TrySet(10), nil)
val, _ := vint64.Get()
assert.Equal(val, uint64(10))
client.Disconnect()
}
func TestAtomicUint64SetGetIncDec(t *testing.T) {
assert := assert.New(t)
client := NewClient(
SetZookeeperNodes("127.0.0.1"),
)
if err := client.Connect(); err != nil {
fmt.Println(err.Error())
}
vint64 := NewAtomicUint64(client, "/supervisor/test/atomic/uint64/var02")
assert.Equal(vint64.TrySet(10), nil)
val, _ := vint64.Get()
assert.Equal(val, uint64(10))
assert.Equal(vint64.Increment(), nil)
val, _ = vint64.Get()
assert.Equal(val, uint64(11))
assert.Equal(vint64.Decrement(), nil)
val, _ = vint64.Get()
assert.Equal(val, uint64(10))
client.Disconnect()
}
func TestAtomicUint64CompareAndSet(t *testing.T) {
assert := assert.New(t)
client := NewClient(
SetZookeeperNodes("127.0.0.1"),
)
if err := client.Connect(); err != nil {
fmt.Println(err.Error())
}
vint64 := NewAtomicUint64(client, "/supervisor/test/atomic/uint64/var03")
assert.Equal(vint64.TrySet(10), nil)
assert.Equal(vint64.CompareAndSet(10, 20), nil)
val, _ := vint64.Get()
assert.Equal(val, uint64(20))
client.Disconnect()
}