diff options
author | Kyle Banker <kylebanker@gmail.com> | 2010-07-29 17:27:48 -0400 |
---|---|---|
committer | Kyle Banker <kylebanker@gmail.com> | 2010-07-29 17:27:48 -0400 |
commit | 9cd0f9ec6b89ac6b8a602f075aa6ae019536148b (patch) | |
tree | a10eded8ddcae810087d5954aad8fd3c0d949af1 /shell | |
parent | 84752a719ec495d93ac4fde4d4a8e8d604daaee0 (diff) | |
download | mongo-9cd0f9ec6b89ac6b8a602f075aa6ae019536148b.tar.gz |
framework for testing with mongobridge (awaiting more suitable rs code)
Diffstat (limited to 'shell')
-rw-r--r-- | shell/servers.js | 56 |
1 files changed, 47 insertions, 9 deletions
diff --git a/shell/servers.js b/shell/servers.js index 52d1391660e..2f8faa1c744 100644 --- a/shell/servers.js +++ b/shell/servers.js @@ -794,9 +794,10 @@ ReplTest.prototype.stop = function( master , signal ){ return stopMongod( this.getPort( master ) , signal || 15 ); } -allocatePorts = function( n ) { +allocatePorts = function( n , startPort ) { var ret = []; - for( var i = 31000; i < 31000 + n; ++i ) + var start = startPort || 31000; + for( var i = start; i < start + n; ++i ) ret.push( i ); return ret; } @@ -866,14 +867,37 @@ ReplSetTest = function( opts ){ this.name = opts.name || "testReplSet"; this.host = opts.host || getHostName(); this.numNodes = opts.nodes || 0; + this.bridged = opts.bridged || false; + this.ports = []; - this.ports = allocatePorts( this.numNodes ); + this.startPort = opts.startPort || 31000; + + if(this.bridged) { + this.bridgePorts = []; + + var allPorts = allocatePorts( this.numNodes * 2 , this.startPort ); + for(var i=0; i < this.numNodes; i++) { + this.ports[i] = allPorts[i*2]; + this.bridgePorts[i] = allPorts[i*2 + 1]; + } + + this.initBridges(); + } + else { + this.ports = allocatePorts( this.numNodes , startPort ); + } this.nodes = []; this.nodeIds = {}; this.initLiveNodes(); } +ReplSetTest.prototype.initBridges = function() { + for(var i=0; i<this.ports.length; i++) { + startMongoProgram( "mongobridge", "--port", this.bridgePorts[i], "--dest", this.host + ":" + this.ports[i] ); + } +} + // List of nodes as host:port strings. ReplSetTest.prototype.nodeList = function() { var list = []; @@ -913,7 +937,13 @@ ReplSetTest.prototype.getReplSetConfig = function() { for(i=0; i<this.ports.length; i++) { member = {}; member['_id'] = i; - member['host'] = this.host + ":" + this.ports[i]; + + if(this.bridged) + var port = this.bridgePorts[i]; + else + var port = this.ports[i]; + + member['host'] = this.host + ":" + port; cfg.members.push(member); } @@ -941,11 +971,19 @@ ReplSetTest.prototype.getOptions = function( n , extra , putBinaryFirst ){ for(i=0; i<this.ports.length; i++) { // Don't include this node in the replica set list - //if(this.ports[i] == this.ports[n]) { - // continue; - //} + if(this.bridged && this.ports[i] == this.ports[n]) { + continue; + } + + // Connect on the right port + if(this.bridged) { + var port = this.bridgePorts[i]; + } + else { + var port = this.ports[i]; + } - var str = this.host + ":" + this.ports[i]; + var str = this.host + ":" + port; hosts.push(str); } replSetString += hosts.join(","); @@ -1025,7 +1063,7 @@ ReplSetTest.prototype.getMaster = function( timeout ) { // Add a node to the test set ReplSetTest.prototype.add = function( config ) { if(this.ports.length == 0) { - var nextPort = allocatePorts(1)[0]; + var nextPort = allocatePorts( 1, this.startPort )[0]; } else { var nextPort = this.ports[this.ports.length-1] + 1; |