-
Notifications
You must be signed in to change notification settings - Fork 0
/
zookeeper_test.go
58 lines (44 loc) · 1.23 KB
/
zookeeper_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
package zookeeper
import (
"context"
"testing"
"time"
"github.com/kvtools/valkeyrie"
"github.com/kvtools/valkeyrie/store"
"github.com/kvtools/valkeyrie/testsuite"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
const testTimeout = 60 * time.Second
const client = "localhost:2181"
func makeZkClient(t *testing.T) store.Store {
t.Helper()
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
config := &Config{
ConnectionTimeout: 3 * time.Second,
}
kv, err := New(ctx, []string{client}, config)
require.NoErrorf(t, err, "cannot create store")
return kv
}
func TestRegister(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
defer cancel()
kv, err := valkeyrie.NewStore(ctx, StoreName, []string{client}, nil)
require.NoError(t, err)
assert.NotNil(t, kv)
if _, ok := kv.(*Store); !ok {
t.Fatal("Error registering and initializing zookeeper")
}
}
func TestZkStore(t *testing.T) {
kv := makeZkClient(t)
ttlKV := makeZkClient(t)
testsuite.RunTestCommon(t, kv)
testsuite.RunTestAtomic(t, kv)
testsuite.RunTestWatch(t, kv)
testsuite.RunTestLock(t, kv)
testsuite.RunTestTTL(t, kv, ttlKV)
testsuite.RunCleanup(t, kv)
}