-
Notifications
You must be signed in to change notification settings - Fork 5
/
kvclient_int_test.go
96 lines (81 loc) · 2.54 KB
/
kvclient_int_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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package gocbcorex_test
import (
"context"
"testing"
"github.com/couchbase/gocbcorex"
"github.com/couchbase/gocbcorex/memdx"
"github.com/couchbase/gocbcorex/testutilsint"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
)
func TestKvClientReconfigureBucket(t *testing.T) {
testutilsint.SkipIfShortTest(t)
logger, _ := zap.NewDevelopment()
auth := &gocbcorex.PasswordAuthenticator{
Username: testutilsint.TestOpts.Username,
Password: testutilsint.TestOpts.Password,
}
cli, err := gocbcorex.NewKvClient(context.Background(), &gocbcorex.KvClientConfig{
Address: testutilsint.TestOpts.MemdAddrs[0],
Authenticator: auth,
}, &gocbcorex.KvClientOptions{
Logger: logger,
})
require.NoError(t, err)
// Select a bucket on a gcccp level request
reconfigureCh := make(chan error)
err = cli.Reconfigure(&gocbcorex.KvClientConfig{
Address: testutilsint.TestOpts.MemdAddrs[0],
Authenticator: auth,
SelectedBucket: testutilsint.TestOpts.BucketName,
}, func(err error) {
reconfigureCh <- err
})
require.NoError(t, err)
err = <-reconfigureCh
require.NoError(t, err)
// Check that an op works
setRes, err := cli.Set(context.Background(), &memdx.SetRequest{
Key: []byte(uuid.NewString()),
VbucketID: 1,
Value: []byte("test"),
})
// We don't know if we sent the Set to the correct node for the vbucket so check that the result is either ok or
// is a NMVB error.
if err == nil {
assert.NotZero(t, setRes.Cas)
} else {
assert.ErrorIs(t, err, memdx.ErrNotMyVbucket)
}
err = cli.Close()
require.NoError(t, err)
}
func TestKvClientCloseAfterReconfigure(t *testing.T) {
testutilsint.SkipIfShortTest(t)
auth := &gocbcorex.PasswordAuthenticator{
Username: testutilsint.TestOpts.Username,
Password: testutilsint.TestOpts.Password,
}
clientConfig := &gocbcorex.KvClientConfig{
Address: testutilsint.TestOpts.MemdAddrs[0],
TlsConfig: nil,
Authenticator: auth,
}
logger, err := zap.NewDevelopment()
require.NoError(t, err)
cli, err := gocbcorex.NewKvClient(context.Background(), clientConfig, &gocbcorex.KvClientOptions{Logger: logger})
require.NoError(t, err)
err = cli.Reconfigure(&gocbcorex.KvClientConfig{
Address: testutilsint.TestOpts.MemdAddrs[0],
TlsConfig: nil,
SelectedBucket: testutilsint.TestOpts.BucketName,
Authenticator: auth,
}, func(err error) {
// We don't need to wait for all of the clients to be fully reconfigured.
})
require.NoError(t, err)
err = cli.Close()
require.NoError(t, err)
}