diff options
author | gregs <greg@10gen.com> | 2011-08-29 15:35:41 -0400 |
---|---|---|
committer | gregs <greg@10gen.com> | 2011-08-29 15:36:41 -0400 |
commit | 8c0e882052259000c665b7ad28f27118bba0ad6f (patch) | |
tree | f6d5f7269a78fd9c7ab5d798928085ec229080f2 | |
parent | ab2b5d24d6f668b842651166656d5e023a0c129b (diff) | |
download | mongo-8c0e882052259000c665b7ad28f27118bba0ad6f.tar.gz |
test for SERVER-3710
-rw-r--r-- | jstests/sharding/sharding_with_keyfile.js | 69 | ||||
-rwxr-xr-x | jstests/sharding/sharding_with_keyfile.key | 3 | ||||
-rwxr-xr-x | shell/servers.js | 23 |
3 files changed, 90 insertions, 5 deletions
diff --git a/jstests/sharding/sharding_with_keyfile.js b/jstests/sharding/sharding_with_keyfile.js new file mode 100644 index 00000000000..94aea571258 --- /dev/null +++ b/jstests/sharding/sharding_with_keyfile.js @@ -0,0 +1,69 @@ +// Tests sharding with a key file + +var st = new ShardingTest({ name : jsTestName(), + shards : 2, + mongos : 1, + keyFile : keyFile = "jstests/sharding/" + jsTestName() + ".key" }) + +// Make sure all our instances got the key +var configs = st._configDB.split(",") +for( var i = 0; i < configs.length; i++ ) configs[i] = new Mongo( configs[i] ) +var shards = st._connections +var mongoses = st._mongos + +for( var i = 0; i < configs.length; i++ ) + assert.eq( configs[i].getDB("admin").runCommand({ getCmdLineOpts : 1 }).parsed.keyFile, keyFile ) + +for( var i = 0; i < shards.length; i++ ) + assert.eq( shards[i].getDB("admin").runCommand({ getCmdLineOpts : 1 }).parsed.keyFile, keyFile ) + +for( var i = 0; i < mongoses.length; i++ ) + assert.eq( mongoses[i].getDB("admin").runCommand({ getCmdLineOpts : 1 }).parsed.keyFile, keyFile ) + +var mongos = st.s0 +var coll = mongos.getCollection( "test.foo" ) + +st.shardColl( coll, { _id : 1 } ) + +// Create an index so we can find by num later +coll.ensureIndex({ insert : 1 }) + +// For more logging +// mongos.getDB("admin").runCommand({ setParameter : 1, logLevel : 3 }) + +print( "INSERT!" ) + +// Insert a bunch of data +var toInsert = 2000 +for( var i = 0; i < toInsert; i++ ){ + coll.insert({ my : "test", data : "to", insert : i }) +} + +assert.eq( coll.getDB().getLastError(), null ) + +print( "UPDATE!" ) + +// Update a bunch of data +var toUpdate = toInsert +for( var i = 0; i < toUpdate; i++ ){ + var id = coll.findOne({ insert : i })._id + coll.update({ insert : i, _id : id }, { $inc : { counter : 1 } }) +} + +assert.eq( coll.getDB().getLastError(), null ) + +print( "DELETE" ) + +// Remove a bunch of data +var toDelete = toInsert / 2 +for( var i = 0; i < toDelete; i++ ){ + coll.remove({ insert : i }) +} + +assert.eq( coll.getDB().getLastError(), null ) + +// Make sure the right amount of data is there +assert.eq( coll.find().count(), toInsert / 2 ) + +// Finish +st.stop() diff --git a/jstests/sharding/sharding_with_keyfile.key b/jstests/sharding/sharding_with_keyfile.key new file mode 100755 index 00000000000..fe3344b9444 --- /dev/null +++ b/jstests/sharding/sharding_with_keyfile.key @@ -0,0 +1,3 @@ +aBcDeFg +1010101 +JJJJJJJ
\ No newline at end of file diff --git a/shell/servers.js b/shell/servers.js index e551559a79c..af22ea84cff 100755 --- a/shell/servers.js +++ b/shell/servers.js @@ -182,13 +182,15 @@ myPort = function() { ShardingTest = function( testName , numShards , verboseLevel , numMongos , otherParams ){ // Check if testName is an object, if so, pull params from there + var keyFile = undefined if( testName && ! testName.charAt ){ var params = testName testName = params.name || "test" numShards = params.shards || 2 verboseLevel = params.verbose || 0 numMongos = params.mongos || 1 - otherParams = params.other || {} + otherParams = params.other || {} + keyFile = params.keyFile || otherParams.keyFile } this._testName = testName; @@ -221,7 +223,7 @@ ShardingTest = function( testName , numShards , verboseLevel , numMongos , other var numReplicas = rsDefaults.nodes || otherParams.numReplicas || 3 delete rsDefaults.nodes - var rs = new ReplSetTest( { name : setName , nodes : numReplicas , startPort : 31100 + ( i * 100 ) } ); + var rs = new ReplSetTest( { name : setName , nodes : numReplicas , startPort : 31100 + ( i * 100 ), keyFile : keyFile } ); this._rs[i] = { setName : setName , test : rs , nodes : rs.startSet( rsDefaults ) , url : rs.getURL() }; rs.initiate(); @@ -237,8 +239,10 @@ ShardingTest = function( testName , numShards , verboseLevel , numMongos , other } this._configServers = [] - for ( var i=0; i<3; i++ ){ - var conn = startMongodTest( 30000 + i , testName + "-config" + i, false, otherParams.extraOptions ); + for ( var i=0; i<3; i++ ){ + var options = otherParams.extraOptions + if( keyFile ) options["keyFile"] = keyFile + var conn = startMongodTest( 30000 + i , testName + "-config" + i, false, options ); this._alldbpaths.push( testName + "-config" + i ) this._configServers.push( conn ); } @@ -251,7 +255,9 @@ ShardingTest = function( testName , numShards , verboseLevel , numMongos , other } else { for ( var i=0; i<numShards; i++){ - var conn = startMongodTest( 30000 + i , testName + i, 0, {useHostname : otherParams.useHostname} ); + var options = { useHostname : otherParams.useHostname } + if( keyFile ) options["keyFile"] = keyFile + var conn = startMongodTest( 30000 + i , testName + i, 0, options ); this._alldbpaths.push( testName +i ) this._connections.push( conn ); } @@ -273,6 +279,7 @@ ShardingTest = function( testName , numShards , verboseLevel , numMongos , other var myPort = startMongosPort - i; print("ShardingTest config: "+this._configDB); var opts = { port : startMongosPort - i , v : verboseLevel || 0 , configdb : this._configDB }; + if( keyFile ) opts["keyFile"] = keyFile for (var j in otherParams.extraOptions) { opts[j] = otherParams.extraOptions[j]; } @@ -1080,6 +1087,7 @@ ReplSetTest = function( opts ){ this.useSeedList = opts.useSeedList || false; this.bridged = opts.bridged || false; this.ports = []; + this.keyFile = opts.keyFile this.startPort = opts.startPort || 31000; @@ -1260,6 +1268,11 @@ ReplSetTest.prototype.getOptions = function( n , extra , putBinaryFirst ){ a.push( "--dbpath" ); a.push( this.getPath( ( n.host ? this.getNodeId( n ) : n ) ) ); + if( this.keyFile ){ + a.push( "--keyFile" ) + a.push( keyFile ) + } + if( jsTestOptions().noJournal ) a.push( "--nojournal" ) if( jsTestOptions().noJournalPrealloc ) a.push( "--nopreallocj" ) |