brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From drigod...@apache.org
Subject [1/2] brooklyn-server git commit: Adds DynamicCluster.testClustersHaveIndependentCounters
Date Wed, 08 Feb 2017 11:59:40 GMT
Repository: brooklyn-server
Updated Branches:
  refs/heads/master c62f84a95 -> 984a1e18f


Adds DynamicCluster.testClustersHaveIndependentCounters

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

Branch: refs/heads/master
Commit: ef96aed188412a0f1c4a8b2df4fb3394e766e5c2
Parents: c62f84a
Author: Aled Sage <aled.sage@gmail.com>
Authored: Wed Feb 8 10:43:47 2017 +0000
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Wed Feb 8 10:46:42 2017 +0000

----------------------------------------------------------------------
 .../entity/group/DynamicClusterTest.java        | 55 ++++++++++++++------
 1 file changed, 38 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/ef96aed1/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterTest.java b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterTest.java
index 3c827f6..f2d74dc 100644
--- a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterTest.java
+++ b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterTest.java
@@ -1042,12 +1042,7 @@ public class DynamicClusterTest extends BrooklynAppUnitTestSupport
{
 
         cluster.start(ImmutableList.of(loc));
 
-        Iterator<Entity> clusterMembersIterator = cluster.getMembers().iterator();
-
-        for (Integer expectedClusterMemberId = 0; expectedClusterMemberId < clusterSize;
expectedClusterMemberId++) {
-            Entity clusterMember = clusterMembersIterator.next();
-            assertEquals(clusterMember.config().get(CLUSTER_MEMBER_ID), expectedClusterMemberId);
-        }
+        assertMemberIdSensors(cluster, ImmutableList.of(0, 1, 2, 3, 4));
     }
 
     @Test
@@ -1063,12 +1058,7 @@ public class DynamicClusterTest extends BrooklynAppUnitTestSupport
{
         int positiveResizeDelta = 3;
         cluster.resizeByDelta(positiveResizeDelta);
 
-        Iterator<Entity> clusterMembersIterator = cluster.getMembers().iterator();
-
-        for (Integer expectedClusterMemberId = 0; expectedClusterMemberId < clusterSize
+ positiveResizeDelta; expectedClusterMemberId++) {
-            Entity clusterMember = clusterMembersIterator.next();
-            assertEquals(clusterMember.config().get(CLUSTER_MEMBER_ID), expectedClusterMemberId);
-        }
+        assertMemberIdSensors(cluster, ImmutableList.of(0, 1, 2, 3, 4, 5, 6, 7));
     }
 
     @Test
@@ -1087,16 +1077,47 @@ public class DynamicClusterTest extends BrooklynAppUnitTestSupport
{
         int positiveResizeDelta = 2;
         cluster.resizeByDelta(positiveResizeDelta);
 
-        Iterator<Entity> clusterMembersIterator = cluster.getMembers().iterator();
+        assertMemberIdSensors(cluster, ImmutableList.of(0, 1, 5, 6));
+    }
 
-        Integer[] expectedClusterMemberIds = {0, 1, 5, 6};
+    @Test
+    public void testClustersHaveIndependentCounters() throws Exception {
+        int numClusters = 2;
+        int clusterInitialSize = 1;
+        int clusterSizeDelta = 1;
+        List<DynamicCluster> clusters = Lists.newArrayList();
+        for (int i = 0; i < numClusters; i++) {
+            DynamicCluster cluster = app.addChild(EntitySpec.create(DynamicCluster.class)
+                    .configure("memberSpec", EntitySpec.create(TestEntity.class))
+                    .configure("initialSize", clusterInitialSize));
+            cluster.start(ImmutableList.of(loc));
+            clusters.add(cluster);
+        }
 
-        for (Integer expectedClusterMemberId : expectedClusterMemberIds) {
-            Entity clusterMember = clusterMembersIterator.next();
-            assertEquals(clusterMember.config().get(CLUSTER_MEMBER_ID), expectedClusterMemberId);
+        // Each cluster has its own independent count, so should start with 0.
+        for (DynamicCluster cluster : clusters) {
+            List<Integer> expectedIds = ImmutableList.of(0);
+            assertMemberIdSensors(cluster, expectedIds);
+        }
+        
+        // Each cluster should continue using its own independent count when resized.
+        for (DynamicCluster cluster : clusters) {
+            cluster.resizeByDelta(clusterSizeDelta);
+        }
+        for (DynamicCluster cluster : clusters) {
+            List<Integer> expectedIds = ImmutableList.of(0, 1);
+            assertMemberIdSensors(cluster, expectedIds);
         }
     }
 
+    private void assertMemberIdSensors(DynamicCluster cluster, List<Integer> expectedIds)
{
+        List<Entity> members = ImmutableList.copyOf(cluster.getMembers());
+        assertEquals(members.size(), expectedIds.size(), "members="+members+"; expectedIds="+expectedIds);
+        for (int i = 0; i < members.size(); i++) {
+            assertEquals(members.get(i).config().get(CLUSTER_MEMBER_ID), expectedIds.get(i));
+        }
+    }
+    
     @Test
     public void testResizeStrategies() throws Exception {
         int clusterSize = 5;


Mime
View raw message