diff options
author | Tyler Brock <tyler.brock@gmail.com> | 2014-06-30 15:08:13 -0400 |
---|---|---|
committer | Tyler Brock <tyler.brock@gmail.com> | 2014-06-30 15:08:13 -0400 |
commit | a353e16805d573af3d5ab4d32fbda87ec98d5c40 (patch) | |
tree | b380194417fd18d7ac24a138cf8a3f14f2535e0c /src/mongo/dbtests | |
parent | e9a6e9365cf4d6d13b4a3f94aec1f433dab9f704 (diff) | |
download | mongo-a353e16805d573af3d5ab4d32fbda87ec98d5c40.tar.gz |
Revert "SERVER-13961 Add OperationContext argument to Client::Context"
This reverts commit e1f5a39b1b625d04752be13f39c774e579b64cd8.
Diffstat (limited to 'src/mongo/dbtests')
33 files changed, 758 insertions, 852 deletions
diff --git a/src/mongo/dbtests/clienttests.cpp b/src/mongo/dbtests/clienttests.cpp index 1ba539f0266..527f52f2554 100644 --- a/src/mongo/dbtests/clienttests.cpp +++ b/src/mongo/dbtests/clienttests.cpp @@ -40,23 +40,19 @@ namespace ClientTests { class Base { public: - Base( string coll ) : _ns("test." + coll) { - OperationContextImpl txn; - DBDirectClient db(&txn); - + Base( string coll ) { db.dropDatabase("test"); + _ns = (string)"test." + coll; } virtual ~Base() { - OperationContextImpl txn; - DBDirectClient db(&txn); - db.dropCollection( _ns ); } const char * ns() { return _ns.c_str(); } - const string _ns; + string _ns; + DBDirectClient db; }; @@ -64,9 +60,6 @@ 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() ); @@ -88,8 +81,6 @@ 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() ); @@ -107,8 +98,6 @@ 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() ); @@ -134,9 +123,7 @@ 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)); @@ -171,14 +158,9 @@ namespace ClientTests { public: CS_10() : Base( "CS_10" ) {} void run() { - 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)); - } - + 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 ) ) ); @@ -190,13 +172,8 @@ namespace ClientTests { public: PushBack() : Base( "PushBack" ) {} void run() { - OperationContextImpl txn; - DBDirectClient db(&txn); - - for (int i = 0; i < 10; ++i) { - db.insert(ns(), BSON("i" << i)); - } - + 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(); @@ -235,10 +212,7 @@ namespace ClientTests { public: Create() : Base( "Create" ) {} void run() { - OperationContextImpl txn; - DBDirectClient db(&txn); - - db.createCollection("unittests.clienttests.create", 4096, true); + db.createCollection( "unittests.clienttests.create", 4096, true ); BSONObj info; ASSERT( db.runCommand( "unittests", BSON( "collstats" << "clienttests.create" ), info ) ); } @@ -263,7 +237,6 @@ 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 955620eac94..a8aeb09bd6a 100644 --- a/src/mongo/dbtests/commandtests.cpp +++ b/src/mongo/dbtests/commandtests.cpp @@ -26,10 +26,9 @@ * then also delete it in the license file. */ -#include "mongo/platform/basic.h" +#include "mongo/pch.h" #include "mongo/db/d_concurrency.h" -#include "mongo/db/operation_context_impl.h" #include "mongo/dbtests/dbtests.h" using namespace mongo; @@ -38,14 +37,13 @@ namespace CommandTests { // one namespace per command namespace FileMD5 { struct Base { - Base() : db(&_txn) { + Base() { 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 f80565e1723..55c2d7f559f 100644 --- a/src/mongo/dbtests/config_server_fixture.h +++ b/src/mongo/dbtests/config_server_fixture.h @@ -36,18 +36,12 @@ 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 f8119b632a1..8e34074e2aa 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(&_txn, ns()) { + Base() : lk(_txn.lockState(), ns()), _context( 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 88c04aece66..e0aeb507e36 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(&txn, ns ); + Client::Context ctx( ns ); KeyRange range( ns, BSON( "_id" << _min ), @@ -115,8 +115,9 @@ 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(); @@ -169,8 +170,9 @@ namespace mongo { // TEST(DBHelperTests, FindDiskLocsNoIndex) { + + DBDirectClient client; OperationContextImpl txn; - DBDirectClient client(&txn); client.remove( ns, BSONObj() ); client.insert( ns, BSON( "_id" << OID::gen() ) ); @@ -182,7 +184,7 @@ namespace mongo { long long estSizeBytes; { Lock::DBRead lk(txn.lockState(), ns); - Client::Context ctx(&txn, ns ); + Client::Context ctx( ns ); // search invalid index range KeyRange range( ns, @@ -210,8 +212,9 @@ namespace mongo { // TEST(DBHelperTests, FindDiskLocsTooBig) { + + DBDirectClient client; OperationContextImpl txn; - DBDirectClient client(&txn); client.remove( ns, BSONObj() ); @@ -228,7 +231,7 @@ namespace mongo { long long estSizeBytes; { Lock::DBRead lk(txn.lockState(), ns); - Client::Context ctx(&txn, ns ); + Client::Context ctx( 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 9c96dc331fd..0bea6ea2399 100644 --- a/src/mongo/dbtests/directclienttests.cpp +++ b/src/mongo/dbtests/directclienttests.cpp @@ -35,7 +35,6 @@ #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" @@ -53,8 +52,7 @@ namespace DirectClientTests { class Capped : public ClientBase { public: virtual void run() { - OperationContextImpl txn; - DBDirectClient client(&txn); + DBDirectClient client; for( int pass=0; pass < 3; pass++ ) { client.createCollection(ns, 1024 * 1024, true, 999); for( int j =0; j < pass*3; j++ ) @@ -78,9 +76,7 @@ namespace DirectClientTests { class InsertMany : ClientBase { public: virtual void run(){ - OperationContextImpl txn; - DBDirectClient client(&txn); - + DBDirectClient client; vector<BSONObj> objs; objs.push_back(BSON("_id" << 1)); objs.push_back(BSON("_id" << 1)); @@ -103,9 +99,7 @@ namespace DirectClientTests { class BadNSCmd : ClientBase { public: virtual void run(){ - OperationContextImpl txn; - DBDirectClient client(&txn); - + DBDirectClient client; BSONObj result; BSONObj cmdObj = BSON( "count" << "" ); ASSERT_THROWS( client.runCommand( "", cmdObj, result ), UserException ); @@ -115,9 +109,7 @@ namespace DirectClientTests { class BadNSQuery : ClientBase { public: virtual void run(){ - OperationContextImpl txn; - DBDirectClient client(&txn); - + DBDirectClient client; auto_ptr<DBClientCursor> cursor = client.query( "", Query(), 1 ); ASSERT(cursor->more()); BSONObj result = cursor->next().getOwned(); @@ -129,9 +121,7 @@ namespace DirectClientTests { class BadNSGetMore : ClientBase { public: virtual void run(){ - OperationContextImpl txn; - DBDirectClient client(&txn); - + DBDirectClient client; auto_ptr<DBClientCursor> cursor = client.getMore("", 1, 1); ASSERT(cursor->more()); BSONObj result = cursor->next().getOwned(); @@ -143,9 +133,7 @@ namespace DirectClientTests { class BadNSInsert : ClientBase { public: virtual void run(){ - OperationContextImpl txn; - DBDirectClient client(&txn); - + DBDirectClient client; client.insert( "", BSONObj(), 0 ); ASSERT( !client.getLastError().empty() ); } @@ -154,9 +142,7 @@ namespace DirectClientTests { class BadNSUpdate : ClientBase { public: virtual void run(){ - OperationContextImpl txn; - DBDirectClient client(&txn); - + DBDirectClient client; client.update( "", Query(), BSON( "$set" << BSON( "x" << 1 )) ); ASSERT( !client.getLastError().empty() ); } @@ -165,9 +151,7 @@ namespace DirectClientTests { class BadNSRemove : ClientBase { public: virtual void run(){ - OperationContextImpl txn; - DBDirectClient client(&txn); - + DBDirectClient client; client.remove( "", Query() ); ASSERT( !client.getLastError().empty() ); } diff --git a/src/mongo/dbtests/gle_test.cpp b/src/mongo/dbtests/gle_test.cpp index ded97a490e1..71b3642e3af 100644 --- a/src/mongo/dbtests/gle_test.cpp +++ b/src/mongo/dbtests/gle_test.cpp @@ -26,7 +26,6 @@ * 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" @@ -44,9 +43,7 @@ namespace { class GetLastErrorCommandFailure { public: void run() { - OperationContextImpl txn; - DBDirectClient client(&txn); - + DBDirectClient client; client.insert(_ns, BSON( "test" << "test")); // Cannot mix fsync + j, will make command fail @@ -61,9 +58,7 @@ namespace { class GetLastErrorClean { public: void run() { - OperationContextImpl txn; - DBDirectClient client(&txn); - + DBDirectClient client; client.insert(_ns, BSON( "test" << "test")); // Make sure there was no error @@ -78,9 +73,7 @@ namespace { class GetLastErrorFromDup { public: void run() { - OperationContextImpl txn; - DBDirectClient client(&txn); - + DBDirectClient client; 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 14c861ca58e..768db4cc307 100644 --- a/src/mongo/dbtests/gridfstest.cpp +++ b/src/mongo/dbtests/gridfstest.cpp @@ -29,7 +29,6 @@ #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" @@ -42,8 +41,7 @@ namespace { class SetChunkSizeTest { public: virtual void run() { - OperationContextImpl txn; - DBDirectClient client(&txn); + DBDirectClient client; GridFS grid(client, "gridtest"); grid.setChunkSize( 5 ); diff --git a/src/mongo/dbtests/jstests.cpp b/src/mongo/dbtests/jstests.cpp index a5f8ff997b6..400aceffd40 100644 --- a/src/mongo/dbtests/jstests.cpp +++ b/src/mongo/dbtests/jstests.cpp @@ -29,20 +29,18 @@ * then also delete it in the license file. */ -#include "mongo/platform/basic.h" +#include "mongo/pch.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 @@ -918,10 +916,6 @@ 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() ) ); @@ -933,15 +927,12 @@ 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; }; class LongUtf8String { @@ -951,21 +942,15 @@ 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; }; class InvalidUTF8Check { @@ -1036,12 +1021,10 @@ 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 @@ -1097,6 +1080,8 @@ namespace JSTests { virtual string jsonOut() const { return json(); } + + DBDirectClient client; }; class DBRefTest : public TestRoundTrip { @@ -2008,9 +1993,7 @@ namespace JSTests { update.append( "_id" , "invalidstoredjs1" ); update.appendCode( "value" , "function () { db.test.find().forEach(function(obj) { continue; }); }" ); - OperationContextImpl txn; - DBDirectClient client(&txn); - + DBDirectClient client; 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 cee3995395c..67bff7ef74b 100644 --- a/src/mongo/dbtests/matchertests.cpp +++ b/src/mongo/dbtests/matchertests.cpp @@ -41,19 +41,18 @@ namespace MatcherTests { class CollectionBase { public: - CollectionBase() : _ns( "unittests.matchertests" ) { - + CollectionBase() : + _ns( "unittests.matchertests" ) { } - virtual ~CollectionBase() { - OperationContextImpl txn; - DBDirectClient client(&txn); - - client.dropCollection(_ns); + 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 45015afe883..a0c94493fbc 100644 --- a/src/mongo/dbtests/oplogstarttests.cpp +++ b/src/mongo/dbtests/oplogstarttests.cpp @@ -38,8 +38,7 @@ namespace OplogStartTests { class Base { public: Base() : _lk(_txn.lockState()), - _context(&_txn, ns()), - _client(&_txn) { + _context(ns()) { Collection* c = _context.db()->getCollection(&_txn, ns()); if (!c) { diff --git a/src/mongo/dbtests/pdfiletests.cpp b/src/mongo/dbtests/pdfiletests.cpp index d954c801fdd..10d4e01d1fd 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(&_txn, ns()) { + _context(ns()) { } diff --git a/src/mongo/dbtests/perf/perftest.cpp b/src/mongo/dbtests/perf/perftest.cpp index 6ae7cf35532..2afa74f68fa 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(txn, ns_ ); + Client::Context ctx( 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(txn, ns_.c_str() ); + Client::Context ctx( 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 3536b8ec07e..74eb31e8f68 100644 --- a/src/mongo/dbtests/perftests.cpp +++ b/src/mongo/dbtests/perftests.cpp @@ -41,7 +41,6 @@ #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" @@ -72,8 +71,8 @@ namespace PerfTests { class ClientBase { public: // NOTE: Not bothering to backup the old error record. - ClientBase() : _client(&_txn) { - mongo::lastError.reset(new LastError()); + ClientBase() { + mongo::lastError.reset( new LastError() ); } virtual ~ClientBase() { @@ -92,7 +91,6 @@ namespace PerfTests { DBClientBase* client() { return &_client; } private: - OperationContextImpl _txn; DBDirectClient _client; }; @@ -358,9 +356,7 @@ namespace PerfTests { static int z; srand( ++z ^ (unsigned) time(0)); #endif - OperationContextImpl txn; - DBDirectClient c(&txn); - + DBDirectClient c; 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 79419bb60fa..240371f1482 100644 --- a/src/mongo/dbtests/plan_ranking.cpp +++ b/src/mongo/dbtests/plan_ranking.cpp @@ -60,10 +60,7 @@ namespace PlanRankingTests { class PlanRankingTestBase { public: - PlanRankingTestBase() - : _internalQueryForceIntersectionPlans(internalQueryForceIntersectionPlans), - _client(&_txn) { - + PlanRankingTestBase() : _internalQueryForceIntersectionPlans(internalQueryForceIntersectionPlans) { Client::WriteContext ctx(&_txn, ns); _client.dropCollection(ns); } @@ -143,13 +140,12 @@ 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 15e04854bf2..b7a58b856d4 100644 --- a/src/mongo/dbtests/profile_test.cpp +++ b/src/mongo/dbtests/profile_test.cpp @@ -31,7 +31,6 @@ */ #include "mongo/db/instance.h" -#include "mongo/db/operation_context_impl.h" #include "mongo/unittest/unittest.h" using mongo::BSONObj; @@ -39,8 +38,7 @@ using mongo::DBDirectClient; using std::string; -namespace mongo { - +namespace mongo_test { class Profiler: public mongo::unittest::Test { public: static const string PROFILER_TEST_DB; @@ -50,13 +48,11 @@ namespace mongo { 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"; @@ -68,9 +64,6 @@ namespace mongo { // 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); @@ -102,8 +95,7 @@ namespace mongo { builder.append(fieldName, x); } - OperationContextImpl txn; - DBDirectClient db(&txn); + DBDirectClient db; { BSONObj replyObj; diff --git a/src/mongo/dbtests/query_multi_plan_runner.cpp b/src/mongo/dbtests/query_multi_plan_runner.cpp index f47d08ecfe8..8ca3b5a248c 100644 --- a/src/mongo/dbtests/query_multi_plan_runner.cpp +++ b/src/mongo/dbtests/query_multi_plan_runner.cpp @@ -57,9 +57,7 @@ namespace QueryMultiPlanRunner { class MultiPlanRunnerBase { public: - MultiPlanRunnerBase() : _client(&_txn) { - - } + MultiPlanRunnerBase() { } virtual ~MultiPlanRunnerBase() { _client.dropCollection(ns()); @@ -84,8 +82,7 @@ namespace QueryMultiPlanRunner { static const char* ns() { return "unittests.QueryStageMultiPlanRunner"; } - protected: - OperationContextImpl _txn; + private: DBDirectClient _client; }; @@ -95,7 +92,8 @@ namespace QueryMultiPlanRunner { class MPRCollectionScanVsHighlySelectiveIXScan : public MultiPlanRunnerBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OperationContextImpl txn; + Client::WriteContext ctx(&txn, ns()); const int N = 5000; for (int i = 0; i < N; ++i) { @@ -108,14 +106,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); @@ -123,7 +121,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. @@ -140,7 +138,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()); @@ -150,7 +148,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 d5290853151..246cf66df1a 100644 --- a/src/mongo/dbtests/query_single_solution_runner.cpp +++ b/src/mongo/dbtests/query_single_solution_runner.cpp @@ -45,9 +45,7 @@ namespace QuerySingleSolutionRunner { class SingleSolutionRunnerBase { public: - SingleSolutionRunnerBase() : _client(&_txn) { - - } + SingleSolutionRunnerBase() { } virtual ~SingleSolutionRunnerBase() { _client.dropCollection(ns()); diff --git a/src/mongo/dbtests/query_stage_and.cpp b/src/mongo/dbtests/query_stage_and.cpp index 59a5ae3819f..ab7ff6a5457 100644 --- a/src/mongo/dbtests/query_stage_and.cpp +++ b/src/mongo/dbtests/query_stage_and.cpp @@ -51,9 +51,7 @@ namespace QueryStageAnd { class QueryStageAndBase { public: - QueryStageAndBase() : _client(&_txn) { - - } + QueryStageAndBase() { } virtual ~QueryStageAndBase() { _client.dropCollection(ns()); diff --git a/src/mongo/dbtests/query_stage_collscan.cpp b/src/mongo/dbtests/query_stage_collscan.cpp index 647b721f878..20fb3ad5b62 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() : _client(&_txn) { + QueryStageCollectionScanBase() { 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 04a45d98044..eaecb772981 100644 --- a/src/mongo/dbtests/query_stage_count.cpp +++ b/src/mongo/dbtests/query_stage_count.cpp @@ -48,9 +48,7 @@ namespace QueryStageCount { class CountBase { public: - CountBase() : _client(&_txn) { - - } + CountBase() { } 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 942c87b264a..c8799f73fcb 100644 --- a/src/mongo/dbtests/query_stage_distinct.cpp +++ b/src/mongo/dbtests/query_stage_distinct.cpp @@ -46,9 +46,7 @@ namespace QueryStageDistinct { class DistinctBase { public: - DistinctBase() : _client(&_txn) { - - } + DistinctBase() { } 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 4bea8b9e004..3414475baf9 100644 --- a/src/mongo/dbtests/query_stage_fetch.cpp +++ b/src/mongo/dbtests/query_stage_fetch.cpp @@ -48,9 +48,7 @@ namespace QueryStageFetch { class QueryStageFetchBase { public: - QueryStageFetchBase() : _client(&_txn) { - - } + QueryStageFetchBase() { } virtual ~QueryStageFetchBase() { _client.dropCollection(ns()); @@ -77,7 +75,6 @@ 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 3283b66ab8c..3be756ae2a5 100644 --- a/src/mongo/dbtests/query_stage_keep.cpp +++ b/src/mongo/dbtests/query_stage_keep.cpp @@ -52,9 +52,7 @@ namespace QueryStageKeep { class QueryStageKeepBase { public: - QueryStageKeepBase() : _client(&_txn) { - - } + QueryStageKeepBase() { } virtual ~QueryStageKeepBase() { _client.dropCollection(ns()); @@ -91,8 +89,7 @@ namespace QueryStageKeep { return WorkingSet::INVALID_ID; } - protected: - OperationContextImpl _txn; + private: DBDirectClient _client; }; @@ -105,12 +102,13 @@ namespace QueryStageKeep { class KeepStageBasic : public QueryStageKeepBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OperationContextImpl txn; + 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 11161a5c6be..ff52f9c6ffc 100644 --- a/src/mongo/dbtests/query_stage_merge_sort.cpp +++ b/src/mongo/dbtests/query_stage_merge_sort.cpp @@ -47,9 +47,7 @@ namespace QueryStageMergeSortTests { class QueryStageMergeSortTestBase { public: - QueryStageMergeSortTestBase() : _client(&_txn) { - - } + QueryStageMergeSortTestBase() { } virtual ~QueryStageMergeSortTestBase() { Client::WriteContext ctx(&_txn, ns()); @@ -111,8 +109,9 @@ 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()); } @@ -174,8 +173,9 @@ 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,8 +236,9 @@ 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()); } @@ -299,8 +300,9 @@ 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()); } @@ -363,8 +365,9 @@ 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()); } @@ -425,8 +428,9 @@ 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()); } @@ -477,8 +481,9 @@ 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 6ae66a0b7bb..1d9b4806db3 100644 --- a/src/mongo/dbtests/query_stage_sort.cpp +++ b/src/mongo/dbtests/query_stage_sort.cpp @@ -47,9 +47,7 @@ namespace QueryStageSortTests { class QueryStageSortTestBase { public: - QueryStageSortTestBase() : _client(&_txn) { - - } + QueryStageSortTestBase() { } void fillData() { for (int i = 0; i < numObj(); ++i) { @@ -170,9 +168,7 @@ namespace QueryStageSortTests { static const char* ns() { return "unittests.QueryStageSort"; } - - protected: - OperationContextImpl _txn; + private: DBDirectClient _client; }; @@ -183,12 +179,13 @@ namespace QueryStageSortTests { virtual int numObj() { return 100; } void run() { - Client::WriteContext ctx(&_txn, ns()); + OperationContextImpl txn; + 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(); @@ -202,12 +199,13 @@ namespace QueryStageSortTests { virtual int numObj() { return 100; } void run() { - Client::WriteContext ctx(&_txn, ns()); + OperationContextImpl txn; + 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(); @@ -230,12 +228,13 @@ namespace QueryStageSortTests { virtual int numObj() { return 10000; } void run() { - Client::WriteContext ctx(&_txn, ns()); + OperationContextImpl txn; + 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(); @@ -249,12 +248,13 @@ namespace QueryStageSortTests { virtual int numObj() { return 2000; } void run() { - Client::WriteContext ctx(&_txn, ns()); + OperationContextImpl txn; + 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,12 +339,13 @@ namespace QueryStageSortTests { virtual int numObj() { return 100; } void run() { - Client::WriteContext ctx(&_txn, ns()); + OperationContextImpl txn; + 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 fc5ee43ea50..23525ca265d 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() : _client(&_txn) { + IndexScanBase() { 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 ef3d859a260..ac70e48555f 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(&_txn, ns()) { + _context(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(&_txn, "unittests.querytests" ); + Client::Context ctx( "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(&_txn); + DBDirectClient cl; 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() : _client(&_txn) { + ClientBase() { mongo::lastError.reset( new LastError() ); } ~ClientBase() { @@ -197,23 +197,27 @@ 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"; @@ -221,23 +225,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(); @@ -245,7 +249,7 @@ namespace QueryTests { { // Check internal server handoff to getmore. Lock::DBWrite lk(_txn.lockState(), ns); - Client::Context ctx(&_txn, ns ); + Client::Context ctx( 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 ); @@ -253,7 +257,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" ) ); } @@ -270,7 +274,7 @@ namespace QueryTests { public: ~GetMoreKillOp() { getGlobalEnvironment()->unsetKillAllOperations(); - _client.dropCollection( "unittests.querytests.GetMoreKillOp" ); + client().dropCollection( "unittests.querytests.GetMoreKillOp" ); } void run() { @@ -281,7 +285,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. @@ -309,7 +313,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 ); } }; @@ -322,7 +326,7 @@ namespace QueryTests { public: ~GetMoreInvalidRequest() { getGlobalEnvironment()->unsetKillAllOperations(); - _client.dropCollection( "unittests.querytests.GetMoreInvalidRequest" ); + client().dropCollection( "unittests.querytests.GetMoreInvalidRequest" ); } void run() { @@ -333,7 +337,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. @@ -346,7 +350,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() ); @@ -371,38 +375,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() ); @@ -413,15 +417,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(); @@ -438,16 +442,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() ); } @@ -456,14 +460,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() ); @@ -488,19 +492,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() ); @@ -510,21 +514,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) { @@ -538,13 +542,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() ); @@ -565,20 +569,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() ); @@ -588,15 +592,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(&_txn, ns ); + Client::Context ctx( ns ); BSONObj info; - _client.runCommand( "unittests", + client().runCommand( "unittests", BSON( "create" << "querytests.OplogReplaySlaveReadTill" << "capped" << true << "size" << 8192 ), info ); @@ -608,7 +612,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() ); @@ -622,14 +626,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() ); @@ -647,11 +651,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 ); @@ -664,20 +668,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() ); } }; @@ -685,14 +689,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() ); } }; @@ -700,84 +704,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(); } @@ -786,130 +790,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() ); } }; @@ -917,16 +921,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 ] ); @@ -950,7 +954,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 ) ) ); @@ -972,15 +976,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; @@ -989,7 +993,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. @@ -1001,16 +1005,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; @@ -1029,19 +1033,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; @@ -1056,8 +1060,8 @@ namespace QueryTests { public: void run() { Lock::GlobalWrite lk(_txn.lockState()); - Client::Context ctx(&_txn, "unittests.DirectLocking"); - _client.remove( "a.b", BSONObj() ); + Client::Context ctx( "unittests.DirectLocking" ); + client().remove( "a.b", BSONObj() ); ASSERT_EQUALS( "unittests", ctx.db()->name() ); } const char *ns; @@ -1066,39 +1070,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() ); @@ -1108,15 +1112,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); } }; @@ -1127,15 +1131,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() { @@ -1159,16 +1163,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() ); } }; @@ -1176,7 +1180,7 @@ namespace QueryTests { public: TailableCappedRaceCondition() : CollectionBase( "tailablecappedrace" ) { - _client.dropCollection( ns() ); + client().dropCollection( ns() ); _n = 0; } void run() { @@ -1193,7 +1197,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(); @@ -1287,7 +1291,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; @@ -1321,18 +1325,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() ); @@ -1352,16 +1356,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() ); @@ -1385,19 +1389,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() ); @@ -1411,7 +1415,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() ); } }; @@ -1421,8 +1425,7 @@ namespace QueryTests { CollectionInternalBase( const char *nsLeaf ) : CollectionBase( nsLeaf ), _lk(_txn.lockState(), ns() ), - _ctx(&_txn, ns()) { - + _ctx( ns() ) { } private: Lock::DBWrite _lk; @@ -1434,10 +1437,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 | @@ -1459,7 +1462,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(); @@ -1482,7 +1485,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() ); @@ -1497,8 +1500,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(); @@ -1510,7 +1513,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 0cd3597f34c..07c57608ea8 100644 --- a/src/mongo/dbtests/replsettests.cpp +++ b/src/mongo/dbtests/replsettests.cpp @@ -128,16 +128,15 @@ namespace ReplSetTests { class Base { + private: + DBDirectClient _client; + protected: static BackgroundSyncTest* _bgsync; static repl::SyncTail* _tailer; - OperationContextImpl _txn; - DBDirectClient _client; - public: - Base() : _client(&_txn) { - + Base() { } ~Base() { @@ -147,22 +146,48 @@ 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() { - Client::WriteContext c(&_txn, ns()); + OperationContextImpl txn; + 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; @@ -181,29 +206,6 @@ 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; @@ -272,7 +274,7 @@ namespace ReplSetTests { return true; } - Base::insert(txn, BSON("_id" << 123)); + Base::insert(BSON("_id" << 123)); return true; } }; @@ -307,6 +309,7 @@ namespace ReplSetTests { class CappedInitialSync : public Base { string _cappedNs; + OperationContextImpl _txn; Lock::DBWrite _lk; string spec() const { @@ -314,15 +317,17 @@ namespace ReplSetTests { } void create() { - Client::Context c(&_txn, _cappedNs); - ASSERT( userCreateNS( &_txn, c.db(), _cappedNs, fromjson( spec() ), false ).isOK() ); + Client::Context c(_cappedNs); + OperationContextImpl txn; + ASSERT( userCreateNS( &txn, c.db(), _cappedNs, fromjson( spec() ), false ).isOK() ); } void dropCapped() { - Client::Context c(&_txn, _cappedNs); + Client::Context c(_cappedNs); + OperationContextImpl txn; Database* db = c.db(); - if ( db->getCollection( &_txn, _cappedNs ) ) { - db->dropCollection( &_txn, _cappedNs ); + if ( db->getCollection( &txn, _cappedNs ) ) { + db->dropCollection( &txn, _cappedNs ); } } @@ -340,7 +345,6 @@ namespace ReplSetTests { verify(!apply(o)); return o; } - public: CappedInitialSync() : _cappedNs("unittests.foo.bar"), _lk(_txn.lockState(), _cappedNs) { @@ -357,18 +361,20 @@ namespace ReplSetTests { // returns true on success, false on failure bool apply(const BSONObj& op) { - Client::Context ctx(&_txn, _cappedNs ); + Client::Context ctx( _cappedNs ); + OperationContextImpl txn; // 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() { - Lock::DBWrite lk(_txn.lockState(), _cappedNs); + OperationContextImpl txn; + Lock::DBWrite lk(txn.lockState(), _cappedNs); BSONObj op = updateFail(); Sync s(""); - verify(!s.shouldRetry(&_txn, op)); + verify(!s.shouldRetry(&txn, op)); } }; @@ -387,7 +393,7 @@ namespace ReplSetTests { } void insert(OperationContext* txn) { - Client::Context ctx(txn, cappedNs()); + Client::Context ctx(cappedNs()); Database* db = ctx.db(); Collection* coll = db->getCollection(txn, cappedNs()); if (!coll) { @@ -401,19 +407,21 @@ 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(&_txn, cappedNs()); - Collection* collection = ctx.db()->getCollection( &_txn, cappedNs() ); + Client::Context ctx(cappedNs()); + Collection* collection = ctx.db()->getCollection( &txn, cappedNs() ); verify(collection->getIndexCatalog()->findIdIndex()); } }; @@ -432,6 +440,7 @@ 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(); @@ -439,8 +448,8 @@ namespace ReplSetTests { // this changed in 2.1.2 // we now have indexes on capped collections - Client::Context ctx(&_txn, cappedNs()); - Collection* collection = ctx.db()->getCollection( &_txn, cappedNs() ); + Client::Context ctx(cappedNs()); + Collection* collection = ctx.db()->getCollection( &txn, cappedNs() ); verify(collection->getIndexCatalog()->findIdIndex()); } }; @@ -532,13 +541,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 11338a61225..eb1b45065ad 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(&_txn, ns()) { + _context(ns()) { oldRepl(); replSettings.replSet = ""; @@ -121,7 +121,7 @@ namespace ReplTests { } int count() const { Lock::GlobalWrite lk(_txn.lockState()); - Client::Context ctx(&_txn, ns() ); + Client::Context ctx( 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(&txn, cllNS() ); + Client::Context ctx( cllNS() ); Database* db = ctx.db(); Collection* coll = db->getCollection( &txn, cllNS() ); @@ -163,7 +163,7 @@ namespace ReplTests { vector< BSONObj > ops; { - Client::Context ctx(&txn, cllNS() ); + Client::Context ctx( cllNS() ); Database* db = ctx.db(); Collection* coll = db->getCollection( &txn, cllNS() ); @@ -176,7 +176,7 @@ namespace ReplTests { delete it; } { - Client::Context ctx(&txn, ns() ); + Client::Context ctx( 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(&txn, ns ); + Client::Context ctx( 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(&txn, ns ); + Client::Context ctx( 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(&txn, ns() ); + Client::Context ctx( 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 797fb53cbbc..d376a8fbaa0 100644 --- a/src/mongo/dbtests/sharding.cpp +++ b/src/mongo/dbtests/sharding.cpp @@ -28,11 +28,10 @@ * then also delete it in the license file. */ -#include "mongo/platform/basic.h" +#include "mongo/pch.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" @@ -82,11 +81,10 @@ namespace ShardingTests { class ChunkManagerTest : public ConnectionString::ConnectionHook { public: - OperationContextImpl _txn; CustomDirectClient _client; Shard _shard; - ChunkManagerTest() : _client(&_txn) { + ChunkManagerTest() { DBException::traceExceptions = true; @@ -133,7 +131,7 @@ namespace ShardingTests { double socketTimeout ) { // Note - must be new, since it gets owned elsewhere - return new CustomDirectClient(&_txn); + return new CustomDirectClient(); } }; diff --git a/src/mongo/dbtests/threadedtests.cpp b/src/mongo/dbtests/threadedtests.cpp index 0e36df8f43f..998ba2c2bed 100644 --- a/src/mongo/dbtests/threadedtests.cpp +++ b/src/mongo/dbtests/threadedtests.cpp @@ -35,7 +35,6 @@ #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" @@ -110,9 +109,7 @@ 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 - OperationContextImpl txn; - DBDirectClient db(&txn); - + DBDirectClient db; db.simpleCommand("admin", NULL, "closeAllDatabases"); } diff --git a/src/mongo/dbtests/updatetests.cpp b/src/mongo/dbtests/updatetests.cpp index cbdcc346dc8..e048ebc2d9f 100644 --- a/src/mongo/dbtests/updatetests.cpp +++ b/src/mongo/dbtests/updatetests.cpp @@ -38,7 +38,6 @@ #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 { @@ -46,26 +45,27 @@ namespace UpdateTests { class ClientBase { public: // NOTE: Not bothering to backup the old error record. - ClientBase() : _client(&_txn) { + ClientBase() { 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(); } - OperationContextImpl _txn; - DBDirectClient _client; + DBDirectClient& client() { return client_; } + + private: + 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 ) { |