brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjcorb...@apache.org
Subject [08/16] incubator-brooklyn git commit: Test should wait for feeds to start
Date Tue, 14 Jul 2015 09:35:59 GMT
Test should wait for feeds to start

Feeds will take some time to start after creation (in this case on rebind). Update the test
to handle it.


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

Branch: refs/heads/master
Commit: c6bb3b8c0ad2f0f907f8e16b0f316618d5501b3a
Parents: 30e6b44
Author: Svetoslav Neykov <svetoslav.neykov@cloudsoftcorp.com>
Authored: Fri Jun 12 19:51:47 2015 +0300
Committer: Svetoslav Neykov <svetoslav.neykov@cloudsoftcorp.com>
Committed: Tue Jul 7 17:29:16 2015 +0300

----------------------------------------------------------------------
 .../brooklyn/entity/rebind/RebindFeedTest.java  | 37 +++++++++++++++-----
 1 file changed, 29 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c6bb3b8c/core/src/test/java/brooklyn/entity/rebind/RebindFeedTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/rebind/RebindFeedTest.java b/core/src/test/java/brooklyn/entity/rebind/RebindFeedTest.java
index 18c1edc..4f5acd1 100644
--- a/core/src/test/java/brooklyn/entity/rebind/RebindFeedTest.java
+++ b/core/src/test/java/brooklyn/entity/rebind/RebindFeedTest.java
@@ -50,6 +50,7 @@ import brooklyn.location.Location;
 import brooklyn.location.basic.LocalhostMachineProvisioningLocation;
 import brooklyn.location.basic.SshMachineLocation;
 import brooklyn.management.internal.BrooklynGarbageCollector;
+import brooklyn.test.Asserts;
 import brooklyn.test.EntityTestUtils;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.test.entity.TestEntityImpl.TestEntityWithoutEnrichers;
@@ -62,6 +63,7 @@ import brooklyn.util.time.Duration;
 import brooklyn.util.time.Time;
 
 import com.google.common.base.Function;
+import com.google.common.base.Predicates;
 import com.google.common.base.Supplier;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
@@ -206,8 +208,8 @@ public class RebindFeedTest extends RebindTestFixtureWithApp {
         int expectedCount = 4;
         assertEquals(currentFeeds.size(), expectedCount);
         knownFeeds.addAll(currentFeeds);
-        assertEquals(countActive(knownFeeds), expectedCount);
-        origEntity.setConfig(MyEntityWithNewFeedsEachTimeImpl.MAKE_NEW, !soakTest);
+        assertActiveFeedsEventually(knownFeeds, expectedCount);
+        origEntity.config().set(MyEntityWithNewFeedsEachTimeImpl.MAKE_NEW, !soakTest);
         
         long usedOriginally = -1;
         
@@ -225,7 +227,7 @@ public class RebindFeedTest extends RebindTestFixtureWithApp {
 
             switchOriginalToNewManagementContext();
             waitForTaskCountToBecome(origManagementContext, expectedCount + SYSTEM_TASK_COUNT);
-            assertEquals(countActive(knownFeeds), expectedCount);
+            assertActiveFeedsEventually(knownFeeds, expectedCount);
             knownFeeds.clear();
             knownFeeds.addAll(currentFeeds);
             
@@ -243,13 +245,32 @@ public class RebindFeedTest extends RebindTestFixtureWithApp {
             }
         }
     }
+
+    // Feeds take a while to start, also they do it asynchronously from the rebind. Wait
for them to catch up.
+    private void assertActiveFeedsEventually(List<Feed> knownFeeds, int expectedCount)
{
+        Asserts.eventually(new CountActiveSupplier(knownFeeds), Predicates.equalTo(expectedCount));
+    }
     
-    private int countActive(List<Feed> knownFeeds) {
-        int activeCount=0;
-        for (Feed f: knownFeeds) {
-            if (f.isRunning()) activeCount++;
+    private static class CountActiveSupplier implements Supplier<Integer> {
+        private List<Feed> knownFeeds;
+
+        public CountActiveSupplier(List<Feed> knownFeeds) {
+            this.knownFeeds = knownFeeds;
+        }
+
+        @Override
+        public Integer get() {
+            return countActive(knownFeeds);
         }
-        return activeCount;
+        
+        private int countActive(List<Feed> knownFeeds) {
+            int activeCount=0;
+            for (Feed f: knownFeeds) {
+                if (f.isRunning()) activeCount++;
+            }
+            return activeCount;
+        }
+        
     }
 
     public static class MyEntityWithHttpFeedImpl extends TestEntityWithoutEnrichers {


Mime
View raw message