forked from ravendb/ravendb-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreplication_test_base_test.go
61 lines (52 loc) · 1.73 KB
/
replication_test_base_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
package tests
import (
"github.com/ravendb/ravendb-go-client"
"time"
)
// Note: Java's ReplicationTestBase is folded into RavenTestDriver
func (d *RavenTestDriver) modifyReplicationDestination(replicationNode *ravendb.ReplicationNode) {
// empty by design
}
func (d *RavenTestDriver) setupReplication(fromStore *ravendb.DocumentStore, destinations ...*ravendb.DocumentStore) error {
for _, store := range destinations {
databaseWatcher := ravendb.NewExternalReplication(store.GetDatabase(), "ConnectionString-"+store.GetIdentifier())
d.modifyReplicationDestination(&databaseWatcher.ReplicationNode)
if err := d.addWatcherToReplicationTopology(fromStore, databaseWatcher); err != nil {
return err
}
}
return nil
}
func (d *RavenTestDriver) addWatcherToReplicationTopology(store *ravendb.DocumentStore, watcher *ravendb.ExternalReplication) error {
connectionString := ravendb.NewRavenConnectionString()
connectionString.Name = watcher.ConnectionStringName
connectionString.Database = watcher.Database
connectionString.TopologyDiscoveryUrls = store.GetUrls()
err := store.Maintenance().Send(ravendb.NewPutConnectionStringOperation(connectionString))
if err != nil {
return err
}
op := ravendb.NewUpdateExternalReplicationOperation(watcher)
return store.Maintenance().Send(op)
}
func (d *RavenTestDriver) waitForDocumentToReplicate(store *ravendb.DocumentStore, result interface{}, id string, timeout time.Duration) error {
sw := time.Now()
for {
time.Sleep(time.Millisecond * 500)
dur := time.Since(sw)
if dur > timeout {
return nil
}
{
session, err := store.OpenSession("")
if err != nil {
return err
}
err = session.Load(result, id)
session.Close()
if err != nil {
return err
}
}
}
}