You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2015/01/29 00:51:06 UTC

[1/2] mesos git commit: Renamed MockAllocatorProcess to TestAllocatorProcess.

Repository: mesos
Updated Branches:
  refs/heads/master 8d74a9a30 -> b7bb6696b


Renamed MockAllocatorProcess to TestAllocatorProcess.

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


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

Branch: refs/heads/master
Commit: ccd697df0b7e05b07dee75d53e0ff55d6884ba2f
Parents: 8d74a9a
Author: Benjamin Mahler <be...@gmail.com>
Authored: Fri Jan 16 12:13:01 2015 -0800
Committer: Benjamin Mahler <be...@gmail.com>
Committed: Wed Jan 28 15:36:11 2015 -0800

----------------------------------------------------------------------
 src/tests/master_allocator_tests.cpp | 8 ++++----
 src/tests/mesos.hpp                  | 6 +++---
 src/tests/resource_offers_tests.cpp  | 2 +-
 src/tests/slave_recovery_tests.cpp   | 2 +-
 4 files changed, 9 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/ccd697df/src/tests/master_allocator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/master_allocator_tests.cpp b/src/tests/master_allocator_tests.cpp
index 2430622..ff025fa 100644
--- a/src/tests/master_allocator_tests.cpp
+++ b/src/tests/master_allocator_tests.cpp
@@ -80,7 +80,7 @@ protected:
     process::wait(allocator.real);
   }
 
-  MockAllocatorProcess<T> allocator;
+  TestAllocatorProcess<T> allocator;
 };
 
 
@@ -94,7 +94,7 @@ TYPED_TEST_CASE(MasterAllocatorTest, AllocatorTypes);
 
 // Checks that in a cluster with one slave and one framework, all of
 // the slave's resources are offered to the framework.
-TYPED_TEST(MasterAllocatorTest, MockAllocator)
+TYPED_TEST(MasterAllocatorTest, SingleFramework)
 {
   EXPECT_CALL(this->allocator, initialize(_, _, _));
 
@@ -1375,7 +1375,7 @@ TYPED_TEST(MasterAllocatorTest, FrameworkReregistersFirst)
   this->ShutdownMasters();
   this->StopAllocator();
 
-  MockAllocatorProcess<TypeParam> allocator2;
+  TestAllocatorProcess<TypeParam> allocator2;
 
   EXPECT_CALL(allocator2, initialize(_, _, _));
 
@@ -1500,7 +1500,7 @@ TYPED_TEST(MasterAllocatorTest, SlaveReregistersFirst)
   this->ShutdownMasters();
   this->StopAllocator();
 
-  MockAllocatorProcess<TypeParam> allocator2;
+  TestAllocatorProcess<TypeParam> allocator2;
 
   EXPECT_CALL(allocator2, initialize(_, _, _));
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/ccd697df/src/tests/mesos.hpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.hpp b/src/tests/mesos.hpp
index 3f4704b..6bb5a7f 100644
--- a/src/tests/mesos.hpp
+++ b/src/tests/mesos.hpp
@@ -675,10 +675,10 @@ public:
 
 
 template <typename T = master::allocator::AllocatorProcess>
-class MockAllocatorProcess : public master::allocator::AllocatorProcess
+class TestAllocatorProcess : public master::allocator::AllocatorProcess
 {
 public:
-  MockAllocatorProcess()
+  TestAllocatorProcess()
   {
     // Spawn the underlying allocator process.
     process::spawn(real);
@@ -728,7 +728,7 @@ public:
       .WillByDefault(InvokeOffersRevived(this));
   }
 
-  ~MockAllocatorProcess()
+  ~TestAllocatorProcess()
   {
     process::terminate(real);
     process::wait(real);

http://git-wip-us.apache.org/repos/asf/mesos/blob/ccd697df/src/tests/resource_offers_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/resource_offers_tests.cpp b/src/tests/resource_offers_tests.cpp
index ffad1f8..ec86e3d 100644
--- a/src/tests/resource_offers_tests.cpp
+++ b/src/tests/resource_offers_tests.cpp
@@ -1324,7 +1324,7 @@ TEST_F(ResourceOffersTest, ResourcesGetReofferedAfterTaskInfoError)
 
 TEST_F(ResourceOffersTest, Request)
 {
-  MockAllocatorProcess<HierarchicalDRFAllocatorProcess> allocator;
+  TestAllocatorProcess<HierarchicalDRFAllocatorProcess> allocator;
 
   EXPECT_CALL(allocator, initialize(_, _, _))
     .Times(1);

http://git-wip-us.apache.org/repos/asf/mesos/blob/ccd697df/src/tests/slave_recovery_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/slave_recovery_tests.cpp b/src/tests/slave_recovery_tests.cpp
index d135856..0b0f306 100644
--- a/src/tests/slave_recovery_tests.cpp
+++ b/src/tests/slave_recovery_tests.cpp
@@ -2255,7 +2255,7 @@ TYPED_TEST(SlaveRecoveryTest, ReconcileShutdownFramework)
 // using an explicit executor.
 TYPED_TEST(SlaveRecoveryTest, ReconcileTasksMissingFromSlave)
 {
-  MockAllocatorProcess<master::allocator::HierarchicalDRFAllocatorProcess>
+  TestAllocatorProcess<master::allocator::HierarchicalDRFAllocatorProcess>
     allocator;
 
   EXPECT_CALL(allocator, initialize(_, _, _));


[2/2] mesos git commit: Updated TestAllocatorProcess to avoid the test warnings.

Posted by bm...@apache.org.
Updated TestAllocatorProcess to avoid the test warnings.

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


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

Branch: refs/heads/master
Commit: b7bb6696b5a78dbc896b4756b7d4123e86c01635
Parents: ccd697d
Author: Benjamin Mahler <be...@gmail.com>
Authored: Fri Jan 16 14:10:05 2015 -0800
Committer: Benjamin Mahler <be...@gmail.com>
Committed: Wed Jan 28 15:40:47 2015 -0800

----------------------------------------------------------------------
 src/tests/containerizer.cpp |  9 +++++---
 src/tests/mesos.hpp         | 48 ++++++++++++++++++++++++++++++++++------
 2 files changed, 47 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/b7bb6696/src/tests/containerizer.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer.cpp b/src/tests/containerizer.cpp
index a17e1e0..26b87ac 100644
--- a/src/tests/containerizer.cpp
+++ b/src/tests/containerizer.cpp
@@ -222,9 +222,12 @@ void TestContainerizer::setup()
   // warning "Uninteresting mock function call" unless each tests puts
   // the expectations in place which would make the tests much more
   // verbose.
-  // See groups.google.com/forum/#!topic/googlemock/EX4kLxddlko for a
-  // suggestion for how we might be able to use 'NiceMock' here
-  // instead.
+  //
+  // TODO(bmahler): Update this to use the same style as the
+  // TestAllocatorProcess, which allows us to have default actions
+  // 'DoDefault', without requiring each test to put expectations in
+  // place.
+
   EXPECT_CALL(*this, recover(_))
     .WillRepeatedly(Return(Nothing()));
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/b7bb6696/src/tests/mesos.hpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.hpp b/src/tests/mesos.hpp
index 6bb5a7f..17c2d8f 100644
--- a/src/tests/mesos.hpp
+++ b/src/tests/mesos.hpp
@@ -62,6 +62,11 @@
 #include "tests/zookeeper.hpp"
 #endif // MESOS_HAS_JAVA
 
+using ::testing::_;
+using ::testing::An;
+using ::testing::DoDefault;
+using ::testing::Return;
+
 namespace mesos {
 namespace internal {
 namespace tests {
@@ -552,9 +557,6 @@ class MockGarbageCollector : public slave::GarbageCollector
 public:
   MockGarbageCollector()
   {
-    using ::testing::_;
-    using ::testing::Return;
-
     // NOTE: We use 'EXPECT_CALL' and 'WillRepeatedly' here instead of
     // 'ON_CALL' and 'WillByDefault'. See 'TestContainerizer::SetUp()'
     // for more details.
@@ -649,9 +651,6 @@ class MockAuthorizer : public Authorizer
 public:
   MockAuthorizer()
   {
-    using ::testing::An;
-    using ::testing::Return;
-
     // NOTE: We use 'EXPECT_CALL' and 'WillRepeatedly' here instead of
     // 'ON_CALL' and 'WillByDefault'. See 'TestContainerizer::SetUp()'
     // for more details.
@@ -683,49 +682,84 @@ public:
     // Spawn the underlying allocator process.
     process::spawn(real);
 
-    using ::testing::_;
+    // We use 'ON_CALL' and 'WillByDefault' here to specify the
+    // default actions (call in to the real allocator). This allows
+    // the tests to leverage the 'DoDefault' action.
+    // However, 'ON_CALL' results in a "Uninteresting mock function
+    // call" warning unless each test puts expectations in place.
+    // As a result, we also use 'EXPECT_CALL' and 'WillRepeatedly'
+    // to get the best of both worlds: the ability to use 'DoDefault'
+    // and no warnings when expectations are not explicit.
 
     ON_CALL(*this, initialize(_, _, _))
       .WillByDefault(InvokeInitialize(this));
+    EXPECT_CALL(*this, initialize(_, _, _))
+      .WillRepeatedly(DoDefault());
 
     ON_CALL(*this, addFramework(_, _, _))
       .WillByDefault(InvokeFrameworkAdded(this));
+    EXPECT_CALL(*this, addFramework(_, _, _))
+      .WillRepeatedly(DoDefault());
 
     ON_CALL(*this, removeFramework(_))
       .WillByDefault(InvokeFrameworkRemoved(this));
+    EXPECT_CALL(*this, removeFramework(_))
+      .WillRepeatedly(DoDefault());
 
     ON_CALL(*this, activateFramework(_))
       .WillByDefault(InvokeFrameworkActivated(this));
+    EXPECT_CALL(*this, activateFramework(_))
+      .WillRepeatedly(DoDefault());
 
     ON_CALL(*this, deactivateFramework(_))
       .WillByDefault(InvokeFrameworkDeactivated(this));
+    EXPECT_CALL(*this, deactivateFramework(_))
+      .WillRepeatedly(DoDefault());
 
     ON_CALL(*this, addSlave(_, _, _, _))
       .WillByDefault(InvokeSlaveAdded(this));
+    EXPECT_CALL(*this, addSlave(_, _, _, _))
+      .WillRepeatedly(DoDefault());
 
     ON_CALL(*this, removeSlave(_))
       .WillByDefault(InvokeSlaveRemoved(this));
+    EXPECT_CALL(*this, removeSlave(_))
+      .WillRepeatedly(DoDefault());
 
     ON_CALL(*this, activateSlave(_))
       .WillByDefault(InvokeSlaveReactivated(this));
+    EXPECT_CALL(*this, activateSlave(_))
+      .WillRepeatedly(DoDefault());
 
     ON_CALL(*this, deactivateSlave(_))
       .WillByDefault(InvokeSlaveDeactivated(this));
+    EXPECT_CALL(*this, deactivateSlave(_))
+      .WillRepeatedly(DoDefault());
 
     ON_CALL(*this, updateWhitelist(_))
       .WillByDefault(InvokeUpdateWhitelist(this));
+    EXPECT_CALL(*this, updateWhitelist(_))
+      .WillRepeatedly(DoDefault());
 
     ON_CALL(*this, requestResources(_, _))
       .WillByDefault(InvokeResourcesRequested(this));
+    EXPECT_CALL(*this, requestResources(_, _))
+      .WillRepeatedly(DoDefault());
 
     ON_CALL(*this, updateAllocation(_, _, _))
       .WillByDefault(InvokeUpdateAllocation(this));
+    EXPECT_CALL(*this, updateAllocation(_, _, _))
+      .WillRepeatedly(DoDefault());
 
     ON_CALL(*this, recoverResources(_, _, _, _))
       .WillByDefault(InvokeResourcesRecovered(this));
+    EXPECT_CALL(*this, recoverResources(_, _, _, _))
+      .WillRepeatedly(DoDefault());
 
     ON_CALL(*this, reviveOffers(_))
       .WillByDefault(InvokeOffersRevived(this));
+    EXPECT_CALL(*this, reviveOffers(_))
+      .WillRepeatedly(DoDefault());
   }
 
   ~TestAllocatorProcess()