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 2017/02/15 18:57:28 UTC
[05/10] brooklyn-server git commit: add
CompositeEffectorYamlRebindTest
add CompositeEffectorYamlRebindTest
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/8809d5cd
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/8809d5cd
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/8809d5cd
Branch: refs/heads/master
Commit: 8809d5cdde60f65636fafdce2917ea37e550f1e1
Parents: b32581d
Author: Andrea Turli <an...@gmail.com>
Authored: Thu Feb 2 17:34:09 2017 +0100
Committer: Andrea Turli <an...@gmail.com>
Committed: Mon Feb 13 15:16:02 2017 +0100
----------------------------------------------------------------------
.../CompositeEffectorYamlRebindTest.java | 102 +++++++++++++++++++
1 file changed, 102 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/8809d5cd/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/CompositeEffectorYamlRebindTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/CompositeEffectorYamlRebindTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/CompositeEffectorYamlRebindTest.java
new file mode 100644
index 0000000..09a9075
--- /dev/null
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/CompositeEffectorYamlRebindTest.java
@@ -0,0 +1,102 @@
+/*
+ * 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.camp.brooklyn;
+
+import static org.apache.brooklyn.test.Asserts.assertFalse;
+import static org.testng.Assert.assertEquals;
+
+import java.util.List;
+
+import org.apache.brooklyn.api.effector.Effector;
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.core.effector.CompositeEffector;
+import org.apache.brooklyn.core.effector.http.HttpCommandEffector;
+import org.apache.brooklyn.core.entity.EntityPredicates;
+import org.apache.brooklyn.core.entity.StartableApplication;
+import org.apache.brooklyn.core.test.entity.TestEntity;
+import org.apache.brooklyn.util.guava.Maybe;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
+
+@Test
+public class CompositeEffectorYamlRebindTest extends AbstractYamlRebindTest {
+
+ private final static String appId = "my-app-with-composite-effector";
+ private final static String appVersion = "1.0.0-SNAPSHOT";
+ static final String appVersionedId = appId + ":" + appVersion;
+
+ static final String catalogYamlSimple = Joiner.on("\n").join(
+ "brooklyn.catalog:",
+ " id: " + appId,
+ " version: " + appVersion,
+ " itemType: entity",
+ " item:",
+ " type: " + TestEntity.class.getName(),
+ " name: targetEntity",
+ " brooklyn.initializers:",
+ " - type: " + HttpCommandEffector.class.getName(),
+ " brooklyn.config:",
+ " name: myEffector",
+ " description: myDescription",
+ " uri: https://httpbin.org/get?id=myId",
+ " httpVerb: GET",
+ " jsonPath: $.args.id",
+ " publishSensor: results",
+ " - type: " + CompositeEffector.class.getName(),
+ " brooklyn.config:",
+ " name: start",
+ " override: true",
+ " effectors:",
+ " - myEffector"
+ );
+
+ @Test
+ public void testRebindWhenHealthy() throws Exception {
+ runRebindWhenIsUp(catalogYamlSimple, appVersionedId);
+ }
+
+ protected void runRebindWhenIsUp(String catalogYaml, String appId) throws Exception {
+ addCatalogItems(catalogYaml);
+
+ String appYaml = Joiner.on("\n").join(
+ "services: ",
+ "- type: " + appId);
+ createStartWaitAndLogApplication(appYaml);
+
+ // Rebind
+ StartableApplication newApp = rebind();
+ TestEntity testEntity = (TestEntity) Iterables.find(newApp.getChildren(), EntityPredicates.displayNameEqualTo("targetEntity"));
+ Effector effector = assertHasInitializers(testEntity, "start");
+
+ // Confirm HttpCommandEffector still functions
+ Object results = testEntity.invoke(effector, ImmutableMap.<String, Object>of()).get();
+ assertEquals(((List<Object>)results).get(0), "myId");
+ }
+
+
+ protected static Effector<?> assertHasInitializers(Entity entity, String effectorName) {
+ Maybe<Effector<?>> effectorMaybe = entity.getEntityType().getEffectorByName(effectorName);
+ assertFalse(effectorMaybe.isAbsent());
+ return effectorMaybe.get();
+ }
+
+}