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 2014/12/11 23:55:47 UTC

[10/11] mesos git commit: Moved DRFAllocatorTest.SameShareAllocations to a unit test.

Moved DRFAllocatorTest.SameShareAllocations to a unit test.

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


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

Branch: refs/heads/master
Commit: 7cfd1d4611eb4f951e82ac90bc9d9abbecf27277
Parents: 3513c21
Author: Benjamin Mahler <be...@gmail.com>
Authored: Sat Dec 6 19:29:04 2014 -0800
Committer: Benjamin Mahler <be...@gmail.com>
Committed: Thu Dec 11 14:40:30 2014 -0800

----------------------------------------------------------------------
 src/tests/hierarchical_allocator_tests.cpp |  47 ++++++++++
 src/tests/master_allocator_tests.cpp       | 111 ------------------------
 2 files changed, 47 insertions(+), 111 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/7cfd1d46/src/tests/hierarchical_allocator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/hierarchical_allocator_tests.cpp b/src/tests/hierarchical_allocator_tests.cpp
index 9f25167..b813d0c 100644
--- a/src/tests/hierarchical_allocator_tests.cpp
+++ b/src/tests/hierarchical_allocator_tests.cpp
@@ -352,3 +352,50 @@ TEST_F(HierarchicalAllocatorTest, CoarseGrained)
   EXPECT_EQ(slave2.resources(),
             sum(allocations[framework1.id()].resources.values()));
 }
+
+
+// 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(HierarchicalAllocatorTest, SameShareFairness)
+{
+  Clock::pause();
+
+  initialize({});
+
+  hashmap<FrameworkID, Resources> EMPTY;
+
+  FrameworkInfo framework1 = createFrameworkInfo("*");
+  allocator->addFramework(framework1.id(), framework1, Resources());
+
+  FrameworkInfo framework2 = createFrameworkInfo("*");
+  allocator->addFramework(framework2.id(), framework2, Resources());
+
+  SlaveInfo slave = createSlaveInfo("cpus:2;mem:1024;disk:0");
+  allocator->addSlave(slave.id(), slave, slave.resources(), EMPTY);
+
+  // Ensure that the slave's resources are alternated between both
+  // frameworks.
+  hashmap<FrameworkID, size_t> counts;
+
+  for (int i = 0; i < 10; i++) {
+    Future<Allocation> allocation = queue.get();
+    AWAIT_READY(allocation);
+    counts[allocation.get().frameworkId]++;
+
+    ASSERT_EQ(1u, allocation.get().resources.size());
+    EXPECT_EQ(slave.resources(), sum(allocation.get().resources.values()));
+
+    allocator->recoverResources(
+        allocation.get().frameworkId,
+        slave.id(),
+        allocation.get().resources.get(slave.id()).get(),
+        None());
+
+    Clock::advance(flags.allocation_interval);
+  }
+
+  EXPECT_EQ(5u, counts[framework1.id()]);
+  EXPECT_EQ(5u, counts[framework2.id()]);
+}

http://git-wip-us.apache.org/repos/asf/mesos/blob/7cfd1d46/src/tests/master_allocator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/master_allocator_tests.cpp b/src/tests/master_allocator_tests.cpp
index 8de1d2a..da32c39 100644
--- a/src/tests/master_allocator_tests.cpp
+++ b/src/tests/master_allocator_tests.cpp
@@ -67,117 +67,6 @@ using testing::DoDefault;
 using testing::Eq;
 using testing::SaveArg;
 
-// TODO(bmahler): Move the remainder of the DRFAllocatorTests to unit
-// tests. This file should only be testing the integration between the
-// master and the allocator.
-class DRFAllocatorTest : public MesosTest {};
-
-
-// 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, addFramework(_, _, _));
-
-  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);
-
-  // We need to retire this expectation on the first match because
-  // framework1 can match this expectation first in which case
-  // framework2 should be able to match the expectation above.
-  EXPECT_CALL(allocator, addFramework(_, _, _))
-    .RetiresOnSaturation();
-
-  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, recoverResources(_, _, _, _))
-    .WillRepeatedly(DoDefault());
-
-  // Start the slave.
-  EXPECT_CALL(allocator, addSlave(_, _, _, _));
-
-  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 {};