summaryrefslogtreecommitdiff
path: root/src/mongo/dbtests/repltests.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/dbtests/repltests.cpp')
-rw-r--r--src/mongo/dbtests/repltests.cpp112
1 files changed, 56 insertions, 56 deletions
diff --git a/src/mongo/dbtests/repltests.cpp b/src/mongo/dbtests/repltests.cpp
index 8a2a597645f..59eedcd86b7 100644
--- a/src/mongo/dbtests/repltests.cpp
+++ b/src/mongo/dbtests/repltests.cpp
@@ -69,36 +69,36 @@ BSONObj f(const char* s) {
class Base {
protected:
const ServiceContext::UniqueOperationContext _txnPtr = cc().makeOperationContext();
- OperationContext& _txn = *_txnPtr;
+ OperationContext& _opCtx = *_txnPtr;
mutable DBDirectClient _client;
public:
- Base() : _client(&_txn) {
+ Base() : _client(&_opCtx) {
ReplSettings replSettings;
replSettings.setOplogSizeBytes(10 * 1024 * 1024);
replSettings.setMaster(true);
setGlobalReplicationCoordinator(
- new repl::ReplicationCoordinatorMock(_txn.getServiceContext(), replSettings));
+ new repl::ReplicationCoordinatorMock(_opCtx.getServiceContext(), replSettings));
// Since the Client object persists across tests, even though the global
// ReplicationCoordinator does not, we need to clear the last op associated with the client
// to avoid the invariant in ReplClientInfo::setLastOp that the optime only goes forward.
- repl::ReplClientInfo::forClient(_txn.getClient()).clearLastOp_forTest();
+ repl::ReplClientInfo::forClient(_opCtx.getClient()).clearLastOp_forTest();
getGlobalServiceContext()->setOpObserver(stdx::make_unique<OpObserverImpl>());
setOplogCollectionName();
- createOplog(&_txn);
+ createOplog(&_opCtx);
- OldClientWriteContext ctx(&_txn, ns());
- WriteUnitOfWork wuow(&_txn);
+ OldClientWriteContext ctx(&_opCtx, ns());
+ WriteUnitOfWork wuow(&_opCtx);
Collection* c = ctx.db()->getCollection(ns());
if (!c) {
- c = ctx.db()->createCollection(&_txn, ns());
+ c = ctx.db()->createCollection(&_opCtx, ns());
}
- ASSERT(c->getIndexCatalog()->haveIdIndex(&_txn));
+ ASSERT(c->getIndexCatalog()->haveIdIndex(&_opCtx));
wuow.commit();
}
~Base() {
@@ -108,7 +108,7 @@ public:
ReplSettings replSettings;
replSettings.setOplogSizeBytes(10 * 1024 * 1024);
setGlobalReplicationCoordinator(
- new repl::ReplicationCoordinatorMock(_txn.getServiceContext(), replSettings));
+ new repl::ReplicationCoordinatorMock(_opCtx.getServiceContext(), replSettings));
} catch (...) {
FAIL("Exception while cleaning up test");
}
@@ -145,68 +145,68 @@ protected:
return _client.findOne(cllNS(), BSONObj());
}
int count() const {
- ScopedTransaction transaction(&_txn, MODE_X);
- Lock::GlobalWrite lk(_txn.lockState());
- OldClientContext ctx(&_txn, ns());
+ ScopedTransaction transaction(&_opCtx, MODE_X);
+ Lock::GlobalWrite lk(_opCtx.lockState());
+ OldClientContext ctx(&_opCtx, ns());
Database* db = ctx.db();
Collection* coll = db->getCollection(ns());
if (!coll) {
- WriteUnitOfWork wunit(&_txn);
- coll = db->createCollection(&_txn, ns());
+ WriteUnitOfWork wunit(&_opCtx);
+ coll = db->createCollection(&_opCtx, ns());
wunit.commit();
}
int count = 0;
- auto cursor = coll->getCursor(&_txn);
+ auto cursor = coll->getCursor(&_opCtx);
while (auto record = cursor->next()) {
++count;
}
return count;
}
int opCount() {
- return DBDirectClient(&_txn).query(cllNS(), BSONObj())->itcount();
+ return DBDirectClient(&_opCtx).query(cllNS(), BSONObj())->itcount();
}
void applyAllOperations() {
- ScopedTransaction transaction(&_txn, MODE_X);
- Lock::GlobalWrite lk(_txn.lockState());
+ ScopedTransaction transaction(&_opCtx, MODE_X);
+ Lock::GlobalWrite lk(_opCtx.lockState());
vector<BSONObj> ops;
{
- DBDirectClient db(&_txn);
+ DBDirectClient db(&_opCtx);
auto cursor = db.query(cllNS(), BSONObj());
while (cursor->more()) {
ops.push_back(cursor->nextSafeOwned());
}
}
{
- OldClientContext ctx(&_txn, ns());
+ OldClientContext ctx(&_opCtx, ns());
BSONObjBuilder b;
b.append("host", "localhost");
b.appendTimestamp("syncedTo", 0);
- ReplSource a(&_txn, b.obj());
+ ReplSource a(&_opCtx, b.obj());
for (vector<BSONObj>::iterator i = ops.begin(); i != ops.end(); ++i) {
if (0) {
mongo::unittest::log() << "op: " << *i << endl;
}
- _txn.setReplicatedWrites(false);
- a.applyOperation(&_txn, ctx.db(), *i);
- _txn.setReplicatedWrites(true);
+ _opCtx.setReplicatedWrites(false);
+ a.applyOperation(&_opCtx, ctx.db(), *i);
+ _opCtx.setReplicatedWrites(true);
}
}
}
void printAll(const char* ns) {
- ScopedTransaction transaction(&_txn, MODE_X);
- Lock::GlobalWrite lk(_txn.lockState());
- OldClientContext ctx(&_txn, ns);
+ ScopedTransaction transaction(&_opCtx, MODE_X);
+ Lock::GlobalWrite lk(_opCtx.lockState());
+ OldClientContext ctx(&_opCtx, ns);
Database* db = ctx.db();
Collection* coll = db->getCollection(ns);
if (!coll) {
- WriteUnitOfWork wunit(&_txn);
- coll = db->createCollection(&_txn, ns);
+ WriteUnitOfWork wunit(&_opCtx);
+ coll = db->createCollection(&_opCtx, ns);
wunit.commit();
}
- auto cursor = coll->getCursor(&_txn);
+ auto cursor = coll->getCursor(&_opCtx);
::mongo::log() << "all for " << ns << endl;
while (auto record = cursor->next()) {
::mongo::log() << record->data.releaseToBson() << endl;
@@ -214,35 +214,35 @@ protected:
}
// These deletes don't get logged.
void deleteAll(const char* ns) const {
- ScopedTransaction transaction(&_txn, MODE_X);
- Lock::GlobalWrite lk(_txn.lockState());
- OldClientContext ctx(&_txn, ns);
- WriteUnitOfWork wunit(&_txn);
+ ScopedTransaction transaction(&_opCtx, MODE_X);
+ Lock::GlobalWrite lk(_opCtx.lockState());
+ OldClientContext ctx(&_opCtx, ns);
+ WriteUnitOfWork wunit(&_opCtx);
Database* db = ctx.db();
Collection* coll = db->getCollection(ns);
if (!coll) {
- coll = db->createCollection(&_txn, ns);
+ coll = db->createCollection(&_opCtx, ns);
}
- ASSERT_OK(coll->truncate(&_txn));
+ ASSERT_OK(coll->truncate(&_opCtx));
wunit.commit();
}
void insert(const BSONObj& o) const {
- ScopedTransaction transaction(&_txn, MODE_X);
- Lock::GlobalWrite lk(_txn.lockState());
- OldClientContext ctx(&_txn, ns());
- WriteUnitOfWork wunit(&_txn);
+ ScopedTransaction transaction(&_opCtx, MODE_X);
+ Lock::GlobalWrite lk(_opCtx.lockState());
+ OldClientContext ctx(&_opCtx, ns());
+ WriteUnitOfWork wunit(&_opCtx);
Database* db = ctx.db();
Collection* coll = db->getCollection(ns());
if (!coll) {
- coll = db->createCollection(&_txn, ns());
+ coll = db->createCollection(&_opCtx, ns());
}
OpDebug* const nullOpDebug = nullptr;
if (o.hasField("_id")) {
- _txn.setReplicatedWrites(false);
- coll->insertDocument(&_txn, o, nullOpDebug, true);
- _txn.setReplicatedWrites(true);
+ _opCtx.setReplicatedWrites(false);
+ coll->insertDocument(&_opCtx, o, nullOpDebug, true);
+ _opCtx.setReplicatedWrites(true);
wunit.commit();
return;
}
@@ -252,9 +252,9 @@ protected:
id.init();
b.appendOID("_id", &id);
b.appendElements(o);
- _txn.setReplicatedWrites(false);
- coll->insertDocument(&_txn, b.obj(), nullOpDebug, true);
- _txn.setReplicatedWrites(true);
+ _opCtx.setReplicatedWrites(false);
+ coll->insertDocument(&_opCtx, b.obj(), nullOpDebug, true);
+ _opCtx.setReplicatedWrites(true);
wunit.commit();
}
static BSONObj wid(const char* json) {
@@ -1240,7 +1240,7 @@ public:
void reset() const {
deleteAll(ns());
// Add an index on 'a'. This prevents the update from running 'in place'.
- ASSERT_OK(dbtests::createIndex(&_txn, ns(), BSON("a" << 1)));
+ ASSERT_OK(dbtests::createIndex(&_opCtx, ns(), BSON("a" << 1)));
insert(fromjson("{'_id':0,z:1}"));
}
};
@@ -1383,7 +1383,7 @@ public:
bool returnEmpty;
SyncTest() : SyncTail(nullptr, SyncTail::MultiSyncApplyFunc()), returnEmpty(false) {}
virtual ~SyncTest() {}
- virtual BSONObj getMissingDoc(OperationContext* txn, Database* db, const BSONObj& o) {
+ virtual BSONObj getMissingDoc(OperationContext* opCtx, Database* db, const BSONObj& o) {
if (returnEmpty) {
BSONObj o;
return o;
@@ -1407,16 +1407,16 @@ public:
<< "foo"
<< "bar"));
- ScopedTransaction transaction(&_txn, MODE_X);
- Lock::GlobalWrite lk(_txn.lockState());
+ ScopedTransaction transaction(&_opCtx, MODE_X);
+ Lock::GlobalWrite lk(_opCtx.lockState());
// this should fail because we can't connect
try {
SyncTail badSource(nullptr, SyncTail::MultiSyncApplyFunc());
badSource.setHostname("localhost:123");
- OldClientContext ctx(&_txn, ns());
- badSource.getMissingDoc(&_txn, ctx.db(), o);
+ OldClientContext ctx(&_opCtx, ns());
+ badSource.getMissingDoc(&_opCtx, ctx.db(), o);
} catch (DBException&) {
threw = true;
}
@@ -1424,7 +1424,7 @@ public:
// now this should succeed
SyncTest t;
- verify(t.shouldRetry(&_txn, o));
+ verify(t.shouldRetry(&_opCtx, o));
verify(!_client
.findOne(ns(),
BSON("_id"
@@ -1433,7 +1433,7 @@ public:
// force it not to find an obj
t.returnEmpty = true;
- verify(!t.shouldRetry(&_txn, o));
+ verify(!t.shouldRetry(&_opCtx, o));
}
};