You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by ri...@apache.org on 2018/04/20 12:04:15 UTC

[1/2] brooklyn-server git commit: Fix non-deterministic EffectorResourceTest

Repository: brooklyn-server
Updated Branches:
  refs/heads/master 9a13fff41 -> 70c9e6ac9


Fix non-deterministic EffectorResourceTest


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

Branch: refs/heads/master
Commit: 80d7d1e25ec5aa37065929081a70dbe23b088a8d
Parents: 9a13fff
Author: Aled Sage <al...@gmail.com>
Authored: Fri Apr 20 11:56:24 2018 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Fri Apr 20 11:56:24 2018 +0100

----------------------------------------------------------------------
 .../rest/resources/EffectorResourceTest.java    | 37 +++++++++++++++++---
 1 file changed, 32 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/80d7d1e2/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/EffectorResourceTest.java
----------------------------------------------------------------------
diff --git a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/EffectorResourceTest.java b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/EffectorResourceTest.java
index b395a1f..674fbb0 100644
--- a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/EffectorResourceTest.java
+++ b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/EffectorResourceTest.java
@@ -27,12 +27,13 @@ import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
 import org.apache.brooklyn.api.entity.EntitySpec;
+import org.apache.brooklyn.core.entity.Entities;
 import org.apache.brooklyn.core.test.entity.TestEntity;
 import org.apache.brooklyn.entity.stock.BasicApplication;
+import org.apache.brooklyn.rest.api.EffectorApi;
 import org.apache.brooklyn.rest.testing.BrooklynRestResourceTest;
 import org.apache.brooklyn.test.Asserts;
 import org.apache.brooklyn.util.time.Duration;
-import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 import com.google.common.base.Stopwatch;
@@ -50,13 +51,23 @@ public class EffectorResourceTest extends BrooklynRestResourceTest {
     BasicApplication app;
     TestEntity entity;
 
-    @BeforeMethod(alwaysRun = true)
-    public void setUpMethod() throws Exception {
+    @Override
+    public void initMethod() throws Exception {
+        super.initMethod();
         app = getManagementContext().getEntityManager().createEntity(EntitySpec.create(BasicApplication.class)
                 .child(EntitySpec.create(TestEntity.class)));
         entity = (TestEntity) Iterables.getOnlyElement(app.getChildren());
     }
 
+    @Override
+    public void destroyMethod() throws Exception {
+        try {
+            if (app != null) Entities.destroy(app);
+        } finally {
+            super.destroyMethod();
+        }
+    }
+
     @Test
     public void testInvokeEffectorNoArgs() throws Exception {
         String path = "/applications/"+app.getId()+"/entities/"+entity.getId()+"/effectors/"+"myEffector";
@@ -114,6 +125,18 @@ public class EffectorResourceTest extends BrooklynRestResourceTest {
     
     @Test
     public void testInvokeEffectorWithTimeoutTimesOut() throws Exception {
+        /*
+         * The effector is invoked via:
+         *   Task<?> task = entity.invoke(effector.get(), parameters)
+         *   task.get(timeout)
+         * On timeout, the task is not cancelled. The effector keeps executing in the background.
+         * 
+         * The task might not yet have reached the effector body's sleep. It sometimes is
+         * still setting up the call (e.g. preparing the effector args).
+         * 
+         * The response returned is a snapshot of the task's state/stacktrace at the time
+         * of the timeout.
+         */
         String path = "/applications/"+app.getId()+"/entities/"+entity.getId()+"/effectors/"+"sleepEffector";
 
         Stopwatch stopwatch = Stopwatch.createStarted();
@@ -126,12 +149,16 @@ public class EffectorResourceTest extends BrooklynRestResourceTest {
         assertEquals(response.getStatus(), 202);
         
         String responseBody = response.readEntity(String.class);
-        assertTrue(entity.getCallHistory().contains("sleepEffector"));
+        Asserts.succeedsEventually(() -> assertTrue(entity.getCallHistory().contains("sleepEffector")));
         assertTrue(runDuration.isShorterThan(Asserts.DEFAULT_LONG_TIMEOUT), "runDuration="+runDuration);
         
         // Expect to get a task back, representing the currently executing effector
         Map<?,?> responseMap = new Gson().fromJson(responseBody, Map.class);
         assertTrue((""+responseMap.get("displayName")).contains("sleepEffector"), "responseMap="+responseMap);
-        assertTrue((""+responseMap.get("detailedStatus")).contains("In progress, thread waiting"), "responseMap="+responseMap);
+        
+        String detailedStatus = ""+responseMap.get("detailedStatus");
+        boolean taskSleeping = detailedStatus.contains("In progress, thread waiting") && detailedStatus.contains("TestEntityImpl.sleepEffector");
+        boolean taskPreparing = detailedStatus.contains("In progress (RUNNABLE)") && detailedStatus.contains("EffectorUtils.invokeMethodEffector");
+        assertTrue(taskSleeping || taskPreparing, "responseMap="+responseMap);
     }
 }


[2/2] brooklyn-server git commit: Merge and close #958

Posted by ri...@apache.org.
Merge and close #958


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

Branch: refs/heads/master
Commit: 70c9e6ac9c915b4ad476df99cf453d478c9465a3
Parents: 9a13fff 80d7d1e
Author: Richard Downer <ri...@apache.org>
Authored: Fri Apr 20 13:03:48 2018 +0100
Committer: Richard Downer <ri...@apache.org>
Committed: Fri Apr 20 13:03:48 2018 +0100

----------------------------------------------------------------------
 .../rest/resources/EffectorResourceTest.java    | 37 +++++++++++++++++---
 1 file changed, 32 insertions(+), 5 deletions(-)
----------------------------------------------------------------------