blob: 2519c09b42bf34bd18ed179647c46e4ef0616c8a (
plain)
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
|
// Test for cloning a db from a replica set [SERVER-1643] -Tony
load('jstests/libs/grid.js')
doTest = function( signal ) {
var N = 2000
print("~1KB string");
var Text = ''
for (var i = 0; i < 40; i++)
Text += 'abcdefghijklmnopqrstuvwxyz'
print("Create replica set");
var repset = new ReplicaSet ('testSet', 3) .begin()
var master = repset.getMaster()
var db1 = master.getDB('test')
print("Insert data");
for (var i = 0; i < N; i++) {
db1['foo'].insert({x: i, text: Text})
db1.getLastError(2) // wait to be copied to at least one secondary
}
print("Create single server");
var solo = new Server ('singleTarget')
var soloConn = solo.begin()
soloConn.getDB("admin").runCommand({setParameter:1,logLevel:5});
var db2 = soloConn.getDB('test')
print("Clone db from replica set to single server");
db2.cloneDatabase (repset.getURL())
print("Confirm clone worked");
assert.eq (Text, db2['foo'] .findOne({x: N-1}) ['text'], 'cloneDatabase failed (test1)')
print("Now test the reverse direction");
db1 = master.getDB('test2')
db2 = soloConn.getDB('test2')
for (var i = 0; i < N; i++) {
db2['foo'].insert({x: i, text: Text})
db2.getLastError()
}
db1.cloneDatabase (solo.host())
assert.eq (Text, db2['foo'] .findOne({x: N-1}) ['text'], 'cloneDatabase failed (test2)')
print("Shut down replica set and single server");
solo.end()
repset.stopSet( signal )
}
doTest( 15 );
print("replsets/cloneDb.js SUCCESS");
|