Fix BrooklynNodeIntegrationTest

- Tests were failing occasionally, non-deterministically. Fix is to 
  wait for the required number of apps rather than just getting back
  a 200 (which could be with an empty list of apps).

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

Branch: refs/heads/master
Commit: e2dfb3b31a6ce1d861895f9cc52637f22fe057c9
Parents: cda838a
Author: Aled Sage <[email protected]>
Authored: Mon Jun 22 00:18:32 2015 +0100
Committer: Aled Sage <[email protected]>
Committed: Mon Jun 22 00:18:32 2015 +0100

----------------------------------------------------------------------
 .../BrooklynNodeIntegrationTest.java             | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2dfb3b3/software/base/src/test/java/brooklyn/entity/brooklynnode/BrooklynNodeIntegrationTest.java
----------------------------------------------------------------------
diff --git 
a/software/base/src/test/java/brooklyn/entity/brooklynnode/BrooklynNodeIntegrationTest.java
 
b/software/base/src/test/java/brooklyn/entity/brooklynnode/BrooklynNodeIntegrationTest.java
index 00586fd..ba6cd92 100644
--- 
a/software/base/src/test/java/brooklyn/entity/brooklynnode/BrooklynNodeIntegrationTest.java
+++ 
b/software/base/src/test/java/brooklyn/entity/brooklynnode/BrooklynNodeIntegrationTest.java
@@ -60,6 +60,7 @@ import 
brooklyn.location.basic.LocalhostMachineProvisioningLocation;
 import brooklyn.location.basic.Locations;
 import brooklyn.location.basic.PortRanges;
 import brooklyn.location.basic.SshMachineLocation;
+import brooklyn.test.Asserts;
 import brooklyn.test.EntityTestUtils;
 import brooklyn.test.HttpTestUtils;
 import brooklyn.util.collections.MutableMap;
@@ -350,7 +351,7 @@ services:
         log.info("started "+app+" containing "+brooklynNode+" for 
"+JavaClassNames.niceClassAndMethod());
 
         URI webConsoleUri = 
brooklynNode.getAttribute(BrooklynNode.WEB_CONSOLE_URI);
-        waitForApps(webConsoleUri.toString());
+        waitForApps(webConsoleUri, 1);
         String apps = 
HttpTestUtils.getContent(webConsoleUri.toString()+"/v1/applications");
         List<String> appType = parseJsonList(apps, ImmutableList.of("spec", 
"type"), String.class);
         assertEquals(appType, 
ImmutableList.of(BasicApplication.class.getName()));
@@ -361,6 +362,18 @@ services:
         
HttpTestUtils.assertHttpStatusCodeEventuallyEquals(webConsoleUri+"/v1/applications",
 200);
     }
 
+    protected void waitForApps(final URI webConsoleUri, final int num) {
+        waitForApps(webConsoleUri.toString());
+        
+        // e.g. [{"id":"UnBqPcqg","spec":{"name":"Application 
(UnBqPcqg)","type":"brooklyn.entity.basic.BasicApplication","locations":["pOL4NtiW"]},"status":"RUNNING","links":{"self":"/v1/applications/UnBqPcqg","entities":"/v1/applications/UnBqPcqg/entities"}}]
+        Asserts.succeedsEventually(new Runnable() {
+            public void run() {
+                String appsContent = 
HttpTestUtils.getContent(webConsoleUri.toString()+"/v1/applications");
+                List<String> appIds = parseJsonList(appsContent, 
ImmutableList.of("id"), String.class);
+                assertEquals(appIds.size(), num);
+            }});
+    }
+
     @Test(groups="Integration")
     public void testStartsAppViaEffector() throws Exception {
         BrooklynNode brooklynNode = 
app.createAndManageChild(newBrooklynNodeSpecForTest());
@@ -400,7 +413,7 @@ services:
         log.info("started "+app+" containing "+brooklynNode+" for 
"+JavaClassNames.niceClassAndMethod());
 
         URI webConsoleUri = 
brooklynNode.getAttribute(BrooklynNode.WEB_CONSOLE_URI);
-        waitForApps(webConsoleUri.toString());
+        waitForApps(webConsoleUri, 1);
 
         // Check that "mynamedloc" has been picked up from the 
brooklyn.properties
         String locsContent = 
HttpTestUtils.getContent(webConsoleUri.toString()+"/v1/locations");
@@ -498,7 +511,7 @@ services:
         File pidFile = new File(getDriver(brooklynNode).getPidFile());
         URI webConsoleUri = 
brooklynNode.getAttribute(BrooklynNode.WEB_CONSOLE_URI);
 
-        waitForApps(webConsoleUri.toString());
+        waitForApps(webConsoleUri, 1);
 
         // Stop just the process; will not have unmanaged entity unless 
machine was being terminated 
         brooklynNode.invoke(BrooklynNode.STOP, ImmutableMap.<String, Object>of(

Reply via email to