brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From drigod...@apache.org
Subject [2/3] brooklyn-server git commit: Add tests for DynamicRegionFabric change
Date Tue, 20 Jun 2017 09:04:50 GMT
Add tests for DynamicRegionFabric change

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

Branch: refs/heads/master
Commit: 5ed32b2ee125bfc9a177cb9ea8e5073efb9e8d6c
Parents: cd29cdf
Author: Richard Downer <richard@apache.org>
Authored: Mon Jun 19 16:33:53 2017 +0100
Committer: Richard Downer <richard@apache.org>
Committed: Mon Jun 19 16:33:53 2017 +0100

----------------------------------------------------------------------
 .../AbstractDynamicClusterOrFabricTest.java     | 45 ++++++++++++++
 .../entity/group/DynamicClusterTest.java        | 16 +----
 .../entity/group/DynamicFabricTest.java         | 24 +++++++-
 .../entity/group/DynamicRegionsFabricTest.java  | 62 ++++++++++++++++++--
 4 files changed, 125 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5ed32b2e/core/src/test/java/org/apache/brooklyn/entity/group/AbstractDynamicClusterOrFabricTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/entity/group/AbstractDynamicClusterOrFabricTest.java
b/core/src/test/java/org/apache/brooklyn/entity/group/AbstractDynamicClusterOrFabricTest.java
new file mode 100644
index 0000000..154a293
--- /dev/null
+++ b/core/src/test/java/org/apache/brooklyn/entity/group/AbstractDynamicClusterOrFabricTest.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.entity.group;
+
+import static org.testng.Assert.assertEquals;
+
+import java.util.Collection;
+import java.util.Set;
+
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
+import org.apache.brooklyn.core.test.entity.TestEntity;
+import org.apache.brooklyn.util.collections.MutableSet;
+
+public class AbstractDynamicClusterOrFabricTest extends BrooklynAppUnitTestSupport {
+    void assertFirstAndNonFirstCounts(Collection<Entity> members, int expectedFirstCount,
int expectedNonFirstCount) {
+        Set<Entity> found = MutableSet.of();
+        for (Entity e: members) {
+            if ("first".equals(e.getConfig(TestEntity.CONF_NAME))) found.add(e);
+        }
+        assertEquals(found.size(), expectedFirstCount, "when counting 'first' nodes");
+
+        found.clear();
+        for (Entity e: members) {
+            if ("non-first".equals(e.getConfig(TestEntity.CONF_NAME))) found.add(e);
+        }
+        assertEquals(found.size(), expectedNonFirstCount, "when counting 'non-first' nodes");
+    }
+}

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5ed32b2e/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 b0e115c..5b76bbc 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
@@ -98,7 +98,7 @@ import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
 
 
-public class DynamicClusterTest extends BrooklynAppUnitTestSupport {
+public class DynamicClusterTest extends AbstractDynamicClusterOrFabricTest {
 
     private static final int TIMEOUT_MS = 2000;
 
@@ -1158,20 +1158,6 @@ public class DynamicClusterTest extends BrooklynAppUnitTestSupport
{
         }
     }
 
-    private void assertFirstAndNonFirstCounts(Collection<Entity> members, int expectedFirstCount,
int expectedNonFirstCount) {
-        Set<Entity> found = MutableSet.of();
-        for (Entity e: members) {
-            if ("first".equals(e.getConfig(TestEntity.CONF_NAME))) found.add(e);
-        }
-        assertEquals(found.size(), expectedFirstCount);
-        
-        found.clear();
-        for (Entity e: members) {
-            if ("non-first".equals(e.getConfig(TestEntity.CONF_NAME))) found.add(e);
-        }
-        assertEquals(found.size(), expectedNonFirstCount);
-    }
-
     @DataProvider
     public Object[][] maxConcurrentCommandsTestProvider() {
         return new Object[][]{{1}, {2}, {3}};

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5ed32b2e/core/src/test/java/org/apache/brooklyn/entity/group/DynamicFabricTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicFabricTest.java b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicFabricTest.java
index c41ddd5..e501b4d 100644
--- a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicFabricTest.java
+++ b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicFabricTest.java
@@ -35,6 +35,8 @@ import org.apache.brooklyn.api.location.Location;
 import org.apache.brooklyn.api.mgmt.Task;
 import org.apache.brooklyn.core.entity.Attributes;
 import org.apache.brooklyn.core.entity.Entities;
+import org.apache.brooklyn.core.entity.EntityAsserts;
+import org.apache.brooklyn.core.entity.lifecycle.Lifecycle;
 import org.apache.brooklyn.core.entity.trait.Startable;
 import org.apache.brooklyn.core.location.PortRanges;
 import org.apache.brooklyn.core.location.SimulatedLocation;
@@ -45,6 +47,7 @@ import org.apache.brooklyn.entity.stock.BasicEntity;
 import org.apache.brooklyn.test.Asserts;
 import org.apache.brooklyn.util.collections.MutableList;
 import org.apache.brooklyn.util.collections.MutableMap;
+import org.apache.brooklyn.util.collections.QuorumCheck;
 import org.apache.brooklyn.util.exceptions.Exceptions;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -57,7 +60,7 @@ import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
 
-public class DynamicFabricTest extends BrooklynAppUnitTestSupport {
+public class DynamicFabricTest extends AbstractDynamicClusterOrFabricTest {
     private static final Logger log = LoggerFactory.getLogger(DynamicFabricTest.class);
 
     private static final int TIMEOUT_MS = 5*1000;
@@ -365,6 +368,25 @@ public class DynamicFabricTest extends BrooklynAppUnitTestSupport {
         return Iterables.get(child.getChildren(), grandchildIndex);
     }
 
+    @Test
+    public void testDifferentFirstMemberSpec() throws Exception {
+        DynamicFabric fabric = app.createAndManageChild(EntitySpec.create(DynamicFabric.class)
+                .configure(DynamicFabric.FIRST_MEMBER_SPEC,
+                        EntitySpec.create(BasicEntity.class).configure(TestEntity.CONF_NAME,
"first"))
+                .configure(DynamicFabric.MEMBER_SPEC,
+                        EntitySpec.create(BasicEntity.class).configure(TestEntity.CONF_NAME,
"non-first"))
+                .configure(DynamicFabric.UP_QUORUM_CHECK, QuorumCheck.QuorumChecks.alwaysTrue()));
+        List<Location> locs = ImmutableList.of(loc1, loc2, loc3);
+        fabric.start(locs);
+
+        EntityAsserts.assertAttributeEqualsEventually(fabric, Attributes.SERVICE_STATE_ACTUAL,
Lifecycle.RUNNING);
+        assertTrue(fabric.getAttribute(Attributes.SERVICE_UP));
+
+        assertEquals(fabric.getMembers().size(), 3);
+
+        assertFirstAndNonFirstCounts(fabric.getMembers(), 1, 2);
+    }
+
     private Entity getChild(Entity entity, int childIndex) {
         return Iterables.get(entity.getChildren(), childIndex);
     }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5ed32b2e/core/src/test/java/org/apache/brooklyn/entity/group/DynamicRegionsFabricTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicRegionsFabricTest.java
b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicRegionsFabricTest.java
index 5227c8d..b2ff9eb 100644
--- a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicRegionsFabricTest.java
+++ b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicRegionsFabricTest.java
@@ -29,13 +29,19 @@ import java.util.Set;
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.location.Location;
+import org.apache.brooklyn.api.location.LocationSpec;
+import org.apache.brooklyn.api.mgmt.LocationManager;
+import org.apache.brooklyn.core.entity.Attributes;
 import org.apache.brooklyn.core.entity.BrooklynConfigKeys;
+import org.apache.brooklyn.core.entity.EntityAsserts;
+import org.apache.brooklyn.core.entity.lifecycle.Lifecycle;
 import org.apache.brooklyn.core.location.SimulatedLocation;
 import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
 import org.apache.brooklyn.core.test.entity.TestApplication;
 import org.apache.brooklyn.core.test.entity.TestEntity;
 import org.apache.brooklyn.entity.stock.BasicEntity;
 import org.apache.brooklyn.util.collections.MutableSet;
+import org.apache.brooklyn.util.collections.QuorumCheck;
 import org.apache.brooklyn.util.exceptions.Exceptions;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
@@ -46,19 +52,22 @@ import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
 
-public class DynamicRegionsFabricTest extends BrooklynAppUnitTestSupport {
+public class DynamicRegionsFabricTest extends AbstractDynamicClusterOrFabricTest {
 
     DynamicRegionsFabric fabric;
     private Location loc1;
     private Location loc2;
-    
+    private Location loc3;
+
     @BeforeMethod(alwaysRun=true)
     @Override
     public void setUp() throws Exception {
         super.setUp();
-        loc1 = new SimulatedLocation();
-        loc2 = new SimulatedLocation();
-        
+        final LocationManager lm = mgmt.getLocationManager();
+        loc1 = lm.createLocation(LocationSpec.create(SimulatedLocation.class).configure("displayName",
"newloc1"));
+        loc2 = lm.createLocation(LocationSpec.create(SimulatedLocation.class).configure("displayName",
"newloc2"));
+        loc3 = lm.createLocation(LocationSpec.create(SimulatedLocation.class).configure("displayName",
"newloc3"));
+
         fabric = app.createAndManageChild(EntitySpec.create(DynamicRegionsFabric.class)
                 .configure("memberSpec", EntitySpec.create(TestEntity.class)));
     }
@@ -240,7 +249,48 @@ public class DynamicRegionsFabricTest extends BrooklynAppUnitTestSupport
{
             if (cause == null && !e.toString().contains("No entity found")) throw
e;
         }
     }
-    
+
+    @Test
+    public void testDifferentFirstMemberSpec() throws Exception {
+        DynamicRegionsFabric fabric = app.createAndManageChild(EntitySpec.create(DynamicRegionsFabric.class)
+                .configure(DynamicRegionsFabric.FIRST_MEMBER_SPEC,
+                        EntitySpec.create(BasicEntity.class).configure(TestEntity.CONF_NAME,
"first"))
+                .configure(DynamicRegionsFabric.MEMBER_SPEC,
+                        EntitySpec.create(BasicEntity.class).configure(TestEntity.CONF_NAME,
"non-first"))
+                .configure(DynamicRegionsFabric.UP_QUORUM_CHECK, QuorumCheck.QuorumChecks.alwaysTrue()));
+        List<Location> locs = ImmutableList.of(loc1, loc2, loc3);
+        fabric.start(locs);
+
+        EntityAsserts.assertAttributeEqualsEventually(fabric, Attributes.SERVICE_STATE_ACTUAL,
Lifecycle.RUNNING);
+        assertTrue(fabric.getAttribute(Attributes.SERVICE_UP));
+
+        assertEquals(fabric.getMembers().size(), 3);
+
+        assertFirstAndNonFirstCounts(fabric.getMembers(), 1, 2);
+
+        // and after re-size
+        fabric.addRegion("localhost:(name=newloc4)");
+        assertFirstAndNonFirstCounts(fabric.getMembers(), 1, 3);
+
+        // and re-size to 1
+        for(Entity r : Iterables.skip(ImmutableSet.copyOf(fabric.getChildren()), 1)) { //
skip 'first', remove the remaining ones
+            fabric.removeRegion(r.getId());
+        }
+        assertFirstAndNonFirstCounts(fabric.getMembers(), 1, 0);
+
+        // and re-size to 0
+        for(Entity r : ImmutableSet.copyOf(fabric.getChildren())) {
+            fabric.removeRegion(r.getId());
+        }
+        assertFirstAndNonFirstCounts(fabric.getMembers(), 0, 0);
+
+        // and back to 3
+        fabric.addRegion("localhost:(name=newloc1)");
+        fabric.addRegion("localhost:(name=newloc2)");
+        fabric.addRegion("localhost:(name=newloc3)");
+        assertFirstAndNonFirstCounts(fabric.getMembers(), 1, 2);
+    }
+
     private List<Location> getLocationsOfChildren(DynamicRegionsFabric fabric) {
         return getLocationsOf(fabric.getChildren());
     }


Mime
View raw message