summaryrefslogtreecommitdiff
path: root/src/mongo/unittest
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2016-03-07 10:08:43 -0500
committerBenety Goh <benety@mongodb.com>2016-03-10 20:30:43 -0500
commit690e2b3cd215f2d9355451aadc8608e5b3026128 (patch)
tree94aa6a4b25e528fc39abe59899098a14e12f688f /src/mongo/unittest
parenteaef6254d3bcb27657de670ec1b9c797965e7c82 (diff)
downloadmongo-690e2b3cd215f2d9355451aadc8608e5b3026128.tar.gz
SERVER-18029 extended Reporter to support keep alive and downconversion for pre-3.2.4.servers.
Diffstat (limited to 'src/mongo/unittest')
-rw-r--r--src/mongo/unittest/SConscript10
-rw-r--r--src/mongo/unittest/task_executor_proxy.cpp113
-rw-r--r--src/mongo/unittest/task_executor_proxy.h77
3 files changed, 200 insertions, 0 deletions
diff --git a/src/mongo/unittest/SConscript b/src/mongo/unittest/SConscript
index dddde95a386..b28e6a00e71 100644
--- a/src/mongo/unittest/SConscript
+++ b/src/mongo/unittest/SConscript
@@ -47,3 +47,13 @@ env.Library(
'$BUILD_DIR/mongo/base',
],
)
+
+env.Library(
+ target='task_executor_proxy',
+ source=[
+ 'task_executor_proxy.cpp',
+ ],
+ LIBDEPS=[
+ '$BUILD_DIR/mongo/executor/task_executor_interface',
+ ],
+)
diff --git a/src/mongo/unittest/task_executor_proxy.cpp b/src/mongo/unittest/task_executor_proxy.cpp
new file mode 100644
index 00000000000..0168e0a752d
--- /dev/null
+++ b/src/mongo/unittest/task_executor_proxy.cpp
@@ -0,0 +1,113 @@
+/**
+ * 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/unittest/task_executor_proxy.h"
+
+namespace mongo {
+namespace unittest {
+
+TaskExecutorProxy::TaskExecutorProxy(executor::TaskExecutor* executor) : _executor(executor) {}
+
+TaskExecutorProxy::~TaskExecutorProxy() = default;
+
+executor::TaskExecutor* TaskExecutorProxy::getExecutor() const {
+ return _executor;
+}
+
+void TaskExecutorProxy::setExecutor(executor::TaskExecutor* executor) {
+ _executor = executor;
+}
+
+void TaskExecutorProxy::startup() {
+ _executor->startup();
+}
+
+void TaskExecutorProxy::shutdown() {
+ _executor->shutdown();
+}
+
+void TaskExecutorProxy::join() {
+ _executor->join();
+}
+
+std::string TaskExecutorProxy::getDiagnosticString() {
+ return _executor->getDiagnosticString();
+}
+
+Date_t TaskExecutorProxy::now() {
+ return _executor->now();
+}
+
+StatusWith<executor::TaskExecutor::EventHandle> TaskExecutorProxy::makeEvent() {
+ return _executor->makeEvent();
+}
+
+void TaskExecutorProxy::signalEvent(const EventHandle& event) {
+ _executor->signalEvent(event);
+}
+
+StatusWith<executor::TaskExecutor::CallbackHandle> TaskExecutorProxy::onEvent(
+ const EventHandle& event, const CallbackFn& work) {
+ return _executor->onEvent(event, work);
+}
+
+void TaskExecutorProxy::waitForEvent(const EventHandle& event) {
+ _executor->waitForEvent(event);
+}
+
+StatusWith<executor::TaskExecutor::CallbackHandle> TaskExecutorProxy::scheduleWork(
+ const CallbackFn& work) {
+ return _executor->scheduleWork(work);
+}
+
+StatusWith<executor::TaskExecutor::CallbackHandle> TaskExecutorProxy::scheduleWorkAt(
+ Date_t when, const CallbackFn& work) {
+ return _executor->scheduleWorkAt(when, work);
+}
+
+StatusWith<executor::TaskExecutor::CallbackHandle> TaskExecutorProxy::scheduleRemoteCommand(
+ const executor::RemoteCommandRequest& request, const RemoteCommandCallbackFn& cb) {
+ return _executor->scheduleRemoteCommand(request, cb);
+}
+
+void TaskExecutorProxy::cancel(const CallbackHandle& cbHandle) {
+ _executor->cancel(cbHandle);
+}
+
+void TaskExecutorProxy::wait(const CallbackHandle& cbHandle) {
+ _executor->wait(cbHandle);
+}
+
+void TaskExecutorProxy::appendConnectionStats(executor::ConnectionPoolStats* stats) const {
+ _executor->appendConnectionStats(stats);
+}
+
+} // namespace unittest
+} // namespace mongo
diff --git a/src/mongo/unittest/task_executor_proxy.h b/src/mongo/unittest/task_executor_proxy.h
new file mode 100644
index 00000000000..f5c9ee63013
--- /dev/null
+++ b/src/mongo/unittest/task_executor_proxy.h
@@ -0,0 +1,77 @@
+/**
+ * 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.
+ */
+
+#pragma once
+
+#include "mongo/base/disallow_copying.h"
+#include "mongo/executor/task_executor.h"
+
+namespace mongo {
+namespace unittest {
+
+/**
+ * Proxy for the executor::TaskExecutor interface used for testing.
+ */
+class TaskExecutorProxy : public executor::TaskExecutor {
+ MONGO_DISALLOW_COPYING(TaskExecutorProxy);
+
+public:
+ /**
+ * Does not own target executor.
+ */
+ TaskExecutorProxy(executor::TaskExecutor* executor);
+ virtual ~TaskExecutorProxy();
+
+ executor::TaskExecutor* getExecutor() const;
+ void setExecutor(executor::TaskExecutor* executor);
+
+ virtual void startup() override;
+ virtual void shutdown() override;
+ virtual void join() override;
+ virtual std::string getDiagnosticString() override;
+ virtual Date_t now() override;
+ virtual StatusWith<EventHandle> makeEvent() override;
+ virtual void signalEvent(const EventHandle& event) override;
+ virtual StatusWith<CallbackHandle> onEvent(const EventHandle& event,
+ const CallbackFn& work) override;
+ virtual void waitForEvent(const EventHandle& event) override;
+ virtual StatusWith<CallbackHandle> scheduleWork(const CallbackFn& work) override;
+ virtual StatusWith<CallbackHandle> scheduleWorkAt(Date_t when, const CallbackFn& work) override;
+ virtual StatusWith<CallbackHandle> scheduleRemoteCommand(
+ const executor::RemoteCommandRequest& request, const RemoteCommandCallbackFn& cb) override;
+ virtual void cancel(const CallbackHandle& cbHandle) override;
+ virtual void wait(const CallbackHandle& cbHandle) override;
+ virtual void appendConnectionStats(executor::ConnectionPoolStats* stats) const override;
+
+private:
+ // Not owned by us.
+ executor::TaskExecutor* _executor;
+};
+
+} // namespace unittest
+} // namespace mongo