You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by gr...@apache.org on 2018/06/21 00:58:21 UTC
[4/4] mesos git commit: Added a test to verify the
`min_allocatable_resources` flag.
Added a test to verify the `min_allocatable_resources` flag.
This test verifies that the allocator honors the
`min_allocatable_resources` flag and only offers resources
that contain at least one of the specified resource quantities.
Review: https://reviews.apache.org/r/67517/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/79547292
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/79547292
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/79547292
Branch: refs/heads/master
Commit: 79547292b58eafe1fbfacce4844533a677084bbe
Parents: a7e3136
Author: Meng Zhu <mz...@mesosphere.io>
Authored: Wed Jun 20 17:00:18 2018 -0700
Committer: Greg Mann <gr...@gmail.com>
Committed: Wed Jun 20 17:48:14 2018 -0700
----------------------------------------------------------------------
src/tests/master_allocator_tests.cpp | 105 ++++++++++++++++++++++++++++++
1 file changed, 105 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/79547292/src/tests/master_allocator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/master_allocator_tests.cpp b/src/tests/master_allocator_tests.cpp
index 58821a4..824a755 100644
--- a/src/tests/master_allocator_tests.cpp
+++ b/src/tests/master_allocator_tests.cpp
@@ -1235,6 +1235,111 @@ TYPED_TEST(MasterAllocatorTest, MemoryOnlyOfferedAndTaskLaunched)
}
+// This test verifies that the allocator honors the `min_allocatable_resources`
+// flag and only offers resources that are more than at least one of the
+// specified resources quantities.
+TYPED_TEST(MasterAllocatorTest, MinAllocatableResources)
+{
+ Clock::pause();
+
+ master::Flags masterFlags = this->CreateMasterFlags();
+ masterFlags.min_allocatable_resources = "cpus:1;mem:100|disk:100";
+
+ TestAllocator<TypeParam> allocator;
+
+ Try<Owned<cluster::Master>> master =
+ this->StartMaster(&allocator, masterFlags);
+ ASSERT_SOME(master);
+
+ Owned<MasterDetector> detector = master.get()->createDetector();
+
+ // Prevent agents from destruction until end of test.
+ vector<Owned<cluster::Slave>> slaves;
+
+ // Add agents with non-allocatable resources.
+ vector<string> nonAllocatableAgentResources = {
+ "cpus:1;mem:0;disk:0",
+ "cpus:0;mem:100;disk:0",
+ "cpus:0.5;mem:200;disk:0",
+ "cpus:0;mem:0;disk:50"};
+
+ foreach (const string& resourcesString, nonAllocatableAgentResources) {
+ Future<SlaveRegisteredMessage> slaveRegisteredMessage =
+ FUTURE_PROTOBUF(SlaveRegisteredMessage(), _, _);
+
+ slave::Flags flags = this->CreateSlaveFlags();
+ flags.resources = resourcesString;
+
+ Try<Owned<cluster::Slave>> slave = this->StartSlave(detector.get(), flags);
+ ASSERT_SOME(slave);
+
+ // Advance the clock to trigger agent registration.
+ Clock::advance(flags.registration_backoff_factor);
+ Clock::settle();
+
+ AWAIT_READY(slaveRegisteredMessage);
+
+ slaves.push_back(slave.get());
+ }
+
+ // Add agents with allocatable resources.
+ vector<string> allocatableAgentResources = {
+ "cpus:1;mem:100;disk:0",
+ "cpus:0;mem:0;disk:100",
+ "cpus:0.5;mem:0;disk:100",
+ "cpus:1;mem:100;disk:50",
+ };
+
+ hashset<SlaveID> allocatableAgents;
+ foreach (const string& resourcesString, allocatableAgentResources) {
+ Future<SlaveRegisteredMessage> slaveRegisteredMessage =
+ FUTURE_PROTOBUF(SlaveRegisteredMessage(), _, _);
+
+ slave::Flags flags = this->CreateSlaveFlags();
+ flags.resources = resourcesString;
+
+ Try<Owned<cluster::Slave>> slave = this->StartSlave(detector.get(), flags);
+ ASSERT_SOME(slave);
+
+ // Advance the clock to trigger agent registration.
+ Clock::advance(flags.registration_backoff_factor);
+ Clock::settle();
+
+ AWAIT_READY(slaveRegisteredMessage);
+
+ slaves.push_back(slave.get());
+ allocatableAgents.insert(slaveRegisteredMessage->slave_id());
+ }
+
+ // Add a framework. This will trigger an event-driven allocation.
+ // Since it is the only framework, it will get all offers.
+ MockScheduler sched;
+ MesosSchedulerDriver driver(
+ &sched, DEFAULT_FRAMEWORK_INFO, master.get()->pid, DEFAULT_CREDENTIAL);
+
+ EXPECT_CALL(sched, registered(_, _, _));
+
+ Future<vector<Offer>> offers;
+ EXPECT_CALL(sched, resourceOffers(&driver, _))
+ .WillOnce(FutureArg<1>(&offers));
+
+ driver.start();
+
+ AWAIT_READY(offers);
+
+ // All allocatable agents are offered. None of the non-allocatable
+ // agents should be offered.
+ EXPECT_EQ(offers->size(), allocatableAgents.size());
+
+ foreach (const Offer& offer, offers.get()) {
+ EXPECT_TRUE(allocatableAgents.count(offer.slave_id()) != 0);
+ }
+
+ driver.stop();
+ driver.join();
+}
+
+
// Checks that changes to the whitelist are sent to the allocator.
// The allocator whitelisting is tested in the allocator unit tests.
// TODO(bmahler): Move this to a whitelist unit test.