/** * Run a mongod process. * * After initializing a MongodRunner, you must call start() on it. * @param {int} port port to run db on, use allocatePorts(num) to requision * @param {string} dbpath path to use * @param {boolean} peer pass in false (DEPRECATED, was used for replica pair host) * @param {boolean} arbiter pass in false (DEPRECATED, was used for replica pair host) * @param {array} extraArgs other arguments for the command line * @param {object} options other options include no_bind to not bind_ip to 127.0.0.1 * (necessary for replica set testing) */ MongodRunner = function( port, dbpath, peer, arbiter, extraArgs, options ) { this.port_ = port; this.dbpath_ = dbpath; this.peer_ = peer; this.arbiter_ = arbiter; this.extraArgs_ = extraArgs; this.options_ = options ? options : {}; }; /** * Start this mongod process. * * @param {boolean} reuseData If the data directory should be left intact (default is to wipe it) */ MongodRunner.prototype.start = function( reuseData ) { var args = []; if ( reuseData ) { args.push( "mongod" ); } args.push( "--port" ); args.push( this.port_ ); args.push( "--dbpath" ); args.push( this.dbpath_ ); args.push( "--nohttpinterface" ); args.push( "--noprealloc" ); args.push( "--smallfiles" ); if (!this.options_.no_bind) { args.push( "--bind_ip" ); args.push( "127.0.0.1" ); } if ( this.extraArgs_ ) { args = args.concat( this.extraArgs_ ); } removeFile( this.dbpath_ + "/mongod.lock" ); if ( reuseData ) { return startMongoProgram.apply( null, args ); } else { return startMongod.apply( null, args ); } } MongodRunner.prototype.port = function() { return this.port_; } MongodRunner.prototype.toString = function() { return [ this.port_, this.dbpath_, this.peer_, this.arbiter_ ].toString(); } ToolTest = function( name, extraOptions ){ this.name = name; this.options = extraOptions; this.port = allocatePorts(1)[0]; this.baseName = "jstests_tool_" + name; this.root = MongoRunner.dataPath + this.baseName; this.dbpath = this.root + "/"; this.ext = this.root + "_external/"; this.extFile = this.root + "_external/a"; this.useSSL = jsTestOptions().useSSL resetDbpath( this.dbpath ); resetDbpath( this.ext ); } ToolTest.prototype.startDB = function( coll ){ assert( ! this.m , "db already running" ); var options = {port : this.port, dbpath : this.dbpath, nohttpinterface : "", noprealloc : "", smallfiles : "", bind_ip : "127.0.0.1"}; Object.extend(options, this.options); if ( this.useSSL ) { Object.extend(options, { sslMode: "requireSSL", sslPEMKeyFile: "jstests/libs/server.pem", sslCAFile: "jstests/libs/ca.pem", sslWeakCertificateValidation: "" } ); } this.m = startMongoProgram.apply(null, MongoRunner.arrOptions("mongod", options)); this.db = this.m.getDB( this.baseName ); if ( coll ) return this.db.getCollection( coll ); return this.db; } ToolTest.prototype.stop = function(){ if ( ! this.m ) return; stopMongod( this.port ); this.m = null; this.db = null; print('*** ' + this.name + " completed successfully ***"); } ToolTest.prototype.runTool = function(){ var a = [ "mongo" + arguments[0] ]; var hasdbpath = false; for ( var i=1; i= 2) { var port = hostAndPort[1]; } } if (port) { args.push("--port", port); } if( jsTestOptions().useSSL ) { args.push( "--ssl" ) args.push( "--sslPEMKeyFile" ) args.push( "jstests/libs/client.pem" ) args.push( "--sslCAFile" ) args.push( "jstests/libs/ca.pem" ) } x = startMongoProgramNoConnect.apply(null, args); return function(){ waitProgram( x ); }; } var testingReplication = false; function skipIfTestingReplication(){ if (testingReplication) { print("skipIfTestingReplication skipping"); quit(0); } }