1
by James Page
Import upstream version 2.4.8 |
1 |
// Tests sharding with a key file
|
2 |
||
3 |
myTestName = "sharding_with_keyfile" |
|
4 |
||
5 |
keyFile = "jstests/sharding/" + myTestName + ".key"; |
|
6 |
||
7 |
run( "chmod" , "600" , keyFile ); |
|
8 |
||
9 |
var st = new ShardingTest({ name : myTestName , |
|
10 |
shards : 2, |
|
11 |
mongos : 1, |
|
12 |
keyFile : keyFile }) |
|
13 |
||
14 |
// Make sure all our instances got the key
|
|
15 |
var configs = st._configServers |
|
16 |
var shards = st._connections |
|
17 |
var mongoses = st._mongos |
|
18 |
||
19 |
for( var i = 0; i < configs.length; i++ ){ |
|
20 |
printjson( new Mongo( "localhost:" + configs[i].port ).getDB("admin").runCommand({ getCmdLineOpts : 1 }) ) |
|
21 |
assert.eq( new Mongo( "localhost:" + configs[i].port ).getDB("admin").runCommand({ getCmdLineOpts : 1 }).parsed.keyFile, keyFile ) |
|
22 |
}
|
|
23 |
||
24 |
for( var i = 0; i < shards.length; i++ ){ |
|
25 |
printjson( new Mongo( "localhost:" + shards[i].port ).getDB("admin").runCommand({ getCmdLineOpts : 1 }) ) |
|
26 |
assert.eq( new Mongo( "localhost:" + shards[i].port ).getDB("admin").runCommand({ getCmdLineOpts : 1 }).parsed.keyFile, keyFile ) |
|
27 |
}
|
|
28 |
||
29 |
for( var i = 0; i < mongoses.length; i++ ){ |
|
30 |
printjson( new Mongo( "localhost:" + mongoses[i].port ).getDB("admin").runCommand({ getCmdLineOpts : 1 }) ) |
|
31 |
assert.eq( new Mongo( "localhost:" + mongoses[i].port ).getDB("admin").runCommand({ getCmdLineOpts : 1 }).parsed.keyFile, keyFile ) |
|
32 |
}
|
|
33 |
||
34 |
var mongos = new Mongo( "localhost:" + st.s0.port ) |
|
35 |
var coll = mongos.getCollection( "test.foo" ) |
|
36 |
||
37 |
st.shardColl( coll, { _id : 1 }, false ) |
|
38 |
||
39 |
// Create an index so we can find by num later
|
|
40 |
coll.ensureIndex({ insert : 1 }) |
|
41 |
||
42 |
// For more logging
|
|
43 |
// mongos.getDB("admin").runCommand({ setParameter : 1, logLevel : 3 })
|
|
44 |
||
45 |
print( "INSERT!" ) |
|
46 |
||
47 |
// Insert a bunch of data
|
|
48 |
var toInsert = 2000 |
|
49 |
for( var i = 0; i < toInsert; i++ ){ |
|
50 |
coll.insert({ my : "test", data : "to", insert : i }) |
|
51 |
}
|
|
52 |
||
53 |
assert.eq( coll.getDB().getLastError(), null ) |
|
54 |
||
55 |
print( "UPDATE!" ) |
|
56 |
||
57 |
// Update a bunch of data
|
|
58 |
var toUpdate = toInsert |
|
59 |
for( var i = 0; i < toUpdate; i++ ){ |
|
60 |
var id = coll.findOne({ insert : i })._id |
|
61 |
coll.update({ insert : i, _id : id }, { $inc : { counter : 1 } }) |
|
62 |
}
|
|
63 |
||
64 |
assert.eq( coll.getDB().getLastError(), null ) |
|
65 |
||
66 |
print( "DELETE" ) |
|
67 |
||
68 |
// Remove a bunch of data
|
|
69 |
var toDelete = toInsert / 2 |
|
70 |
for( var i = 0; i < toDelete; i++ ){ |
|
71 |
coll.remove({ insert : i }) |
|
72 |
}
|
|
73 |
||
74 |
assert.eq( coll.getDB().getLastError(), null ) |
|
75 |
||
76 |
// Make sure the right amount of data is there
|
|
77 |
assert.eq( coll.find().count(), toInsert / 2 ) |
|
78 |
||
79 |
// Finish
|
|
80 |
st.stop() |