diff options
Diffstat (limited to 'src')
17 files changed, 155 insertions, 46 deletions
diff --git a/src/mongo/db/repl/replication_executor_test.cpp b/src/mongo/db/repl/replication_executor_test.cpp index 527d0eb310b..fb6639b788c 100644 --- a/src/mongo/db/repl/replication_executor_test.cpp +++ b/src/mongo/db/repl/replication_executor_test.cpp @@ -58,7 +58,7 @@ const int64_t prngSeed = 1; MONGO_INITIALIZER(ReplExecutorCommonTests)(InitializerContext*) { mongo::executor::addTestsForExecutor( "ReplicationExecutorCommon", - [](std::unique_ptr<executor::NetworkInterface>* net) { + [](std::unique_ptr<executor::NetworkInterfaceMock>* net) { return stdx::make_unique<ReplicationExecutor>( net->release(), new StorageInterfaceMock(), prngSeed); }); diff --git a/src/mongo/db/repl/replication_executor_test_fixture.cpp b/src/mongo/db/repl/replication_executor_test_fixture.cpp index 8d2172eb291..2ee87f372de 100644 --- a/src/mongo/db/repl/replication_executor_test_fixture.cpp +++ b/src/mongo/db/repl/replication_executor_test_fixture.cpp @@ -52,7 +52,7 @@ void ReplicationExecutorTest::postExecutorThreadLaunch() { } std::unique_ptr<executor::TaskExecutor> ReplicationExecutorTest::makeTaskExecutor( - std::unique_ptr<executor::NetworkInterface> net) { + std::unique_ptr<executor::NetworkInterfaceMock> net) { _storage = new StorageInterfaceMock(); return stdx::make_unique<ReplicationExecutor>(net.release(), _storage, prngSeed); } diff --git a/src/mongo/db/repl/replication_executor_test_fixture.h b/src/mongo/db/repl/replication_executor_test_fixture.h index f7bd59a8672..73e5ae2c504 100644 --- a/src/mongo/db/repl/replication_executor_test_fixture.h +++ b/src/mongo/db/repl/replication_executor_test_fixture.h @@ -60,7 +60,7 @@ protected: private: std::unique_ptr<executor::TaskExecutor> makeTaskExecutor( - std::unique_ptr<executor::NetworkInterface> net) override; + std::unique_ptr<executor::NetworkInterfaceMock> net) override; StorageInterfaceMock* _storage{nullptr}; diff --git a/src/mongo/executor/SConscript b/src/mongo/executor/SConscript index 2339743ffa1..24147c3c578 100644 --- a/src/mongo/executor/SConscript +++ b/src/mongo/executor/SConscript @@ -11,6 +11,7 @@ env.Library(target='task_executor_interface', 'task_executor.cpp', ], LIBDEPS=[ + '$BUILD_DIR/mongo/base/base', '$BUILD_DIR/mongo/rpc/metadata', '$BUILD_DIR/mongo/util/net/hostandport', ]) @@ -27,7 +28,7 @@ env.Library(target='network_interface_impl', # TODO: rename to thread_pool_netwo '$BUILD_DIR/mongo/client/remote_command_runner_impl', '$BUILD_DIR/mongo/util/concurrency/thread_pool', 'network_interface', - # TODO: add dependency on the task executor *interface* once available. + 'task_executor_interface', ]) env.Library('network_interface_mock', @@ -47,8 +48,8 @@ env.Library(target='network_test_env', source=['network_test_env.cpp',], LIBDEPS=[ 'network_interface_mock', + 'task_executor_interface', '$BUILD_DIR/mongo/db/coredb', - '$BUILD_DIR/mongo/db/repl/replication_executor', ]) env.Library( @@ -98,7 +99,19 @@ env.Library( 'thread_pool_task_executor.cpp', ], LIBDEPS=[ - '$BUILD_DIR/mongo/util/concurrency/thread_pool' + '$BUILD_DIR/mongo/util/concurrency/thread_pool', + 'task_executor_interface', + ] +) + +env.Library( + target='thread_pool_task_executor_test_fixture', + source=[ + 'thread_pool_task_executor_test_fixture.cpp', + ], + LIBDEPS=[ + 'thread_pool_task_executor', + 'task_executor_test_fixture', ] ) @@ -108,7 +121,6 @@ env.CppUnitTest( 'thread_pool_task_executor_test.cpp', ], LIBDEPS=[ - 'thread_pool_task_executor', - 'task_executor_test_fixture', + 'thread_pool_task_executor_test_fixture', ] ) diff --git a/src/mongo/executor/network_test_env.cpp b/src/mongo/executor/network_test_env.cpp index 18ed04ebd00..c65d1adcf2a 100644 --- a/src/mongo/executor/network_test_env.cpp +++ b/src/mongo/executor/network_test_env.cpp @@ -38,7 +38,7 @@ namespace mongo { namespace executor { -NetworkTestEnv::NetworkTestEnv(repl::ReplicationExecutor* executor, NetworkInterfaceMock* network) +NetworkTestEnv::NetworkTestEnv(TaskExecutor* executor, NetworkInterfaceMock* network) : _executor(executor), _mockNetwork(network) {} void NetworkTestEnv::onCommand(OnCommandFunction func) { diff --git a/src/mongo/executor/network_test_env.h b/src/mongo/executor/network_test_env.h index bfec66d570f..b68b15a5a7f 100644 --- a/src/mongo/executor/network_test_env.h +++ b/src/mongo/executor/network_test_env.h @@ -31,11 +31,11 @@ #include <type_traits> #include <vector> -#include "mongo/db/repl/replication_executor.h" #include "mongo/executor/network_interface_mock.h" -#include "mongo/stdx/thread.h" +#include "mongo/executor/task_executor.h" #include "mongo/stdx/functional.h" #include "mongo/stdx/future.h" +#include "mongo/stdx/thread.h" #include "mongo/unittest/unittest.h" namespace mongo { @@ -138,7 +138,7 @@ public: /** * Create a new environment based on the given network. */ - NetworkTestEnv(repl::ReplicationExecutor* executor, NetworkInterfaceMock* network); + NetworkTestEnv(TaskExecutor* executor, NetworkInterfaceMock* network); /** * Blocking methods, which receive one message from the network and respond using the @@ -150,7 +150,7 @@ public: private: // Task executor used for running asynchronous operations. - repl::ReplicationExecutor* _executor; + TaskExecutor* _executor; // Mocked out network under the task executor. NetworkInterfaceMock* _mockNetwork; diff --git a/src/mongo/executor/task_executor_test_common.cpp b/src/mongo/executor/task_executor_test_common.cpp index 19eddcee5e9..d57f2e15434 100644 --- a/src/mongo/executor/task_executor_test_common.cpp +++ b/src/mongo/executor/task_executor_test_common.cpp @@ -51,7 +51,7 @@ namespace executor { namespace { using ExecutorFactory = - stdx::function<std::unique_ptr<TaskExecutor>(std::unique_ptr<NetworkInterface>*)>; + stdx::function<std::unique_ptr<TaskExecutor>(std::unique_ptr<NetworkInterfaceMock>*)>; class CommonTaskExecutorTestFixture : public TaskExecutorTest { public: @@ -59,7 +59,8 @@ public: : _makeExecutor(std::move(makeExecutor)) {} private: - std::unique_ptr<TaskExecutor> makeTaskExecutor(std::unique_ptr<NetworkInterface> net) override { + std::unique_ptr<TaskExecutor> makeTaskExecutor( + std::unique_ptr<NetworkInterfaceMock> net) override { return _makeExecutor(&net); } diff --git a/src/mongo/executor/task_executor_test_common.h b/src/mongo/executor/task_executor_test_common.h index 8d933cfcde5..b9fd7e7235c 100644 --- a/src/mongo/executor/task_executor_test_common.h +++ b/src/mongo/executor/task_executor_test_common.h @@ -36,7 +36,7 @@ namespace mongo { namespace executor { -class NetworkInterface; +class NetworkInterfaceMock; class TaskExecutor; /** @@ -49,9 +49,9 @@ class TaskExecutor; * presumably after the release of MSVC2015, the signature can be changed to take the unique_ptr * by value. */ -void addTestsForExecutor( - const std::string& suiteName, - stdx::function<std::unique_ptr<TaskExecutor>(std::unique_ptr<NetworkInterface>*)> makeExecutor); +void addTestsForExecutor(const std::string& suiteName, + stdx::function<std::unique_ptr<TaskExecutor>( + std::unique_ptr<NetworkInterfaceMock>*)> makeExecutor); } // namespace executor } // namespace mongo diff --git a/src/mongo/executor/task_executor_test_fixture.h b/src/mongo/executor/task_executor_test_fixture.h index 2e3b6f135c7..2077bdb027c 100644 --- a/src/mongo/executor/task_executor_test_fixture.h +++ b/src/mongo/executor/task_executor_test_fixture.h @@ -77,7 +77,7 @@ protected: private: virtual std::unique_ptr<TaskExecutor> makeTaskExecutor( - std::unique_ptr<NetworkInterface> net) = 0; + std::unique_ptr<NetworkInterfaceMock> net) = 0; virtual void postExecutorThreadLaunch(); diff --git a/src/mongo/executor/thread_pool_task_executor_test.cpp b/src/mongo/executor/thread_pool_task_executor_test.cpp index 63e8e142f3d..af1f4fb53b5 100644 --- a/src/mongo/executor/thread_pool_task_executor_test.cpp +++ b/src/mongo/executor/thread_pool_task_executor_test.cpp @@ -35,37 +35,24 @@ #include "mongo/executor/network_interface_mock.h" #include "mongo/executor/task_executor_test_common.h" #include "mongo/executor/task_executor_test_fixture.h" +#include "mongo/executor/thread_pool_mock.h" #include "mongo/executor/thread_pool_task_executor.h" +#include "mongo/executor/thread_pool_task_executor_test_fixture.h" #include "mongo/stdx/memory.h" #include "mongo/unittest/unittest.h" -#include "mongo/executor/thread_pool_mock.h" namespace mongo { namespace executor { namespace { -std::unique_ptr<ThreadPoolTaskExecutor> makeThreadPoolTestExecutor( - std::unique_ptr<NetworkInterface> net) { - auto netPtr = checked_cast<NetworkInterfaceMock*>(net.get()); - return stdx::make_unique<ThreadPoolTaskExecutor>(stdx::make_unique<ThreadPoolMock>(netPtr, 1), - std::move(net)); -} - MONGO_INITIALIZER(ThreadPoolExecutorCommonTests)(InitializerContext*) { addTestsForExecutor("ThreadPoolExecutorCommon", - [](std::unique_ptr<NetworkInterface>* net) { + [](std::unique_ptr<NetworkInterfaceMock>* net) { return makeThreadPoolTestExecutor(std::move(*net)); }); return Status::OK(); } -class ThreadPoolExecutorTest : public TaskExecutorTest { -private: - std::unique_ptr<TaskExecutor> makeTaskExecutor(std::unique_ptr<NetworkInterface> net) override { - return makeThreadPoolTestExecutor(std::move(net)); - } -}; - void setStatus(const TaskExecutor::CallbackArgs& cbData, Status* outStatus) { *outStatus = cbData.status; } diff --git a/src/mongo/executor/thread_pool_task_executor_test_fixture.cpp b/src/mongo/executor/thread_pool_task_executor_test_fixture.cpp new file mode 100644 index 00000000000..618ef921323 --- /dev/null +++ b/src/mongo/executor/thread_pool_task_executor_test_fixture.cpp @@ -0,0 +1,52 @@ +/** + * Copyright (C) 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 "mongo/executor/thread_pool_task_executor_test_fixture.h" + +#include "mongo/executor/thread_pool_mock.h" +#include "mongo/stdx/memory.h" + +namespace mongo { +namespace executor { + +std::unique_ptr<ThreadPoolTaskExecutor> makeThreadPoolTestExecutor( + std::unique_ptr<NetworkInterfaceMock> net) { + auto netPtr = net.get(); + return stdx::make_unique<ThreadPoolTaskExecutor>(stdx::make_unique<ThreadPoolMock>(netPtr, 1), + std::move(net)); +} + +std::unique_ptr<TaskExecutor> ThreadPoolExecutorTest::makeTaskExecutor( + std::unique_ptr<NetworkInterfaceMock> net) { + return makeThreadPoolTestExecutor(std::move(net)); +} + +} // namespace executor +} // namespace mongo diff --git a/src/mongo/executor/thread_pool_task_executor_test_fixture.h b/src/mongo/executor/thread_pool_task_executor_test_fixture.h new file mode 100644 index 00000000000..04a3089bbab --- /dev/null +++ b/src/mongo/executor/thread_pool_task_executor_test_fixture.h @@ -0,0 +1,56 @@ +/** + * Copyright (C) 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. + */ + +#pragma once + +#include <memory> + +#include "mongo/executor/network_interface_mock.h" +#include "mongo/executor/thread_pool_task_executor.h" +#include "mongo/executor/task_executor_test_fixture.h" + +namespace mongo { +namespace executor { + +/** + * Makes a new ThreadPoolTaskExecutor for use in unit tests. + */ +std::unique_ptr<ThreadPoolTaskExecutor> makeThreadPoolTestExecutor( + std::unique_ptr<NetworkInterfaceMock> net); + +/** + * Useful fixture class for tests that use a ThreadPoolTaskExecutor. + */ +class ThreadPoolExecutorTest : public TaskExecutorTest { +private: + std::unique_ptr<TaskExecutor> makeTaskExecutor( + std::unique_ptr<NetworkInterfaceMock> net) override; +}; + +} // namespace executor +} // namespace mongo diff --git a/src/mongo/s/catalog/SConscript b/src/mongo/s/catalog/SConscript index 170f22d1727..ab3d850e2ad 100644 --- a/src/mongo/s/catalog/SConscript +++ b/src/mongo/s/catalog/SConscript @@ -146,13 +146,14 @@ env.CppUnitTest( 'dist_lock_catalog_impl_test.cpp', ], LIBDEPS=[ - 'catalog_manager_mock', - 'dist_lock_catalog_impl', '$BUILD_DIR/mongo/client/remote_command_targeter_mock', '$BUILD_DIR/mongo/db/auth/authorization_manager_mock_init', '$BUILD_DIR/mongo/executor/network_test_env', + '$BUILD_DIR/mongo/executor/thread_pool_task_executor_test_fixture', '$BUILD_DIR/mongo/s/coreshard', '$BUILD_DIR/mongo/s/mongoscore', + 'catalog_manager_mock', + 'dist_lock_catalog_impl', ] ) diff --git a/src/mongo/s/catalog/dist_lock_catalog_impl_test.cpp b/src/mongo/s/catalog/dist_lock_catalog_impl_test.cpp index 7fbe52eea03..456ecaa70ba 100644 --- a/src/mongo/s/catalog/dist_lock_catalog_impl_test.cpp +++ b/src/mongo/s/catalog/dist_lock_catalog_impl_test.cpp @@ -38,9 +38,9 @@ #include "mongo/db/commands.h" #include "mongo/db/jsobj.h" #include "mongo/db/query/find_and_modify_request.h" -#include "mongo/db/repl/replication_executor.h" #include "mongo/executor/network_interface_mock.h" #include "mongo/executor/network_test_env.h" +#include "mongo/executor/thread_pool_task_executor_test_fixture.h" #include "mongo/s/catalog/catalog_manager_mock.h" #include "mongo/s/catalog/dist_lock_catalog_impl.h" #include "mongo/s/catalog/type_lockpings.h" @@ -105,8 +105,7 @@ private: void setUp() override { auto networkUniquePtr = stdx::make_unique<executor::NetworkInterfaceMock>(); executor::NetworkInterfaceMock* network = networkUniquePtr.get(); - auto executor = - stdx::make_unique<repl::ReplicationExecutor>(networkUniquePtr.release(), nullptr, 0); + auto executor = executor::makeThreadPoolTestExecutor(std::move(networkUniquePtr)); _networkTestEnv = stdx::make_unique<NetworkTestEnv>(executor.get(), network); diff --git a/src/mongo/s/catalog/replset/SConscript b/src/mongo/s/catalog/replset/SConscript index fe1d0e307c9..2e7d7d72f4a 100644 --- a/src/mongo/s/catalog/replset/SConscript +++ b/src/mongo/s/catalog/replset/SConscript @@ -59,6 +59,7 @@ env.CppUnitTest( '$BUILD_DIR/mongo/client/remote_command_targeter_mock', '$BUILD_DIR/mongo/db/auth/authorization_manager_mock_init', '$BUILD_DIR/mongo/executor/network_test_env', + '$BUILD_DIR/mongo/executor/thread_pool_task_executor_test_fixture', '$BUILD_DIR/mongo/s/catalog/dist_lock_manager_mock', '$BUILD_DIR/mongo/s/coreshard', '$BUILD_DIR/mongo/s/mongoscore', diff --git a/src/mongo/s/catalog/replset/catalog_manager_replica_set_test_fixture.cpp b/src/mongo/s/catalog/replset/catalog_manager_replica_set_test_fixture.cpp index 48778885397..a8ae5bc04fc 100644 --- a/src/mongo/s/catalog/replset/catalog_manager_replica_set_test_fixture.cpp +++ b/src/mongo/s/catalog/replset/catalog_manager_replica_set_test_fixture.cpp @@ -40,9 +40,9 @@ #include "mongo/db/commands.h" #include "mongo/db/namespace_string.h" #include "mongo/db/query/lite_parsed_query.h" -#include "mongo/db/repl/replication_executor.h" #include "mongo/db/service_context_noop.h" #include "mongo/executor/network_interface_mock.h" +#include "mongo/executor/thread_pool_task_executor_test_fixture.h" #include "mongo/s/catalog/dist_lock_manager_mock.h" #include "mongo/s/catalog/replset/catalog_manager_replica_set.h" #include "mongo/s/catalog/type_changelog.h" @@ -83,8 +83,7 @@ void CatalogManagerReplSetTestFixture::setUp() { auto network(stdx::make_unique<executor::NetworkInterfaceMock>()); _mockNetwork = network.get(); - std::unique_ptr<repl::ReplicationExecutor> executor( - stdx::make_unique<repl::ReplicationExecutor>(network.release(), nullptr, 0)); + auto executor = makeThreadPoolTestExecutor(std::move(network)); _networkTestEnv = stdx::make_unique<NetworkTestEnv>(executor.get(), _mockNetwork); _executor = executor.get(); @@ -216,7 +215,7 @@ void CatalogManagerReplSetTestFixture::expectGetShards(const std::vector<ShardTy }); } -void CatalogManagerReplSetTestFixture::expectInserts(const NamespaceString nss, +void CatalogManagerReplSetTestFixture::expectInserts(const NamespaceString& nss, const std::vector<BSONObj>& expected) { onCommand([&nss, &expected](const RemoteCommandRequest& request) { ASSERT_EQUALS(nss.db(), request.dbname); diff --git a/src/mongo/s/catalog/replset/catalog_manager_replica_set_test_fixture.h b/src/mongo/s/catalog/replset/catalog_manager_replica_set_test_fixture.h index 574944460f1..62aaa1a9602 100644 --- a/src/mongo/s/catalog/replset/catalog_manager_replica_set_test_fixture.h +++ b/src/mongo/s/catalog/replset/catalog_manager_replica_set_test_fixture.h @@ -40,6 +40,7 @@ namespace mongo { class BSONObj; class CatalogManagerReplicaSet; class DistLockManagerMock; +class NamespaceString; class RemoteCommandTargeterFactoryMock; class RemoteCommandTargeterMock; class ShardRegistry; @@ -107,7 +108,7 @@ protected: * Wait for a single insert request and ensures that the items being inserted exactly match the * expected items. Responds with a success status. */ - void expectInserts(const NamespaceString nss, const std::vector<BSONObj>& expected); + void expectInserts(const NamespaceString& nss, const std::vector<BSONObj>& expected); /** * Waits for a count command and returns a response reporting the given number of documents |