summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl/idempotency_test_fixture.cpp
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2017-10-25 23:03:52 -0400
committerBenety Goh <benety@mongodb.com>2017-11-07 14:11:56 -0500
commita8b621d8a3ac790ac95d17323fe8b66558b3cb3f (patch)
tree5ac8bd81cc212fe7b056a459b84bc84a1c804b7c /src/mongo/db/repl/idempotency_test_fixture.cpp
parente37ad56eaad3c0d4c7c38af4ee06eaa1329426cd (diff)
downloadmongo-a8b621d8a3ac790ac95d17323fe8b66558b3cb3f.tar.gz
SERVER-31356 update the following unit tests to not mutate OplogEntry after construction
ChangeStreamStageTest SessionCatalogMigrationDestinationTest SessionCatalogMigrationSourceTest SessionHistoryIteratorTest SessionTest SyncTailTest WriteOpsRetryabilityTest
Diffstat (limited to 'src/mongo/db/repl/idempotency_test_fixture.cpp')
-rw-r--r--src/mongo/db/repl/idempotency_test_fixture.cpp104
1 files changed, 86 insertions, 18 deletions
diff --git a/src/mongo/db/repl/idempotency_test_fixture.cpp b/src/mongo/db/repl/idempotency_test_fixture.cpp
index 3c3cc06a72f..32b7347380c 100644
--- a/src/mongo/db/repl/idempotency_test_fixture.cpp
+++ b/src/mongo/db/repl/idempotency_test_fixture.cpp
@@ -60,6 +60,38 @@
namespace mongo {
namespace repl {
+namespace {
+
+/**
+ * Creates an OplogEntry with given parameters and preset defaults for this test suite.
+ */
+repl::OplogEntry makeOplogEntry(repl::OpTime opTime,
+ repl::OpTypeEnum opType,
+ NamespaceString nss,
+ BSONObj object,
+ boost::optional<BSONObj> object2 = boost::none,
+ OperationSessionInfo sessionInfo = {},
+ boost::optional<Date_t> wallClockTime = boost::none,
+ boost::optional<StmtId> stmtId = boost::none) {
+ return repl::OplogEntry(opTime, // optime
+ 1LL, // hash
+ opType, // opType
+ nss, // namespace
+ boost::none, // uuid
+ boost::none, // fromMigrate
+ repl::OplogEntry::kOplogVersion, // version
+ object, // o
+ object2, // o2
+ sessionInfo, // sessionInfo
+ wallClockTime, // wall clock time
+ stmtId, // statement id
+ boost::none, // optime of previous write within same transaction
+ boost::none, // pre-image optime
+ boost::none); // post-image optime
+}
+
+} // namespace
+
/**
* Compares BSON objects (BSONObj) in two sets of BSON objects (BSONObjSet) to see if the two
* sets are equivalent.
@@ -170,7 +202,7 @@ const auto kCollectionDoesNotExist = CollectionState();
OplogEntry makeCommandOplogEntry(OpTime opTime,
const NamespaceString& nss,
const BSONObj& command) {
- return OplogEntry(opTime, 1LL, OpTypeEnum::kCommand, nss.getCommandNS(), 2, command);
+ return makeOplogEntry(opTime, OpTypeEnum::kCommand, nss.getCommandNS(), command);
}
/**
@@ -191,9 +223,13 @@ OplogEntry makeCreateCollectionOplogEntry(OpTime opTime,
OplogEntry makeInsertDocumentOplogEntry(OpTime opTime,
const NamespaceString& nss,
const BSONObj& documentToInsert) {
- auto oplogEntry = OplogEntry(opTime, 1LL, OpTypeEnum::kInsert, nss, documentToInsert);
- oplogEntry.setWallClockTime(Date_t::now());
- return oplogEntry;
+ return makeOplogEntry(opTime, // optime
+ OpTypeEnum::kInsert, // op type
+ nss, // namespace
+ documentToInsert, // o
+ boost::none, // o2
+ {}, // session info
+ Date_t::now()); // wall clock time
}
/**
@@ -202,9 +238,13 @@ OplogEntry makeInsertDocumentOplogEntry(OpTime opTime,
OplogEntry makeDeleteDocumentOplogEntry(OpTime opTime,
const NamespaceString& nss,
const BSONObj& documentToDelete) {
- auto oplogEntry = OplogEntry(opTime, 1LL, OpTypeEnum::kDelete, nss, documentToDelete);
- oplogEntry.setWallClockTime(Date_t::now());
- return oplogEntry;
+ return makeOplogEntry(opTime, // optime
+ OpTypeEnum::kDelete, // op type
+ nss, // namespace
+ documentToDelete, // o
+ boost::none, // o2
+ {}, // session info
+ Date_t::now()); // wall clock time
}
/**
@@ -214,10 +254,13 @@ OplogEntry makeUpdateDocumentOplogEntry(OpTime opTime,
const NamespaceString& nss,
const BSONObj& documentToUpdate,
const BSONObj& updatedDocument) {
- auto oplogEntry =
- OplogEntry(opTime, 1LL, OpTypeEnum::kUpdate, nss, updatedDocument, documentToUpdate);
- oplogEntry.setWallClockTime(Date_t::now());
- return oplogEntry;
+ return makeOplogEntry(opTime, // optime
+ OpTypeEnum::kUpdate, // op type
+ nss, // namespace
+ updatedDocument, // o
+ documentToUpdate, // o2
+ {}, // session info
+ Date_t::now()); // wall clock time
}
/**
@@ -236,17 +279,42 @@ OplogEntry makeCreateIndexOplogEntry(OpTime opTime,
opTime, NamespaceString(nss.getSystemIndexesCollection()), indexInfoBob.obj());
}
-void appendSessionTransactionInfo(OplogEntry& entry,
- LogicalSessionId lsid,
- TxnNumber txnNum,
- StmtId stmtId) {
- auto info = entry.getOperationSessionInfo();
+/**
+ * Creates an insert oplog entry with given optime, namespace and session info.
+ */
+OplogEntry makeInsertDocumentOplogEntryWithSessionInfo(OpTime opTime,
+ const NamespaceString& nss,
+ const BSONObj& documentToInsert,
+ OperationSessionInfo info) {
+ return makeOplogEntry(opTime, // optime
+ OpTypeEnum::kInsert, // op type
+ nss, // namespace
+ documentToInsert, // o
+ boost::none, // o2
+ info, // session info
+ Date_t::now()); // wall clock time
+}
+
+OplogEntry makeInsertDocumentOplogEntryWithSessionInfoAndStmtId(OpTime opTime,
+ const NamespaceString& nss,
+ const BSONObj& documentToInsert,
+ LogicalSessionId lsid,
+ TxnNumber txnNum,
+ StmtId stmtId) {
+ OperationSessionInfo info;
info.setSessionId(lsid);
info.setTxnNumber(txnNum);
- entry.setOperationSessionInfo(std::move(info));
- entry.setStatementId(stmtId);
+ return makeOplogEntry(opTime, // optime
+ OpTypeEnum::kInsert, // op type
+ nss, // namespace
+ documentToInsert, // o
+ boost::none, // o2
+ info, // session info
+ Date_t::now(), // wall clock time
+ stmtId); // statement id
}
+
Status IdempotencyTest::resetState() {
return Status::OK();
}