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/12 22:58:15 UTC

[5/6] mesos git commit: Added an allocator unit test for allocatable resources.

Added an allocator unit test for allocatable resources.

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


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

Branch: refs/heads/master
Commit: df521b029b4cbd60fac8ef14ae109be9351d300d
Parents: 92fb594
Author: Benjamin Mahler <be...@gmail.com>
Authored: Thu Dec 11 22:21:48 2014 -0800
Committer: Benjamin Mahler <be...@gmail.com>
Committed: Fri Dec 12 13:39:13 2014 -0800

----------------------------------------------------------------------
 src/tests/hierarchical_allocator_tests.cpp | 72 +++++++++++++++++++++++++
 1 file changed, 72 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/df521b02/src/tests/hierarchical_allocator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/hierarchical_allocator_tests.cpp b/src/tests/hierarchical_allocator_tests.cpp
index 5e617ff..e429253 100644
--- a/src/tests/hierarchical_allocator_tests.cpp
+++ b/src/tests/hierarchical_allocator_tests.cpp
@@ -32,12 +32,16 @@
 #include <stout/utils.hpp>
 
 #include "master/allocator.hpp"
+#include "master/constants.hpp"
 #include "master/flags.hpp"
 #include "master/hierarchical_allocator_process.hpp"
 
 using namespace mesos;
 using namespace mesos::internal;
 
+using mesos::internal::master::MIN_CPUS;
+using mesos::internal::master::MIN_MEM;
+
 using mesos::internal::master::allocator::Allocator;
 using mesos::internal::master::allocator::AllocatorProcess;
 using mesos::internal::master::allocator::HierarchicalDRFAllocatorProcess;
@@ -524,6 +528,74 @@ TEST_F(HierarchicalAllocatorTest, RecoverResources)
 }
 
 
+TEST_F(HierarchicalAllocatorTest, Allocatable)
+{
+  // Pausing the clock is not necessary, but ensures that the test
+  // doesn't rely on the periodic allocation in the allocator, which
+  // would slow down the test.
+  Clock::pause();
+
+  initialize({"role1"});
+
+  FrameworkInfo framework = createFrameworkInfo("role1");
+  allocator->addFramework(framework.id(), framework, Resources());
+
+  hashmap<FrameworkID, Resources> EMPTY;
+
+  // Not enough memory or cpu to be considered allocatable.
+  SlaveInfo slave1 = createSlaveInfo(
+      "cpus:" + stringify(MIN_CPUS / 2) + ";"
+      "mem:" + stringify((MIN_MEM / 2).megabytes()) + ";"
+      "disk:128");
+  allocator->addSlave(slave1.id(), slave1, slave1.resources(), EMPTY);
+
+  // Enough cpus to be considered allocatable.
+  SlaveInfo slave2 = createSlaveInfo(
+      "cpus:" + stringify(MIN_CPUS) + ";"
+      "mem:" + stringify((MIN_MEM / 2).megabytes()) + ";"
+      "disk:128");
+  allocator->addSlave(slave2.id(), slave2, slave2.resources(), EMPTY);
+
+  Future<Allocation> allocation = queue.get();
+  AWAIT_READY(allocation);
+  EXPECT_EQ(framework.id(), allocation.get().frameworkId);
+  EXPECT_EQ(1u, allocation.get().resources.size());
+  EXPECT_TRUE(allocation.get().resources.contains(slave2.id()));
+  EXPECT_EQ(slave2.resources(), sum(allocation.get().resources.values()));
+
+  // Enough memory to be considered allocatable.
+  SlaveInfo slave3 = createSlaveInfo(
+      "cpus:" + stringify(MIN_CPUS / 2) + ";"
+      "mem:" + stringify((MIN_MEM).megabytes()) + ";"
+      "disk:128");
+  allocator->addSlave(slave3.id(), slave3, slave3.resources(), EMPTY);
+
+  allocation = queue.get();
+  AWAIT_READY(allocation);
+  EXPECT_EQ(framework.id(), allocation.get().frameworkId);
+  EXPECT_EQ(1u, allocation.get().resources.size());
+  EXPECT_TRUE(allocation.get().resources.contains(slave3.id()));
+  EXPECT_EQ(slave3.resources(), sum(allocation.get().resources.values()));
+
+  // slave4 has enough cpu and memory to be considered allocatable,
+  // but it lies across unreserved and reserved resources!
+  SlaveInfo slave4 = createSlaveInfo(
+      "cpus:" + stringify(MIN_CPUS / 1.5) + ";"
+      "mem:" + stringify((MIN_MEM / 2).megabytes()) + ";"
+      "cpus(role1):" + stringify(MIN_CPUS / 1.5) + ";"
+      "mem(role1):" + stringify((MIN_MEM / 2).megabytes()) + ";"
+      "disk:128");
+  allocator->addSlave(slave4.id(), slave4, slave4.resources(), EMPTY);
+
+  allocation = queue.get();
+  AWAIT_READY(allocation);
+  EXPECT_EQ(framework.id(), allocation.get().frameworkId);
+  EXPECT_EQ(1u, allocation.get().resources.size());
+  EXPECT_TRUE(allocation.get().resources.contains(slave4.id()));
+  EXPECT_EQ(slave4.resources(), sum(allocation.get().resources.values()));
+}
+
+
 // Checks that a slave that is not whitelisted will not have its
 // resources get offered, and that if the whitelist is updated so
 // that it is whitelisted, its resources will then be offered.