You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by dr...@apache.org on 2018/02/02 10:07:32 UTC
[1/3] brooklyn-server git commit: Fix config key names in
BlockingEntity (in tests)
Repository: brooklyn-server
Updated Branches:
refs/heads/master 8d382ab37 -> f85674e55
Fix config key names in BlockingEntity (in tests)
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/e00a9db6
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/e00a9db6
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/e00a9db6
Branch: refs/heads/master
Commit: e00a9db64a096708758397cdd2d1ea57d2359606
Parents: 8d382ab
Author: Aled Sage <al...@gmail.com>
Authored: Fri Feb 2 09:03:05 2018 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Fri Feb 2 09:03:05 2018 +0000
----------------------------------------------------------------------
.../org/apache/brooklyn/core/test/entity/BlockingEntity.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/e00a9db6/core/src/test/java/org/apache/brooklyn/core/test/entity/BlockingEntity.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/test/entity/BlockingEntity.java b/core/src/test/java/org/apache/brooklyn/core/test/entity/BlockingEntity.java
index dcf3e5c..855bdb5 100644
--- a/core/src/test/java/org/apache/brooklyn/core/test/entity/BlockingEntity.java
+++ b/core/src/test/java/org/apache/brooklyn/core/test/entity/BlockingEntity.java
@@ -44,7 +44,7 @@ public interface BlockingEntity extends TestEntity {
@SetFromFlag("executingShutdownNotificationLatch")
public static final ConfigKey<CountDownLatch> EXECUTING_SHUTDOWN_NOTIFICATION_LATCH = new BasicConfigKey<CountDownLatch>(CountDownLatch.class, "test.executingShutdownNotificationLatch", "");
- public static final ConfigKey<Duration> STARTUP_DELAY = new BasicConfigKey<Duration>(Duration.class, "startupLatch", "Delay before starting");
+ public static final ConfigKey<Duration> STARTUP_DELAY = new BasicConfigKey<Duration>(Duration.class, "startupDelay", "Delay before starting");
- public static final ConfigKey<Duration> SHUTDOWN_DELAY = new BasicConfigKey<Duration>(Duration.class, "startupLatch", "Delay before stopping");
+ public static final ConfigKey<Duration> SHUTDOWN_DELAY = new BasicConfigKey<Duration>(Duration.class, "shutdownDelay", "Delay before stopping");
}
[3/3] brooklyn-server git commit: This closes #944
Posted by dr...@apache.org.
This closes #944
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/f85674e5
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/f85674e5
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/f85674e5
Branch: refs/heads/master
Commit: f85674e551d2e7990f46b3d582f194763599bfd2
Parents: 8d382ab 954b64c
Author: Duncan Godwin <dr...@googlemail.com>
Authored: Fri Feb 2 10:07:23 2018 +0000
Committer: Duncan Godwin <dr...@googlemail.com>
Committed: Fri Feb 2 10:07:23 2018 +0000
----------------------------------------------------------------------
.../core/test/entity/BlockingEntity.java | 4 +-
.../rest/resources/EffectorResourceTest.java | 147 +++++++++++++++++++
2 files changed, 149 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
[2/3] brooklyn-server git commit: Add EffectorResourceTest
Posted by dr...@apache.org.
Add 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/954b64c4
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/954b64c4
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/954b64c4
Branch: refs/heads/master
Commit: 954b64c4129e8f008e96922f40710f18bae97f99
Parents: e00a9db
Author: Aled Sage <al...@gmail.com>
Authored: Fri Feb 2 09:05:29 2018 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Fri Feb 2 09:08:23 2018 +0000
----------------------------------------------------------------------
.../rest/resources/EffectorResourceTest.java | 147 +++++++++++++++++++
1 file changed, 147 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/954b64c4/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
new file mode 100644
index 0000000..3519556
--- /dev/null
+++ b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/EffectorResourceTest.java
@@ -0,0 +1,147 @@
+/*
+ * 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.rest.resources;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+
+import java.util.Map;
+
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.apache.brooklyn.api.entity.EntitySpec;
+import org.apache.brooklyn.api.sensor.AttributeSensor;
+import org.apache.brooklyn.core.config.render.RendererHints;
+import org.apache.brooklyn.core.test.entity.TestEntity;
+import org.apache.brooklyn.entity.stock.BasicApplication;
+import org.apache.brooklyn.rest.api.SensorApi;
+import org.apache.brooklyn.rest.test.config.render.TestRendererHints;
+import org.apache.brooklyn.rest.testing.BrooklynRestResourceTest;
+import org.apache.brooklyn.test.Asserts;
+import org.apache.brooklyn.util.time.Duration;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Stopwatch;
+import com.google.common.collect.Iterables;
+import com.google.gson.Gson;
+
+/**
+ * Test the {@link EffectorApi} implementation.
+ */
+@Test(singleThreaded = true,
+ // by using a different suite name we disallow interleaving other tests between the methods of this test class, which wrecks the test fixtures
+ suiteName = "EffectorResourceTest")
+public class EffectorResourceTest extends BrooklynRestResourceTest {
+
+ BasicApplication app;
+ TestEntity entity;
+
+ @AfterClass(alwaysRun = true)
+ public void tearDown() throws Exception {
+ TestRendererHints.clearRegistry();
+ }
+
+ @BeforeMethod(alwaysRun = true)
+ public void setUpMethod() throws Exception {
+ app = getManagementContext().getEntityManager().createEntity(EntitySpec.create(BasicApplication.class)
+ .child(EntitySpec.create(TestEntity.class)));
+ entity = (TestEntity) Iterables.getOnlyElement(app.getChildren());
+ }
+
+ @Test
+ public void testInvokeEffectorNoArgs() throws Exception {
+ String path = "/applications/"+app.getId()+"/entities/"+entity.getId()+"/effectors/"+"myEffector";
+
+ Response response = client().path(path)
+ .accept(MediaType.APPLICATION_JSON)
+ .post(null);
+ assertEquals(response.getStatus(), 202);
+ Asserts.succeedsEventually(() -> assertTrue(entity.getCallHistory().contains("myEffector")));
+ }
+
+ @Test
+ public void testInvokeEffectorNoArgsBlocking() throws Exception {
+ String path = "/applications/"+app.getId()+"/entities/"+entity.getId()+"/effectors/"+"myEffector";
+
+ Response response = client().path(path)
+ .query("timeout", "0")
+ .accept(MediaType.APPLICATION_JSON)
+ .post(null);
+ assertEquals(response.getStatus(), 202);
+ assertTrue(entity.getCallHistory().contains("myEffector"));
+ }
+
+ @Test
+ public void testInvokeEffectorWithArg() throws Exception {
+ String path = "/applications/"+app.getId()+"/entities/"+entity.getId()+"/effectors/"+"identityEffector";
+
+ Response response = client().path(path)
+ .accept(MediaType.APPLICATION_JSON)
+ .header("Content-Type", MediaType.APPLICATION_JSON)
+ .post("{\"arg\": \"myval\"}");
+ assertEquals(response.getStatus(), 202);
+
+ String responseBody = response.readEntity(String.class);
+ assertTrue(entity.getCallHistory().contains("identityEffector"));
+ assertEquals(responseBody, "myval");
+ }
+
+ @Test
+ public void testInvokeEffectorWithTimeoutWaits() throws Exception {
+ String path = "/applications/"+app.getId()+"/entities/"+entity.getId()+"/effectors/"+"sleepEffector";
+
+ Stopwatch stopwatch = Stopwatch.createStarted();
+ Response response = client().path(path)
+ .query("timeout", "1m")
+ .accept(MediaType.APPLICATION_JSON)
+ .header("Content-Type", MediaType.APPLICATION_JSON)
+ .post("{\"duration\": \"50ms\"}");
+ Duration runDuration = Duration.of(stopwatch);
+ assertEquals(response.getStatus(), 202);
+
+ assertTrue(entity.getCallHistory().contains("sleepEffector"));
+ assertTrue(runDuration.isLongerThan(Duration.millis(40)), "runDuration="+runDuration);
+ }
+
+ @Test
+ public void testInvokeEffectorWithTimeoutTimesOut() throws Exception {
+ String path = "/applications/"+app.getId()+"/entities/"+entity.getId()+"/effectors/"+"sleepEffector";
+
+ Stopwatch stopwatch = Stopwatch.createStarted();
+ Response response = client().path(path)
+ .query("timeout", "1ms")
+ .header("Content-Type", MediaType.APPLICATION_JSON)
+ .accept(MediaType.APPLICATION_JSON)
+ .post("{\"duration\": \"5m\"}");
+ Duration runDuration = Duration.of(stopwatch);
+ assertEquals(response.getStatus(), 202);
+
+ String responseBody = response.readEntity(String.class);
+ 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);
+ }
+}