You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2014/07/14 17:35:59 UTC

[03/11] git commit: Fix randomly failing test.

Fix randomly failing test.

The test was depending on preserving the order of elements in non-preserving
collection implementation (set over the keys of live map). When the instantiated
entities have the same creation time there isn't determinism in picking one of them.
Make the test non-dependant on the insertion order.


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

Branch: refs/heads/master
Commit: b4d1df956f6a651f6965a30fd8ba6dd937ce8551
Parents: ce8ae49
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Authored: Thu Jul 10 16:03:24 2014 +0300
Committer: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Committed: Thu Jul 10 16:03:24 2014 +0300

----------------------------------------------------------------------
 .../java/brooklyn/entity/group/DynamicClusterTest.java  | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/b4d1df95/core/src/test/java/brooklyn/entity/group/DynamicClusterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/group/DynamicClusterTest.java b/core/src/test/java/brooklyn/entity/group/DynamicClusterTest.java
index 654f6d5..191ce17 100644
--- a/core/src/test/java/brooklyn/entity/group/DynamicClusterTest.java
+++ b/core/src/test/java/brooklyn/entity/group/DynamicClusterTest.java
@@ -501,7 +501,7 @@ public class DynamicClusterTest extends BrooklynAppUnitTestSupport {
         final List<Entity> creationOrder = Lists.newArrayList();
         DynamicCluster cluster = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
                 .configure("initialSize", 0)
-                .configure("factory", new EntityFactory() {
+                .configure("factory", new EntityFactory<Entity>() {
                     @Override public Entity newEntity(Map flags, Entity parent) {
                         Entity result = new TestEntityImpl(flags);
                         creationOrder.add(result);
@@ -514,10 +514,18 @@ public class DynamicClusterTest extends BrooklynAppUnitTestSupport {
         assertEquals(cluster.getCurrentSize(), (Integer)2);
         assertEquals(ImmutableSet.copyOf(cluster.getMembers()), ImmutableSet.copyOf(creationOrder), "actual="+cluster.getMembers());
 
+        Collection<Entity> preStopMembers = ImmutableList.copyOf(cluster.getMembers());
+
         // Now stop one
         cluster.resize(1);
         assertEquals(cluster.getCurrentSize(), (Integer)1);
-        assertEquals(ImmutableList.copyOf(cluster.getMembers()), creationOrder.subList(0, 1));
+
+        //Make sure we stopped the entity with the earliest creation time
+        //Could be multiple entities with identical creation time, pick any.
+        Entity remainingEntity = cluster.getMembers().iterator().next();
+        for(Entity entity : preStopMembers) {
+            assertTrue(entity.getCreationTime() >= remainingEntity.getCreationTime());
+        }
     }
 
     @Test