diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2014-06-28 14:12:40 -0400 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2014-06-28 14:12:40 -0400 |
commit | e1f5a39b1b625d04752be13f39c774e579b64cd8 (patch) | |
tree | b0211887cf6ff4628c7b783a989dae341caa5d01 /src/mongo/dbtests | |
parent | 89fcbab94c7103105e8c72f654a5774a066bdb90 (diff) | |
download | mongo-e1f5a39b1b625d04752be13f39c774e579b64cd8.tar.gz |
SERVER-13961 Add OperationContext argument to Client::Context
Time tracking and database access in Client::Context require access to the
OperationContext. Adding it as argument.
This is in preparation for removing LockState from Client.
Diffstat (limited to 'src/mongo/dbtests')
33 files changed, 852 insertions, 758 deletions
diff --git a/src/mongo/dbtests/clienttests.cpp b/src/mongo/dbtests/clienttests.cpp index 527f52f2554..1ba539f0266 100644 --- a/src/mongo/dbtests/clienttests.cpp +++ b/src/mongo/dbtests/clienttests.cpp @@ -40,19 +40,23 @@ namespace ClientTests { class Base { public: - Base( string coll ) { + Base( string coll ) : _ns("test." + coll) { + OperationContextImpl txn; + DBDirectClient db(&txn); + db.dropDatabase("test"); - _ns = (string)"test." + coll; } virtual ~Base() { + OperationContextImpl txn; + DBDirectClient db(&txn); + db.dropCollection( _ns ); } const char * ns() { return _ns.c_str(); } - string _ns; - DBDirectClient db; + const string _ns; }; @@ -60,6 +64,9 @@ namespace ClientTests { public: DropIndex() : Base( "dropindex" ) {} void run() { + OperationContextImpl txn; + DBDirectClient db(&txn); + db.insert( ns() , BSON( "x" << 2 ) ); ASSERT_EQUALS( 1 , db.getIndexes( ns() )->itcount() ); @@ -81,6 +88,8 @@ namespace ClientTests { public: ReIndex() : Base( "reindex" ) {} void run() { + OperationContextImpl txn; + DBDirectClient db(&txn); db.insert( ns() , BSON( "x" << 2 ) ); ASSERT_EQUALS( 1 , db.getIndexes( ns() )->itcount() ); @@ -98,6 +107,8 @@ namespace ClientTests { public: ReIndex2() : Base( "reindex2" ) {} void run() { + OperationContextImpl txn; + DBDirectClient db(&txn); db.insert( ns() , BSON( "x" << 2 ) ); ASSERT_EQUALS( 1 , db.getIndexes( ns() )->itcount() ); @@ -123,7 +134,9 @@ namespace ClientTests { BuildIndex() : Base("buildIndex") {} void run() { OperationContextImpl txn; + Client::WriteContext ctx(&txn, ns()); + DBDirectClient db(&txn); db.insert(ns(), BSON("x" << 1 << "y" << 2)); db.insert(ns(), BSON("x" << 2 << "y" << 2)); @@ -158,9 +171,14 @@ namespace ClientTests { public: CS_10() : Base( "CS_10" ) {} void run() { - string longs( 770, 'c' ); - for( int i = 0; i < 1111; ++i ) - db.insert( ns(), BSON( "a" << i << "b" << longs ) ); + OperationContextImpl txn; + DBDirectClient db(&txn); + + const string longs( 770, 'c' ); + for (int i = 0; i < 1111; ++i) { + db.insert(ns(), BSON("a" << i << "b" << longs)); + } + db.ensureIndex( ns(), BSON( "a" << 1 << "b" << 1 ) ); auto_ptr< DBClientCursor > c = db.query( ns(), Query().sort( BSON( "a" << 1 << "b" << 1 ) ) ); @@ -172,8 +190,13 @@ namespace ClientTests { public: PushBack() : Base( "PushBack" ) {} void run() { - for( int i = 0; i < 10; ++i ) - db.insert( ns(), BSON( "i" << i ) ); + OperationContextImpl txn; + DBDirectClient db(&txn); + + for (int i = 0; i < 10; ++i) { + db.insert(ns(), BSON("i" << i)); + } + auto_ptr< DBClientCursor > c = db.query( ns(), Query().sort( BSON( "i" << 1 ) ) ); BSONObj o = c->next(); @@ -212,7 +235,10 @@ namespace ClientTests { public: Create() : Base( "Create" ) {} void run() { - db.createCollection( "unittests.clienttests.create", 4096, true ); + OperationContextImpl txn; + DBDirectClient db(&txn); + + db.createCollection("unittests.clienttests.create", 4096, true); BSONObj info; ASSERT( db.runCommand( "unittests", BSON( "collstats" << "clienttests.create" ), info ) ); } @@ -237,6 +263,7 @@ namespace ClientTests { class All : public Suite { public: All() : Suite( "client" ) { + } void setupTests() { diff --git a/src/mongo/dbtests/commandtests.cpp b/src/mongo/dbtests/commandtests.cpp index a8aeb09bd6a..955620eac94 100644 --- a/src/mongo/dbtests/commandtests.cpp +++ b/src/mongo/dbtests/commandtests.cpp @@ -26,9 +26,10 @@ * then also delete it in the license file. */ -#include "mongo/pch.h" +#include "mongo/platform/basic.h" #include "mongo/db/d_concurrency.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/dbtests/dbtests.h" using namespace mongo; @@ -37,13 +38,14 @@ namespace CommandTests { // one namespace per command namespace FileMD5 { struct Base { - Base() { + Base() : db(&_txn) { db.dropCollection(ns()); db.ensureIndex(ns(), BSON( "files_id" << 1 << "n" << 1 )); } const char* ns() { return "test.fs.chunks"; } + OperationContextImpl _txn; DBDirectClient db; }; struct Type0 : Base { diff --git a/src/mongo/dbtests/config_server_fixture.h b/src/mongo/dbtests/config_server_fixture.h index 55c2d7f559f..f80565e1723 100644 --- a/src/mongo/dbtests/config_server_fixture.h +++ b/src/mongo/dbtests/config_server_fixture.h @@ -36,12 +36,18 @@ namespace mongo { + class OperationContext; + class CustomDirectClient: public DBDirectClient { public: CustomDirectClient() { setWireVersions(minWireVersion, maxWireVersion); } + CustomDirectClient(OperationContext* txn) : DBDirectClient(txn) { + setWireVersions(minWireVersion, maxWireVersion); + } + virtual ConnectionString::ConnectionType type() const { return ConnectionString::CUSTOM; } diff --git a/src/mongo/dbtests/counttests.cpp b/src/mongo/dbtests/counttests.cpp index 8e34074e2aa..f8119b632a1 100644 --- a/src/mongo/dbtests/counttests.cpp +++ b/src/mongo/dbtests/counttests.cpp @@ -42,7 +42,7 @@ namespace CountTests { class Base { public: - Base() : lk(_txn.lockState(), ns()), _context( ns() ) { + Base() : lk(_txn.lockState(), ns()), _context(&_txn, ns()) { _database = _context.db(); _collection = _database->getCollection( &_txn, ns() ); if ( _collection ) { diff --git a/src/mongo/dbtests/dbhelper_tests.cpp b/src/mongo/dbtests/dbhelper_tests.cpp index e0aeb507e36..88c04aece66 100644 --- a/src/mongo/dbtests/dbhelper_tests.cpp +++ b/src/mongo/dbtests/dbhelper_tests.cpp @@ -61,7 +61,7 @@ namespace mongo { { // Remove _id range [_min, _max). Lock::DBWrite lk(txn.lockState(), ns); - Client::Context ctx( ns ); + Client::Context ctx(&txn, ns ); KeyRange range( ns, BSON( "_id" << _min ), @@ -115,9 +115,8 @@ namespace mongo { // TEST(DBHelperTests, FindDiskLocs) { - - DBDirectClient client; OperationContextImpl txn; + DBDirectClient client(&txn); // Some unique tag we can use to make sure we're pulling back the right data OID tag = OID::gen(); @@ -170,9 +169,8 @@ namespace mongo { // TEST(DBHelperTests, FindDiskLocsNoIndex) { - - DBDirectClient client; OperationContextImpl txn; + DBDirectClient client(&txn); client.remove( ns, BSONObj() ); client.insert( ns, BSON( "_id" << OID::gen() ) ); @@ -184,7 +182,7 @@ namespace mongo { long long estSizeBytes; { Lock::DBRead lk(txn.lockState(), ns); - Client::Context ctx( ns ); + Client::Context ctx(&txn, ns ); // search invalid index range KeyRange range( ns, @@ -212,9 +210,8 @@ namespace mongo { // TEST(DBHelperTests, FindDiskLocsTooBig) { - - DBDirectClient client; OperationContextImpl txn; + DBDirectClient client(&txn); client.remove( ns, BSONObj() ); @@ -231,7 +228,7 @@ namespace mongo { long long estSizeBytes; { Lock::DBRead lk(txn.lockState(), ns); - Client::Context ctx( ns ); + Client::Context ctx(&txn, ns ); KeyRange range( ns, BSON( "_id" << 0 ), BSON( "_id" << numDocsInserted ), diff --git a/src/mongo/dbtests/directclienttests.cpp b/src/mongo/dbtests/directclienttests.cpp index 0bea6ea2399..9c96dc331fd 100644 --- a/src/mongo/dbtests/directclienttests.cpp +++ b/src/mongo/dbtests/directclienttests.cpp @@ -35,6 +35,7 @@ #include "mongo/db/instance.h" #include "mongo/db/json.h" #include "mongo/db/lasterror.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/dbtests/dbtests.h" #include "mongo/util/timer.h" @@ -52,7 +53,8 @@ namespace DirectClientTests { class Capped : public ClientBase { public: virtual void run() { - DBDirectClient client; + OperationContextImpl txn; + DBDirectClient client(&txn); for( int pass=0; pass < 3; pass++ ) { client.createCollection(ns, 1024 * 1024, true, 999); for( int j =0; j < pass*3; j++ ) @@ -76,7 +78,9 @@ namespace DirectClientTests { class InsertMany : ClientBase { public: virtual void run(){ - DBDirectClient client; + OperationContextImpl txn; + DBDirectClient client(&txn); + vector<BSONObj> objs; objs.push_back(BSON("_id" << 1)); objs.push_back(BSON("_id" << 1)); @@ -99,7 +103,9 @@ namespace DirectClientTests { class BadNSCmd : ClientBase { public: virtual void run(){ - DBDirectClient client; + OperationContextImpl txn; + DBDirectClient client(&txn); + BSONObj result; BSONObj cmdObj = BSON( "count" << "" ); ASSERT_THROWS( client.runCommand( "", cmdObj, result ), UserException ); @@ -109,7 +115,9 @@ namespace DirectClientTests { class BadNSQuery : ClientBase { public: virtual void run(){ - DBDirectClient client; + OperationContextImpl txn; + DBDirectClient client(&txn); + auto_ptr<DBClientCursor> cursor = client.query( "", Query(), 1 ); ASSERT(cursor->more()); BSONObj result = cursor->next().getOwned(); @@ -121,7 +129,9 @@ namespace DirectClientTests { class BadNSGetMore : ClientBase { public: virtual void run(){ - DBDirectClient client; + OperationContextImpl txn; + DBDirectClient client(&txn); + auto_ptr<DBClientCursor> cursor = client.getMore("", 1, 1); ASSERT(cursor->more()); BSONObj result = cursor->next().getOwned(); @@ -133,7 +143,9 @@ namespace DirectClientTests { class BadNSInsert : ClientBase { public: virtual void run(){ - DBDirectClient client; + OperationContextImpl txn; + DBDirectClient client(&txn); + client.insert( "", BSONObj(), 0 ); ASSERT( !client.getLastError().empty() ); } @@ -142,7 +154,9 @@ namespace DirectClientTests { class BadNSUpdate : ClientBase { public: virtual void run(){ - DBDirectClient client; + OperationContextImpl txn; + DBDirectClient client(&txn); + client.update( "", Query(), BSON( "$set" << BSON( "x" << 1 )) ); ASSERT( !client.getLastError().empty() ); } @@ -151,7 +165,9 @@ namespace DirectClientTests { class BadNSRemove : ClientBase { public: virtual void run(){ - DBDirectClient client; + OperationContextImpl txn; + DBDirectClient client(&txn); + client.remove( "", Query() ); ASSERT( !client.getLastError().empty() ); } diff --git a/src/mongo/dbtests/gle_test.cpp b/src/mongo/dbtests/gle_test.cpp index 71b3642e3af..ded97a490e1 100644 --- a/src/mongo/dbtests/gle_test.cpp +++ b/src/mongo/dbtests/gle_test.cpp @@ -26,6 +26,7 @@ * then also delete it in the license file. */ +#include "mongo/db/operation_context_impl.h" #include "mongo/dbtests/dbtests.h" #include "mongo/util/assert_util.h" @@ -43,7 +44,9 @@ namespace { class GetLastErrorCommandFailure { public: void run() { - DBDirectClient client; + OperationContextImpl txn; + DBDirectClient client(&txn); + client.insert(_ns, BSON( "test" << "test")); // Cannot mix fsync + j, will make command fail @@ -58,7 +61,9 @@ namespace { class GetLastErrorClean { public: void run() { - DBDirectClient client; + OperationContextImpl txn; + DBDirectClient client(&txn); + client.insert(_ns, BSON( "test" << "test")); // Make sure there was no error @@ -73,7 +78,9 @@ namespace { class GetLastErrorFromDup { public: void run() { - DBDirectClient client; + OperationContextImpl txn; + DBDirectClient client(&txn); + client.insert(_ns, BSON( "_id" << 1)); // Make sure there was no error diff --git a/src/mongo/dbtests/gridfstest.cpp b/src/mongo/dbtests/gridfstest.cpp index 768db4cc307..14c861ca58e 100644 --- a/src/mongo/dbtests/gridfstest.cpp +++ b/src/mongo/dbtests/gridfstest.cpp @@ -29,6 +29,7 @@ #include "mongo/pch.h" #include "mongo/client/gridfs.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/dbtests/dbtests.h" #include "mongo/util/assert_util.h" @@ -41,7 +42,8 @@ namespace { class SetChunkSizeTest { public: virtual void run() { - DBDirectClient client; + OperationContextImpl txn; + DBDirectClient client(&txn); GridFS grid(client, "gridtest"); grid.setChunkSize( 5 ); diff --git a/src/mongo/dbtests/jstests.cpp b/src/mongo/dbtests/jstests.cpp index 400aceffd40..a5f8ff997b6 100644 --- a/src/mongo/dbtests/jstests.cpp +++ b/src/mongo/dbtests/jstests.cpp @@ -29,18 +29,20 @@ * then also delete it in the license file. */ -#include "mongo/pch.h" +#include "mongo/platform/basic.h" #include <limits> #include "mongo/base/parse_number.h" #include "mongo/db/instance.h" #include "mongo/db/json.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/storage_options.h" #include "mongo/dbtests/dbtests.h" #include "mongo/scripting/engine.h" #include "mongo/util/timer.h" + namespace mongo { bool dbEval(const string& dbName , BSONObj& cmd, BSONObjBuilder& result, string& errmsg); } // namespace mongo @@ -916,6 +918,10 @@ namespace JSTests { } string utf8ObjSpec = "{'_id':'\\u0001\\u007f\\u07ff\\uffff'}"; BSONObj utf8Obj = fromjson( utf8ObjSpec ); + + OperationContextImpl txn; + DBDirectClient client(&txn); + client.insert( ns(), utf8Obj ); client.eval( "unittest", "v = db.jstests.utf8check.findOne(); db.jstests.utf8check.remove( {} ); db.jstests.utf8check.insert( v );" ); check( utf8Obj, client.findOne( ns(), BSONObj() ) ); @@ -927,12 +933,15 @@ namespace JSTests { FAIL( fail.c_str() ); } } + void reset() { + OperationContextImpl txn; + DBDirectClient client(&txn); + client.dropCollection( ns() ); } - static const char *ns() { return "unittest.jstests.utf8check"; } - DBDirectClient client; + static const char *ns() { return "unittest.jstests.utf8check"; } }; class LongUtf8String { @@ -942,15 +951,21 @@ namespace JSTests { void run() { if( !globalScriptEngine->utf8Ok() ) return; + + OperationContextImpl txn; + DBDirectClient client(&txn); + client.eval( "unittest", "db.jstests.longutf8string.save( {_id:'\\uffff\\uffff\\uffff\\uffff'} )" ); } private: void reset() { + OperationContextImpl txn; + DBDirectClient client(&txn); + client.dropCollection( ns() ); } - static const char *ns() { return "unittest.jstests.longutf8string"; } - DBDirectClient client; + static const char *ns() { return "unittest.jstests.longutf8string"; } }; class InvalidUTF8Check { @@ -1021,10 +1036,12 @@ namespace JSTests { public: virtual ~TestRoundTrip() {} void run() { - // Insert in Javascript -> Find using DBDirectClient // Drop the collection + OperationContextImpl txn; + DBDirectClient client(&txn); + client.dropCollection( "unittest.testroundtrip" ); // Insert in Javascript @@ -1080,8 +1097,6 @@ namespace JSTests { virtual string jsonOut() const { return json(); } - - DBDirectClient client; }; class DBRefTest : public TestRoundTrip { @@ -1993,7 +2008,9 @@ namespace JSTests { update.append( "_id" , "invalidstoredjs1" ); update.appendCode( "value" , "function () { db.test.find().forEach(function(obj) { continue; }); }" ); - DBDirectClient client; + OperationContextImpl txn; + DBDirectClient client(&txn); + client.update( "test.system.js" , query.obj() , update.obj() , true /* upsert */ ); scoped_ptr<Scope> s( globalScriptEngine->newScope() ); diff --git a/src/mongo/dbtests/matchertests.cpp b/src/mongo/dbtests/matchertests.cpp index 67bff7ef74b..cee3995395c 100644 --- a/src/mongo/dbtests/matchertests.cpp +++ b/src/mongo/dbtests/matchertests.cpp @@ -41,18 +41,19 @@ namespace MatcherTests { class CollectionBase { public: - CollectionBase() : - _ns( "unittests.matchertests" ) { + CollectionBase() : _ns( "unittests.matchertests" ) { + } + virtual ~CollectionBase() { - client().dropCollection( ns() ); + OperationContextImpl txn; + DBDirectClient client(&txn); + + client.dropCollection(_ns); } + protected: - const char* ns() const { return _ns; } - DBDirectClient &client() { return _client; } - private: const char * const _ns; - DBDirectClient _client; }; template <typename M> diff --git a/src/mongo/dbtests/oplogstarttests.cpp b/src/mongo/dbtests/oplogstarttests.cpp index a0c94493fbc..45015afe883 100644 --- a/src/mongo/dbtests/oplogstarttests.cpp +++ b/src/mongo/dbtests/oplogstarttests.cpp @@ -38,7 +38,8 @@ namespace OplogStartTests { class Base { public: Base() : _lk(_txn.lockState()), - _context(ns()) { + _context(&_txn, ns()), + _client(&_txn) { Collection* c = _context.db()->getCollection(&_txn, ns()); if (!c) { diff --git a/src/mongo/dbtests/pdfiletests.cpp b/src/mongo/dbtests/pdfiletests.cpp index 10d4e01d1fd..d954c801fdd 100644 --- a/src/mongo/dbtests/pdfiletests.cpp +++ b/src/mongo/dbtests/pdfiletests.cpp @@ -48,7 +48,7 @@ namespace PdfileTests { class Base { public: Base() : _lk(_txn.lockState()), - _context(ns()) { + _context(&_txn, ns()) { } diff --git a/src/mongo/dbtests/perf/perftest.cpp b/src/mongo/dbtests/perf/perftest.cpp index 2afa74f68fa..6ae7cf35532 100644 --- a/src/mongo/dbtests/perf/perftest.cpp +++ b/src/mongo/dbtests/perf/perftest.cpp @@ -702,7 +702,7 @@ namespace Plan { lk_.reset( new Lock::GlobalWrite ); } void run() { - Client::Context ctx( ns_ ); + Client::Context ctx(txn, ns_ ); for( int i = 0; i < 10000; ++i ) { scoped_ptr<MultiPlanScanner> s ( MultiPlanScanner::make( ns_.c_str(), BSONObj(), BSON( "a" << 1 ) ) ); @@ -723,7 +723,7 @@ namespace Plan { lk_.reset( new Lock::GlobalWrite ); } void run() { - Client::Context ctx( ns_.c_str() ); + Client::Context ctx(txn, ns_.c_str() ); for( int i = 0; i < 10000; ++i ) { scoped_ptr<MultiPlanScanner> s( MultiPlanScanner::make( ns_.c_str(), BSON( "a" << 1 ), BSONObj() ) ); diff --git a/src/mongo/dbtests/perftests.cpp b/src/mongo/dbtests/perftests.cpp index 74eb31e8f68..3536b8ec07e 100644 --- a/src/mongo/dbtests/perftests.cpp +++ b/src/mongo/dbtests/perftests.cpp @@ -41,6 +41,7 @@ #include <fstream> #include "mongo/db/db.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/storage/mmap_v1/durable_mapped_file.h" #include "mongo/db/storage/mmap_v1/dur_stats.h" #include "mongo/db/instance.h" @@ -71,8 +72,8 @@ namespace PerfTests { class ClientBase { public: // NOTE: Not bothering to backup the old error record. - ClientBase() { - mongo::lastError.reset( new LastError() ); + ClientBase() : _client(&_txn) { + mongo::lastError.reset(new LastError()); } virtual ~ClientBase() { @@ -91,6 +92,7 @@ namespace PerfTests { DBClientBase* client() { return &_client; } private: + OperationContextImpl _txn; DBDirectClient _client; }; @@ -356,7 +358,9 @@ namespace PerfTests { static int z; srand( ++z ^ (unsigned) time(0)); #endif - DBDirectClient c; + OperationContextImpl txn; + DBDirectClient c(&txn); + Client::initThreadIfNotAlready("perftestthr"); const unsigned int Batch = batchSize(); while( 1 ) { diff --git a/src/mongo/dbtests/plan_ranking.cpp b/src/mongo/dbtests/plan_ranking.cpp index 240371f1482..79419bb60fa 100644 --- a/src/mongo/dbtests/plan_ranking.cpp +++ b/src/mongo/dbtests/plan_ranking.cpp @@ -60,7 +60,10 @@ namespace PlanRankingTests { class PlanRankingTestBase { public: - PlanRankingTestBase() : _internalQueryForceIntersectionPlans(internalQueryForceIntersectionPlans) { + PlanRankingTestBase() + : _internalQueryForceIntersectionPlans(internalQueryForceIntersectionPlans), + _client(&_txn) { + Client::WriteContext ctx(&_txn, ns); _client.dropCollection(ns); } @@ -140,12 +143,13 @@ namespace PlanRankingTests { OperationContextImpl _txn; private: - - DBDirectClient _client; - scoped_ptr<MultiPlanStage> _mps; // Holds the value of global "internalQueryForceIntersectionPlans" setParameter flag. // Restored at end of test invocation regardless of test result. bool _internalQueryForceIntersectionPlans; + + scoped_ptr<MultiPlanStage> _mps; + + DBDirectClient _client; }; // static diff --git a/src/mongo/dbtests/profile_test.cpp b/src/mongo/dbtests/profile_test.cpp index b7a58b856d4..15e04854bf2 100644 --- a/src/mongo/dbtests/profile_test.cpp +++ b/src/mongo/dbtests/profile_test.cpp @@ -31,6 +31,7 @@ */ #include "mongo/db/instance.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/unittest/unittest.h" using mongo::BSONObj; @@ -38,7 +39,8 @@ using mongo::DBDirectClient; using std::string; -namespace mongo_test { +namespace mongo { + class Profiler: public mongo::unittest::Test { public: static const string PROFILER_TEST_DB; @@ -48,11 +50,13 @@ namespace mongo_test { protected: void setUp() { BSONObj ret; + + OperationContextImpl txn; + DBDirectClient db(&txn); + db.runCommand(PROFILER_TEST_DB, BSON("dropDatabase" << 1), ret); ASSERT(ret["ok"].trueValue()); } - - DBDirectClient db; }; const string Profiler::PROFILER_TEST_DB = "profilerTestDB"; @@ -64,6 +68,9 @@ namespace mongo_test { // be profiled in a shortened version const string bigStr(16 * (1 << 20) - 200, 'a'); + OperationContextImpl txn; + DBDirectClient db(&txn); + { BSONObj replyObj; db.runCommand(PROFILER_TEST_DB, BSON("profile" << 2), replyObj); @@ -95,7 +102,8 @@ namespace mongo_test { builder.append(fieldName, x); } - DBDirectClient db; + OperationContextImpl txn; + DBDirectClient db(&txn); { BSONObj replyObj; diff --git a/src/mongo/dbtests/query_multi_plan_runner.cpp b/src/mongo/dbtests/query_multi_plan_runner.cpp index 8ca3b5a248c..f47d08ecfe8 100644 --- a/src/mongo/dbtests/query_multi_plan_runner.cpp +++ b/src/mongo/dbtests/query_multi_plan_runner.cpp @@ -57,7 +57,9 @@ namespace QueryMultiPlanRunner { class MultiPlanRunnerBase { public: - MultiPlanRunnerBase() { } + MultiPlanRunnerBase() : _client(&_txn) { + + } virtual ~MultiPlanRunnerBase() { _client.dropCollection(ns()); @@ -82,7 +84,8 @@ namespace QueryMultiPlanRunner { static const char* ns() { return "unittests.QueryStageMultiPlanRunner"; } - private: + protected: + OperationContextImpl _txn; DBDirectClient _client; }; @@ -92,8 +95,7 @@ namespace QueryMultiPlanRunner { class MPRCollectionScanVsHighlySelectiveIXScan : public MultiPlanRunnerBase { public: void run() { - OperationContextImpl txn; - Client::WriteContext ctx(&txn, ns()); + Client::WriteContext ctx(&_txn, ns()); const int N = 5000; for (int i = 0; i < N; ++i) { @@ -106,14 +108,14 @@ namespace QueryMultiPlanRunner { // Every call to work() returns something so this should clearly win (by current scoring // at least). IndexScanParams ixparams; - ixparams.descriptor = getIndex(&txn, ctx.ctx().db(), BSON("foo" << 1)); + ixparams.descriptor = getIndex(&_txn, ctx.ctx().db(), BSON("foo" << 1)); ixparams.bounds.isSimpleRange = true; ixparams.bounds.startKey = BSON("" << 7); ixparams.bounds.endKey = BSON("" << 7); ixparams.bounds.endKeyInclusive = true; ixparams.direction = 1; - const Collection* coll = ctx.ctx().db()->getCollection(&txn, ns()); + const Collection* coll = ctx.ctx().db()->getCollection(&_txn, ns()); auto_ptr<WorkingSet> sharedWs(new WorkingSet()); IndexScan* ix = new IndexScan(ixparams, sharedWs.get(), NULL); @@ -121,7 +123,7 @@ namespace QueryMultiPlanRunner { // Plan 1: CollScan with matcher. CollectionScanParams csparams; - csparams.collection = ctx.ctx().db()->getCollection( &txn, ns() ); + csparams.collection = ctx.ctx().db()->getCollection( &_txn, ns() ); csparams.direction = CollectionScanParams::FORWARD; // Make the filter. @@ -138,7 +140,7 @@ namespace QueryMultiPlanRunner { verify(CanonicalQuery::canonicalize(ns(), BSON("foo" << 7), &cq).isOK()); verify(NULL != cq); - MultiPlanStage* mps = new MultiPlanStage(ctx.ctx().db()->getCollection(&txn, ns()),cq); + MultiPlanStage* mps = new MultiPlanStage(ctx.ctx().db()->getCollection(&_txn, ns()),cq); mps->addPlan(createQuerySolution(), firstRoot.release(), sharedWs.get()); mps->addPlan(createQuerySolution(), secondRoot.release(), sharedWs.get()); @@ -148,7 +150,7 @@ namespace QueryMultiPlanRunner { ASSERT_EQUALS(0, mps->bestPlanIdx()); SingleSolutionRunner sr( - ctx.ctx().db()->getCollection(&txn, ns()), + ctx.ctx().db()->getCollection(&_txn, ns()), cq, mps->bestSolution(), mps, diff --git a/src/mongo/dbtests/query_single_solution_runner.cpp b/src/mongo/dbtests/query_single_solution_runner.cpp index 246cf66df1a..d5290853151 100644 --- a/src/mongo/dbtests/query_single_solution_runner.cpp +++ b/src/mongo/dbtests/query_single_solution_runner.cpp @@ -45,7 +45,9 @@ namespace QuerySingleSolutionRunner { class SingleSolutionRunnerBase { public: - SingleSolutionRunnerBase() { } + SingleSolutionRunnerBase() : _client(&_txn) { + + } virtual ~SingleSolutionRunnerBase() { _client.dropCollection(ns()); diff --git a/src/mongo/dbtests/query_stage_and.cpp b/src/mongo/dbtests/query_stage_and.cpp index ab7ff6a5457..59a5ae3819f 100644 --- a/src/mongo/dbtests/query_stage_and.cpp +++ b/src/mongo/dbtests/query_stage_and.cpp @@ -51,7 +51,9 @@ namespace QueryStageAnd { class QueryStageAndBase { public: - QueryStageAndBase() { } + QueryStageAndBase() : _client(&_txn) { + + } virtual ~QueryStageAndBase() { _client.dropCollection(ns()); diff --git a/src/mongo/dbtests/query_stage_collscan.cpp b/src/mongo/dbtests/query_stage_collscan.cpp index 20fb3ad5b62..647b721f878 100644 --- a/src/mongo/dbtests/query_stage_collscan.cpp +++ b/src/mongo/dbtests/query_stage_collscan.cpp @@ -313,7 +313,7 @@ namespace QueryStageCollectionScan { class QueryStageCollectionScanBase { public: - QueryStageCollectionScanBase() { + QueryStageCollectionScanBase() : _client(&_txn) { Client::WriteContext ctx(&_txn, ns()); for (int i = 0; i < numObj(); ++i) { diff --git a/src/mongo/dbtests/query_stage_count.cpp b/src/mongo/dbtests/query_stage_count.cpp index eaecb772981..04a45d98044 100644 --- a/src/mongo/dbtests/query_stage_count.cpp +++ b/src/mongo/dbtests/query_stage_count.cpp @@ -48,7 +48,9 @@ namespace QueryStageCount { class CountBase { public: - CountBase() { } + CountBase() : _client(&_txn) { + + } virtual ~CountBase() { Client::WriteContext ctx(&_txn, ns()); diff --git a/src/mongo/dbtests/query_stage_distinct.cpp b/src/mongo/dbtests/query_stage_distinct.cpp index c8799f73fcb..942c87b264a 100644 --- a/src/mongo/dbtests/query_stage_distinct.cpp +++ b/src/mongo/dbtests/query_stage_distinct.cpp @@ -46,7 +46,9 @@ namespace QueryStageDistinct { class DistinctBase { public: - DistinctBase() { } + DistinctBase() : _client(&_txn) { + + } virtual ~DistinctBase() { Client::WriteContext ctx(&_txn, ns()); diff --git a/src/mongo/dbtests/query_stage_fetch.cpp b/src/mongo/dbtests/query_stage_fetch.cpp index 3414475baf9..4bea8b9e004 100644 --- a/src/mongo/dbtests/query_stage_fetch.cpp +++ b/src/mongo/dbtests/query_stage_fetch.cpp @@ -48,7 +48,9 @@ namespace QueryStageFetch { class QueryStageFetchBase { public: - QueryStageFetchBase() { } + QueryStageFetchBase() : _client(&_txn) { + + } virtual ~QueryStageFetchBase() { _client.dropCollection(ns()); @@ -75,6 +77,7 @@ namespace QueryStageFetch { static const char* ns() { return "unittests.QueryStageFetch"; } private: + OperationContextImpl _txn; DBDirectClient _client; }; diff --git a/src/mongo/dbtests/query_stage_keep.cpp b/src/mongo/dbtests/query_stage_keep.cpp index 3be756ae2a5..3283b66ab8c 100644 --- a/src/mongo/dbtests/query_stage_keep.cpp +++ b/src/mongo/dbtests/query_stage_keep.cpp @@ -52,7 +52,9 @@ namespace QueryStageKeep { class QueryStageKeepBase { public: - QueryStageKeepBase() { } + QueryStageKeepBase() : _client(&_txn) { + + } virtual ~QueryStageKeepBase() { _client.dropCollection(ns()); @@ -89,7 +91,8 @@ namespace QueryStageKeep { return WorkingSet::INVALID_ID; } - private: + protected: + OperationContextImpl _txn; DBDirectClient _client; }; @@ -102,13 +105,12 @@ namespace QueryStageKeep { class KeepStageBasic : public QueryStageKeepBase { public: void run() { - OperationContextImpl txn; - Client::WriteContext ctx(&txn, ns()); + Client::WriteContext ctx(&_txn, ns()); Database* db = ctx.ctx().db(); - Collection* coll = db->getCollection(&txn, ns()); + Collection* coll = db->getCollection(&_txn, ns()); if (!coll) { - coll = db->createCollection(&txn, ns()); + coll = db->createCollection(&_txn, ns()); } WorkingSet ws; diff --git a/src/mongo/dbtests/query_stage_merge_sort.cpp b/src/mongo/dbtests/query_stage_merge_sort.cpp index ff52f9c6ffc..11161a5c6be 100644 --- a/src/mongo/dbtests/query_stage_merge_sort.cpp +++ b/src/mongo/dbtests/query_stage_merge_sort.cpp @@ -47,7 +47,9 @@ namespace QueryStageMergeSortTests { class QueryStageMergeSortTestBase { public: - QueryStageMergeSortTestBase() { } + QueryStageMergeSortTestBase() : _client(&_txn) { + + } virtual ~QueryStageMergeSortTestBase() { Client::WriteContext ctx(&_txn, ns()); @@ -109,9 +111,8 @@ namespace QueryStageMergeSortTests { public: void run() { Client::WriteContext ctx(&_txn, ns()); - OperationContextImpl txn; Database* db = ctx.ctx().db(); - Collection* coll = db->getCollection(&txn, ns()); + Collection* coll = db->getCollection(&_txn, ns()); if (!coll) { coll = db->createCollection(&_txn, ns()); } @@ -173,9 +174,8 @@ namespace QueryStageMergeSortTests { public: void run() { Client::WriteContext ctx(&_txn, ns()); - OperationContextImpl txn; Database* db = ctx.ctx().db(); - Collection* coll = db->getCollection(&txn, ns()); + Collection* coll = db->getCollection(&_txn, ns()); if (!coll) { coll = db->createCollection(&_txn, ns()); } @@ -236,9 +236,8 @@ namespace QueryStageMergeSortTests { public: void run() { Client::WriteContext ctx(&_txn, ns()); - OperationContextImpl txn; Database* db = ctx.ctx().db(); - Collection* coll = db->getCollection(&txn, ns()); + Collection* coll = db->getCollection(&_txn, ns()); if (!coll) { coll = db->createCollection(&_txn, ns()); } @@ -300,9 +299,8 @@ namespace QueryStageMergeSortTests { public: void run() { Client::WriteContext ctx(&_txn, ns()); - OperationContextImpl txn; Database* db = ctx.ctx().db(); - Collection* coll = db->getCollection(&txn, ns()); + Collection* coll = db->getCollection(&_txn, ns()); if (!coll) { coll = db->createCollection(&_txn, ns()); } @@ -365,9 +363,8 @@ namespace QueryStageMergeSortTests { public: void run() { Client::WriteContext ctx(&_txn, ns()); - OperationContextImpl txn; Database* db = ctx.ctx().db(); - Collection* coll = db->getCollection(&txn, ns()); + Collection* coll = db->getCollection(&_txn, ns()); if (!coll) { coll = db->createCollection(&_txn, ns()); } @@ -428,9 +425,8 @@ namespace QueryStageMergeSortTests { public: void run() { Client::WriteContext ctx(&_txn, ns()); - OperationContextImpl txn; Database* db = ctx.ctx().db(); - Collection* coll = db->getCollection(&txn, ns()); + Collection* coll = db->getCollection(&_txn, ns()); if (!coll) { coll = db->createCollection(&_txn, ns()); } @@ -481,9 +477,8 @@ namespace QueryStageMergeSortTests { public: void run() { Client::WriteContext ctx(&_txn, ns()); - OperationContextImpl txn; Database* db = ctx.ctx().db(); - Collection* coll = db->getCollection(&txn, ns()); + Collection* coll = db->getCollection(&_txn, ns()); if (!coll) { coll = db->createCollection(&_txn, ns()); } diff --git a/src/mongo/dbtests/query_stage_sort.cpp b/src/mongo/dbtests/query_stage_sort.cpp index 1d9b4806db3..6ae66a0b7bb 100644 --- a/src/mongo/dbtests/query_stage_sort.cpp +++ b/src/mongo/dbtests/query_stage_sort.cpp @@ -47,7 +47,9 @@ namespace QueryStageSortTests { class QueryStageSortTestBase { public: - QueryStageSortTestBase() { } + QueryStageSortTestBase() : _client(&_txn) { + + } void fillData() { for (int i = 0; i < numObj(); ++i) { @@ -168,7 +170,9 @@ namespace QueryStageSortTests { static const char* ns() { return "unittests.QueryStageSort"; } - private: + + protected: + OperationContextImpl _txn; DBDirectClient _client; }; @@ -179,13 +183,12 @@ namespace QueryStageSortTests { virtual int numObj() { return 100; } void run() { - OperationContextImpl txn; - Client::WriteContext ctx(&txn, ns()); + Client::WriteContext ctx(&_txn, ns()); Database* db = ctx.ctx().db(); - Collection* coll = db->getCollection(&txn, ns()); + Collection* coll = db->getCollection(&_txn, ns()); if (!coll) { - coll = db->createCollection(&txn, ns()); + coll = db->createCollection(&_txn, ns()); } fillData(); @@ -199,13 +202,12 @@ namespace QueryStageSortTests { virtual int numObj() { return 100; } void run() { - OperationContextImpl txn; - Client::WriteContext ctx(&txn, ns()); + Client::WriteContext ctx(&_txn, ns()); Database* db = ctx.ctx().db(); - Collection* coll = db->getCollection(&txn, ns()); + Collection* coll = db->getCollection(&_txn, ns()); if (!coll) { - coll = db->createCollection(&txn, ns()); + coll = db->createCollection(&_txn, ns()); } fillData(); @@ -228,13 +230,12 @@ namespace QueryStageSortTests { virtual int numObj() { return 10000; } void run() { - OperationContextImpl txn; - Client::WriteContext ctx(&txn, ns()); + Client::WriteContext ctx(&_txn, ns()); Database* db = ctx.ctx().db(); - Collection* coll = db->getCollection(&txn, ns()); + Collection* coll = db->getCollection(&_txn, ns()); if (!coll) { - coll = db->createCollection(&txn, ns()); + coll = db->createCollection(&_txn, ns()); } fillData(); @@ -248,13 +249,12 @@ namespace QueryStageSortTests { virtual int numObj() { return 2000; } void run() { - OperationContextImpl txn; - Client::WriteContext ctx(&txn, ns()); + Client::WriteContext ctx(&_txn, ns()); Database* db = ctx.ctx().db(); - Collection* coll = db->getCollection(&txn, ns()); + Collection* coll = db->getCollection(&_txn, ns()); if (!coll) { - coll = db->createCollection(&txn, ns()); + coll = db->createCollection(&_txn, ns()); } fillData(); @@ -339,13 +339,12 @@ namespace QueryStageSortTests { virtual int numObj() { return 100; } void run() { - OperationContextImpl txn; - Client::WriteContext ctx(&txn, ns()); + Client::WriteContext ctx(&_txn, ns()); Database* db = ctx.ctx().db(); - Collection* coll = db->getCollection(&txn, ns()); + Collection* coll = db->getCollection(&_txn, ns()); if (!coll) { - coll = db->createCollection(&txn, ns()); + coll = db->createCollection(&_txn, ns()); } WorkingSet* ws = new WorkingSet(); diff --git a/src/mongo/dbtests/query_stage_tests.cpp b/src/mongo/dbtests/query_stage_tests.cpp index 23525ca265d..fc5ee43ea50 100644 --- a/src/mongo/dbtests/query_stage_tests.cpp +++ b/src/mongo/dbtests/query_stage_tests.cpp @@ -46,7 +46,7 @@ namespace QueryStageTests { class IndexScanBase { public: - IndexScanBase() { + IndexScanBase() : _client(&_txn) { Client::WriteContext ctx(&_txn, ns()); for (int i = 0; i < numObj(); ++i) { diff --git a/src/mongo/dbtests/querytests.cpp b/src/mongo/dbtests/querytests.cpp index ac70e48555f..ef3d859a260 100644 --- a/src/mongo/dbtests/querytests.cpp +++ b/src/mongo/dbtests/querytests.cpp @@ -65,7 +65,7 @@ namespace QueryTests { public: Base() : _lk(_txn.lockState()), - _context(ns()) { + _context(&_txn, ns()) { _database = _context.db(); _collection = _database->getCollection( &_txn, ns() ); @@ -162,7 +162,7 @@ namespace QueryTests { // We don't normally allow empty objects in the database, but test that we can find // an empty object (one might be allowed inside a reserved namespace at some point). Lock::GlobalWrite lk(_txn.lockState()); - Client::Context ctx( "unittests.querytests" ); + Client::Context ctx(&_txn, "unittests.querytests" ); Database* db = ctx.db(); if ( db->getCollection( &_txn, ns() ) ) { @@ -172,7 +172,7 @@ namespace QueryTests { _collection = db->createCollection( &_txn, ns(), CollectionOptions(), true, false ); ASSERT( _collection ); - DBDirectClient cl; + DBDirectClient cl(&_txn); BSONObj info; bool ok = cl.runCommand( "unittests", BSON( "godinsert" << "querytests" << "obj" << BSONObj() ), info ); ASSERT( ok ); @@ -188,7 +188,7 @@ namespace QueryTests { class ClientBase { public: - ClientBase() { + ClientBase() : _client(&_txn) { mongo::lastError.reset( new LastError() ); } ~ClientBase() { @@ -197,27 +197,23 @@ namespace QueryTests { protected: void insert( const char *ns, BSONObj o ) { - client_.insert( ns, o ); + _client.insert( ns, o ); } void update( const char *ns, BSONObj q, BSONObj o, bool upsert = 0 ) { - client_.update( ns, Query( q ), o, upsert ); + _client.update( ns, Query( q ), o, upsert ); } bool error() { - return !client_.getPrevError().getField( "err" ).isNull(); + return !_client.getPrevError().getField( "err" ).isNull(); } - const DBDirectClient& client() const { return client_; } - DBDirectClient& client() { return client_; } - - DBDirectClient client_; - OperationContextImpl _txn; + DBDirectClient _client; }; class BoundedKey : public ClientBase { public: ~BoundedKey() { - client().dropCollection( "unittests.querytests.BoundedKey" ); + _client.dropCollection( "unittests.querytests.BoundedKey" ); } void run() { const char *ns = "unittests.querytests.BoundedKey"; @@ -225,23 +221,23 @@ namespace QueryTests { BSONObjBuilder a; a.appendMaxKey( "$lt" ); BSONObj limit = a.done(); - ASSERT( !client().findOne( ns, QUERY( "a" << limit ) ).isEmpty() ); - client().ensureIndex( ns, BSON( "a" << 1 ) ); - ASSERT( !client().findOne( ns, QUERY( "a" << limit ).hint( BSON( "a" << 1 ) ) ).isEmpty() ); + ASSERT( !_client.findOne( ns, QUERY( "a" << limit ) ).isEmpty() ); + _client.ensureIndex( ns, BSON( "a" << 1 ) ); + ASSERT( !_client.findOne( ns, QUERY( "a" << limit ).hint( BSON( "a" << 1 ) ) ).isEmpty() ); } }; class GetMore : public ClientBase { public: ~GetMore() { - client().dropCollection( "unittests.querytests.GetMore" ); + _client.dropCollection( "unittests.querytests.GetMore" ); } void run() { const char *ns = "unittests.querytests.GetMore"; insert( ns, BSON( "a" << 1 ) ); insert( ns, BSON( "a" << 2 ) ); insert( ns, BSON( "a" << 3 ) ); - auto_ptr< DBClientCursor > cursor = client().query( ns, BSONObj(), 2 ); + auto_ptr< DBClientCursor > cursor = _client.query( ns, BSONObj(), 2 ); long long cursorId = cursor->getCursorId(); cursor->decouple(); cursor.reset(); @@ -249,7 +245,7 @@ namespace QueryTests { { // Check internal server handoff to getmore. Lock::DBWrite lk(_txn.lockState(), ns); - Client::Context ctx( ns ); + Client::Context ctx(&_txn, ns ); ClientCursorPin clientCursor( ctx.db()->getCollection(&_txn, ns), cursorId ); // pq doesn't exist if it's a runner inside of the clientcursor. // ASSERT( clientCursor.c()->pq ); @@ -257,7 +253,7 @@ namespace QueryTests { ASSERT_EQUALS( 2, clientCursor.c()->pos() ); } - cursor = client().getMore( ns, cursorId ); + cursor = _client.getMore( ns, cursorId ); ASSERT( cursor->more() ); ASSERT_EQUALS( 3, cursor->next().getIntField( "a" ) ); } @@ -274,7 +270,7 @@ namespace QueryTests { public: ~GetMoreKillOp() { getGlobalEnvironment()->unsetKillAllOperations(); - client().dropCollection( "unittests.querytests.GetMoreKillOp" ); + _client.dropCollection( "unittests.querytests.GetMoreKillOp" ); } void run() { @@ -285,7 +281,7 @@ namespace QueryTests { } // Create a cursor on the collection, with a batch size of 200. - auto_ptr<DBClientCursor> cursor = client().query( ns, "", 0, 0, 0, 0, 200 ); + auto_ptr<DBClientCursor> cursor = _client.query( ns, "", 0, 0, 0, 0, 200 ); CursorId cursorId = cursor->getCursorId(); // Count 500 results, spanning a few batches of documents. @@ -313,7 +309,7 @@ namespace QueryTests { ASSERT_FALSE(CollectionCursorCache::eraseCursorGlobal(&_txn, cursorId)); // Check that a subsequent get more fails with the cursor removed. - ASSERT_THROWS( client().getMore( ns, cursorId ), UserException ); + ASSERT_THROWS( _client.getMore( ns, cursorId ), UserException ); } }; @@ -326,7 +322,7 @@ namespace QueryTests { public: ~GetMoreInvalidRequest() { getGlobalEnvironment()->unsetKillAllOperations(); - client().dropCollection( "unittests.querytests.GetMoreInvalidRequest" ); + _client.dropCollection( "unittests.querytests.GetMoreInvalidRequest" ); } void run() { @@ -337,7 +333,7 @@ namespace QueryTests { } // Create a cursor on the collection, with a batch size of 200. - auto_ptr<DBClientCursor> cursor = client().query( ns, "", 0, 0, 0, 0, 200 ); + auto_ptr<DBClientCursor> cursor = _client.query( ns, "", 0, 0, 0, 0, 200 ); CursorId cursorId = cursor->getCursorId(); // Count 500 results, spanning a few batches of documents. @@ -350,7 +346,7 @@ namespace QueryTests { // Send a get more with a namespace that is incorrect ('spoofed') for this cursor id. // This is the invalaid get more request described in the comment preceding this class. - client().getMore + _client.getMore ( "unittests.querytests.GetMoreInvalidRequest_WRONG_NAMESPACE_FOR_CURSOR", cursor->getCursorId() ); @@ -375,38 +371,38 @@ namespace QueryTests { const char* ns; PositiveLimit() : ns("unittests.querytests.PositiveLimit") {} ~PositiveLimit() { - client().dropCollection( ns ); + _client.dropCollection( ns ); } void testLimit(int limit) { - ASSERT_EQUALS(client().query( ns, BSONObj(), limit )->itcount(), limit); + ASSERT_EQUALS(_client.query( ns, BSONObj(), limit )->itcount(), limit); } void run() { for(int i=0; i<1000; i++) insert( ns, BSON( GENOID << "i" << i ) ); - ASSERT_EQUALS( client().query(ns, BSONObj(), 1 )->itcount(), 1); - ASSERT_EQUALS( client().query(ns, BSONObj(), 10 )->itcount(), 10); - ASSERT_EQUALS( client().query(ns, BSONObj(), 101 )->itcount(), 101); - ASSERT_EQUALS( client().query(ns, BSONObj(), 999 )->itcount(), 999); - ASSERT_EQUALS( client().query(ns, BSONObj(), 1000 )->itcount(), 1000); - ASSERT_EQUALS( client().query(ns, BSONObj(), 1001 )->itcount(), 1000); - ASSERT_EQUALS( client().query(ns, BSONObj(), 0 )->itcount(), 1000); + ASSERT_EQUALS( _client.query(ns, BSONObj(), 1 )->itcount(), 1); + ASSERT_EQUALS( _client.query(ns, BSONObj(), 10 )->itcount(), 10); + ASSERT_EQUALS( _client.query(ns, BSONObj(), 101 )->itcount(), 101); + ASSERT_EQUALS( _client.query(ns, BSONObj(), 999 )->itcount(), 999); + ASSERT_EQUALS( _client.query(ns, BSONObj(), 1000 )->itcount(), 1000); + ASSERT_EQUALS( _client.query(ns, BSONObj(), 1001 )->itcount(), 1000); + ASSERT_EQUALS( _client.query(ns, BSONObj(), 0 )->itcount(), 1000); } }; class ReturnOneOfManyAndTail : public ClientBase { public: ~ReturnOneOfManyAndTail() { - client().dropCollection( "unittests.querytests.ReturnOneOfManyAndTail" ); + _client.dropCollection( "unittests.querytests.ReturnOneOfManyAndTail" ); } void run() { const char *ns = "unittests.querytests.ReturnOneOfManyAndTail"; - client().createCollection( ns, 1024, true ); + _client.createCollection( ns, 1024, true ); insert( ns, BSON( "a" << 0 ) ); insert( ns, BSON( "a" << 1 ) ); insert( ns, BSON( "a" << 2 ) ); - auto_ptr< DBClientCursor > c = client().query( ns, QUERY( "a" << GT << 0 ).hint( BSON( "$natural" << 1 ) ), 1, 0, 0, QueryOption_CursorTailable ); + auto_ptr< DBClientCursor > c = _client.query( ns, QUERY( "a" << GT << 0 ).hint( BSON( "$natural" << 1 ) ), 1, 0, 0, QueryOption_CursorTailable ); // If only one result requested, a cursor is not saved. ASSERT_EQUALS( 0, c->getCursorId() ); ASSERT( c->more() ); @@ -417,15 +413,15 @@ namespace QueryTests { class TailNotAtEnd : public ClientBase { public: ~TailNotAtEnd() { - client().dropCollection( "unittests.querytests.TailNotAtEnd" ); + _client.dropCollection( "unittests.querytests.TailNotAtEnd" ); } void run() { const char *ns = "unittests.querytests.TailNotAtEnd"; - client().createCollection( ns, 2047, true ); + _client.createCollection( ns, 2047, true ); insert( ns, BSON( "a" << 0 ) ); insert( ns, BSON( "a" << 1 ) ); insert( ns, BSON( "a" << 2 ) ); - auto_ptr< DBClientCursor > c = client().query( ns, Query().hint( BSON( "$natural" << 1 ) ), 2, 0, 0, QueryOption_CursorTailable ); + auto_ptr< DBClientCursor > c = _client.query( ns, Query().hint( BSON( "$natural" << 1 ) ), 2, 0, 0, QueryOption_CursorTailable ); ASSERT( 0 != c->getCursorId() ); while( c->more() ) c->next(); @@ -442,16 +438,16 @@ namespace QueryTests { class EmptyTail : public ClientBase { public: ~EmptyTail() { - client().dropCollection( "unittests.querytests.EmptyTail" ); + _client.dropCollection( "unittests.querytests.EmptyTail" ); } void run() { const char *ns = "unittests.querytests.EmptyTail"; - client().createCollection( ns, 1900, true ); - auto_ptr< DBClientCursor > c = client().query( ns, Query().hint( BSON( "$natural" << 1 ) ), 2, 0, 0, QueryOption_CursorTailable ); + _client.createCollection( ns, 1900, true ); + auto_ptr< DBClientCursor > c = _client.query( ns, Query().hint( BSON( "$natural" << 1 ) ), 2, 0, 0, QueryOption_CursorTailable ); ASSERT_EQUALS( 0, c->getCursorId() ); ASSERT( c->isDead() ); insert( ns, BSON( "a" << 0 ) ); - c = client().query( ns, QUERY( "a" << 1 ).hint( BSON( "$natural" << 1 ) ), 2, 0, 0, QueryOption_CursorTailable ); + c = _client.query( ns, QUERY( "a" << 1 ).hint( BSON( "$natural" << 1 ) ), 2, 0, 0, QueryOption_CursorTailable ); ASSERT( 0 != c->getCursorId() ); ASSERT( !c->isDead() ); } @@ -460,14 +456,14 @@ namespace QueryTests { class TailableDelete : public ClientBase { public: ~TailableDelete() { - client().dropCollection( "unittests.querytests.TailableDelete" ); + _client.dropCollection( "unittests.querytests.TailableDelete" ); } void run() { const char *ns = "unittests.querytests.TailableDelete"; - client().createCollection( ns, 8192, true, 2 ); + _client.createCollection( ns, 8192, true, 2 ); insert( ns, BSON( "a" << 0 ) ); insert( ns, BSON( "a" << 1 ) ); - auto_ptr< DBClientCursor > c = client().query( ns, Query().hint( BSON( "$natural" << 1 ) ), 2, 0, 0, QueryOption_CursorTailable ); + auto_ptr< DBClientCursor > c = _client.query( ns, Query().hint( BSON( "$natural" << 1 ) ), 2, 0, 0, QueryOption_CursorTailable ); c->next(); c->next(); ASSERT( !c->more() ); @@ -492,19 +488,19 @@ namespace QueryTests { class TailableInsertDelete : public ClientBase { public: ~TailableInsertDelete() { - client().dropCollection( "unittests.querytests.TailableInsertDelete" ); + _client.dropCollection( "unittests.querytests.TailableInsertDelete" ); } void run() { const char *ns = "unittests.querytests.TailableInsertDelete"; - client().createCollection( ns, 1330, true ); + _client.createCollection( ns, 1330, true ); insert( ns, BSON( "a" << 0 ) ); insert( ns, BSON( "a" << 1 ) ); - auto_ptr< DBClientCursor > c = client().query( ns, Query().hint( BSON( "$natural" << 1 ) ), 2, 0, 0, QueryOption_CursorTailable ); + auto_ptr< DBClientCursor > c = _client.query( ns, Query().hint( BSON( "$natural" << 1 ) ), 2, 0, 0, QueryOption_CursorTailable ); c->next(); c->next(); ASSERT( !c->more() ); insert( ns, BSON( "a" << 2 ) ); - client().remove( ns, QUERY( "a" << 1 ) ); + _client.remove( ns, QUERY( "a" << 1 ) ); ASSERT( c->more() ); ASSERT_EQUALS( 2, c->next().getIntField( "a" ) ); ASSERT( !c->more() ); @@ -514,21 +510,21 @@ namespace QueryTests { class TailCappedOnly : public ClientBase { public: ~TailCappedOnly() { - client().dropCollection( "unittest.querytests.TailCappedOnly" ); + _client.dropCollection( "unittest.querytests.TailCappedOnly" ); } void run() { const char *ns = "unittests.querytests.TailCappedOnly"; - client().insert( ns, BSONObj() ); - auto_ptr< DBClientCursor > c = client().query( ns, BSONObj(), 0, 0, 0, QueryOption_CursorTailable ); + _client.insert( ns, BSONObj() ); + auto_ptr< DBClientCursor > c = _client.query( ns, BSONObj(), 0, 0, 0, QueryOption_CursorTailable ); ASSERT( c->isDead() ); - ASSERT( !client().getLastError().empty() ); + ASSERT( !_client.getLastError().empty() ); } }; class TailableQueryOnId : public ClientBase { public: ~TailableQueryOnId() { - client().dropCollection( "unittests.querytests.TailableQueryOnId" ); + _client.dropCollection( "unittests.querytests.TailableQueryOnId" ); } void insertA(const char* ns, int a) { @@ -542,13 +538,13 @@ namespace QueryTests { void run() { const char *ns = "unittests.querytests.TailableQueryOnId"; BSONObj info; - client().runCommand( "unittests", BSON( "create" << "querytests.TailableQueryOnId" << "capped" << true << "size" << 8192 << "autoIndexId" << true ), info ); + _client.runCommand( "unittests", BSON( "create" << "querytests.TailableQueryOnId" << "capped" << true << "size" << 8192 << "autoIndexId" << true ), info ); insertA( ns, 0 ); insertA( ns, 1 ); - auto_ptr< DBClientCursor > c1 = client().query( ns, QUERY( "a" << GT << -1 ), 0, 0, 0, QueryOption_CursorTailable ); + auto_ptr< DBClientCursor > c1 = _client.query( ns, QUERY( "a" << GT << -1 ), 0, 0, 0, QueryOption_CursorTailable ); OID id; id.init("000000000000000000000000"); - auto_ptr< DBClientCursor > c2 = client().query( ns, QUERY( "value" << GT << id ), 0, 0, 0, QueryOption_CursorTailable ); + auto_ptr< DBClientCursor > c2 = _client.query( ns, QUERY( "value" << GT << id ), 0, 0, 0, QueryOption_CursorTailable ); c1->next(); c1->next(); ASSERT( !c1->more() ); @@ -569,20 +565,20 @@ namespace QueryTests { class OplogReplayMode : public ClientBase { public: ~OplogReplayMode() { - client().dropCollection( "unittests.querytests.OplogReplayMode" ); + _client.dropCollection( "unittests.querytests.OplogReplayMode" ); } void run() { const char *ns = "unittests.querytests.OplogReplayMode"; insert( ns, BSON( "ts" << 0 ) ); insert( ns, BSON( "ts" << 1 ) ); insert( ns, BSON( "ts" << 2 ) ); - auto_ptr< DBClientCursor > c = client().query( ns, QUERY( "ts" << GT << 1 ).hint( BSON( "$natural" << 1 ) ), 0, 0, 0, QueryOption_OplogReplay ); + auto_ptr< DBClientCursor > c = _client.query( ns, QUERY( "ts" << GT << 1 ).hint( BSON( "$natural" << 1 ) ), 0, 0, 0, QueryOption_OplogReplay ); ASSERT( c->more() ); ASSERT_EQUALS( 2, c->next().getIntField( "ts" ) ); ASSERT( !c->more() ); insert( ns, BSON( "ts" << 3 ) ); - c = client().query( ns, QUERY( "ts" << GT << 1 ).hint( BSON( "$natural" << 1 ) ), 0, 0, 0, QueryOption_OplogReplay ); + c = _client.query( ns, QUERY( "ts" << GT << 1 ).hint( BSON( "$natural" << 1 ) ), 0, 0, 0, QueryOption_OplogReplay ); ASSERT( c->more() ); ASSERT_EQUALS( 2, c->next().getIntField( "ts" ) ); ASSERT( c->more() ); @@ -592,15 +588,15 @@ namespace QueryTests { class OplogReplaySlaveReadTill : public ClientBase { public: ~OplogReplaySlaveReadTill() { - client().dropCollection( "unittests.querytests.OplogReplaySlaveReadTill" ); + _client.dropCollection( "unittests.querytests.OplogReplaySlaveReadTill" ); } void run() { const char *ns = "unittests.querytests.OplogReplaySlaveReadTill"; Lock::DBWrite lk(_txn.lockState(), ns); - Client::Context ctx( ns ); + Client::Context ctx(&_txn, ns ); BSONObj info; - client().runCommand( "unittests", + _client.runCommand( "unittests", BSON( "create" << "querytests.OplogReplaySlaveReadTill" << "capped" << true << "size" << 8192 ), info ); @@ -612,7 +608,7 @@ namespace QueryTests { insert( ns, BSON( "ts" << two ) ); insert( ns, BSON( "ts" << three ) ); auto_ptr<DBClientCursor> c = - client().query( ns, QUERY( "ts" << GTE << two ).hint( BSON( "$natural" << 1 ) ), + _client.query( ns, QUERY( "ts" << GTE << two ).hint( BSON( "$natural" << 1 ) ), 0, 0, 0, QueryOption_OplogReplay | QueryOption_CursorTailable ); ASSERT( c->more() ); ASSERT_EQUALS( two, c->next()["ts"].Date() ); @@ -626,14 +622,14 @@ namespace QueryTests { class OplogReplayExplain : public ClientBase { public: ~OplogReplayExplain() { - client().dropCollection( "unittests.querytests.OplogReplayExplain" ); + _client.dropCollection( "unittests.querytests.OplogReplayExplain" ); } void run() { const char *ns = "unittests.querytests.OplogReplayExplain"; insert( ns, BSON( "ts" << 0 ) ); insert( ns, BSON( "ts" << 1 ) ); insert( ns, BSON( "ts" << 2 ) ); - auto_ptr< DBClientCursor > c = client().query( + auto_ptr< DBClientCursor > c = _client.query( ns, QUERY( "ts" << GT << 1 ).hint( BSON( "$natural" << 1 ) ).explain(), 0, 0, 0, QueryOption_OplogReplay ); ASSERT( c->more() ); @@ -651,11 +647,11 @@ namespace QueryTests { class BasicCount : public ClientBase { public: ~BasicCount() { - client().dropCollection( "unittests.querytests.BasicCount" ); + _client.dropCollection( "unittests.querytests.BasicCount" ); } void run() { const char *ns = "unittests.querytests.BasicCount"; - client().ensureIndex( ns, BSON( "a" << 1 ) ); + _client.ensureIndex( ns, BSON( "a" << 1 ) ); count( 0 ); insert( ns, BSON( "a" << 3 ) ); count( 0 ); @@ -668,20 +664,20 @@ namespace QueryTests { } private: void count( unsigned long long c ) { - ASSERT_EQUALS( c, client().count( "unittests.querytests.BasicCount", BSON( "a" << 4 ) ) ); + ASSERT_EQUALS( c, _client.count( "unittests.querytests.BasicCount", BSON( "a" << 4 ) ) ); } }; class ArrayId : public ClientBase { public: ~ArrayId() { - client().dropCollection( "unittests.querytests.ArrayId" ); + _client.dropCollection( "unittests.querytests.ArrayId" ); } void run() { const char *ns = "unittests.querytests.ArrayId"; - client().ensureIndex( ns, BSON( "_id" << 1 ) ); + _client.ensureIndex( ns, BSON( "_id" << 1 ) ); ASSERT( !error() ); - client().insert( ns, fromjson( "{'_id':[1,2]}" ) ); + _client.insert( ns, fromjson( "{'_id':[1,2]}" ) ); ASSERT( error() ); } }; @@ -689,14 +685,14 @@ namespace QueryTests { class UnderscoreNs : public ClientBase { public: ~UnderscoreNs() { - client().dropCollection( "unittests.querytests._UnderscoreNs" ); + _client.dropCollection( "unittests.querytests._UnderscoreNs" ); } void run() { ASSERT( !error() ); const char *ns = "unittests.querytests._UnderscoreNs"; - ASSERT( client().findOne( ns, "{}" ).isEmpty() ); - client().insert( ns, BSON( "a" << 1 ) ); - ASSERT_EQUALS( 1, client().findOne( ns, "{}" ).getIntField( "a" ) ); + ASSERT( _client.findOne( ns, "{}" ).isEmpty() ); + _client.insert( ns, BSON( "a" << 1 ) ); + ASSERT_EQUALS( 1, _client.findOne( ns, "{}" ).getIntField( "a" ) ); ASSERT( !error() ); } }; @@ -704,84 +700,84 @@ namespace QueryTests { class EmptyFieldSpec : public ClientBase { public: ~EmptyFieldSpec() { - client().dropCollection( "unittests.querytests.EmptyFieldSpec" ); + _client.dropCollection( "unittests.querytests.EmptyFieldSpec" ); } void run() { const char *ns = "unittests.querytests.EmptyFieldSpec"; - client().insert( ns, BSON( "a" << 1 ) ); - ASSERT( !client().findOne( ns, "" ).isEmpty() ); + _client.insert( ns, BSON( "a" << 1 ) ); + ASSERT( !_client.findOne( ns, "" ).isEmpty() ); BSONObj empty; - ASSERT( !client().findOne( ns, "", &empty ).isEmpty() ); + ASSERT( !_client.findOne( ns, "", &empty ).isEmpty() ); } }; class MultiNe : public ClientBase { public: ~MultiNe() { - client().dropCollection( "unittests.querytests.Ne" ); + _client.dropCollection( "unittests.querytests.Ne" ); } void run() { const char *ns = "unittests.querytests.Ne"; - client().insert( ns, fromjson( "{a:[1,2]}" ) ); - ASSERT( client().findOne( ns, fromjson( "{a:{$ne:1}}" ) ).isEmpty() ); + _client.insert( ns, fromjson( "{a:[1,2]}" ) ); + ASSERT( _client.findOne( ns, fromjson( "{a:{$ne:1}}" ) ).isEmpty() ); BSONObj spec = fromjson( "{a:{$ne:1,$ne:2}}" ); - ASSERT( client().findOne( ns, spec ).isEmpty() ); + ASSERT( _client.findOne( ns, spec ).isEmpty() ); } }; class EmbeddedNe : public ClientBase { public: ~EmbeddedNe() { - client().dropCollection( "unittests.querytests.NestedNe" ); + _client.dropCollection( "unittests.querytests.NestedNe" ); } void run() { const char *ns = "unittests.querytests.NestedNe"; - client().insert( ns, fromjson( "{a:[{b:1},{b:2}]}" ) ); - ASSERT( client().findOne( ns, fromjson( "{'a.b':{$ne:1}}" ) ).isEmpty() ); + _client.insert( ns, fromjson( "{a:[{b:1},{b:2}]}" ) ); + ASSERT( _client.findOne( ns, fromjson( "{'a.b':{$ne:1}}" ) ).isEmpty() ); } }; class EmbeddedNumericTypes : public ClientBase { public: ~EmbeddedNumericTypes() { - client().dropCollection( "unittests.querytests.NumericEmbedded" ); + _client.dropCollection( "unittests.querytests.NumericEmbedded" ); } void run() { const char *ns = "unittests.querytests.NumericEmbedded"; - client().insert( ns, BSON( "a" << BSON ( "b" << 1 ) ) ); - ASSERT( ! client().findOne( ns, BSON( "a" << BSON ( "b" << 1.0 ) ) ).isEmpty() ); - client().ensureIndex( ns , BSON( "a" << 1 ) ); - ASSERT( ! client().findOne( ns, BSON( "a" << BSON ( "b" << 1.0 ) ) ).isEmpty() ); + _client.insert( ns, BSON( "a" << BSON ( "b" << 1 ) ) ); + ASSERT( ! _client.findOne( ns, BSON( "a" << BSON ( "b" << 1.0 ) ) ).isEmpty() ); + _client.ensureIndex( ns , BSON( "a" << 1 ) ); + ASSERT( ! _client.findOne( ns, BSON( "a" << BSON ( "b" << 1.0 ) ) ).isEmpty() ); } }; class AutoResetIndexCache : public ClientBase { public: ~AutoResetIndexCache() { - client().dropCollection( "unittests.querytests.AutoResetIndexCache" ); + _client.dropCollection( "unittests.querytests.AutoResetIndexCache" ); } static const char *ns() { return "unittests.querytests.AutoResetIndexCache"; } static const char *idxNs() { return "unittests.system.indexes"; } - void index() { ASSERT( !client().findOne( idxNs(), BSON( "name" << NE << "_id_" ) ).isEmpty() ); } + void index() { ASSERT( !_client.findOne( idxNs(), BSON( "name" << NE << "_id_" ) ).isEmpty() ); } void noIndex() { - BSONObj o = client().findOne( idxNs(), BSON( "name" << NE << "_id_" ) ); + BSONObj o = _client.findOne( idxNs(), BSON( "name" << NE << "_id_" ) ); if( !o.isEmpty() ) { cout << o.toString() << endl; ASSERT( false ); } } void checkIndex() { - client().ensureIndex( ns(), BSON( "a" << 1 ) ); + _client.ensureIndex( ns(), BSON( "a" << 1 ) ); index(); } void run() { - client().dropDatabase( "unittests" ); + _client.dropDatabase( "unittests" ); noIndex(); checkIndex(); - client().dropCollection( ns() ); + _client.dropCollection( ns() ); noIndex(); checkIndex(); - client().dropDatabase( "unittests" ); + _client.dropDatabase( "unittests" ); noIndex(); checkIndex(); } @@ -790,130 +786,130 @@ namespace QueryTests { class UniqueIndex : public ClientBase { public: ~UniqueIndex() { - client().dropCollection( "unittests.querytests.UniqueIndex" ); + _client.dropCollection( "unittests.querytests.UniqueIndex" ); } void run() { const char *ns = "unittests.querytests.UniqueIndex"; - client().ensureIndex( ns, BSON( "a" << 1 ), true ); - client().insert( ns, BSON( "a" << 4 << "b" << 2 ) ); - client().insert( ns, BSON( "a" << 4 << "b" << 3 ) ); - ASSERT_EQUALS( 1U, client().count( ns, BSONObj() ) ); - client().dropCollection( ns ); - client().ensureIndex( ns, BSON( "b" << 1 ), true ); - client().insert( ns, BSON( "a" << 4 << "b" << 2 ) ); - client().insert( ns, BSON( "a" << 4 << "b" << 3 ) ); - ASSERT_EQUALS( 2U, client().count( ns, BSONObj() ) ); + _client.ensureIndex( ns, BSON( "a" << 1 ), true ); + _client.insert( ns, BSON( "a" << 4 << "b" << 2 ) ); + _client.insert( ns, BSON( "a" << 4 << "b" << 3 ) ); + ASSERT_EQUALS( 1U, _client.count( ns, BSONObj() ) ); + _client.dropCollection( ns ); + _client.ensureIndex( ns, BSON( "b" << 1 ), true ); + _client.insert( ns, BSON( "a" << 4 << "b" << 2 ) ); + _client.insert( ns, BSON( "a" << 4 << "b" << 3 ) ); + ASSERT_EQUALS( 2U, _client.count( ns, BSONObj() ) ); } }; class UniqueIndexPreexistingData : public ClientBase { public: ~UniqueIndexPreexistingData() { - client().dropCollection( "unittests.querytests.UniqueIndexPreexistingData" ); + _client.dropCollection( "unittests.querytests.UniqueIndexPreexistingData" ); } void run() { const char *ns = "unittests.querytests.UniqueIndexPreexistingData"; - client().insert( ns, BSON( "a" << 4 << "b" << 2 ) ); - client().insert( ns, BSON( "a" << 4 << "b" << 3 ) ); - client().ensureIndex( ns, BSON( "a" << 1 ), true ); - ASSERT_EQUALS( 0U, client().count( "unittests.system.indexes", BSON( "ns" << ns << "name" << NE << "_id_" ) ) ); + _client.insert( ns, BSON( "a" << 4 << "b" << 2 ) ); + _client.insert( ns, BSON( "a" << 4 << "b" << 3 ) ); + _client.ensureIndex( ns, BSON( "a" << 1 ), true ); + ASSERT_EQUALS( 0U, _client.count( "unittests.system.indexes", BSON( "ns" << ns << "name" << NE << "_id_" ) ) ); } }; class SubobjectInArray : public ClientBase { public: ~SubobjectInArray() { - client().dropCollection( "unittests.querytests.SubobjectInArray" ); + _client.dropCollection( "unittests.querytests.SubobjectInArray" ); } void run() { const char *ns = "unittests.querytests.SubobjectInArray"; - client().insert( ns, fromjson( "{a:[{b:{c:1}}]}" ) ); - ASSERT( !client().findOne( ns, BSON( "a.b.c" << 1 ) ).isEmpty() ); - ASSERT( !client().findOne( ns, fromjson( "{'a.c':null}" ) ).isEmpty() ); + _client.insert( ns, fromjson( "{a:[{b:{c:1}}]}" ) ); + ASSERT( !_client.findOne( ns, BSON( "a.b.c" << 1 ) ).isEmpty() ); + ASSERT( !_client.findOne( ns, fromjson( "{'a.c':null}" ) ).isEmpty() ); } }; class Size : public ClientBase { public: ~Size() { - client().dropCollection( "unittests.querytests.Size" ); + _client.dropCollection( "unittests.querytests.Size" ); } void run() { const char *ns = "unittests.querytests.Size"; - client().insert( ns, fromjson( "{a:[1,2,3]}" ) ); - client().ensureIndex( ns, BSON( "a" << 1 ) ); - ASSERT( client().query( ns, QUERY( "a" << mongo::BSIZE << 3 ).hint( BSON( "a" << 1 ) ) )->more() ); + _client.insert( ns, fromjson( "{a:[1,2,3]}" ) ); + _client.ensureIndex( ns, BSON( "a" << 1 ) ); + ASSERT( _client.query( ns, QUERY( "a" << mongo::BSIZE << 3 ).hint( BSON( "a" << 1 ) ) )->more() ); } }; class FullArray : public ClientBase { public: ~FullArray() { - client().dropCollection( "unittests.querytests.IndexedArray" ); + _client.dropCollection( "unittests.querytests.IndexedArray" ); } void run() { const char *ns = "unittests.querytests.IndexedArray"; - client().insert( ns, fromjson( "{a:[1,2,3]}" ) ); - ASSERT( client().query( ns, Query( "{a:[1,2,3]}" ) )->more() ); - client().ensureIndex( ns, BSON( "a" << 1 ) ); - ASSERT( client().query( ns, Query( "{a:{$in:[1,[1,2,3]]}}" ).hint( BSON( "a" << 1 ) ) )->more() ); - ASSERT( client().query( ns, Query( "{a:[1,2,3]}" ).hint( BSON( "a" << 1 ) ) )->more() ); // SERVER-146 + _client.insert( ns, fromjson( "{a:[1,2,3]}" ) ); + ASSERT( _client.query( ns, Query( "{a:[1,2,3]}" ) )->more() ); + _client.ensureIndex( ns, BSON( "a" << 1 ) ); + ASSERT( _client.query( ns, Query( "{a:{$in:[1,[1,2,3]]}}" ).hint( BSON( "a" << 1 ) ) )->more() ); + ASSERT( _client.query( ns, Query( "{a:[1,2,3]}" ).hint( BSON( "a" << 1 ) ) )->more() ); // SERVER-146 } }; class InsideArray : public ClientBase { public: ~InsideArray() { - client().dropCollection( "unittests.querytests.InsideArray" ); + _client.dropCollection( "unittests.querytests.InsideArray" ); } void run() { const char *ns = "unittests.querytests.InsideArray"; - client().insert( ns, fromjson( "{a:[[1],2]}" ) ); + _client.insert( ns, fromjson( "{a:[[1],2]}" ) ); check( "$natural" ); - client().ensureIndex( ns, BSON( "a" << 1 ) ); + _client.ensureIndex( ns, BSON( "a" << 1 ) ); check( "a" ); // SERVER-146 } private: void check( const string &hintField ) { const char *ns = "unittests.querytests.InsideArray"; - ASSERT( client().query( ns, Query( "{a:[[1],2]}" ).hint( BSON( hintField << 1 ) ) )->more() ); - ASSERT( client().query( ns, Query( "{a:[1]}" ).hint( BSON( hintField << 1 ) ) )->more() ); - ASSERT( client().query( ns, Query( "{a:2}" ).hint( BSON( hintField << 1 ) ) )->more() ); - ASSERT( !client().query( ns, Query( "{a:1}" ).hint( BSON( hintField << 1 ) ) )->more() ); + ASSERT( _client.query( ns, Query( "{a:[[1],2]}" ).hint( BSON( hintField << 1 ) ) )->more() ); + ASSERT( _client.query( ns, Query( "{a:[1]}" ).hint( BSON( hintField << 1 ) ) )->more() ); + ASSERT( _client.query( ns, Query( "{a:2}" ).hint( BSON( hintField << 1 ) ) )->more() ); + ASSERT( !_client.query( ns, Query( "{a:1}" ).hint( BSON( hintField << 1 ) ) )->more() ); } }; class IndexInsideArrayCorrect : public ClientBase { public: ~IndexInsideArrayCorrect() { - client().dropCollection( "unittests.querytests.IndexInsideArrayCorrect" ); + _client.dropCollection( "unittests.querytests.IndexInsideArrayCorrect" ); } void run() { const char *ns = "unittests.querytests.IndexInsideArrayCorrect"; - client().insert( ns, fromjson( "{'_id':1,a:[1]}" ) ); - client().insert( ns, fromjson( "{'_id':2,a:[[1]]}" ) ); - client().ensureIndex( ns, BSON( "a" << 1 ) ); - ASSERT_EQUALS( 1, client().query( ns, Query( "{a:[1]}" ).hint( BSON( "a" << 1 ) ) )->next().getIntField( "_id" ) ); + _client.insert( ns, fromjson( "{'_id':1,a:[1]}" ) ); + _client.insert( ns, fromjson( "{'_id':2,a:[[1]]}" ) ); + _client.ensureIndex( ns, BSON( "a" << 1 ) ); + ASSERT_EQUALS( 1, _client.query( ns, Query( "{a:[1]}" ).hint( BSON( "a" << 1 ) ) )->next().getIntField( "_id" ) ); } }; class SubobjArr : public ClientBase { public: ~SubobjArr() { - client().dropCollection( "unittests.querytests.SubobjArr" ); + _client.dropCollection( "unittests.querytests.SubobjArr" ); } void run() { const char *ns = "unittests.querytests.SubobjArr"; - client().insert( ns, fromjson( "{a:[{b:[1]}]}" ) ); + _client.insert( ns, fromjson( "{a:[{b:[1]}]}" ) ); check( "$natural" ); - client().ensureIndex( ns, BSON( "a" << 1 ) ); + _client.ensureIndex( ns, BSON( "a" << 1 ) ); check( "a" ); } private: void check( const string &hintField ) { const char *ns = "unittests.querytests.SubobjArr"; - ASSERT( client().query( ns, Query( "{'a.b':1}" ).hint( BSON( hintField << 1 ) ) )->more() ); - ASSERT( client().query( ns, Query( "{'a.b':[1]}" ).hint( BSON( hintField << 1 ) ) )->more() ); + ASSERT( _client.query( ns, Query( "{'a.b':1}" ).hint( BSON( hintField << 1 ) ) )->more() ); + ASSERT( _client.query( ns, Query( "{'a.b':[1]}" ).hint( BSON( hintField << 1 ) ) )->more() ); } }; @@ -921,16 +917,16 @@ namespace QueryTests { public: MinMax() : ns( "unittests.querytests.MinMax" ) {} ~MinMax() { - client().dropCollection( "unittests.querytests.MinMax" ); + _client.dropCollection( "unittests.querytests.MinMax" ); } void run() { - client().ensureIndex( ns, BSON( "a" << 1 << "b" << 1 ) ); - client().insert( ns, BSON( "a" << 1 << "b" << 1 ) ); - client().insert( ns, BSON( "a" << 1 << "b" << 2 ) ); - client().insert( ns, BSON( "a" << 2 << "b" << 1 ) ); - client().insert( ns, BSON( "a" << 2 << "b" << 2 ) ); + _client.ensureIndex( ns, BSON( "a" << 1 << "b" << 1 ) ); + _client.insert( ns, BSON( "a" << 1 << "b" << 1 ) ); + _client.insert( ns, BSON( "a" << 1 << "b" << 2 ) ); + _client.insert( ns, BSON( "a" << 2 << "b" << 1 ) ); + _client.insert( ns, BSON( "a" << 2 << "b" << 2 ) ); - ASSERT_EQUALS( 4, count( client().query( ns, BSONObj() ) ) ); + ASSERT_EQUALS( 4, count( _client.query( ns, BSONObj() ) ) ); BSONObj hints[] = { BSONObj(), BSON( "a" << 1 << "b" << 1 ) }; for( int i = 0; i < 2; ++i ) { check( 0, 0, 3, 3, 4, hints[ i ] ); @@ -954,7 +950,7 @@ namespace QueryTests { q = q.minKey( BSON( "a" << minA << "b" << minB ) ).maxKey( BSON( "a" << maxA << "b" << maxB ) ); if ( !hint.isEmpty() ) q.hint( hint ); - return client().query( ns, q ); + return _client.query( ns, q ); } void check( int minA, int minB, int maxA, int maxB, int expectedCount, const BSONObj &hint = empty_ ) { ASSERT_EQUALS( expectedCount, count( query( minA, minB, maxA, maxB, hint ) ) ); @@ -976,15 +972,15 @@ namespace QueryTests { public: MatchCodeCodeWScope() : _ns( "unittests.querytests.MatchCodeCodeWScope" ) {} ~MatchCodeCodeWScope() { - client().dropCollection( "unittests.querytests.MatchCodeCodeWScope" ); + _client.dropCollection( "unittests.querytests.MatchCodeCodeWScope" ); } void run() { checkMatch(); - client().ensureIndex( _ns, BSON( "a" << 1 ) ); + _client.ensureIndex( _ns, BSON( "a" << 1 ) ); checkMatch(); // Use explain queries to check index bounds. { - BSONObj explain = client().findOne( _ns, QUERY( "a" << BSON( "$type" << (int)Code ) ).explain() ); + BSONObj explain = _client.findOne( _ns, QUERY( "a" << BSON( "$type" << (int)Code ) ).explain() ); BSONObjBuilder lower; lower.appendCode( "", "" ); BSONObjBuilder upper; @@ -993,7 +989,7 @@ namespace QueryTests { ASSERT( upper.done().firstElement().valuesEqual( explain[ "indexBounds" ].Obj()[ "a" ].Array()[ 0 ].Array()[ 1 ] ) ); } { - BSONObj explain = client().findOne( _ns, QUERY( "a" << BSON( "$type" << (int)CodeWScope ) ).explain() ); + BSONObj explain = _client.findOne( _ns, QUERY( "a" << BSON( "$type" << (int)CodeWScope ) ).explain() ); BSONObjBuilder lower; lower.appendCodeWScope( "", "", BSONObj() ); // This upper bound may change if a new bson type is added. @@ -1005,16 +1001,16 @@ namespace QueryTests { } private: void checkMatch() { - client().remove( _ns, BSONObj() ); + _client.remove( _ns, BSONObj() ); - client().insert( _ns, code() ); - client().insert( _ns, codeWScope() ); + _client.insert( _ns, code() ); + _client.insert( _ns, codeWScope() ); - ASSERT_EQUALS( 1U, client().count( _ns, code() ) ); - ASSERT_EQUALS( 1U, client().count( _ns, codeWScope() ) ); + ASSERT_EQUALS( 1U, _client.count( _ns, code() ) ); + ASSERT_EQUALS( 1U, _client.count( _ns, codeWScope() ) ); - ASSERT_EQUALS( 1U, client().count( _ns, BSON( "a" << BSON( "$type" << (int)Code ) ) ) ); - ASSERT_EQUALS( 1U, client().count( _ns, BSON( "a" << BSON( "$type" << (int)CodeWScope ) ) ) ); + ASSERT_EQUALS( 1U, _client.count( _ns, BSON( "a" << BSON( "$type" << (int)Code ) ) ) ); + ASSERT_EQUALS( 1U, _client.count( _ns, BSON( "a" << BSON( "$type" << (int)CodeWScope ) ) ) ); } BSONObj code() const { BSONObjBuilder codeBuilder; @@ -1033,19 +1029,19 @@ namespace QueryTests { public: MatchDBRefType() : _ns( "unittests.querytests.MatchDBRefType" ) {} ~MatchDBRefType() { - client().dropCollection( "unittests.querytests.MatchDBRefType" ); + _client.dropCollection( "unittests.querytests.MatchDBRefType" ); } void run() { checkMatch(); - client().ensureIndex( _ns, BSON( "a" << 1 ) ); + _client.ensureIndex( _ns, BSON( "a" << 1 ) ); checkMatch(); } private: void checkMatch() { - client().remove( _ns, BSONObj() ); - client().insert( _ns, dbref() ); - ASSERT_EQUALS( 1U, client().count( _ns, dbref() ) ); - ASSERT_EQUALS( 1U, client().count( _ns, BSON( "a" << BSON( "$type" << (int)DBRef ) ) ) ); + _client.remove( _ns, BSONObj() ); + _client.insert( _ns, dbref() ); + ASSERT_EQUALS( 1U, _client.count( _ns, dbref() ) ); + ASSERT_EQUALS( 1U, _client.count( _ns, BSON( "a" << BSON( "$type" << (int)DBRef ) ) ) ); } BSONObj dbref() const { BSONObjBuilder b; @@ -1060,8 +1056,8 @@ namespace QueryTests { public: void run() { Lock::GlobalWrite lk(_txn.lockState()); - Client::Context ctx( "unittests.DirectLocking" ); - client().remove( "a.b", BSONObj() ); + Client::Context ctx(&_txn, "unittests.DirectLocking"); + _client.remove( "a.b", BSONObj() ); ASSERT_EQUALS( "unittests", ctx.db()->name() ); } const char *ns; @@ -1070,39 +1066,39 @@ namespace QueryTests { class FastCountIn : public ClientBase { public: ~FastCountIn() { - client().dropCollection( "unittests.querytests.FastCountIn" ); + _client.dropCollection( "unittests.querytests.FastCountIn" ); } void run() { const char *ns = "unittests.querytests.FastCountIn"; - client().insert( ns, BSON( "i" << "a" ) ); - client().ensureIndex( ns, BSON( "i" << 1 ) ); - ASSERT_EQUALS( 1U, client().count( ns, fromjson( "{i:{$in:['a']}}" ) ) ); + _client.insert( ns, BSON( "i" << "a" ) ); + _client.ensureIndex( ns, BSON( "i" << 1 ) ); + ASSERT_EQUALS( 1U, _client.count( ns, fromjson( "{i:{$in:['a']}}" ) ) ); } }; class EmbeddedArray : public ClientBase { public: ~EmbeddedArray() { - client().dropCollection( "unittests.querytests.EmbeddedArray" ); + _client.dropCollection( "unittests.querytests.EmbeddedArray" ); } void run() { const char *ns = "unittests.querytests.EmbeddedArray"; - client().insert( ns, fromjson( "{foo:{bar:['spam']}}" ) ); - client().insert( ns, fromjson( "{foo:{bar:['spam','eggs']}}" ) ); - client().insert( ns, fromjson( "{bar:['spam']}" ) ); - client().insert( ns, fromjson( "{bar:['spam','eggs']}" ) ); - ASSERT_EQUALS( 2U, client().count( ns, BSON( "bar" << "spam" ) ) ); - ASSERT_EQUALS( 2U, client().count( ns, BSON( "foo.bar" << "spam" ) ) ); + _client.insert( ns, fromjson( "{foo:{bar:['spam']}}" ) ); + _client.insert( ns, fromjson( "{foo:{bar:['spam','eggs']}}" ) ); + _client.insert( ns, fromjson( "{bar:['spam']}" ) ); + _client.insert( ns, fromjson( "{bar:['spam','eggs']}" ) ); + ASSERT_EQUALS( 2U, _client.count( ns, BSON( "bar" << "spam" ) ) ); + ASSERT_EQUALS( 2U, _client.count( ns, BSON( "foo.bar" << "spam" ) ) ); } }; class DifferentNumbers : public ClientBase { public: ~DifferentNumbers() { - client().dropCollection( "unittests.querytests.DifferentNumbers" ); + _client.dropCollection( "unittests.querytests.DifferentNumbers" ); } void t( const char * ns ) { - auto_ptr< DBClientCursor > cursor = client().query( ns, Query().sort( "7" ) ); + auto_ptr< DBClientCursor > cursor = _client.query( ns, Query().sort( "7" ) ); while ( cursor->more() ) { BSONObj o = cursor->next(); verify( o.valid() ); @@ -1112,15 +1108,15 @@ namespace QueryTests { } void run() { const char *ns = "unittests.querytests.DifferentNumbers"; - { BSONObjBuilder b; b.append( "7" , (int)4 ); client().insert( ns , b.obj() ); } - { BSONObjBuilder b; b.append( "7" , (long long)2 ); client().insert( ns , b.obj() ); } - { BSONObjBuilder b; b.appendNull( "7" ); client().insert( ns , b.obj() ); } - { BSONObjBuilder b; b.append( "7" , "b" ); client().insert( ns , b.obj() ); } - { BSONObjBuilder b; b.appendNull( "8" ); client().insert( ns , b.obj() ); } - { BSONObjBuilder b; b.append( "7" , (double)3.7 ); client().insert( ns , b.obj() ); } + { BSONObjBuilder b; b.append( "7" , (int)4 ); _client.insert( ns , b.obj() ); } + { BSONObjBuilder b; b.append( "7" , (long long)2 ); _client.insert( ns , b.obj() ); } + { BSONObjBuilder b; b.appendNull( "7" ); _client.insert( ns , b.obj() ); } + { BSONObjBuilder b; b.append( "7" , "b" ); _client.insert( ns , b.obj() ); } + { BSONObjBuilder b; b.appendNull( "8" ); _client.insert( ns , b.obj() ); } + { BSONObjBuilder b; b.append( "7" , (double)3.7 ); _client.insert( ns , b.obj() ); } t(ns); - client().ensureIndex( ns , BSON( "7" << 1 ) ); + _client.ensureIndex( ns , BSON( "7" << 1 ) ); t(ns); } }; @@ -1131,15 +1127,15 @@ namespace QueryTests { CollectionBase( string leaf ) { _ns = "unittests.querytests."; _ns += leaf; - client().dropCollection( ns() ); + _client.dropCollection( ns() ); } virtual ~CollectionBase() { - client().dropCollection( ns() ); + _client.dropCollection( ns() ); } int count() { - return (int) client().count( ns() ); + return (int) _client.count( ns() ); } size_t numCursorsOpen() { @@ -1163,16 +1159,16 @@ namespace QueryTests { SymbolStringSame() : CollectionBase( "symbolstringsame" ) {} void run() { - { BSONObjBuilder b; b.appendSymbol( "x" , "eliot" ); b.append( "z" , 17 ); client().insert( ns() , b.obj() ); } - ASSERT_EQUALS( 17 , client().findOne( ns() , BSONObj() )["z"].number() ); + { BSONObjBuilder b; b.appendSymbol( "x" , "eliot" ); b.append( "z" , 17 ); _client.insert( ns() , b.obj() ); } + ASSERT_EQUALS( 17 , _client.findOne( ns() , BSONObj() )["z"].number() ); { BSONObjBuilder b; b.appendSymbol( "x" , "eliot" ); - ASSERT_EQUALS( 17 , client().findOne( ns() , b.obj() )["z"].number() ); + ASSERT_EQUALS( 17 , _client.findOne( ns() , b.obj() )["z"].number() ); } - ASSERT_EQUALS( 17 , client().findOne( ns() , BSON( "x" << "eliot" ) )["z"].number() ); - client().ensureIndex( ns() , BSON( "x" << 1 ) ); - ASSERT_EQUALS( 17 , client().findOne( ns() , BSON( "x" << "eliot" ) )["z"].number() ); + ASSERT_EQUALS( 17 , _client.findOne( ns() , BSON( "x" << "eliot" ) )["z"].number() ); + _client.ensureIndex( ns() , BSON( "x" << 1 ) ); + ASSERT_EQUALS( 17 , _client.findOne( ns() , BSON( "x" << "eliot" ) )["z"].number() ); } }; @@ -1180,7 +1176,7 @@ namespace QueryTests { public: TailableCappedRaceCondition() : CollectionBase( "tailablecappedrace" ) { - client().dropCollection( ns() ); + _client.dropCollection( ns() ); _n = 0; } void run() { @@ -1197,7 +1193,7 @@ namespace QueryTests { int a = count(); - auto_ptr< DBClientCursor > c = client().query( ns() , QUERY( "i" << GT << 0 ).hint( BSON( "$natural" << 1 ) ), 0, 0, 0, QueryOption_CursorTailable ); + auto_ptr< DBClientCursor > c = _client.query( ns() , QUERY( "i" << GT << 0 ).hint( BSON( "$natural" << 1 ) ), 0, 0, 0, QueryOption_CursorTailable ); int n=0; while ( c->more() ) { BSONObj z = c->next(); @@ -1291,7 +1287,7 @@ namespace QueryTests { insert( ns() , BSON( "_id" << i << "x" << i * 2 ) ); } for ( int i=0; i<1000; i+=2 ) { - client_.remove( ns() , BSON( "_id" << i ) ); + _client.remove( ns() , BSON( "_id" << i ) ); } BSONObj res; @@ -1325,18 +1321,18 @@ namespace QueryTests { void run() { BSONObj info; - ASSERT( client().runCommand( "unittests", BSON( "create" << "querytests.findingstart" << "capped" << true << "$nExtents" << 5 << "autoIndexId" << false ), info ) ); + ASSERT( _client.runCommand( "unittests", BSON( "create" << "querytests.findingstart" << "capped" << true << "$nExtents" << 5 << "autoIndexId" << false ), info ) ); int i = 0; for( int oldCount = -1; count() != oldCount; - oldCount = count(), client().insert( ns(), BSON( "ts" << i++ ) ) ); + oldCount = count(), _client.insert( ns(), BSON( "ts" << i++ ) ) ); for( int k = 0; k < 5; ++k ) { - client().insert( ns(), BSON( "ts" << i++ ) ); - int min = client().query( ns(), Query().sort( BSON( "$natural" << 1 ) ) )->next()[ "ts" ].numberInt(); + _client.insert( ns(), BSON( "ts" << i++ ) ); + int min = _client.query( ns(), Query().sort( BSON( "$natural" << 1 ) ) )->next()[ "ts" ].numberInt(); for( int j = -1; j < i; ++j ) { - auto_ptr< DBClientCursor > c = client().query( ns(), QUERY( "ts" << GTE << j ), 0, 0, 0, QueryOption_OplogReplay ); + auto_ptr< DBClientCursor > c = _client.query( ns(), QUERY( "ts" << GTE << j ), 0, 0, 0, QueryOption_OplogReplay ); ASSERT( c->more() ); BSONObj next = c->next(); ASSERT( !next[ "ts" ].eoo() ); @@ -1356,16 +1352,16 @@ namespace QueryTests { size_t startNumCursors = numCursorsOpen(); BSONObj info; - ASSERT( client().runCommand( "unittests", BSON( "create" << "querytests.findingstart" << "capped" << true << "$nExtents" << 5 << "autoIndexId" << false ), info ) ); + ASSERT( _client.runCommand( "unittests", BSON( "create" << "querytests.findingstart" << "capped" << true << "$nExtents" << 5 << "autoIndexId" << false ), info ) ); int i = 0; - for( ; i < 150; client().insert( ns(), BSON( "ts" << i++ ) ) ); + for( ; i < 150; _client.insert( ns(), BSON( "ts" << i++ ) ) ); for( int k = 0; k < 5; ++k ) { - client().insert( ns(), BSON( "ts" << i++ ) ); - int min = client().query( ns(), Query().sort( BSON( "$natural" << 1 ) ) )->next()[ "ts" ].numberInt(); + _client.insert( ns(), BSON( "ts" << i++ ) ); + int min = _client.query( ns(), Query().sort( BSON( "$natural" << 1 ) ) )->next()[ "ts" ].numberInt(); for( int j = -1; j < i; ++j ) { - auto_ptr< DBClientCursor > c = client().query( ns(), QUERY( "ts" << GTE << j ), 0, 0, 0, QueryOption_OplogReplay ); + auto_ptr< DBClientCursor > c = _client.query( ns(), QUERY( "ts" << GTE << j ), 0, 0, 0, QueryOption_OplogReplay ); ASSERT( c->more() ); BSONObj next = c->next(); ASSERT( !next[ "ts" ].eoo() ); @@ -1389,19 +1385,19 @@ namespace QueryTests { size_t startNumCursors = numCursorsOpen(); // Check OplogReplay mode with missing collection. - auto_ptr< DBClientCursor > c0 = client().query( ns(), QUERY( "ts" << GTE << 50 ), 0, 0, 0, QueryOption_OplogReplay ); + auto_ptr< DBClientCursor > c0 = _client.query( ns(), QUERY( "ts" << GTE << 50 ), 0, 0, 0, QueryOption_OplogReplay ); ASSERT( !c0->more() ); BSONObj info; - ASSERT( client().runCommand( "unittests", BSON( "create" << "querytests.findingstart" << "capped" << true << "$nExtents" << 5 << "autoIndexId" << false ), info ) ); + ASSERT( _client.runCommand( "unittests", BSON( "create" << "querytests.findingstart" << "capped" << true << "$nExtents" << 5 << "autoIndexId" << false ), info ) ); // Check OplogReplay mode with empty collection. - auto_ptr< DBClientCursor > c = client().query( ns(), QUERY( "ts" << GTE << 50 ), 0, 0, 0, QueryOption_OplogReplay ); + auto_ptr< DBClientCursor > c = _client.query( ns(), QUERY( "ts" << GTE << 50 ), 0, 0, 0, QueryOption_OplogReplay ); ASSERT( !c->more() ); // Check with some docs in the collection. - for( int i = 100; i < 150; client().insert( ns(), BSON( "ts" << i++ ) ) ); - c = client().query( ns(), QUERY( "ts" << GTE << 50 ), 0, 0, 0, QueryOption_OplogReplay ); + for( int i = 100; i < 150; _client.insert( ns(), BSON( "ts" << i++ ) ) ); + c = _client.query( ns(), QUERY( "ts" << GTE << 50 ), 0, 0, 0, QueryOption_OplogReplay ); ASSERT( c->more() ); ASSERT_EQUALS( 100, c->next()[ "ts" ].numberInt() ); @@ -1415,7 +1411,7 @@ namespace QueryTests { WhatsMyUri() : CollectionBase( "whatsmyuri" ) {} void run() { BSONObj result; - client().runCommand( "admin", BSON( "whatsmyuri" << 1 ), result ); + _client.runCommand( "admin", BSON( "whatsmyuri" << 1 ), result ); ASSERT_EQUALS( unknownAddress.toString(), result[ "you" ].str() ); } }; @@ -1425,7 +1421,8 @@ namespace QueryTests { CollectionInternalBase( const char *nsLeaf ) : CollectionBase( nsLeaf ), _lk(_txn.lockState(), ns() ), - _ctx( ns() ) { + _ctx(&_txn, ns()) { + } private: Lock::DBWrite _lk; @@ -1437,10 +1434,10 @@ namespace QueryTests { Exhaust() : CollectionInternalBase( "exhaust" ) {} void run() { BSONObj info; - ASSERT( client().runCommand( "unittests", + ASSERT( _client.runCommand( "unittests", BSON( "create" << "querytests.exhaust" << "capped" << true << "size" << 8192 ), info ) ); - client().insert( ns(), BSON( "ts" << 0 ) ); + _client.insert( ns(), BSON( "ts" << 0 ) ); Message message; assembleRequest( ns(), BSON( "ts" << GTE << 0 ), 0, 0, 0, QueryOption_OplogReplay | QueryOption_CursorTailable | @@ -1462,7 +1459,7 @@ namespace QueryTests { for( int i = 0; i < 150; ++i ) { insert( ns(), BSONObj() ); } - auto_ptr<DBClientCursor> c = client().query( ns(), Query() ); + auto_ptr<DBClientCursor> c = _client.query( ns(), Query() ); ASSERT( c->more() ); long long cursorId = c->getCursorId(); @@ -1485,7 +1482,7 @@ namespace QueryTests { for( int i = 0; i < 5; ++i ) { insert( ns(), BSONObj() ); } - auto_ptr<DBClientCursor> c = client().query( ns(), Query(), 5 ); + auto_ptr<DBClientCursor> c = _client.query( ns(), Query(), 5 ); ASSERT( c->more() ); // With five results and a batch size of 5, no cursor is created. ASSERT_EQUALS( 0, c->getCursorId() ); @@ -1500,8 +1497,8 @@ namespace QueryTests { KillPinnedCursor() : CollectionBase( "killpinnedcursor" ) { } void run() { - client().insert( ns(), vector<BSONObj>( 3, BSONObj() ) ); - auto_ptr<DBClientCursor> cursor = client().query( ns(), BSONObj(), 0, 0, 0, 0, 2 ); + _client.insert( ns(), vector<BSONObj>( 3, BSONObj() ) ); + auto_ptr<DBClientCursor> cursor = _client.query( ns(), BSONObj(), 0, 0, 0, 0, 2 ); ASSERT_EQUALS( 2, cursor->objsLeftInBatch() ); long long cursorId = cursor->getCursorId(); @@ -1513,7 +1510,7 @@ namespace QueryTests { MsgAssertionException); string expectedAssertion = str::stream() << "Cannot kill active cursor " << cursorId; - ASSERT_EQUALS( expectedAssertion, client().getLastError() ); + ASSERT_EQUALS( expectedAssertion, _client.getLastError() ); } // Verify that the remaining document is read from the cursor. diff --git a/src/mongo/dbtests/replsettests.cpp b/src/mongo/dbtests/replsettests.cpp index 07c57608ea8..0cd3597f34c 100644 --- a/src/mongo/dbtests/replsettests.cpp +++ b/src/mongo/dbtests/replsettests.cpp @@ -128,15 +128,16 @@ namespace ReplSetTests { class Base { - private: - DBDirectClient _client; - protected: static BackgroundSyncTest* _bgsync; static repl::SyncTail* _tailer; + OperationContextImpl _txn; + DBDirectClient _client; + public: - Base() { + Base() : _client(&_txn) { + } ~Base() { @@ -146,48 +147,22 @@ namespace ReplSetTests { return "unittests.repltests"; } - DBDirectClient *client() { return &_client; } - - static void insert( const BSONObj &o, bool god = false ) { - OperationContextImpl txn; - Lock::DBWrite lk(txn.lockState(), ns()); - Client::Context ctx(ns()); - - Database* db = ctx.db(); - Collection* coll = db->getCollection(&txn, ns()); - if (!coll) { - coll = db->createCollection(&txn, ns()); - } - - if (o.hasField("_id")) { - coll->insertDocument(&txn, o, true); - return; - } - - class BSONObjBuilder b; - OID id; - id.init(); - b.appendOID("_id", &id); - b.appendElements(o); - coll->insertDocument(&txn, b.obj(), true); - } - BSONObj findOne( const BSONObj &query = BSONObj() ) { - return client()->findOne( ns(), query ); + return _client.findOne( ns(), query ); } void drop() { - OperationContextImpl txn; - Client::WriteContext c(&txn, ns()); + Client::WriteContext c(&_txn, ns()); Database* db = c.ctx().db(); - if ( db->getCollection( &txn, ns() ) == NULL ) { + if ( db->getCollection( &_txn, ns() ) == NULL ) { return; } - db->dropCollection(&txn, ns()); + db->dropCollection(&_txn, ns()); } + static void setup() { replSettings.replSet = "foo"; replSettings.oplogSize = 5 * 1024 * 1024; @@ -206,6 +181,29 @@ namespace ReplSetTests { delete repl::theReplSet; repl::theReplSet = rst; } + + static void insert(OperationContext* txn, const BSONObj &o, bool god = false) { + Lock::DBWrite lk(txn->lockState(), ns()); + Client::Context ctx(txn, ns()); + + Database* db = ctx.db(); + Collection* coll = db->getCollection(txn, ns()); + if (!coll) { + coll = db->createCollection(txn, ns()); + } + + if (o.hasField("_id")) { + coll->insertDocument(txn, o, true); + return; + } + + class BSONObjBuilder b; + OID id; + id.init(); + b.appendOID("_id", &id); + b.appendElements(o); + coll->insertDocument(txn, b.obj(), true); + } }; BackgroundSyncTest* Base::_bgsync = NULL; @@ -274,7 +272,7 @@ namespace ReplSetTests { return true; } - Base::insert(BSON("_id" << 123)); + Base::insert(txn, BSON("_id" << 123)); return true; } }; @@ -309,7 +307,6 @@ namespace ReplSetTests { class CappedInitialSync : public Base { string _cappedNs; - OperationContextImpl _txn; Lock::DBWrite _lk; string spec() const { @@ -317,17 +314,15 @@ namespace ReplSetTests { } void create() { - Client::Context c(_cappedNs); - OperationContextImpl txn; - ASSERT( userCreateNS( &txn, c.db(), _cappedNs, fromjson( spec() ), false ).isOK() ); + Client::Context c(&_txn, _cappedNs); + ASSERT( userCreateNS( &_txn, c.db(), _cappedNs, fromjson( spec() ), false ).isOK() ); } void dropCapped() { - Client::Context c(_cappedNs); - OperationContextImpl txn; + Client::Context c(&_txn, _cappedNs); Database* db = c.db(); - if ( db->getCollection( &txn, _cappedNs ) ) { - db->dropCollection( &txn, _cappedNs ); + if ( db->getCollection( &_txn, _cappedNs ) ) { + db->dropCollection( &_txn, _cappedNs ); } } @@ -345,6 +340,7 @@ namespace ReplSetTests { verify(!apply(o)); return o; } + public: CappedInitialSync() : _cappedNs("unittests.foo.bar"), _lk(_txn.lockState(), _cappedNs) { @@ -361,20 +357,18 @@ namespace ReplSetTests { // returns true on success, false on failure bool apply(const BSONObj& op) { - Client::Context ctx( _cappedNs ); - OperationContextImpl txn; + Client::Context ctx(&_txn, _cappedNs ); // in an annoying twist of api, returns true on failure - return !applyOperation_inlock(&txn, ctx.db(), op, true); + return !applyOperation_inlock(&_txn, ctx.db(), op, true); } void run() { - OperationContextImpl txn; - Lock::DBWrite lk(txn.lockState(), _cappedNs); + Lock::DBWrite lk(_txn.lockState(), _cappedNs); BSONObj op = updateFail(); Sync s(""); - verify(!s.shouldRetry(&txn, op)); + verify(!s.shouldRetry(&_txn, op)); } }; @@ -393,7 +387,7 @@ namespace ReplSetTests { } void insert(OperationContext* txn) { - Client::Context ctx(cappedNs()); + Client::Context ctx(txn, cappedNs()); Database* db = ctx.db(); Collection* coll = db->getCollection(txn, cappedNs()); if (!coll) { @@ -407,21 +401,19 @@ namespace ReplSetTests { public: virtual ~CappedUpdate() {} void run() { - OperationContextImpl txn; - // RARELY shoud be once/128x for (int i=0; i<150; i++) { - insert(&txn); + insert(&_txn); updateSucceed(); } - DBDirectClient client(&txn); + DBDirectClient client(&_txn); int count = (int) client.count(cappedNs(), BSONObj()); verify(count > 1); // check _id index created - Client::Context ctx(cappedNs()); - Collection* collection = ctx.db()->getCollection( &txn, cappedNs() ); + Client::Context ctx(&_txn, cappedNs()); + Collection* collection = ctx.db()->getCollection( &_txn, cappedNs() ); verify(collection->getIndexCatalog()->findIdIndex()); } }; @@ -440,7 +432,6 @@ namespace ReplSetTests { public: virtual ~CappedInsert() {} void run() { - OperationContextImpl txn; // This will succeed, but not insert anything because they are changed to upserts for (int i=0; i<150; i++) { insertSucceed(); @@ -448,8 +439,8 @@ namespace ReplSetTests { // this changed in 2.1.2 // we now have indexes on capped collections - Client::Context ctx(cappedNs()); - Collection* collection = ctx.db()->getCollection( &txn, cappedNs() ); + Client::Context ctx(&_txn, cappedNs()); + Collection* collection = ctx.db()->getCollection( &_txn, cappedNs() ); verify(collection->getIndexCatalog()->findIdIndex()); } }; @@ -541,13 +532,13 @@ namespace ReplSetTests { addInserts(100); applyOplog(); - ASSERT_EQUALS(expected, static_cast<int>(client()->count(ns()))); + ASSERT_EQUALS(expected, static_cast<int>(_client.count(ns()))); drop(); addVersionedInserts(100); applyOplog(); - ASSERT_EQUALS(expected, static_cast<int>(client()->count(ns()))); + ASSERT_EQUALS(expected, static_cast<int>(_client.count(ns()))); drop(); addUpdates(); diff --git a/src/mongo/dbtests/repltests.cpp b/src/mongo/dbtests/repltests.cpp index eb1b45065ad..11338a61225 100644 --- a/src/mongo/dbtests/repltests.cpp +++ b/src/mongo/dbtests/repltests.cpp @@ -65,7 +65,7 @@ namespace ReplTests { public: Base() : _lk(_txn.lockState()), _client(&_txn), - _context(ns()) { + _context(&_txn, ns()) { oldRepl(); replSettings.replSet = ""; @@ -121,7 +121,7 @@ namespace ReplTests { } int count() const { Lock::GlobalWrite lk(_txn.lockState()); - Client::Context ctx( ns() ); + Client::Context ctx(&_txn, ns() ); Database* db = ctx.db(); Collection* coll = db->getCollection( &_txn, ns() ); if ( !coll ) { @@ -140,7 +140,7 @@ namespace ReplTests { static int opCount() { OperationContextImpl txn; Lock::GlobalWrite lk(txn.lockState()); - Client::Context ctx( cllNS() ); + Client::Context ctx(&txn, cllNS() ); Database* db = ctx.db(); Collection* coll = db->getCollection( &txn, cllNS() ); @@ -163,7 +163,7 @@ namespace ReplTests { vector< BSONObj > ops; { - Client::Context ctx( cllNS() ); + Client::Context ctx(&txn, cllNS() ); Database* db = ctx.db(); Collection* coll = db->getCollection( &txn, cllNS() ); @@ -176,7 +176,7 @@ namespace ReplTests { delete it; } { - Client::Context ctx( ns() ); + Client::Context ctx(&txn, ns() ); BSONObjBuilder b; b.append("host", "localhost"); b.appendTimestamp("syncedTo", 0); @@ -192,7 +192,7 @@ namespace ReplTests { static void printAll( const char *ns ) { OperationContextImpl txn; Lock::GlobalWrite lk(txn.lockState()); - Client::Context ctx( ns ); + Client::Context ctx(&txn, ns ); Database* db = ctx.db(); Collection* coll = db->getCollection( &txn, ns ); @@ -213,7 +213,7 @@ namespace ReplTests { static void deleteAll( const char *ns ) { OperationContextImpl txn; Lock::GlobalWrite lk(txn.lockState()); - Client::Context ctx( ns ); + Client::Context ctx(&txn, ns ); Database* db = ctx.db(); Collection* coll = db->getCollection( &txn, ns ); @@ -235,7 +235,7 @@ namespace ReplTests { static void insert( const BSONObj &o ) { OperationContextImpl txn; Lock::GlobalWrite lk(txn.lockState()); - Client::Context ctx( ns() ); + Client::Context ctx(&txn, ns() ); Database* db = ctx.db(); Collection* coll = db->getCollection( &txn, ns() ); diff --git a/src/mongo/dbtests/sharding.cpp b/src/mongo/dbtests/sharding.cpp index d376a8fbaa0..797fb53cbbc 100644 --- a/src/mongo/dbtests/sharding.cpp +++ b/src/mongo/dbtests/sharding.cpp @@ -28,10 +28,11 @@ * then also delete it in the license file. */ -#include "mongo/pch.h" +#include "mongo/platform/basic.h" #include "mongo/client/dbclientmockcursor.h" #include "mongo/client/parallel.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/dbtests/config_server_fixture.h" #include "mongo/dbtests/dbtests.h" #include "mongo/s/chunk_diff.h" @@ -81,10 +82,11 @@ namespace ShardingTests { class ChunkManagerTest : public ConnectionString::ConnectionHook { public: + OperationContextImpl _txn; CustomDirectClient _client; Shard _shard; - ChunkManagerTest() { + ChunkManagerTest() : _client(&_txn) { DBException::traceExceptions = true; @@ -131,7 +133,7 @@ namespace ShardingTests { double socketTimeout ) { // Note - must be new, since it gets owned elsewhere - return new CustomDirectClient(); + return new CustomDirectClient(&_txn); } }; diff --git a/src/mongo/dbtests/threadedtests.cpp b/src/mongo/dbtests/threadedtests.cpp index 998ba2c2bed..0e36df8f43f 100644 --- a/src/mongo/dbtests/threadedtests.cpp +++ b/src/mongo/dbtests/threadedtests.cpp @@ -35,6 +35,7 @@ #include "mongo/bson/util/atomic_int.h" #include "mongo/db/d_concurrency.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/dbtests/dbtests.h" #include "mongo/platform/atomic_word.h" #include "mongo/platform/bits.h" @@ -109,7 +110,9 @@ namespace ThreadedTests { // in _DEBUG builds on linux we mprotect each time a writelock // is taken. That can greatly slow down this test if there are // many open files - DBDirectClient db; + OperationContextImpl txn; + DBDirectClient db(&txn); + db.simpleCommand("admin", NULL, "closeAllDatabases"); } diff --git a/src/mongo/dbtests/updatetests.cpp b/src/mongo/dbtests/updatetests.cpp index e048ebc2d9f..cbdcc346dc8 100644 --- a/src/mongo/dbtests/updatetests.cpp +++ b/src/mongo/dbtests/updatetests.cpp @@ -38,6 +38,7 @@ #include "mongo/db/json.h" #include "mongo/db/lasterror.h" #include "mongo/db/ops/update.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/dbtests/dbtests.h" namespace UpdateTests { @@ -45,27 +46,26 @@ namespace UpdateTests { class ClientBase { public: // NOTE: Not bothering to backup the old error record. - ClientBase() { + ClientBase() : _client(&_txn) { mongo::lastError.reset( new LastError() ); } ~ClientBase() { mongo::lastError.release(); } + protected: void insert( const char *ns, BSONObj o ) { - client_.insert( ns, o ); + _client.insert( ns, o ); } void update( const char *ns, BSONObj q, BSONObj o, bool upsert = 0 ) { - client_.update( ns, Query( q ), o, upsert ); + _client.update( ns, Query( q ), o, upsert ); } bool error() { - return !client_.getPrevError().getField( "err" ).isNull(); + return !_client.getPrevError().getField( "err" ).isNull(); } - DBDirectClient& client() { return client_; } - - private: - DBDirectClient client_; + OperationContextImpl _txn; + DBDirectClient _client; }; class Fail : public ClientBase { @@ -145,7 +145,7 @@ namespace UpdateTests { class SetBase : public ClientBase { public: ~SetBase() { - client().dropCollection( ns() ); + _client.dropCollection( ns() ); } protected: const char *ns() { return "unittests.updatetests.SetBase"; } @@ -154,45 +154,45 @@ namespace UpdateTests { class SetNum : public SetBase { public: void run() { - client().insert( ns(), BSON( "a" << 1 ) ); - client().update( ns(), BSON( "a" << 1 ), BSON( "$set" << BSON( "a" << 4 ) ) ); - ASSERT( !client().findOne( ns(), BSON( "a" << 4 ) ).isEmpty() ); + _client.insert( ns(), BSON( "a" << 1 ) ); + _client.update( ns(), BSON( "a" << 1 ), BSON( "$set" << BSON( "a" << 4 ) ) ); + ASSERT( !_client.findOne( ns(), BSON( "a" << 4 ) ).isEmpty() ); } }; class SetString : public SetBase { public: void run() { - client().insert( ns(), BSON( "a" << "b" ) ); - client().update( ns(), BSON( "a" << "b" ), BSON( "$set" << BSON( "a" << "c" ) ) ); - ASSERT( !client().findOne( ns(), BSON( "a" << "c" ) ).isEmpty() ); + _client.insert( ns(), BSON( "a" << "b" ) ); + _client.update( ns(), BSON( "a" << "b" ), BSON( "$set" << BSON( "a" << "c" ) ) ); + ASSERT( !_client.findOne( ns(), BSON( "a" << "c" ) ).isEmpty() ); } }; class SetStringDifferentLength : public SetBase { public: void run() { - client().insert( ns(), BSON( "a" << "b" ) ); - client().update( ns(), BSON( "a" << "b" ), BSON( "$set" << BSON( "a" << "cd" ) ) ); - ASSERT( !client().findOne( ns(), BSON( "a" << "cd" ) ).isEmpty() ); + _client.insert( ns(), BSON( "a" << "b" ) ); + _client.update( ns(), BSON( "a" << "b" ), BSON( "$set" << BSON( "a" << "cd" ) ) ); + ASSERT( !_client.findOne( ns(), BSON( "a" << "cd" ) ).isEmpty() ); } }; class SetStringToNum : public SetBase { public: void run() { - client().insert( ns(), BSON( "a" << "b" ) ); - client().update( ns(), Query(), BSON( "$set" << BSON( "a" << 5 ) ) ); - ASSERT( !client().findOne( ns(), BSON( "a" << 5 ) ).isEmpty() ); + _client.insert( ns(), BSON( "a" << "b" ) ); + _client.update( ns(), Query(), BSON( "$set" << BSON( "a" << 5 ) ) ); + ASSERT( !_client.findOne( ns(), BSON( "a" << 5 ) ).isEmpty() ); } }; class SetStringToNumInPlace : public SetBase { public: void run() { - client().insert( ns(), BSON( "a" << "bcd" ) ); - client().update( ns(), Query(), BSON( "$set" << BSON( "a" << 5.0 ) ) ); - ASSERT( !client().findOne( ns(), BSON( "a" << 5.0 ) ).isEmpty() ); + _client.insert( ns(), BSON( "a" << "bcd" ) ); + _client.update( ns(), Query(), BSON( "$set" << BSON( "a" << 5.0 ) ) ); + ASSERT( !_client.findOne( ns(), BSON( "a" << 5.0 ) ).isEmpty() ); } }; @@ -200,13 +200,13 @@ namespace UpdateTests { public: void run() { // Try with upsert false first. - client().insert( ns(), BSONObj() /* empty document */); - client().update( ns(), Query(), BSON( "$setOnInsert" << BSON( "a" << 1 ) ), false ); - ASSERT( client().findOne( ns(), BSON( "a" << 1 ) ).isEmpty() ); + _client.insert( ns(), BSONObj() /* empty document */); + _client.update( ns(), Query(), BSON( "$setOnInsert" << BSON( "a" << 1 ) ), false ); + ASSERT( _client.findOne( ns(), BSON( "a" << 1 ) ).isEmpty() ); // Then with upsert true. - client().update( ns(), Query(), BSON( "$setOnInsert" << BSON( "a" << 1 ) ), true ); - ASSERT( client().findOne( ns(), BSON( "a" << 1 ) ).isEmpty() ); + _client.update( ns(), Query(), BSON( "$setOnInsert" << BSON( "a" << 1 ) ), true ); + ASSERT( _client.findOne( ns(), BSON( "a" << 1 ) ).isEmpty() ); } }; @@ -215,12 +215,12 @@ namespace UpdateTests { public: void run() { // Try with upsert false first. - client().update( ns(), Query(), BSON( "$setOnInsert" << BSON( "a" << 1 ) ), false ); - ASSERT( client().findOne( ns(), BSON( "a" << 1 ) ).isEmpty() ); + _client.update( ns(), Query(), BSON( "$setOnInsert" << BSON( "a" << 1 ) ), false ); + ASSERT( _client.findOne( ns(), BSON( "a" << 1 ) ).isEmpty() ); // Then with upsert true. - client().update( ns(), Query(), BSON( "$setOnInsert" << BSON( "a" << 1 ) ), true ); - ASSERT( !client().findOne( ns(), BSON( "a" << 1 ) ).isEmpty() ); + _client.update( ns(), Query(), BSON( "$setOnInsert" << BSON( "a" << 1 ) ), true ); + ASSERT( !_client.findOne( ns(), BSON( "a" << 1 ) ).isEmpty() ); } }; @@ -231,12 +231,12 @@ namespace UpdateTests { Query q("{a:1}"); // Try with upsert false first. - client().update( ns(), q, BSON( "$setOnInsert" << BSON( "b" << 1 ) ), false ); - ASSERT( client().findOne( ns(), BSON( "a" << 1 ) ).isEmpty() ); + _client.update( ns(), q, BSON( "$setOnInsert" << BSON( "b" << 1 ) ), false ); + ASSERT( _client.findOne( ns(), BSON( "a" << 1 ) ).isEmpty() ); // Then with upsert true. - client().update( ns(), q, BSON( "$setOnInsert" << BSON( "b" << 1 ) ), true ); - ASSERT( !client().findOne( ns(), BSON( "a" << 1 << "b" << 1) ).isEmpty() ); + _client.update( ns(), q, BSON( "$setOnInsert" << BSON( "b" << 1 ) ), true ); + ASSERT( !_client.findOne( ns(), BSON( "a" << 1 << "b" << 1) ).isEmpty() ); } }; @@ -247,12 +247,12 @@ namespace UpdateTests { Query q("{a:1}"); // same field that we'll setOnInsert on // Try with upsert false first. - client().update( ns(), q, BSON( "$setOnInsert" << BSON( "a" << 2 ) ), false ); - ASSERT( client().findOne( ns(), BSON( "a" << 1 ) ).isEmpty() ); + _client.update( ns(), q, BSON( "$setOnInsert" << BSON( "a" << 2 ) ), false ); + ASSERT( _client.findOne( ns(), BSON( "a" << 1 ) ).isEmpty() ); // Then with upsert true. - client().update( ns(), q, BSON( "$setOnInsert" << BSON( "a" << 2 ) ), true ); - ASSERT( !client().findOne( ns(), BSON( "a" << 2 ) ).isEmpty() ); + _client.update( ns(), q, BSON( "$setOnInsert" << BSON( "a" << 2 ) ), true ); + ASSERT( !_client.findOne( ns(), BSON( "a" << 2 ) ).isEmpty() ); } }; @@ -261,18 +261,18 @@ namespace UpdateTests { public: void run() { BSONObj res = fromjson("{'_id':0, a:1}"); - client().insert( ns(), res ); - client().update( ns(), Query(), BSON( "$setOnInsert" << BSON( "b" << 1 ) ) ); - ASSERT( client().findOne( ns(), BSON( "a" << 1 ) ).woCompare( res ) == 0 ); + _client.insert( ns(), res ); + _client.update( ns(), Query(), BSON( "$setOnInsert" << BSON( "b" << 1 ) ) ); + ASSERT( _client.findOne( ns(), BSON( "a" << 1 ) ).woCompare( res ) == 0 ); } }; class SetOnInsertExisting : public SetBase { public: void run() { - client().insert( ns(), BSON( "a" << 1 ) ); - client().update( ns(), Query(), BSON( "$setOnInsert" << BSON( "a" << 2 ) ) ); - ASSERT( !client().findOne( ns(), BSON( "a" << 1 ) ).isEmpty() ); + _client.insert( ns(), BSON( "a" << 1 ) ); + _client.update( ns(), Query(), BSON( "$setOnInsert" << BSON( "a" << 2 ) ) ); + ASSERT( !_client.findOne( ns(), BSON( "a" << 1 ) ).isEmpty() ); } }; @@ -280,14 +280,14 @@ namespace UpdateTests { public: void run() { // Try with upsert false first. - client().update( ns(), Query(), BSON( "$set" << BSON( "a" << 1 ) << + _client.update( ns(), Query(), BSON( "$set" << BSON( "a" << 1 ) << "$setOnInsert" << BSON( "b" << 2 ) ), false ); - ASSERT( client().findOne( ns(), BSON( "a" << 1 << "b" << 2 ) ).isEmpty() ); + ASSERT( _client.findOne( ns(), BSON( "a" << 1 << "b" << 2 ) ).isEmpty() ); // Then with upsert true. - client().update( ns(), Query(), BSON( "$set" << BSON( "a" << 1 ) << + _client.update( ns(), Query(), BSON( "$set" << BSON( "a" << 1 ) << "$setOnInsert" << BSON( "b" << 2 ) ), true ); - ASSERT( !client().findOne( ns(), BSON( "a" << 1 << "b" << 2 ) ).isEmpty() ); + ASSERT( !_client.findOne( ns(), BSON( "a" << 1 << "b" << 2 ) ).isEmpty() ); } }; @@ -298,58 +298,58 @@ namespace UpdateTests { // parent unneccesarily. BSONObj initial = fromjson( "{'_id':0}" ); BSONObj final = fromjson( "{'_id':0, d:1}" ); - client().insert( ns(), initial ); - client().update( ns(), initial, BSON( "$setOnInsert" << BSON( "a.b" << 1 ) << + _client.insert( ns(), initial ); + _client.update( ns(), initial, BSON( "$setOnInsert" << BSON( "a.b" << 1 ) << "$set" << BSON( "d" << 1 ) ) ); - ASSERT_EQUALS( client().findOne( ns(), initial ), final ); + ASSERT_EQUALS( _client.findOne( ns(), initial ), final ); } }; class ModDotted : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{a:{b:4}}" ) ); - client().update( ns(), Query(), BSON( "$inc" << BSON( "a.b" << 10 ) ) ); - ASSERT( !client().findOne( ns(), BSON( "a.b" << 14 ) ).isEmpty() ); - client().update( ns(), Query(), BSON( "$set" << BSON( "a.b" << 55 ) ) ); - ASSERT( !client().findOne( ns(), BSON( "a.b" << 55 ) ).isEmpty() ); + _client.insert( ns(), fromjson( "{a:{b:4}}" ) ); + _client.update( ns(), Query(), BSON( "$inc" << BSON( "a.b" << 10 ) ) ); + ASSERT( !_client.findOne( ns(), BSON( "a.b" << 14 ) ).isEmpty() ); + _client.update( ns(), Query(), BSON( "$set" << BSON( "a.b" << 55 ) ) ); + ASSERT( !_client.findOne( ns(), BSON( "a.b" << 55 ) ).isEmpty() ); } }; class SetInPlaceDotted : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{a:{b:'cdef'}}" ) ); - client().update( ns(), Query(), BSON( "$set" << BSON( "a.b" << "llll" ) ) ); - ASSERT( !client().findOne( ns(), BSON( "a.b" << "llll" ) ).isEmpty() ); + _client.insert( ns(), fromjson( "{a:{b:'cdef'}}" ) ); + _client.update( ns(), Query(), BSON( "$set" << BSON( "a.b" << "llll" ) ) ); + ASSERT( !_client.findOne( ns(), BSON( "a.b" << "llll" ) ).isEmpty() ); } }; class SetRecreateDotted : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0,a:{b:'cdef'}}" ) ); - client().update( ns(), Query(), BSON( "$set" << BSON( "a.b" << "lllll" ) ) ); - ASSERT( client().findOne( ns(), BSON( "a.b" << "lllll" ) ).woCompare( fromjson( "{'_id':0,a:{b:'lllll'}}" ) ) == 0 ); + _client.insert( ns(), fromjson( "{'_id':0,a:{b:'cdef'}}" ) ); + _client.update( ns(), Query(), BSON( "$set" << BSON( "a.b" << "lllll" ) ) ); + ASSERT( _client.findOne( ns(), BSON( "a.b" << "lllll" ) ).woCompare( fromjson( "{'_id':0,a:{b:'lllll'}}" ) ) == 0 ); } }; class SetMissingDotted : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0}" ) ); - client().update( ns(), BSONObj(), BSON( "$set" << BSON( "a.b" << "lllll" ) ) ); - ASSERT( client().findOne( ns(), BSON( "a.b" << "lllll" ) ).woCompare( fromjson( "{'_id':0,a:{b:'lllll'}}" ) ) == 0 ); + _client.insert( ns(), fromjson( "{'_id':0}" ) ); + _client.update( ns(), BSONObj(), BSON( "$set" << BSON( "a.b" << "lllll" ) ) ); + ASSERT( _client.findOne( ns(), BSON( "a.b" << "lllll" ) ).woCompare( fromjson( "{'_id':0,a:{b:'lllll'}}" ) ) == 0 ); } }; class SetAdjacentDotted : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0,a:{c:4}}" ) ); - client().update( ns(), Query(), BSON( "$set" << BSON( "a.b" << "lllll" ) ) ); + _client.insert( ns(), fromjson( "{'_id':0,a:{c:4}}" ) ); + _client.update( ns(), Query(), BSON( "$set" << BSON( "a.b" << "lllll" ) ) ); ASSERT_EQUALS( - mutablebson::unordered( client().findOne( ns(), BSON( "a.b" << "lllll" ) ) ), + mutablebson::unordered( _client.findOne( ns(), BSON( "a.b" << "lllll" ) ) ), mutablebson::unordered( fromjson( "{'_id':0,a:{b:'lllll',c:4}}" ) ) ); } }; @@ -357,9 +357,9 @@ namespace UpdateTests { class IncMissing : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0}" ) ); - client().update( ns(), Query(), BSON( "$inc" << BSON( "f" << 3.0 ) ) ); - ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,f:3}" ) ) == 0 ); + _client.insert( ns(), fromjson( "{'_id':0}" ) ); + _client.update( ns(), Query(), BSON( "$inc" << BSON( "f" << 3.0 ) ) ); + ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,f:3}" ) ) == 0 ); } }; @@ -368,7 +368,7 @@ namespace UpdateTests { string s() { stringstream ss; - auto_ptr<DBClientCursor> cc = client().query( ns() , Query().sort( BSON( "_id" << 1 ) ) ); + auto_ptr<DBClientCursor> cc = _client.query( ns() , Query().sort( BSON( "_id" << 1 ) ) ); bool first = true; while ( cc->more() ) { if ( first ) first = false; @@ -381,18 +381,18 @@ namespace UpdateTests { } void run() { - client().insert( ns(), BSON( "_id" << 1 << "x" << 1 ) ); - client().insert( ns(), BSON( "_id" << 2 << "x" << 5 ) ); + _client.insert( ns(), BSON( "_id" << 1 << "x" << 1 ) ); + _client.insert( ns(), BSON( "_id" << 2 << "x" << 5 ) ); ASSERT_EQUALS( "1,5" , s() ); - client().update( ns() , BSON( "_id" << 1 ) , BSON( "$inc" << BSON( "x" << 1 ) ) ); + _client.update( ns() , BSON( "_id" << 1 ) , BSON( "$inc" << BSON( "x" << 1 ) ) ); ASSERT_EQUALS( "2,5" , s() ); - client().update( ns() , BSONObj() , BSON( "$inc" << BSON( "x" << 1 ) ) ); + _client.update( ns() , BSONObj() , BSON( "$inc" << BSON( "x" << 1 ) ) ); ASSERT_EQUALS( "3,5" , s() ); - client().update( ns() , BSONObj() , BSON( "$inc" << BSON( "x" << 1 ) ) , false , true ); + _client.update( ns() , BSONObj() , BSON( "$inc" << BSON( "x" << 1 ) ) , false , true ); ASSERT_EQUALS( "4,6" , s() ); } @@ -401,10 +401,10 @@ namespace UpdateTests { class UnorderedNewSet : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0}" ) ); - client().update( ns(), Query(), BSON( "$set" << BSON( "f.g.h" << 3.0 << "f.g.a" << 2.0 ) ) ); + _client.insert( ns(), fromjson( "{'_id':0}" ) ); + _client.update( ns(), Query(), BSON( "$set" << BSON( "f.g.h" << 3.0 << "f.g.a" << 2.0 ) ) ); ASSERT_EQUALS( - mutablebson::unordered( client().findOne( ns(), Query() ) ), + mutablebson::unordered( _client.findOne( ns(), Query() ) ), mutablebson::unordered( fromjson( "{'_id':0,f:{g:{a:2,h:3}}}" ) ) ); } }; @@ -412,10 +412,10 @@ namespace UpdateTests { class UnorderedNewSetAdjacent : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0}" ) ); - client().update( ns(), BSONObj(), BSON( "$set" << BSON( "f.g.h.b" << 3.0 << "f.g.a.b" << 2.0 ) ) ); + _client.insert( ns(), fromjson( "{'_id':0}" ) ); + _client.update( ns(), BSONObj(), BSON( "$set" << BSON( "f.g.h.b" << 3.0 << "f.g.a.b" << 2.0 ) ) ); ASSERT_EQUALS( - mutablebson::unordered( client().findOne( ns(), Query() ) ), + mutablebson::unordered( _client.findOne( ns(), Query() ) ), mutablebson::unordered( fromjson( "{'_id':0,f:{g:{a:{b:2},h:{b:3}}}}" ) ) ); } }; @@ -423,161 +423,161 @@ namespace UpdateTests { class ArrayEmbeddedSet : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0,z:[4,'b']}" ) ); - client().update( ns(), Query(), BSON( "$set" << BSON( "z.0" << "a" ) ) ); - ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,z:['a','b']}" ) ); + _client.insert( ns(), fromjson( "{'_id':0,z:[4,'b']}" ) ); + _client.update( ns(), Query(), BSON( "$set" << BSON( "z.0" << "a" ) ) ); + ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,z:['a','b']}" ) ); } }; class AttemptEmbedInExistingNum : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0,a:1}" ) ); - client().update( ns(), Query(), BSON( "$set" << BSON( "a.b" << 1 ) ) ); - ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:1}" ) ) == 0 ); + _client.insert( ns(), fromjson( "{'_id':0,a:1}" ) ); + _client.update( ns(), Query(), BSON( "$set" << BSON( "a.b" << 1 ) ) ); + ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:1}" ) ) == 0 ); } }; class AttemptEmbedConflictsWithOtherSet : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0}" ) ); - client().update( ns(), Query(), BSON( "$set" << BSON( "a" << 2 << "a.b" << 1 ) ) ); - ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0}" ) ); + _client.insert( ns(), fromjson( "{'_id':0}" ) ); + _client.update( ns(), Query(), BSON( "$set" << BSON( "a" << 2 << "a.b" << 1 ) ) ); + ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0}" ) ); } }; class ModMasksEmbeddedConflict : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0,a:{b:2}}" ) ); - client().update( ns(), Query(), BSON( "$set" << BSON( "a" << 2 << "a.b" << 1 ) ) ); - ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:2}}" ) ) == 0 ); + _client.insert( ns(), fromjson( "{'_id':0,a:{b:2}}" ) ); + _client.update( ns(), Query(), BSON( "$set" << BSON( "a" << 2 << "a.b" << 1 ) ) ); + ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:2}}" ) ) == 0 ); } }; class ModOverwritesExistingObject : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0,a:{b:2}}" ) ); - client().update( ns(), Query(), BSON( "$set" << BSON( "a" << BSON( "c" << 2 ) ) ) ); - ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{c:2}}" ) ) == 0 ); + _client.insert( ns(), fromjson( "{'_id':0,a:{b:2}}" ) ); + _client.update( ns(), Query(), BSON( "$set" << BSON( "a" << BSON( "c" << 2 ) ) ) ); + ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{c:2}}" ) ) == 0 ); } }; class InvalidEmbeddedSet : public Fail { public: virtual void doIt() { - client().update( ns(), Query(), BSON( "$set" << BSON( "a." << 1 ) ) ); + _client.update( ns(), Query(), BSON( "$set" << BSON( "a." << 1 ) ) ); } }; class UpsertMissingEmbedded : public SetBase { public: void run() { - client().update( ns(), Query(), BSON( "$set" << BSON( "a.b" << 1 ) ), true ); - ASSERT( !client().findOne( ns(), QUERY( "a.b" << 1 ) ).isEmpty() ); + _client.update( ns(), Query(), BSON( "$set" << BSON( "a.b" << 1 ) ), true ); + ASSERT( !_client.findOne( ns(), QUERY( "a.b" << 1 ) ).isEmpty() ); } }; class Push : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0,a:[1]}" ) ); - client().update( ns(), Query(), BSON( "$push" << BSON( "a" << 5 ) ) ); - ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1,5]}" ) ); + _client.insert( ns(), fromjson( "{'_id':0,a:[1]}" ) ); + _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << 5 ) ) ); + ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1,5]}" ) ); } }; class PushInvalidEltType : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0,a:1}" ) ); - client().update( ns(), Query(), BSON( "$push" << BSON( "a" << 5 ) ) ); - ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:1}" ) ) == 0 ); + _client.insert( ns(), fromjson( "{'_id':0,a:1}" ) ); + _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << 5 ) ) ); + ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:1}" ) ) == 0 ); } }; class PushConflictsWithOtherMod : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0,a:[1]}" ) ); - client().update( ns(), Query(), BSON( "$set" << BSON( "a" << 1 ) <<"$push" << BSON( "a" << 5 ) ) ); - ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:[1]}" ) ) == 0 ); + _client.insert( ns(), fromjson( "{'_id':0,a:[1]}" ) ); + _client.update( ns(), Query(), BSON( "$set" << BSON( "a" << 1 ) <<"$push" << BSON( "a" << 5 ) ) ); + ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:[1]}" ) ) == 0 ); } }; class PushFromNothing : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0}" ) ); - client().update( ns(), Query(), BSON( "$push" << BSON( "a" << 5 ) ) ); - ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[5]}" ) ); + _client.insert( ns(), fromjson( "{'_id':0}" ) ); + _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << 5 ) ) ); + ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[5]}" ) ); } }; class PushFromEmpty : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0,a:[]}" ) ); - client().update( ns(), Query(), BSON( "$push" << BSON( "a" << 5 ) ) ); - ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:[5]}" ) ) == 0 ); + _client.insert( ns(), fromjson( "{'_id':0,a:[]}" ) ); + _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << 5 ) ) ); + ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:[5]}" ) ) == 0 ); } }; class PushInsideNothing : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0}" ) ); - client().update( ns(), Query(), BSON( "$push" << BSON( "a.b" << 5 ) ) ); - ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:[5]}}" ) ) == 0 ); + _client.insert( ns(), fromjson( "{'_id':0}" ) ); + _client.update( ns(), Query(), BSON( "$push" << BSON( "a.b" << 5 ) ) ); + ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:[5]}}" ) ) == 0 ); } }; class CantPushInsideOtherMod : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0}" ) ); - client().update( ns(), Query(), BSON( "$set" << BSON( "a" << BSONObj() ) << "$push" << BSON( "a.b" << 5 ) ) ); - ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0}" ) ) == 0 ); + _client.insert( ns(), fromjson( "{'_id':0}" ) ); + _client.update( ns(), Query(), BSON( "$set" << BSON( "a" << BSONObj() ) << "$push" << BSON( "a.b" << 5 ) ) ); + ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0}" ) ) == 0 ); } }; class CantPushTwice : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0,a:[]}" ) ); - client().update( ns(), Query(), BSON( "$push" << BSON( "a" << 4 ) << "$push" << BSON( "a" << 5 ) ) ); - ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:[]}" ) ) == 0 ); + _client.insert( ns(), fromjson( "{'_id':0,a:[]}" ) ); + _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << 4 ) << "$push" << BSON( "a" << 5 ) ) ); + ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:[]}" ) ) == 0 ); } }; class SetEncapsulationConflictsWithExistingType : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0,a:{b:4}}" ) ); - client().update( ns(), Query(), BSON( "$set" << BSON( "a.b.c" << 4.0 ) ) ); - ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:4}}" ) ) == 0 ); + _client.insert( ns(), fromjson( "{'_id':0,a:{b:4}}" ) ); + _client.update( ns(), Query(), BSON( "$set" << BSON( "a.b.c" << 4.0 ) ) ); + ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:4}}" ) ) == 0 ); } }; class CantPushToParent : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0,a:{b:4}}" ) ); - client().update( ns(), Query(), BSON( "$push" << BSON( "a" << 4.0 ) ) ); - ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:4}}" ) ) == 0 ); + _client.insert( ns(), fromjson( "{'_id':0,a:{b:4}}" ) ); + _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << 4.0 ) ) ); + ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:4}}" ) ) == 0 ); } }; class PushEachSimple : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0,a:[1]}" ) ); + _client.insert( ns(), fromjson( "{'_id':0,a:[1]}" ) ); // { $push : { a : { $each : [ 2, 3 ] } } } BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 2 << 3 ) ); - client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) ); - ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1,2,3]}" ) ); + _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) ); + ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1,2,3]}" ) ); } }; @@ -585,11 +585,11 @@ namespace UpdateTests { class PushEachFromEmpty : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0,a:[]}" ) ); + _client.insert( ns(), fromjson( "{'_id':0,a:[]}" ) ); // { $push : { a : { $each : [ 1, 2, 3 ] } } } BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 1 << 2 << 3 ) ); - client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) ); - ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1,2,3]}" ) ); + _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) ); + ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1,2,3]}" ) ); } }; @@ -597,189 +597,189 @@ namespace UpdateTests { class PushSliceBelowFull : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0,a:[1]}" ) ); + _client.insert( ns(), fromjson( "{'_id':0,a:[1]}" ) ); // { $push : { a : { $each : [ 2 ] , $slice : -3 } } } BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 2 ) << "$slice" << -3 ); - client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) ); - ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1,2]}" ) ); + _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) ); + ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1,2]}" ) ); } }; class PushSliceReachedFullExact : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0,a:[1]}" ) ); + _client.insert( ns(), fromjson( "{'_id':0,a:[1]}" ) ); // { $push : { a : { $each : [ 2 ] , $slice : -2 } } } BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 2 ) << "$slice" << -2 ); - client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) ); - ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1,2]}" ) ); + _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) ); + ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1,2]}" ) ); } }; class PushSliceReachedFullWithEach : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0,a:[1]}" ) ); + _client.insert( ns(), fromjson( "{'_id':0,a:[1]}" ) ); // { $push : { a : { $each : [ 2 , 3 ] , $slice : -2 } } } BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 2 << 3 ) << "$slice" << -2 ); - client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) ); - ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[2,3]}" ) ); + _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) ); + ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[2,3]}" ) ); } }; class PushSliceReachedFullWithBoth : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) ); + _client.insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) ); // { $push : { a : { $each : [ 3 ] , $slice : -2 } } } BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 3 ) << "$slice" << -2 ); - client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) ); - ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[2,3]}" ) ); + _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) ); + ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[2,3]}" ) ); } }; class PushSliceToZero : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) ); + _client.insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) ); // { $push : { a : { $each : [ 3 ] , $slice : 0 } } } BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 3 ) << "$slice" << 0 ); - client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) ); - ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[]}" ) ); + _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) ); + ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[]}" ) ); } }; class PushSliceToZeroFromNothing : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0}" ) ); + _client.insert( ns(), fromjson( "{'_id':0}" ) ); // { $push : { a : { $each : [ 3 ] , $slice : 0 } } } BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 3 ) << "$slice" << 0 ); - client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) ); - ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[]}" ) ); + _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) ); + ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[]}" ) ); } }; class PushSliceFromNothing : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0}" ) ); + _client.insert( ns(), fromjson( "{'_id':0}" ) ); // { $push : { a : { $each : [ 1 , 2 ] , $slice : -3 } } } BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 1 << 2 ) << "$slice" << -3 ); - client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) ); - ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1,2]}" ) ); + _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) ); + ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1,2]}" ) ); } }; class PushSliceLongerThanSliceFromNothing : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0}" ) ); + _client.insert( ns(), fromjson( "{'_id':0}" ) ); // { $push : { a : { $each : [ 1 , 2 , 3 ] , $slice : -2 } } } BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 1 << 2 << 3 ) << "$slice" << -2 ); - client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) ); - ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[2,3]}" ) ); + _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) ); + ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[2,3]}" ) ); } }; class PushSliceFromEmpty : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0,a:[]}" ) ); + _client.insert( ns(), fromjson( "{'_id':0,a:[]}" ) ); // { $push : { a : { $each : [ 1 ] , $slice : -3 } } } BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 1 ) << "$slice" << -3 ); - client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) ); - ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1]}" ) ); + _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) ); + ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1]}" ) ); } }; class PushSliceLongerThanSliceFromEmpty : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0,a:[]}" ) ); + _client.insert( ns(), fromjson( "{'_id':0,a:[]}" ) ); // { $push : { a : { $each : [ 1 , 2 , 3 ] , $slice : -2 } } } BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 1 << 2 << 3 ) << "$slice" << -2 ); - client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) ); - ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[2,3]}" ) ); + _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) ); + ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[2,3]}" ) ); } }; class PushSliceTwoFields : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0,a:[1,2],b:[3,4]}" ) ); + _client.insert( ns(), fromjson( "{'_id':0,a:[1,2],b:[3,4]}" ) ); // { $push: { a: { $each: [ 5 ] , $slice : -2 }, { b: $each: [ 6 ] , $slice: -1 } } } BSONObj objA = BSON( "$each" << BSON_ARRAY( 5 ) << "$slice" << -2 ); BSONObj objB = BSON( "$each" << BSON_ARRAY( 6 ) << "$slice" << -1 ); - client().update( ns(), Query(), BSON( "$push" << BSON( "a" << objA << "b" << objB ) ) ); - ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson("{'_id':0,a:[2,5],b:[6]}")); + _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << objA << "b" << objB ) ) ); + ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson("{'_id':0,a:[2,5],b:[6]}")); } }; class PushSliceAndNormal : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0,a:[1,2],b:[3]}" ) ); + _client.insert( ns(), fromjson( "{'_id':0,a:[1,2],b:[3]}" ) ); // { $push : { a : { $each : [ 5 ] , $slice : -2 } , { b : 4 } } BSONObj objA = BSON( "$each" << BSON_ARRAY( 5 ) << "$slice" << -2 ); - client().update( ns(), Query(), BSON("$push" << BSON("a" << objA << "b" << 4))); - ASSERT_EQUALS(client().findOne(ns(), Query()) , fromjson("{'_id':0,a:[2,5],b:[3,4]}")); + _client.update( ns(), Query(), BSON("$push" << BSON("a" << objA << "b" << 4))); + ASSERT_EQUALS(_client.findOne(ns(), Query()) , fromjson("{'_id':0,a:[2,5],b:[3,4]}")); } }; class PushSliceTwoFieldsConflict : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0,a:[1],b:[3]}" ) ); + _client.insert( ns(), fromjson( "{'_id':0,a:[1],b:[3]}" ) ); // { $push: { a: { $each: [ 5 ] , $slice: -2 } , { a: $each: [ 6 ] , $slice: -1 } } } BSONObj objA = BSON( "$each" << BSON_ARRAY( 5 ) << "$slice" << -2 ); BSONObj other = BSON( "$each" << BSON_ARRAY( 6 ) << "$slice" << -1 ); - client().update( ns(), Query(), BSON( "$push" << BSON( "a" << objA << "a" << other ) ) ); - ASSERT(client().findOne( ns(), Query()).woCompare(fromjson("{'_id':0,a:[1],b:[3]}"))==0); + _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << objA << "a" << other ) ) ); + ASSERT(_client.findOne( ns(), Query()).woCompare(fromjson("{'_id':0,a:[1],b:[3]}"))==0); } }; class PushSliceAndNormalConflict : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0,a:[1],b:[3]}" ) ); + _client.insert( ns(), fromjson( "{'_id':0,a:[1],b:[3]}" ) ); // { $push : { a : { $each : [ 5 ] , $slice : -2 } , { a : 4 } } } BSONObj objA = BSON( "$each" << BSON_ARRAY( 5 ) << "$slice" << -2 ); - client().update( ns(), Query(), BSON( "$push" << BSON( "a" << objA << "a" << 4 ) ) ); - ASSERT(client().findOne( ns(), Query()).woCompare(fromjson("{'_id':0,a:[1],b:[3]}"))==0); + _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << objA << "a" << 4 ) ) ); + ASSERT(_client.findOne( ns(), Query()).woCompare(fromjson("{'_id':0,a:[1],b:[3]}"))==0); } }; class PushSliceInvalidEachType : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) ); + _client.insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) ); // { $push : { a : { $each : 3 , $slice : -2 } } } BSONObj pushObj = BSON( "$each" << 3 << "$slice" << -2 ); - client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) ); - ASSERT( client().findOne(ns(), Query()).woCompare(fromjson("{'_id':0,a:[1,2]}")) == 0); + _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) ); + ASSERT( _client.findOne(ns(), Query()).woCompare(fromjson("{'_id':0,a:[1,2]}")) == 0); } }; class PushSliceInvalidSliceType : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) ); + _client.insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) ); // { $push : { a : { $each : [ 3 ], $slice : [ -2 ] } } } BSONObj pushObj = BSON( "$each" << BSON_ARRAY(3) << "$slice" << BSON_ARRAY(-2) ); - client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) ); - ASSERT( client().findOne( ns(), Query() ).woCompare(fromjson("{'_id':0,a:[1,2]}")) == 0); + _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) ); + ASSERT( _client.findOne( ns(), Query() ).woCompare(fromjson("{'_id':0,a:[1,2]}")) == 0); } }; class PushSliceInvalidSliceValue : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) ); + _client.insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) ); // { $push : { a : { $each : [ 3 ], $slice : 2 } } } BSONObj pushObj = BSON( "$each" << BSON_ARRAY(3) << "$slice" << 2 ); - client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) ); - ASSERT( client().findOne( ns(), Query() ).woCompare(fromjson("{'_id':0,a:[1,2]}")) == 0); + _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) ); + ASSERT( _client.findOne( ns(), Query() ).woCompare(fromjson("{'_id':0,a:[1,2]}")) == 0); } }; @@ -787,33 +787,33 @@ namespace UpdateTests { class PushSliceInvalidSliceDouble : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) ); + _client.insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) ); // { $push : { a : { $each : [ 3 ], $slice : -2.1 } } } BSONObj pushObj = BSON( "$each" << BSON_ARRAY(3) << "$slice" << -2.1 ); - client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) ); - ASSERT( client().findOne( ns(), Query() ).woCompare(fromjson("{'_id':0,a:[1,2]}")) == 0); + _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) ); + ASSERT( _client.findOne( ns(), Query() ).woCompare(fromjson("{'_id':0,a:[1,2]}")) == 0); } }; class PushSliceValidSliceDouble : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) ); + _client.insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) ); // { $push : { a : { $each : [ 3 ], $slice : -2.0 } } } BSONObj pushObj = BSON( "$each" << BSON_ARRAY(3) << "$slice" << -2.0 ); - client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) ); - ASSERT_EQUALS(client().findOne(ns(), Query()) , fromjson("{'_id':0,a:[2,3]}")); + _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) ); + ASSERT_EQUALS(_client.findOne(ns(), Query()) , fromjson("{'_id':0,a:[2,3]}")); } }; class PushSliceInvalidSlice : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) ); + _client.insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) ); // { $push : { a : { $each : [ 3 ], $xxxx : 2 } } } BSONObj pushObj = BSON( "$each" << BSON_ARRAY(3) << "$xxxx" << 2 ); - client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) ); - ASSERT( client().findOne( ns(), Query() ).woCompare(fromjson("{'_id':0,a:[1,2]}")) == 0); + _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) ); + ASSERT( _client.findOne( ns(), Query() ).woCompare(fromjson("{'_id':0,a:[1,2]}")) == 0); } }; @@ -826,7 +826,7 @@ namespace UpdateTests { class PushSortBase : public ClientBase { public: ~PushSortBase() { - client().dropCollection( ns() ); + _client.dropCollection( ns() ); } protected: @@ -904,8 +904,8 @@ namespace UpdateTests { void check( BSONObj expected ) { std::cout << expected.toString() << std::endl; - std::cout << client().findOne( ns(), Query() ) << std::endl; - ASSERT( client().findOne( ns(), Query() ).woCompare( expected ) == 0 ); + std::cout << _client.findOne( ns(), Query() ) << std::endl; + ASSERT( _client.findOne( ns(), Query() ).woCompare( expected ) == 0 ); } private: @@ -930,24 +930,24 @@ namespace UpdateTests { // BOTTOMK_DESC: $push: { x: { $each: [ {a:2,b:2} ], $slice:3, $sort: { b:-1 } } } for ( int i = 0; i < 2; i++ ) { // i < 4 when we have positive $slice - client().dropCollection( ns() ); - client().insert( ns(), fromjson( "{'_id':0,x:[{a:1,b:1}]}" ) ); + _client.dropCollection( ns() ); + _client.insert( ns(), fromjson( "{'_id':0,x:[{a:1,b:1}]}" ) ); BSONObj result; BSONObj expected; switch ( i ) { case TOPK_ASC: case BOTTOMK_ASC: - client().update( ns(), Query(), getUpdate(i) ); - result = client().findOne( ns(), Query() ); + _client.update( ns(), Query(), getUpdate(i) ); + result = _client.findOne( ns(), Query() ); expected = fromjson( "{'_id':0,x:[{a:1,b:1},{a:2,b:2}]}" ); ASSERT_EQUALS( result, expected ); break; case TOPK_DESC: case BOTTOMK_DESC: - client().update( ns(), Query(), getUpdate(i) ); - result = client().findOne( ns(), Query() ); + _client.update( ns(), Query(), getUpdate(i) ); + result = _client.findOne( ns(), Query() ); expected = fromjson( "{'_id':0,x:[{a:2,b:2},{a:1,b:1}]}" ) ; ASSERT_EQUALS( result, expected ); break; @@ -971,24 +971,24 @@ namespace UpdateTests { // BOTTOMK_DESC: $push: { x: { $each: [ {a:2,b:2} ], $slice:2, $sort: { b:-1 } } } for ( int i = 0; i < 2; i++ ) { // i < 4 when we have positive $slice - client().dropCollection( ns() ); - client().insert( ns(), fromjson( "{'_id':0,x:[{a:1,b:1}]}" ) ); + _client.dropCollection( ns() ); + _client.insert( ns(), fromjson( "{'_id':0,x:[{a:1,b:1}]}" ) ); BSONObj result; BSONObj expected; switch (i) { case TOPK_ASC: case BOTTOMK_ASC: - client().update( ns(), Query(), getUpdate(i) ); - result = client().findOne( ns(), Query() ); + _client.update( ns(), Query(), getUpdate(i) ); + result = _client.findOne( ns(), Query() ); expected = fromjson( "{'_id':0,x:[{a:1,b:1},{a:2,b:2}]}" ); ASSERT_EQUALS( result, expected ); break; case TOPK_DESC: case BOTTOMK_DESC: - client().update( ns(), Query(), getUpdate(i) ); - result = client().findOne( ns(), Query() ); + _client.update( ns(), Query(), getUpdate(i) ); + result = _client.findOne( ns(), Query() ); expected = fromjson( "{'_id':0,x:[{a:2,b:2},{a:1,b:1}]}" ); ASSERT_EQUALS( result, expected ); break; @@ -1012,22 +1012,22 @@ namespace UpdateTests { // BOTTOMK_DESC: $push: { x: { $each: [ {a:2,b:2} ], $slice:2, $sort: { b:-1 } } } for ( int i = 0; i < 2; i++ ) { // i < 4 when we have positive $slice - client().dropCollection( ns() ); - client().insert( ns(), fromjson( "{'_id':0,x:[{a:1,b:1},{a:3,b:3}]}" ) ); + _client.dropCollection( ns() ); + _client.insert( ns(), fromjson( "{'_id':0,x:[{a:1,b:1},{a:3,b:3}]}" ) ); BSONObj result; BSONObj expected; switch ( i ) { case TOPK_ASC: - client().update( ns(), Query(), getUpdate(i) ); - result = client().findOne( ns(), Query() ); + _client.update( ns(), Query(), getUpdate(i) ); + result = _client.findOne( ns(), Query() ); expected = fromjson( "{'_id':0,x:[{a:2,b:2},{a:3,b:3}]}" ); ASSERT_EQUALS( result, expected ); break; case TOPK_DESC: - client().update( ns(), Query(), getUpdate(i) ); - result = client().findOne( ns(), Query() ); + _client.update( ns(), Query(), getUpdate(i) ); + result = _client.findOne( ns(), Query() ); expected = fromjson( "{'_id':0,x:[{a:2,b:2},{a:1,b:1}]}" ); ASSERT_EQUALS( result, expected ); break; @@ -1056,14 +1056,14 @@ namespace UpdateTests { // BOTTOMK_DESC: $push: { x: { $each: [ {a:2,b:2} ], $slice:0, $sort: { b:-1 } } } for ( int i = 0; i < 2; i++ ) { // i < 4 when we have positive $slice - client().dropCollection( ns() ); - client().insert( ns(), fromjson( "{'_id':0,x:[{a:1,b:1},{a:3,b:3}]}" ) ); + _client.dropCollection( ns() ); + _client.insert( ns(), fromjson( "{'_id':0,x:[{a:1,b:1},{a:3,b:3}]}" ) ); BSONObj result; BSONObj expected; - client().update( ns(), Query(), getUpdate(i) ); - result = client().findOne( ns(), Query() ); + _client.update( ns(), Query(), getUpdate(i) ); + result = _client.findOne( ns(), Query() ); expected = fromjson( "{'_id':0,x:[]}" ); ASSERT_EQUALS( result, expected ); } @@ -1085,14 +1085,14 @@ namespace UpdateTests { // BOTTOMK_DESC: $push: { x: { $each: [ {a:2,b:2} ], $slice:0, $sort: { b:-1 } } } for ( int i = 0; i < 2; i++ ) { // i < 4 when we have positive $slice - client().dropCollection( ns() ); - client().insert( ns(), fromjson( "{'_id':0}" ) ); + _client.dropCollection( ns() ); + _client.insert( ns(), fromjson( "{'_id':0}" ) ); BSONObj result; BSONObj expected; - client().update( ns(), Query(), getUpdate(i) ); - result = client().findOne( ns(), Query() ); + _client.update( ns(), Query(), getUpdate(i) ); + result = _client.findOne( ns(), Query() ); expected = fromjson( "{'_id':0,x:[]}" ); ASSERT_EQUALS( result, expected ); } @@ -1116,24 +1116,24 @@ namespace UpdateTests { // BOTTOMK_DESC: $push: { x: { $each: [ <genarray> ], $slice:2, $sort: { b:-1 } } } for ( int i = 0; i < 2; i++ ) { // i < 4 when we have positive $slice - client().dropCollection( ns() ); - client().insert( ns(), fromjson( "{'_id':0}" ) ); + _client.dropCollection( ns() ); + _client.insert( ns(), fromjson( "{'_id':0}" ) ); BSONObj result; BSONObj expected; switch (i) { case TOPK_ASC: case BOTTOMK_ASC: - client().update( ns(), Query(), getUpdate(i) ); - result = client().findOne( ns(), Query() ); + _client.update( ns(), Query(), getUpdate(i) ); + result = _client.findOne( ns(), Query() ); expected = fromjson( "{'_id':0,x:[{a:1,b:1},{a:2,b:2}]}" ); ASSERT_EQUALS( result, expected ); break; case TOPK_DESC: case BOTTOMK_DESC: - client().update( ns(), Query(), getUpdate(i) ); - result = client().findOne( ns(), Query() ); + _client.update( ns(), Query(), getUpdate(i) ); + result = _client.findOne( ns(), Query() ); expected = fromjson( "{'_id':0,x:[{a:2,b:2},{a:1,b:1}]}" ); ASSERT_EQUALS( result, expected ); break; @@ -1158,22 +1158,22 @@ namespace UpdateTests { // BOTTOMK_DESC: $push: { x: { $each: [ <genarray> ], $slice:2, $sort: { b:-1 } } } for ( int i = 0; i < 2; i++ ) { // i < 4 when we have positive $slice - client().dropCollection( ns() ); - client().insert( ns(), fromjson( "{'_id':0}" ) ); + _client.dropCollection( ns() ); + _client.insert( ns(), fromjson( "{'_id':0}" ) ); BSONObj result; BSONObj expected; switch (i) { case TOPK_ASC: - client().update( ns(), Query(), getUpdate(i) ); - result = client().findOne( ns(), Query() ); + _client.update( ns(), Query(), getUpdate(i) ); + result = _client.findOne( ns(), Query() ); expected = fromjson( "{'_id':0,x:[{a:2,b:2},{a:3,b:3}]}" ); ASSERT_EQUALS( result, expected ); break; case TOPK_DESC: - client().update( ns(), Query(), getUpdate(i) ); - result = client().findOne( ns(), Query() ); + _client.update( ns(), Query(), getUpdate(i) ); + result = _client.findOne( ns(), Query() ); expected = fromjson( "{'_id':0,x:[{a:2,b:2},{a:1,b:1}]}" ); ASSERT_EQUALS( result, expected ); break; @@ -1203,24 +1203,24 @@ namespace UpdateTests { // BOTTOMK_DESC: $push: { x: { $each: [ <genarray> ], $slice:2, $sort: { b:-1 } } } for ( int i = 0; i < 2; i++ ) { // i < 4 when we have positive $slice - client().dropCollection( ns() ); - client().insert( ns(), fromjson( "{'_id':0,x:[]}" ) ); + _client.dropCollection( ns() ); + _client.insert( ns(), fromjson( "{'_id':0,x:[]}" ) ); BSONObj result; BSONObj expected; switch (i) { case TOPK_ASC: case BOTTOMK_ASC: - client().update( ns(), Query(), getUpdate(i) ); - result = client().findOne( ns(), Query() ); + _client.update( ns(), Query(), getUpdate(i) ); + result = _client.findOne( ns(), Query() ); expected = fromjson( "{'_id':0,x:[{a:1,b:1},{a:2,b:2}]}" ); ASSERT_EQUALS( result, expected ); break; case TOPK_DESC: case BOTTOMK_DESC: - client().update( ns(), Query(), getUpdate(i) ); - result = client().findOne( ns(), Query() ); + _client.update( ns(), Query(), getUpdate(i) ); + result = _client.findOne( ns(), Query() ); expected = fromjson( "{'_id':0,x:[{a:2,b:2},{a:1,b:1}]}" ); ASSERT_EQUALS( result, expected ); break; @@ -1245,22 +1245,22 @@ namespace UpdateTests { // BOTTOMK_DESC: $push: { x: { $each: [ <genarray> ], $slice:2, $sort: { b:-1 } } } for ( int i = 0; i < 2; i++ ) { // i < 4 when we have positive $slice - client().dropCollection( ns() ); - client().insert( ns(), fromjson( "{'_id':0,x:[]}" ) ); + _client.dropCollection( ns() ); + _client.insert( ns(), fromjson( "{'_id':0,x:[]}" ) ); BSONObj result; BSONObj expected; switch (i) { case TOPK_ASC: - client().update( ns(), Query(), getUpdate(i) ); - result = client().findOne( ns(), Query() ); + _client.update( ns(), Query(), getUpdate(i) ); + result = _client.findOne( ns(), Query() ); expected = fromjson( "{'_id':0,x:[{a:2,b:2},{a:3,b:3}]}" ); ASSERT_EQUALS( result, expected ); break; case TOPK_DESC: - client().update( ns(), Query(), getUpdate(i) ); - result = client().findOne( ns(), Query() ); + _client.update( ns(), Query(), getUpdate(i) ); + result = _client.findOne( ns(), Query() ); expected = fromjson( "{'_id':0,x:[{a:2,b:2},{a:1,b:1}]}" ); ASSERT_EQUALS( result, expected ); break; @@ -1416,14 +1416,14 @@ namespace UpdateTests { // catch bad patterns, we have to write updated that use them. BSONObj expected = fromjson( "{'_id':0,x:[{a:1}, {a:2}]}" ); - client().insert( ns(), expected ); + _client.insert( ns(), expected ); // { $push : { x : { $each : [ {a:3} ], $slice:-2, $sort : {a..d:1} } } } BSONObj pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 3 ) ) << "$slice" << -2 << "$sort" << BSON( "a..d" << 1 ) ); - client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) ); - BSONObj result = client().findOne( ns(), Query() ); + _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) ); + BSONObj result = _client.findOne( ns(), Query() ); ASSERT_EQUALS( result, expected ); @@ -1431,32 +1431,32 @@ namespace UpdateTests { pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 3 ) ) << "$slice" << -2 << "$sort" << BSON( "a." << 1 ) ); - client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) ); - result = client().findOne( ns(), Query() ); + _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) ); + result = _client.findOne( ns(), Query() ); ASSERT_EQUALS( result, expected ); // { $push : { x : { $each : [ {a:3} ], $slice:-2, $sort : {.b:1} } } } pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 3 ) ) << "$slice" << -2 << "$sort" << BSON( ".b" << 1 ) ); - client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) ); - result = client().findOne( ns(), Query() ); + _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) ); + result = _client.findOne( ns(), Query() ); ASSERT_EQUALS( result, expected ); // { $push : { x : { $each : [ {a:3} ], $slice:-2, $sort : {.:1} } } } pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 3 ) ) << "$slice" << -2 << "$sort" << BSON( "." << 1 ) ); - client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) ); - result = client().findOne( ns(), Query() ); + _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) ); + result = _client.findOne( ns(), Query() ); ASSERT_EQUALS( result, expected ); // { $push : { x : { $each : [ {a:3} ], $slice:-2, $sort : {'':1} } } } pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 3 ) ) << "$slice" << -2 << "$sort" << BSON( "" << 1 ) ); - client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) ); - result = client().findOne( ns(), Query() ); + _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) ); + result = _client.findOne( ns(), Query() ); ASSERT_EQUALS( result, expected ); } }; @@ -1465,13 +1465,13 @@ namespace UpdateTests { public: void run() { BSONObj expected = fromjson( "{'_id':0,x:[{a:1},{a:2}]}" ); - client().insert( ns(), expected ); + _client.insert( ns(), expected ); // { $push : { x : { $each : [ 3 ], $slice:-2, $sort : {a:1} } } } BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 3 ) << "$slice" << -2 << "$sort" << BSON( "a" << 1 ) ); - client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) ); - BSONObj result = client().findOne( ns(), Query() ); + _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) ); + BSONObj result = _client.findOne( ns(), Query() ); ASSERT_EQUALS( result, expected ); } }; @@ -1480,13 +1480,13 @@ namespace UpdateTests { public: void run() { BSONObj expected = fromjson( "{'_id':0,x:[{a:1},{a:2}]}" ); - client().insert( ns(), expected ); + _client.insert( ns(), expected ); // { $push : { x : { $each : [ {a:3} ], $slice:-2, $sort : 2} } } BSONObj pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 3 ) ) << "$slice" << -2 << "$sort" << 2 ); - client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) ); - BSONObj result = client().findOne( ns(), Query() ); + _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) ); + BSONObj result = _client.findOne( ns(), Query() ); ASSERT_EQUALS( result, expected ); } }; @@ -1495,13 +1495,13 @@ namespace UpdateTests { public: void run() { BSONObj expected = fromjson( "{'_id':0,x:[{a:1},{a:2}]}" ); - client().insert( ns(), expected ); + _client.insert( ns(), expected ); // { $push : { x : { $each : [ {a:3} ], $slice:2, $sort : {a:1} } } } BSONObj pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 3 ) ) << "$slice" << 2 << "$sort" << BSON( "a" << 1 ) ); - client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) ); - BSONObj result = client().findOne( ns(), Query() ); + _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) ); + BSONObj result = _client.findOne( ns(), Query() ); ASSERT_EQUALS( result, expected ); } }; @@ -1510,13 +1510,13 @@ namespace UpdateTests { public: void run() { BSONObj expected = fromjson( "{'_id':0,x:[{a:1},{a:2}]}" ); - client().insert( ns(), expected ); + _client.insert( ns(), expected ); // { $push : { x : { $each : [ {a:3} ], $slice:-2.1, $sort : {a:1} } } } BSONObj pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 3 ) ) << "$slice" << -2.1 << "$sort" << BSON( "a" << 1 ) ); - client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) ); - BSONObj result = client().findOne( ns(), Query() ); + _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) ); + BSONObj result = _client.findOne( ns(), Query() ); ASSERT_EQUALS( result, expected ); } }; @@ -1524,14 +1524,14 @@ namespace UpdateTests { class PushSortValidSortDouble : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0,x:[{a:1},{a:2}]}" ) ); + _client.insert( ns(), fromjson( "{'_id':0,x:[{a:1},{a:2}]}" ) ); // { $push : { x : { $each : [ {a:3} ], $slice:-2.0, $sort : {a:1} } } } BSONObj pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 3 ) ) << "$slice" << -2.0 << "$sort" << BSON( "a" << 1 ) ); - client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) ); + _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) ); BSONObj expected = fromjson( "{'_id':0,x:[{a:2},{a:3}]}" ); - BSONObj result = client().findOne( ns(), Query() ); + BSONObj result = _client.findOne( ns(), Query() ); ASSERT_EQUALS( result, expected ); } }; @@ -1540,13 +1540,13 @@ namespace UpdateTests { public: void run() { BSONObj expected = fromjson( "{'_id':0,x:[{a:1},{a:2}]}" ); - client().insert( ns(), expected ); + _client.insert( ns(), expected ); // { $push : { x : { $each : [ {a:3} ], $slice:-2.0, $sort : [2, 1] } } } BSONObj pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 3 ) ) << "$slice" << -2.0 << "$sort" << BSON_ARRAY( 2 << 1 ) ); - client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) ); - BSONObj result = client().findOne( ns(), Query() ); + _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) ); + BSONObj result = _client.findOne( ns(), Query() ); ASSERT_EQUALS( result, expected ); } }; @@ -1555,13 +1555,13 @@ namespace UpdateTests { public: void run() { BSONObj expected = fromjson( "{'_id':0,x:[{a:1},{a:2}]}" ); - client().insert( ns(), expected ); + _client.insert( ns(), expected ); // { $push : { x : { $each : [ {a:3} ], $slice:-2, $sort : {a:10} } } } BSONObj pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 3 ) ) << "$slice" << -2 << "$sort" << BSON( "a" << 10 ) ); - client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) ); - BSONObj result = client().findOne( ns(), Query() ); + _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) ); + BSONObj result = _client.findOne( ns(), Query() ); ASSERT_EQUALS( result, expected ); } }; @@ -1569,14 +1569,14 @@ namespace UpdateTests { class PushSortInvertedSortAndSlice : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0,x:[{a:1},{a:3}]}" ) ); + _client.insert( ns(), fromjson( "{'_id':0,x:[{a:1},{a:3}]}" ) ); // { $push : { x : { $each : [ {a:2} ], $sort: {a:1}, $slice:-2 } } } BSONObj pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 2 ) ) << "$sort" << BSON( "a" << 1 ) << "$slice" << -2.0 ); - client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) ); + _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) ); BSONObj expected = fromjson( "{'_id':0,x:[{a:2},{a:3}]}" ); - BSONObj result = client().findOne( ns(), Query() ); + BSONObj result = _client.findOne( ns(), Query() ); ASSERT_EQUALS( result, expected ); } @@ -1586,13 +1586,13 @@ namespace UpdateTests { public: void run() { BSONObj expected = fromjson( "{'_id':0,x:[{a:1},{a:3}]}" ); - client().insert( ns(), expected ); + _client.insert( ns(), expected ); // { $push : { x : { $each : [ {a:2} ], $sort : {a:1}, $sort: {a:1} } } } BSONObj pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 2 ) ) << "$sort" << BSON( "a" << 1 ) << "$sort" << BSON( "a" << 1 ) ); - client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) ); - BSONObj result = client().findOne( ns(), Query() ); + _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) ); + BSONObj result = _client.findOne( ns(), Query() ); ASSERT_EQUALS( result, expected ); } @@ -1601,54 +1601,54 @@ namespace UpdateTests { class CantIncParent : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0,a:{b:4}}" ) ); - client().update( ns(), Query(), BSON( "$inc" << BSON( "a" << 4.0 ) ) ); - ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:4}}" ) ) == 0 ); + _client.insert( ns(), fromjson( "{'_id':0,a:{b:4}}" ) ); + _client.update( ns(), Query(), BSON( "$inc" << BSON( "a" << 4.0 ) ) ); + ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:4}}" ) ) == 0 ); } }; class DontDropEmpty : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0,a:{b:{}}}" ) ); - client().update( ns(), Query(), BSON( "$set" << BSON( "a.c" << 4.0 ) ) ); - ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:{},c:4}}" ) ) == 0 ); + _client.insert( ns(), fromjson( "{'_id':0,a:{b:{}}}" ) ); + _client.update( ns(), Query(), BSON( "$set" << BSON( "a.c" << 4.0 ) ) ); + ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:{},c:4}}" ) ) == 0 ); } }; class InsertInEmpty : public SetBase { public: void run() { - client().insert( ns(), fromjson( "{'_id':0,a:{b:{}}}" ) ); - client().update( ns(), Query(), BSON( "$set" << BSON( "a.b.f" << 4.0 ) ) ); - ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:{f:4}}}" ) ) == 0 ); + _client.insert( ns(), fromjson( "{'_id':0,a:{b:{}}}" ) ); + _client.update( ns(), Query(), BSON( "$set" << BSON( "a.b.f" << 4.0 ) ) ); + ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:{f:4}}}" ) ) == 0 ); } }; class IndexParentOfMod : public SetBase { public: void run() { - client().ensureIndex( ns(), BSON( "a" << 1 ) ); - client().insert( ns(), fromjson( "{'_id':0}" ) ); - client().update( ns(), Query(), fromjson( "{$set:{'a.b':4}}" ) ); - ASSERT_EQUALS( fromjson( "{'_id':0,a:{b:4}}" ) , client().findOne( ns(), Query() ) ); - ASSERT_EQUALS( fromjson( "{'_id':0,a:{b:4}}" ) , client().findOne( ns(), fromjson( "{'a.b':4}" ) ) ); // make sure the index works + _client.ensureIndex( ns(), BSON( "a" << 1 ) ); + _client.insert( ns(), fromjson( "{'_id':0}" ) ); + _client.update( ns(), Query(), fromjson( "{$set:{'a.b':4}}" ) ); + ASSERT_EQUALS( fromjson( "{'_id':0,a:{b:4}}" ) , _client.findOne( ns(), Query() ) ); + ASSERT_EQUALS( fromjson( "{'_id':0,a:{b:4}}" ) , _client.findOne( ns(), fromjson( "{'a.b':4}" ) ) ); // make sure the index works } }; class PreserveIdWithIndex : public SetBase { // Not using $set, but base class is still useful public: void run() { - client().insert( ns(), BSON( "_id" << 55 << "i" << 5 ) ); - client().update( ns(), BSON( "i" << 5 ), BSON( "i" << 6 ) ); - ASSERT( !client().findOne( ns(), Query( BSON( "_id" << 55 ) ).hint ( "{\"_id\":1}" ) ).isEmpty() ); + _client.insert( ns(), BSON( "_id" << 55 << "i" << 5 ) ); + _client.update( ns(), BSON( "i" << 5 ), BSON( "i" << 6 ) ); + ASSERT( !_client.findOne( ns(), Query( BSON( "_id" << 55 ) ).hint ( "{\"_id\":1}" ) ).isEmpty() ); } }; class CheckNoMods : public SetBase { public: void run() { - client().update( ns(), BSONObj(), BSON( "i" << 5 << "$set" << BSON( "q" << 3 ) ), true ); + _client.update( ns(), BSONObj(), BSON( "i" << 5 << "$set" << BSON( "q" << 3 ) ), true ); ASSERT( error() ); } }; @@ -1656,9 +1656,9 @@ namespace UpdateTests { class UpdateMissingToNull : public SetBase { public: void run() { - client().insert( ns(), BSON( "a" << 5 ) ); - client().update( ns(), BSON( "a" << 5 ), fromjson( "{$set:{b:null}}" ) ); - ASSERT_EQUALS( jstNULL, client().findOne( ns(), QUERY( "a" << 5 ) ).getField( "b" ).type() ); + _client.insert( ns(), BSON( "a" << 5 ) ); + _client.update( ns(), BSON( "a" << 5 ), fromjson( "{$set:{b:null}}" ) ); + ASSERT_EQUALS( jstNULL, _client.findOne( ns(), QUERY( "a" << 5 ) ).getField( "b" ).type() ); } }; @@ -1666,14 +1666,14 @@ namespace UpdateTests { class TwoModsWithinDuplicatedField : public SetBase { public: void run() { - client().insert( ns(), BSON( "_id" << 0 << "a" << 1 + _client.insert( ns(), BSON( "_id" << 0 << "a" << 1 << "x" << BSONObj() << "x" << BSONObj() << "z" << 5 ) ); - client().update( ns(), BSONObj(), BSON( "$set" << BSON( "x.b" << 1 << "x.c" << 1 ) ) ); + _client.update( ns(), BSONObj(), BSON( "$set" << BSON( "x.b" << 1 << "x.c" << 1 ) ) ); ASSERT_EQUALS( BSON( "_id" << 0 << "a" << 1 << "x" << BSON( "b" << 1 << "c" << 1 ) << "x" << BSONObj() << "z" << 5 ), - client().findOne( ns(), BSONObj() ) ); + _client.findOne( ns(), BSONObj() ) ); } }; @@ -1681,27 +1681,27 @@ namespace UpdateTests { class ThreeModsWithinDuplicatedField : public SetBase { public: void run() { - client().insert( ns(), + _client.insert( ns(), BSON( "_id" << 0 << "x" << BSONObj() << "x" << BSONObj() << "x" << BSONObj() ) ); - client().update( ns(), BSONObj(), + _client.update( ns(), BSONObj(), BSON( "$set" << BSON( "x.b" << 1 << "x.c" << 1 << "x.d" << 1 ) ) ); ASSERT_EQUALS( BSON( "_id" << 0 << "x" << BSON( "b" << 1 << "c" << 1 << "d" << 1 ) << "x" << BSONObj() << "x" << BSONObj() ), - client().findOne( ns(), BSONObj() ) ); + _client.findOne( ns(), BSONObj() ) ); } }; class TwoModsBeforeExistingField : public SetBase { public: void run() { - client().insert( ns(), BSON( "_id" << 0 << "x" << 5 ) ); - client().update( ns(), BSONObj(), + _client.insert( ns(), BSON( "_id" << 0 << "x" << 5 ) ); + _client.update( ns(), BSONObj(), BSON( "$set" << BSON( "a" << 1 << "b" << 1 << "x" << 10 ) ) ); ASSERT_EQUALS( mutablebson::unordered( BSON( "_id" << 0 << "a" << 1 << "b" << 1 << "x" << 10 ) ), - mutablebson::unordered( client().findOne( ns(), BSONObj() ) ) ); + mutablebson::unordered( _client.findOne( ns(), BSONObj() ) ) ); } }; @@ -1713,15 +1713,15 @@ namespace UpdateTests { virtual void dotest() = 0; void insert( const BSONObj& o ) { - client().insert( ns() , o ); + _client.insert( ns() , o ); } void update( const BSONObj& m ) { - client().update( ns() , BSONObj() , m ); + _client.update( ns() , BSONObj() , m ); } BSONObj findOne() { - return client().findOne( ns() , BSONObj() ); + return _client.findOne( ns() , BSONObj() ); } void test( const char* initial , const char* mod , const char* after ) { @@ -1730,11 +1730,11 @@ namespace UpdateTests { void test( const BSONObj& initial , const BSONObj& mod , const BSONObj& after ) { - client().dropCollection( ns() ); + _client.dropCollection( ns() ); insert( initial ); update( mod ); ASSERT_EQUALS( after , findOne() ); - client().dropCollection( ns() ); + _client.dropCollection( ns() ); } public: @@ -1744,11 +1744,11 @@ namespace UpdateTests { } void run() { - client().dropCollection( ns() ); + _client.dropCollection( ns() ); dotest(); - client().dropCollection( ns() ); + _client.dropCollection( ns() ); } }; @@ -1858,7 +1858,7 @@ namespace UpdateTests { long long start = numeric_limits<int>::max() - 5; long long max = numeric_limits<int>::max() + 5ll; - client().insert( ns() , BSON( "x" << (int)start ) ); + _client.insert( ns() , BSON( "x" << (int)start ) ); ASSERT( findOne()["x"].type() == NumberInt ); while ( start < max ) { |