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