[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mesos-commits
Subject:    mesos git commit: Moved definition of ctors and dtors for mock classes out of header file.
From:       joris () apache ! org
Date:       2015-11-25 17:17:55
Message-ID: 7af510c5afa04af28778e238f1c83e89 () git ! apache ! org
[Download RAW message or body]

Repository: mesos
Updated Branches:
  refs/heads/master c085b0a9f -> 23e996483


Moved definition of ctors and dtors for mock classes out of header file.

As discussed in MESOS-3827, this can improve compilation time of classes
that use GMock. On my system, this improves the compilation time of the
unit tests by about 8%.

Note that we can't use this technique with TestAllocator, because it is
templatized.

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


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

Branch: refs/heads/master
Commit: 23e996483a99323602292083fc52474a51f12a27
Parents: c085b0a
Author: Neil Conway <neil.conway@gmail.com>
Authored: Wed Nov 25 10:55:49 2015 -0500
Committer: Joris Van Remoortere <joris.van.remoortere@gmail.com>
Committed: Wed Nov 25 12:17:42 2015 -0500

----------------------------------------------------------------------
 src/Makefile.am                      |   1 +
 src/tests/containerizer/launcher.cpp |  72 ++++++++++++++
 src/tests/containerizer/launcher.hpp |  45 +--------
 src/tests/mesos.cpp                  | 153 ++++++++++++++++++++++++++++++
 src/tests/mesos.hpp                  | 116 +++++-----------------
 5 files changed, 251 insertions(+), 136 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/23e99648/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index a57e46d..de68e24 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1738,6 +1738,7 @@ mesos_tests_SOURCES =						\
   tests/containerizer/docker_tests.cpp				\
   tests/containerizer/external_containerizer_test.cpp		\
   tests/containerizer/isolator_tests.cpp			\
+  tests/containerizer/launcher.cpp				\
   tests/containerizer/memory_test_helper.cpp			\
   tests/containerizer/mesos_containerizer_tests.cpp		\
   tests/containerizer/provisioner_appc_tests.cpp		\

http://git-wip-us.apache.org/repos/asf/mesos/blob/23e99648/src/tests/containerizer/launcher.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/launcher.cpp b/src/tests/containerizer/launcher.cpp
new file mode 100644
index 0000000..22b44ba
--- /dev/null
+++ b/src/tests/containerizer/launcher.cpp
@@ -0,0 +1,72 @@
+/**
+ * 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 "tests/containerizer/launcher.hpp"
+
+namespace mesos {
+namespace internal {
+namespace tests {
+
+
+ACTION_P(InvokeRecover, launcher)
+{
+  return launcher->real->recover(arg0);
+}
+
+
+ACTION_P(InvokeFork, launcher)
+{
+  return launcher->real->fork(
+      arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
+}
+
+
+ACTION_P(InvokeDestroy, launcher)
+{
+  return launcher->real->destroy(arg0);
+}
+
+
+TestLauncher::TestLauncher(const process::Owned<slave::Launcher>& _real)
+  : real(_real)
+{
+  using testing::_;
+  using testing::DoDefault;
+
+  ON_CALL(*this, recover(_))
+    .WillByDefault(InvokeRecover(this));
+  EXPECT_CALL(*this, recover(_))
+    .WillRepeatedly(DoDefault());
+
+  ON_CALL(*this, fork(_, _, _, _, _, _, _, _, _, _))
+    .WillByDefault(InvokeFork(this));
+  EXPECT_CALL(*this, fork(_, _, _, _, _, _, _, _, _, _))
+    .WillRepeatedly(DoDefault());
+
+  ON_CALL(*this, destroy(_))
+    .WillByDefault(InvokeDestroy(this));
+  EXPECT_CALL(*this, destroy(_))
+    .WillRepeatedly(DoDefault());
+}
+
+
+TestLauncher::~TestLauncher() {}
+
+} // namespace tests {
+} // namespace internal {
+} // namespace mesos {

http://git-wip-us.apache.org/repos/asf/mesos/blob/23e99648/src/tests/containerizer/launcher.hpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/launcher.hpp b/src/tests/containerizer/launcher.hpp
index 09c4ba2..36405a9 100644
--- a/src/tests/containerizer/launcher.hpp
+++ b/src/tests/containerizer/launcher.hpp
@@ -44,51 +44,12 @@ namespace internal {
 namespace tests {
 
 
-ACTION_P(InvokeRecover, launcher)
-{
-  return launcher->real->recover(arg0);
-}
-
-
-ACTION_P(InvokeFork, launcher)
-{
-  return launcher->real->fork(
-      arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
-}
-
-
-ACTION_P(InvokeDestroy, launcher)
-{
-  return launcher->real->destroy(arg0);
-}
-
-
 class TestLauncher : public slave::Launcher
 {
 public:
-  TestLauncher(const process::Owned<slave::Launcher>& _real)
-    : real(_real)
-  {
-    using testing::_;
-    using testing::DoDefault;
-
-    ON_CALL(*this, recover(_))
-      .WillByDefault(InvokeRecover(this));
-    EXPECT_CALL(*this, recover(_))
-      .WillRepeatedly(DoDefault());
-
-    ON_CALL(*this, fork(_, _, _, _, _, _, _, _, _, _))
-      .WillByDefault(InvokeFork(this));
-    EXPECT_CALL(*this, fork(_, _, _, _, _, _, _, _, _, _))
-      .WillRepeatedly(DoDefault());
-
-    ON_CALL(*this, destroy(_))
-      .WillByDefault(InvokeDestroy(this));
-    EXPECT_CALL(*this, destroy(_))
-      .WillRepeatedly(DoDefault());
-  }
-
-  ~TestLauncher() {}
+  TestLauncher(const process::Owned<slave::Launcher>& _real);
+
+  ~TestLauncher();
 
   MOCK_METHOD1(
       recover,

http://git-wip-us.apache.org/repos/asf/mesos/blob/23e99648/src/tests/mesos.cpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.cpp b/src/tests/mesos.cpp
index b2211d5..a75182e 100644
--- a/src/tests/mesos.cpp
+++ b/src/tests/mesos.cpp
@@ -442,6 +442,74 @@ void MesosTest::ShutdownSlaves()
   containerizers.clear();
 }
 
+// Although the constructors and destructors for mock classes are
+// often trivial, defining them out-of-line (in a separate compilation
+// unit) improves compilation time: see MESOS-3827.
+
+MockScheduler::MockScheduler() {}
+
+
+MockScheduler::~MockScheduler() {}
+
+
+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(process::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(process::Future<std::list<mesos::slave::QoSCorrection>>()));
+  EXPECT_CALL(*this, corrections())
+    .WillRepeatedly(DoDefault());
+}
+
+
+MockQoSController::~MockQoSController() {}
+
 
 MockSlave::MockSlave(const slave::Flags& flags,
                      MasterDetector* detector,
@@ -537,6 +605,91 @@ MockFetcherProcess::MockFetcherProcess()
 }
 
 
+MockFetcherProcess::~MockFetcherProcess() {}
+
+
+MockDocker::MockDocker(
+    const std::string& path,
+    const std::string &socket)
+  : Docker(path, socket)
+{
+  EXPECT_CALL(*this, pull(_, _, _))
+    .WillRepeatedly(Invoke(this, &MockDocker::_pull));
+
+  EXPECT_CALL(*this, stop(_, _, _))
+    .WillRepeatedly(Invoke(this, &MockDocker::_stop));
+
+  EXPECT_CALL(*this, run(_, _, _, _, _, _, _, _, _))
+    .WillRepeatedly(Invoke(this, &MockDocker::_run));
+
+  EXPECT_CALL(*this, inspect(_, _))
+    .WillRepeatedly(Invoke(this, &MockDocker::_inspect));
+}
+
+
+MockDocker::~MockDocker() {}
+
+
+MockDockerContainerizer::MockDockerContainerizer(
+    const slave::Flags& flags,
+    slave::Fetcher* fetcher,
+    process::Shared<Docker> docker)
+  : slave::DockerContainerizer(flags, fetcher, docker)
+{
+  initialize();
+}
+
+
+MockDockerContainerizer::MockDockerContainerizer(
+    const process::Owned<slave::DockerContainerizerProcess>& process)
+  : slave::DockerContainerizer(process)
+{
+  initialize();
+}
+
+
+MockDockerContainerizer::~MockDockerContainerizer() {}
+
+
+MockDockerContainerizerProcess::MockDockerContainerizerProcess(
+    const slave::Flags& flags,
+    slave::Fetcher* fetcher,
+    const process::Shared<Docker>& docker)
+  : slave::DockerContainerizerProcess(flags, fetcher, docker)
+{
+  EXPECT_CALL(*this, fetch(_, _))
+    .WillRepeatedly(Invoke(this, &MockDockerContainerizerProcess::_fetch));
+
+  EXPECT_CALL(*this, pull(_))
+    .WillRepeatedly(Invoke(this, &MockDockerContainerizerProcess::_pull));
+}
+
+
+MockDockerContainerizerProcess::~MockDockerContainerizerProcess() {}
+
+
+MockAuthorizer::MockAuthorizer()
+{
+  // NOTE: We use 'EXPECT_CALL' and 'WillRepeatedly' here instead of
+  // 'ON_CALL' and 'WillByDefault'. See 'TestContainerizer::SetUp()'
+  // for more details.
+  EXPECT_CALL(*this, authorize(An<const mesos::ACL::RegisterFramework&>()))
+    .WillRepeatedly(Return(true));
+
+  EXPECT_CALL(*this, authorize(An<const mesos::ACL::RunTask&>()))
+    .WillRepeatedly(Return(true));
+
+  EXPECT_CALL(*this, authorize(An<const mesos::ACL::ShutdownFramework&>()))
+    .WillRepeatedly(Return(true));
+
+  EXPECT_CALL(*this, initialize(An<const Option<ACLs>&>()))
+    .WillRepeatedly(Return(Nothing()));
+}
+
+
+MockAuthorizer::~MockAuthorizer() {}
+
+
 process::Future<Nothing> MockFetcherProcess::unmocked__fetch(
   const hashmap<CommandInfo::URI, Option<Future<shared_ptr<Cache::Entry>>>>&
     entries,

http://git-wip-us.apache.org/repos/asf/mesos/blob/23e99648/src/tests/mesos.hpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.hpp b/src/tests/mesos.hpp
index a2a76f5..eabbf44 100644
--- a/src/tests/mesos.hpp
+++ b/src/tests/mesos.hpp
@@ -582,6 +582,9 @@ inline Offer::Operation LAUNCH(const std::vector<TaskInfo>& tasks)
 class MockScheduler : public Scheduler
 {
 public:
+  MockScheduler();
+  virtual ~MockScheduler();
+
   MOCK_METHOD3(registered, void(SchedulerDriver*,
                                 const FrameworkID&,
                                 const MasterInfo&));
@@ -679,7 +682,8 @@ ACTION_P(DeclineOffers, filters)
 class MockExecutor : public Executor
 {
 public:
-  MockExecutor(const ExecutorID& _id) : id(_id) {}
+  MockExecutor(const ExecutorID& _id);
+  virtual ~MockExecutor();
 
   MOCK_METHOD4(registered, void(ExecutorDriver*,
                                 const ExecutorInfo&,
@@ -759,20 +763,8 @@ public:
 class MockGarbageCollector : public slave::GarbageCollector
 {
 public:
-  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();
+  virtual ~MockGarbageCollector();
 
   MOCK_METHOD2(
       schedule,
@@ -789,20 +781,8 @@ public:
 class MockResourceEstimator : public mesos::slave::ResourceEstimator
 {
 public:
-  MockResourceEstimator()
-  {
-    ON_CALL(*this, initialize(_))
-      .WillByDefault(Return(Nothing()));
-    EXPECT_CALL(*this, initialize(_))
-      .WillRepeatedly(DoDefault());
-
-    ON_CALL(*this, oversubscribable())
-      .WillByDefault(Return(process::Future<Resources>()));
-    EXPECT_CALL(*this, oversubscribable())
-      .WillRepeatedly(DoDefault());
-  }
-
-  virtual ~MockResourceEstimator() {}
+  MockResourceEstimator();
+  virtual ~MockResourceEstimator();
 
   MOCK_METHOD1(
       initialize,
@@ -819,19 +799,8 @@ public:
 class MockQoSController : public mesos::slave::QoSController
 {
 public:
-  MockQoSController()
-  {
-    ON_CALL(*this, initialize(_))
-      .WillByDefault(Return(Nothing()));
-    EXPECT_CALL(*this, initialize(_))
-      .WillRepeatedly(DoDefault());
-
-    ON_CALL(*this, corrections())
-      .WillByDefault(
-          Return(process::Future<std::list<mesos::slave::QoSCorrection>>()));
-    EXPECT_CALL(*this, corrections())
-      .WillRepeatedly(DoDefault());
-  }
+  MockQoSController();
+  virtual ~MockQoSController();
 
   MOCK_METHOD1(
       initialize,
@@ -923,8 +892,7 @@ class MockFetcherProcess : public slave::FetcherProcess
 {
 public:
   MockFetcherProcess();
-
-  virtual ~MockFetcherProcess() {}
+  virtual ~MockFetcherProcess();
 
   MOCK_METHOD6(_fetch, process::Future<Nothing>(
       const hashmap<
@@ -970,21 +938,8 @@ class MockDocker : public Docker
 public:
   MockDocker(
       const std::string& path,
-      const std::string& socket)
-    : Docker(path, socket)
-  {
-    EXPECT_CALL(*this, pull(_, _, _))
-      .WillRepeatedly(Invoke(this, &MockDocker::_pull));
-
-    EXPECT_CALL(*this, stop(_, _, _))
-      .WillRepeatedly(Invoke(this, &MockDocker::_stop));
-
-    EXPECT_CALL(*this, run(_, _, _, _, _, _, _, _, _))
-      .WillRepeatedly(Invoke(this, &MockDocker::_run));
-
-    EXPECT_CALL(*this, inspect(_, _))
-      .WillRepeatedly(Invoke(this, &MockDocker::_inspect));
-  }
+      const std::string& socket);
+  virtual ~MockDocker();
 
   MOCK_CONST_METHOD9(
       run,
@@ -1073,18 +1028,12 @@ public:
   MockDockerContainerizer(
       const slave::Flags& flags,
       slave::Fetcher* fetcher,
-      process::Shared<Docker> docker)
-    : slave::DockerContainerizer(flags, fetcher, docker)
-  {
-    initialize();
-  }
+      process::Shared<Docker> docker);
 
   MockDockerContainerizer(
-      const process::Owned<slave::DockerContainerizerProcess>& process)
-    : slave::DockerContainerizer(process)
-  {
-    initialize();
-  }
+      const process::Owned<slave::DockerContainerizerProcess>& process);
+
+  virtual ~MockDockerContainerizer();
 
   void initialize()
   {
@@ -1191,15 +1140,9 @@ public:
   MockDockerContainerizerProcess(
       const slave::Flags& flags,
       slave::Fetcher* fetcher,
-      const process::Shared<Docker>& docker)
-    : slave::DockerContainerizerProcess(flags, fetcher, docker)
-  {
-    EXPECT_CALL(*this, fetch(_, _))
-      .WillRepeatedly(Invoke(this, &MockDockerContainerizerProcess::_fetch));
+      const process::Shared<Docker>& docker);
 
-    EXPECT_CALL(*this, pull(_))
-      .WillRepeatedly(Invoke(this, &MockDockerContainerizerProcess::_pull));
-  }
+  virtual ~MockDockerContainerizerProcess();
 
   MOCK_METHOD2(
       fetch,
@@ -1229,23 +1172,8 @@ public:
 class MockAuthorizer : public Authorizer
 {
 public:
-  MockAuthorizer()
-  {
-    // NOTE: We use 'EXPECT_CALL' and 'WillRepeatedly' here instead of
-    // 'ON_CALL' and 'WillByDefault'. See 'TestContainerizer::SetUp()'
-    // for more details.
-    EXPECT_CALL(*this, authorize(An<const mesos::ACL::RegisterFramework&>()))
-      .WillRepeatedly(Return(true));
-
-    EXPECT_CALL(*this, authorize(An<const mesos::ACL::RunTask&>()))
-      .WillRepeatedly(Return(true));
-
-    EXPECT_CALL(*this, authorize(An<const mesos::ACL::ShutdownFramework&>()))
-      .WillRepeatedly(Return(true));
-
-    EXPECT_CALL(*this, initialize(An<const Option<ACLs>&>()))
-      .WillRepeatedly(Return(Nothing()));
-  }
+  MockAuthorizer();
+  virtual ~MockAuthorizer();
 
   MOCK_METHOD1(
       initialize, Try<Nothing>(const Option<ACLs>& acls));

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic