Repository: mesos
Updated Branches:
  refs/heads/master 656702960 -> c23932d57


Moved variable declarations closer to where they are used.

We usually declare related variables closer
to each other to increase code readability.

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


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

Branch: refs/heads/master
Commit: 69ab7520bb6a89596ef7bd5afcfc7b7c619f5386
Parents: 6567029
Author: Alexander Rukletsov <ruklet...@gmail.com>
Authored: Wed Apr 13 12:08:42 2016 +0200
Committer: Alexander Rukletsov <al...@apache.org>
Committed: Wed Apr 13 12:08:42 2016 +0200

----------------------------------------------------------------------
 src/tests/hierarchical_allocator_tests.cpp | 67 ++++++++-----------------
 1 file changed, 21 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/69ab7520/src/tests/hierarchical_allocator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/hierarchical_allocator_tests.cpp 
b/src/tests/hierarchical_allocator_tests.cpp
index 03064da..2e56e85 100644
--- a/src/tests/hierarchical_allocator_tests.cpp
+++ b/src/tests/hierarchical_allocator_tests.cpp
@@ -490,11 +490,9 @@ TEST_F(HierarchicalAllocatorTest, OfferFilter)
   initialize();
 
   FrameworkInfo framework1 = createFrameworkInfo(ROLE);
-
-  SlaveInfo agent1 = createSlaveInfo("cpus:1;mem:512;disk:0");
-
   allocator->addFramework(framework1.id(), framework1, {});
 
+  SlaveInfo agent1 = createSlaveInfo("cpus:1;mem:512;disk:0");
   allocator->addSlave(agent1.id(), agent1, None(), agent1.resources(), {});
 
   // `framework1` will be offered all of `agent1` resources
@@ -575,14 +573,12 @@ TEST_F(HierarchicalAllocatorTest, SmallOfferFilterTimeout)
   initialize(flags_);
 
   FrameworkInfo framework1 = createFrameworkInfo(ROLE);
-  FrameworkInfo framework2 = createFrameworkInfo(ROLE);
-
-  SlaveInfo agent1 = createSlaveInfo("cpus:1;mem:512;disk:0");
-
   allocator->addFramework(framework1.id(), framework1, {});
 
+  FrameworkInfo framework2 = createFrameworkInfo(ROLE);
   allocator->addFramework(framework2.id(), framework2, {});
 
+  SlaveInfo agent1 = createSlaveInfo("cpus:1;mem:512;disk:0");
   allocator->addSlave(
       agent1.id(),
       agent1,
@@ -1199,7 +1195,6 @@ TEST_F(HierarchicalAllocatorTest, UpdateSlave)
   FrameworkInfo framework = createFrameworkInfo("role1");
   framework.add_capabilities()->set_type(
       FrameworkInfo::Capability::REVOCABLE_RESOURCES);
-
   allocator->addFramework(framework.id(), framework, {});
 
   // Initially, all the resources are allocated.
@@ -1287,7 +1282,6 @@ TEST_F(HierarchicalAllocatorTest, 
RecoverOversubscribedResources)
   FrameworkInfo framework = createFrameworkInfo("role1");
   framework.add_capabilities()->set_type(
       FrameworkInfo::Capability::REVOCABLE_RESOURCES);
-
   allocator->addFramework(framework.id(), framework, {});
 
   // Initially, all the resources are allocated.
@@ -1511,22 +1505,16 @@ TEST_F(HierarchicalAllocatorTest, RemoveQuota)
 
   initialize();
 
-  // Create framework and agent descriptions.
-  FrameworkInfo framework1 = createFrameworkInfo(QUOTA_ROLE);
-  FrameworkInfo framework2 = createFrameworkInfo(NO_QUOTA_ROLE);
-
-  SlaveInfo agent1 = createSlaveInfo("cpus:1;mem:512;disk:0");
-  SlaveInfo agent2 = createSlaveInfo("cpus:1;mem:512;disk:0");
-
   const Quota quota1 = createQuota(QUOTA_ROLE, "cpus:2;mem:1024");
-
-  // Notify allocator of agents, frameworks, quota and current allocations.
   allocator->setQuota(QUOTA_ROLE, quota1);
 
+  FrameworkInfo framework1 = createFrameworkInfo(QUOTA_ROLE);
   allocator->addFramework(framework1.id(), framework1, {});
 
+  FrameworkInfo framework2 = createFrameworkInfo(NO_QUOTA_ROLE);
   allocator->addFramework(framework2.id(), framework2, {});
 
+  SlaveInfo agent1 = createSlaveInfo("cpus:1;mem:512;disk:0");
   allocator->addSlave(
       agent1.id(),
       agent1,
@@ -1534,6 +1522,7 @@ TEST_F(HierarchicalAllocatorTest, RemoveQuota)
       agent1.resources(),
       {std::make_pair(framework1.id(), agent1.resources())});
 
+  SlaveInfo agent2 = createSlaveInfo("cpus:1;mem:512;disk:0");
   allocator->addSlave(
       agent2.id(),
       agent2,
@@ -1782,19 +1771,13 @@ TEST_F(HierarchicalAllocatorTest, DRFWithQuota)
 
   initialize();
 
-  // Create framework and agent descriptions.
-  FrameworkInfo framework1 = createFrameworkInfo(QUOTA_ROLE);
-  FrameworkInfo framework2 = createFrameworkInfo(NO_QUOTA_ROLE);
-
-  SlaveInfo agent1 = createSlaveInfo("cpus:1;mem:512;disk:0");
-
   const Quota quota1 = createQuota(QUOTA_ROLE, "cpus:0.25;mem:128");
-
-  // Notify allocator of agents, frameworks, quota and current allocations.
   allocator->setQuota(QUOTA_ROLE, quota1);
 
+  FrameworkInfo framework1 = createFrameworkInfo(QUOTA_ROLE);
   allocator->addFramework(framework1.id(), framework1, {});
 
+  FrameworkInfo framework2 = createFrameworkInfo(NO_QUOTA_ROLE);
   allocator->addFramework(framework2.id(), framework2, {});
 
   // Process all triggered allocation events.
@@ -1818,6 +1801,8 @@ TEST_F(HierarchicalAllocatorTest, DRFWithQuota)
     "/guarantee";
   EXPECT_EQ(128, metrics.values[metric]);
 
+  // Add an agent with some allocated resources.
+  SlaveInfo agent1 = createSlaveInfo("cpus:1;mem:512;disk:0");
   allocator->addSlave(
       agent1.id(),
       agent1,
@@ -1907,18 +1892,13 @@ TEST_F(HierarchicalAllocatorTest, 
QuotaAgainstStarvation)
 
   initialize();
 
-  // Create framework and agent descriptions.
   FrameworkInfo framework1 = createFrameworkInfo(QUOTA_ROLE);
-  FrameworkInfo framework2 = createFrameworkInfo(NO_QUOTA_ROLE);
-
-  SlaveInfo agent1 = createSlaveInfo("cpus:1;mem:512;disk:0");
-  SlaveInfo agent2 = createSlaveInfo("cpus:1;mem:512;disk:0");
-
-  // Notify allocator of agents, frameworks, and current allocations.
   allocator->addFramework(framework1.id(), framework1, {});
 
+  FrameworkInfo framework2 = createFrameworkInfo(NO_QUOTA_ROLE);
   allocator->addFramework(framework2.id(), framework2, {});
 
+  SlaveInfo agent1 = createSlaveInfo("cpus:1;mem:512;disk:0");
   allocator->addSlave(
       agent1.id(),
       agent1,
@@ -1937,6 +1917,7 @@ TEST_F(HierarchicalAllocatorTest, QuotaAgainstStarvation)
   // NO_QUOTA_ROLE share = 0
   //   framework2 share = 0
 
+  SlaveInfo agent2 = createSlaveInfo("cpus:1;mem:512;disk:0");
   allocator->addSlave(agent2.id(), agent2, None(), agent2.resources(), {});
 
   // Free cluster resources on `agent2` will be allocated to `framework2`
@@ -2036,9 +2017,6 @@ TEST_F(HierarchicalAllocatorTest, QuotaAbsentFramework)
   // NOTE: No allocations happen because there are no resources to allocate.
   Clock::settle();
 
-  SlaveInfo agent1 = createSlaveInfo("cpus:2;mem:1024;disk:0");
-  SlaveInfo agent2 = createSlaveInfo("cpus:1;mem:512;disk:0");
-
   // Total cluster resources (0 agents): 0.
   // QUOTA_ROLE share = 0 [quota: cpus=2, mem=1024]
   //   no frameworks
@@ -2050,7 +2028,10 @@ TEST_F(HierarchicalAllocatorTest, QuotaAbsentFramework)
   // NOTE: The second event-based allocation for `agent2` takes into account
   // that `agent1`'s resources are laid away for `QUOTA_ROLE`'s quota and
   // hence freely allocates for the non-quota'ed `NO_QUOTA_ROLE` role.
+  SlaveInfo agent1 = createSlaveInfo("cpus:2;mem:1024;disk:0");
   allocator->addSlave(agent1.id(), agent1, None(), agent1.resources(), {});
+
+  SlaveInfo agent2 = createSlaveInfo("cpus:1;mem:512;disk:0");
   allocator->addSlave(agent2.id(), agent2, None(), agent2.resources(), {});
 
   // `framework` can only be allocated resources on `agent2`. This
@@ -2098,7 +2079,6 @@ TEST_F(HierarchicalAllocatorTest, 
MultiQuotaAbsentFrameworks)
   initialize();
 
   SlaveInfo agent = createSlaveInfo("cpus:2;mem:2048;disk:0");
-
   allocator->addSlave(agent.id(), agent, None(), agent.resources(), {});
 
   // Set quota for both roles.
@@ -2139,9 +2119,6 @@ TEST_F(HierarchicalAllocatorTest, 
MultiQuotaWithFrameworks)
 
   initialize();
 
-  SlaveInfo agent1 = createSlaveInfo("cpus:1;mem:1024;disk:0");
-  SlaveInfo agent2 = createSlaveInfo("cpus:1;mem:1024;disk:0");
-
   // Mem Quota for `QUOTA_ROLE1` is 10 times smaller than for `QUOTA_ROLE2`.
   const Quota quota1 = createQuota(QUOTA_ROLE1, "cpus:1;mem:200");
   allocator->setQuota(QUOTA_ROLE1, quota1);
@@ -2162,6 +2139,7 @@ TEST_F(HierarchicalAllocatorTest, 
MultiQuotaWithFrameworks)
   // NOTE: No allocations happen because there are no resources to allocate.
   Clock::settle();
 
+  SlaveInfo agent1 = createSlaveInfo("cpus:1;mem:1024;disk:0");
   allocator->addSlave(
       agent1.id(),
       agent1,
@@ -2169,6 +2147,7 @@ TEST_F(HierarchicalAllocatorTest, 
MultiQuotaWithFrameworks)
       agent1.resources(),
       {std::make_pair(framework1.id(), agent1.resources())});
 
+  SlaveInfo agent2 = createSlaveInfo("cpus:1;mem:1024;disk:0");
   allocator->addSlave(
       agent2.id(),
       agent2,
@@ -2187,7 +2166,6 @@ TEST_F(HierarchicalAllocatorTest, 
MultiQuotaWithFrameworks)
   // to the framework in `QUOTA_ROLE2`.
 
   SlaveInfo agent3 = createSlaveInfo("cpus:2;mem:2048");
-
   allocator->addSlave(agent3.id(), agent3, None(), agent3.resources(), {});
 
   // `framework2` will get all agent3's resources because its role is under
@@ -2218,16 +2196,13 @@ TEST_F(HierarchicalAllocatorTest, 
ReservationWithinQuota)
 
   initialize();
 
-  FrameworkInfo framework1 = createFrameworkInfo(QUOTA_ROLE);
-  FrameworkInfo framework2 = createFrameworkInfo(NON_QUOTA_ROLE);
-
   const Quota quota = createQuota(QUOTA_ROLE, "cpus:2;mem:256");
-
-  // Notify allocator of agents, frameworks, quota and current allocations.
   allocator->setQuota(QUOTA_ROLE, quota);
 
+  FrameworkInfo framework1 = createFrameworkInfo(QUOTA_ROLE);
   allocator->addFramework(framework1.id(), framework1, {});
 
+  FrameworkInfo framework2 = createFrameworkInfo(NON_QUOTA_ROLE);
   allocator->addFramework(framework2.id(), framework2, {});
 
   // Process all triggered allocation events.

Reply via email to