Moved `MockSlave` into a separate header/implementation file.

Review: https://reviews.apache.org/r/51148/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/686de9b0
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/686de9b0
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/686de9b0

Branch: refs/heads/master
Commit: 686de9b0a727b7db03d5b136132b44218ada58df
Parents: 97c7855
Author: Neil Conway <neil.con...@gmail.com>
Authored: Tue Sep 13 19:17:21 2016 +0200
Committer: Michael Park <mp...@apache.org>
Committed: Thu Sep 15 01:24:05 2016 +0200

----------------------------------------------------------------------
 src/Makefile.am                                 |   2 +
 .../containerizer/cgroups_isolator_tests.cpp    |   1 +
 src/tests/mesos.cpp                             | 163 --------------
 src/tests/mesos.hpp                             | 149 -------------
 src/tests/mock_slave.cpp                        | 213 +++++++++++++++++++
 src/tests/mock_slave.hpp                        | 199 +++++++++++++++++
 src/tests/oversubscription_tests.cpp            |   1 +
 src/tests/persistent_volume_tests.cpp           |   1 +
 src/tests/reservation_tests.cpp                 |   1 +
 src/tests/slave_tests.cpp                       |   1 +
 10 files changed, 419 insertions(+), 312 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/686de9b0/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index 1a9210d..f1d202a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -989,6 +989,7 @@ libmesos_no_3rdparty_la_SOURCES +=                          
        \
   tests/limiter.hpp                                                    \
   tests/mesos.hpp                                                      \
   tests/mock_docker.hpp                                                        
\
+  tests/mock_slave.hpp                                                 \
   tests/module.hpp                                                     \
   tests/script.hpp                                                     \
   tests/utils.hpp                                                      \
@@ -2097,6 +2098,7 @@ mesos_tests_SOURCES =                                     
        \
   tests/mesos.cpp                                              \
   tests/metrics_tests.cpp                                      \
   tests/mock_docker.cpp                                                \
+  tests/mock_slave.cpp                                         \
   tests/module.cpp                                             \
   tests/module_tests.cpp                                       \
   tests/oversubscription_tests.cpp                             \

http://git-wip-us.apache.org/repos/asf/mesos/blob/686de9b0/src/tests/containerizer/cgroups_isolator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/cgroups_isolator_tests.cpp 
b/src/tests/containerizer/cgroups_isolator_tests.cpp
index 31c95c8..25ff910 100644
--- a/src/tests/containerizer/cgroups_isolator_tests.cpp
+++ b/src/tests/containerizer/cgroups_isolator_tests.cpp
@@ -27,6 +27,7 @@
 #include "slave/containerizer/mesos/isolators/cgroups/subsystems/net_cls.hpp"
 
 #include "tests/mesos.hpp"
+#include "tests/mock_slave.hpp"
 #include "tests/script.hpp"
 
 #include "tests/containerizer/docker_archive.hpp"

http://git-wip-us.apache.org/repos/asf/mesos/blob/686de9b0/src/tests/mesos.cpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.cpp b/src/tests/mesos.cpp
index 3d8f16a..07a64f0 100644
--- a/src/tests/mesos.cpp
+++ b/src/tests/mesos.cpp
@@ -464,169 +464,6 @@ MockExecutor::MockExecutor(const ExecutorID& _id) : 
id(_id) {}
 MockExecutor::~MockExecutor() {}
 
 
-MockGarbageCollector::MockGarbageCollector()
-{
-  // NOTE: We use 'EXPECT_CALL' and 'WillRepeatedly' here instead of
-  // 'ON_CALL' and 'WillByDefault'. See 'TestContainerizer::SetUp()'
-  // for more details.
-  EXPECT_CALL(*this, schedule(_, _))
-    .WillRepeatedly(Return(Nothing()));
-
-  EXPECT_CALL(*this, unschedule(_))
-    .WillRepeatedly(Return(true));
-
-  EXPECT_CALL(*this, prune(_))
-    .WillRepeatedly(Return());
-}
-
-
-MockGarbageCollector::~MockGarbageCollector() {}
-
-
-MockResourceEstimator::MockResourceEstimator()
-{
-  ON_CALL(*this, initialize(_))
-    .WillByDefault(Return(Nothing()));
-  EXPECT_CALL(*this, initialize(_))
-    .WillRepeatedly(DoDefault());
-
-  ON_CALL(*this, oversubscribable())
-    .WillByDefault(Return(Future<Resources>()));
-  EXPECT_CALL(*this, oversubscribable())
-    .WillRepeatedly(DoDefault());
-}
-
-MockResourceEstimator::~MockResourceEstimator() {}
-
-
-MockQoSController::MockQoSController()
-{
-  ON_CALL(*this, initialize(_))
-    .WillByDefault(Return(Nothing()));
-  EXPECT_CALL(*this, initialize(_))
-    .WillRepeatedly(DoDefault());
-
-  ON_CALL(*this, corrections())
-    .WillByDefault(
-        Return(Future<list<mesos::slave::QoSCorrection>>()));
-  EXPECT_CALL(*this, corrections())
-    .WillRepeatedly(DoDefault());
-}
-
-
-MockQoSController::~MockQoSController() {}
-
-
-MockSlave::MockSlave(
-    const slave::Flags& flags,
-    MasterDetector* detector,
-    slave::Containerizer* containerizer,
-    const Option<mesos::slave::QoSController*>& _qosController,
-    const Option<mesos::Authorizer*>& authorizer)
-  : slave::Slave(
-        process::ID::generate("slave"),
-        flags,
-        detector,
-        containerizer,
-        &files,
-        &gc,
-        statusUpdateManager = new slave::StatusUpdateManager(flags),
-        &resourceEstimator,
-        _qosController.isSome() ? _qosController.get() : &qosController,
-        authorizer),
-    files(slave::READONLY_HTTP_AUTHENTICATION_REALM)
-{
-  // Set up default behaviors, calling the original methods.
-  EXPECT_CALL(*this, runTask(_, _, _, _, _))
-    .WillRepeatedly(Invoke(this, &MockSlave::unmocked_runTask));
-  EXPECT_CALL(*this, _run(_, _, _, _, _))
-    .WillRepeatedly(Invoke(this, &MockSlave::unmocked__run));
-  EXPECT_CALL(*this, runTaskGroup(_, _, _, _))
-    .WillRepeatedly(Invoke(this, &MockSlave::unmocked_runTaskGroup));
-  EXPECT_CALL(*this, killTask(_, _))
-    .WillRepeatedly(Invoke(this, &MockSlave::unmocked_killTask));
-  EXPECT_CALL(*this, removeFramework(_))
-    .WillRepeatedly(Invoke(this, &MockSlave::unmocked_removeFramework));
-  EXPECT_CALL(*this, __recover(_))
-    .WillRepeatedly(Invoke(this, &MockSlave::unmocked___recover));
-  EXPECT_CALL(*this, qosCorrections())
-    .WillRepeatedly(Invoke(this, &MockSlave::unmocked_qosCorrections));
-  EXPECT_CALL(*this, usage())
-    .WillRepeatedly(Invoke(this, &MockSlave::unmocked_usage));
-}
-
-
-MockSlave::~MockSlave()
-{
-  delete statusUpdateManager;
-}
-
-
-void MockSlave::unmocked_runTask(
-    const UPID& from,
-    const FrameworkInfo& frameworkInfo,
-    const FrameworkID& frameworkId,
-    const UPID& pid,
-    const TaskInfo& task)
-{
-  slave::Slave::runTask(from, frameworkInfo, frameworkInfo.id(), pid, task);
-}
-
-
-void MockSlave::unmocked__run(
-    const Future<bool>& future,
-    const FrameworkInfo& frameworkInfo,
-    const ExecutorInfo& executorInfo,
-    const Option<TaskInfo>& taskInfo,
-    const Option<TaskGroupInfo>& taskGroup)
-{
-  slave::Slave::_run(
-      future, frameworkInfo, executorInfo, taskInfo, taskGroup);
-}
-
-
-void MockSlave::unmocked_runTaskGroup(
-    const UPID& from,
-    const FrameworkInfo& frameworkInfo,
-    const ExecutorInfo& executorInfo,
-    const TaskGroupInfo& taskGroup)
-{
-  slave::Slave::runTaskGroup(from, frameworkInfo, executorInfo, taskGroup);
-}
-
-
-void MockSlave::unmocked_killTask(
-    const UPID& from,
-    const KillTaskMessage& killTaskMessage)
-{
-  slave::Slave::killTask(from, killTaskMessage);
-}
-
-
-void MockSlave::unmocked_removeFramework(slave::Framework* framework)
-{
-  slave::Slave::removeFramework(framework);
-}
-
-
-void MockSlave::unmocked___recover(const Future<Nothing>& future)
-{
-  slave::Slave::__recover(future);
-}
-
-
-void MockSlave::unmocked_qosCorrections()
-{
-  slave::Slave::qosCorrections();
-}
-
-
-Future<ResourceUsage> MockSlave::unmocked_usage()
-{
-  return slave::Slave::usage();
-}
-
-
 MockFetcherProcess::MockFetcherProcess()
 {
   // Set up default behaviors, calling the original methods.

http://git-wip-us.apache.org/repos/asf/mesos/blob/686de9b0/src/tests/mesos.hpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.hpp b/src/tests/mesos.hpp
index 8471b92..fa6789b 100644
--- a/src/tests/mesos.hpp
+++ b/src/tests/mesos.hpp
@@ -39,9 +39,6 @@
 
 #include <mesos/master/detector.hpp>
 
-#include <mesos/slave/qos_controller.hpp>
-#include <mesos/slave/resource_estimator.hpp>
-
 #include <process/future.hpp>
 #include <process/gmock.hpp>
 #include <process/gtest.hpp>
@@ -1284,152 +1281,6 @@ using MockV1HTTPExecutor =
     mesos::v1::executor::Mesos, mesos::v1::executor::Event>;
 
 
-class MockGarbageCollector : public slave::GarbageCollector
-{
-public:
-  MockGarbageCollector();
-  virtual ~MockGarbageCollector();
-
-  MOCK_METHOD2(
-      schedule,
-      process::Future<Nothing>(const Duration& d, const std::string& path));
-  MOCK_METHOD1(
-      unschedule,
-      process::Future<bool>(const std::string& path));
-  MOCK_METHOD1(
-      prune,
-      void(const Duration& d));
-};
-
-
-class MockResourceEstimator : public mesos::slave::ResourceEstimator
-{
-public:
-  MockResourceEstimator();
-  virtual ~MockResourceEstimator();
-
-  MOCK_METHOD1(
-      initialize,
-      Try<Nothing>(const lambda::function<process::Future<ResourceUsage>()>&));
-
-  MOCK_METHOD0(
-      oversubscribable,
-      process::Future<Resources>());
-};
-
-
-// The MockQoSController is a stub which lets tests fill the
-// correction queue for a slave.
-class MockQoSController : public mesos::slave::QoSController
-{
-public:
-  MockQoSController();
-  virtual ~MockQoSController();
-
-  MOCK_METHOD1(
-      initialize,
-      Try<Nothing>(const lambda::function<process::Future<ResourceUsage>()>&));
-
-  MOCK_METHOD0(
-      corrections, process::Future<std::list<mesos::slave::QoSCorrection>>());
-};
-
-
-// Definition of a mock Slave to be used in tests with gmock, covering
-// potential races between runTask and killTask.
-class MockSlave : public slave::Slave
-{
-public:
-  MockSlave(
-      const slave::Flags& flags,
-      mesos::master::detector::MasterDetector* detector,
-      slave::Containerizer* containerizer,
-      const Option<mesos::slave::QoSController*>& qosController = None(),
-      const Option<mesos::Authorizer*>& authorizer = None());
-
-  virtual ~MockSlave();
-
-  MOCK_METHOD5(runTask, void(
-      const process::UPID& from,
-      const FrameworkInfo& frameworkInfo,
-      const FrameworkID& frameworkId,
-      const process::UPID& pid,
-      const TaskInfo& task));
-
-  void unmocked_runTask(
-      const process::UPID& from,
-      const FrameworkInfo& frameworkInfo,
-      const FrameworkID& frameworkId,
-      const process::UPID& pid,
-      const TaskInfo& task);
-
-  MOCK_METHOD5(_run, void(
-      const process::Future<bool>& future,
-      const FrameworkInfo& frameworkInfo,
-      const ExecutorInfo& executorInfo,
-      const Option<TaskInfo>& task,
-      const Option<TaskGroupInfo>& taskGroup));
-
-  void unmocked__run(
-      const process::Future<bool>& future,
-      const FrameworkInfo& frameworkInfo,
-      const ExecutorInfo& executorInfo,
-      const Option<TaskInfo>& task,
-      const Option<TaskGroupInfo>& taskGroup);
-
-  MOCK_METHOD4(runTaskGroup, void(
-      const process::UPID& from,
-      const FrameworkInfo& frameworkInfo,
-      const ExecutorInfo& executorInfo,
-      const TaskGroupInfo& taskGroup));
-
-  void unmocked_runTaskGroup(
-      const process::UPID& from,
-      const FrameworkInfo& frameworkInfo,
-      const ExecutorInfo& executorInfo,
-      const TaskGroupInfo& taskGroup);
-
-  MOCK_METHOD2(killTask, void(
-      const process::UPID& from,
-      const KillTaskMessage& killTaskMessage));
-
-  void unmocked_killTask(
-      const process::UPID& from,
-      const KillTaskMessage& killTaskMessage);
-
-  MOCK_METHOD1(removeFramework, void(
-      slave::Framework* framework));
-
-  void unmocked_removeFramework(
-      slave::Framework* framework);
-
-  MOCK_METHOD1(__recover, void(
-      const process::Future<Nothing>& future));
-
-  void unmocked___recover(
-      const process::Future<Nothing>& future);
-
-  MOCK_METHOD0(qosCorrections, void());
-
-  void unmocked_qosCorrections();
-
-  MOCK_METHOD1(_qosCorrections, void(
-      const process::Future<std::list<
-          mesos::slave::QoSCorrection>>& correction));
-
-  MOCK_METHOD0(usage, process::Future<ResourceUsage>());
-
-  process::Future<ResourceUsage> unmocked_usage();
-
-private:
-  Files files;
-  MockGarbageCollector gc;
-  MockResourceEstimator resourceEstimator;
-  MockQoSController qosController;
-  slave::StatusUpdateManager* statusUpdateManager;
-};
-
-
 // Definition of a mock FetcherProcess to be used in tests with gmock.
 class MockFetcherProcess : public slave::FetcherProcess
 {

http://git-wip-us.apache.org/repos/asf/mesos/blob/686de9b0/src/tests/mock_slave.cpp
----------------------------------------------------------------------
diff --git a/src/tests/mock_slave.cpp b/src/tests/mock_slave.cpp
new file mode 100644
index 0000000..50c04bf
--- /dev/null
+++ b/src/tests/mock_slave.cpp
@@ -0,0 +1,213 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <list>
+
+#include <gmock/gmock.h>
+
+#include <mesos/slave/qos_controller.hpp>
+#include <mesos/slave/resource_estimator.hpp>
+
+#include <process/future.hpp>
+#include <process/pid.hpp>
+
+#include <stout/option.hpp>
+
+#include "slave/slave.hpp"
+#include "slave/status_update_manager.hpp"
+
+#include "tests/mock_slave.hpp"
+
+using mesos::master::detector::MasterDetector;
+
+using std::list;
+
+using process::Future;
+using process::UPID;
+
+using testing::_;
+using testing::Invoke;
+
+namespace mesos {
+namespace internal {
+namespace tests {
+
+MockGarbageCollector::MockGarbageCollector()
+{
+  // NOTE: We use 'EXPECT_CALL' and 'WillRepeatedly' here instead of
+  // 'ON_CALL' and 'WillByDefault'. See 'TestContainerizer::SetUp()'
+  // for more details.
+  EXPECT_CALL(*this, schedule(_, _))
+    .WillRepeatedly(Return(Nothing()));
+
+  EXPECT_CALL(*this, unschedule(_))
+    .WillRepeatedly(Return(true));
+
+  EXPECT_CALL(*this, prune(_))
+    .WillRepeatedly(Return());
+}
+
+
+MockGarbageCollector::~MockGarbageCollector() {}
+
+
+MockResourceEstimator::MockResourceEstimator()
+{
+  ON_CALL(*this, initialize(_))
+    .WillByDefault(Return(Nothing()));
+  EXPECT_CALL(*this, initialize(_))
+    .WillRepeatedly(DoDefault());
+
+  ON_CALL(*this, oversubscribable())
+    .WillByDefault(Return(Future<Resources>()));
+  EXPECT_CALL(*this, oversubscribable())
+    .WillRepeatedly(DoDefault());
+}
+
+
+MockResourceEstimator::~MockResourceEstimator() {}
+
+
+MockQoSController::MockQoSController()
+{
+  ON_CALL(*this, initialize(_))
+    .WillByDefault(Return(Nothing()));
+  EXPECT_CALL(*this, initialize(_))
+    .WillRepeatedly(DoDefault());
+
+  ON_CALL(*this, corrections())
+    .WillByDefault(
+        Return(Future<list<mesos::slave::QoSCorrection>>()));
+  EXPECT_CALL(*this, corrections())
+    .WillRepeatedly(DoDefault());
+}
+
+
+MockQoSController::~MockQoSController() {}
+
+
+MockSlave::MockSlave(
+    const slave::Flags& flags,
+    MasterDetector* detector,
+    slave::Containerizer* containerizer,
+    const Option<mesos::slave::QoSController*>& _qosController,
+    const Option<mesos::Authorizer*>& authorizer)
+  : slave::Slave(
+        process::ID::generate("slave"),
+        flags,
+        detector,
+        containerizer,
+        &files,
+        &gc,
+        statusUpdateManager = new slave::StatusUpdateManager(flags),
+        &resourceEstimator,
+        _qosController.isSome() ? _qosController.get() : &qosController,
+        authorizer),
+    files(slave::READONLY_HTTP_AUTHENTICATION_REALM)
+{
+  // Set up default behaviors, calling the original methods.
+  EXPECT_CALL(*this, runTask(_, _, _, _, _))
+    .WillRepeatedly(Invoke(this, &MockSlave::unmocked_runTask));
+  EXPECT_CALL(*this, _run(_, _, _, _, _))
+    .WillRepeatedly(Invoke(this, &MockSlave::unmocked__run));
+  EXPECT_CALL(*this, runTaskGroup(_, _, _, _))
+    .WillRepeatedly(Invoke(this, &MockSlave::unmocked_runTaskGroup));
+  EXPECT_CALL(*this, killTask(_, _))
+    .WillRepeatedly(Invoke(this, &MockSlave::unmocked_killTask));
+  EXPECT_CALL(*this, removeFramework(_))
+    .WillRepeatedly(Invoke(this, &MockSlave::unmocked_removeFramework));
+  EXPECT_CALL(*this, __recover(_))
+    .WillRepeatedly(Invoke(this, &MockSlave::unmocked___recover));
+  EXPECT_CALL(*this, qosCorrections())
+    .WillRepeatedly(Invoke(this, &MockSlave::unmocked_qosCorrections));
+  EXPECT_CALL(*this, usage())
+    .WillRepeatedly(Invoke(this, &MockSlave::unmocked_usage));
+}
+
+
+MockSlave::~MockSlave()
+{
+  delete statusUpdateManager;
+}
+
+
+void MockSlave::unmocked_runTask(
+    const UPID& from,
+    const FrameworkInfo& frameworkInfo,
+    const FrameworkID& frameworkId,
+    const UPID& pid,
+    const TaskInfo& task)
+{
+  slave::Slave::runTask(from, frameworkInfo, frameworkInfo.id(), pid, task);
+}
+
+
+void MockSlave::unmocked__run(
+    const Future<bool>& future,
+    const FrameworkInfo& frameworkInfo,
+    const ExecutorInfo& executorInfo,
+    const Option<TaskInfo>& taskInfo,
+    const Option<TaskGroupInfo>& taskGroup)
+{
+  slave::Slave::_run(
+      future, frameworkInfo, executorInfo, taskInfo, taskGroup);
+}
+
+
+void MockSlave::unmocked_runTaskGroup(
+    const UPID& from,
+    const FrameworkInfo& frameworkInfo,
+    const ExecutorInfo& executorInfo,
+    const TaskGroupInfo& taskGroup)
+{
+  slave::Slave::runTaskGroup(from, frameworkInfo, executorInfo, taskGroup);
+}
+
+
+void MockSlave::unmocked_killTask(
+    const UPID& from,
+    const KillTaskMessage& killTaskMessage)
+{
+  slave::Slave::killTask(from, killTaskMessage);
+}
+
+
+void MockSlave::unmocked_removeFramework(slave::Framework* framework)
+{
+  slave::Slave::removeFramework(framework);
+}
+
+
+void MockSlave::unmocked___recover(const Future<Nothing>& future)
+{
+  slave::Slave::__recover(future);
+}
+
+
+void MockSlave::unmocked_qosCorrections()
+{
+  slave::Slave::qosCorrections();
+}
+
+
+Future<ResourceUsage> MockSlave::unmocked_usage()
+{
+  return slave::Slave::usage();
+}
+
+} // namespace tests {
+} // namespace internal {
+} // namespace mesos {

http://git-wip-us.apache.org/repos/asf/mesos/blob/686de9b0/src/tests/mock_slave.hpp
----------------------------------------------------------------------
diff --git a/src/tests/mock_slave.hpp b/src/tests/mock_slave.hpp
new file mode 100644
index 0000000..53e1c9e
--- /dev/null
+++ b/src/tests/mock_slave.hpp
@@ -0,0 +1,199 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef __TESTS_MOCKSLAVE_HPP__
+#define __TESTS_MOCKSLAVE_HPP__
+
+#include <list>
+#include <string>
+
+#include <gmock/gmock.h>
+
+#include <mesos/master/detector.hpp>
+
+#include <mesos/slave/qos_controller.hpp>
+#include <mesos/slave/resource_estimator.hpp>
+
+#include <process/future.hpp>
+#include <process/pid.hpp>
+
+#include <stout/duration.hpp>
+#include <stout/none.hpp>
+#include <stout/option.hpp>
+#include <stout/try.hpp>
+
+#include "messages/messages.hpp"
+
+#include "slave/slave.hpp"
+
+using ::testing::_;
+using ::testing::DoDefault;
+using ::testing::Return;
+
+namespace mesos {
+namespace internal {
+namespace tests {
+
+class MockGarbageCollector : public slave::GarbageCollector
+{
+public:
+  MockGarbageCollector();
+  virtual ~MockGarbageCollector();
+
+  MOCK_METHOD2(
+      schedule,
+      process::Future<Nothing>(const Duration& d, const std::string& path));
+  MOCK_METHOD1(
+      unschedule,
+      process::Future<bool>(const std::string& path));
+  MOCK_METHOD1(
+      prune,
+      void(const Duration& d));
+};
+
+
+class MockResourceEstimator : public mesos::slave::ResourceEstimator
+{
+public:
+  MockResourceEstimator();
+  virtual ~MockResourceEstimator();
+
+  MOCK_METHOD1(
+      initialize,
+      Try<Nothing>(const lambda::function<process::Future<ResourceUsage>()>&));
+
+  MOCK_METHOD0(
+      oversubscribable,
+      process::Future<Resources>());
+};
+
+
+// The MockQoSController is a stub which lets tests fill the
+// correction queue for a slave.
+class MockQoSController : public mesos::slave::QoSController
+{
+public:
+  MockQoSController();
+  virtual ~MockQoSController();
+
+  MOCK_METHOD1(
+      initialize,
+      Try<Nothing>(const lambda::function<process::Future<ResourceUsage>()>&));
+
+  MOCK_METHOD0(
+      corrections, process::Future<std::list<mesos::slave::QoSCorrection>>());
+};
+
+
+// Definition of a mock Slave to be used in tests with gmock, covering
+// potential races between runTask and killTask.
+class MockSlave : public slave::Slave
+{
+public:
+  MockSlave(
+      const slave::Flags& flags,
+      mesos::master::detector::MasterDetector* detector,
+      slave::Containerizer* containerizer,
+      const Option<mesos::slave::QoSController*>& qosController = None(),
+      const Option<mesos::Authorizer*>& authorizer = None());
+
+  virtual ~MockSlave();
+
+  MOCK_METHOD5(runTask, void(
+      const process::UPID& from,
+      const FrameworkInfo& frameworkInfo,
+      const FrameworkID& frameworkId,
+      const process::UPID& pid,
+      const TaskInfo& task));
+
+  void unmocked_runTask(
+      const process::UPID& from,
+      const FrameworkInfo& frameworkInfo,
+      const FrameworkID& frameworkId,
+      const process::UPID& pid,
+      const TaskInfo& task);
+
+  MOCK_METHOD5(_run, void(
+      const process::Future<bool>& future,
+      const FrameworkInfo& frameworkInfo,
+      const ExecutorInfo& executorInfo,
+      const Option<TaskInfo>& task,
+      const Option<TaskGroupInfo>& taskGroup));
+
+  void unmocked__run(
+      const process::Future<bool>& future,
+      const FrameworkInfo& frameworkInfo,
+      const ExecutorInfo& executorInfo,
+      const Option<TaskInfo>& task,
+      const Option<TaskGroupInfo>& taskGroup);
+
+  MOCK_METHOD4(runTaskGroup, void(
+      const process::UPID& from,
+      const FrameworkInfo& frameworkInfo,
+      const ExecutorInfo& executorInfo,
+      const TaskGroupInfo& taskGroup));
+
+  void unmocked_runTaskGroup(
+      const process::UPID& from,
+      const FrameworkInfo& frameworkInfo,
+      const ExecutorInfo& executorInfo,
+      const TaskGroupInfo& taskGroup);
+
+  MOCK_METHOD2(killTask, void(
+      const process::UPID& from,
+      const KillTaskMessage& killTaskMessage));
+
+  void unmocked_killTask(
+      const process::UPID& from,
+      const KillTaskMessage& killTaskMessage);
+
+  MOCK_METHOD1(removeFramework, void(
+      slave::Framework* framework));
+
+  void unmocked_removeFramework(
+      slave::Framework* framework);
+
+  MOCK_METHOD1(__recover, void(
+      const process::Future<Nothing>& future));
+
+  void unmocked___recover(
+      const process::Future<Nothing>& future);
+
+  MOCK_METHOD0(qosCorrections, void());
+
+  void unmocked_qosCorrections();
+
+  MOCK_METHOD1(_qosCorrections, void(
+      const process::Future<std::list<
+          mesos::slave::QoSCorrection>>& correction));
+
+  MOCK_METHOD0(usage, process::Future<ResourceUsage>());
+
+  process::Future<ResourceUsage> unmocked_usage();
+
+private:
+  Files files;
+  MockGarbageCollector gc;
+  MockResourceEstimator resourceEstimator;
+  MockQoSController qosController;
+  slave::StatusUpdateManager* statusUpdateManager;
+};
+
+} // namespace tests {
+} // namespace internal {
+} // namespace mesos {
+
+#endif // __TESTS_MOCKSLAVE_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/686de9b0/src/tests/oversubscription_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/oversubscription_tests.cpp 
b/src/tests/oversubscription_tests.cpp
index 18da40e..3dd34ea 100644
--- a/src/tests/oversubscription_tests.cpp
+++ b/src/tests/oversubscription_tests.cpp
@@ -49,6 +49,7 @@
 #include "tests/flags.hpp"
 #include "tests/containerizer.hpp"
 #include "tests/mesos.hpp"
+#include "tests/mock_slave.hpp"
 #include "tests/utils.hpp"
 
 using namespace process;

http://git-wip-us.apache.org/repos/asf/mesos/blob/686de9b0/src/tests/persistent_volume_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/persistent_volume_tests.cpp 
b/src/tests/persistent_volume_tests.cpp
index d07ff1f..c38d848 100644
--- a/src/tests/persistent_volume_tests.cpp
+++ b/src/tests/persistent_volume_tests.cpp
@@ -53,6 +53,7 @@
 #include "tests/containerizer.hpp"
 #include "tests/environment.hpp"
 #include "tests/mesos.hpp"
+#include "tests/mock_slave.hpp"
 
 using namespace process;
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/686de9b0/src/tests/reservation_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/reservation_tests.cpp b/src/tests/reservation_tests.cpp
index 0009578..93e95a9 100644
--- a/src/tests/reservation_tests.cpp
+++ b/src/tests/reservation_tests.cpp
@@ -47,6 +47,7 @@
 #include "tests/allocator.hpp"
 #include "tests/containerizer.hpp"
 #include "tests/mesos.hpp"
+#include "tests/mock_slave.hpp"
 
 using mesos::internal::master::allocator::HierarchicalDRFAllocator;
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/686de9b0/src/tests/slave_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/slave_tests.cpp b/src/tests/slave_tests.cpp
index e8b7dc0..d82c34b 100644
--- a/src/tests/slave_tests.cpp
+++ b/src/tests/slave_tests.cpp
@@ -66,6 +66,7 @@
 #include "tests/flags.hpp"
 #include "tests/limiter.hpp"
 #include "tests/mesos.hpp"
+#include "tests/mock_slave.hpp"
 #include "tests/utils.hpp"
 
 using namespace mesos::internal::slave;

Reply via email to