You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by vi...@apache.org on 2014/06/24 21:21:01 UTC

git commit: Added a test to verify that frameworks with equal share get equal number of allocations.

Repository: mesos
Updated Branches:
  refs/heads/master 6f32d9a17 -> 6b66a0714


Added a test to verify that frameworks with equal share get equal
number of allocations.

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


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

Branch: refs/heads/master
Commit: 6b66a0714b0796b72723f6d657a66140cc0f7110
Parents: 6f32d9a
Author: Vinod Kone <vi...@twitter.com>
Authored: Tue Jun 17 14:35:14 2014 -0700
Committer: Vinod Kone <vi...@gmail.com>
Committed: Tue Jun 24 12:20:21 2014 -0700

----------------------------------------------------------------------
 src/tests/allocator_tests.cpp | 108 ++++++++++++++++++++++++++++++++++---
 src/tests/mesos.hpp           |  12 +++++
 2 files changed, 114 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/6b66a071/src/tests/allocator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/allocator_tests.cpp b/src/tests/allocator_tests.cpp
index 7ad4964..a968ea3 100644
--- a/src/tests/allocator_tests.cpp
+++ b/src/tests/allocator_tests.cpp
@@ -322,6 +322,108 @@ TEST_F(DRFAllocatorTest, DRFAllocatorProcess)
 }
 
 
+// Helper that simply increments the value by reference.
+ACTION_P(Increment, value) { *value += 1; }
+
+
+// This test ensures that frameworks that have the same share get an
+// equal number of allocations over time (rather than the same
+// framework getting all the allocations because it's name is
+// lexicographically ordered first).
+TEST_F(DRFAllocatorTest, SameShareAllocations)
+{
+  MockAllocatorProcess<HierarchicalDRFAllocatorProcess> allocator;
+
+  EXPECT_CALL(allocator, initialize(_, _, _));
+
+  master::Flags masterFlags = CreateMasterFlags();
+  Try<PID<Master> > master = StartMaster(&allocator, masterFlags);
+  ASSERT_SOME(master);
+
+  // Start the first scheduler.
+  FrameworkInfo frameworkInfo1; // Bug in gcc 4.1.*, must assign on next line.
+  frameworkInfo1 = DEFAULT_FRAMEWORK_INFO;
+  frameworkInfo1.set_name("framework1");
+
+  MockScheduler sched1;
+  MesosSchedulerDriver driver1(
+      &sched1, frameworkInfo1, master.get(), DEFAULT_CREDENTIAL);
+
+  EXPECT_CALL(allocator, frameworkAdded(_, _, _));
+
+  Future<Nothing> registered1;
+  EXPECT_CALL(sched1, registered(_, _, _))
+    .WillOnce(FutureSatisfy(&registered1));
+
+  driver1.start();
+
+  AWAIT_READY(registered1);
+
+  // Start the second scheduler.
+  FrameworkInfo frameworkInfo2; // Bug in gcc 4.1.*, must assign on next line.
+  frameworkInfo2 = DEFAULT_FRAMEWORK_INFO;
+  frameworkInfo2.set_name("framework2");
+
+  MockScheduler sched2;
+  MesosSchedulerDriver driver2(
+      &sched2, frameworkInfo2, master.get(), DEFAULT_CREDENTIAL);
+
+  EXPECT_CALL(allocator, frameworkAdded(_, _, _));
+
+  Future<Nothing> registered2;
+  EXPECT_CALL(sched2, registered(_, _, _))
+    .WillOnce(FutureSatisfy(&registered2));
+
+  driver2.start();
+
+  AWAIT_READY(registered2);
+
+  // Set filter timeout to 0 so that both frameworks are eligible
+  // for allocation during every allocation interval.
+  Filters filters;
+  filters.set_refuse_seconds(0);
+
+  int allocations1 = 0;
+  EXPECT_CALL(sched1, resourceOffers(_, _))
+    .WillRepeatedly(DoAll(Increment(&allocations1),
+                          DeclineOffers(filters)));
+
+  int allocations2 = 0;
+  EXPECT_CALL(sched2, resourceOffers(_, _))
+    .WillRepeatedly(DoAll(Increment(&allocations2),
+                          DeclineOffers(filters)));
+
+  EXPECT_CALL(allocator, resourcesUnused(_, _, _, _))
+    .WillRepeatedly(DoDefault());
+
+  // Start the slave.
+  EXPECT_CALL(allocator, slaveAdded(_, _, _));
+
+  Try<PID<Slave> > slave = StartSlave();
+  ASSERT_SOME(slave);
+
+  // Continuously do allocations.
+  Clock::pause();
+  while(allocations1 + allocations2 < 10) {
+    Clock::advance(masterFlags.allocation_interval);
+    Clock::settle();
+  }
+
+  // Each framework should get equal number of allocations.
+  ASSERT_EQ(allocations1, allocations2);
+
+  Clock::resume();
+
+  driver1.stop();
+  driver1.join();
+
+  driver2.stop();
+  driver2.join();
+
+  Shutdown();
+}
+
+
 class ReservationAllocatorTest : public MesosTest {};
 
 
@@ -1740,9 +1842,3 @@ TYPED_TEST(AllocatorTest, RoleTest)
 
   this->Shutdown();
 }
-
-
-// TODO(benh): Add a DRF allocator test which ensures that frameworks
-// that have the same share get an equal number of allocations over
-// time (rather than the same framework getting all the allocations
-// because it's name is lexicographically ordered first.

http://git-wip-us.apache.org/repos/asf/mesos/blob/6b66a071/src/tests/mesos.hpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.hpp b/src/tests/mesos.hpp
index c40c82d..eeb8631 100644
--- a/src/tests/mesos.hpp
+++ b/src/tests/mesos.hpp
@@ -405,6 +405,18 @@ ACTION(DeclineOffers)
 }
 
 
+// Like DeclineOffers, but takes a custom filters object.
+ACTION_P(DeclineOffers, filters)
+{
+  SchedulerDriver* driver = arg0;
+  std::vector<Offer> offers = arg1;
+
+  for (size_t i = 0; i < offers.size(); i++) {
+    driver->declineOffer(offers[i].id(), filters);
+  }
+}
+
+
 // Definition of a mock Executor to be used in tests with gmock.
 class MockExecutor : public Executor
 {