From ee269aa35d11f8c9deeee8d79b79b11465f934b6 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Tue, 3 Jul 2012 10:44:44 +0100 Subject: [PATCH] Added the --delay option for mongobridge. This new argument adds an artificial delay after reading a message and before passing it on. This is mostly useful when testing replicaset member selection algorithms. --- src/mongo/tools/bridge.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/mongo/tools/bridge.cpp b/src/mongo/tools/bridge.cpp index 8c7547cd21ddb..ff63aa68b89a4 100644 --- a/src/mongo/tools/bridge.cpp +++ b/src/mongo/tools/bridge.cpp @@ -29,6 +29,7 @@ using namespace mongo; using namespace std; int port = 0; +int delay = 0; string destUri; void cleanup( int sig ); @@ -50,6 +51,7 @@ class Forwarder { mp_.shutdown(); break; } + sleepmillis( delay ); int oldId = m.header()->id; if ( m.operation() == dbQuery || m.operation() == dbMsg || m.operation() == dbGetMore ) { @@ -135,9 +137,10 @@ inline void setupSignals() {} #endif void helpExit() { - cout << "usage mongobridge --port --dest " << endl; + cout << "usage mongobridge --port --dest [ --delay ]" << endl; cout << " port: port to listen for mongo messages" << endl; cout << " destUri: uri of remote mongod instance" << endl; + cout << " ms: transfer delay in milliseconds (default = 0)" << endl; ::_exit( -1 ); } @@ -151,9 +154,9 @@ int main( int argc, char **argv ) { setupSignals(); - check( argc == 5 ); + check( argc == 5 || argc == 7 ); - for( int i = 1; i < 5; ++i ) { + for( int i = 1; i < argc; ++i ) { check( i % 2 != 0 ); if ( strcmp( argv[ i ], "--port" ) == 0 ) { port = strtol( argv[ ++i ], 0, 10 ); @@ -161,6 +164,9 @@ int main( int argc, char **argv ) { else if ( strcmp( argv[ i ], "--dest" ) == 0 ) { destUri = argv[ ++i ]; } + else if ( strcmp( argv[ i ], "--delay" ) == 0 ) { + delay = strtol( argv[ ++i ], 0, 10 ); + } else { check( false ); }