diff options
author | Eliot Horowitz <eliot@10gen.com> | 2014-06-18 18:15:03 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2014-06-19 01:49:58 -0400 |
commit | b4cafb46595d6e889f8effdca16e98c3f505078e (patch) | |
tree | b3304b672e2d540a72c7ba7424469e9b78bcce74 /src/mongo/dbtests | |
parent | 7ce2ffdbbaac003fb608e81ae03090adef960237 (diff) | |
download | mongo-b4cafb46595d6e889f8effdca16e98c3f505078e.tar.gz |
SERVER-13635 SERVER-1153: can choose heap1 at startup, but doesn't remotely work yet
Diffstat (limited to 'src/mongo/dbtests')
-rw-r--r-- | src/mongo/dbtests/basictests.cpp | 25 | ||||
-rw-r--r-- | src/mongo/dbtests/dbhelper_tests.cpp | 3 | ||||
-rw-r--r-- | src/mongo/dbtests/directclienttests.cpp | 58 | ||||
-rw-r--r-- | src/mongo/dbtests/gle_test.cpp | 20 | ||||
-rw-r--r-- | src/mongo/dbtests/gridfstest.cpp | 4 | ||||
-rw-r--r-- | src/mongo/dbtests/indexupdatetests.cpp | 2 | ||||
-rw-r--r-- | src/mongo/dbtests/jstests.cpp | 6 | ||||
-rw-r--r-- | src/mongo/dbtests/perftests.cpp | 57 | ||||
-rw-r--r-- | src/mongo/dbtests/query_multi_plan_runner.cpp | 3 | ||||
-rw-r--r-- | src/mongo/dbtests/query_stage_fetch.cpp | 4 | ||||
-rw-r--r-- | src/mongo/dbtests/query_stage_keep.cpp | 4 | ||||
-rw-r--r-- | src/mongo/dbtests/runner_registry.cpp | 4 | ||||
-rw-r--r-- | src/mongo/dbtests/updatetests.cpp | 11 |
13 files changed, 92 insertions, 109 deletions
diff --git a/src/mongo/dbtests/basictests.cpp b/src/mongo/dbtests/basictests.cpp index 8149254024b..1fbd27763c4 100644 --- a/src/mongo/dbtests/basictests.cpp +++ b/src/mongo/dbtests/basictests.cpp @@ -43,8 +43,6 @@ #include "mongo/util/text.h" #include "mongo/util/time_support.h" -#include "mongo/db/storage/mmap_v1/mmap_v1_database_catalog_entry.h" //XXX - namespace BasicTests { class Rarely { @@ -381,23 +379,12 @@ namespace BasicTests { OperationContextImpl txn; Lock::GlobalWrite lk(txn.lockState()); - bool isNew = false; - // this leaks as ~Database is private - // if that changes, should put this on the stack - { - MMAPV1DatabaseCatalogEntry* temp = new MMAPV1DatabaseCatalogEntry(&txn, - "dbtests_basictests_ownsns", - storageGlobalParams.dbpath, - storageGlobalParams.directoryperdb, - true); - Database * db = new Database( &txn, "dbtests_basictests_ownsns", isNew, temp ); - ASSERT( isNew ); - - ASSERT( db->ownsNS( "dbtests_basictests_ownsns.x" ) ); - ASSERT( db->ownsNS( "dbtests_basictests_ownsns.x.y" ) ); - ASSERT( ! db->ownsNS( "dbtests_basictests_ownsn.x.y" ) ); - ASSERT( ! db->ownsNS( "dbtests_basictests_ownsnsa.x.y" ) ); - } + Database db( &txn, "dbtests_basictests_ownsns", NULL ); + + ASSERT( db.ownsNS( "dbtests_basictests_ownsns.x" ) ); + ASSERT( db.ownsNS( "dbtests_basictests_ownsns.x.y" ) ); + ASSERT( !db.ownsNS( "dbtests_basictests_ownsn.x.y" ) ); + ASSERT( !db.ownsNS( "dbtests_basictests_ownsnsa.x.y" ) ); } }; diff --git a/src/mongo/dbtests/dbhelper_tests.cpp b/src/mongo/dbtests/dbhelper_tests.cpp index dac9e27ca73..06354880e42 100644 --- a/src/mongo/dbtests/dbhelper_tests.cpp +++ b/src/mongo/dbtests/dbhelper_tests.cpp @@ -40,7 +40,6 @@ namespace mongo { */ static const char * const ns = "unittests.removetests"; - static DBDirectClient client; // TODO: Normalize with test framework /** Simple test for Helpers::RemoveRange. */ @@ -51,6 +50,7 @@ namespace mongo { { } void run() { + DBDirectClient client; for ( int i = 0; i < 10; ++i ) { client.insert( ns, BSON( "_id" << i ) ); } @@ -83,6 +83,7 @@ namespace mongo { return bab.arr(); } BSONArray docs() const { + DBDirectClient client; auto_ptr<DBClientCursor> cursor = client.query( ns, Query().hint( BSON( "_id" << 1 ) ) ); BSONArrayBuilder bab; diff --git a/src/mongo/dbtests/directclienttests.cpp b/src/mongo/dbtests/directclienttests.cpp index 772d7b4d668..0bea6ea2399 100644 --- a/src/mongo/dbtests/directclienttests.cpp +++ b/src/mongo/dbtests/directclienttests.cpp @@ -45,37 +45,30 @@ namespace DirectClientTests { // NOTE: Not bothering to backup the old error record. ClientBase() { mongo::lastError.reset( new LastError() ); } virtual ~ClientBase() { } - protected: - static bool error() { - return !_client.getPrevError().getField( "err" ).isNull(); - } - DBDirectClient &client() const { return _client; } - private: - static DBDirectClient _client; }; - DBDirectClient ClientBase::_client; const char *ns = "a.b"; class Capped : public ClientBase { public: virtual void run() { + DBDirectClient client; for( int pass=0; pass < 3; pass++ ) { - client().createCollection(ns, 1024 * 1024, true, 999); + client.createCollection(ns, 1024 * 1024, true, 999); for( int j =0; j < pass*3; j++ ) - client().insert(ns, BSON("x" << j)); + client.insert(ns, BSON("x" << j)); // test truncation of a capped collection if( pass ) { BSONObj info; BSONObj cmd = BSON( "captrunc" << "b" << "n" << 1 << "inc" << true ); //cout << cmd.toString() << endl; - bool ok = client().runCommand("a", cmd, info); + bool ok = client.runCommand("a", cmd, info); //cout << info.toString() << endl; verify(ok); } - verify( client().dropCollection(ns) ); + verify( client.dropCollection(ns) ); } } }; @@ -83,21 +76,22 @@ namespace DirectClientTests { class InsertMany : ClientBase { public: virtual void run(){ + DBDirectClient client; vector<BSONObj> objs; objs.push_back(BSON("_id" << 1)); objs.push_back(BSON("_id" << 1)); objs.push_back(BSON("_id" << 2)); - client().dropCollection(ns); - client().insert(ns, objs); - ASSERT_EQUALS(client().getLastErrorDetailed()["code"].numberInt(), 11000); - ASSERT_EQUALS((int)client().count(ns), 1); + client.dropCollection(ns); + client.insert(ns, objs); + ASSERT_EQUALS(client.getLastErrorDetailed()["code"].numberInt(), 11000); + ASSERT_EQUALS((int)client.count(ns), 1); - client().dropCollection(ns); - client().insert(ns, objs, InsertOption_ContinueOnError); - ASSERT_EQUALS(client().getLastErrorDetailed()["code"].numberInt(), 11000); - ASSERT_EQUALS((int)client().count(ns), 2); + client.dropCollection(ns); + client.insert(ns, objs, InsertOption_ContinueOnError); + ASSERT_EQUALS(client.getLastErrorDetailed()["code"].numberInt(), 11000); + ASSERT_EQUALS((int)client.count(ns), 2); } }; @@ -105,16 +99,18 @@ namespace DirectClientTests { class BadNSCmd : ClientBase { public: virtual void run(){ + DBDirectClient client; BSONObj result; BSONObj cmdObj = BSON( "count" << "" ); - ASSERT_THROWS( client().runCommand( "", cmdObj, result ), UserException ); + ASSERT_THROWS( client.runCommand( "", cmdObj, result ), UserException ); } }; class BadNSQuery : ClientBase { public: virtual void run(){ - auto_ptr<DBClientCursor> cursor = client().query( "", Query(), 1 ); + DBDirectClient client; + auto_ptr<DBClientCursor> cursor = client.query( "", Query(), 1 ); ASSERT(cursor->more()); BSONObj result = cursor->next().getOwned(); ASSERT( result.hasField( "$err" )); @@ -125,7 +121,8 @@ namespace DirectClientTests { class BadNSGetMore : ClientBase { public: virtual void run(){ - auto_ptr<DBClientCursor> cursor = client().getMore("", 1, 1); + DBDirectClient client; + auto_ptr<DBClientCursor> cursor = client.getMore("", 1, 1); ASSERT(cursor->more()); BSONObj result = cursor->next().getOwned(); ASSERT(result.hasField("$err")); @@ -136,24 +133,27 @@ namespace DirectClientTests { class BadNSInsert : ClientBase { public: virtual void run(){ - client().insert( "", BSONObj(), 0 ); - ASSERT( !client().getLastError().empty() ); + DBDirectClient client; + client.insert( "", BSONObj(), 0 ); + ASSERT( !client.getLastError().empty() ); } }; class BadNSUpdate : ClientBase { public: virtual void run(){ - client().update( "", Query(), BSON( "$set" << BSON( "x" << 1 )) ); - ASSERT( !client().getLastError().empty() ); + DBDirectClient client; + client.update( "", Query(), BSON( "$set" << BSON( "x" << 1 )) ); + ASSERT( !client.getLastError().empty() ); } }; class BadNSRemove : ClientBase { public: virtual void run(){ - client().remove( "", Query() ); - ASSERT( !client().getLastError().empty() ); + DBDirectClient client; + client.remove( "", Query() ); + ASSERT( !client.getLastError().empty() ); } }; diff --git a/src/mongo/dbtests/gle_test.cpp b/src/mongo/dbtests/gle_test.cpp index b1894735c6c..e804b167ed3 100644 --- a/src/mongo/dbtests/gle_test.cpp +++ b/src/mongo/dbtests/gle_test.cpp @@ -35,7 +35,6 @@ using mongo::MsgAssertionException; * Test getLastError client handling */ namespace { - DBDirectClient _client; static const char* const _ns = "unittests.gle"; /** @@ -44,9 +43,10 @@ namespace { class GetLastErrorCommandFailure { public: void run() { - _client.insert(_ns, BSON( "test" << "test")); + DBDirectClient client; + client.insert(_ns, BSON( "test" << "test")); // Cannot mix fsync + j, will make command fail - string gleString = _client.getLastError(true, true, 10, 10); + string gleString = client.getLastError(true, true, 10, 10); ASSERT_NOT_EQUALS(gleString, ""); } }; @@ -57,9 +57,10 @@ namespace { class GetLastErrorClean { public: void run() { - _client.insert(_ns, BSON( "test" << "test")); + DBDirectClient client; + client.insert(_ns, BSON( "test" << "test")); // Make sure there was no error - string gleString = _client.getLastError(); + string gleString = client.getLastError(); ASSERT_EQUALS(gleString, ""); } }; @@ -70,15 +71,16 @@ namespace { class GetLastErrorFromDup { public: void run() { - _client.insert(_ns, BSON( "_id" << 1)); + DBDirectClient client; + client.insert(_ns, BSON( "_id" << 1)); // Make sure there was no error - string gleString = _client.getLastError(); + string gleString = client.getLastError(); ASSERT_EQUALS(gleString, ""); //insert dup - _client.insert(_ns, BSON( "_id" << 1)); + client.insert(_ns, BSON( "_id" << 1)); // Make sure there was an error - gleString = _client.getLastError(); + gleString = client.getLastError(); ASSERT_NOT_EQUALS(gleString, ""); } }; diff --git a/src/mongo/dbtests/gridfstest.cpp b/src/mongo/dbtests/gridfstest.cpp index b1d2bca8d8a..edabefa1d32 100644 --- a/src/mongo/dbtests/gridfstest.cpp +++ b/src/mongo/dbtests/gridfstest.cpp @@ -37,12 +37,12 @@ using mongo::GridFS; using mongo::MsgAssertionException; namespace { - DBDirectClient _client; class SetChunkSizeTest { public: virtual void run() { - GridFS grid( _client, "gridtest" ); + DBDirectClient client; + GridFS grid( client, "gridtest" ); grid.setChunkSize( 5 ); ASSERT_EQUALS( 5U, grid.getChunkSize() ); diff --git a/src/mongo/dbtests/indexupdatetests.cpp b/src/mongo/dbtests/indexupdatetests.cpp index 6fb11363da6..f0cdf72e32e 100644 --- a/src/mongo/dbtests/indexupdatetests.cpp +++ b/src/mongo/dbtests/indexupdatetests.cpp @@ -43,7 +43,6 @@ namespace IndexUpdateTests { static const char* const _ns = "unittests.indexupdate"; - DBDirectClient _client; #if 0 ExternalSortComparison* _aFirstSort = BtreeBasedBulkAccessMethod::getComparison(0, BSON("a" << 1)); #endif @@ -94,6 +93,7 @@ namespace IndexUpdateTests { } #endif + DBDirectClient _client; OperationContextImpl _txn; Client::WriteContext _ctx; }; diff --git a/src/mongo/dbtests/jstests.cpp b/src/mongo/dbtests/jstests.cpp index d8a116ee6ea..136d590b09f 100644 --- a/src/mongo/dbtests/jstests.cpp +++ b/src/mongo/dbtests/jstests.cpp @@ -904,8 +904,6 @@ namespace JSTests { verify(0); } - DBDirectClient client; - class Utf8Check { public: Utf8Check() { reset(); } @@ -932,6 +930,7 @@ namespace JSTests { client.dropCollection( ns() ); } static const char *ns() { return "unittest.jstests.utf8check"; } + DBDirectClient client; }; class LongUtf8String { @@ -948,6 +947,7 @@ namespace JSTests { client.dropCollection( ns() ); } static const char *ns() { return "unittest.jstests.longutf8string"; } + DBDirectClient client; }; class InvalidUTF8Check { @@ -1077,6 +1077,7 @@ namespace JSTests { virtual string jsonOut() const { return json(); } + DBDirectClient client; }; class DBRefTest : public TestRoundTrip { @@ -1981,6 +1982,7 @@ namespace JSTests { class InvalidStoredJS { public: void run() { + DBDirectClient client; BSONObjBuilder query; query.append( "_id" , "invalidstoredjs1" ); diff --git a/src/mongo/dbtests/perftests.cpp b/src/mongo/dbtests/perftests.cpp index 6a898659cd1..672e9b99a62 100644 --- a/src/mongo/dbtests/perftests.cpp +++ b/src/mongo/dbtests/perftests.cpp @@ -82,20 +82,19 @@ namespace PerfTests { //mongo::lastError.release(); } protected: - static void insert( const char *ns, BSONObj o ) { + void insert( const char *ns, BSONObj o ) { _client.insert( ns, o ); } - static void update( const char *ns, BSONObj q, BSONObj o, bool upsert = 0 ) { + void update( const char *ns, BSONObj q, BSONObj o, bool upsert = 0 ) { _client.update( ns, Query( q ), o, upsert ); } - static bool error() { + bool error() { return !_client.getPrevError().getField( "err" ).isNull(); } - DBClientBase &client() const { return _client; } + DBClientBase* client() { return &_client; } private: - static DBClientType _client; + DBClientType _client; }; - DBClientType ClientBase::_client; /* if you want recording of the timings, place the password for the perf database in ./../settings.py: @@ -178,7 +177,7 @@ namespace PerfTests { // optional 2nd test phase to be timed separately. You must provide it with a unique // name in order for it to run by overloading 'name2'. - virtual void timed2(DBClientBase&) {} + virtual void timed2(DBClientBase*) {} // return name of second test. virtual string name2() { return name(); } @@ -297,7 +296,7 @@ namespace PerfTests { unsigned long long n = 0; _ns = string("perftest.") + name(); - client().dropCollection(ns()); + client()->dropCollection(ns()); prep(); int hlm = howLong(); dur::stats._intervalMicros = 0; // no auto rotate @@ -319,7 +318,7 @@ namespace PerfTests { } while( t.micros() < (hlm * 1000) ); } - client().getLastError(); // block until all ops are finished + client()->getLastError(); // block until all ops are finished say(n, t.micros(), name()); @@ -365,7 +364,7 @@ namespace PerfTests { while( 1 ) { unsigned int i = 0; for( i = 0; i < Batch; i++ ) - timed2(c); + timed2(&c); *counter += i; if( stop ) break; @@ -989,13 +988,13 @@ namespace PerfTests { return "insert-duplicate-_ids"; } void prep() { - client().insert( ns(), o ); + client()->insert( ns(), o ); } void timed() { - client().insert( ns(), o ); + client()->insert( ns(), o ); } void post() { - verify( client().count(ns()) == 1 ); + verify( client()->count(ns()) == 1 ); } }; @@ -1014,7 +1013,7 @@ namespace PerfTests { unsigned i; void timed() { BSONObj o = BSON( "_id" << i++ << "x" << 99 ); - client().insert( ns(), o ); + client()->insert( ns(), o ); } virtual bool testThreaded() { if( profiling ) @@ -1025,13 +1024,13 @@ namespace PerfTests { return "findOne_by_id"; } - void timed2(DBClientBase& c) { + void timed2(DBClientBase* c) { Query q = QUERY( "_id" << (unsigned) (rand() % i) ); - c.findOne(ns(), q); + c->findOne(ns(), q); } void post() { #if !defined(_DEBUG) - verify( client().count(ns()) > 50 ); + verify( client()->count(ns()) > 50 ); #endif } }; @@ -1059,7 +1058,7 @@ namespace PerfTests { } string name() { return "insert-big"; } void timed() { - client().insert( ns(), x ); + client()->insert( ns(), x ); } }; @@ -1068,13 +1067,13 @@ namespace PerfTests { virtual int howLongMillis() { return profiling ? 30000 : 5000; } string name() { return "random-inserts"; } void prep() { - client().insert( ns(), BSONObj() ); - client().ensureIndex(ns(), BSON("x"<<1)); + client()->insert( ns(), BSONObj() ); + client()->ensureIndex(ns(), BSON("x"<<1)); } void timed() { int x = rand(); BSONObj y = BSON("x" << x << "y" << rand() << "z" << 33); - client().insert(ns(), y); + client()->insert(ns(), y); } }; @@ -1088,26 +1087,26 @@ namespace PerfTests { } virtual string name() { return "random-upserts"; } void prep() { - client().insert( ns(), BSONObj() ); - client().ensureIndex(ns(), BSON("x"<<1)); + client()->insert( ns(), BSONObj() ); + client()->ensureIndex(ns(), BSON("x"<<1)); } void timed() { int x = rand(); BSONObj q = BSON("x" << x); BSONObj y = BSON("x" << x << "y" << rand() << "z" << 33); - client().update(ns(), q, y, /*upsert*/true); + client()->update(ns(), q, y, /*upsert*/true); } virtual bool testThreaded() { return true; } virtual string name2() { return name()+"-inc"; } - virtual void timed2(DBClientBase& c) { + virtual void timed2(DBClientBase* c) { static BSONObj I = BSON( "$inc" << BSON( "y" << 1 ) ); // test some $inc's int x = rand(); BSONObj q = BSON("x" << x); - c.update(ns(), q, I); + c->update(ns(), q, I); } }; @@ -1117,8 +1116,8 @@ namespace PerfTests { string name() { return T::name() + "-more-indexes"; } void prep() { T::prep(); - this->client().ensureIndex(this->ns(), BSON("y"<<1)); - this->client().ensureIndex(this->ns(), BSON("z"<<1)); + this->client()->ensureIndex(this->ns(), BSON("y"<<1)); + this->client()->ensureIndex(this->ns(), BSON("z"<<1)); } }; @@ -1175,7 +1174,7 @@ namespace PerfTests { return name(); } - virtual void timed2(DBClientBase&) { + virtual void timed2(DBClientBase*) { // We just want to re-run 'timed' when timed2 is invoked as a threaded test, so it // invoke 'timed' statically to avoid overhead of virtual function call. this->FailPointTest::timed(); diff --git a/src/mongo/dbtests/query_multi_plan_runner.cpp b/src/mongo/dbtests/query_multi_plan_runner.cpp index 30393e396f4..8ca3b5a248c 100644 --- a/src/mongo/dbtests/query_multi_plan_runner.cpp +++ b/src/mongo/dbtests/query_multi_plan_runner.cpp @@ -83,10 +83,9 @@ namespace QueryMultiPlanRunner { static const char* ns() { return "unittests.QueryStageMultiPlanRunner"; } private: - static DBDirectClient _client; + DBDirectClient _client; }; - DBDirectClient MultiPlanRunnerBase::_client; // Basic ranking test: collection scan vs. highly selective index scan. Make sure we also get // all expected results out as well. diff --git a/src/mongo/dbtests/query_stage_fetch.cpp b/src/mongo/dbtests/query_stage_fetch.cpp index 5a97b5eb254..2fa7b25b377 100644 --- a/src/mongo/dbtests/query_stage_fetch.cpp +++ b/src/mongo/dbtests/query_stage_fetch.cpp @@ -76,11 +76,9 @@ namespace QueryStageFetch { static const char* ns() { return "unittests.QueryStageFetch"; } private: - static DBDirectClient _client; + DBDirectClient _client; }; - DBDirectClient QueryStageFetchBase::_client; - // // Test that a WSM with an obj is passed through verbatim. // diff --git a/src/mongo/dbtests/query_stage_keep.cpp b/src/mongo/dbtests/query_stage_keep.cpp index 8df8f1a5f28..c56f8ae7c71 100644 --- a/src/mongo/dbtests/query_stage_keep.cpp +++ b/src/mongo/dbtests/query_stage_keep.cpp @@ -91,11 +91,9 @@ namespace QueryStageKeep { } private: - static DBDirectClient _client; + DBDirectClient _client; }; - DBDirectClient QueryStageKeepBase::_client; - // Test that we actually merge flagged results. // diff --git a/src/mongo/dbtests/runner_registry.cpp b/src/mongo/dbtests/runner_registry.cpp index 8f197a5c552..ce84f65f446 100644 --- a/src/mongo/dbtests/runner_registry.cpp +++ b/src/mongo/dbtests/runner_registry.cpp @@ -95,13 +95,11 @@ namespace RunnerRegistry { } static const char* ns() { return "unittests.RunnerRegistryDiskLocInvalidation"; } - static DBDirectClient _client; + DBDirectClient _client; auto_ptr<Client::WriteContext> _ctx; OperationContextImpl _opCtx; }; - DBDirectClient RunnerRegistryBase::_client; - // Test that a registered runner receives invalidation notifications. class RunnerRegistryDiskLocInvalid : public RunnerRegistryBase { public: diff --git a/src/mongo/dbtests/updatetests.cpp b/src/mongo/dbtests/updatetests.cpp index e89997330cf..f486dd0ce3a 100644 --- a/src/mongo/dbtests/updatetests.cpp +++ b/src/mongo/dbtests/updatetests.cpp @@ -52,20 +52,19 @@ namespace UpdateTests { mongo::lastError.release(); } protected: - static void insert( const char *ns, BSONObj o ) { + void insert( const char *ns, BSONObj o ) { client_.insert( ns, o ); } - static void update( const char *ns, BSONObj q, BSONObj o, bool upsert = 0 ) { + void update( const char *ns, BSONObj q, BSONObj o, bool upsert = 0 ) { client_.update( ns, Query( q ), o, upsert ); } - static bool error() { + bool error() { return !client_.getPrevError().getField( "err" ).isNull(); } - DBDirectClient &client() const { return client_; } + DBDirectClient &client() { return client_; } private: - static DBDirectClient client_; + DBDirectClient client_; }; - DBDirectClient ClientBase::client_; class Fail : public ClientBase { public: |