summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2014-06-28 14:12:40 -0400
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2014-06-28 14:12:40 -0400
commite1f5a39b1b625d04752be13f39c774e579b64cd8 (patch)
treeb0211887cf6ff4628c7b783a989dae341caa5d01
parent89fcbab94c7103105e8c72f654a5774a066bdb90 (diff)
downloadmongo-e1f5a39b1b625d04752be13f39c774e579b64cd8.tar.gz
SERVER-13961 Add OperationContext argument to Client::Context
Time tracking and database access in Client::Context require access to the OperationContext. Adding it as argument. This is in preparation for removing LockState from Client.
-rw-r--r--src/mongo/db/catalog/collection_cursor_cache.cpp4
-rw-r--r--src/mongo/db/catalog/database.cpp2
-rw-r--r--src/mongo/db/catalog/database_holder.cpp4
-rw-r--r--src/mongo/db/catalog/index_catalog.cpp3
-rw-r--r--src/mongo/db/client.cpp72
-rw-r--r--src/mongo/db/client.h11
-rw-r--r--src/mongo/db/commands/apply_ops.cpp2
-rw-r--r--src/mongo/db/commands/collection_to_capped.cpp6
-rw-r--r--src/mongo/db/commands/compact.cpp2
-rw-r--r--src/mongo/db/commands/count.cpp2
-rw-r--r--src/mongo/db/commands/cpuprofile.cpp4
-rw-r--r--src/mongo/db/commands/drop_indexes.cpp4
-rw-r--r--src/mongo/db/commands/find_and_modify.cpp6
-rw-r--r--src/mongo/db/commands/mr.cpp7
-rw-r--r--src/mongo/db/commands/rename_collection.cpp18
-rw-r--r--src/mongo/db/commands/test_commands.cpp2
-rw-r--r--src/mongo/db/commands/write_commands/batch_executor.cpp10
-rw-r--r--src/mongo/db/curop.cpp8
-rw-r--r--src/mongo/db/curop.h2
-rw-r--r--src/mongo/db/db.cpp2
-rw-r--r--src/mongo/db/dbcommands.cpp16
-rw-r--r--src/mongo/db/dbeval.cpp2
-rw-r--r--src/mongo/db/dbhelpers.cpp12
-rw-r--r--src/mongo/db/instance.cpp6
-rw-r--r--src/mongo/db/introspect.cpp3
-rw-r--r--src/mongo/db/operation_context_impl.h2
-rw-r--r--src/mongo/db/operation_context_noop.h4
-rw-r--r--src/mongo/db/pipeline/document_source_cursor.cpp5
-rw-r--r--src/mongo/db/repl/master_slave.cpp22
-rw-r--r--src/mongo/db/repl/oplog.cpp15
-rw-r--r--src/mongo/db/repl/repl_set_impl.cpp2
-rw-r--r--src/mongo/db/repl/resync.cpp2
-rw-r--r--src/mongo/db/repl/rs_rollback.cpp8
-rw-r--r--src/mongo/db/repl/rs_sync.cpp3
-rw-r--r--src/mongo/db/repl/sync.cpp2
-rw-r--r--src/mongo/db/repl/sync_tail.cpp2
-rw-r--r--src/mongo/db/storage/mmap_v1/repair_database.cpp17
-rw-r--r--src/mongo/dbtests/clienttests.cpp47
-rw-r--r--src/mongo/dbtests/commandtests.cpp6
-rw-r--r--src/mongo/dbtests/config_server_fixture.h6
-rw-r--r--src/mongo/dbtests/counttests.cpp2
-rw-r--r--src/mongo/dbtests/dbhelper_tests.cpp15
-rw-r--r--src/mongo/dbtests/directclienttests.cpp32
-rw-r--r--src/mongo/dbtests/gle_test.cpp13
-rw-r--r--src/mongo/dbtests/gridfstest.cpp4
-rw-r--r--src/mongo/dbtests/jstests.cpp35
-rw-r--r--src/mongo/dbtests/matchertests.cpp15
-rw-r--r--src/mongo/dbtests/oplogstarttests.cpp3
-rw-r--r--src/mongo/dbtests/pdfiletests.cpp2
-rw-r--r--src/mongo/dbtests/perf/perftest.cpp4
-rw-r--r--src/mongo/dbtests/perftests.cpp10
-rw-r--r--src/mongo/dbtests/plan_ranking.cpp12
-rw-r--r--src/mongo/dbtests/profile_test.cpp16
-rw-r--r--src/mongo/dbtests/query_multi_plan_runner.cpp20
-rw-r--r--src/mongo/dbtests/query_single_solution_runner.cpp4
-rw-r--r--src/mongo/dbtests/query_stage_and.cpp4
-rw-r--r--src/mongo/dbtests/query_stage_collscan.cpp2
-rw-r--r--src/mongo/dbtests/query_stage_count.cpp4
-rw-r--r--src/mongo/dbtests/query_stage_distinct.cpp4
-rw-r--r--src/mongo/dbtests/query_stage_fetch.cpp5
-rw-r--r--src/mongo/dbtests/query_stage_keep.cpp14
-rw-r--r--src/mongo/dbtests/query_stage_merge_sort.cpp25
-rw-r--r--src/mongo/dbtests/query_stage_sort.cpp43
-rw-r--r--src/mongo/dbtests/query_stage_tests.cpp2
-rw-r--r--src/mongo/dbtests/querytests.cpp459
-rw-r--r--src/mongo/dbtests/replsettests.cpp115
-rw-r--r--src/mongo/dbtests/repltests.cpp16
-rw-r--r--src/mongo/dbtests/sharding.cpp8
-rw-r--r--src/mongo/dbtests/threadedtests.cpp5
-rw-r--r--src/mongo/dbtests/updatetests.cpp658
-rw-r--r--src/mongo/s/d_migrate.cpp2
-rw-r--r--src/mongo/s/d_state.cpp2
72 files changed, 1010 insertions, 898 deletions
diff --git a/src/mongo/db/catalog/collection_cursor_cache.cpp b/src/mongo/db/catalog/collection_cursor_cache.cpp
index 2e941dd1f40..c8e8feae704 100644
--- a/src/mongo/db/catalog/collection_cursor_cache.cpp
+++ b/src/mongo/db/catalog/collection_cursor_cache.cpp
@@ -191,7 +191,7 @@ namespace mongo {
Database* db = dbHolder().get(txn, ns);
if ( !db )
return false;
- Client::Context context( ns, db );
+ Client::Context context(txn, ns, db );
Collection* collection = db->getCollection( txn, ns );
if ( !collection ) {
if ( checkAuth )
@@ -221,7 +221,7 @@ namespace mongo {
Database* db = dbHolder().get(txn, ns);
if ( !db )
continue;
- Client::Context context( ns, db );
+ Client::Context context(txn, ns, db );
Collection* collection = db->getCollection( txn, ns );
if ( collection == NULL ) {
continue;
diff --git a/src/mongo/db/catalog/database.cpp b/src/mongo/db/catalog/database.cpp
index affa5d64195..1238072ba59 100644
--- a/src/mongo/db/catalog/database.cpp
+++ b/src/mongo/db/catalog/database.cpp
@@ -513,7 +513,7 @@ namespace mongo {
log() << "dropAllDatabasesExceptLocal " << n.size() << endl;
for( vector<string>::iterator i = n.begin(); i != n.end(); i++ ) {
if( *i != "local" ) {
- Client::Context ctx(*i);
+ Client::Context ctx(txn, *i);
dropDatabase(txn, ctx.db());
}
}
diff --git a/src/mongo/db/catalog/database_holder.cpp b/src/mongo/db/catalog/database_holder.cpp
index e1f83b53e98..438be2fd6aa 100644
--- a/src/mongo/db/catalog/database_holder.cpp
+++ b/src/mongo/db/catalog/database_holder.cpp
@@ -141,8 +141,10 @@ namespace mongo {
int nNotClosed = 0;
for( set< string >::iterator i = dbs.begin(); i != dbs.end(); ++i ) {
string name = *i;
+
LOG(2) << "DatabaseHolder::closeAll name:" << name;
- Client::Context ctx( name );
+ Client::Context ctx(txn, name);
+
if( !force && BackgroundOperation::inProgForDb(name) ) {
log() << "WARNING: can't close database "
<< name
diff --git a/src/mongo/db/catalog/index_catalog.cpp b/src/mongo/db/catalog/index_catalog.cpp
index 309775aed85..8d70c6b123c 100644
--- a/src/mongo/db/catalog/index_catalog.cpp
+++ b/src/mongo/db/catalog/index_catalog.cpp
@@ -420,7 +420,8 @@ namespace mongo {
return;
}
- Client::Context context( _collection->ns().ns(),
+ Client::Context context( _txn,
+ _collection->ns().ns(),
_collection->_database );
// if we're here, the index build failed or was interrupted
diff --git a/src/mongo/db/client.cpp b/src/mongo/db/client.cpp
index fb87dc5b9a7..6cfefce96a6 100644
--- a/src/mongo/db/client.cpp
+++ b/src/mongo/db/client.cpp
@@ -54,7 +54,7 @@
#include "mongo/db/instance.h"
#include "mongo/db/json.h"
#include "mongo/db/jsobj.h"
-#include "mongo/db/operation_context_impl.h"
+#include "mongo/db/operation_context.h"
#include "mongo/db/repl/repl_coordinator_global.h"
#include "mongo/db/repl/rs.h"
#include "mongo/db/storage_options.h"
@@ -162,23 +162,27 @@ namespace mongo {
}
BSONObj CachedBSONObjBase::_tooBig = fromjson("{\"$msg\":\"query not recording (too large)\"}");
- Client::Context::Context(const std::string& ns , Database * db) :
- _client( currentClient.get() ),
- _justCreated(false),
- _doVersion( true ),
- _ns( ns ),
- _db(db)
- {
+
+ Client::Context::Context(OperationContext* txn, const std::string& ns, Database * db)
+ : _client( currentClient.get() ),
+ _justCreated(false),
+ _doVersion( true ),
+ _ns( ns ),
+ _db(db),
+ _txn(txn) {
}
- Client::Context::Context(const string& ns, bool doVersion) :
- _client( currentClient.get() ),
- _justCreated(false), // set for real in finishInit
- _doVersion(doVersion),
- _ns( ns ),
- _db(0)
- {
+ Client::Context::Context(OperationContext* txn,
+ const string& ns,
+ bool doVersion)
+ : _client( currentClient.get() ),
+ _justCreated(false), // set for real in finishInit
+ _doVersion(doVersion),
+ _ns( ns ),
+ _db(NULL),
+ _txn(txn) {
+
_finishInit();
}
@@ -191,7 +195,7 @@ namespace mongo {
_lk.reset(new Lock::DBRead(txn->lockState(), ns));
Database *db = dbHolder().get(txn, ns);
if( db ) {
- _c.reset(new Context(ns, db, doVersion));
+ _c.reset(new Context(txn, ns, db, doVersion));
return;
}
}
@@ -202,18 +206,18 @@ namespace mongo {
if (txn->lockState()->isW()) {
// write locked already
DEV RARELY log() << "write locked on ReadContext construction " << ns << endl;
- _c.reset(new Context(ns, doVersion));
+ _c.reset(new Context(txn, ns, doVersion));
}
else if (!txn->lockState()->isRecursive()) {
_lk.reset(0);
{
Lock::GlobalWrite w(txn->lockState());
- Context c(ns, doVersion);
+ Context c(txn, ns, doVersion);
}
// db could be closed at this interim point -- that is ok, we will throw, and don't mind throwing.
_lk.reset(new Lock::DBRead(txn->lockState(), ns));
- _c.reset(new Context(ns, doVersion));
+ _c.reset(new Context(txn, ns, doVersion));
}
else {
uasserted(15928, str::stream() << "can't open a database from a nested read lock " << ns);
@@ -228,7 +232,8 @@ namespace mongo {
Client::WriteContext::WriteContext(
OperationContext* opCtx, const std::string& ns, bool doVersion)
: _lk(opCtx->lockState(), ns),
- _c(ns, doVersion) {
+ _c(opCtx, ns, doVersion) {
+
}
@@ -252,21 +257,24 @@ namespace mongo {
}
// invoked from ReadContext
- Client::Context::Context(const string& ns, Database *db, bool doVersion) :
- _client( currentClient.get() ),
- _justCreated(false),
- _doVersion( doVersion ),
- _ns( ns ),
- _db(db)
- {
+ Client::Context::Context(OperationContext* txn,
+ const string& ns,
+ Database *db,
+ bool doVersion)
+ : _client( currentClient.get() ),
+ _justCreated(false),
+ _doVersion( doVersion ),
+ _ns( ns ),
+ _db(db),
+ _txn(txn) {
+
verify(_db);
if (_doVersion) checkNotStale();
_client->_curOp->enter( this );
}
void Client::Context::_finishInit() {
- OperationContextImpl txn; // TODO get rid of this once reads require transactions
- _db = dbHolder().getOrCreate(&txn, _ns, _justCreated);
+ _db = dbHolder().getOrCreate(_txn, _ns, _justCreated);
invariant(_db);
if( _doVersion ) checkNotStale();
@@ -276,7 +284,11 @@ namespace mongo {
Client::Context::~Context() {
DEV verify( _client == currentClient.get() );
- _client->_curOp->recordGlobalTime( _timer.micros() );
+
+ // Lock must still be held
+ invariant(_txn->lockState()->isLocked());
+
+ _client->_curOp->recordGlobalTime(_txn->lockState()->isWriteLocked(), _timer.micros());
}
void Client::appendLastOp( BSONObjBuilder& b ) const {
diff --git a/src/mongo/db/client.h b/src/mongo/db/client.h
index 48a8d74dd18..cf5c9f38964 100644
--- a/src/mongo/db/client.h
+++ b/src/mongo/db/client.h
@@ -157,20 +157,20 @@ namespace mongo {
/* Set database we want to use, then, restores when we finish (are out of scope)
Note this is also helpful if an exception happens as the state if fixed up.
*/
- class Context : boost::noncopyable {
+ class Context {
+ MONGO_DISALLOW_COPYING(Context);
public:
/** this is probably what you want */
- Context(const std::string& ns,
- bool doVersion = true);
+ Context(OperationContext* txn, const std::string& ns, bool doVersion = true);
/** note: this does not call finishInit -- i.e., does not call
shardVersionOk() for example.
see also: reset().
*/
- Context(const std::string& ns , Database * db);
+ Context(OperationContext* txn, const std::string& ns, Database * db);
// used by ReadContext
- Context(const std::string& ns, Database *db, bool doVersion );
+ Context(OperationContext* txn, const std::string& ns, Database *db, bool doVersion);
~Context();
Client* getClient() const { return _client; }
@@ -199,6 +199,7 @@ namespace mongo {
bool _doVersion;
const std::string _ns;
Database * _db;
+ OperationContext* _txn;
Timer _timer;
}; // class Client::Context
diff --git a/src/mongo/db/commands/apply_ops.cpp b/src/mongo/db/commands/apply_ops.cpp
index 88c8c66f484..b3fa1b6ce2e 100644
--- a/src/mongo/db/commands/apply_ops.cpp
+++ b/src/mongo/db/commands/apply_ops.cpp
@@ -133,7 +133,7 @@ namespace mongo {
Lock::DBWrite lk(txn->lockState(), ns);
invariant(txn->lockState()->isRecursive());
- Client::Context ctx(ns);
+ Client::Context ctx(txn, ns);
bool failed = repl::applyOperation_inlock(txn,
ctx.db(),
temp,
diff --git a/src/mongo/db/commands/collection_to_capped.cpp b/src/mongo/db/commands/collection_to_capped.cpp
index 7299f0abf29..476d80edf08 100644
--- a/src/mongo/db/commands/collection_to_capped.cpp
+++ b/src/mongo/db/commands/collection_to_capped.cpp
@@ -60,7 +60,7 @@ namespace mongo {
// create new collection
{
- Client::Context ctx( toNs );
+ Client::Context ctx(txn, toNs );
BSONObjBuilder spec;
spec.appendBool( "capped", true );
spec.append( "size", size );
@@ -153,7 +153,7 @@ namespace mongo {
}
Lock::DBWrite dbXLock(txn->lockState(), dbname);
- Client::Context ctx(dbname);
+ Client::Context ctx(txn, dbname);
Status status = cloneCollectionAsCapped( txn, ctx.db(), from, to, size, temp, true );
return appendCommandStatus( result, status );
@@ -200,7 +200,7 @@ namespace mongo {
// calls renamecollection which does a global lock, so we must too:
//
Lock::GlobalWrite globalWriteLock(txn->lockState());
- Client::Context ctx(dbname);
+ Client::Context ctx(txn, dbname);
Database* db = ctx.db();
diff --git a/src/mongo/db/commands/compact.cpp b/src/mongo/db/commands/compact.cpp
index e9d4ca106d8..c0df090d29a 100644
--- a/src/mongo/db/commands/compact.cpp
+++ b/src/mongo/db/commands/compact.cpp
@@ -142,7 +142,7 @@ namespace mongo {
Lock::DBWrite lk(txn->lockState(), ns.ns());
BackgroundOperation::assertNoBgOpInProgForNs(ns.ns());
- Client::Context ctx(ns);
+ Client::Context ctx(txn, ns);
Collection* collection = ctx.db()->getCollection(txn, ns.ns());
if( ! collection ) {
diff --git a/src/mongo/db/commands/count.cpp b/src/mongo/db/commands/count.cpp
index 48ebb4422e1..aa43882ea78 100644
--- a/src/mongo/db/commands/count.cpp
+++ b/src/mongo/db/commands/count.cpp
@@ -73,7 +73,7 @@ namespace mongo {
string &err,
int &errCode) {
// Lock 'ns'.
- Client::Context cx(ns);
+ Client::Context cx(txn, ns);
Collection* collection = cx.db()->getCollection(txn, ns);
if (NULL == collection) {
diff --git a/src/mongo/db/commands/cpuprofile.cpp b/src/mongo/db/commands/cpuprofile.cpp
index b6c6f923f83..de614b8a553 100644
--- a/src/mongo/db/commands/cpuprofile.cpp
+++ b/src/mongo/db/commands/cpuprofile.cpp
@@ -136,7 +136,7 @@ namespace mongo {
BSONObjBuilder &result,
bool fromRepl ) {
Lock::DBWrite dbXLock(db);
- Client::Context ctx(db);
+ Client::Context ctx(txn, db);
std::string profileFilename = cmdObj[commandName]["profileFilename"].String();
if ( ! ::ProfilerStart( profileFilename.c_str() ) ) {
@@ -154,7 +154,7 @@ namespace mongo {
BSONObjBuilder &result,
bool fromRepl ) {
Lock::DBWrite dbXLock(db);
- Client::Context ctx(db);
+ Client::Context ctx(txn, db);
::ProfilerStop();
return true;
diff --git a/src/mongo/db/commands/drop_indexes.cpp b/src/mongo/db/commands/drop_indexes.cpp
index c659454d684..d5491d166e7 100644
--- a/src/mongo/db/commands/drop_indexes.cpp
+++ b/src/mongo/db/commands/drop_indexes.cpp
@@ -110,7 +110,7 @@ namespace mongo {
LOG(0) << "CMD: dropIndexes " << toDeleteNs << endl;
}
- Client::Context ctx(toDeleteNs);
+ Client::Context ctx(txn, toDeleteNs);
Database* db = ctx.db();
Collection* collection = db->getCollection( txn, toDeleteNs );
@@ -222,7 +222,7 @@ namespace mongo {
LOG(0) << "CMD: reIndex " << toDeleteNs << endl;
Lock::DBWrite dbXLock(txn->lockState(), dbname);
- Client::Context ctx(toDeleteNs);
+ Client::Context ctx(txn, toDeleteNs);
Collection* collection = ctx.db()->getCollection( txn, toDeleteNs );
diff --git a/src/mongo/db/commands/find_and_modify.cpp b/src/mongo/db/commands/find_and_modify.cpp
index 7c3221cbbb6..3981705ed00 100644
--- a/src/mongo/db/commands/find_and_modify.cpp
+++ b/src/mongo/db/commands/find_and_modify.cpp
@@ -94,7 +94,7 @@ namespace mongo {
}
Lock::DBWrite dbXLock(txn->lockState(), dbname);
- Client::Context ctx(ns);
+ Client::Context ctx(txn, ns);
return runNoDirectClient( txn, ns ,
query , fields , update ,
@@ -134,7 +134,7 @@ namespace mongo {
string& errmsg) {
Lock::DBWrite lk(txn->lockState(), ns);
- Client::Context cx( ns );
+ Client::Context cx(txn, ns);
Collection* collection = cx.db()->getCollection( txn, ns );
const WhereCallbackReal whereCallback = WhereCallbackReal(StringData(ns));
@@ -330,7 +330,7 @@ namespace mongo {
}
Lock::DBWrite dbXLock(txn->lockState(), dbname);
- Client::Context ctx(ns);
+ Client::Context ctx(txn, ns);
BSONObj out = db.findOne(ns, q, fields);
if (out.isEmpty()) {
diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp
index 38dbceefe4d..b359a6fa3e4 100644
--- a/src/mongo/db/commands/mr.cpp
+++ b/src/mongo/db/commands/mr.cpp
@@ -588,7 +588,7 @@ namespace mongo {
bool found;
{
- Client::Context tx( _config.outputOptions.finalNamespace );
+ Client::Context tx(txn, _config.outputOptions.finalNamespace);
Collection* coll =
tx.db()->getCollection(_txn, _config.outputOptions.finalNamespace);
found = Helpers::findOne(_txn,
@@ -1290,7 +1290,7 @@ namespace mongo {
// This context does no version check, safe b/c we checked earlier and have an
// open cursor
- scoped_ptr<Client::Context> ctx(new Client::Context(config.ns, false));
+ scoped_ptr<Client::Context> ctx(new Client::Context(txn, config.ns, false));
const NamespaceString nss(config.ns);
const WhereCallbackReal whereCallback(nss.db());
@@ -1349,7 +1349,8 @@ namespace mongo {
lock.reset();
state.reduceAndSpillInMemoryStateIfNeeded();
lock.reset(new Lock::DBRead(txn->lockState(), config.ns));
- ctx.reset(new Client::Context(config.ns, false));
+
+ ctx.reset(new Client::Context(txn, config.ns, false));
reduceTime += t.micros();
diff --git a/src/mongo/db/commands/rename_collection.cpp b/src/mongo/db/commands/rename_collection.cpp
index bae48fcc17f..a25b2e19a09 100644
--- a/src/mongo/db/commands/rename_collection.cpp
+++ b/src/mongo/db/commands/rename_collection.cpp
@@ -139,7 +139,7 @@ namespace mongo {
std::vector<BSONObj> indexesInProg;
{
- Client::Context srcCtx( source );
+ Client::Context srcCtx(txn, source);
Collection* sourceColl = srcCtx.db()->getCollection( txn, source );
if ( !sourceColl ) {
@@ -182,7 +182,7 @@ namespace mongo {
}
{
- Client::Context ctx( target );
+ Client::Context ctx(txn, target );
// Check if the target namespace exists and if dropTarget is true.
// If target exists and dropTarget is not true, return false.
@@ -245,7 +245,7 @@ namespace mongo {
Collection* sourceColl = NULL;
{
- Client::Context srcCtx( source );
+ Client::Context srcCtx(txn, source);
sourceColl = srcCtx.db()->getCollection( txn, source );
sourceIt.reset( sourceColl->getIterator( DiskLoc(), false, CollectionScanParams::FORWARD ) );
}
@@ -254,12 +254,12 @@ namespace mongo {
while ( !sourceIt->isEOF() ) {
BSONObj o;
{
- Client::Context srcCtx( source );
+ Client::Context srcCtx(txn, source);
o = sourceColl->docFor(sourceIt->getNext());
}
// Insert and check return status of insert.
{
- Client::Context ctx( target );
+ Client::Context ctx(txn, target );
if ( !targetColl )
targetColl = ctx.db()->getCollection( txn, target );
// No logOp necessary because the entire renameCollection command is one logOp.
@@ -275,7 +275,7 @@ namespace mongo {
// If inserts were unsuccessful, drop the target collection and return false.
if ( !insertSuccessful ) {
- Client::Context ctx( target );
+ Client::Context ctx(txn, target );
Status s = ctx.db()->dropCollection( txn, target );
if ( !s.isOK() )
errmsg = s.toString();
@@ -287,7 +287,7 @@ namespace mongo {
vector<BSONObj> copiedIndexes;
bool indexSuccessful = true;
{
- Client::Context srcCtx( source );
+ Client::Context srcCtx(txn, source);
IndexCatalog::IndexIterator sourceIndIt =
sourceColl->getIndexCatalog()->getIndexIterator( true );
@@ -313,7 +313,7 @@ namespace mongo {
}
{
- Client::Context ctx( target );
+ Client::Context ctx(txn, target );
if ( !targetColl )
targetColl = ctx.db()->getCollection( txn, target );
@@ -339,7 +339,7 @@ namespace mongo {
// Drop the source collection.
{
- Client::Context srcCtx( source );
+ Client::Context srcCtx(txn, source);
Status s = srcCtx.db()->dropCollection( txn, source );
if ( !s.isOK() ) {
errmsg = s.toString();
diff --git a/src/mongo/db/commands/test_commands.cpp b/src/mongo/db/commands/test_commands.cpp
index 58d5e143a11..20175588afc 100644
--- a/src/mongo/db/commands/test_commands.cpp
+++ b/src/mongo/db/commands/test_commands.cpp
@@ -62,7 +62,7 @@ namespace mongo {
BSONObj obj = cmdObj[ "obj" ].embeddedObjectUserCheck();
Lock::DBWrite lk(txn->lockState(), ns);
- Client::Context ctx( ns );
+ Client::Context ctx(txn, ns );
Database* db = ctx.db();
Collection* collection = db->getCollection( txn, ns );
if ( !collection ) {
diff --git a/src/mongo/db/commands/write_commands/batch_executor.cpp b/src/mongo/db/commands/write_commands/batch_executor.cpp
index 52acb7aae6f..39b5e7c0014 100644
--- a/src/mongo/db/commands/write_commands/batch_executor.cpp
+++ b/src/mongo/db/commands/write_commands/batch_executor.cpp
@@ -918,8 +918,9 @@ namespace mongo {
if (!checkIndexConstraints(txn, &shardingState, *request, result)) {
return false;
}
- _context.reset(new Client::Context(request->getNS(),
- false /* don't check version */));
+
+ _context.reset(new Client::Context(txn, request->getNS(), false));
+
Database* database = _context->db();
dassert(database);
_collection = database->getCollection(txn, request->getTargetingNS());
@@ -1098,7 +1099,7 @@ namespace mongo {
if (!checkShardVersion(txn, &shardingState, *updateItem.getRequest(), result))
return;
- Client::Context ctx(nsString.ns(), false /* don't check version */);
+ Client::Context ctx(txn, nsString.ns(), false /* don't check version */);
try {
UpdateResult res = executor.execute(txn, ctx.db());
@@ -1159,8 +1160,7 @@ namespace mongo {
// Context once we're locked, to set more details in currentOp()
// TODO: better constructor?
- Client::Context writeContext( nss.ns(),
- false /* don't check version */);
+ Client::Context writeContext(txn, nss.ns(), false /* don't check version */);
try {
result->getStats().n = executor.execute(txn, writeContext.db());
diff --git a/src/mongo/db/curop.cpp b/src/mongo/db/curop.cpp
index 178166402d3..2f968ca4979 100644
--- a/src/mongo/db/curop.cpp
+++ b/src/mongo/db/curop.cpp
@@ -158,12 +158,8 @@ namespace mongo {
_dbprofile = std::max( context->_db ? context->_db->getProfilingLevel() : 0 , _dbprofile );
}
- void CurOp::recordGlobalTime( long long micros ) const {
- if ( _client ) {
- const LockState& ls = _client->lockState();
- verify( ls.threadState() );
- Top::global.record( _ns , _op , ls.isWriteLocked() ? 1 : -1 , micros , _isCommand );
- }
+ void CurOp::recordGlobalTime(bool isWriteLocked, long long micros) const {
+ Top::global.record(_ns, _op, isWriteLocked ? 1 : -1, micros, _isCommand);
}
void CurOp::reportState(BSONObjBuilder* builder) {
diff --git a/src/mongo/db/curop.h b/src/mongo/db/curop.h
index f24da292c98..ee52d2682a9 100644
--- a/src/mongo/db/curop.h
+++ b/src/mongo/db/curop.h
@@ -305,7 +305,7 @@ namespace mongo {
long long getExpectedLatencyMs() const { return _expectedLatencyMs; }
void setExpectedLatencyMs( long long latency ) { _expectedLatencyMs = latency; }
- void recordGlobalTime( long long micros ) const;
+ void recordGlobalTime(bool isWriteLocked, long long micros) const;
const LockStat& lockStat() const { return _lockStat; }
LockStat& lockStat() { return _lockStat; }
diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp
index 913419ef4f0..75242557c32 100644
--- a/src/mongo/db/db.cpp
+++ b/src/mongo/db/db.cpp
@@ -335,7 +335,7 @@ namespace mongo {
string dbName = *i;
LOG(1) << "\t" << dbName << endl;
- Client::Context ctx( dbName );
+ Client::Context ctx(&txn, dbName );
if (repl::replSettings.usingReplSets()) {
// we only care about the _id index if we are in a replset
diff --git a/src/mongo/db/dbcommands.cpp b/src/mongo/db/dbcommands.cpp
index 4d7f8000f15..8dfc574c064 100644
--- a/src/mongo/db/dbcommands.cpp
+++ b/src/mongo/db/dbcommands.cpp
@@ -181,7 +181,7 @@ namespace mongo {
// this is suboptimal but syncDataAndTruncateJournal is called from dropDatabase,
// and that may need a global lock.
Lock::GlobalWrite lk(txn->lockState());
- Client::Context context(dbname);
+ Client::Context context(txn, dbname);
log() << "dropDatabase " << dbname << " starting" << endl;
@@ -258,7 +258,7 @@ namespace mongo {
// SERVER-4328 todo don't lock globally. currently syncDataAndTruncateJournal is being
// called within, and that requires a global lock i believe.
Lock::GlobalWrite lk(txn->lockState());
- Client::Context context( dbname );
+ Client::Context context(txn, dbname );
log() << "repairDatabase " << dbname;
std::vector<BSONObj> indexesInProg = stopIndexBuilds(txn, context.db(), cmdObj);
@@ -331,7 +331,7 @@ namespace mongo {
// in the local database.
//
Lock::DBWrite dbXLock(txn->lockState(), dbname);
- Client::Context ctx(dbname);
+ Client::Context ctx(txn, dbname);
BSONElement e = cmdObj.firstElement();
result.append("was", ctx.db()->getProfilingLevel());
@@ -381,7 +381,7 @@ namespace mongo {
// locking, but originally the lock was set to be WRITE, so preserving the behaviour.
//
Lock::DBWrite dbXLock(txn->lockState(), dbname);
- Client::Context ctx(dbname);
+ Client::Context ctx(txn, dbname);
int was = _diaglog.setLevel( cmdObj.firstElement().numberInt() );
_diaglog.flush();
@@ -436,7 +436,7 @@ namespace mongo {
}
Lock::DBWrite dbXLock(txn->lockState(), dbname);
- Client::Context ctx(nsToDrop);
+ Client::Context ctx(txn, nsToDrop);
Database* db = ctx.db();
Collection* coll = db->getCollection( txn, nsToDrop );
@@ -534,7 +534,7 @@ namespace mongo {
options.hasField("$nExtents"));
Lock::DBWrite dbXLock(txn->lockState(), dbname);
- Client::Context ctx(ns);
+ Client::Context ctx(txn, ns);
// Create collection.
return appendCommandStatus( result,
@@ -648,7 +648,7 @@ namespace mongo {
bool run(OperationContext* txn, const string& dbname , BSONObj& jsobj, int, string& errmsg, BSONObjBuilder& result, bool /*fromRepl*/) {
Lock::GlobalWrite globalWriteLock(txn->lockState());
- Client::Context ctx(dbname);
+ Client::Context ctx(txn, dbname);
try {
return dbHolder().closeAll(txn, result, false);
@@ -1032,7 +1032,7 @@ namespace mongo {
const string ns = dbname + "." + jsobj.firstElement().valuestr();
Lock::DBWrite dbXLock(txn->lockState(), dbname);
- Client::Context ctx( ns );
+ Client::Context ctx(txn, ns );
Collection* coll = ctx.db()->getCollection( txn, ns );
if ( !coll ) {
diff --git a/src/mongo/db/dbeval.cpp b/src/mongo/db/dbeval.cpp
index f2076e97178..e5bd01890e7 100644
--- a/src/mongo/db/dbeval.cpp
+++ b/src/mongo/db/dbeval.cpp
@@ -143,7 +143,7 @@ namespace mongo {
}
Lock::GlobalWrite lk(txn->lockState());
- Client::Context ctx( dbname );
+ Client::Context ctx(txn, dbname );
return dbEval(dbname, cmdObj, result, errmsg);
}
diff --git a/src/mongo/db/dbhelpers.cpp b/src/mongo/db/dbhelpers.cpp
index abbeea15a86..0de77233f93 100644
--- a/src/mongo/db/dbhelpers.cpp
+++ b/src/mongo/db/dbhelpers.cpp
@@ -181,7 +181,7 @@ namespace mongo {
Returns: true if object exists.
*/
bool Helpers::getSingleton(OperationContext* txn, const char *ns, BSONObj& result) {
- Client::Context context(ns);
+ Client::Context context(txn, ns);
auto_ptr<Runner> runner(InternalPlanner::collectionScan(ns,
context.db()->getCollection(txn,
ns)));
@@ -191,7 +191,7 @@ namespace mongo {
}
bool Helpers::getLast(OperationContext* txn, const char *ns, BSONObj& result) {
- Client::Context ctx(ns);
+ Client::Context ctx(txn, ns);
Collection* coll = ctx.db()->getCollection( txn, ns );
auto_ptr<Runner> runner(InternalPlanner::collectionScan(ns,
coll,
@@ -209,7 +209,7 @@ namespace mongo {
BSONObj id = e.wrap();
OpDebug debug;
- Client::Context context(ns);
+ Client::Context context(txn, ns);
const NamespaceString requestNs(ns);
UpdateRequest request(requestNs);
@@ -227,7 +227,7 @@ namespace mongo {
void Helpers::putSingleton(OperationContext* txn, const char *ns, BSONObj obj) {
OpDebug debug;
- Client::Context context(ns);
+ Client::Context context(txn, ns);
const NamespaceString requestNs(ns);
UpdateRequest request(requestNs);
@@ -245,7 +245,7 @@ namespace mongo {
void Helpers::putSingletonGod(OperationContext* txn, const char *ns, BSONObj obj, bool logTheOp) {
OpDebug debug;
- Client::Context context(ns);
+ Client::Context context(txn, ns);
const NamespaceString requestNs(ns);
UpdateRequest request(requestNs);
@@ -546,7 +546,7 @@ namespace mongo {
void Helpers::emptyCollection(OperationContext* txn, const char *ns) {
- Client::Context context(ns);
+ Client::Context context(txn, ns);
deleteObjects(txn, context.db(), ns, BSONObj(), false);
}
diff --git a/src/mongo/db/instance.cpp b/src/mongo/db/instance.cpp
index 745ab93bd52..3edb27e5e65 100644
--- a/src/mongo/db/instance.cpp
+++ b/src/mongo/db/instance.cpp
@@ -615,7 +615,7 @@ namespace mongo {
if ( ! broadcast && handlePossibleShardedMessage( m , 0 ) )
return;
- Client::Context ctx( ns );
+ Client::Context ctx(txn, ns );
UpdateResult res = executor.execute(txn, ctx.db());
@@ -654,7 +654,7 @@ namespace mongo {
if ( ! broadcast && handlePossibleShardedMessage( m , 0 ) )
return;
- Client::Context ctx(ns);
+ Client::Context ctx(txn, ns);
long long n = executor.execute(txn, ctx.db());
lastError.getSafe()->recordDelete( n );
@@ -895,7 +895,7 @@ namespace mongo {
if ( handlePossibleShardedMessage( m , 0 ) )
return;
- Client::Context ctx(ns);
+ Client::Context ctx(txn, ns);
if (multi.size() > 1) {
const bool keepGoing = d.reservedField() & InsertOption_ContinueOnError;
diff --git a/src/mongo/db/introspect.cpp b/src/mongo/db/introspect.cpp
index 667964aee1a..87b74e6201a 100644
--- a/src/mongo/db/introspect.cpp
+++ b/src/mongo/db/introspect.cpp
@@ -138,8 +138,7 @@ namespace {
// we're sometimes inside the lock already
Lock::DBWrite lk(txn->lockState(), currentOp.getNS() );
if (dbHolder().get(txn, nsToDatabase(currentOp.getNS())) != NULL) {
-
- Client::Context cx(currentOp.getNS(), false);
+ Client::Context cx(txn, currentOp.getNS(), false);
_profile(txn, c, cx.db(), currentOp, profileBufBuilder);
}
else {
diff --git a/src/mongo/db/operation_context_impl.h b/src/mongo/db/operation_context_impl.h
index 3acadbca4a5..ed681f1940a 100644
--- a/src/mongo/db/operation_context_impl.h
+++ b/src/mongo/db/operation_context_impl.h
@@ -25,13 +25,13 @@
* exception statement from all source files in the program, then also delete
* it in the license file.
*/
+#pragma once
#include <boost/scoped_ptr.hpp>
#include <string>
#include "mongo/db/operation_context.h"
-#pragma once
namespace mongo {
diff --git a/src/mongo/db/operation_context_noop.h b/src/mongo/db/operation_context_noop.h
index 527348b1537..f3964494936 100644
--- a/src/mongo/db/operation_context_noop.h
+++ b/src/mongo/db/operation_context_noop.h
@@ -25,13 +25,13 @@
* exception statement from all source files in the program, then also delete
* it in the license file.
*/
+#pragma once
#include "mongo/db/operation_context.h"
#include "mongo/db/client.h"
#include "mongo/db/curop.h"
-
#include "mongo/db/storage/recovery_unit_noop.h"
-#pragma once
+
namespace mongo {
diff --git a/src/mongo/db/pipeline/document_source_cursor.cpp b/src/mongo/db/pipeline/document_source_cursor.cpp
index 62b8b52645a..6c4d8c5d6c0 100644
--- a/src/mongo/db/pipeline/document_source_cursor.cpp
+++ b/src/mongo/db/pipeline/document_source_cursor.cpp
@@ -80,7 +80,7 @@ namespace mongo {
// We have already validated the sharding version when we constructed the Runner
// so we shouldn't check it again.
Lock::DBRead lk(pExpCtx->opCtx->lockState(), _ns);
- Client::Context ctx(_ns, /*doVersion=*/false);
+ Client::Context ctx(pExpCtx->opCtx, _ns, /*doVersion=*/false);
_runner->restoreState(pExpCtx->opCtx);
@@ -200,7 +200,8 @@ namespace {
scoped_ptr<TypeExplain> plan;
{
Lock::DBRead lk(pExpCtx->opCtx->lockState(), _ns);
- Client::Context ctx(_ns, /*doVersion=*/false);
+ Client::Context ctx(pExpCtx->opCtx, _ns, /*doVersion=*/ false);
+
massert(17392, "No _runner. Were we disposed before explained?",
_runner);
diff --git a/src/mongo/db/repl/master_slave.cpp b/src/mongo/db/repl/master_slave.cpp
index 2b3eca3de42..bdbbc14cc41 100644
--- a/src/mongo/db/repl/master_slave.cpp
+++ b/src/mongo/db/repl/master_slave.cpp
@@ -196,9 +196,10 @@ namespace repl {
LOG( 1 ) << "Saving repl source: " << o << endl;
{
- OpDebug debug;
- Client::Context ctx("local.sources");
OperationContextImpl txn;
+ OpDebug debug;
+
+ Client::Context ctx(&txn, "local.sources");
const NamespaceString requestNs("local.sources");
UpdateRequest request(requestNs);
@@ -234,7 +235,7 @@ namespace repl {
*/
void ReplSource::loadAll(OperationContext* txn, SourceVector &v) {
const char* localSources = "local.sources";
- Client::Context ctx(localSources);
+ Client::Context ctx(txn, localSources);
SourceVector old = v;
v.clear();
@@ -364,7 +365,7 @@ namespace repl {
void ReplSource::resyncDrop( OperationContext* txn, const string& db ) {
log() << "resync: dropping database " << db;
- Client::Context ctx(db);
+ Client::Context ctx(txn, db);
dropDatabase(txn, ctx.db());
}
@@ -513,8 +514,9 @@ namespace repl {
___databaseIgnorer.doIgnoreUntilAfter( *i, lastTime );
incompleteCloneDbs.erase(*i);
addDbNextPass.erase(*i);
- Client::Context ctx(*i);
- dropDatabase(txn, ctx.db() );
+
+ Client::Context ctx(txn, *i);
+ dropDatabase(txn, ctx.db());
}
massert(14034, "Duplicate database names present after attempting to delete duplicates",
@@ -626,11 +628,11 @@ namespace repl {
if (!handleDuplicateDbName(txn, op, ns, clientName)) {
return;
}
-
+
// This code executes on the slaves only, so it doesn't need to be sharding-aware since
// mongos will not send requests there. That's why the last argument is false (do not do
// version checking).
- Client::Context ctx(ns, false);
+ Client::Context ctx(txn, ns, false);
ctx.getClient()->curop()->reset();
bool empty = ctx.db()->getDatabaseCatalogEntry()->isEmpty();
@@ -661,7 +663,7 @@ namespace repl {
log() << "An earlier initial clone of '" << clientName << "' did not complete, now resyncing." << endl;
}
save();
- Client::Context ctx(ns);
+ Client::Context ctx(txn, ns);
nClonedThisPass++;
resync(txn, ctx.db()->name());
addDbNextPass.erase(clientName);
@@ -1285,7 +1287,7 @@ namespace repl {
BSONObjBuilder b;
b.append(_id);
BSONObj result;
- Client::Context ctx( ns );
+ Client::Context ctx(&txn, ns);
if( Helpers::findById(&txn, ctx.db(), ns, b.done(), result) )
_dummy_z += result.objsize(); // touch
}
diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp
index 632986c9426..18754046e2f 100644
--- a/src/mongo/db/repl/oplog.cpp
+++ b/src/mongo/db/repl/oplog.cpp
@@ -123,7 +123,8 @@ namespace repl {
{
if ( localOplogRSCollection == 0 ) {
- Client::Context ctx(rsoplog);
+ Client::Context ctx(&txn, rsoplog);
+
localDB = ctx.db();
verify( localDB );
localOplogRSCollection = localDB->getCollection( &txn, rsoplog );
@@ -131,7 +132,7 @@ namespace repl {
"local.oplog.rs missing. did you drop it? if so restart server",
localOplogRSCollection);
}
- Client::Context ctx(rsoplog, localDB);
+ Client::Context ctx(&txn, rsoplog, localDB);
checkOplogInsert( localOplogRSCollection->insertDocument( &txn, op, false ) );
/* todo: now() has code to handle clock skew. but if the skew server to server is large it will get unhappy.
@@ -283,14 +284,14 @@ namespace repl {
DEV verify( logNS == 0 ); // check this was never a master/slave master
if ( localOplogRSCollection == 0 ) {
- Client::Context ctx(rsoplog);
+ Client::Context ctx(txn, rsoplog);
localDB = ctx.db();
verify( localDB );
localOplogRSCollection = localDB->getCollection( txn, rsoplog );
massert(13347, "local.oplog.rs missing. did you drop it? if so restart server", localOplogRSCollection);
}
- Client::Context ctx(rsoplog, localDB);
+ Client::Context ctx(txn, rsoplog, localDB);
OplogDocWriter writer( partial, obj );
checkOplogInsert( localOplogRSCollection->insertDocument( txn, &writer, false ) );
@@ -361,14 +362,14 @@ namespace repl {
}
if ( localOplogMainCollection == 0 ) {
- Client::Context ctx(logNS);
+ Client::Context ctx(txn, logNS);
localDB = ctx.db();
verify( localDB );
localOplogMainCollection = localDB->getCollection(txn, logNS);
verify( localOplogMainCollection );
}
- Client::Context ctx(logNS , localDB);
+ Client::Context ctx(txn, logNS , localDB);
OplogDocWriter writer( partial, obj );
checkOplogInsert( localOplogMainCollection->insertDocument( txn, &writer, false ) );
@@ -454,7 +455,7 @@ namespace repl {
if( rs )
ns = rsoplog;
- Client::Context ctx(ns);
+ Client::Context ctx(&txn, ns);
Collection* collection = ctx.db()->getCollection( &txn, ns );
if ( collection ) {
diff --git a/src/mongo/db/repl/repl_set_impl.cpp b/src/mongo/db/repl/repl_set_impl.cpp
index 5a9d393ae4e..030da5fc532 100644
--- a/src/mongo/db/repl/repl_set_impl.cpp
+++ b/src/mongo/db/repl/repl_set_impl.cpp
@@ -105,7 +105,7 @@ namespace {
if (*it == "local")
continue;
- Client::Context ctx(*it);
+ Client::Context ctx(&txn, *it);
ctx.db()->clearTmpCollections(&txn);
}
}
diff --git a/src/mongo/db/repl/resync.cpp b/src/mongo/db/repl/resync.cpp
index d1c693d4b92..ca16a00139a 100644
--- a/src/mongo/db/repl/resync.cpp
+++ b/src/mongo/db/repl/resync.cpp
@@ -68,7 +68,7 @@ namespace repl {
const std::string ns = parseNs(dbname, cmdObj);
Lock::GlobalWrite globalWriteLock(txn->lockState());
- Client::Context ctx(ns);
+ Client::Context ctx(txn, ns);
if (replSettings.usingReplSets()) {
if (!theReplSet) {
errmsg = "no replication yet active";
diff --git a/src/mongo/db/repl/rs_rollback.cpp b/src/mongo/db/repl/rs_rollback.cpp
index 985d751aa8e..19a2b70fbf7 100644
--- a/src/mongo/db/repl/rs_rollback.cpp
+++ b/src/mongo/db/repl/rs_rollback.cpp
@@ -230,7 +230,7 @@ namespace repl {
int getRBID(DBClientConnection*);
static void syncRollbackFindCommonPoint(OperationContext* txn, DBClientConnection* them, FixUpInfo& fixUpInfo) {
- Client::Context ctx(rsoplog);
+ Client::Context ctx(txn, rsoplog);
boost::scoped_ptr<Runner> runner(
InternalPlanner::collectionScan(rsoplog,
@@ -499,13 +499,13 @@ namespace repl {
for (set<string>::iterator it = fixUpInfo.toDrop.begin();
it != fixUpInfo.toDrop.end();
it++) {
- Client::Context ctx(*it);
+ Client::Context ctx(txn, *it);
log() << "replSet rollback drop: " << *it << rsLog;
ctx.db()->dropCollection(txn, *it);
}
sethbmsg("rollback 4.7");
- Client::Context ctx(rsoplog);
+ Client::Context ctx(txn, rsoplog);
Collection* oplogCollection = ctx.db()->getCollection(txn, rsoplog);
uassert(13423,
str::stream() << "replSet error in rollback can't find " << rsoplog,
@@ -543,7 +543,7 @@ namespace repl {
removeSaver.reset(new Helpers::RemoveSaver("rollback", "", doc.ns));
// todo: lots of overhead in context, this can be faster
- Client::Context ctx(doc.ns);
+ Client::Context ctx(txn, doc.ns);
// Add the doc to our rollback file
BSONObj obj;
diff --git a/src/mongo/db/repl/rs_sync.cpp b/src/mongo/db/repl/rs_sync.cpp
index 41b7247bd52..b0a16002336 100644
--- a/src/mongo/db/repl/rs_sync.cpp
+++ b/src/mongo/db/repl/rs_sync.cpp
@@ -228,8 +228,9 @@ namespace repl {
bool ReplSetImpl::resync(string& errmsg) {
changeState(MemberState::RS_RECOVERING);
- Client::Context ctx("local");
OperationContextImpl txn;
+ Client::Context ctx(&txn, "local");
+
ctx.db()->dropCollection(&txn, "local.oplog.rs");
{
boost::unique_lock<boost::mutex> lock(theReplSet->initialSyncMutex);
diff --git a/src/mongo/db/repl/sync.cpp b/src/mongo/db/repl/sync.cpp
index 153e7e048e2..c9f43ebf894 100644
--- a/src/mongo/db/repl/sync.cpp
+++ b/src/mongo/db/repl/sync.cpp
@@ -109,7 +109,7 @@ namespace repl {
// should already have write lock
const char *ns = o.getStringField("ns");
- Client::Context ctx(ns);
+ Client::Context ctx(txn, ns);
// we don't have the object yet, which is possible on initial sync. get it.
log() << "replication info adding missing object" << endl; // rare enough we can log
diff --git a/src/mongo/db/repl/sync_tail.cpp b/src/mongo/db/repl/sync_tail.cpp
index 9719dceeeee..ce4e3902a59 100644
--- a/src/mongo/db/repl/sync_tail.cpp
+++ b/src/mongo/db/repl/sync_tail.cpp
@@ -106,7 +106,7 @@ namespace repl {
lk.reset(new Lock::DBWrite(txn->lockState(), ns));
}
- Client::Context ctx(ns);
+ Client::Context ctx(txn, ns);
ctx.getClient()->curop()->reset();
// For non-initial-sync, we convert updates to upserts
// to suppress errors when replaying oplog entries.
diff --git a/src/mongo/db/storage/mmap_v1/repair_database.cpp b/src/mongo/db/storage/mmap_v1/repair_database.cpp
index f1061147a70..dc9e50f1f6c 100644
--- a/src/mongo/db/storage/mmap_v1/repair_database.cpp
+++ b/src/mongo/db/storage/mmap_v1/repair_database.cpp
@@ -247,7 +247,9 @@ namespace mongo {
try {
_txn->recoveryUnit()->syncDataAndTruncateJournal();
+
globalStorageEngine->flushAllFiles(true); // need both in case journaling is disabled
+
MONGO_ASSERT_ON_EXCEPTION( boost::filesystem::remove_all( _path ) );
}
catch ( DBException& e ) {
@@ -335,7 +337,7 @@ namespace mongo {
map<string,CollectionOptions> namespacesToCopy;
{
string ns = dbName + ".system.namespaces";
- Client::Context ctx( ns );
+ Client::Context ctx(txn, ns );
Collection* coll = originalDatabase->getCollection( txn, ns );
if ( coll ) {
scoped_ptr<RecordIterator> it( coll->getIterator( DiskLoc(),
@@ -377,11 +379,11 @@ namespace mongo {
Collection* tempCollection = NULL;
{
- Client::Context tempContext( ns, tempDatabase );
+ Client::Context tempContext(txn, ns, tempDatabase );
tempCollection = tempDatabase->createCollection( txn, ns, options, true, false );
}
- Client::Context readContext( ns, originalDatabase );
+ Client::Context readContext(txn, ns, originalDatabase);
Collection* originalCollection = originalDatabase->getCollection( txn, ns );
invariant( originalCollection );
@@ -397,7 +399,7 @@ namespace mongo {
indexes.push_back( desc->infoObj() );
}
- Client::Context tempContext( ns, tempDatabase );
+ Client::Context tempContext(txn, ns, tempDatabase);
Status status = indexBlock.init( indexes );
if ( !status.isOK() )
return status;
@@ -413,7 +415,7 @@ namespace mongo {
BSONObj doc = originalCollection->docFor( loc );
- Client::Context tempContext( ns, tempDatabase );
+ Client::Context tempContext(txn, ns, tempDatabase);
StatusWith<DiskLoc> result = tempCollection->insertDocument( txn, doc, indexBlock );
if ( !result.isOK() )
return result.getStatus();
@@ -423,7 +425,7 @@ namespace mongo {
}
{
- Client::Context tempContext( ns, tempDatabase );
+ Client::Context tempContext(txn, ns, tempDatabase);
Status status = indexBlock.commit();
if ( !status.isOK() )
return status;
@@ -435,7 +437,6 @@ namespace mongo {
globalStorageEngine->flushAllFiles(true); // need both in case journaling is disabled
txn->checkForInterrupt(false);
-
}
// at this point if we abort, we don't want to delete new files
@@ -444,7 +445,7 @@ namespace mongo {
if ( repairFileDeleter.get() )
repairFileDeleter->success();
- Client::Context ctx( dbName );
+ Client::Context ctx(txn, dbName);
Database::closeDatabase(txn, dbName);
if ( backupOriginalFiles ) {
diff --git a/src/mongo/dbtests/clienttests.cpp b/src/mongo/dbtests/clienttests.cpp
index 527f52f2554..1ba539f0266 100644
--- a/src/mongo/dbtests/clienttests.cpp
+++ b/src/mongo/dbtests/clienttests.cpp
@@ -40,19 +40,23 @@ namespace ClientTests {
class Base {
public:
- Base( string coll ) {
+ Base( string coll ) : _ns("test." + coll) {
+ OperationContextImpl txn;
+ DBDirectClient db(&txn);
+
db.dropDatabase("test");
- _ns = (string)"test." + coll;
}
virtual ~Base() {
+ OperationContextImpl txn;
+ DBDirectClient db(&txn);
+
db.dropCollection( _ns );
}
const char * ns() { return _ns.c_str(); }
- string _ns;
- DBDirectClient db;
+ const string _ns;
};
@@ -60,6 +64,9 @@ namespace ClientTests {
public:
DropIndex() : Base( "dropindex" ) {}
void run() {
+ OperationContextImpl txn;
+ DBDirectClient db(&txn);
+
db.insert( ns() , BSON( "x" << 2 ) );
ASSERT_EQUALS( 1 , db.getIndexes( ns() )->itcount() );
@@ -81,6 +88,8 @@ namespace ClientTests {
public:
ReIndex() : Base( "reindex" ) {}
void run() {
+ OperationContextImpl txn;
+ DBDirectClient db(&txn);
db.insert( ns() , BSON( "x" << 2 ) );
ASSERT_EQUALS( 1 , db.getIndexes( ns() )->itcount() );
@@ -98,6 +107,8 @@ namespace ClientTests {
public:
ReIndex2() : Base( "reindex2" ) {}
void run() {
+ OperationContextImpl txn;
+ DBDirectClient db(&txn);
db.insert( ns() , BSON( "x" << 2 ) );
ASSERT_EQUALS( 1 , db.getIndexes( ns() )->itcount() );
@@ -123,7 +134,9 @@ namespace ClientTests {
BuildIndex() : Base("buildIndex") {}
void run() {
OperationContextImpl txn;
+
Client::WriteContext ctx(&txn, ns());
+ DBDirectClient db(&txn);
db.insert(ns(), BSON("x" << 1 << "y" << 2));
db.insert(ns(), BSON("x" << 2 << "y" << 2));
@@ -158,9 +171,14 @@ namespace ClientTests {
public:
CS_10() : Base( "CS_10" ) {}
void run() {
- string longs( 770, 'c' );
- for( int i = 0; i < 1111; ++i )
- db.insert( ns(), BSON( "a" << i << "b" << longs ) );
+ OperationContextImpl txn;
+ DBDirectClient db(&txn);
+
+ const string longs( 770, 'c' );
+ for (int i = 0; i < 1111; ++i) {
+ db.insert(ns(), BSON("a" << i << "b" << longs));
+ }
+
db.ensureIndex( ns(), BSON( "a" << 1 << "b" << 1 ) );
auto_ptr< DBClientCursor > c = db.query( ns(), Query().sort( BSON( "a" << 1 << "b" << 1 ) ) );
@@ -172,8 +190,13 @@ namespace ClientTests {
public:
PushBack() : Base( "PushBack" ) {}
void run() {
- for( int i = 0; i < 10; ++i )
- db.insert( ns(), BSON( "i" << i ) );
+ OperationContextImpl txn;
+ DBDirectClient db(&txn);
+
+ for (int i = 0; i < 10; ++i) {
+ db.insert(ns(), BSON("i" << i));
+ }
+
auto_ptr< DBClientCursor > c = db.query( ns(), Query().sort( BSON( "i" << 1 ) ) );
BSONObj o = c->next();
@@ -212,7 +235,10 @@ namespace ClientTests {
public:
Create() : Base( "Create" ) {}
void run() {
- db.createCollection( "unittests.clienttests.create", 4096, true );
+ OperationContextImpl txn;
+ DBDirectClient db(&txn);
+
+ db.createCollection("unittests.clienttests.create", 4096, true);
BSONObj info;
ASSERT( db.runCommand( "unittests", BSON( "collstats" << "clienttests.create" ), info ) );
}
@@ -237,6 +263,7 @@ namespace ClientTests {
class All : public Suite {
public:
All() : Suite( "client" ) {
+
}
void setupTests() {
diff --git a/src/mongo/dbtests/commandtests.cpp b/src/mongo/dbtests/commandtests.cpp
index a8aeb09bd6a..955620eac94 100644
--- a/src/mongo/dbtests/commandtests.cpp
+++ b/src/mongo/dbtests/commandtests.cpp
@@ -26,9 +26,10 @@
* then also delete it in the license file.
*/
-#include "mongo/pch.h"
+#include "mongo/platform/basic.h"
#include "mongo/db/d_concurrency.h"
+#include "mongo/db/operation_context_impl.h"
#include "mongo/dbtests/dbtests.h"
using namespace mongo;
@@ -37,13 +38,14 @@ namespace CommandTests {
// one namespace per command
namespace FileMD5 {
struct Base {
- Base() {
+ Base() : db(&_txn) {
db.dropCollection(ns());
db.ensureIndex(ns(), BSON( "files_id" << 1 << "n" << 1 ));
}
const char* ns() { return "test.fs.chunks"; }
+ OperationContextImpl _txn;
DBDirectClient db;
};
struct Type0 : Base {
diff --git a/src/mongo/dbtests/config_server_fixture.h b/src/mongo/dbtests/config_server_fixture.h
index 55c2d7f559f..f80565e1723 100644
--- a/src/mongo/dbtests/config_server_fixture.h
+++ b/src/mongo/dbtests/config_server_fixture.h
@@ -36,12 +36,18 @@
namespace mongo {
+ class OperationContext;
+
class CustomDirectClient: public DBDirectClient {
public:
CustomDirectClient() {
setWireVersions(minWireVersion, maxWireVersion);
}
+ CustomDirectClient(OperationContext* txn) : DBDirectClient(txn) {
+ setWireVersions(minWireVersion, maxWireVersion);
+ }
+
virtual ConnectionString::ConnectionType type() const {
return ConnectionString::CUSTOM;
}
diff --git a/src/mongo/dbtests/counttests.cpp b/src/mongo/dbtests/counttests.cpp
index 8e34074e2aa..f8119b632a1 100644
--- a/src/mongo/dbtests/counttests.cpp
+++ b/src/mongo/dbtests/counttests.cpp
@@ -42,7 +42,7 @@ namespace CountTests {
class Base {
public:
- Base() : lk(_txn.lockState(), ns()), _context( ns() ) {
+ Base() : lk(_txn.lockState(), ns()), _context(&_txn, ns()) {
_database = _context.db();
_collection = _database->getCollection( &_txn, ns() );
if ( _collection ) {
diff --git a/src/mongo/dbtests/dbhelper_tests.cpp b/src/mongo/dbtests/dbhelper_tests.cpp
index e0aeb507e36..88c04aece66 100644
--- a/src/mongo/dbtests/dbhelper_tests.cpp
+++ b/src/mongo/dbtests/dbhelper_tests.cpp
@@ -61,7 +61,7 @@ namespace mongo {
{
// Remove _id range [_min, _max).
Lock::DBWrite lk(txn.lockState(), ns);
- Client::Context ctx( ns );
+ Client::Context ctx(&txn, ns );
KeyRange range( ns,
BSON( "_id" << _min ),
@@ -115,9 +115,8 @@ namespace mongo {
//
TEST(DBHelperTests, FindDiskLocs) {
-
- DBDirectClient client;
OperationContextImpl txn;
+ DBDirectClient client(&txn);
// Some unique tag we can use to make sure we're pulling back the right data
OID tag = OID::gen();
@@ -170,9 +169,8 @@ namespace mongo {
//
TEST(DBHelperTests, FindDiskLocsNoIndex) {
-
- DBDirectClient client;
OperationContextImpl txn;
+ DBDirectClient client(&txn);
client.remove( ns, BSONObj() );
client.insert( ns, BSON( "_id" << OID::gen() ) );
@@ -184,7 +182,7 @@ namespace mongo {
long long estSizeBytes;
{
Lock::DBRead lk(txn.lockState(), ns);
- Client::Context ctx( ns );
+ Client::Context ctx(&txn, ns );
// search invalid index range
KeyRange range( ns,
@@ -212,9 +210,8 @@ namespace mongo {
//
TEST(DBHelperTests, FindDiskLocsTooBig) {
-
- DBDirectClient client;
OperationContextImpl txn;
+ DBDirectClient client(&txn);
client.remove( ns, BSONObj() );
@@ -231,7 +228,7 @@ namespace mongo {
long long estSizeBytes;
{
Lock::DBRead lk(txn.lockState(), ns);
- Client::Context ctx( ns );
+ Client::Context ctx(&txn, ns );
KeyRange range( ns,
BSON( "_id" << 0 ),
BSON( "_id" << numDocsInserted ),
diff --git a/src/mongo/dbtests/directclienttests.cpp b/src/mongo/dbtests/directclienttests.cpp
index 0bea6ea2399..9c96dc331fd 100644
--- a/src/mongo/dbtests/directclienttests.cpp
+++ b/src/mongo/dbtests/directclienttests.cpp
@@ -35,6 +35,7 @@
#include "mongo/db/instance.h"
#include "mongo/db/json.h"
#include "mongo/db/lasterror.h"
+#include "mongo/db/operation_context_impl.h"
#include "mongo/dbtests/dbtests.h"
#include "mongo/util/timer.h"
@@ -52,7 +53,8 @@ namespace DirectClientTests {
class Capped : public ClientBase {
public:
virtual void run() {
- DBDirectClient client;
+ OperationContextImpl txn;
+ DBDirectClient client(&txn);
for( int pass=0; pass < 3; pass++ ) {
client.createCollection(ns, 1024 * 1024, true, 999);
for( int j =0; j < pass*3; j++ )
@@ -76,7 +78,9 @@ namespace DirectClientTests {
class InsertMany : ClientBase {
public:
virtual void run(){
- DBDirectClient client;
+ OperationContextImpl txn;
+ DBDirectClient client(&txn);
+
vector<BSONObj> objs;
objs.push_back(BSON("_id" << 1));
objs.push_back(BSON("_id" << 1));
@@ -99,7 +103,9 @@ namespace DirectClientTests {
class BadNSCmd : ClientBase {
public:
virtual void run(){
- DBDirectClient client;
+ OperationContextImpl txn;
+ DBDirectClient client(&txn);
+
BSONObj result;
BSONObj cmdObj = BSON( "count" << "" );
ASSERT_THROWS( client.runCommand( "", cmdObj, result ), UserException );
@@ -109,7 +115,9 @@ namespace DirectClientTests {
class BadNSQuery : ClientBase {
public:
virtual void run(){
- DBDirectClient client;
+ OperationContextImpl txn;
+ DBDirectClient client(&txn);
+
auto_ptr<DBClientCursor> cursor = client.query( "", Query(), 1 );
ASSERT(cursor->more());
BSONObj result = cursor->next().getOwned();
@@ -121,7 +129,9 @@ namespace DirectClientTests {
class BadNSGetMore : ClientBase {
public:
virtual void run(){
- DBDirectClient client;
+ OperationContextImpl txn;
+ DBDirectClient client(&txn);
+
auto_ptr<DBClientCursor> cursor = client.getMore("", 1, 1);
ASSERT(cursor->more());
BSONObj result = cursor->next().getOwned();
@@ -133,7 +143,9 @@ namespace DirectClientTests {
class BadNSInsert : ClientBase {
public:
virtual void run(){
- DBDirectClient client;
+ OperationContextImpl txn;
+ DBDirectClient client(&txn);
+
client.insert( "", BSONObj(), 0 );
ASSERT( !client.getLastError().empty() );
}
@@ -142,7 +154,9 @@ namespace DirectClientTests {
class BadNSUpdate : ClientBase {
public:
virtual void run(){
- DBDirectClient client;
+ OperationContextImpl txn;
+ DBDirectClient client(&txn);
+
client.update( "", Query(), BSON( "$set" << BSON( "x" << 1 )) );
ASSERT( !client.getLastError().empty() );
}
@@ -151,7 +165,9 @@ namespace DirectClientTests {
class BadNSRemove : ClientBase {
public:
virtual void run(){
- DBDirectClient client;
+ OperationContextImpl txn;
+ DBDirectClient client(&txn);
+
client.remove( "", Query() );
ASSERT( !client.getLastError().empty() );
}
diff --git a/src/mongo/dbtests/gle_test.cpp b/src/mongo/dbtests/gle_test.cpp
index 71b3642e3af..ded97a490e1 100644
--- a/src/mongo/dbtests/gle_test.cpp
+++ b/src/mongo/dbtests/gle_test.cpp
@@ -26,6 +26,7 @@
* then also delete it in the license file.
*/
+#include "mongo/db/operation_context_impl.h"
#include "mongo/dbtests/dbtests.h"
#include "mongo/util/assert_util.h"
@@ -43,7 +44,9 @@ namespace {
class GetLastErrorCommandFailure {
public:
void run() {
- DBDirectClient client;
+ OperationContextImpl txn;
+ DBDirectClient client(&txn);
+
client.insert(_ns, BSON( "test" << "test"));
// Cannot mix fsync + j, will make command fail
@@ -58,7 +61,9 @@ namespace {
class GetLastErrorClean {
public:
void run() {
- DBDirectClient client;
+ OperationContextImpl txn;
+ DBDirectClient client(&txn);
+
client.insert(_ns, BSON( "test" << "test"));
// Make sure there was no error
@@ -73,7 +78,9 @@ namespace {
class GetLastErrorFromDup {
public:
void run() {
- DBDirectClient client;
+ OperationContextImpl txn;
+ DBDirectClient client(&txn);
+
client.insert(_ns, BSON( "_id" << 1));
// Make sure there was no error
diff --git a/src/mongo/dbtests/gridfstest.cpp b/src/mongo/dbtests/gridfstest.cpp
index 768db4cc307..14c861ca58e 100644
--- a/src/mongo/dbtests/gridfstest.cpp
+++ b/src/mongo/dbtests/gridfstest.cpp
@@ -29,6 +29,7 @@
#include "mongo/pch.h"
#include "mongo/client/gridfs.h"
+#include "mongo/db/operation_context_impl.h"
#include "mongo/dbtests/dbtests.h"
#include "mongo/util/assert_util.h"
@@ -41,7 +42,8 @@ namespace {
class SetChunkSizeTest {
public:
virtual void run() {
- DBDirectClient client;
+ OperationContextImpl txn;
+ DBDirectClient client(&txn);
GridFS grid(client, "gridtest");
grid.setChunkSize( 5 );
diff --git a/src/mongo/dbtests/jstests.cpp b/src/mongo/dbtests/jstests.cpp
index 400aceffd40..a5f8ff997b6 100644
--- a/src/mongo/dbtests/jstests.cpp
+++ b/src/mongo/dbtests/jstests.cpp
@@ -29,18 +29,20 @@
* then also delete it in the license file.
*/
-#include "mongo/pch.h"
+#include "mongo/platform/basic.h"
#include <limits>
#include "mongo/base/parse_number.h"
#include "mongo/db/instance.h"
#include "mongo/db/json.h"
+#include "mongo/db/operation_context_impl.h"
#include "mongo/db/storage_options.h"
#include "mongo/dbtests/dbtests.h"
#include "mongo/scripting/engine.h"
#include "mongo/util/timer.h"
+
namespace mongo {
bool dbEval(const string& dbName , BSONObj& cmd, BSONObjBuilder& result, string& errmsg);
} // namespace mongo
@@ -916,6 +918,10 @@ namespace JSTests {
}
string utf8ObjSpec = "{'_id':'\\u0001\\u007f\\u07ff\\uffff'}";
BSONObj utf8Obj = fromjson( utf8ObjSpec );
+
+ OperationContextImpl txn;
+ DBDirectClient client(&txn);
+
client.insert( ns(), utf8Obj );
client.eval( "unittest", "v = db.jstests.utf8check.findOne(); db.jstests.utf8check.remove( {} ); db.jstests.utf8check.insert( v );" );
check( utf8Obj, client.findOne( ns(), BSONObj() ) );
@@ -927,12 +933,15 @@ namespace JSTests {
FAIL( fail.c_str() );
}
}
+
void reset() {
+ OperationContextImpl txn;
+ DBDirectClient client(&txn);
+
client.dropCollection( ns() );
}
- static const char *ns() { return "unittest.jstests.utf8check"; }
- DBDirectClient client;
+ static const char *ns() { return "unittest.jstests.utf8check"; }
};
class LongUtf8String {
@@ -942,15 +951,21 @@ namespace JSTests {
void run() {
if( !globalScriptEngine->utf8Ok() )
return;
+
+ OperationContextImpl txn;
+ DBDirectClient client(&txn);
+
client.eval( "unittest", "db.jstests.longutf8string.save( {_id:'\\uffff\\uffff\\uffff\\uffff'} )" );
}
private:
void reset() {
+ OperationContextImpl txn;
+ DBDirectClient client(&txn);
+
client.dropCollection( ns() );
}
- static const char *ns() { return "unittest.jstests.longutf8string"; }
- DBDirectClient client;
+ static const char *ns() { return "unittest.jstests.longutf8string"; }
};
class InvalidUTF8Check {
@@ -1021,10 +1036,12 @@ namespace JSTests {
public:
virtual ~TestRoundTrip() {}
void run() {
-
// Insert in Javascript -> Find using DBDirectClient
// Drop the collection
+ OperationContextImpl txn;
+ DBDirectClient client(&txn);
+
client.dropCollection( "unittest.testroundtrip" );
// Insert in Javascript
@@ -1080,8 +1097,6 @@ namespace JSTests {
virtual string jsonOut() const {
return json();
}
-
- DBDirectClient client;
};
class DBRefTest : public TestRoundTrip {
@@ -1993,7 +2008,9 @@ namespace JSTests {
update.append( "_id" , "invalidstoredjs1" );
update.appendCode( "value" , "function () { db.test.find().forEach(function(obj) { continue; }); }" );
- DBDirectClient client;
+ OperationContextImpl txn;
+ DBDirectClient client(&txn);
+
client.update( "test.system.js" , query.obj() , update.obj() , true /* upsert */ );
scoped_ptr<Scope> s( globalScriptEngine->newScope() );
diff --git a/src/mongo/dbtests/matchertests.cpp b/src/mongo/dbtests/matchertests.cpp
index 67bff7ef74b..cee3995395c 100644
--- a/src/mongo/dbtests/matchertests.cpp
+++ b/src/mongo/dbtests/matchertests.cpp
@@ -41,18 +41,19 @@ namespace MatcherTests {
class CollectionBase {
public:
- CollectionBase() :
- _ns( "unittests.matchertests" ) {
+ CollectionBase() : _ns( "unittests.matchertests" ) {
+
}
+
virtual ~CollectionBase() {
- client().dropCollection( ns() );
+ OperationContextImpl txn;
+ DBDirectClient client(&txn);
+
+ client.dropCollection(_ns);
}
+
protected:
- const char* ns() const { return _ns; }
- DBDirectClient &client() { return _client; }
- private:
const char * const _ns;
- DBDirectClient _client;
};
template <typename M>
diff --git a/src/mongo/dbtests/oplogstarttests.cpp b/src/mongo/dbtests/oplogstarttests.cpp
index a0c94493fbc..45015afe883 100644
--- a/src/mongo/dbtests/oplogstarttests.cpp
+++ b/src/mongo/dbtests/oplogstarttests.cpp
@@ -38,7 +38,8 @@ namespace OplogStartTests {
class Base {
public:
Base() : _lk(_txn.lockState()),
- _context(ns()) {
+ _context(&_txn, ns()),
+ _client(&_txn) {
Collection* c = _context.db()->getCollection(&_txn, ns());
if (!c) {
diff --git a/src/mongo/dbtests/pdfiletests.cpp b/src/mongo/dbtests/pdfiletests.cpp
index 10d4e01d1fd..d954c801fdd 100644
--- a/src/mongo/dbtests/pdfiletests.cpp
+++ b/src/mongo/dbtests/pdfiletests.cpp
@@ -48,7 +48,7 @@ namespace PdfileTests {
class Base {
public:
Base() : _lk(_txn.lockState()),
- _context(ns()) {
+ _context(&_txn, ns()) {
}
diff --git a/src/mongo/dbtests/perf/perftest.cpp b/src/mongo/dbtests/perf/perftest.cpp
index 2afa74f68fa..6ae7cf35532 100644
--- a/src/mongo/dbtests/perf/perftest.cpp
+++ b/src/mongo/dbtests/perf/perftest.cpp
@@ -702,7 +702,7 @@ namespace Plan {
lk_.reset( new Lock::GlobalWrite );
}
void run() {
- Client::Context ctx( ns_ );
+ Client::Context ctx(txn, ns_ );
for( int i = 0; i < 10000; ++i ) {
scoped_ptr<MultiPlanScanner> s
( MultiPlanScanner::make( ns_.c_str(), BSONObj(), BSON( "a" << 1 ) ) );
@@ -723,7 +723,7 @@ namespace Plan {
lk_.reset( new Lock::GlobalWrite );
}
void run() {
- Client::Context ctx( ns_.c_str() );
+ Client::Context ctx(txn, ns_.c_str() );
for( int i = 0; i < 10000; ++i ) {
scoped_ptr<MultiPlanScanner>
s( MultiPlanScanner::make( ns_.c_str(), BSON( "a" << 1 ), BSONObj() ) );
diff --git a/src/mongo/dbtests/perftests.cpp b/src/mongo/dbtests/perftests.cpp
index 74eb31e8f68..3536b8ec07e 100644
--- a/src/mongo/dbtests/perftests.cpp
+++ b/src/mongo/dbtests/perftests.cpp
@@ -41,6 +41,7 @@
#include <fstream>
#include "mongo/db/db.h"
+#include "mongo/db/operation_context_impl.h"
#include "mongo/db/storage/mmap_v1/durable_mapped_file.h"
#include "mongo/db/storage/mmap_v1/dur_stats.h"
#include "mongo/db/instance.h"
@@ -71,8 +72,8 @@ namespace PerfTests {
class ClientBase {
public:
// NOTE: Not bothering to backup the old error record.
- ClientBase() {
- mongo::lastError.reset( new LastError() );
+ ClientBase() : _client(&_txn) {
+ mongo::lastError.reset(new LastError());
}
virtual ~ClientBase() {
@@ -91,6 +92,7 @@ namespace PerfTests {
DBClientBase* client() { return &_client; }
private:
+ OperationContextImpl _txn;
DBDirectClient _client;
};
@@ -356,7 +358,9 @@ namespace PerfTests {
static int z;
srand( ++z ^ (unsigned) time(0));
#endif
- DBDirectClient c;
+ OperationContextImpl txn;
+ DBDirectClient c(&txn);
+
Client::initThreadIfNotAlready("perftestthr");
const unsigned int Batch = batchSize();
while( 1 ) {
diff --git a/src/mongo/dbtests/plan_ranking.cpp b/src/mongo/dbtests/plan_ranking.cpp
index 240371f1482..79419bb60fa 100644
--- a/src/mongo/dbtests/plan_ranking.cpp
+++ b/src/mongo/dbtests/plan_ranking.cpp
@@ -60,7 +60,10 @@ namespace PlanRankingTests {
class PlanRankingTestBase {
public:
- PlanRankingTestBase() : _internalQueryForceIntersectionPlans(internalQueryForceIntersectionPlans) {
+ PlanRankingTestBase()
+ : _internalQueryForceIntersectionPlans(internalQueryForceIntersectionPlans),
+ _client(&_txn) {
+
Client::WriteContext ctx(&_txn, ns);
_client.dropCollection(ns);
}
@@ -140,12 +143,13 @@ namespace PlanRankingTests {
OperationContextImpl _txn;
private:
-
- DBDirectClient _client;
- scoped_ptr<MultiPlanStage> _mps;
// Holds the value of global "internalQueryForceIntersectionPlans" setParameter flag.
// Restored at end of test invocation regardless of test result.
bool _internalQueryForceIntersectionPlans;
+
+ scoped_ptr<MultiPlanStage> _mps;
+
+ DBDirectClient _client;
};
// static
diff --git a/src/mongo/dbtests/profile_test.cpp b/src/mongo/dbtests/profile_test.cpp
index b7a58b856d4..15e04854bf2 100644
--- a/src/mongo/dbtests/profile_test.cpp
+++ b/src/mongo/dbtests/profile_test.cpp
@@ -31,6 +31,7 @@
*/
#include "mongo/db/instance.h"
+#include "mongo/db/operation_context_impl.h"
#include "mongo/unittest/unittest.h"
using mongo::BSONObj;
@@ -38,7 +39,8 @@ using mongo::DBDirectClient;
using std::string;
-namespace mongo_test {
+namespace mongo {
+
class Profiler: public mongo::unittest::Test {
public:
static const string PROFILER_TEST_DB;
@@ -48,11 +50,13 @@ namespace mongo_test {
protected:
void setUp() {
BSONObj ret;
+
+ OperationContextImpl txn;
+ DBDirectClient db(&txn);
+
db.runCommand(PROFILER_TEST_DB, BSON("dropDatabase" << 1), ret);
ASSERT(ret["ok"].trueValue());
}
-
- DBDirectClient db;
};
const string Profiler::PROFILER_TEST_DB = "profilerTestDB";
@@ -64,6 +68,9 @@ namespace mongo_test {
// be profiled in a shortened version
const string bigStr(16 * (1 << 20) - 200, 'a');
+ OperationContextImpl txn;
+ DBDirectClient db(&txn);
+
{
BSONObj replyObj;
db.runCommand(PROFILER_TEST_DB, BSON("profile" << 2), replyObj);
@@ -95,7 +102,8 @@ namespace mongo_test {
builder.append(fieldName, x);
}
- DBDirectClient db;
+ OperationContextImpl txn;
+ DBDirectClient db(&txn);
{
BSONObj replyObj;
diff --git a/src/mongo/dbtests/query_multi_plan_runner.cpp b/src/mongo/dbtests/query_multi_plan_runner.cpp
index 8ca3b5a248c..f47d08ecfe8 100644
--- a/src/mongo/dbtests/query_multi_plan_runner.cpp
+++ b/src/mongo/dbtests/query_multi_plan_runner.cpp
@@ -57,7 +57,9 @@ namespace QueryMultiPlanRunner {
class MultiPlanRunnerBase {
public:
- MultiPlanRunnerBase() { }
+ MultiPlanRunnerBase() : _client(&_txn) {
+
+ }
virtual ~MultiPlanRunnerBase() {
_client.dropCollection(ns());
@@ -82,7 +84,8 @@ namespace QueryMultiPlanRunner {
static const char* ns() { return "unittests.QueryStageMultiPlanRunner"; }
- private:
+ protected:
+ OperationContextImpl _txn;
DBDirectClient _client;
};
@@ -92,8 +95,7 @@ namespace QueryMultiPlanRunner {
class MPRCollectionScanVsHighlySelectiveIXScan : public MultiPlanRunnerBase {
public:
void run() {
- OperationContextImpl txn;
- Client::WriteContext ctx(&txn, ns());
+ Client::WriteContext ctx(&_txn, ns());
const int N = 5000;
for (int i = 0; i < N; ++i) {
@@ -106,14 +108,14 @@ namespace QueryMultiPlanRunner {
// Every call to work() returns something so this should clearly win (by current scoring
// at least).
IndexScanParams ixparams;
- ixparams.descriptor = getIndex(&txn, ctx.ctx().db(), BSON("foo" << 1));
+ ixparams.descriptor = getIndex(&_txn, ctx.ctx().db(), BSON("foo" << 1));
ixparams.bounds.isSimpleRange = true;
ixparams.bounds.startKey = BSON("" << 7);
ixparams.bounds.endKey = BSON("" << 7);
ixparams.bounds.endKeyInclusive = true;
ixparams.direction = 1;
- const Collection* coll = ctx.ctx().db()->getCollection(&txn, ns());
+ const Collection* coll = ctx.ctx().db()->getCollection(&_txn, ns());
auto_ptr<WorkingSet> sharedWs(new WorkingSet());
IndexScan* ix = new IndexScan(ixparams, sharedWs.get(), NULL);
@@ -121,7 +123,7 @@ namespace QueryMultiPlanRunner {
// Plan 1: CollScan with matcher.
CollectionScanParams csparams;
- csparams.collection = ctx.ctx().db()->getCollection( &txn, ns() );
+ csparams.collection = ctx.ctx().db()->getCollection( &_txn, ns() );
csparams.direction = CollectionScanParams::FORWARD;
// Make the filter.
@@ -138,7 +140,7 @@ namespace QueryMultiPlanRunner {
verify(CanonicalQuery::canonicalize(ns(), BSON("foo" << 7), &cq).isOK());
verify(NULL != cq);
- MultiPlanStage* mps = new MultiPlanStage(ctx.ctx().db()->getCollection(&txn, ns()),cq);
+ MultiPlanStage* mps = new MultiPlanStage(ctx.ctx().db()->getCollection(&_txn, ns()),cq);
mps->addPlan(createQuerySolution(), firstRoot.release(), sharedWs.get());
mps->addPlan(createQuerySolution(), secondRoot.release(), sharedWs.get());
@@ -148,7 +150,7 @@ namespace QueryMultiPlanRunner {
ASSERT_EQUALS(0, mps->bestPlanIdx());
SingleSolutionRunner sr(
- ctx.ctx().db()->getCollection(&txn, ns()),
+ ctx.ctx().db()->getCollection(&_txn, ns()),
cq,
mps->bestSolution(),
mps,
diff --git a/src/mongo/dbtests/query_single_solution_runner.cpp b/src/mongo/dbtests/query_single_solution_runner.cpp
index 246cf66df1a..d5290853151 100644
--- a/src/mongo/dbtests/query_single_solution_runner.cpp
+++ b/src/mongo/dbtests/query_single_solution_runner.cpp
@@ -45,7 +45,9 @@ namespace QuerySingleSolutionRunner {
class SingleSolutionRunnerBase {
public:
- SingleSolutionRunnerBase() { }
+ SingleSolutionRunnerBase() : _client(&_txn) {
+
+ }
virtual ~SingleSolutionRunnerBase() {
_client.dropCollection(ns());
diff --git a/src/mongo/dbtests/query_stage_and.cpp b/src/mongo/dbtests/query_stage_and.cpp
index ab7ff6a5457..59a5ae3819f 100644
--- a/src/mongo/dbtests/query_stage_and.cpp
+++ b/src/mongo/dbtests/query_stage_and.cpp
@@ -51,7 +51,9 @@ namespace QueryStageAnd {
class QueryStageAndBase {
public:
- QueryStageAndBase() { }
+ QueryStageAndBase() : _client(&_txn) {
+
+ }
virtual ~QueryStageAndBase() {
_client.dropCollection(ns());
diff --git a/src/mongo/dbtests/query_stage_collscan.cpp b/src/mongo/dbtests/query_stage_collscan.cpp
index 20fb3ad5b62..647b721f878 100644
--- a/src/mongo/dbtests/query_stage_collscan.cpp
+++ b/src/mongo/dbtests/query_stage_collscan.cpp
@@ -313,7 +313,7 @@ namespace QueryStageCollectionScan {
class QueryStageCollectionScanBase {
public:
- QueryStageCollectionScanBase() {
+ QueryStageCollectionScanBase() : _client(&_txn) {
Client::WriteContext ctx(&_txn, ns());
for (int i = 0; i < numObj(); ++i) {
diff --git a/src/mongo/dbtests/query_stage_count.cpp b/src/mongo/dbtests/query_stage_count.cpp
index eaecb772981..04a45d98044 100644
--- a/src/mongo/dbtests/query_stage_count.cpp
+++ b/src/mongo/dbtests/query_stage_count.cpp
@@ -48,7 +48,9 @@ namespace QueryStageCount {
class CountBase {
public:
- CountBase() { }
+ CountBase() : _client(&_txn) {
+
+ }
virtual ~CountBase() {
Client::WriteContext ctx(&_txn, ns());
diff --git a/src/mongo/dbtests/query_stage_distinct.cpp b/src/mongo/dbtests/query_stage_distinct.cpp
index c8799f73fcb..942c87b264a 100644
--- a/src/mongo/dbtests/query_stage_distinct.cpp
+++ b/src/mongo/dbtests/query_stage_distinct.cpp
@@ -46,7 +46,9 @@ namespace QueryStageDistinct {
class DistinctBase {
public:
- DistinctBase() { }
+ DistinctBase() : _client(&_txn) {
+
+ }
virtual ~DistinctBase() {
Client::WriteContext ctx(&_txn, ns());
diff --git a/src/mongo/dbtests/query_stage_fetch.cpp b/src/mongo/dbtests/query_stage_fetch.cpp
index 3414475baf9..4bea8b9e004 100644
--- a/src/mongo/dbtests/query_stage_fetch.cpp
+++ b/src/mongo/dbtests/query_stage_fetch.cpp
@@ -48,7 +48,9 @@ namespace QueryStageFetch {
class QueryStageFetchBase {
public:
- QueryStageFetchBase() { }
+ QueryStageFetchBase() : _client(&_txn) {
+
+ }
virtual ~QueryStageFetchBase() {
_client.dropCollection(ns());
@@ -75,6 +77,7 @@ namespace QueryStageFetch {
static const char* ns() { return "unittests.QueryStageFetch"; }
private:
+ OperationContextImpl _txn;
DBDirectClient _client;
};
diff --git a/src/mongo/dbtests/query_stage_keep.cpp b/src/mongo/dbtests/query_stage_keep.cpp
index 3be756ae2a5..3283b66ab8c 100644
--- a/src/mongo/dbtests/query_stage_keep.cpp
+++ b/src/mongo/dbtests/query_stage_keep.cpp
@@ -52,7 +52,9 @@ namespace QueryStageKeep {
class QueryStageKeepBase {
public:
- QueryStageKeepBase() { }
+ QueryStageKeepBase() : _client(&_txn) {
+
+ }
virtual ~QueryStageKeepBase() {
_client.dropCollection(ns());
@@ -89,7 +91,8 @@ namespace QueryStageKeep {
return WorkingSet::INVALID_ID;
}
- private:
+ protected:
+ OperationContextImpl _txn;
DBDirectClient _client;
};
@@ -102,13 +105,12 @@ namespace QueryStageKeep {
class KeepStageBasic : public QueryStageKeepBase {
public:
void run() {
- OperationContextImpl txn;
- Client::WriteContext ctx(&txn, ns());
+ Client::WriteContext ctx(&_txn, ns());
Database* db = ctx.ctx().db();
- Collection* coll = db->getCollection(&txn, ns());
+ Collection* coll = db->getCollection(&_txn, ns());
if (!coll) {
- coll = db->createCollection(&txn, ns());
+ coll = db->createCollection(&_txn, ns());
}
WorkingSet ws;
diff --git a/src/mongo/dbtests/query_stage_merge_sort.cpp b/src/mongo/dbtests/query_stage_merge_sort.cpp
index ff52f9c6ffc..11161a5c6be 100644
--- a/src/mongo/dbtests/query_stage_merge_sort.cpp
+++ b/src/mongo/dbtests/query_stage_merge_sort.cpp
@@ -47,7 +47,9 @@ namespace QueryStageMergeSortTests {
class QueryStageMergeSortTestBase {
public:
- QueryStageMergeSortTestBase() { }
+ QueryStageMergeSortTestBase() : _client(&_txn) {
+
+ }
virtual ~QueryStageMergeSortTestBase() {
Client::WriteContext ctx(&_txn, ns());
@@ -109,9 +111,8 @@ namespace QueryStageMergeSortTests {
public:
void run() {
Client::WriteContext ctx(&_txn, ns());
- OperationContextImpl txn;
Database* db = ctx.ctx().db();
- Collection* coll = db->getCollection(&txn, ns());
+ Collection* coll = db->getCollection(&_txn, ns());
if (!coll) {
coll = db->createCollection(&_txn, ns());
}
@@ -173,9 +174,8 @@ namespace QueryStageMergeSortTests {
public:
void run() {
Client::WriteContext ctx(&_txn, ns());
- OperationContextImpl txn;
Database* db = ctx.ctx().db();
- Collection* coll = db->getCollection(&txn, ns());
+ Collection* coll = db->getCollection(&_txn, ns());
if (!coll) {
coll = db->createCollection(&_txn, ns());
}
@@ -236,9 +236,8 @@ namespace QueryStageMergeSortTests {
public:
void run() {
Client::WriteContext ctx(&_txn, ns());
- OperationContextImpl txn;
Database* db = ctx.ctx().db();
- Collection* coll = db->getCollection(&txn, ns());
+ Collection* coll = db->getCollection(&_txn, ns());
if (!coll) {
coll = db->createCollection(&_txn, ns());
}
@@ -300,9 +299,8 @@ namespace QueryStageMergeSortTests {
public:
void run() {
Client::WriteContext ctx(&_txn, ns());
- OperationContextImpl txn;
Database* db = ctx.ctx().db();
- Collection* coll = db->getCollection(&txn, ns());
+ Collection* coll = db->getCollection(&_txn, ns());
if (!coll) {
coll = db->createCollection(&_txn, ns());
}
@@ -365,9 +363,8 @@ namespace QueryStageMergeSortTests {
public:
void run() {
Client::WriteContext ctx(&_txn, ns());
- OperationContextImpl txn;
Database* db = ctx.ctx().db();
- Collection* coll = db->getCollection(&txn, ns());
+ Collection* coll = db->getCollection(&_txn, ns());
if (!coll) {
coll = db->createCollection(&_txn, ns());
}
@@ -428,9 +425,8 @@ namespace QueryStageMergeSortTests {
public:
void run() {
Client::WriteContext ctx(&_txn, ns());
- OperationContextImpl txn;
Database* db = ctx.ctx().db();
- Collection* coll = db->getCollection(&txn, ns());
+ Collection* coll = db->getCollection(&_txn, ns());
if (!coll) {
coll = db->createCollection(&_txn, ns());
}
@@ -481,9 +477,8 @@ namespace QueryStageMergeSortTests {
public:
void run() {
Client::WriteContext ctx(&_txn, ns());
- OperationContextImpl txn;
Database* db = ctx.ctx().db();
- Collection* coll = db->getCollection(&txn, ns());
+ Collection* coll = db->getCollection(&_txn, ns());
if (!coll) {
coll = db->createCollection(&_txn, ns());
}
diff --git a/src/mongo/dbtests/query_stage_sort.cpp b/src/mongo/dbtests/query_stage_sort.cpp
index 1d9b4806db3..6ae66a0b7bb 100644
--- a/src/mongo/dbtests/query_stage_sort.cpp
+++ b/src/mongo/dbtests/query_stage_sort.cpp
@@ -47,7 +47,9 @@ namespace QueryStageSortTests {
class QueryStageSortTestBase {
public:
- QueryStageSortTestBase() { }
+ QueryStageSortTestBase() : _client(&_txn) {
+
+ }
void fillData() {
for (int i = 0; i < numObj(); ++i) {
@@ -168,7 +170,9 @@ namespace QueryStageSortTests {
static const char* ns() { return "unittests.QueryStageSort"; }
- private:
+
+ protected:
+ OperationContextImpl _txn;
DBDirectClient _client;
};
@@ -179,13 +183,12 @@ namespace QueryStageSortTests {
virtual int numObj() { return 100; }
void run() {
- OperationContextImpl txn;
- Client::WriteContext ctx(&txn, ns());
+ Client::WriteContext ctx(&_txn, ns());
Database* db = ctx.ctx().db();
- Collection* coll = db->getCollection(&txn, ns());
+ Collection* coll = db->getCollection(&_txn, ns());
if (!coll) {
- coll = db->createCollection(&txn, ns());
+ coll = db->createCollection(&_txn, ns());
}
fillData();
@@ -199,13 +202,12 @@ namespace QueryStageSortTests {
virtual int numObj() { return 100; }
void run() {
- OperationContextImpl txn;
- Client::WriteContext ctx(&txn, ns());
+ Client::WriteContext ctx(&_txn, ns());
Database* db = ctx.ctx().db();
- Collection* coll = db->getCollection(&txn, ns());
+ Collection* coll = db->getCollection(&_txn, ns());
if (!coll) {
- coll = db->createCollection(&txn, ns());
+ coll = db->createCollection(&_txn, ns());
}
fillData();
@@ -228,13 +230,12 @@ namespace QueryStageSortTests {
virtual int numObj() { return 10000; }
void run() {
- OperationContextImpl txn;
- Client::WriteContext ctx(&txn, ns());
+ Client::WriteContext ctx(&_txn, ns());
Database* db = ctx.ctx().db();
- Collection* coll = db->getCollection(&txn, ns());
+ Collection* coll = db->getCollection(&_txn, ns());
if (!coll) {
- coll = db->createCollection(&txn, ns());
+ coll = db->createCollection(&_txn, ns());
}
fillData();
@@ -248,13 +249,12 @@ namespace QueryStageSortTests {
virtual int numObj() { return 2000; }
void run() {
- OperationContextImpl txn;
- Client::WriteContext ctx(&txn, ns());
+ Client::WriteContext ctx(&_txn, ns());
Database* db = ctx.ctx().db();
- Collection* coll = db->getCollection(&txn, ns());
+ Collection* coll = db->getCollection(&_txn, ns());
if (!coll) {
- coll = db->createCollection(&txn, ns());
+ coll = db->createCollection(&_txn, ns());
}
fillData();
@@ -339,13 +339,12 @@ namespace QueryStageSortTests {
virtual int numObj() { return 100; }
void run() {
- OperationContextImpl txn;
- Client::WriteContext ctx(&txn, ns());
+ Client::WriteContext ctx(&_txn, ns());
Database* db = ctx.ctx().db();
- Collection* coll = db->getCollection(&txn, ns());
+ Collection* coll = db->getCollection(&_txn, ns());
if (!coll) {
- coll = db->createCollection(&txn, ns());
+ coll = db->createCollection(&_txn, ns());
}
WorkingSet* ws = new WorkingSet();
diff --git a/src/mongo/dbtests/query_stage_tests.cpp b/src/mongo/dbtests/query_stage_tests.cpp
index 23525ca265d..fc5ee43ea50 100644
--- a/src/mongo/dbtests/query_stage_tests.cpp
+++ b/src/mongo/dbtests/query_stage_tests.cpp
@@ -46,7 +46,7 @@ namespace QueryStageTests {
class IndexScanBase {
public:
- IndexScanBase() {
+ IndexScanBase() : _client(&_txn) {
Client::WriteContext ctx(&_txn, ns());
for (int i = 0; i < numObj(); ++i) {
diff --git a/src/mongo/dbtests/querytests.cpp b/src/mongo/dbtests/querytests.cpp
index ac70e48555f..ef3d859a260 100644
--- a/src/mongo/dbtests/querytests.cpp
+++ b/src/mongo/dbtests/querytests.cpp
@@ -65,7 +65,7 @@ namespace QueryTests {
public:
Base() : _lk(_txn.lockState()),
- _context(ns()) {
+ _context(&_txn, ns()) {
_database = _context.db();
_collection = _database->getCollection( &_txn, ns() );
@@ -162,7 +162,7 @@ namespace QueryTests {
// We don't normally allow empty objects in the database, but test that we can find
// an empty object (one might be allowed inside a reserved namespace at some point).
Lock::GlobalWrite lk(_txn.lockState());
- Client::Context ctx( "unittests.querytests" );
+ Client::Context ctx(&_txn, "unittests.querytests" );
Database* db = ctx.db();
if ( db->getCollection( &_txn, ns() ) ) {
@@ -172,7 +172,7 @@ namespace QueryTests {
_collection = db->createCollection( &_txn, ns(), CollectionOptions(), true, false );
ASSERT( _collection );
- DBDirectClient cl;
+ DBDirectClient cl(&_txn);
BSONObj info;
bool ok = cl.runCommand( "unittests", BSON( "godinsert" << "querytests" << "obj" << BSONObj() ), info );
ASSERT( ok );
@@ -188,7 +188,7 @@ namespace QueryTests {
class ClientBase {
public:
- ClientBase() {
+ ClientBase() : _client(&_txn) {
mongo::lastError.reset( new LastError() );
}
~ClientBase() {
@@ -197,27 +197,23 @@ namespace QueryTests {
protected:
void insert( const char *ns, BSONObj o ) {
- client_.insert( ns, o );
+ _client.insert( ns, o );
}
void update( const char *ns, BSONObj q, BSONObj o, bool upsert = 0 ) {
- client_.update( ns, Query( q ), o, upsert );
+ _client.update( ns, Query( q ), o, upsert );
}
bool error() {
- return !client_.getPrevError().getField( "err" ).isNull();
+ return !_client.getPrevError().getField( "err" ).isNull();
}
- const DBDirectClient& client() const { return client_; }
- DBDirectClient& client() { return client_; }
-
- DBDirectClient client_;
-
OperationContextImpl _txn;
+ DBDirectClient _client;
};
class BoundedKey : public ClientBase {
public:
~BoundedKey() {
- client().dropCollection( "unittests.querytests.BoundedKey" );
+ _client.dropCollection( "unittests.querytests.BoundedKey" );
}
void run() {
const char *ns = "unittests.querytests.BoundedKey";
@@ -225,23 +221,23 @@ namespace QueryTests {
BSONObjBuilder a;
a.appendMaxKey( "$lt" );
BSONObj limit = a.done();
- ASSERT( !client().findOne( ns, QUERY( "a" << limit ) ).isEmpty() );
- client().ensureIndex( ns, BSON( "a" << 1 ) );
- ASSERT( !client().findOne( ns, QUERY( "a" << limit ).hint( BSON( "a" << 1 ) ) ).isEmpty() );
+ ASSERT( !_client.findOne( ns, QUERY( "a" << limit ) ).isEmpty() );
+ _client.ensureIndex( ns, BSON( "a" << 1 ) );
+ ASSERT( !_client.findOne( ns, QUERY( "a" << limit ).hint( BSON( "a" << 1 ) ) ).isEmpty() );
}
};
class GetMore : public ClientBase {
public:
~GetMore() {
- client().dropCollection( "unittests.querytests.GetMore" );
+ _client.dropCollection( "unittests.querytests.GetMore" );
}
void run() {
const char *ns = "unittests.querytests.GetMore";
insert( ns, BSON( "a" << 1 ) );
insert( ns, BSON( "a" << 2 ) );
insert( ns, BSON( "a" << 3 ) );
- auto_ptr< DBClientCursor > cursor = client().query( ns, BSONObj(), 2 );
+ auto_ptr< DBClientCursor > cursor = _client.query( ns, BSONObj(), 2 );
long long cursorId = cursor->getCursorId();
cursor->decouple();
cursor.reset();
@@ -249,7 +245,7 @@ namespace QueryTests {
{
// Check internal server handoff to getmore.
Lock::DBWrite lk(_txn.lockState(), ns);
- Client::Context ctx( ns );
+ Client::Context ctx(&_txn, ns );
ClientCursorPin clientCursor( ctx.db()->getCollection(&_txn, ns), cursorId );
// pq doesn't exist if it's a runner inside of the clientcursor.
// ASSERT( clientCursor.c()->pq );
@@ -257,7 +253,7 @@ namespace QueryTests {
ASSERT_EQUALS( 2, clientCursor.c()->pos() );
}
- cursor = client().getMore( ns, cursorId );
+ cursor = _client.getMore( ns, cursorId );
ASSERT( cursor->more() );
ASSERT_EQUALS( 3, cursor->next().getIntField( "a" ) );
}
@@ -274,7 +270,7 @@ namespace QueryTests {
public:
~GetMoreKillOp() {
getGlobalEnvironment()->unsetKillAllOperations();
- client().dropCollection( "unittests.querytests.GetMoreKillOp" );
+ _client.dropCollection( "unittests.querytests.GetMoreKillOp" );
}
void run() {
@@ -285,7 +281,7 @@ namespace QueryTests {
}
// Create a cursor on the collection, with a batch size of 200.
- auto_ptr<DBClientCursor> cursor = client().query( ns, "", 0, 0, 0, 0, 200 );
+ auto_ptr<DBClientCursor> cursor = _client.query( ns, "", 0, 0, 0, 0, 200 );
CursorId cursorId = cursor->getCursorId();
// Count 500 results, spanning a few batches of documents.
@@ -313,7 +309,7 @@ namespace QueryTests {
ASSERT_FALSE(CollectionCursorCache::eraseCursorGlobal(&_txn, cursorId));
// Check that a subsequent get more fails with the cursor removed.
- ASSERT_THROWS( client().getMore( ns, cursorId ), UserException );
+ ASSERT_THROWS( _client.getMore( ns, cursorId ), UserException );
}
};
@@ -326,7 +322,7 @@ namespace QueryTests {
public:
~GetMoreInvalidRequest() {
getGlobalEnvironment()->unsetKillAllOperations();
- client().dropCollection( "unittests.querytests.GetMoreInvalidRequest" );
+ _client.dropCollection( "unittests.querytests.GetMoreInvalidRequest" );
}
void run() {
@@ -337,7 +333,7 @@ namespace QueryTests {
}
// Create a cursor on the collection, with a batch size of 200.
- auto_ptr<DBClientCursor> cursor = client().query( ns, "", 0, 0, 0, 0, 200 );
+ auto_ptr<DBClientCursor> cursor = _client.query( ns, "", 0, 0, 0, 0, 200 );
CursorId cursorId = cursor->getCursorId();
// Count 500 results, spanning a few batches of documents.
@@ -350,7 +346,7 @@ namespace QueryTests {
// Send a get more with a namespace that is incorrect ('spoofed') for this cursor id.
// This is the invalaid get more request described in the comment preceding this class.
- client().getMore
+ _client.getMore
( "unittests.querytests.GetMoreInvalidRequest_WRONG_NAMESPACE_FOR_CURSOR",
cursor->getCursorId() );
@@ -375,38 +371,38 @@ namespace QueryTests {
const char* ns;
PositiveLimit() : ns("unittests.querytests.PositiveLimit") {}
~PositiveLimit() {
- client().dropCollection( ns );
+ _client.dropCollection( ns );
}
void testLimit(int limit) {
- ASSERT_EQUALS(client().query( ns, BSONObj(), limit )->itcount(), limit);
+ ASSERT_EQUALS(_client.query( ns, BSONObj(), limit )->itcount(), limit);
}
void run() {
for(int i=0; i<1000; i++)
insert( ns, BSON( GENOID << "i" << i ) );
- ASSERT_EQUALS( client().query(ns, BSONObj(), 1 )->itcount(), 1);
- ASSERT_EQUALS( client().query(ns, BSONObj(), 10 )->itcount(), 10);
- ASSERT_EQUALS( client().query(ns, BSONObj(), 101 )->itcount(), 101);
- ASSERT_EQUALS( client().query(ns, BSONObj(), 999 )->itcount(), 999);
- ASSERT_EQUALS( client().query(ns, BSONObj(), 1000 )->itcount(), 1000);
- ASSERT_EQUALS( client().query(ns, BSONObj(), 1001 )->itcount(), 1000);
- ASSERT_EQUALS( client().query(ns, BSONObj(), 0 )->itcount(), 1000);
+ ASSERT_EQUALS( _client.query(ns, BSONObj(), 1 )->itcount(), 1);
+ ASSERT_EQUALS( _client.query(ns, BSONObj(), 10 )->itcount(), 10);
+ ASSERT_EQUALS( _client.query(ns, BSONObj(), 101 )->itcount(), 101);
+ ASSERT_EQUALS( _client.query(ns, BSONObj(), 999 )->itcount(), 999);
+ ASSERT_EQUALS( _client.query(ns, BSONObj(), 1000 )->itcount(), 1000);
+ ASSERT_EQUALS( _client.query(ns, BSONObj(), 1001 )->itcount(), 1000);
+ ASSERT_EQUALS( _client.query(ns, BSONObj(), 0 )->itcount(), 1000);
}
};
class ReturnOneOfManyAndTail : public ClientBase {
public:
~ReturnOneOfManyAndTail() {
- client().dropCollection( "unittests.querytests.ReturnOneOfManyAndTail" );
+ _client.dropCollection( "unittests.querytests.ReturnOneOfManyAndTail" );
}
void run() {
const char *ns = "unittests.querytests.ReturnOneOfManyAndTail";
- client().createCollection( ns, 1024, true );
+ _client.createCollection( ns, 1024, true );
insert( ns, BSON( "a" << 0 ) );
insert( ns, BSON( "a" << 1 ) );
insert( ns, BSON( "a" << 2 ) );
- auto_ptr< DBClientCursor > c = client().query( ns, QUERY( "a" << GT << 0 ).hint( BSON( "$natural" << 1 ) ), 1, 0, 0, QueryOption_CursorTailable );
+ auto_ptr< DBClientCursor > c = _client.query( ns, QUERY( "a" << GT << 0 ).hint( BSON( "$natural" << 1 ) ), 1, 0, 0, QueryOption_CursorTailable );
// If only one result requested, a cursor is not saved.
ASSERT_EQUALS( 0, c->getCursorId() );
ASSERT( c->more() );
@@ -417,15 +413,15 @@ namespace QueryTests {
class TailNotAtEnd : public ClientBase {
public:
~TailNotAtEnd() {
- client().dropCollection( "unittests.querytests.TailNotAtEnd" );
+ _client.dropCollection( "unittests.querytests.TailNotAtEnd" );
}
void run() {
const char *ns = "unittests.querytests.TailNotAtEnd";
- client().createCollection( ns, 2047, true );
+ _client.createCollection( ns, 2047, true );
insert( ns, BSON( "a" << 0 ) );
insert( ns, BSON( "a" << 1 ) );
insert( ns, BSON( "a" << 2 ) );
- auto_ptr< DBClientCursor > c = client().query( ns, Query().hint( BSON( "$natural" << 1 ) ), 2, 0, 0, QueryOption_CursorTailable );
+ auto_ptr< DBClientCursor > c = _client.query( ns, Query().hint( BSON( "$natural" << 1 ) ), 2, 0, 0, QueryOption_CursorTailable );
ASSERT( 0 != c->getCursorId() );
while( c->more() )
c->next();
@@ -442,16 +438,16 @@ namespace QueryTests {
class EmptyTail : public ClientBase {
public:
~EmptyTail() {
- client().dropCollection( "unittests.querytests.EmptyTail" );
+ _client.dropCollection( "unittests.querytests.EmptyTail" );
}
void run() {
const char *ns = "unittests.querytests.EmptyTail";
- client().createCollection( ns, 1900, true );
- auto_ptr< DBClientCursor > c = client().query( ns, Query().hint( BSON( "$natural" << 1 ) ), 2, 0, 0, QueryOption_CursorTailable );
+ _client.createCollection( ns, 1900, true );
+ auto_ptr< DBClientCursor > c = _client.query( ns, Query().hint( BSON( "$natural" << 1 ) ), 2, 0, 0, QueryOption_CursorTailable );
ASSERT_EQUALS( 0, c->getCursorId() );
ASSERT( c->isDead() );
insert( ns, BSON( "a" << 0 ) );
- c = client().query( ns, QUERY( "a" << 1 ).hint( BSON( "$natural" << 1 ) ), 2, 0, 0, QueryOption_CursorTailable );
+ c = _client.query( ns, QUERY( "a" << 1 ).hint( BSON( "$natural" << 1 ) ), 2, 0, 0, QueryOption_CursorTailable );
ASSERT( 0 != c->getCursorId() );
ASSERT( !c->isDead() );
}
@@ -460,14 +456,14 @@ namespace QueryTests {
class TailableDelete : public ClientBase {
public:
~TailableDelete() {
- client().dropCollection( "unittests.querytests.TailableDelete" );
+ _client.dropCollection( "unittests.querytests.TailableDelete" );
}
void run() {
const char *ns = "unittests.querytests.TailableDelete";
- client().createCollection( ns, 8192, true, 2 );
+ _client.createCollection( ns, 8192, true, 2 );
insert( ns, BSON( "a" << 0 ) );
insert( ns, BSON( "a" << 1 ) );
- auto_ptr< DBClientCursor > c = client().query( ns, Query().hint( BSON( "$natural" << 1 ) ), 2, 0, 0, QueryOption_CursorTailable );
+ auto_ptr< DBClientCursor > c = _client.query( ns, Query().hint( BSON( "$natural" << 1 ) ), 2, 0, 0, QueryOption_CursorTailable );
c->next();
c->next();
ASSERT( !c->more() );
@@ -492,19 +488,19 @@ namespace QueryTests {
class TailableInsertDelete : public ClientBase {
public:
~TailableInsertDelete() {
- client().dropCollection( "unittests.querytests.TailableInsertDelete" );
+ _client.dropCollection( "unittests.querytests.TailableInsertDelete" );
}
void run() {
const char *ns = "unittests.querytests.TailableInsertDelete";
- client().createCollection( ns, 1330, true );
+ _client.createCollection( ns, 1330, true );
insert( ns, BSON( "a" << 0 ) );
insert( ns, BSON( "a" << 1 ) );
- auto_ptr< DBClientCursor > c = client().query( ns, Query().hint( BSON( "$natural" << 1 ) ), 2, 0, 0, QueryOption_CursorTailable );
+ auto_ptr< DBClientCursor > c = _client.query( ns, Query().hint( BSON( "$natural" << 1 ) ), 2, 0, 0, QueryOption_CursorTailable );
c->next();
c->next();
ASSERT( !c->more() );
insert( ns, BSON( "a" << 2 ) );
- client().remove( ns, QUERY( "a" << 1 ) );
+ _client.remove( ns, QUERY( "a" << 1 ) );
ASSERT( c->more() );
ASSERT_EQUALS( 2, c->next().getIntField( "a" ) );
ASSERT( !c->more() );
@@ -514,21 +510,21 @@ namespace QueryTests {
class TailCappedOnly : public ClientBase {
public:
~TailCappedOnly() {
- client().dropCollection( "unittest.querytests.TailCappedOnly" );
+ _client.dropCollection( "unittest.querytests.TailCappedOnly" );
}
void run() {
const char *ns = "unittests.querytests.TailCappedOnly";
- client().insert( ns, BSONObj() );
- auto_ptr< DBClientCursor > c = client().query( ns, BSONObj(), 0, 0, 0, QueryOption_CursorTailable );
+ _client.insert( ns, BSONObj() );
+ auto_ptr< DBClientCursor > c = _client.query( ns, BSONObj(), 0, 0, 0, QueryOption_CursorTailable );
ASSERT( c->isDead() );
- ASSERT( !client().getLastError().empty() );
+ ASSERT( !_client.getLastError().empty() );
}
};
class TailableQueryOnId : public ClientBase {
public:
~TailableQueryOnId() {
- client().dropCollection( "unittests.querytests.TailableQueryOnId" );
+ _client.dropCollection( "unittests.querytests.TailableQueryOnId" );
}
void insertA(const char* ns, int a) {
@@ -542,13 +538,13 @@ namespace QueryTests {
void run() {
const char *ns = "unittests.querytests.TailableQueryOnId";
BSONObj info;
- client().runCommand( "unittests", BSON( "create" << "querytests.TailableQueryOnId" << "capped" << true << "size" << 8192 << "autoIndexId" << true ), info );
+ _client.runCommand( "unittests", BSON( "create" << "querytests.TailableQueryOnId" << "capped" << true << "size" << 8192 << "autoIndexId" << true ), info );
insertA( ns, 0 );
insertA( ns, 1 );
- auto_ptr< DBClientCursor > c1 = client().query( ns, QUERY( "a" << GT << -1 ), 0, 0, 0, QueryOption_CursorTailable );
+ auto_ptr< DBClientCursor > c1 = _client.query( ns, QUERY( "a" << GT << -1 ), 0, 0, 0, QueryOption_CursorTailable );
OID id;
id.init("000000000000000000000000");
- auto_ptr< DBClientCursor > c2 = client().query( ns, QUERY( "value" << GT << id ), 0, 0, 0, QueryOption_CursorTailable );
+ auto_ptr< DBClientCursor > c2 = _client.query( ns, QUERY( "value" << GT << id ), 0, 0, 0, QueryOption_CursorTailable );
c1->next();
c1->next();
ASSERT( !c1->more() );
@@ -569,20 +565,20 @@ namespace QueryTests {
class OplogReplayMode : public ClientBase {
public:
~OplogReplayMode() {
- client().dropCollection( "unittests.querytests.OplogReplayMode" );
+ _client.dropCollection( "unittests.querytests.OplogReplayMode" );
}
void run() {
const char *ns = "unittests.querytests.OplogReplayMode";
insert( ns, BSON( "ts" << 0 ) );
insert( ns, BSON( "ts" << 1 ) );
insert( ns, BSON( "ts" << 2 ) );
- auto_ptr< DBClientCursor > c = client().query( ns, QUERY( "ts" << GT << 1 ).hint( BSON( "$natural" << 1 ) ), 0, 0, 0, QueryOption_OplogReplay );
+ auto_ptr< DBClientCursor > c = _client.query( ns, QUERY( "ts" << GT << 1 ).hint( BSON( "$natural" << 1 ) ), 0, 0, 0, QueryOption_OplogReplay );
ASSERT( c->more() );
ASSERT_EQUALS( 2, c->next().getIntField( "ts" ) );
ASSERT( !c->more() );
insert( ns, BSON( "ts" << 3 ) );
- c = client().query( ns, QUERY( "ts" << GT << 1 ).hint( BSON( "$natural" << 1 ) ), 0, 0, 0, QueryOption_OplogReplay );
+ c = _client.query( ns, QUERY( "ts" << GT << 1 ).hint( BSON( "$natural" << 1 ) ), 0, 0, 0, QueryOption_OplogReplay );
ASSERT( c->more() );
ASSERT_EQUALS( 2, c->next().getIntField( "ts" ) );
ASSERT( c->more() );
@@ -592,15 +588,15 @@ namespace QueryTests {
class OplogReplaySlaveReadTill : public ClientBase {
public:
~OplogReplaySlaveReadTill() {
- client().dropCollection( "unittests.querytests.OplogReplaySlaveReadTill" );
+ _client.dropCollection( "unittests.querytests.OplogReplaySlaveReadTill" );
}
void run() {
const char *ns = "unittests.querytests.OplogReplaySlaveReadTill";
Lock::DBWrite lk(_txn.lockState(), ns);
- Client::Context ctx( ns );
+ Client::Context ctx(&_txn, ns );
BSONObj info;
- client().runCommand( "unittests",
+ _client.runCommand( "unittests",
BSON( "create" << "querytests.OplogReplaySlaveReadTill" <<
"capped" << true << "size" << 8192 ),
info );
@@ -612,7 +608,7 @@ namespace QueryTests {
insert( ns, BSON( "ts" << two ) );
insert( ns, BSON( "ts" << three ) );
auto_ptr<DBClientCursor> c =
- client().query( ns, QUERY( "ts" << GTE << two ).hint( BSON( "$natural" << 1 ) ),
+ _client.query( ns, QUERY( "ts" << GTE << two ).hint( BSON( "$natural" << 1 ) ),
0, 0, 0, QueryOption_OplogReplay | QueryOption_CursorTailable );
ASSERT( c->more() );
ASSERT_EQUALS( two, c->next()["ts"].Date() );
@@ -626,14 +622,14 @@ namespace QueryTests {
class OplogReplayExplain : public ClientBase {
public:
~OplogReplayExplain() {
- client().dropCollection( "unittests.querytests.OplogReplayExplain" );
+ _client.dropCollection( "unittests.querytests.OplogReplayExplain" );
}
void run() {
const char *ns = "unittests.querytests.OplogReplayExplain";
insert( ns, BSON( "ts" << 0 ) );
insert( ns, BSON( "ts" << 1 ) );
insert( ns, BSON( "ts" << 2 ) );
- auto_ptr< DBClientCursor > c = client().query(
+ auto_ptr< DBClientCursor > c = _client.query(
ns, QUERY( "ts" << GT << 1 ).hint( BSON( "$natural" << 1 ) ).explain(),
0, 0, 0, QueryOption_OplogReplay );
ASSERT( c->more() );
@@ -651,11 +647,11 @@ namespace QueryTests {
class BasicCount : public ClientBase {
public:
~BasicCount() {
- client().dropCollection( "unittests.querytests.BasicCount" );
+ _client.dropCollection( "unittests.querytests.BasicCount" );
}
void run() {
const char *ns = "unittests.querytests.BasicCount";
- client().ensureIndex( ns, BSON( "a" << 1 ) );
+ _client.ensureIndex( ns, BSON( "a" << 1 ) );
count( 0 );
insert( ns, BSON( "a" << 3 ) );
count( 0 );
@@ -668,20 +664,20 @@ namespace QueryTests {
}
private:
void count( unsigned long long c ) {
- ASSERT_EQUALS( c, client().count( "unittests.querytests.BasicCount", BSON( "a" << 4 ) ) );
+ ASSERT_EQUALS( c, _client.count( "unittests.querytests.BasicCount", BSON( "a" << 4 ) ) );
}
};
class ArrayId : public ClientBase {
public:
~ArrayId() {
- client().dropCollection( "unittests.querytests.ArrayId" );
+ _client.dropCollection( "unittests.querytests.ArrayId" );
}
void run() {
const char *ns = "unittests.querytests.ArrayId";
- client().ensureIndex( ns, BSON( "_id" << 1 ) );
+ _client.ensureIndex( ns, BSON( "_id" << 1 ) );
ASSERT( !error() );
- client().insert( ns, fromjson( "{'_id':[1,2]}" ) );
+ _client.insert( ns, fromjson( "{'_id':[1,2]}" ) );
ASSERT( error() );
}
};
@@ -689,14 +685,14 @@ namespace QueryTests {
class UnderscoreNs : public ClientBase {
public:
~UnderscoreNs() {
- client().dropCollection( "unittests.querytests._UnderscoreNs" );
+ _client.dropCollection( "unittests.querytests._UnderscoreNs" );
}
void run() {
ASSERT( !error() );
const char *ns = "unittests.querytests._UnderscoreNs";
- ASSERT( client().findOne( ns, "{}" ).isEmpty() );
- client().insert( ns, BSON( "a" << 1 ) );
- ASSERT_EQUALS( 1, client().findOne( ns, "{}" ).getIntField( "a" ) );
+ ASSERT( _client.findOne( ns, "{}" ).isEmpty() );
+ _client.insert( ns, BSON( "a" << 1 ) );
+ ASSERT_EQUALS( 1, _client.findOne( ns, "{}" ).getIntField( "a" ) );
ASSERT( !error() );
}
};
@@ -704,84 +700,84 @@ namespace QueryTests {
class EmptyFieldSpec : public ClientBase {
public:
~EmptyFieldSpec() {
- client().dropCollection( "unittests.querytests.EmptyFieldSpec" );
+ _client.dropCollection( "unittests.querytests.EmptyFieldSpec" );
}
void run() {
const char *ns = "unittests.querytests.EmptyFieldSpec";
- client().insert( ns, BSON( "a" << 1 ) );
- ASSERT( !client().findOne( ns, "" ).isEmpty() );
+ _client.insert( ns, BSON( "a" << 1 ) );
+ ASSERT( !_client.findOne( ns, "" ).isEmpty() );
BSONObj empty;
- ASSERT( !client().findOne( ns, "", &empty ).isEmpty() );
+ ASSERT( !_client.findOne( ns, "", &empty ).isEmpty() );
}
};
class MultiNe : public ClientBase {
public:
~MultiNe() {
- client().dropCollection( "unittests.querytests.Ne" );
+ _client.dropCollection( "unittests.querytests.Ne" );
}
void run() {
const char *ns = "unittests.querytests.Ne";
- client().insert( ns, fromjson( "{a:[1,2]}" ) );
- ASSERT( client().findOne( ns, fromjson( "{a:{$ne:1}}" ) ).isEmpty() );
+ _client.insert( ns, fromjson( "{a:[1,2]}" ) );
+ ASSERT( _client.findOne( ns, fromjson( "{a:{$ne:1}}" ) ).isEmpty() );
BSONObj spec = fromjson( "{a:{$ne:1,$ne:2}}" );
- ASSERT( client().findOne( ns, spec ).isEmpty() );
+ ASSERT( _client.findOne( ns, spec ).isEmpty() );
}
};
class EmbeddedNe : public ClientBase {
public:
~EmbeddedNe() {
- client().dropCollection( "unittests.querytests.NestedNe" );
+ _client.dropCollection( "unittests.querytests.NestedNe" );
}
void run() {
const char *ns = "unittests.querytests.NestedNe";
- client().insert( ns, fromjson( "{a:[{b:1},{b:2}]}" ) );
- ASSERT( client().findOne( ns, fromjson( "{'a.b':{$ne:1}}" ) ).isEmpty() );
+ _client.insert( ns, fromjson( "{a:[{b:1},{b:2}]}" ) );
+ ASSERT( _client.findOne( ns, fromjson( "{'a.b':{$ne:1}}" ) ).isEmpty() );
}
};
class EmbeddedNumericTypes : public ClientBase {
public:
~EmbeddedNumericTypes() {
- client().dropCollection( "unittests.querytests.NumericEmbedded" );
+ _client.dropCollection( "unittests.querytests.NumericEmbedded" );
}
void run() {
const char *ns = "unittests.querytests.NumericEmbedded";
- client().insert( ns, BSON( "a" << BSON ( "b" << 1 ) ) );
- ASSERT( ! client().findOne( ns, BSON( "a" << BSON ( "b" << 1.0 ) ) ).isEmpty() );
- client().ensureIndex( ns , BSON( "a" << 1 ) );
- ASSERT( ! client().findOne( ns, BSON( "a" << BSON ( "b" << 1.0 ) ) ).isEmpty() );
+ _client.insert( ns, BSON( "a" << BSON ( "b" << 1 ) ) );
+ ASSERT( ! _client.findOne( ns, BSON( "a" << BSON ( "b" << 1.0 ) ) ).isEmpty() );
+ _client.ensureIndex( ns , BSON( "a" << 1 ) );
+ ASSERT( ! _client.findOne( ns, BSON( "a" << BSON ( "b" << 1.0 ) ) ).isEmpty() );
}
};
class AutoResetIndexCache : public ClientBase {
public:
~AutoResetIndexCache() {
- client().dropCollection( "unittests.querytests.AutoResetIndexCache" );
+ _client.dropCollection( "unittests.querytests.AutoResetIndexCache" );
}
static const char *ns() { return "unittests.querytests.AutoResetIndexCache"; }
static const char *idxNs() { return "unittests.system.indexes"; }
- void index() { ASSERT( !client().findOne( idxNs(), BSON( "name" << NE << "_id_" ) ).isEmpty() ); }
+ void index() { ASSERT( !_client.findOne( idxNs(), BSON( "name" << NE << "_id_" ) ).isEmpty() ); }
void noIndex() {
- BSONObj o = client().findOne( idxNs(), BSON( "name" << NE << "_id_" ) );
+ BSONObj o = _client.findOne( idxNs(), BSON( "name" << NE << "_id_" ) );
if( !o.isEmpty() ) {
cout << o.toString() << endl;
ASSERT( false );
}
}
void checkIndex() {
- client().ensureIndex( ns(), BSON( "a" << 1 ) );
+ _client.ensureIndex( ns(), BSON( "a" << 1 ) );
index();
}
void run() {
- client().dropDatabase( "unittests" );
+ _client.dropDatabase( "unittests" );
noIndex();
checkIndex();
- client().dropCollection( ns() );
+ _client.dropCollection( ns() );
noIndex();
checkIndex();
- client().dropDatabase( "unittests" );
+ _client.dropDatabase( "unittests" );
noIndex();
checkIndex();
}
@@ -790,130 +786,130 @@ namespace QueryTests {
class UniqueIndex : public ClientBase {
public:
~UniqueIndex() {
- client().dropCollection( "unittests.querytests.UniqueIndex" );
+ _client.dropCollection( "unittests.querytests.UniqueIndex" );
}
void run() {
const char *ns = "unittests.querytests.UniqueIndex";
- client().ensureIndex( ns, BSON( "a" << 1 ), true );
- client().insert( ns, BSON( "a" << 4 << "b" << 2 ) );
- client().insert( ns, BSON( "a" << 4 << "b" << 3 ) );
- ASSERT_EQUALS( 1U, client().count( ns, BSONObj() ) );
- client().dropCollection( ns );
- client().ensureIndex( ns, BSON( "b" << 1 ), true );
- client().insert( ns, BSON( "a" << 4 << "b" << 2 ) );
- client().insert( ns, BSON( "a" << 4 << "b" << 3 ) );
- ASSERT_EQUALS( 2U, client().count( ns, BSONObj() ) );
+ _client.ensureIndex( ns, BSON( "a" << 1 ), true );
+ _client.insert( ns, BSON( "a" << 4 << "b" << 2 ) );
+ _client.insert( ns, BSON( "a" << 4 << "b" << 3 ) );
+ ASSERT_EQUALS( 1U, _client.count( ns, BSONObj() ) );
+ _client.dropCollection( ns );
+ _client.ensureIndex( ns, BSON( "b" << 1 ), true );
+ _client.insert( ns, BSON( "a" << 4 << "b" << 2 ) );
+ _client.insert( ns, BSON( "a" << 4 << "b" << 3 ) );
+ ASSERT_EQUALS( 2U, _client.count( ns, BSONObj() ) );
}
};
class UniqueIndexPreexistingData : public ClientBase {
public:
~UniqueIndexPreexistingData() {
- client().dropCollection( "unittests.querytests.UniqueIndexPreexistingData" );
+ _client.dropCollection( "unittests.querytests.UniqueIndexPreexistingData" );
}
void run() {
const char *ns = "unittests.querytests.UniqueIndexPreexistingData";
- client().insert( ns, BSON( "a" << 4 << "b" << 2 ) );
- client().insert( ns, BSON( "a" << 4 << "b" << 3 ) );
- client().ensureIndex( ns, BSON( "a" << 1 ), true );
- ASSERT_EQUALS( 0U, client().count( "unittests.system.indexes", BSON( "ns" << ns << "name" << NE << "_id_" ) ) );
+ _client.insert( ns, BSON( "a" << 4 << "b" << 2 ) );
+ _client.insert( ns, BSON( "a" << 4 << "b" << 3 ) );
+ _client.ensureIndex( ns, BSON( "a" << 1 ), true );
+ ASSERT_EQUALS( 0U, _client.count( "unittests.system.indexes", BSON( "ns" << ns << "name" << NE << "_id_" ) ) );
}
};
class SubobjectInArray : public ClientBase {
public:
~SubobjectInArray() {
- client().dropCollection( "unittests.querytests.SubobjectInArray" );
+ _client.dropCollection( "unittests.querytests.SubobjectInArray" );
}
void run() {
const char *ns = "unittests.querytests.SubobjectInArray";
- client().insert( ns, fromjson( "{a:[{b:{c:1}}]}" ) );
- ASSERT( !client().findOne( ns, BSON( "a.b.c" << 1 ) ).isEmpty() );
- ASSERT( !client().findOne( ns, fromjson( "{'a.c':null}" ) ).isEmpty() );
+ _client.insert( ns, fromjson( "{a:[{b:{c:1}}]}" ) );
+ ASSERT( !_client.findOne( ns, BSON( "a.b.c" << 1 ) ).isEmpty() );
+ ASSERT( !_client.findOne( ns, fromjson( "{'a.c':null}" ) ).isEmpty() );
}
};
class Size : public ClientBase {
public:
~Size() {
- client().dropCollection( "unittests.querytests.Size" );
+ _client.dropCollection( "unittests.querytests.Size" );
}
void run() {
const char *ns = "unittests.querytests.Size";
- client().insert( ns, fromjson( "{a:[1,2,3]}" ) );
- client().ensureIndex( ns, BSON( "a" << 1 ) );
- ASSERT( client().query( ns, QUERY( "a" << mongo::BSIZE << 3 ).hint( BSON( "a" << 1 ) ) )->more() );
+ _client.insert( ns, fromjson( "{a:[1,2,3]}" ) );
+ _client.ensureIndex( ns, BSON( "a" << 1 ) );
+ ASSERT( _client.query( ns, QUERY( "a" << mongo::BSIZE << 3 ).hint( BSON( "a" << 1 ) ) )->more() );
}
};
class FullArray : public ClientBase {
public:
~FullArray() {
- client().dropCollection( "unittests.querytests.IndexedArray" );
+ _client.dropCollection( "unittests.querytests.IndexedArray" );
}
void run() {
const char *ns = "unittests.querytests.IndexedArray";
- client().insert( ns, fromjson( "{a:[1,2,3]}" ) );
- ASSERT( client().query( ns, Query( "{a:[1,2,3]}" ) )->more() );
- client().ensureIndex( ns, BSON( "a" << 1 ) );
- ASSERT( client().query( ns, Query( "{a:{$in:[1,[1,2,3]]}}" ).hint( BSON( "a" << 1 ) ) )->more() );
- ASSERT( client().query( ns, Query( "{a:[1,2,3]}" ).hint( BSON( "a" << 1 ) ) )->more() ); // SERVER-146
+ _client.insert( ns, fromjson( "{a:[1,2,3]}" ) );
+ ASSERT( _client.query( ns, Query( "{a:[1,2,3]}" ) )->more() );
+ _client.ensureIndex( ns, BSON( "a" << 1 ) );
+ ASSERT( _client.query( ns, Query( "{a:{$in:[1,[1,2,3]]}}" ).hint( BSON( "a" << 1 ) ) )->more() );
+ ASSERT( _client.query( ns, Query( "{a:[1,2,3]}" ).hint( BSON( "a" << 1 ) ) )->more() ); // SERVER-146
}
};
class InsideArray : public ClientBase {
public:
~InsideArray() {
- client().dropCollection( "unittests.querytests.InsideArray" );
+ _client.dropCollection( "unittests.querytests.InsideArray" );
}
void run() {
const char *ns = "unittests.querytests.InsideArray";
- client().insert( ns, fromjson( "{a:[[1],2]}" ) );
+ _client.insert( ns, fromjson( "{a:[[1],2]}" ) );
check( "$natural" );
- client().ensureIndex( ns, BSON( "a" << 1 ) );
+ _client.ensureIndex( ns, BSON( "a" << 1 ) );
check( "a" ); // SERVER-146
}
private:
void check( const string &hintField ) {
const char *ns = "unittests.querytests.InsideArray";
- ASSERT( client().query( ns, Query( "{a:[[1],2]}" ).hint( BSON( hintField << 1 ) ) )->more() );
- ASSERT( client().query( ns, Query( "{a:[1]}" ).hint( BSON( hintField << 1 ) ) )->more() );
- ASSERT( client().query( ns, Query( "{a:2}" ).hint( BSON( hintField << 1 ) ) )->more() );
- ASSERT( !client().query( ns, Query( "{a:1}" ).hint( BSON( hintField << 1 ) ) )->more() );
+ ASSERT( _client.query( ns, Query( "{a:[[1],2]}" ).hint( BSON( hintField << 1 ) ) )->more() );
+ ASSERT( _client.query( ns, Query( "{a:[1]}" ).hint( BSON( hintField << 1 ) ) )->more() );
+ ASSERT( _client.query( ns, Query( "{a:2}" ).hint( BSON( hintField << 1 ) ) )->more() );
+ ASSERT( !_client.query( ns, Query( "{a:1}" ).hint( BSON( hintField << 1 ) ) )->more() );
}
};
class IndexInsideArrayCorrect : public ClientBase {
public:
~IndexInsideArrayCorrect() {
- client().dropCollection( "unittests.querytests.IndexInsideArrayCorrect" );
+ _client.dropCollection( "unittests.querytests.IndexInsideArrayCorrect" );
}
void run() {
const char *ns = "unittests.querytests.IndexInsideArrayCorrect";
- client().insert( ns, fromjson( "{'_id':1,a:[1]}" ) );
- client().insert( ns, fromjson( "{'_id':2,a:[[1]]}" ) );
- client().ensureIndex( ns, BSON( "a" << 1 ) );
- ASSERT_EQUALS( 1, client().query( ns, Query( "{a:[1]}" ).hint( BSON( "a" << 1 ) ) )->next().getIntField( "_id" ) );
+ _client.insert( ns, fromjson( "{'_id':1,a:[1]}" ) );
+ _client.insert( ns, fromjson( "{'_id':2,a:[[1]]}" ) );
+ _client.ensureIndex( ns, BSON( "a" << 1 ) );
+ ASSERT_EQUALS( 1, _client.query( ns, Query( "{a:[1]}" ).hint( BSON( "a" << 1 ) ) )->next().getIntField( "_id" ) );
}
};
class SubobjArr : public ClientBase {
public:
~SubobjArr() {
- client().dropCollection( "unittests.querytests.SubobjArr" );
+ _client.dropCollection( "unittests.querytests.SubobjArr" );
}
void run() {
const char *ns = "unittests.querytests.SubobjArr";
- client().insert( ns, fromjson( "{a:[{b:[1]}]}" ) );
+ _client.insert( ns, fromjson( "{a:[{b:[1]}]}" ) );
check( "$natural" );
- client().ensureIndex( ns, BSON( "a" << 1 ) );
+ _client.ensureIndex( ns, BSON( "a" << 1 ) );
check( "a" );
}
private:
void check( const string &hintField ) {
const char *ns = "unittests.querytests.SubobjArr";
- ASSERT( client().query( ns, Query( "{'a.b':1}" ).hint( BSON( hintField << 1 ) ) )->more() );
- ASSERT( client().query( ns, Query( "{'a.b':[1]}" ).hint( BSON( hintField << 1 ) ) )->more() );
+ ASSERT( _client.query( ns, Query( "{'a.b':1}" ).hint( BSON( hintField << 1 ) ) )->more() );
+ ASSERT( _client.query( ns, Query( "{'a.b':[1]}" ).hint( BSON( hintField << 1 ) ) )->more() );
}
};
@@ -921,16 +917,16 @@ namespace QueryTests {
public:
MinMax() : ns( "unittests.querytests.MinMax" ) {}
~MinMax() {
- client().dropCollection( "unittests.querytests.MinMax" );
+ _client.dropCollection( "unittests.querytests.MinMax" );
}
void run() {
- client().ensureIndex( ns, BSON( "a" << 1 << "b" << 1 ) );
- client().insert( ns, BSON( "a" << 1 << "b" << 1 ) );
- client().insert( ns, BSON( "a" << 1 << "b" << 2 ) );
- client().insert( ns, BSON( "a" << 2 << "b" << 1 ) );
- client().insert( ns, BSON( "a" << 2 << "b" << 2 ) );
+ _client.ensureIndex( ns, BSON( "a" << 1 << "b" << 1 ) );
+ _client.insert( ns, BSON( "a" << 1 << "b" << 1 ) );
+ _client.insert( ns, BSON( "a" << 1 << "b" << 2 ) );
+ _client.insert( ns, BSON( "a" << 2 << "b" << 1 ) );
+ _client.insert( ns, BSON( "a" << 2 << "b" << 2 ) );
- ASSERT_EQUALS( 4, count( client().query( ns, BSONObj() ) ) );
+ ASSERT_EQUALS( 4, count( _client.query( ns, BSONObj() ) ) );
BSONObj hints[] = { BSONObj(), BSON( "a" << 1 << "b" << 1 ) };
for( int i = 0; i < 2; ++i ) {
check( 0, 0, 3, 3, 4, hints[ i ] );
@@ -954,7 +950,7 @@ namespace QueryTests {
q = q.minKey( BSON( "a" << minA << "b" << minB ) ).maxKey( BSON( "a" << maxA << "b" << maxB ) );
if ( !hint.isEmpty() )
q.hint( hint );
- return client().query( ns, q );
+ return _client.query( ns, q );
}
void check( int minA, int minB, int maxA, int maxB, int expectedCount, const BSONObj &hint = empty_ ) {
ASSERT_EQUALS( expectedCount, count( query( minA, minB, maxA, maxB, hint ) ) );
@@ -976,15 +972,15 @@ namespace QueryTests {
public:
MatchCodeCodeWScope() : _ns( "unittests.querytests.MatchCodeCodeWScope" ) {}
~MatchCodeCodeWScope() {
- client().dropCollection( "unittests.querytests.MatchCodeCodeWScope" );
+ _client.dropCollection( "unittests.querytests.MatchCodeCodeWScope" );
}
void run() {
checkMatch();
- client().ensureIndex( _ns, BSON( "a" << 1 ) );
+ _client.ensureIndex( _ns, BSON( "a" << 1 ) );
checkMatch();
// Use explain queries to check index bounds.
{
- BSONObj explain = client().findOne( _ns, QUERY( "a" << BSON( "$type" << (int)Code ) ).explain() );
+ BSONObj explain = _client.findOne( _ns, QUERY( "a" << BSON( "$type" << (int)Code ) ).explain() );
BSONObjBuilder lower;
lower.appendCode( "", "" );
BSONObjBuilder upper;
@@ -993,7 +989,7 @@ namespace QueryTests {
ASSERT( upper.done().firstElement().valuesEqual( explain[ "indexBounds" ].Obj()[ "a" ].Array()[ 0 ].Array()[ 1 ] ) );
}
{
- BSONObj explain = client().findOne( _ns, QUERY( "a" << BSON( "$type" << (int)CodeWScope ) ).explain() );
+ BSONObj explain = _client.findOne( _ns, QUERY( "a" << BSON( "$type" << (int)CodeWScope ) ).explain() );
BSONObjBuilder lower;
lower.appendCodeWScope( "", "", BSONObj() );
// This upper bound may change if a new bson type is added.
@@ -1005,16 +1001,16 @@ namespace QueryTests {
}
private:
void checkMatch() {
- client().remove( _ns, BSONObj() );
+ _client.remove( _ns, BSONObj() );
- client().insert( _ns, code() );
- client().insert( _ns, codeWScope() );
+ _client.insert( _ns, code() );
+ _client.insert( _ns, codeWScope() );
- ASSERT_EQUALS( 1U, client().count( _ns, code() ) );
- ASSERT_EQUALS( 1U, client().count( _ns, codeWScope() ) );
+ ASSERT_EQUALS( 1U, _client.count( _ns, code() ) );
+ ASSERT_EQUALS( 1U, _client.count( _ns, codeWScope() ) );
- ASSERT_EQUALS( 1U, client().count( _ns, BSON( "a" << BSON( "$type" << (int)Code ) ) ) );
- ASSERT_EQUALS( 1U, client().count( _ns, BSON( "a" << BSON( "$type" << (int)CodeWScope ) ) ) );
+ ASSERT_EQUALS( 1U, _client.count( _ns, BSON( "a" << BSON( "$type" << (int)Code ) ) ) );
+ ASSERT_EQUALS( 1U, _client.count( _ns, BSON( "a" << BSON( "$type" << (int)CodeWScope ) ) ) );
}
BSONObj code() const {
BSONObjBuilder codeBuilder;
@@ -1033,19 +1029,19 @@ namespace QueryTests {
public:
MatchDBRefType() : _ns( "unittests.querytests.MatchDBRefType" ) {}
~MatchDBRefType() {
- client().dropCollection( "unittests.querytests.MatchDBRefType" );
+ _client.dropCollection( "unittests.querytests.MatchDBRefType" );
}
void run() {
checkMatch();
- client().ensureIndex( _ns, BSON( "a" << 1 ) );
+ _client.ensureIndex( _ns, BSON( "a" << 1 ) );
checkMatch();
}
private:
void checkMatch() {
- client().remove( _ns, BSONObj() );
- client().insert( _ns, dbref() );
- ASSERT_EQUALS( 1U, client().count( _ns, dbref() ) );
- ASSERT_EQUALS( 1U, client().count( _ns, BSON( "a" << BSON( "$type" << (int)DBRef ) ) ) );
+ _client.remove( _ns, BSONObj() );
+ _client.insert( _ns, dbref() );
+ ASSERT_EQUALS( 1U, _client.count( _ns, dbref() ) );
+ ASSERT_EQUALS( 1U, _client.count( _ns, BSON( "a" << BSON( "$type" << (int)DBRef ) ) ) );
}
BSONObj dbref() const {
BSONObjBuilder b;
@@ -1060,8 +1056,8 @@ namespace QueryTests {
public:
void run() {
Lock::GlobalWrite lk(_txn.lockState());
- Client::Context ctx( "unittests.DirectLocking" );
- client().remove( "a.b", BSONObj() );
+ Client::Context ctx(&_txn, "unittests.DirectLocking");
+ _client.remove( "a.b", BSONObj() );
ASSERT_EQUALS( "unittests", ctx.db()->name() );
}
const char *ns;
@@ -1070,39 +1066,39 @@ namespace QueryTests {
class FastCountIn : public ClientBase {
public:
~FastCountIn() {
- client().dropCollection( "unittests.querytests.FastCountIn" );
+ _client.dropCollection( "unittests.querytests.FastCountIn" );
}
void run() {
const char *ns = "unittests.querytests.FastCountIn";
- client().insert( ns, BSON( "i" << "a" ) );
- client().ensureIndex( ns, BSON( "i" << 1 ) );
- ASSERT_EQUALS( 1U, client().count( ns, fromjson( "{i:{$in:['a']}}" ) ) );
+ _client.insert( ns, BSON( "i" << "a" ) );
+ _client.ensureIndex( ns, BSON( "i" << 1 ) );
+ ASSERT_EQUALS( 1U, _client.count( ns, fromjson( "{i:{$in:['a']}}" ) ) );
}
};
class EmbeddedArray : public ClientBase {
public:
~EmbeddedArray() {
- client().dropCollection( "unittests.querytests.EmbeddedArray" );
+ _client.dropCollection( "unittests.querytests.EmbeddedArray" );
}
void run() {
const char *ns = "unittests.querytests.EmbeddedArray";
- client().insert( ns, fromjson( "{foo:{bar:['spam']}}" ) );
- client().insert( ns, fromjson( "{foo:{bar:['spam','eggs']}}" ) );
- client().insert( ns, fromjson( "{bar:['spam']}" ) );
- client().insert( ns, fromjson( "{bar:['spam','eggs']}" ) );
- ASSERT_EQUALS( 2U, client().count( ns, BSON( "bar" << "spam" ) ) );
- ASSERT_EQUALS( 2U, client().count( ns, BSON( "foo.bar" << "spam" ) ) );
+ _client.insert( ns, fromjson( "{foo:{bar:['spam']}}" ) );
+ _client.insert( ns, fromjson( "{foo:{bar:['spam','eggs']}}" ) );
+ _client.insert( ns, fromjson( "{bar:['spam']}" ) );
+ _client.insert( ns, fromjson( "{bar:['spam','eggs']}" ) );
+ ASSERT_EQUALS( 2U, _client.count( ns, BSON( "bar" << "spam" ) ) );
+ ASSERT_EQUALS( 2U, _client.count( ns, BSON( "foo.bar" << "spam" ) ) );
}
};
class DifferentNumbers : public ClientBase {
public:
~DifferentNumbers() {
- client().dropCollection( "unittests.querytests.DifferentNumbers" );
+ _client.dropCollection( "unittests.querytests.DifferentNumbers" );
}
void t( const char * ns ) {
- auto_ptr< DBClientCursor > cursor = client().query( ns, Query().sort( "7" ) );
+ auto_ptr< DBClientCursor > cursor = _client.query( ns, Query().sort( "7" ) );
while ( cursor->more() ) {
BSONObj o = cursor->next();
verify( o.valid() );
@@ -1112,15 +1108,15 @@ namespace QueryTests {
}
void run() {
const char *ns = "unittests.querytests.DifferentNumbers";
- { BSONObjBuilder b; b.append( "7" , (int)4 ); client().insert( ns , b.obj() ); }
- { BSONObjBuilder b; b.append( "7" , (long long)2 ); client().insert( ns , b.obj() ); }
- { BSONObjBuilder b; b.appendNull( "7" ); client().insert( ns , b.obj() ); }
- { BSONObjBuilder b; b.append( "7" , "b" ); client().insert( ns , b.obj() ); }
- { BSONObjBuilder b; b.appendNull( "8" ); client().insert( ns , b.obj() ); }
- { BSONObjBuilder b; b.append( "7" , (double)3.7 ); client().insert( ns , b.obj() ); }
+ { BSONObjBuilder b; b.append( "7" , (int)4 ); _client.insert( ns , b.obj() ); }
+ { BSONObjBuilder b; b.append( "7" , (long long)2 ); _client.insert( ns , b.obj() ); }
+ { BSONObjBuilder b; b.appendNull( "7" ); _client.insert( ns , b.obj() ); }
+ { BSONObjBuilder b; b.append( "7" , "b" ); _client.insert( ns , b.obj() ); }
+ { BSONObjBuilder b; b.appendNull( "8" ); _client.insert( ns , b.obj() ); }
+ { BSONObjBuilder b; b.append( "7" , (double)3.7 ); _client.insert( ns , b.obj() ); }
t(ns);
- client().ensureIndex( ns , BSON( "7" << 1 ) );
+ _client.ensureIndex( ns , BSON( "7" << 1 ) );
t(ns);
}
};
@@ -1131,15 +1127,15 @@ namespace QueryTests {
CollectionBase( string leaf ) {
_ns = "unittests.querytests.";
_ns += leaf;
- client().dropCollection( ns() );
+ _client.dropCollection( ns() );
}
virtual ~CollectionBase() {
- client().dropCollection( ns() );
+ _client.dropCollection( ns() );
}
int count() {
- return (int) client().count( ns() );
+ return (int) _client.count( ns() );
}
size_t numCursorsOpen() {
@@ -1163,16 +1159,16 @@ namespace QueryTests {
SymbolStringSame() : CollectionBase( "symbolstringsame" ) {}
void run() {
- { BSONObjBuilder b; b.appendSymbol( "x" , "eliot" ); b.append( "z" , 17 ); client().insert( ns() , b.obj() ); }
- ASSERT_EQUALS( 17 , client().findOne( ns() , BSONObj() )["z"].number() );
+ { BSONObjBuilder b; b.appendSymbol( "x" , "eliot" ); b.append( "z" , 17 ); _client.insert( ns() , b.obj() ); }
+ ASSERT_EQUALS( 17 , _client.findOne( ns() , BSONObj() )["z"].number() );
{
BSONObjBuilder b;
b.appendSymbol( "x" , "eliot" );
- ASSERT_EQUALS( 17 , client().findOne( ns() , b.obj() )["z"].number() );
+ ASSERT_EQUALS( 17 , _client.findOne( ns() , b.obj() )["z"].number() );
}
- ASSERT_EQUALS( 17 , client().findOne( ns() , BSON( "x" << "eliot" ) )["z"].number() );
- client().ensureIndex( ns() , BSON( "x" << 1 ) );
- ASSERT_EQUALS( 17 , client().findOne( ns() , BSON( "x" << "eliot" ) )["z"].number() );
+ ASSERT_EQUALS( 17 , _client.findOne( ns() , BSON( "x" << "eliot" ) )["z"].number() );
+ _client.ensureIndex( ns() , BSON( "x" << 1 ) );
+ ASSERT_EQUALS( 17 , _client.findOne( ns() , BSON( "x" << "eliot" ) )["z"].number() );
}
};
@@ -1180,7 +1176,7 @@ namespace QueryTests {
public:
TailableCappedRaceCondition() : CollectionBase( "tailablecappedrace" ) {
- client().dropCollection( ns() );
+ _client.dropCollection( ns() );
_n = 0;
}
void run() {
@@ -1197,7 +1193,7 @@ namespace QueryTests {
int a = count();
- auto_ptr< DBClientCursor > c = client().query( ns() , QUERY( "i" << GT << 0 ).hint( BSON( "$natural" << 1 ) ), 0, 0, 0, QueryOption_CursorTailable );
+ auto_ptr< DBClientCursor > c = _client.query( ns() , QUERY( "i" << GT << 0 ).hint( BSON( "$natural" << 1 ) ), 0, 0, 0, QueryOption_CursorTailable );
int n=0;
while ( c->more() ) {
BSONObj z = c->next();
@@ -1291,7 +1287,7 @@ namespace QueryTests {
insert( ns() , BSON( "_id" << i << "x" << i * 2 ) );
}
for ( int i=0; i<1000; i+=2 ) {
- client_.remove( ns() , BSON( "_id" << i ) );
+ _client.remove( ns() , BSON( "_id" << i ) );
}
BSONObj res;
@@ -1325,18 +1321,18 @@ namespace QueryTests {
void run() {
BSONObj info;
- ASSERT( client().runCommand( "unittests", BSON( "create" << "querytests.findingstart" << "capped" << true << "$nExtents" << 5 << "autoIndexId" << false ), info ) );
+ ASSERT( _client.runCommand( "unittests", BSON( "create" << "querytests.findingstart" << "capped" << true << "$nExtents" << 5 << "autoIndexId" << false ), info ) );
int i = 0;
for( int oldCount = -1;
count() != oldCount;
- oldCount = count(), client().insert( ns(), BSON( "ts" << i++ ) ) );
+ oldCount = count(), _client.insert( ns(), BSON( "ts" << i++ ) ) );
for( int k = 0; k < 5; ++k ) {
- client().insert( ns(), BSON( "ts" << i++ ) );
- int min = client().query( ns(), Query().sort( BSON( "$natural" << 1 ) ) )->next()[ "ts" ].numberInt();
+ _client.insert( ns(), BSON( "ts" << i++ ) );
+ int min = _client.query( ns(), Query().sort( BSON( "$natural" << 1 ) ) )->next()[ "ts" ].numberInt();
for( int j = -1; j < i; ++j ) {
- auto_ptr< DBClientCursor > c = client().query( ns(), QUERY( "ts" << GTE << j ), 0, 0, 0, QueryOption_OplogReplay );
+ auto_ptr< DBClientCursor > c = _client.query( ns(), QUERY( "ts" << GTE << j ), 0, 0, 0, QueryOption_OplogReplay );
ASSERT( c->more() );
BSONObj next = c->next();
ASSERT( !next[ "ts" ].eoo() );
@@ -1356,16 +1352,16 @@ namespace QueryTests {
size_t startNumCursors = numCursorsOpen();
BSONObj info;
- ASSERT( client().runCommand( "unittests", BSON( "create" << "querytests.findingstart" << "capped" << true << "$nExtents" << 5 << "autoIndexId" << false ), info ) );
+ ASSERT( _client.runCommand( "unittests", BSON( "create" << "querytests.findingstart" << "capped" << true << "$nExtents" << 5 << "autoIndexId" << false ), info ) );
int i = 0;
- for( ; i < 150; client().insert( ns(), BSON( "ts" << i++ ) ) );
+ for( ; i < 150; _client.insert( ns(), BSON( "ts" << i++ ) ) );
for( int k = 0; k < 5; ++k ) {
- client().insert( ns(), BSON( "ts" << i++ ) );
- int min = client().query( ns(), Query().sort( BSON( "$natural" << 1 ) ) )->next()[ "ts" ].numberInt();
+ _client.insert( ns(), BSON( "ts" << i++ ) );
+ int min = _client.query( ns(), Query().sort( BSON( "$natural" << 1 ) ) )->next()[ "ts" ].numberInt();
for( int j = -1; j < i; ++j ) {
- auto_ptr< DBClientCursor > c = client().query( ns(), QUERY( "ts" << GTE << j ), 0, 0, 0, QueryOption_OplogReplay );
+ auto_ptr< DBClientCursor > c = _client.query( ns(), QUERY( "ts" << GTE << j ), 0, 0, 0, QueryOption_OplogReplay );
ASSERT( c->more() );
BSONObj next = c->next();
ASSERT( !next[ "ts" ].eoo() );
@@ -1389,19 +1385,19 @@ namespace QueryTests {
size_t startNumCursors = numCursorsOpen();
// Check OplogReplay mode with missing collection.
- auto_ptr< DBClientCursor > c0 = client().query( ns(), QUERY( "ts" << GTE << 50 ), 0, 0, 0, QueryOption_OplogReplay );
+ auto_ptr< DBClientCursor > c0 = _client.query( ns(), QUERY( "ts" << GTE << 50 ), 0, 0, 0, QueryOption_OplogReplay );
ASSERT( !c0->more() );
BSONObj info;
- ASSERT( client().runCommand( "unittests", BSON( "create" << "querytests.findingstart" << "capped" << true << "$nExtents" << 5 << "autoIndexId" << false ), info ) );
+ ASSERT( _client.runCommand( "unittests", BSON( "create" << "querytests.findingstart" << "capped" << true << "$nExtents" << 5 << "autoIndexId" << false ), info ) );
// Check OplogReplay mode with empty collection.
- auto_ptr< DBClientCursor > c = client().query( ns(), QUERY( "ts" << GTE << 50 ), 0, 0, 0, QueryOption_OplogReplay );
+ auto_ptr< DBClientCursor > c = _client.query( ns(), QUERY( "ts" << GTE << 50 ), 0, 0, 0, QueryOption_OplogReplay );
ASSERT( !c->more() );
// Check with some docs in the collection.
- for( int i = 100; i < 150; client().insert( ns(), BSON( "ts" << i++ ) ) );
- c = client().query( ns(), QUERY( "ts" << GTE << 50 ), 0, 0, 0, QueryOption_OplogReplay );
+ for( int i = 100; i < 150; _client.insert( ns(), BSON( "ts" << i++ ) ) );
+ c = _client.query( ns(), QUERY( "ts" << GTE << 50 ), 0, 0, 0, QueryOption_OplogReplay );
ASSERT( c->more() );
ASSERT_EQUALS( 100, c->next()[ "ts" ].numberInt() );
@@ -1415,7 +1411,7 @@ namespace QueryTests {
WhatsMyUri() : CollectionBase( "whatsmyuri" ) {}
void run() {
BSONObj result;
- client().runCommand( "admin", BSON( "whatsmyuri" << 1 ), result );
+ _client.runCommand( "admin", BSON( "whatsmyuri" << 1 ), result );
ASSERT_EQUALS( unknownAddress.toString(), result[ "you" ].str() );
}
};
@@ -1425,7 +1421,8 @@ namespace QueryTests {
CollectionInternalBase( const char *nsLeaf ) :
CollectionBase( nsLeaf ),
_lk(_txn.lockState(), ns() ),
- _ctx( ns() ) {
+ _ctx(&_txn, ns()) {
+
}
private:
Lock::DBWrite _lk;
@@ -1437,10 +1434,10 @@ namespace QueryTests {
Exhaust() : CollectionInternalBase( "exhaust" ) {}
void run() {
BSONObj info;
- ASSERT( client().runCommand( "unittests",
+ ASSERT( _client.runCommand( "unittests",
BSON( "create" << "querytests.exhaust" <<
"capped" << true << "size" << 8192 ), info ) );
- client().insert( ns(), BSON( "ts" << 0 ) );
+ _client.insert( ns(), BSON( "ts" << 0 ) );
Message message;
assembleRequest( ns(), BSON( "ts" << GTE << 0 ), 0, 0, 0,
QueryOption_OplogReplay | QueryOption_CursorTailable |
@@ -1462,7 +1459,7 @@ namespace QueryTests {
for( int i = 0; i < 150; ++i ) {
insert( ns(), BSONObj() );
}
- auto_ptr<DBClientCursor> c = client().query( ns(), Query() );
+ auto_ptr<DBClientCursor> c = _client.query( ns(), Query() );
ASSERT( c->more() );
long long cursorId = c->getCursorId();
@@ -1485,7 +1482,7 @@ namespace QueryTests {
for( int i = 0; i < 5; ++i ) {
insert( ns(), BSONObj() );
}
- auto_ptr<DBClientCursor> c = client().query( ns(), Query(), 5 );
+ auto_ptr<DBClientCursor> c = _client.query( ns(), Query(), 5 );
ASSERT( c->more() );
// With five results and a batch size of 5, no cursor is created.
ASSERT_EQUALS( 0, c->getCursorId() );
@@ -1500,8 +1497,8 @@ namespace QueryTests {
KillPinnedCursor() : CollectionBase( "killpinnedcursor" ) {
}
void run() {
- client().insert( ns(), vector<BSONObj>( 3, BSONObj() ) );
- auto_ptr<DBClientCursor> cursor = client().query( ns(), BSONObj(), 0, 0, 0, 0, 2 );
+ _client.insert( ns(), vector<BSONObj>( 3, BSONObj() ) );
+ auto_ptr<DBClientCursor> cursor = _client.query( ns(), BSONObj(), 0, 0, 0, 0, 2 );
ASSERT_EQUALS( 2, cursor->objsLeftInBatch() );
long long cursorId = cursor->getCursorId();
@@ -1513,7 +1510,7 @@ namespace QueryTests {
MsgAssertionException);
string expectedAssertion =
str::stream() << "Cannot kill active cursor " << cursorId;
- ASSERT_EQUALS( expectedAssertion, client().getLastError() );
+ ASSERT_EQUALS( expectedAssertion, _client.getLastError() );
}
// Verify that the remaining document is read from the cursor.
diff --git a/src/mongo/dbtests/replsettests.cpp b/src/mongo/dbtests/replsettests.cpp
index 07c57608ea8..0cd3597f34c 100644
--- a/src/mongo/dbtests/replsettests.cpp
+++ b/src/mongo/dbtests/replsettests.cpp
@@ -128,15 +128,16 @@ namespace ReplSetTests {
class Base {
- private:
- DBDirectClient _client;
-
protected:
static BackgroundSyncTest* _bgsync;
static repl::SyncTail* _tailer;
+ OperationContextImpl _txn;
+ DBDirectClient _client;
+
public:
- Base() {
+ Base() : _client(&_txn) {
+
}
~Base() {
@@ -146,48 +147,22 @@ namespace ReplSetTests {
return "unittests.repltests";
}
- DBDirectClient *client() { return &_client; }
-
- static void insert( const BSONObj &o, bool god = false ) {
- OperationContextImpl txn;
- Lock::DBWrite lk(txn.lockState(), ns());
- Client::Context ctx(ns());
-
- Database* db = ctx.db();
- Collection* coll = db->getCollection(&txn, ns());
- if (!coll) {
- coll = db->createCollection(&txn, ns());
- }
-
- if (o.hasField("_id")) {
- coll->insertDocument(&txn, o, true);
- return;
- }
-
- class BSONObjBuilder b;
- OID id;
- id.init();
- b.appendOID("_id", &id);
- b.appendElements(o);
- coll->insertDocument(&txn, b.obj(), true);
- }
-
BSONObj findOne( const BSONObj &query = BSONObj() ) {
- return client()->findOne( ns(), query );
+ return _client.findOne( ns(), query );
}
void drop() {
- OperationContextImpl txn;
- Client::WriteContext c(&txn, ns());
+ Client::WriteContext c(&_txn, ns());
Database* db = c.ctx().db();
- if ( db->getCollection( &txn, ns() ) == NULL ) {
+ if ( db->getCollection( &_txn, ns() ) == NULL ) {
return;
}
- db->dropCollection(&txn, ns());
+ db->dropCollection(&_txn, ns());
}
+
static void setup() {
replSettings.replSet = "foo";
replSettings.oplogSize = 5 * 1024 * 1024;
@@ -206,6 +181,29 @@ namespace ReplSetTests {
delete repl::theReplSet;
repl::theReplSet = rst;
}
+
+ static void insert(OperationContext* txn, const BSONObj &o, bool god = false) {
+ Lock::DBWrite lk(txn->lockState(), ns());
+ Client::Context ctx(txn, ns());
+
+ Database* db = ctx.db();
+ Collection* coll = db->getCollection(txn, ns());
+ if (!coll) {
+ coll = db->createCollection(txn, ns());
+ }
+
+ if (o.hasField("_id")) {
+ coll->insertDocument(txn, o, true);
+ return;
+ }
+
+ class BSONObjBuilder b;
+ OID id;
+ id.init();
+ b.appendOID("_id", &id);
+ b.appendElements(o);
+ coll->insertDocument(txn, b.obj(), true);
+ }
};
BackgroundSyncTest* Base::_bgsync = NULL;
@@ -274,7 +272,7 @@ namespace ReplSetTests {
return true;
}
- Base::insert(BSON("_id" << 123));
+ Base::insert(txn, BSON("_id" << 123));
return true;
}
};
@@ -309,7 +307,6 @@ namespace ReplSetTests {
class CappedInitialSync : public Base {
string _cappedNs;
- OperationContextImpl _txn;
Lock::DBWrite _lk;
string spec() const {
@@ -317,17 +314,15 @@ namespace ReplSetTests {
}
void create() {
- Client::Context c(_cappedNs);
- OperationContextImpl txn;
- ASSERT( userCreateNS( &txn, c.db(), _cappedNs, fromjson( spec() ), false ).isOK() );
+ Client::Context c(&_txn, _cappedNs);
+ ASSERT( userCreateNS( &_txn, c.db(), _cappedNs, fromjson( spec() ), false ).isOK() );
}
void dropCapped() {
- Client::Context c(_cappedNs);
- OperationContextImpl txn;
+ Client::Context c(&_txn, _cappedNs);
Database* db = c.db();
- if ( db->getCollection( &txn, _cappedNs ) ) {
- db->dropCollection( &txn, _cappedNs );
+ if ( db->getCollection( &_txn, _cappedNs ) ) {
+ db->dropCollection( &_txn, _cappedNs );
}
}
@@ -345,6 +340,7 @@ namespace ReplSetTests {
verify(!apply(o));
return o;
}
+
public:
CappedInitialSync() :
_cappedNs("unittests.foo.bar"), _lk(_txn.lockState(), _cappedNs) {
@@ -361,20 +357,18 @@ namespace ReplSetTests {
// returns true on success, false on failure
bool apply(const BSONObj& op) {
- Client::Context ctx( _cappedNs );
- OperationContextImpl txn;
+ Client::Context ctx(&_txn, _cappedNs );
// in an annoying twist of api, returns true on failure
- return !applyOperation_inlock(&txn, ctx.db(), op, true);
+ return !applyOperation_inlock(&_txn, ctx.db(), op, true);
}
void run() {
- OperationContextImpl txn;
- Lock::DBWrite lk(txn.lockState(), _cappedNs);
+ Lock::DBWrite lk(_txn.lockState(), _cappedNs);
BSONObj op = updateFail();
Sync s("");
- verify(!s.shouldRetry(&txn, op));
+ verify(!s.shouldRetry(&_txn, op));
}
};
@@ -393,7 +387,7 @@ namespace ReplSetTests {
}
void insert(OperationContext* txn) {
- Client::Context ctx(cappedNs());
+ Client::Context ctx(txn, cappedNs());
Database* db = ctx.db();
Collection* coll = db->getCollection(txn, cappedNs());
if (!coll) {
@@ -407,21 +401,19 @@ namespace ReplSetTests {
public:
virtual ~CappedUpdate() {}
void run() {
- OperationContextImpl txn;
-
// RARELY shoud be once/128x
for (int i=0; i<150; i++) {
- insert(&txn);
+ insert(&_txn);
updateSucceed();
}
- DBDirectClient client(&txn);
+ DBDirectClient client(&_txn);
int count = (int) client.count(cappedNs(), BSONObj());
verify(count > 1);
// check _id index created
- Client::Context ctx(cappedNs());
- Collection* collection = ctx.db()->getCollection( &txn, cappedNs() );
+ Client::Context ctx(&_txn, cappedNs());
+ Collection* collection = ctx.db()->getCollection( &_txn, cappedNs() );
verify(collection->getIndexCatalog()->findIdIndex());
}
};
@@ -440,7 +432,6 @@ namespace ReplSetTests {
public:
virtual ~CappedInsert() {}
void run() {
- OperationContextImpl txn;
// This will succeed, but not insert anything because they are changed to upserts
for (int i=0; i<150; i++) {
insertSucceed();
@@ -448,8 +439,8 @@ namespace ReplSetTests {
// this changed in 2.1.2
// we now have indexes on capped collections
- Client::Context ctx(cappedNs());
- Collection* collection = ctx.db()->getCollection( &txn, cappedNs() );
+ Client::Context ctx(&_txn, cappedNs());
+ Collection* collection = ctx.db()->getCollection( &_txn, cappedNs() );
verify(collection->getIndexCatalog()->findIdIndex());
}
};
@@ -541,13 +532,13 @@ namespace ReplSetTests {
addInserts(100);
applyOplog();
- ASSERT_EQUALS(expected, static_cast<int>(client()->count(ns())));
+ ASSERT_EQUALS(expected, static_cast<int>(_client.count(ns())));
drop();
addVersionedInserts(100);
applyOplog();
- ASSERT_EQUALS(expected, static_cast<int>(client()->count(ns())));
+ ASSERT_EQUALS(expected, static_cast<int>(_client.count(ns())));
drop();
addUpdates();
diff --git a/src/mongo/dbtests/repltests.cpp b/src/mongo/dbtests/repltests.cpp
index eb1b45065ad..11338a61225 100644
--- a/src/mongo/dbtests/repltests.cpp
+++ b/src/mongo/dbtests/repltests.cpp
@@ -65,7 +65,7 @@ namespace ReplTests {
public:
Base() : _lk(_txn.lockState()),
_client(&_txn),
- _context(ns()) {
+ _context(&_txn, ns()) {
oldRepl();
replSettings.replSet = "";
@@ -121,7 +121,7 @@ namespace ReplTests {
}
int count() const {
Lock::GlobalWrite lk(_txn.lockState());
- Client::Context ctx( ns() );
+ Client::Context ctx(&_txn, ns() );
Database* db = ctx.db();
Collection* coll = db->getCollection( &_txn, ns() );
if ( !coll ) {
@@ -140,7 +140,7 @@ namespace ReplTests {
static int opCount() {
OperationContextImpl txn;
Lock::GlobalWrite lk(txn.lockState());
- Client::Context ctx( cllNS() );
+ Client::Context ctx(&txn, cllNS() );
Database* db = ctx.db();
Collection* coll = db->getCollection( &txn, cllNS() );
@@ -163,7 +163,7 @@ namespace ReplTests {
vector< BSONObj > ops;
{
- Client::Context ctx( cllNS() );
+ Client::Context ctx(&txn, cllNS() );
Database* db = ctx.db();
Collection* coll = db->getCollection( &txn, cllNS() );
@@ -176,7 +176,7 @@ namespace ReplTests {
delete it;
}
{
- Client::Context ctx( ns() );
+ Client::Context ctx(&txn, ns() );
BSONObjBuilder b;
b.append("host", "localhost");
b.appendTimestamp("syncedTo", 0);
@@ -192,7 +192,7 @@ namespace ReplTests {
static void printAll( const char *ns ) {
OperationContextImpl txn;
Lock::GlobalWrite lk(txn.lockState());
- Client::Context ctx( ns );
+ Client::Context ctx(&txn, ns );
Database* db = ctx.db();
Collection* coll = db->getCollection( &txn, ns );
@@ -213,7 +213,7 @@ namespace ReplTests {
static void deleteAll( const char *ns ) {
OperationContextImpl txn;
Lock::GlobalWrite lk(txn.lockState());
- Client::Context ctx( ns );
+ Client::Context ctx(&txn, ns );
Database* db = ctx.db();
Collection* coll = db->getCollection( &txn, ns );
@@ -235,7 +235,7 @@ namespace ReplTests {
static void insert( const BSONObj &o ) {
OperationContextImpl txn;
Lock::GlobalWrite lk(txn.lockState());
- Client::Context ctx( ns() );
+ Client::Context ctx(&txn, ns() );
Database* db = ctx.db();
Collection* coll = db->getCollection( &txn, ns() );
diff --git a/src/mongo/dbtests/sharding.cpp b/src/mongo/dbtests/sharding.cpp
index d376a8fbaa0..797fb53cbbc 100644
--- a/src/mongo/dbtests/sharding.cpp
+++ b/src/mongo/dbtests/sharding.cpp
@@ -28,10 +28,11 @@
* then also delete it in the license file.
*/
-#include "mongo/pch.h"
+#include "mongo/platform/basic.h"
#include "mongo/client/dbclientmockcursor.h"
#include "mongo/client/parallel.h"
+#include "mongo/db/operation_context_impl.h"
#include "mongo/dbtests/config_server_fixture.h"
#include "mongo/dbtests/dbtests.h"
#include "mongo/s/chunk_diff.h"
@@ -81,10 +82,11 @@ namespace ShardingTests {
class ChunkManagerTest : public ConnectionString::ConnectionHook {
public:
+ OperationContextImpl _txn;
CustomDirectClient _client;
Shard _shard;
- ChunkManagerTest() {
+ ChunkManagerTest() : _client(&_txn) {
DBException::traceExceptions = true;
@@ -131,7 +133,7 @@ namespace ShardingTests {
double socketTimeout )
{
// Note - must be new, since it gets owned elsewhere
- return new CustomDirectClient();
+ return new CustomDirectClient(&_txn);
}
};
diff --git a/src/mongo/dbtests/threadedtests.cpp b/src/mongo/dbtests/threadedtests.cpp
index 998ba2c2bed..0e36df8f43f 100644
--- a/src/mongo/dbtests/threadedtests.cpp
+++ b/src/mongo/dbtests/threadedtests.cpp
@@ -35,6 +35,7 @@
#include "mongo/bson/util/atomic_int.h"
#include "mongo/db/d_concurrency.h"
+#include "mongo/db/operation_context_impl.h"
#include "mongo/dbtests/dbtests.h"
#include "mongo/platform/atomic_word.h"
#include "mongo/platform/bits.h"
@@ -109,7 +110,9 @@ namespace ThreadedTests {
// in _DEBUG builds on linux we mprotect each time a writelock
// is taken. That can greatly slow down this test if there are
// many open files
- DBDirectClient db;
+ OperationContextImpl txn;
+ DBDirectClient db(&txn);
+
db.simpleCommand("admin", NULL, "closeAllDatabases");
}
diff --git a/src/mongo/dbtests/updatetests.cpp b/src/mongo/dbtests/updatetests.cpp
index e048ebc2d9f..cbdcc346dc8 100644
--- a/src/mongo/dbtests/updatetests.cpp
+++ b/src/mongo/dbtests/updatetests.cpp
@@ -38,6 +38,7 @@
#include "mongo/db/json.h"
#include "mongo/db/lasterror.h"
#include "mongo/db/ops/update.h"
+#include "mongo/db/operation_context_impl.h"
#include "mongo/dbtests/dbtests.h"
namespace UpdateTests {
@@ -45,27 +46,26 @@ namespace UpdateTests {
class ClientBase {
public:
// NOTE: Not bothering to backup the old error record.
- ClientBase() {
+ ClientBase() : _client(&_txn) {
mongo::lastError.reset( new LastError() );
}
~ClientBase() {
mongo::lastError.release();
}
+
protected:
void insert( const char *ns, BSONObj o ) {
- client_.insert( ns, o );
+ _client.insert( ns, o );
}
void update( const char *ns, BSONObj q, BSONObj o, bool upsert = 0 ) {
- client_.update( ns, Query( q ), o, upsert );
+ _client.update( ns, Query( q ), o, upsert );
}
bool error() {
- return !client_.getPrevError().getField( "err" ).isNull();
+ return !_client.getPrevError().getField( "err" ).isNull();
}
- DBDirectClient& client() { return client_; }
-
- private:
- DBDirectClient client_;
+ OperationContextImpl _txn;
+ DBDirectClient _client;
};
class Fail : public ClientBase {
@@ -145,7 +145,7 @@ namespace UpdateTests {
class SetBase : public ClientBase {
public:
~SetBase() {
- client().dropCollection( ns() );
+ _client.dropCollection( ns() );
}
protected:
const char *ns() { return "unittests.updatetests.SetBase"; }
@@ -154,45 +154,45 @@ namespace UpdateTests {
class SetNum : public SetBase {
public:
void run() {
- client().insert( ns(), BSON( "a" << 1 ) );
- client().update( ns(), BSON( "a" << 1 ), BSON( "$set" << BSON( "a" << 4 ) ) );
- ASSERT( !client().findOne( ns(), BSON( "a" << 4 ) ).isEmpty() );
+ _client.insert( ns(), BSON( "a" << 1 ) );
+ _client.update( ns(), BSON( "a" << 1 ), BSON( "$set" << BSON( "a" << 4 ) ) );
+ ASSERT( !_client.findOne( ns(), BSON( "a" << 4 ) ).isEmpty() );
}
};
class SetString : public SetBase {
public:
void run() {
- client().insert( ns(), BSON( "a" << "b" ) );
- client().update( ns(), BSON( "a" << "b" ), BSON( "$set" << BSON( "a" << "c" ) ) );
- ASSERT( !client().findOne( ns(), BSON( "a" << "c" ) ).isEmpty() );
+ _client.insert( ns(), BSON( "a" << "b" ) );
+ _client.update( ns(), BSON( "a" << "b" ), BSON( "$set" << BSON( "a" << "c" ) ) );
+ ASSERT( !_client.findOne( ns(), BSON( "a" << "c" ) ).isEmpty() );
}
};
class SetStringDifferentLength : public SetBase {
public:
void run() {
- client().insert( ns(), BSON( "a" << "b" ) );
- client().update( ns(), BSON( "a" << "b" ), BSON( "$set" << BSON( "a" << "cd" ) ) );
- ASSERT( !client().findOne( ns(), BSON( "a" << "cd" ) ).isEmpty() );
+ _client.insert( ns(), BSON( "a" << "b" ) );
+ _client.update( ns(), BSON( "a" << "b" ), BSON( "$set" << BSON( "a" << "cd" ) ) );
+ ASSERT( !_client.findOne( ns(), BSON( "a" << "cd" ) ).isEmpty() );
}
};
class SetStringToNum : public SetBase {
public:
void run() {
- client().insert( ns(), BSON( "a" << "b" ) );
- client().update( ns(), Query(), BSON( "$set" << BSON( "a" << 5 ) ) );
- ASSERT( !client().findOne( ns(), BSON( "a" << 5 ) ).isEmpty() );
+ _client.insert( ns(), BSON( "a" << "b" ) );
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "a" << 5 ) ) );
+ ASSERT( !_client.findOne( ns(), BSON( "a" << 5 ) ).isEmpty() );
}
};
class SetStringToNumInPlace : public SetBase {
public:
void run() {
- client().insert( ns(), BSON( "a" << "bcd" ) );
- client().update( ns(), Query(), BSON( "$set" << BSON( "a" << 5.0 ) ) );
- ASSERT( !client().findOne( ns(), BSON( "a" << 5.0 ) ).isEmpty() );
+ _client.insert( ns(), BSON( "a" << "bcd" ) );
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "a" << 5.0 ) ) );
+ ASSERT( !_client.findOne( ns(), BSON( "a" << 5.0 ) ).isEmpty() );
}
};
@@ -200,13 +200,13 @@ namespace UpdateTests {
public:
void run() {
// Try with upsert false first.
- client().insert( ns(), BSONObj() /* empty document */);
- client().update( ns(), Query(), BSON( "$setOnInsert" << BSON( "a" << 1 ) ), false );
- ASSERT( client().findOne( ns(), BSON( "a" << 1 ) ).isEmpty() );
+ _client.insert( ns(), BSONObj() /* empty document */);
+ _client.update( ns(), Query(), BSON( "$setOnInsert" << BSON( "a" << 1 ) ), false );
+ ASSERT( _client.findOne( ns(), BSON( "a" << 1 ) ).isEmpty() );
// Then with upsert true.
- client().update( ns(), Query(), BSON( "$setOnInsert" << BSON( "a" << 1 ) ), true );
- ASSERT( client().findOne( ns(), BSON( "a" << 1 ) ).isEmpty() );
+ _client.update( ns(), Query(), BSON( "$setOnInsert" << BSON( "a" << 1 ) ), true );
+ ASSERT( _client.findOne( ns(), BSON( "a" << 1 ) ).isEmpty() );
}
};
@@ -215,12 +215,12 @@ namespace UpdateTests {
public:
void run() {
// Try with upsert false first.
- client().update( ns(), Query(), BSON( "$setOnInsert" << BSON( "a" << 1 ) ), false );
- ASSERT( client().findOne( ns(), BSON( "a" << 1 ) ).isEmpty() );
+ _client.update( ns(), Query(), BSON( "$setOnInsert" << BSON( "a" << 1 ) ), false );
+ ASSERT( _client.findOne( ns(), BSON( "a" << 1 ) ).isEmpty() );
// Then with upsert true.
- client().update( ns(), Query(), BSON( "$setOnInsert" << BSON( "a" << 1 ) ), true );
- ASSERT( !client().findOne( ns(), BSON( "a" << 1 ) ).isEmpty() );
+ _client.update( ns(), Query(), BSON( "$setOnInsert" << BSON( "a" << 1 ) ), true );
+ ASSERT( !_client.findOne( ns(), BSON( "a" << 1 ) ).isEmpty() );
}
};
@@ -231,12 +231,12 @@ namespace UpdateTests {
Query q("{a:1}");
// Try with upsert false first.
- client().update( ns(), q, BSON( "$setOnInsert" << BSON( "b" << 1 ) ), false );
- ASSERT( client().findOne( ns(), BSON( "a" << 1 ) ).isEmpty() );
+ _client.update( ns(), q, BSON( "$setOnInsert" << BSON( "b" << 1 ) ), false );
+ ASSERT( _client.findOne( ns(), BSON( "a" << 1 ) ).isEmpty() );
// Then with upsert true.
- client().update( ns(), q, BSON( "$setOnInsert" << BSON( "b" << 1 ) ), true );
- ASSERT( !client().findOne( ns(), BSON( "a" << 1 << "b" << 1) ).isEmpty() );
+ _client.update( ns(), q, BSON( "$setOnInsert" << BSON( "b" << 1 ) ), true );
+ ASSERT( !_client.findOne( ns(), BSON( "a" << 1 << "b" << 1) ).isEmpty() );
}
};
@@ -247,12 +247,12 @@ namespace UpdateTests {
Query q("{a:1}"); // same field that we'll setOnInsert on
// Try with upsert false first.
- client().update( ns(), q, BSON( "$setOnInsert" << BSON( "a" << 2 ) ), false );
- ASSERT( client().findOne( ns(), BSON( "a" << 1 ) ).isEmpty() );
+ _client.update( ns(), q, BSON( "$setOnInsert" << BSON( "a" << 2 ) ), false );
+ ASSERT( _client.findOne( ns(), BSON( "a" << 1 ) ).isEmpty() );
// Then with upsert true.
- client().update( ns(), q, BSON( "$setOnInsert" << BSON( "a" << 2 ) ), true );
- ASSERT( !client().findOne( ns(), BSON( "a" << 2 ) ).isEmpty() );
+ _client.update( ns(), q, BSON( "$setOnInsert" << BSON( "a" << 2 ) ), true );
+ ASSERT( !_client.findOne( ns(), BSON( "a" << 2 ) ).isEmpty() );
}
};
@@ -261,18 +261,18 @@ namespace UpdateTests {
public:
void run() {
BSONObj res = fromjson("{'_id':0, a:1}");
- client().insert( ns(), res );
- client().update( ns(), Query(), BSON( "$setOnInsert" << BSON( "b" << 1 ) ) );
- ASSERT( client().findOne( ns(), BSON( "a" << 1 ) ).woCompare( res ) == 0 );
+ _client.insert( ns(), res );
+ _client.update( ns(), Query(), BSON( "$setOnInsert" << BSON( "b" << 1 ) ) );
+ ASSERT( _client.findOne( ns(), BSON( "a" << 1 ) ).woCompare( res ) == 0 );
}
};
class SetOnInsertExisting : public SetBase {
public:
void run() {
- client().insert( ns(), BSON( "a" << 1 ) );
- client().update( ns(), Query(), BSON( "$setOnInsert" << BSON( "a" << 2 ) ) );
- ASSERT( !client().findOne( ns(), BSON( "a" << 1 ) ).isEmpty() );
+ _client.insert( ns(), BSON( "a" << 1 ) );
+ _client.update( ns(), Query(), BSON( "$setOnInsert" << BSON( "a" << 2 ) ) );
+ ASSERT( !_client.findOne( ns(), BSON( "a" << 1 ) ).isEmpty() );
}
};
@@ -280,14 +280,14 @@ namespace UpdateTests {
public:
void run() {
// Try with upsert false first.
- client().update( ns(), Query(), BSON( "$set" << BSON( "a" << 1 ) <<
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "a" << 1 ) <<
"$setOnInsert" << BSON( "b" << 2 ) ), false );
- ASSERT( client().findOne( ns(), BSON( "a" << 1 << "b" << 2 ) ).isEmpty() );
+ ASSERT( _client.findOne( ns(), BSON( "a" << 1 << "b" << 2 ) ).isEmpty() );
// Then with upsert true.
- client().update( ns(), Query(), BSON( "$set" << BSON( "a" << 1 ) <<
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "a" << 1 ) <<
"$setOnInsert" << BSON( "b" << 2 ) ), true );
- ASSERT( !client().findOne( ns(), BSON( "a" << 1 << "b" << 2 ) ).isEmpty() );
+ ASSERT( !_client.findOne( ns(), BSON( "a" << 1 << "b" << 2 ) ).isEmpty() );
}
};
@@ -298,58 +298,58 @@ namespace UpdateTests {
// parent unneccesarily.
BSONObj initial = fromjson( "{'_id':0}" );
BSONObj final = fromjson( "{'_id':0, d:1}" );
- client().insert( ns(), initial );
- client().update( ns(), initial, BSON( "$setOnInsert" << BSON( "a.b" << 1 ) <<
+ _client.insert( ns(), initial );
+ _client.update( ns(), initial, BSON( "$setOnInsert" << BSON( "a.b" << 1 ) <<
"$set" << BSON( "d" << 1 ) ) );
- ASSERT_EQUALS( client().findOne( ns(), initial ), final );
+ ASSERT_EQUALS( _client.findOne( ns(), initial ), final );
}
};
class ModDotted : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{a:{b:4}}" ) );
- client().update( ns(), Query(), BSON( "$inc" << BSON( "a.b" << 10 ) ) );
- ASSERT( !client().findOne( ns(), BSON( "a.b" << 14 ) ).isEmpty() );
- client().update( ns(), Query(), BSON( "$set" << BSON( "a.b" << 55 ) ) );
- ASSERT( !client().findOne( ns(), BSON( "a.b" << 55 ) ).isEmpty() );
+ _client.insert( ns(), fromjson( "{a:{b:4}}" ) );
+ _client.update( ns(), Query(), BSON( "$inc" << BSON( "a.b" << 10 ) ) );
+ ASSERT( !_client.findOne( ns(), BSON( "a.b" << 14 ) ).isEmpty() );
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "a.b" << 55 ) ) );
+ ASSERT( !_client.findOne( ns(), BSON( "a.b" << 55 ) ).isEmpty() );
}
};
class SetInPlaceDotted : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{a:{b:'cdef'}}" ) );
- client().update( ns(), Query(), BSON( "$set" << BSON( "a.b" << "llll" ) ) );
- ASSERT( !client().findOne( ns(), BSON( "a.b" << "llll" ) ).isEmpty() );
+ _client.insert( ns(), fromjson( "{a:{b:'cdef'}}" ) );
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "a.b" << "llll" ) ) );
+ ASSERT( !_client.findOne( ns(), BSON( "a.b" << "llll" ) ).isEmpty() );
}
};
class SetRecreateDotted : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:{b:'cdef'}}" ) );
- client().update( ns(), Query(), BSON( "$set" << BSON( "a.b" << "lllll" ) ) );
- ASSERT( client().findOne( ns(), BSON( "a.b" << "lllll" ) ).woCompare( fromjson( "{'_id':0,a:{b:'lllll'}}" ) ) == 0 );
+ _client.insert( ns(), fromjson( "{'_id':0,a:{b:'cdef'}}" ) );
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "a.b" << "lllll" ) ) );
+ ASSERT( _client.findOne( ns(), BSON( "a.b" << "lllll" ) ).woCompare( fromjson( "{'_id':0,a:{b:'lllll'}}" ) ) == 0 );
}
};
class SetMissingDotted : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0}" ) );
- client().update( ns(), BSONObj(), BSON( "$set" << BSON( "a.b" << "lllll" ) ) );
- ASSERT( client().findOne( ns(), BSON( "a.b" << "lllll" ) ).woCompare( fromjson( "{'_id':0,a:{b:'lllll'}}" ) ) == 0 );
+ _client.insert( ns(), fromjson( "{'_id':0}" ) );
+ _client.update( ns(), BSONObj(), BSON( "$set" << BSON( "a.b" << "lllll" ) ) );
+ ASSERT( _client.findOne( ns(), BSON( "a.b" << "lllll" ) ).woCompare( fromjson( "{'_id':0,a:{b:'lllll'}}" ) ) == 0 );
}
};
class SetAdjacentDotted : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:{c:4}}" ) );
- client().update( ns(), Query(), BSON( "$set" << BSON( "a.b" << "lllll" ) ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:{c:4}}" ) );
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "a.b" << "lllll" ) ) );
ASSERT_EQUALS(
- mutablebson::unordered( client().findOne( ns(), BSON( "a.b" << "lllll" ) ) ),
+ mutablebson::unordered( _client.findOne( ns(), BSON( "a.b" << "lllll" ) ) ),
mutablebson::unordered( fromjson( "{'_id':0,a:{b:'lllll',c:4}}" ) ) );
}
};
@@ -357,9 +357,9 @@ namespace UpdateTests {
class IncMissing : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0}" ) );
- client().update( ns(), Query(), BSON( "$inc" << BSON( "f" << 3.0 ) ) );
- ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,f:3}" ) ) == 0 );
+ _client.insert( ns(), fromjson( "{'_id':0}" ) );
+ _client.update( ns(), Query(), BSON( "$inc" << BSON( "f" << 3.0 ) ) );
+ ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,f:3}" ) ) == 0 );
}
};
@@ -368,7 +368,7 @@ namespace UpdateTests {
string s() {
stringstream ss;
- auto_ptr<DBClientCursor> cc = client().query( ns() , Query().sort( BSON( "_id" << 1 ) ) );
+ auto_ptr<DBClientCursor> cc = _client.query( ns() , Query().sort( BSON( "_id" << 1 ) ) );
bool first = true;
while ( cc->more() ) {
if ( first ) first = false;
@@ -381,18 +381,18 @@ namespace UpdateTests {
}
void run() {
- client().insert( ns(), BSON( "_id" << 1 << "x" << 1 ) );
- client().insert( ns(), BSON( "_id" << 2 << "x" << 5 ) );
+ _client.insert( ns(), BSON( "_id" << 1 << "x" << 1 ) );
+ _client.insert( ns(), BSON( "_id" << 2 << "x" << 5 ) );
ASSERT_EQUALS( "1,5" , s() );
- client().update( ns() , BSON( "_id" << 1 ) , BSON( "$inc" << BSON( "x" << 1 ) ) );
+ _client.update( ns() , BSON( "_id" << 1 ) , BSON( "$inc" << BSON( "x" << 1 ) ) );
ASSERT_EQUALS( "2,5" , s() );
- client().update( ns() , BSONObj() , BSON( "$inc" << BSON( "x" << 1 ) ) );
+ _client.update( ns() , BSONObj() , BSON( "$inc" << BSON( "x" << 1 ) ) );
ASSERT_EQUALS( "3,5" , s() );
- client().update( ns() , BSONObj() , BSON( "$inc" << BSON( "x" << 1 ) ) , false , true );
+ _client.update( ns() , BSONObj() , BSON( "$inc" << BSON( "x" << 1 ) ) , false , true );
ASSERT_EQUALS( "4,6" , s() );
}
@@ -401,10 +401,10 @@ namespace UpdateTests {
class UnorderedNewSet : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0}" ) );
- client().update( ns(), Query(), BSON( "$set" << BSON( "f.g.h" << 3.0 << "f.g.a" << 2.0 ) ) );
+ _client.insert( ns(), fromjson( "{'_id':0}" ) );
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "f.g.h" << 3.0 << "f.g.a" << 2.0 ) ) );
ASSERT_EQUALS(
- mutablebson::unordered( client().findOne( ns(), Query() ) ),
+ mutablebson::unordered( _client.findOne( ns(), Query() ) ),
mutablebson::unordered( fromjson( "{'_id':0,f:{g:{a:2,h:3}}}" ) ) );
}
};
@@ -412,10 +412,10 @@ namespace UpdateTests {
class UnorderedNewSetAdjacent : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0}" ) );
- client().update( ns(), BSONObj(), BSON( "$set" << BSON( "f.g.h.b" << 3.0 << "f.g.a.b" << 2.0 ) ) );
+ _client.insert( ns(), fromjson( "{'_id':0}" ) );
+ _client.update( ns(), BSONObj(), BSON( "$set" << BSON( "f.g.h.b" << 3.0 << "f.g.a.b" << 2.0 ) ) );
ASSERT_EQUALS(
- mutablebson::unordered( client().findOne( ns(), Query() ) ),
+ mutablebson::unordered( _client.findOne( ns(), Query() ) ),
mutablebson::unordered( fromjson( "{'_id':0,f:{g:{a:{b:2},h:{b:3}}}}" ) ) );
}
};
@@ -423,161 +423,161 @@ namespace UpdateTests {
class ArrayEmbeddedSet : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,z:[4,'b']}" ) );
- client().update( ns(), Query(), BSON( "$set" << BSON( "z.0" << "a" ) ) );
- ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,z:['a','b']}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,z:[4,'b']}" ) );
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "z.0" << "a" ) ) );
+ ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,z:['a','b']}" ) );
}
};
class AttemptEmbedInExistingNum : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:1}" ) );
- client().update( ns(), Query(), BSON( "$set" << BSON( "a.b" << 1 ) ) );
- ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:1}" ) ) == 0 );
+ _client.insert( ns(), fromjson( "{'_id':0,a:1}" ) );
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "a.b" << 1 ) ) );
+ ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:1}" ) ) == 0 );
}
};
class AttemptEmbedConflictsWithOtherSet : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0}" ) );
- client().update( ns(), Query(), BSON( "$set" << BSON( "a" << 2 << "a.b" << 1 ) ) );
- ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0}" ) );
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "a" << 2 << "a.b" << 1 ) ) );
+ ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0}" ) );
}
};
class ModMasksEmbeddedConflict : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:{b:2}}" ) );
- client().update( ns(), Query(), BSON( "$set" << BSON( "a" << 2 << "a.b" << 1 ) ) );
- ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:2}}" ) ) == 0 );
+ _client.insert( ns(), fromjson( "{'_id':0,a:{b:2}}" ) );
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "a" << 2 << "a.b" << 1 ) ) );
+ ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:2}}" ) ) == 0 );
}
};
class ModOverwritesExistingObject : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:{b:2}}" ) );
- client().update( ns(), Query(), BSON( "$set" << BSON( "a" << BSON( "c" << 2 ) ) ) );
- ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{c:2}}" ) ) == 0 );
+ _client.insert( ns(), fromjson( "{'_id':0,a:{b:2}}" ) );
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "a" << BSON( "c" << 2 ) ) ) );
+ ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{c:2}}" ) ) == 0 );
}
};
class InvalidEmbeddedSet : public Fail {
public:
virtual void doIt() {
- client().update( ns(), Query(), BSON( "$set" << BSON( "a." << 1 ) ) );
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "a." << 1 ) ) );
}
};
class UpsertMissingEmbedded : public SetBase {
public:
void run() {
- client().update( ns(), Query(), BSON( "$set" << BSON( "a.b" << 1 ) ), true );
- ASSERT( !client().findOne( ns(), QUERY( "a.b" << 1 ) ).isEmpty() );
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "a.b" << 1 ) ), true );
+ ASSERT( !_client.findOne( ns(), QUERY( "a.b" << 1 ) ).isEmpty() );
}
};
class Push : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[1]}" ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << 5 ) ) );
- ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1,5]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[1]}" ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << 5 ) ) );
+ ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1,5]}" ) );
}
};
class PushInvalidEltType : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:1}" ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << 5 ) ) );
- ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:1}" ) ) == 0 );
+ _client.insert( ns(), fromjson( "{'_id':0,a:1}" ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << 5 ) ) );
+ ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:1}" ) ) == 0 );
}
};
class PushConflictsWithOtherMod : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[1]}" ) );
- client().update( ns(), Query(), BSON( "$set" << BSON( "a" << 1 ) <<"$push" << BSON( "a" << 5 ) ) );
- ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:[1]}" ) ) == 0 );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[1]}" ) );
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "a" << 1 ) <<"$push" << BSON( "a" << 5 ) ) );
+ ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:[1]}" ) ) == 0 );
}
};
class PushFromNothing : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0}" ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << 5 ) ) );
- ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[5]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0}" ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << 5 ) ) );
+ ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[5]}" ) );
}
};
class PushFromEmpty : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[]}" ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << 5 ) ) );
- ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:[5]}" ) ) == 0 );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[]}" ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << 5 ) ) );
+ ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:[5]}" ) ) == 0 );
}
};
class PushInsideNothing : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0}" ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a.b" << 5 ) ) );
- ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:[5]}}" ) ) == 0 );
+ _client.insert( ns(), fromjson( "{'_id':0}" ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a.b" << 5 ) ) );
+ ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:[5]}}" ) ) == 0 );
}
};
class CantPushInsideOtherMod : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0}" ) );
- client().update( ns(), Query(), BSON( "$set" << BSON( "a" << BSONObj() ) << "$push" << BSON( "a.b" << 5 ) ) );
- ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0}" ) ) == 0 );
+ _client.insert( ns(), fromjson( "{'_id':0}" ) );
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "a" << BSONObj() ) << "$push" << BSON( "a.b" << 5 ) ) );
+ ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0}" ) ) == 0 );
}
};
class CantPushTwice : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[]}" ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << 4 ) << "$push" << BSON( "a" << 5 ) ) );
- ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:[]}" ) ) == 0 );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[]}" ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << 4 ) << "$push" << BSON( "a" << 5 ) ) );
+ ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:[]}" ) ) == 0 );
}
};
class SetEncapsulationConflictsWithExistingType : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:{b:4}}" ) );
- client().update( ns(), Query(), BSON( "$set" << BSON( "a.b.c" << 4.0 ) ) );
- ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:4}}" ) ) == 0 );
+ _client.insert( ns(), fromjson( "{'_id':0,a:{b:4}}" ) );
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "a.b.c" << 4.0 ) ) );
+ ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:4}}" ) ) == 0 );
}
};
class CantPushToParent : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:{b:4}}" ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << 4.0 ) ) );
- ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:4}}" ) ) == 0 );
+ _client.insert( ns(), fromjson( "{'_id':0,a:{b:4}}" ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << 4.0 ) ) );
+ ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:4}}" ) ) == 0 );
}
};
class PushEachSimple : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[1]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[1]}" ) );
// { $push : { a : { $each : [ 2, 3 ] } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 2 << 3 ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
- ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1,2,3]}" ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
+ ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1,2,3]}" ) );
}
};
@@ -585,11 +585,11 @@ namespace UpdateTests {
class PushEachFromEmpty : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[]}" ) );
// { $push : { a : { $each : [ 1, 2, 3 ] } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 1 << 2 << 3 ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
- ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1,2,3]}" ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
+ ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1,2,3]}" ) );
}
};
@@ -597,189 +597,189 @@ namespace UpdateTests {
class PushSliceBelowFull : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[1]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[1]}" ) );
// { $push : { a : { $each : [ 2 ] , $slice : -3 } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 2 ) << "$slice" << -3 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
- ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1,2]}" ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
+ ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1,2]}" ) );
}
};
class PushSliceReachedFullExact : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[1]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[1]}" ) );
// { $push : { a : { $each : [ 2 ] , $slice : -2 } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 2 ) << "$slice" << -2 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
- ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1,2]}" ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
+ ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1,2]}" ) );
}
};
class PushSliceReachedFullWithEach : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[1]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[1]}" ) );
// { $push : { a : { $each : [ 2 , 3 ] , $slice : -2 } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 2 << 3 ) << "$slice" << -2 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
- ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[2,3]}" ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
+ ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[2,3]}" ) );
}
};
class PushSliceReachedFullWithBoth : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) );
// { $push : { a : { $each : [ 3 ] , $slice : -2 } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 3 ) << "$slice" << -2 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
- ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[2,3]}" ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
+ ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[2,3]}" ) );
}
};
class PushSliceToZero : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) );
// { $push : { a : { $each : [ 3 ] , $slice : 0 } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 3 ) << "$slice" << 0 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
- ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[]}" ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
+ ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[]}" ) );
}
};
class PushSliceToZeroFromNothing : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0}" ) );
// { $push : { a : { $each : [ 3 ] , $slice : 0 } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 3 ) << "$slice" << 0 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
- ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[]}" ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
+ ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[]}" ) );
}
};
class PushSliceFromNothing : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0}" ) );
// { $push : { a : { $each : [ 1 , 2 ] , $slice : -3 } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 1 << 2 ) << "$slice" << -3 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
- ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1,2]}" ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
+ ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1,2]}" ) );
}
};
class PushSliceLongerThanSliceFromNothing : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0}" ) );
// { $push : { a : { $each : [ 1 , 2 , 3 ] , $slice : -2 } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 1 << 2 << 3 ) << "$slice" << -2 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
- ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[2,3]}" ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
+ ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[2,3]}" ) );
}
};
class PushSliceFromEmpty : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[]}" ) );
// { $push : { a : { $each : [ 1 ] , $slice : -3 } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 1 ) << "$slice" << -3 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
- ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1]}" ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
+ ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1]}" ) );
}
};
class PushSliceLongerThanSliceFromEmpty : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[]}" ) );
// { $push : { a : { $each : [ 1 , 2 , 3 ] , $slice : -2 } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 1 << 2 << 3 ) << "$slice" << -2 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
- ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[2,3]}" ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
+ ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[2,3]}" ) );
}
};
class PushSliceTwoFields : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[1,2],b:[3,4]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[1,2],b:[3,4]}" ) );
// { $push: { a: { $each: [ 5 ] , $slice : -2 }, { b: $each: [ 6 ] , $slice: -1 } } }
BSONObj objA = BSON( "$each" << BSON_ARRAY( 5 ) << "$slice" << -2 );
BSONObj objB = BSON( "$each" << BSON_ARRAY( 6 ) << "$slice" << -1 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << objA << "b" << objB ) ) );
- ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson("{'_id':0,a:[2,5],b:[6]}"));
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << objA << "b" << objB ) ) );
+ ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson("{'_id':0,a:[2,5],b:[6]}"));
}
};
class PushSliceAndNormal : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[1,2],b:[3]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[1,2],b:[3]}" ) );
// { $push : { a : { $each : [ 5 ] , $slice : -2 } , { b : 4 } }
BSONObj objA = BSON( "$each" << BSON_ARRAY( 5 ) << "$slice" << -2 );
- client().update( ns(), Query(), BSON("$push" << BSON("a" << objA << "b" << 4)));
- ASSERT_EQUALS(client().findOne(ns(), Query()) , fromjson("{'_id':0,a:[2,5],b:[3,4]}"));
+ _client.update( ns(), Query(), BSON("$push" << BSON("a" << objA << "b" << 4)));
+ ASSERT_EQUALS(_client.findOne(ns(), Query()) , fromjson("{'_id':0,a:[2,5],b:[3,4]}"));
}
};
class PushSliceTwoFieldsConflict : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[1],b:[3]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[1],b:[3]}" ) );
// { $push: { a: { $each: [ 5 ] , $slice: -2 } , { a: $each: [ 6 ] , $slice: -1 } } }
BSONObj objA = BSON( "$each" << BSON_ARRAY( 5 ) << "$slice" << -2 );
BSONObj other = BSON( "$each" << BSON_ARRAY( 6 ) << "$slice" << -1 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << objA << "a" << other ) ) );
- ASSERT(client().findOne( ns(), Query()).woCompare(fromjson("{'_id':0,a:[1],b:[3]}"))==0);
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << objA << "a" << other ) ) );
+ ASSERT(_client.findOne( ns(), Query()).woCompare(fromjson("{'_id':0,a:[1],b:[3]}"))==0);
}
};
class PushSliceAndNormalConflict : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[1],b:[3]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[1],b:[3]}" ) );
// { $push : { a : { $each : [ 5 ] , $slice : -2 } , { a : 4 } } }
BSONObj objA = BSON( "$each" << BSON_ARRAY( 5 ) << "$slice" << -2 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << objA << "a" << 4 ) ) );
- ASSERT(client().findOne( ns(), Query()).woCompare(fromjson("{'_id':0,a:[1],b:[3]}"))==0);
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << objA << "a" << 4 ) ) );
+ ASSERT(_client.findOne( ns(), Query()).woCompare(fromjson("{'_id':0,a:[1],b:[3]}"))==0);
}
};
class PushSliceInvalidEachType : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) );
// { $push : { a : { $each : 3 , $slice : -2 } } }
BSONObj pushObj = BSON( "$each" << 3 << "$slice" << -2 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
- ASSERT( client().findOne(ns(), Query()).woCompare(fromjson("{'_id':0,a:[1,2]}")) == 0);
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
+ ASSERT( _client.findOne(ns(), Query()).woCompare(fromjson("{'_id':0,a:[1,2]}")) == 0);
}
};
class PushSliceInvalidSliceType : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) );
// { $push : { a : { $each : [ 3 ], $slice : [ -2 ] } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY(3) << "$slice" << BSON_ARRAY(-2) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
- ASSERT( client().findOne( ns(), Query() ).woCompare(fromjson("{'_id':0,a:[1,2]}")) == 0);
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
+ ASSERT( _client.findOne( ns(), Query() ).woCompare(fromjson("{'_id':0,a:[1,2]}")) == 0);
}
};
class PushSliceInvalidSliceValue : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) );
// { $push : { a : { $each : [ 3 ], $slice : 2 } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY(3) << "$slice" << 2 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
- ASSERT( client().findOne( ns(), Query() ).woCompare(fromjson("{'_id':0,a:[1,2]}")) == 0);
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
+ ASSERT( _client.findOne( ns(), Query() ).woCompare(fromjson("{'_id':0,a:[1,2]}")) == 0);
}
};
@@ -787,33 +787,33 @@ namespace UpdateTests {
class PushSliceInvalidSliceDouble : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) );
// { $push : { a : { $each : [ 3 ], $slice : -2.1 } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY(3) << "$slice" << -2.1 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
- ASSERT( client().findOne( ns(), Query() ).woCompare(fromjson("{'_id':0,a:[1,2]}")) == 0);
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
+ ASSERT( _client.findOne( ns(), Query() ).woCompare(fromjson("{'_id':0,a:[1,2]}")) == 0);
}
};
class PushSliceValidSliceDouble : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) );
// { $push : { a : { $each : [ 3 ], $slice : -2.0 } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY(3) << "$slice" << -2.0 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
- ASSERT_EQUALS(client().findOne(ns(), Query()) , fromjson("{'_id':0,a:[2,3]}"));
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
+ ASSERT_EQUALS(_client.findOne(ns(), Query()) , fromjson("{'_id':0,a:[2,3]}"));
}
};
class PushSliceInvalidSlice : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) );
// { $push : { a : { $each : [ 3 ], $xxxx : 2 } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY(3) << "$xxxx" << 2 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
- ASSERT( client().findOne( ns(), Query() ).woCompare(fromjson("{'_id':0,a:[1,2]}")) == 0);
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
+ ASSERT( _client.findOne( ns(), Query() ).woCompare(fromjson("{'_id':0,a:[1,2]}")) == 0);
}
};
@@ -826,7 +826,7 @@ namespace UpdateTests {
class PushSortBase : public ClientBase {
public:
~PushSortBase() {
- client().dropCollection( ns() );
+ _client.dropCollection( ns() );
}
protected:
@@ -904,8 +904,8 @@ namespace UpdateTests {
void check( BSONObj expected ) {
std::cout << expected.toString() << std::endl;
- std::cout << client().findOne( ns(), Query() ) << std::endl;
- ASSERT( client().findOne( ns(), Query() ).woCompare( expected ) == 0 );
+ std::cout << _client.findOne( ns(), Query() ) << std::endl;
+ ASSERT( _client.findOne( ns(), Query() ).woCompare( expected ) == 0 );
}
private:
@@ -930,24 +930,24 @@ namespace UpdateTests {
// BOTTOMK_DESC: $push: { x: { $each: [ {a:2,b:2} ], $slice:3, $sort: { b:-1 } } }
for ( int i = 0; i < 2; i++ ) { // i < 4 when we have positive $slice
- client().dropCollection( ns() );
- client().insert( ns(), fromjson( "{'_id':0,x:[{a:1,b:1}]}" ) );
+ _client.dropCollection( ns() );
+ _client.insert( ns(), fromjson( "{'_id':0,x:[{a:1,b:1}]}" ) );
BSONObj result;
BSONObj expected;
switch ( i ) {
case TOPK_ASC:
case BOTTOMK_ASC:
- client().update( ns(), Query(), getUpdate(i) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), getUpdate(i) );
+ result = _client.findOne( ns(), Query() );
expected = fromjson( "{'_id':0,x:[{a:1,b:1},{a:2,b:2}]}" );
ASSERT_EQUALS( result, expected );
break;
case TOPK_DESC:
case BOTTOMK_DESC:
- client().update( ns(), Query(), getUpdate(i) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), getUpdate(i) );
+ result = _client.findOne( ns(), Query() );
expected = fromjson( "{'_id':0,x:[{a:2,b:2},{a:1,b:1}]}" ) ;
ASSERT_EQUALS( result, expected );
break;
@@ -971,24 +971,24 @@ namespace UpdateTests {
// BOTTOMK_DESC: $push: { x: { $each: [ {a:2,b:2} ], $slice:2, $sort: { b:-1 } } }
for ( int i = 0; i < 2; i++ ) { // i < 4 when we have positive $slice
- client().dropCollection( ns() );
- client().insert( ns(), fromjson( "{'_id':0,x:[{a:1,b:1}]}" ) );
+ _client.dropCollection( ns() );
+ _client.insert( ns(), fromjson( "{'_id':0,x:[{a:1,b:1}]}" ) );
BSONObj result;
BSONObj expected;
switch (i) {
case TOPK_ASC:
case BOTTOMK_ASC:
- client().update( ns(), Query(), getUpdate(i) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), getUpdate(i) );
+ result = _client.findOne( ns(), Query() );
expected = fromjson( "{'_id':0,x:[{a:1,b:1},{a:2,b:2}]}" );
ASSERT_EQUALS( result, expected );
break;
case TOPK_DESC:
case BOTTOMK_DESC:
- client().update( ns(), Query(), getUpdate(i) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), getUpdate(i) );
+ result = _client.findOne( ns(), Query() );
expected = fromjson( "{'_id':0,x:[{a:2,b:2},{a:1,b:1}]}" );
ASSERT_EQUALS( result, expected );
break;
@@ -1012,22 +1012,22 @@ namespace UpdateTests {
// BOTTOMK_DESC: $push: { x: { $each: [ {a:2,b:2} ], $slice:2, $sort: { b:-1 } } }
for ( int i = 0; i < 2; i++ ) { // i < 4 when we have positive $slice
- client().dropCollection( ns() );
- client().insert( ns(), fromjson( "{'_id':0,x:[{a:1,b:1},{a:3,b:3}]}" ) );
+ _client.dropCollection( ns() );
+ _client.insert( ns(), fromjson( "{'_id':0,x:[{a:1,b:1},{a:3,b:3}]}" ) );
BSONObj result;
BSONObj expected;
switch ( i ) {
case TOPK_ASC:
- client().update( ns(), Query(), getUpdate(i) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), getUpdate(i) );
+ result = _client.findOne( ns(), Query() );
expected = fromjson( "{'_id':0,x:[{a:2,b:2},{a:3,b:3}]}" );
ASSERT_EQUALS( result, expected );
break;
case TOPK_DESC:
- client().update( ns(), Query(), getUpdate(i) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), getUpdate(i) );
+ result = _client.findOne( ns(), Query() );
expected = fromjson( "{'_id':0,x:[{a:2,b:2},{a:1,b:1}]}" );
ASSERT_EQUALS( result, expected );
break;
@@ -1056,14 +1056,14 @@ namespace UpdateTests {
// BOTTOMK_DESC: $push: { x: { $each: [ {a:2,b:2} ], $slice:0, $sort: { b:-1 } } }
for ( int i = 0; i < 2; i++ ) { // i < 4 when we have positive $slice
- client().dropCollection( ns() );
- client().insert( ns(), fromjson( "{'_id':0,x:[{a:1,b:1},{a:3,b:3}]}" ) );
+ _client.dropCollection( ns() );
+ _client.insert( ns(), fromjson( "{'_id':0,x:[{a:1,b:1},{a:3,b:3}]}" ) );
BSONObj result;
BSONObj expected;
- client().update( ns(), Query(), getUpdate(i) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), getUpdate(i) );
+ result = _client.findOne( ns(), Query() );
expected = fromjson( "{'_id':0,x:[]}" );
ASSERT_EQUALS( result, expected );
}
@@ -1085,14 +1085,14 @@ namespace UpdateTests {
// BOTTOMK_DESC: $push: { x: { $each: [ {a:2,b:2} ], $slice:0, $sort: { b:-1 } } }
for ( int i = 0; i < 2; i++ ) { // i < 4 when we have positive $slice
- client().dropCollection( ns() );
- client().insert( ns(), fromjson( "{'_id':0}" ) );
+ _client.dropCollection( ns() );
+ _client.insert( ns(), fromjson( "{'_id':0}" ) );
BSONObj result;
BSONObj expected;
- client().update( ns(), Query(), getUpdate(i) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), getUpdate(i) );
+ result = _client.findOne( ns(), Query() );
expected = fromjson( "{'_id':0,x:[]}" );
ASSERT_EQUALS( result, expected );
}
@@ -1116,24 +1116,24 @@ namespace UpdateTests {
// BOTTOMK_DESC: $push: { x: { $each: [ <genarray> ], $slice:2, $sort: { b:-1 } } }
for ( int i = 0; i < 2; i++ ) { // i < 4 when we have positive $slice
- client().dropCollection( ns() );
- client().insert( ns(), fromjson( "{'_id':0}" ) );
+ _client.dropCollection( ns() );
+ _client.insert( ns(), fromjson( "{'_id':0}" ) );
BSONObj result;
BSONObj expected;
switch (i) {
case TOPK_ASC:
case BOTTOMK_ASC:
- client().update( ns(), Query(), getUpdate(i) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), getUpdate(i) );
+ result = _client.findOne( ns(), Query() );
expected = fromjson( "{'_id':0,x:[{a:1,b:1},{a:2,b:2}]}" );
ASSERT_EQUALS( result, expected );
break;
case TOPK_DESC:
case BOTTOMK_DESC:
- client().update( ns(), Query(), getUpdate(i) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), getUpdate(i) );
+ result = _client.findOne( ns(), Query() );
expected = fromjson( "{'_id':0,x:[{a:2,b:2},{a:1,b:1}]}" );
ASSERT_EQUALS( result, expected );
break;
@@ -1158,22 +1158,22 @@ namespace UpdateTests {
// BOTTOMK_DESC: $push: { x: { $each: [ <genarray> ], $slice:2, $sort: { b:-1 } } }
for ( int i = 0; i < 2; i++ ) { // i < 4 when we have positive $slice
- client().dropCollection( ns() );
- client().insert( ns(), fromjson( "{'_id':0}" ) );
+ _client.dropCollection( ns() );
+ _client.insert( ns(), fromjson( "{'_id':0}" ) );
BSONObj result;
BSONObj expected;
switch (i) {
case TOPK_ASC:
- client().update( ns(), Query(), getUpdate(i) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), getUpdate(i) );
+ result = _client.findOne( ns(), Query() );
expected = fromjson( "{'_id':0,x:[{a:2,b:2},{a:3,b:3}]}" );
ASSERT_EQUALS( result, expected );
break;
case TOPK_DESC:
- client().update( ns(), Query(), getUpdate(i) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), getUpdate(i) );
+ result = _client.findOne( ns(), Query() );
expected = fromjson( "{'_id':0,x:[{a:2,b:2},{a:1,b:1}]}" );
ASSERT_EQUALS( result, expected );
break;
@@ -1203,24 +1203,24 @@ namespace UpdateTests {
// BOTTOMK_DESC: $push: { x: { $each: [ <genarray> ], $slice:2, $sort: { b:-1 } } }
for ( int i = 0; i < 2; i++ ) { // i < 4 when we have positive $slice
- client().dropCollection( ns() );
- client().insert( ns(), fromjson( "{'_id':0,x:[]}" ) );
+ _client.dropCollection( ns() );
+ _client.insert( ns(), fromjson( "{'_id':0,x:[]}" ) );
BSONObj result;
BSONObj expected;
switch (i) {
case TOPK_ASC:
case BOTTOMK_ASC:
- client().update( ns(), Query(), getUpdate(i) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), getUpdate(i) );
+ result = _client.findOne( ns(), Query() );
expected = fromjson( "{'_id':0,x:[{a:1,b:1},{a:2,b:2}]}" );
ASSERT_EQUALS( result, expected );
break;
case TOPK_DESC:
case BOTTOMK_DESC:
- client().update( ns(), Query(), getUpdate(i) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), getUpdate(i) );
+ result = _client.findOne( ns(), Query() );
expected = fromjson( "{'_id':0,x:[{a:2,b:2},{a:1,b:1}]}" );
ASSERT_EQUALS( result, expected );
break;
@@ -1245,22 +1245,22 @@ namespace UpdateTests {
// BOTTOMK_DESC: $push: { x: { $each: [ <genarray> ], $slice:2, $sort: { b:-1 } } }
for ( int i = 0; i < 2; i++ ) { // i < 4 when we have positive $slice
- client().dropCollection( ns() );
- client().insert( ns(), fromjson( "{'_id':0,x:[]}" ) );
+ _client.dropCollection( ns() );
+ _client.insert( ns(), fromjson( "{'_id':0,x:[]}" ) );
BSONObj result;
BSONObj expected;
switch (i) {
case TOPK_ASC:
- client().update( ns(), Query(), getUpdate(i) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), getUpdate(i) );
+ result = _client.findOne( ns(), Query() );
expected = fromjson( "{'_id':0,x:[{a:2,b:2},{a:3,b:3}]}" );
ASSERT_EQUALS( result, expected );
break;
case TOPK_DESC:
- client().update( ns(), Query(), getUpdate(i) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), getUpdate(i) );
+ result = _client.findOne( ns(), Query() );
expected = fromjson( "{'_id':0,x:[{a:2,b:2},{a:1,b:1}]}" );
ASSERT_EQUALS( result, expected );
break;
@@ -1416,14 +1416,14 @@ namespace UpdateTests {
// catch bad patterns, we have to write updated that use them.
BSONObj expected = fromjson( "{'_id':0,x:[{a:1}, {a:2}]}" );
- client().insert( ns(), expected );
+ _client.insert( ns(), expected );
// { $push : { x : { $each : [ {a:3} ], $slice:-2, $sort : {a..d:1} } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 3 ) ) <<
"$slice" << -2 <<
"$sort" << BSON( "a..d" << 1 ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
- BSONObj result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
+ BSONObj result = _client.findOne( ns(), Query() );
ASSERT_EQUALS( result, expected );
@@ -1431,32 +1431,32 @@ namespace UpdateTests {
pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 3 ) ) <<
"$slice" << -2 <<
"$sort" << BSON( "a." << 1 ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
+ result = _client.findOne( ns(), Query() );
ASSERT_EQUALS( result, expected );
// { $push : { x : { $each : [ {a:3} ], $slice:-2, $sort : {.b:1} } } }
pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 3 ) ) <<
"$slice" << -2 <<
"$sort" << BSON( ".b" << 1 ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
+ result = _client.findOne( ns(), Query() );
ASSERT_EQUALS( result, expected );
// { $push : { x : { $each : [ {a:3} ], $slice:-2, $sort : {.:1} } } }
pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 3 ) ) <<
"$slice" << -2 <<
"$sort" << BSON( "." << 1 ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
+ result = _client.findOne( ns(), Query() );
ASSERT_EQUALS( result, expected );
// { $push : { x : { $each : [ {a:3} ], $slice:-2, $sort : {'':1} } } }
pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 3 ) ) <<
"$slice" << -2 <<
"$sort" << BSON( "" << 1 ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
+ result = _client.findOne( ns(), Query() );
ASSERT_EQUALS( result, expected );
}
};
@@ -1465,13 +1465,13 @@ namespace UpdateTests {
public:
void run() {
BSONObj expected = fromjson( "{'_id':0,x:[{a:1},{a:2}]}" );
- client().insert( ns(), expected );
+ _client.insert( ns(), expected );
// { $push : { x : { $each : [ 3 ], $slice:-2, $sort : {a:1} } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 3 ) <<
"$slice" << -2 <<
"$sort" << BSON( "a" << 1 ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
- BSONObj result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
+ BSONObj result = _client.findOne( ns(), Query() );
ASSERT_EQUALS( result, expected );
}
};
@@ -1480,13 +1480,13 @@ namespace UpdateTests {
public:
void run() {
BSONObj expected = fromjson( "{'_id':0,x:[{a:1},{a:2}]}" );
- client().insert( ns(), expected );
+ _client.insert( ns(), expected );
// { $push : { x : { $each : [ {a:3} ], $slice:-2, $sort : 2} } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 3 ) ) <<
"$slice" << -2 <<
"$sort" << 2 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
- BSONObj result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
+ BSONObj result = _client.findOne( ns(), Query() );
ASSERT_EQUALS( result, expected );
}
};
@@ -1495,13 +1495,13 @@ namespace UpdateTests {
public:
void run() {
BSONObj expected = fromjson( "{'_id':0,x:[{a:1},{a:2}]}" );
- client().insert( ns(), expected );
+ _client.insert( ns(), expected );
// { $push : { x : { $each : [ {a:3} ], $slice:2, $sort : {a:1} } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 3 ) ) <<
"$slice" << 2 <<
"$sort" << BSON( "a" << 1 ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
- BSONObj result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
+ BSONObj result = _client.findOne( ns(), Query() );
ASSERT_EQUALS( result, expected );
}
};
@@ -1510,13 +1510,13 @@ namespace UpdateTests {
public:
void run() {
BSONObj expected = fromjson( "{'_id':0,x:[{a:1},{a:2}]}" );
- client().insert( ns(), expected );
+ _client.insert( ns(), expected );
// { $push : { x : { $each : [ {a:3} ], $slice:-2.1, $sort : {a:1} } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 3 ) ) <<
"$slice" << -2.1 <<
"$sort" << BSON( "a" << 1 ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
- BSONObj result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
+ BSONObj result = _client.findOne( ns(), Query() );
ASSERT_EQUALS( result, expected );
}
};
@@ -1524,14 +1524,14 @@ namespace UpdateTests {
class PushSortValidSortDouble : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,x:[{a:1},{a:2}]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,x:[{a:1},{a:2}]}" ) );
// { $push : { x : { $each : [ {a:3} ], $slice:-2.0, $sort : {a:1} } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 3 ) ) <<
"$slice" << -2.0 <<
"$sort" << BSON( "a" << 1 ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
BSONObj expected = fromjson( "{'_id':0,x:[{a:2},{a:3}]}" );
- BSONObj result = client().findOne( ns(), Query() );
+ BSONObj result = _client.findOne( ns(), Query() );
ASSERT_EQUALS( result, expected );
}
};
@@ -1540,13 +1540,13 @@ namespace UpdateTests {
public:
void run() {
BSONObj expected = fromjson( "{'_id':0,x:[{a:1},{a:2}]}" );
- client().insert( ns(), expected );
+ _client.insert( ns(), expected );
// { $push : { x : { $each : [ {a:3} ], $slice:-2.0, $sort : [2, 1] } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 3 ) ) <<
"$slice" << -2.0 <<
"$sort" << BSON_ARRAY( 2 << 1 ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
- BSONObj result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
+ BSONObj result = _client.findOne( ns(), Query() );
ASSERT_EQUALS( result, expected );
}
};
@@ -1555,13 +1555,13 @@ namespace UpdateTests {
public:
void run() {
BSONObj expected = fromjson( "{'_id':0,x:[{a:1},{a:2}]}" );
- client().insert( ns(), expected );
+ _client.insert( ns(), expected );
// { $push : { x : { $each : [ {a:3} ], $slice:-2, $sort : {a:10} } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 3 ) ) <<
"$slice" << -2 <<
"$sort" << BSON( "a" << 10 ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
- BSONObj result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
+ BSONObj result = _client.findOne( ns(), Query() );
ASSERT_EQUALS( result, expected );
}
};
@@ -1569,14 +1569,14 @@ namespace UpdateTests {
class PushSortInvertedSortAndSlice : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,x:[{a:1},{a:3}]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,x:[{a:1},{a:3}]}" ) );
// { $push : { x : { $each : [ {a:2} ], $sort: {a:1}, $slice:-2 } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 2 ) ) <<
"$sort" << BSON( "a" << 1 ) <<
"$slice" << -2.0 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
BSONObj expected = fromjson( "{'_id':0,x:[{a:2},{a:3}]}" );
- BSONObj result = client().findOne( ns(), Query() );
+ BSONObj result = _client.findOne( ns(), Query() );
ASSERT_EQUALS( result, expected );
}
@@ -1586,13 +1586,13 @@ namespace UpdateTests {
public:
void run() {
BSONObj expected = fromjson( "{'_id':0,x:[{a:1},{a:3}]}" );
- client().insert( ns(), expected );
+ _client.insert( ns(), expected );
// { $push : { x : { $each : [ {a:2} ], $sort : {a:1}, $sort: {a:1} } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 2 ) ) <<
"$sort" << BSON( "a" << 1 ) <<
"$sort" << BSON( "a" << 1 ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
- BSONObj result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
+ BSONObj result = _client.findOne( ns(), Query() );
ASSERT_EQUALS( result, expected );
}
@@ -1601,54 +1601,54 @@ namespace UpdateTests {
class CantIncParent : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:{b:4}}" ) );
- client().update( ns(), Query(), BSON( "$inc" << BSON( "a" << 4.0 ) ) );
- ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:4}}" ) ) == 0 );
+ _client.insert( ns(), fromjson( "{'_id':0,a:{b:4}}" ) );
+ _client.update( ns(), Query(), BSON( "$inc" << BSON( "a" << 4.0 ) ) );
+ ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:4}}" ) ) == 0 );
}
};
class DontDropEmpty : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:{b:{}}}" ) );
- client().update( ns(), Query(), BSON( "$set" << BSON( "a.c" << 4.0 ) ) );
- ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:{},c:4}}" ) ) == 0 );
+ _client.insert( ns(), fromjson( "{'_id':0,a:{b:{}}}" ) );
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "a.c" << 4.0 ) ) );
+ ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:{},c:4}}" ) ) == 0 );
}
};
class InsertInEmpty : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:{b:{}}}" ) );
- client().update( ns(), Query(), BSON( "$set" << BSON( "a.b.f" << 4.0 ) ) );
- ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:{f:4}}}" ) ) == 0 );
+ _client.insert( ns(), fromjson( "{'_id':0,a:{b:{}}}" ) );
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "a.b.f" << 4.0 ) ) );
+ ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:{f:4}}}" ) ) == 0 );
}
};
class IndexParentOfMod : public SetBase {
public:
void run() {
- client().ensureIndex( ns(), BSON( "a" << 1 ) );
- client().insert( ns(), fromjson( "{'_id':0}" ) );
- client().update( ns(), Query(), fromjson( "{$set:{'a.b':4}}" ) );
- ASSERT_EQUALS( fromjson( "{'_id':0,a:{b:4}}" ) , client().findOne( ns(), Query() ) );
- ASSERT_EQUALS( fromjson( "{'_id':0,a:{b:4}}" ) , client().findOne( ns(), fromjson( "{'a.b':4}" ) ) ); // make sure the index works
+ _client.ensureIndex( ns(), BSON( "a" << 1 ) );
+ _client.insert( ns(), fromjson( "{'_id':0}" ) );
+ _client.update( ns(), Query(), fromjson( "{$set:{'a.b':4}}" ) );
+ ASSERT_EQUALS( fromjson( "{'_id':0,a:{b:4}}" ) , _client.findOne( ns(), Query() ) );
+ ASSERT_EQUALS( fromjson( "{'_id':0,a:{b:4}}" ) , _client.findOne( ns(), fromjson( "{'a.b':4}" ) ) ); // make sure the index works
}
};
class PreserveIdWithIndex : public SetBase { // Not using $set, but base class is still useful
public:
void run() {
- client().insert( ns(), BSON( "_id" << 55 << "i" << 5 ) );
- client().update( ns(), BSON( "i" << 5 ), BSON( "i" << 6 ) );
- ASSERT( !client().findOne( ns(), Query( BSON( "_id" << 55 ) ).hint ( "{\"_id\":1}" ) ).isEmpty() );
+ _client.insert( ns(), BSON( "_id" << 55 << "i" << 5 ) );
+ _client.update( ns(), BSON( "i" << 5 ), BSON( "i" << 6 ) );
+ ASSERT( !_client.findOne( ns(), Query( BSON( "_id" << 55 ) ).hint ( "{\"_id\":1}" ) ).isEmpty() );
}
};
class CheckNoMods : public SetBase {
public:
void run() {
- client().update( ns(), BSONObj(), BSON( "i" << 5 << "$set" << BSON( "q" << 3 ) ), true );
+ _client.update( ns(), BSONObj(), BSON( "i" << 5 << "$set" << BSON( "q" << 3 ) ), true );
ASSERT( error() );
}
};
@@ -1656,9 +1656,9 @@ namespace UpdateTests {
class UpdateMissingToNull : public SetBase {
public:
void run() {
- client().insert( ns(), BSON( "a" << 5 ) );
- client().update( ns(), BSON( "a" << 5 ), fromjson( "{$set:{b:null}}" ) );
- ASSERT_EQUALS( jstNULL, client().findOne( ns(), QUERY( "a" << 5 ) ).getField( "b" ).type() );
+ _client.insert( ns(), BSON( "a" << 5 ) );
+ _client.update( ns(), BSON( "a" << 5 ), fromjson( "{$set:{b:null}}" ) );
+ ASSERT_EQUALS( jstNULL, _client.findOne( ns(), QUERY( "a" << 5 ) ).getField( "b" ).type() );
}
};
@@ -1666,14 +1666,14 @@ namespace UpdateTests {
class TwoModsWithinDuplicatedField : public SetBase {
public:
void run() {
- client().insert( ns(), BSON( "_id" << 0 << "a" << 1
+ _client.insert( ns(), BSON( "_id" << 0 << "a" << 1
<< "x" << BSONObj() << "x" << BSONObj()
<< "z" << 5 ) );
- client().update( ns(), BSONObj(), BSON( "$set" << BSON( "x.b" << 1 << "x.c" << 1 ) ) );
+ _client.update( ns(), BSONObj(), BSON( "$set" << BSON( "x.b" << 1 << "x.c" << 1 ) ) );
ASSERT_EQUALS( BSON( "_id" << 0 << "a" << 1
<< "x" << BSON( "b" << 1 << "c" << 1 ) << "x" << BSONObj()
<< "z" << 5 ),
- client().findOne( ns(), BSONObj() ) );
+ _client.findOne( ns(), BSONObj() ) );
}
};
@@ -1681,27 +1681,27 @@ namespace UpdateTests {
class ThreeModsWithinDuplicatedField : public SetBase {
public:
void run() {
- client().insert( ns(),
+ _client.insert( ns(),
BSON( "_id" << 0
<< "x" << BSONObj() << "x" << BSONObj() << "x" << BSONObj() ) );
- client().update( ns(), BSONObj(),
+ _client.update( ns(), BSONObj(),
BSON( "$set" << BSON( "x.b" << 1 << "x.c" << 1 << "x.d" << 1 ) ) );
ASSERT_EQUALS( BSON( "_id" << 0
<< "x" << BSON( "b" << 1 << "c" << 1 << "d" << 1 )
<< "x" << BSONObj() << "x" << BSONObj() ),
- client().findOne( ns(), BSONObj() ) );
+ _client.findOne( ns(), BSONObj() ) );
}
};
class TwoModsBeforeExistingField : public SetBase {
public:
void run() {
- client().insert( ns(), BSON( "_id" << 0 << "x" << 5 ) );
- client().update( ns(), BSONObj(),
+ _client.insert( ns(), BSON( "_id" << 0 << "x" << 5 ) );
+ _client.update( ns(), BSONObj(),
BSON( "$set" << BSON( "a" << 1 << "b" << 1 << "x" << 10 ) ) );
ASSERT_EQUALS(
mutablebson::unordered( BSON( "_id" << 0 << "a" << 1 << "b" << 1 << "x" << 10 ) ),
- mutablebson::unordered( client().findOne( ns(), BSONObj() ) ) );
+ mutablebson::unordered( _client.findOne( ns(), BSONObj() ) ) );
}
};
@@ -1713,15 +1713,15 @@ namespace UpdateTests {
virtual void dotest() = 0;
void insert( const BSONObj& o ) {
- client().insert( ns() , o );
+ _client.insert( ns() , o );
}
void update( const BSONObj& m ) {
- client().update( ns() , BSONObj() , m );
+ _client.update( ns() , BSONObj() , m );
}
BSONObj findOne() {
- return client().findOne( ns() , BSONObj() );
+ return _client.findOne( ns() , BSONObj() );
}
void test( const char* initial , const char* mod , const char* after ) {
@@ -1730,11 +1730,11 @@ namespace UpdateTests {
void test( const BSONObj& initial , const BSONObj& mod , const BSONObj& after ) {
- client().dropCollection( ns() );
+ _client.dropCollection( ns() );
insert( initial );
update( mod );
ASSERT_EQUALS( after , findOne() );
- client().dropCollection( ns() );
+ _client.dropCollection( ns() );
}
public:
@@ -1744,11 +1744,11 @@ namespace UpdateTests {
}
void run() {
- client().dropCollection( ns() );
+ _client.dropCollection( ns() );
dotest();
- client().dropCollection( ns() );
+ _client.dropCollection( ns() );
}
};
@@ -1858,7 +1858,7 @@ namespace UpdateTests {
long long start = numeric_limits<int>::max() - 5;
long long max = numeric_limits<int>::max() + 5ll;
- client().insert( ns() , BSON( "x" << (int)start ) );
+ _client.insert( ns() , BSON( "x" << (int)start ) );
ASSERT( findOne()["x"].type() == NumberInt );
while ( start < max ) {
diff --git a/src/mongo/s/d_migrate.cpp b/src/mongo/s/d_migrate.cpp
index 6ca6b19ca57..47facbfc02a 100644
--- a/src/mongo/s/d_migrate.cpp
+++ b/src/mongo/s/d_migrate.cpp
@@ -308,7 +308,7 @@ namespace mongo {
break;
case 'u':
- Client::Context ctx( _ns );
+ Client::Context ctx(txn, _ns );
if ( ! Helpers::findById( txn, ctx.db(), _ns.c_str(), ide.wrap(), it ) ) {
warning() << "logOpForSharding couldn't find: " << ide << " even though should have" << migrateLog;
return;
diff --git a/src/mongo/s/d_state.cpp b/src/mongo/s/d_state.cpp
index 80d0a9eda96..767e894ab58 100644
--- a/src/mongo/s/d_state.cpp
+++ b/src/mongo/s/d_state.cpp
@@ -1247,7 +1247,7 @@ namespace mongo {
bool run(OperationContext* txn, const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) {
Lock::DBWrite dbXLock(txn->lockState(), dbname);
- Client::Context ctx(dbname);
+ Client::Context ctx(txn, dbname);
shardingState.appendInfo( result );
return true;