You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by al...@apache.org on 2016/07/11 17:32:08 UTC
[4/4] mesos git commit: Renamed and lambda-ified a function in
allocator tests.
Renamed and lambda-ified a function in allocator tests.
Review: https://reviews.apache.org/r/49883/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/b4196339
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/b4196339
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/b4196339
Branch: refs/heads/master
Commit: b419633967308e0b6b615818a430aa5781e10842
Parents: 0434858
Author: Neil Conway <ne...@gmail.com>
Authored: Mon Jul 11 19:03:32 2016 +0200
Committer: Alexander Rukletsov <al...@apache.org>
Committed: Mon Jul 11 19:03:32 2016 +0200
----------------------------------------------------------------------
src/tests/hierarchical_allocator_tests.cpp | 63 ++++++++++++-------------
1 file changed, 31 insertions(+), 32 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/b4196339/src/tests/hierarchical_allocator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/hierarchical_allocator_tests.cpp b/src/tests/hierarchical_allocator_tests.cpp
index 472c82f..153c9b4 100644
--- a/src/tests/hierarchical_allocator_tests.cpp
+++ b/src/tests/hierarchical_allocator_tests.cpp
@@ -243,35 +243,6 @@ protected:
return weightInfo;
}
- void handleAllocationsAndRecoverResources(
- Resources& totalAllocatedResources,
- hashmap<FrameworkID, Allocation>& frameworkAllocations,
- int allocationsCount,
- bool recoverResources)
- {
- for (int i = 0; i < allocationsCount; i++) {
- Future<Allocation> allocation = allocations.get();
- AWAIT_READY(allocation);
-
- frameworkAllocations[allocation.get().frameworkId] = allocation.get();
- totalAllocatedResources += Resources::sum(allocation.get().resources);
-
- if (recoverResources) {
- // Recover the allocated resources so they can be offered again
- // next time.
- foreachpair (const SlaveID& slaveId,
- const Resources& resources,
- allocation.get().resources) {
- allocator->recoverResources(
- allocation.get().frameworkId,
- slaveId,
- resources,
- None());
- }
- }
- }
- }
-
protected:
master::Flags flags;
@@ -3045,6 +3016,34 @@ TEST_F(HierarchicalAllocatorTest, UpdateWeight)
const string FOURFOLD_RESOURCES = "cpus:8;mem:4096";
const string TOTAL_RESOURCES = "cpus:12;mem:6144";
+ auto awaitAllocationsAndRecoverResources = [this](
+ Resources& totalAllocatedResources,
+ hashmap<FrameworkID, Allocation>& frameworkAllocations,
+ int allocationsCount,
+ bool recoverResources) {
+ for (int i = 0; i < allocationsCount; i++) {
+ Future<Allocation> allocation = allocations.get();
+ AWAIT_READY(allocation);
+
+ frameworkAllocations[allocation.get().frameworkId] = allocation.get();
+ totalAllocatedResources += Resources::sum(allocation.get().resources);
+
+ if (recoverResources) {
+ // Recover the allocated resources so they can be offered
+ // again next time.
+ foreachpair (const SlaveID& slaveId,
+ const Resources& resources,
+ allocation.get().resources) {
+ allocator->recoverResources(
+ allocation.get().frameworkId,
+ slaveId,
+ resources,
+ None());
+ }
+ }
+ }
+ };
+
// Register six agents with the same resources (cpus:2;mem:1024).
vector<SlaveInfo> agents;
for (unsigned i = 0; i < 6; i++) {
@@ -3106,7 +3105,7 @@ TEST_F(HierarchicalAllocatorTest, UpdateWeight)
// since each framework's role has a weight of 1.0 by default.
hashmap<FrameworkID, Allocation> frameworkAllocations;
Resources totalAllocatedResources;
- handleAllocationsAndRecoverResources(totalAllocatedResources,
+ awaitAllocationsAndRecoverResources(totalAllocatedResources,
frameworkAllocations, 2, true);
// Framework1 should get one allocation with three agents.
@@ -3144,7 +3143,7 @@ TEST_F(HierarchicalAllocatorTest, UpdateWeight)
// resources are offered with a ratio of 1:2 between both frameworks.
hashmap<FrameworkID, Allocation> frameworkAllocations;
Resources totalAllocatedResources;
- handleAllocationsAndRecoverResources(totalAllocatedResources,
+ awaitAllocationsAndRecoverResources(totalAllocatedResources,
frameworkAllocations, 2, true);
// Framework1 should get one allocation with two agents.
@@ -3193,7 +3192,7 @@ TEST_F(HierarchicalAllocatorTest, UpdateWeight)
// will get the proper resource ratio of 1:2:3.
hashmap<FrameworkID, Allocation> frameworkAllocations;
Resources totalAllocatedResources;
- handleAllocationsAndRecoverResources(totalAllocatedResources,
+ awaitAllocationsAndRecoverResources(totalAllocatedResources,
frameworkAllocations, 3, false);
// Framework1 should get one allocation with one agent.