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:44 UTC
[07/11] mesos git commit: Moved DRFAllocatorTest.PerSlaveAllocation
to a unit test.
Moved DRFAllocatorTest.PerSlaveAllocation to a unit test.
Review: https://reviews.apache.org/r/28816
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/3513c21a
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/3513c21a
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/3513c21a
Branch: refs/heads/master
Commit: 3513c21aa0a3c524a59c73f576bd9ec1fbc749ca
Parents: 6cf1b01
Author: Benjamin Mahler <be...@gmail.com>
Authored: Sat Dec 6 18:54:04 2014 -0800
Committer: Benjamin Mahler <be...@gmail.com>
Committed: Thu Dec 11 14:40:30 2014 -0800
----------------------------------------------------------------------
src/tests/hierarchical_allocator_tests.cpp | 72 ++++++++++++
src/tests/master_allocator_tests.cpp | 144 ------------------------
2 files changed, 72 insertions(+), 144 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/3513c21a/src/tests/hierarchical_allocator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/hierarchical_allocator_tests.cpp b/src/tests/hierarchical_allocator_tests.cpp
index 9ecbd0f..9f25167 100644
--- a/src/tests/hierarchical_allocator_tests.cpp
+++ b/src/tests/hierarchical_allocator_tests.cpp
@@ -280,3 +280,75 @@ TEST_F(HierarchicalAllocatorTest, DRF)
EXPECT_EQ(framework2.id(), allocation.get().frameworkId);
EXPECT_EQ(slave5.resources(), sum(allocation.get().resources.values()));
}
+
+
+// This test ensures that allocation is done per slave. This is done
+// by having 2 slaves and 2 frameworks and making sure each framework
+// gets only one slave's resources during an allocation.
+TEST_F(HierarchicalAllocatorTest, CoarseGrained)
+{
+ // Pausing the clock ensures that the batch allocation does not
+ // influence this test.
+ Clock::pause();
+
+ initialize({"role1", "role2"});
+
+ hashmap<FrameworkID, Resources> EMPTY;
+
+ SlaveInfo slave1 = createSlaveInfo("cpus:2;mem:1024;disk:0");
+ allocator->addSlave(slave1.id(), slave1, slave1.resources(), EMPTY);
+
+ SlaveInfo slave2 = createSlaveInfo("cpus:2;mem:1024;disk:0");
+ allocator->addSlave(slave2.id(), slave2, slave2.resources(), EMPTY);
+
+ // Once framework1 is added, an allocation will occur. Return the
+ // resources so that we can test what happens when there are 2
+ // frameworks and 2 slaves to consider during allocation.
+ FrameworkInfo framework1 = createFrameworkInfo("role1");
+ allocator->addFramework(framework1.id(), framework1, Resources());
+
+ Future<Allocation> allocation = queue.get();
+ AWAIT_READY(allocation);
+ EXPECT_EQ(framework1.id(), allocation.get().frameworkId);
+ EXPECT_EQ(slave1.resources() + slave2.resources(),
+ sum(allocation.get().resources.values()));
+
+ allocator->recoverResources(
+ framework1.id(),
+ slave1.id(),
+ allocation.get().resources.get(slave1.id()).get(),
+ None());
+ allocator->recoverResources(
+ framework1.id(),
+ slave2.id(),
+ allocation.get().resources.get(slave2.id()).get(),
+ None());
+
+ // Now add the second framework, we expect there to be 2 subsequent
+ // allocations, each framework being allocated a full slave.
+ FrameworkInfo framework2 = createFrameworkInfo("role2");
+ allocator->addFramework(framework2.id(), framework2, Resources());
+
+ hashmap<FrameworkID, Allocation> allocations;
+
+ allocation = queue.get();
+ AWAIT_READY(allocation);
+ allocations[allocation.get().frameworkId] = allocation.get();
+
+ allocation = queue.get();
+ AWAIT_READY(allocation);
+ allocations[allocation.get().frameworkId] = allocation.get();
+
+ // Note that slave1 and slave2 have the same resources, we don't
+ // care which framework received which slave.. only that they each
+ // received one.
+ ASSERT_TRUE(allocations.contains(framework1.id()));
+ ASSERT_EQ(1u, allocations[framework1.id()].resources.size());
+ EXPECT_EQ(slave1.resources(),
+ sum(allocations[framework1.id()].resources.values()));
+
+ ASSERT_TRUE(allocations.contains(framework2.id()));
+ ASSERT_EQ(1u, allocations[framework1.id()].resources.size());
+ EXPECT_EQ(slave2.resources(),
+ sum(allocations[framework1.id()].resources.values()));
+}
http://git-wip-us.apache.org/repos/asf/mesos/blob/3513c21a/src/tests/master_allocator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/master_allocator_tests.cpp b/src/tests/master_allocator_tests.cpp
index de0d7e8..8de1d2a 100644
--- a/src/tests/master_allocator_tests.cpp
+++ b/src/tests/master_allocator_tests.cpp
@@ -72,150 +72,6 @@ using testing::SaveArg;
// master and the allocator.
class DRFAllocatorTest : public MesosTest {};
-// This test ensures that allocation is done per slave. This is done
-// by having 2 slaves and 2 frameworks and making sure each framework
-// gets only one slave's resources during an allocation.
-TEST_F(DRFAllocatorTest, PerSlaveAllocation)
-{
- MockAllocatorProcess<HierarchicalDRFAllocatorProcess> allocator;
-
- EXPECT_CALL(allocator, initialize(_, _, _));
-
- // Start the master.
- // NOTE: We set a high allocation interval, so that allocator does
- // allocations only based on events (framework added, slave added)
- // but not due to allocation interval. This lets us tightly control
- // the test expectations.
- master::Flags masterFlags = CreateMasterFlags();
- masterFlags.roles = Some("role1,role2");
- masterFlags.allocation_interval = Days(1);
- Try<PID<Master> > master = StartMaster(&allocator, masterFlags);
- ASSERT_SOME(master);
-
- // Start slave 1.
- slave::Flags flags1 = CreateSlaveFlags();
- flags1.resources = Some("cpus:2;mem:1024;disk:0");
-
- Future<Nothing> addSlave1;
- EXPECT_CALL(allocator, addSlave(_, _, _, _))
- .WillOnce(DoAll(InvokeSlaveAdded(&allocator),
- FutureSatisfy(&addSlave1)));
-
- Try<PID<Slave> > slave1 = StartSlave(flags1);
- ASSERT_SOME(slave1);
-
- AWAIT_READY(addSlave1);
-
- // Start slave 2.
- slave::Flags flags2 = CreateSlaveFlags();
- flags2.resources = Some("cpus:2;mem:1024;disk:0");
-
- Future<Nothing> addSlave2;
- EXPECT_CALL(allocator, addSlave(_, _, _, _))
- .WillOnce(DoAll(InvokeSlaveAdded(&allocator),
- FutureSatisfy(&addSlave2)));
-
- Try<PID<Slave> > slave2 = StartSlave(flags2);
- ASSERT_SOME(slave2);
-
- AWAIT_READY(addSlave2);
-
- // Start framework 1.
- FrameworkInfo frameworkInfo1; // Bug in gcc 4.1.*, must assign on next line.
- frameworkInfo1 = DEFAULT_FRAMEWORK_INFO;
- frameworkInfo1.set_name("framework1");
- frameworkInfo1.set_user("user1");
- frameworkInfo1.set_role("role1");
-
- MockScheduler sched1;
- MesosSchedulerDriver driver1(
- &sched1, frameworkInfo1, master.get(), DEFAULT_CREDENTIAL);
-
- EXPECT_CALL(allocator, addFramework(_, _, _));
-
- EXPECT_CALL(sched1, registered(_, _, _));
-
- Future<Nothing> recoverResources1;
- Future<Nothing> recoverResources2;
- EXPECT_CALL(allocator, recoverResources(_, _, _, _))
- .WillOnce(DoAll(InvokeResourcesRecovered(&allocator),
- FutureSatisfy(&recoverResources1)))
- .WillOnce(DoAll(InvokeResourcesRecovered(&allocator),
- FutureSatisfy(&recoverResources2)));
-
- // Decline the offers immediately so that resources for both slaves
- // are eligible for allocation to this and other frameworks.
- Filters filters;
- filters.set_refuse_seconds(0);
- EXPECT_CALL(sched1, resourceOffers(_, _))
- .WillOnce(DeclineOffers(filters));
-
- driver1.start();
-
- // Wait until the resources are returned to the allocator.
- // NOTE: No allocations will be made after this point until a new
- // framework registers because
- // 1) 'recoverResources' does not trigger an allocation and
- // 2) 'flags.allocation_interval' is set to a very high value.
- AWAIT_READY(recoverResources1);
- AWAIT_READY(recoverResources2);
-
- // Start framework 2.
- FrameworkInfo frameworkInfo2; // Bug in gcc 4.1.*, must assign on next line.
- frameworkInfo2 = DEFAULT_FRAMEWORK_INFO;
- frameworkInfo2.set_name("framework2");
- frameworkInfo2.set_user("user2");
- frameworkInfo2.set_role("role2");
-
- MockScheduler sched2;
- MesosSchedulerDriver driver2(
- &sched2, frameworkInfo2, master.get(), DEFAULT_CREDENTIAL);
-
- EXPECT_CALL(allocator, addFramework(_, _, _));
-
- EXPECT_CALL(sched2, registered(_, _, _));
-
- // Offers to framework 1.
- Future<vector<Offer> > offers1;
- EXPECT_CALL(sched1, resourceOffers(_, _))
- .WillOnce(FutureArg<1>(&offers1));
-
- // Offers to framework 2.
- Future<vector<Offer> > offers2;
- EXPECT_CALL(sched2, resourceOffers(_, _))
- .WillOnce(FutureArg<1>(&offers2));
-
- driver2.start();
-
- // Now each framework should receive offers for one slave each.
- AWAIT_READY(offers1);
- EXPECT_THAT(offers1.get(), OfferEq(2, 1024));
-
- AWAIT_READY(offers2);
- EXPECT_THAT(offers2.get(), OfferEq(2, 1024));
-
- // Shut everything down.
- EXPECT_CALL(allocator, recoverResources(_, _, _, _))
- .WillRepeatedly(DoDefault());
-
- EXPECT_CALL(allocator, deactivateFramework(_))
- .WillRepeatedly(DoDefault());
-
- EXPECT_CALL(allocator, removeFramework(_))
- .WillRepeatedly(DoDefault());
-
- driver1.stop();
- driver1.join();
-
- driver2.stop();
- driver2.join();
-
- EXPECT_CALL(allocator, removeSlave(_))
- .WillRepeatedly(DoDefault());
-
- Shutdown();
-}
-
// Helper that simply increments the value by reference.
ACTION_P(Increment, value) { *value += 1; }