forked from ravendb/ravendb-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoperation_add_database_to_node_test.go
74 lines (63 loc) · 1.92 KB
/
operation_add_database_to_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
package tests
import (
"errors"
"github.com/ravendb/ravendb-go-client"
"github.com/ravendb/ravendb-go-client/serverwide/operations"
"github.com/stretchr/testify/assert"
"os"
"testing"
"time"
)
const iterations = 10
func AddDatabaseToNode(t *testing.T, driver *RavenTestDriver) error {
if os.Getenv("RAVEN_License") == "" {
t.Skip("This test requires RavenDB license.")
}
var err error
store := driver.getDocumentStoreMust(t)
defer store.Close()
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)
operationAddDatabaseNode := operations.OperationAddDatabaseNode{
Name: store.GetDatabase(),
Node: "B",
}
err = store.Maintenance().Server().Send(&operationAddDatabaseNode)
assert.NoError(t, err)
for i := 0; i <= iterations; i++ {
time.Sleep(2 * time.Second) //we HAVE to wait for things to move around
command := ravendb.NewGetDatabaseTopologyCommand()
err = store2.GetRequestExecutor(store.GetDatabase()).ExecuteCommand(command, nil)
assert.NoError(t, err)
result := command.Result
assert.NotNil(t, result)
if len(result.Nodes) == 2 {
assert.Equal(t, result.Nodes[0].Database, store.GetDatabase())
assert.Equal(t, result.Nodes[1].Database, store.GetDatabase())
break
} else if i == iterations {
return errors.New("Expected database to be included in both node A and node B. ")
}
}
return nil
}
func TestAddDatabaseToNode(t *testing.T) {
driver := createTestDriver(t)
destroy := func() { destroyDriver(t, driver) }
defer recoverTest(t, destroy)
err := AddDatabaseToNode(t, driver)
if err != nil {
panic(err.Error())
}
}