summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl/sync_tail_test_fixture.cpp
diff options
context:
space:
mode:
authorJudah Schvimer <judah@mongodb.com>2017-10-20 10:43:41 -0400
committerJudah Schvimer <judah@mongodb.com>2017-10-20 10:43:41 -0400
commitb3d26b5f94636870f75b92582d6b7c31190a1295 (patch)
tree2eb4a511066b693e08d7a51d34406b665107ce14 /src/mongo/db/repl/sync_tail_test_fixture.cpp
parent29140e49080de0c25482a2b13d1cc51c7b0096bf (diff)
downloadmongo-b3d26b5f94636870f75b92582d6b7c31190a1295.tar.gz
SERVER-31189 SERVER-31426 fail rollback on downgrade
Diffstat (limited to 'src/mongo/db/repl/sync_tail_test_fixture.cpp')
-rw-r--r--src/mongo/db/repl/sync_tail_test_fixture.cpp45
1 files changed, 44 insertions, 1 deletions
diff --git a/src/mongo/db/repl/sync_tail_test_fixture.cpp b/src/mongo/db/repl/sync_tail_test_fixture.cpp
index c9998c89660..0026f658fad 100644
--- a/src/mongo/db/repl/sync_tail_test_fixture.cpp
+++ b/src/mongo/db/repl/sync_tail_test_fixture.cpp
@@ -32,6 +32,8 @@
#include "mongo/db/catalog/document_validation.h"
#include "mongo/db/curop.h"
+#include "mongo/db/db_raii.h"
+#include "mongo/db/op_observer_impl.h"
#include "mongo/db/repl/drop_pending_collection_reaper.h"
#include "mongo/db/repl/replication_consistency_markers_mock.h"
#include "mongo/db/repl/replication_coordinator_mock.h"
@@ -46,16 +48,31 @@ void SyncTailTest::setUp() {
ServiceContextMongoDTest::setUp();
auto service = getServiceContext();
+ _opCtx = cc().makeOperationContext();
+
ReplicationCoordinator::set(service, stdx::make_unique<ReplicationCoordinatorMock>(service));
+ ASSERT_OK(ReplicationCoordinator::get(_opCtx.get())->setFollowerMode(MemberState::RS_PRIMARY));
+
auto storageInterface = stdx::make_unique<StorageInterfaceMock>();
_storageInterface = storageInterface.get();
storageInterface->insertDocumentsFn =
[](OperationContext*, const NamespaceString&, const std::vector<InsertStatement>&) {
return Status::OK();
};
+
+ // Storage interface mock should get the real uuid.
+ storageInterface->getCollectionUUIDFn = [](
+ OperationContext* opCtx, const NamespaceString& nss) -> StatusWith<OptionalCollectionUUID> {
+ AutoGetCollectionForRead autoColl(opCtx, nss);
+ return autoColl.getCollection()->uuid();
+ };
+
StorageInterface::set(service, std::move(storageInterface));
DropPendingCollectionReaper::set(
service, stdx::make_unique<DropPendingCollectionReaper>(_storageInterface));
+ repl::setOplogCollectionName();
+ repl::createOplog(_opCtx.get());
+ service->setOpObserver(stdx::make_unique<OpObserverImpl>());
_replicationProcess =
new ReplicationProcess(_storageInterface,
@@ -65,7 +82,6 @@ void SyncTailTest::setUp() {
std::unique_ptr<ReplicationProcess>(_replicationProcess));
- _opCtx = cc().makeOperationContext();
_opsApplied = 0;
_applyOp = [](OperationContext* opCtx,
Database* db,
@@ -74,6 +90,9 @@ void SyncTailTest::setUp() {
stdx::function<void()>) { return Status::OK(); };
_applyCmd = [](OperationContext* opCtx, const BSONObj& op, bool) { return Status::OK(); };
_incOps = [this]() { _opsApplied++; };
+
+ serverGlobalParams.featureCompatibility.setVersion(
+ ServerGlobalParams::FeatureCompatibility::Version::k36);
}
void SyncTailTest::tearDown() {
@@ -121,5 +140,29 @@ Status failedApplyCommand(OperationContext* opCtx, const BSONObj& theOperation,
return Status::OK();
}
+Status SyncTailTest::runOpSteadyState(const OplogEntry& op) {
+ SyncTail syncTail(nullptr, SyncTail::MultiSyncApplyFunc(), nullptr);
+ MultiApplier::OperationPtrs opsPtrs{&op};
+ auto syncApply = [](OperationContext* opCtx, const BSONObj& op, bool inSteadyStateReplication) {
+ return SyncTail::syncApply(opCtx, op, inSteadyStateReplication);
+ };
+ return multiSyncApply_noAbort(_opCtx.get(), &opsPtrs, syncApply);
+}
+
+Status SyncTailTest::runOpInitialSync(const OplogEntry& op) {
+ return runOpsInitialSync({op});
+}
+
+Status SyncTailTest::runOpsInitialSync(std::vector<OplogEntry> ops) {
+ SyncTail syncTail(nullptr, SyncTail::MultiSyncApplyFunc(), nullptr);
+ MultiApplier::OperationPtrs opsPtrs;
+ for (auto& op : ops) {
+ opsPtrs.push_back(&op);
+ }
+ AtomicUInt32 fetchCount(0);
+ return multiInitialSyncApply_noAbort(_opCtx.get(), &opsPtrs, &syncTail, &fetchCount);
+}
+
+
} // namespace repl
} // namespace mongo