summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2016-04-06 16:31:59 -0400
committerBenety Goh <benety@mongodb.com>2016-04-12 15:33:18 -0400
commitdbccf902ef519fb2a15cf50237144dc3df319e95 (patch)
tree157283f3f1ffaac66eab96c4929f68107ce15b5b /src/mongo
parenta74a8290941e7ef9f30e337e1ac3cd43f0982a53 (diff)
downloadmongo-dbccf902ef519fb2a15cf50237144dc3df319e95.tar.gz
SERVER-18038 added placeholder test for repl storage interface and test fixture for tests requiring use of ephemeral storage engine
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/SConscript13
-rw-r--r--src/mongo/db/repl/SConscript26
-rw-r--r--src/mongo/db/repl/rs_rollback_test.cpp23
-rw-r--r--src/mongo/db/repl/storage_interface.h9
-rw-r--r--src/mongo/db/repl/storage_interface_impl.cpp5
-rw-r--r--src/mongo/db/repl/storage_interface_impl.h9
-rw-r--r--src/mongo/db/repl/storage_interface_impl_test.cpp51
-rw-r--r--src/mongo/db/repl/storage_interface_mock.cpp4
-rw-r--r--src/mongo/db/repl/storage_interface_mock.h10
-rw-r--r--src/mongo/db/repl/sync_tail_test.cpp20
-rw-r--r--src/mongo/db/service_context_d_test_fixture.cpp55
-rw-r--r--src/mongo/db/service_context_d_test_fixture.h (renamed from src/mongo/db/repl/storage_interface.cpp)22
12 files changed, 166 insertions, 81 deletions
diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript
index 86e3b88198a..e530792b0de 100644
--- a/src/mongo/db/SConscript
+++ b/src/mongo/db/SConscript
@@ -737,6 +737,19 @@ serveronlyEnv.Library(
)
env.Library(
+ target= 'service_context_d_test_fixture',
+ source= [
+ 'service_context_d_test_fixture.cpp',
+ ],
+ LIBDEPS= [
+ '$BUILD_DIR/mongo/db/serveronly',
+ '$BUILD_DIR/mongo/db/storage/storage_options',
+ '$BUILD_DIR/mongo/unittest/unittest',
+ '$BUILD_DIR/mongo/util/ntservice_mock',
+ ],
+)
+
+env.Library(
target='log_process_details',
source=[
'log_process_details.cpp',
diff --git a/src/mongo/db/repl/SConscript b/src/mongo/db/repl/SConscript
index 27fd72ad763..a69df1942e1 100644
--- a/src/mongo/db/repl/SConscript
+++ b/src/mongo/db/repl/SConscript
@@ -48,11 +48,6 @@ env.Library('rslog',
'$BUILD_DIR/mongo/base',
])
-env.Library('storage_interface',
- 'storage_interface.cpp',
- LIBDEPS=[
- ])
-
env.Library(
target='storage_interface_impl',
source=[
@@ -61,9 +56,20 @@ env.Library(
LIBDEPS=[
'$BUILD_DIR/mongo/db/serveronly', # For OperationContextImpl
'$BUILD_DIR/mongo/db/service_context',
- 'storage_interface',
])
+env.CppUnitTest(
+ target='storage_interface_impl_test',
+ source=[
+ 'storage_interface_impl_test.cpp',
+ ],
+ LIBDEPS=[
+ 'storage_interface_impl',
+ '$BUILD_DIR/mongo/db/service_context_d_test_fixture',
+ ],
+ NO_CRUTCH = True,
+)
+
env.Library(
target='replication_executor',
source=[
@@ -74,7 +80,6 @@ env.Library(
LIBDEPS=[
'database_task',
'task_runner',
- 'storage_interface',
'$BUILD_DIR/mongo/executor/network_interface',
'$BUILD_DIR/mongo/executor/task_executor_interface',
'$BUILD_DIR/mongo/util/foundation',
@@ -184,8 +189,7 @@ env.CppUnitTest(
'oplog_interface_mock',
'replmocks',
'rs_rollback',
- '$BUILD_DIR/mongo/db/serveronly',
- '$BUILD_DIR/mongo/util/ntservice_mock',
+ '$BUILD_DIR/mongo/db/service_context_d_test_fixture',
],
NO_CRUTCH = True,
)
@@ -250,8 +254,7 @@ env.CppUnitTest(
LIBDEPS=[
'replmocks',
'sync_tail',
- '$BUILD_DIR/mongo/db/serveronly',
- '$BUILD_DIR/mongo/util/ntservice_mock',
+ '$BUILD_DIR/mongo/db/service_context_d_test_fixture',
],
NO_CRUTCH = True,
)
@@ -471,7 +474,6 @@ env.Library('replmocks',
'repl_settings',
'replica_set_messages',
'replication_executor',
- 'storage_interface',
])
env.Library('read_concern_args',
diff --git a/src/mongo/db/repl/rs_rollback_test.cpp b/src/mongo/db/repl/rs_rollback_test.cpp
index 84dd923eaef..04681ebf365 100644
--- a/src/mongo/db/repl/rs_rollback_test.cpp
+++ b/src/mongo/db/repl/rs_rollback_test.cpp
@@ -33,7 +33,6 @@
#include <list>
#include <utility>
-#include "mongo/base/checked_cast.h"
#include "mongo/db/catalog/collection.h"
#include "mongo/db/catalog/database.h"
#include "mongo/db/catalog/database_holder.h"
@@ -53,11 +52,8 @@
#include "mongo/db/repl/replication_coordinator_mock.h"
#include "mongo/db/repl/rollback_source.h"
#include "mongo/db/repl/rs_rollback.h"
-#include "mongo/db/service_context.h"
-#include "mongo/db/service_context_d.h"
-#include "mongo/db/storage/storage_options.h"
+#include "mongo/db/service_context_d_test_fixture.h"
#include "mongo/stdx/memory.h"
-#include "mongo/unittest/temp_dir.h"
#include "mongo/unittest/unittest.h"
namespace {
@@ -128,7 +124,7 @@ StatusWith<BSONObj> RollbackSourceMock::getCollectionInfo(const NamespaceString&
return BSON("name" << nss.ns() << "options" << BSONObj());
}
-class RSRollbackTest : public unittest::Test {
+class RSRollbackTest : public ServiceContextMongoDTest {
protected:
std::unique_ptr<OperationContext> _txn;
@@ -141,19 +137,7 @@ private:
};
void RSRollbackTest::setUp() {
- ServiceContext* serviceContext = getGlobalServiceContext();
- if (!serviceContext->getGlobalStorageEngine()) {
- // When using the 'devnull' storage engine, it is fine for the temporary directory to
- // go away after the global storage engine is initialized.
- unittest::TempDir tempDir("rs_rollback_test");
- mongo::storageGlobalParams.dbpath = tempDir.path();
- mongo::storageGlobalParams.dbpath = tempDir.path();
- mongo::storageGlobalParams.engine = "ephemeralForTest";
- mongo::storageGlobalParams.engineSetByUser = true;
- checked_cast<ServiceContextMongoD*>(getGlobalServiceContext())->createLockFile();
- serviceContext->initializeGlobalStorageEngine();
- }
-
+ ServiceContextMongoDTest::setUp();
Client::initThreadIfNotAlready();
_txn.reset(new OperationContextReplMock(&cc(), 1));
_coordinator = new ReplicationCoordinatorRollbackMock();
@@ -174,6 +158,7 @@ void RSRollbackTest::tearDown() {
setGlobalReplicationCoordinator(nullptr);
}
+
void noSleep(Seconds seconds) {}
TEST_F(RSRollbackTest, InconsistentMinValid) {
diff --git a/src/mongo/db/repl/storage_interface.h b/src/mongo/db/repl/storage_interface.h
index 1f9d0576741..7316b47f8af 100644
--- a/src/mongo/db/repl/storage_interface.h
+++ b/src/mongo/db/repl/storage_interface.h
@@ -29,6 +29,7 @@
#pragma once
+#include "mongo/base/disallow_copying.h"
namespace mongo {
@@ -41,16 +42,16 @@ namespace repl {
* ReplicationExectutor's ability to take database locks.
*/
class StorageInterface {
+ MONGO_DISALLOW_COPYING(StorageInterface);
+
public:
- virtual ~StorageInterface();
+ StorageInterface() = default;
+ virtual ~StorageInterface() = default;
/**
* Creates an operation context for running database operations.
*/
virtual OperationContext* createOperationContext() = 0;
-
-protected:
- StorageInterface();
};
} // namespace repl
diff --git a/src/mongo/db/repl/storage_interface_impl.cpp b/src/mongo/db/repl/storage_interface_impl.cpp
index a58f85964b4..76bcf285d6c 100644
--- a/src/mongo/db/repl/storage_interface_impl.cpp
+++ b/src/mongo/db/repl/storage_interface_impl.cpp
@@ -26,8 +26,6 @@
* it in the license file.
*/
-#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kReplication
-
#include "mongo/platform/basic.h"
#include "mongo/db/repl/storage_interface_impl.h"
@@ -39,9 +37,6 @@
namespace mongo {
namespace repl {
-StorageInterfaceImpl::StorageInterfaceImpl() : StorageInterface() {}
-StorageInterfaceImpl::~StorageInterfaceImpl() {}
-
OperationContext* StorageInterfaceImpl::createOperationContext() {
if (!ClientBasic::getCurrent()) {
Client::initThreadIfNotAlready();
diff --git a/src/mongo/db/repl/storage_interface_impl.h b/src/mongo/db/repl/storage_interface_impl.h
index fa378e537fd..0aa51b43360 100644
--- a/src/mongo/db/repl/storage_interface_impl.h
+++ b/src/mongo/db/repl/storage_interface_impl.h
@@ -29,18 +29,17 @@
#pragma once
+#include "mongo/base/disallow_copying.h"
#include "mongo/db/repl/storage_interface.h"
namespace mongo {
-
-class OperationContext;
-
namespace repl {
class StorageInterfaceImpl : public StorageInterface {
+ MONGO_DISALLOW_COPYING(StorageInterfaceImpl);
+
public:
- explicit StorageInterfaceImpl();
- virtual ~StorageInterfaceImpl();
+ StorageInterfaceImpl() = default;
OperationContext* createOperationContext() override;
};
diff --git a/src/mongo/db/repl/storage_interface_impl_test.cpp b/src/mongo/db/repl/storage_interface_impl_test.cpp
new file mode 100644
index 00000000000..159791daa77
--- /dev/null
+++ b/src/mongo/db/repl/storage_interface_impl_test.cpp
@@ -0,0 +1,51 @@
+/**
+ * Copyright 2015 MongoDB Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the GNU Affero General Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
+ */
+
+#include "mongo/platform/basic.h"
+
+#include <memory>
+
+#include "mongo/db/operation_context.h"
+#include "mongo/db/repl/storage_interface_impl.h"
+#include "mongo/db/service_context_d_test_fixture.h"
+
+#include "mongo/unittest/unittest.h"
+
+namespace {
+
+using namespace mongo;
+using namespace mongo::repl;
+
+class StorageInterfaceImplTest : public ServiceContextMongoDTest {};
+
+TEST_F(StorageInterfaceImplTest, CreateOperationContextShouldNotReturnNull) {
+ std::unique_ptr<OperationContext> txn(StorageInterfaceImpl().createOperationContext());
+ ASSERT_TRUE(txn);
+}
+
+} // namespace
diff --git a/src/mongo/db/repl/storage_interface_mock.cpp b/src/mongo/db/repl/storage_interface_mock.cpp
index b620c65276d..76ccf7a1704 100644
--- a/src/mongo/db/repl/storage_interface_mock.cpp
+++ b/src/mongo/db/repl/storage_interface_mock.cpp
@@ -37,10 +37,6 @@
namespace mongo {
namespace repl {
-StorageInterfaceMock::StorageInterfaceMock() {}
-
-StorageInterfaceMock::~StorageInterfaceMock() {}
-
OperationContext* StorageInterfaceMock::createOperationContext() {
return new OperationContextReplMock();
}
diff --git a/src/mongo/db/repl/storage_interface_mock.h b/src/mongo/db/repl/storage_interface_mock.h
index 8ce76adb642..1ee2858cfec 100644
--- a/src/mongo/db/repl/storage_interface_mock.h
+++ b/src/mongo/db/repl/storage_interface_mock.h
@@ -29,19 +29,17 @@
#pragma once
+#include "mongo/base/disallow_copying.h"
#include "mongo/db/repl/storage_interface.h"
namespace mongo {
-
-class OperationContext;
-
namespace repl {
class StorageInterfaceMock : public StorageInterface {
-public:
- explicit StorageInterfaceMock();
- virtual ~StorageInterfaceMock();
+ MONGO_DISALLOW_COPYING(StorageInterfaceMock);
+public:
+ StorageInterfaceMock() = default;
OperationContext* createOperationContext() override;
};
diff --git a/src/mongo/db/repl/sync_tail_test.cpp b/src/mongo/db/repl/sync_tail_test.cpp
index e157e02f173..000a761be1c 100644
--- a/src/mongo/db/repl/sync_tail_test.cpp
+++ b/src/mongo/db/repl/sync_tail_test.cpp
@@ -30,7 +30,6 @@
#include <memory>
-#include "mongo/base/checked_cast.h"
#include "mongo/db/catalog/database.h"
#include "mongo/db/catalog/database_holder.h"
#include "mongo/db/catalog/document_validation.h"
@@ -44,10 +43,7 @@
#include "mongo/db/repl/replication_coordinator_global.h"
#include "mongo/db/repl/replication_coordinator_mock.h"
#include "mongo/db/repl/sync_tail.h"
-#include "mongo/db/service_context.h"
-#include "mongo/db/service_context_d.h"
-#include "mongo/db/storage/storage_options.h"
-#include "mongo/unittest/temp_dir.h"
+#include "mongo/db/service_context_d_test_fixture.h"
#include "mongo/unittest/unittest.h"
namespace {
@@ -68,7 +64,7 @@ bool BackgroundSyncMock::peek(BSONObj* op) {
void BackgroundSyncMock::consume() {}
void BackgroundSyncMock::waitForMore() {}
-class SyncTailTest : public unittest::Test {
+class SyncTailTest : public ServiceContextMongoDTest {
protected:
void _testSyncApplyInsertDocument(LockMode expectedMode);
@@ -84,17 +80,7 @@ private:
};
void SyncTailTest::setUp() {
- ServiceContext* serviceContext = getGlobalServiceContext();
- if (!serviceContext->getGlobalStorageEngine()) {
- // When using the 'devnull' storage engine, it is fine for the temporary directory to
- // go away after the global storage engine is initialized.
- unittest::TempDir tempDir("sync_tail_test");
- mongo::storageGlobalParams.dbpath = tempDir.path();
- mongo::storageGlobalParams.engine = "devnull";
- mongo::storageGlobalParams.engineSetByUser = true;
- checked_cast<ServiceContextMongoD*>(getGlobalServiceContext())->createLockFile();
- serviceContext->initializeGlobalStorageEngine();
- }
+ ServiceContextMongoDTest::setUp();
ReplSettings replSettings;
replSettings.setOplogSizeBytes(5 * 1024 * 1024);
diff --git a/src/mongo/db/service_context_d_test_fixture.cpp b/src/mongo/db/service_context_d_test_fixture.cpp
new file mode 100644
index 00000000000..59079ce2a49
--- /dev/null
+++ b/src/mongo/db/service_context_d_test_fixture.cpp
@@ -0,0 +1,55 @@
+/**
+ * Copyright (C) 2016 MongoDB Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the GNU Affero General Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
+ */
+
+#include "mongo/platform/basic.h"
+
+#include "mongo/db/service_context_d_test_fixture.h"
+
+#include "mongo/base/checked_cast.h"
+#include "mongo/db/service_context.h"
+#include "mongo/db/service_context_d.h"
+#include "mongo/db/storage/storage_options.h"
+#include "mongo/unittest/temp_dir.h"
+
+namespace mongo {
+
+void ServiceContextMongoDTest::setUp() {
+ ServiceContext* serviceContext = getGlobalServiceContext();
+ if (!serviceContext->getGlobalStorageEngine()) {
+ // When using the "ephemeralForTest" storage engine, it is fine for the temporary directory
+ // to go away after the global storage engine is initialized.
+ unittest::TempDir tempDir("service_context_d_test_fixture");
+ storageGlobalParams.dbpath = tempDir.path();
+ storageGlobalParams.engine = "ephemeralForTest";
+ storageGlobalParams.engineSetByUser = true;
+ checked_cast<ServiceContextMongoD*>(getGlobalServiceContext())->createLockFile();
+ serviceContext->initializeGlobalStorageEngine();
+ }
+}
+
+} // namespace mongo
diff --git a/src/mongo/db/repl/storage_interface.cpp b/src/mongo/db/service_context_d_test_fixture.h
index 0b883d827b9..47a54cc4eaa 100644
--- a/src/mongo/db/repl/storage_interface.cpp
+++ b/src/mongo/db/service_context_d_test_fixture.h
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2015 MongoDB Inc.
+ * Copyright (C) 2016 MongoDB Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
@@ -26,17 +26,21 @@
* it in the license file.
*/
-#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kReplication
+#pragma once
-#include "mongo/platform/basic.h"
-
-#include "mongo/db/repl/storage_interface.h"
+#include "mongo/unittest/unittest.h"
namespace mongo {
-namespace repl {
-StorageInterface::StorageInterface() {}
-StorageInterface::~StorageInterface() {}
+/**
+ * Test fixture class for tests that use either the "ephemeralForTest" or "devnull" storage engines.
+ */
+class ServiceContextMongoDTest : public unittest::Test {
+protected:
+ /**
+ * Initializes global storage engine.
+ */
+ void setUp() override;
+};
-} // namespace repl
} // namespace mongo