-
Notifications
You must be signed in to change notification settings - Fork 16
/
operation_remove_cluster_node_test.go
79 lines (66 loc) · 2.2 KB
/
operation_remove_cluster_node_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
package tests
import (
"github.com/ravendb/ravendb-go-client/serverwide/operations"
"github.com/stretchr/testify/assert"
"os"
"testing"
"time"
)
func removeNodeFromClusterTest(t *testing.T, driver *RavenTestDriver) {
if os.Getenv("RAVEN_License") == "" {
t.Skip("This test requires RavenDB license.")
}
var err error
store := driver.getDocumentStoreMust(t)
defer store.Close()
assert.NoError(t, err)
driver2 := createTestDriver(t)
store2, err := driver2.createMainStore()
defer store2.Close()
assert.NoError(t, err)
destroy := func() { destroyDriver(t, driver) }
defer recoverTest(t, destroy)
operationAddNodeToCluster := operations.OperationAddClusterNode{
Url: store2.GetUrls()[0],
Tag: "B",
Watcher: false,
}
err = store.Maintenance().Server().Send(&operationAddNodeToCluster)
assert.NoError(t, err)
time.Sleep(time.Second * 5) // wait for topology to be updated
operation := operations.OperationGetClusterTopology{}
err = store.Maintenance().Server().Send(&operation)
assert.NoError(t, err)
assert.NotEmpty(t, operation.Leader)
assert.NotEmpty(t, operation.NodeTag)
topology := operation.Topology
assert.NotNil(t, topology)
assert.NotEmpty(t, topology.TopologyID)
assert.Equal(t, 2, len(topology.Members))
assert.Equal(t, 0, len(topology.Watchers))
assert.Equal(t, 0, len(topology.Promotables))
operationRemoveNode := operations.RemoveClusterNode{
Node: store2.GetUrls()[0],
Tag: "B",
}
err = store.Maintenance().Server().Send(&operationRemoveNode)
assert.NoError(t, err)
time.Sleep(time.Second * 5) // wait for topology to be updated
operation = operations.OperationGetClusterTopology{}
err = store.Maintenance().Server().Send(&operation)
assert.NoError(t, err)
assert.NotEmpty(t, operation.Leader)
assert.NotEmpty(t, operation.NodeTag)
topology = operation.Topology
assert.NotNil(t, topology)
assert.NotEmpty(t, topology.TopologyID)
assert.Equal(t, 1, len(topology.Members))
assert.Equal(t, 0, len(topology.Watchers))
assert.Equal(t, 0, len(topology.Promotables))
}
func TestRemoveNodeFromCluster(t *testing.T) {
driver := createTestDriver(t)
destroy := func() { destroyDriver(t, driver) }
defer recoverTest(t, destroy)
removeNodeFromClusterTest(t, driver)
}