Repository: incubator-brooklyn Updated Branches: refs/heads/master 7154cc9ec -> cc4ffb9d7
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6f58ef3e/usage/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/AbstractBlueprintTest.java ---------------------------------------------------------------------- diff --git a/usage/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/AbstractBlueprintTest.java b/usage/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/AbstractBlueprintTest.java new file mode 100644 index 0000000..ab73cbf --- /dev/null +++ b/usage/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/AbstractBlueprintTest.java @@ -0,0 +1,202 @@ +/* + * 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.launcher.blueprints; + +import static org.testng.Assert.assertNotEquals; + +import java.io.File; +import java.io.Reader; +import java.io.StringReader; +import java.util.Collection; + +import org.apache.brooklyn.camp.brooklyn.BrooklynCampPlatformLauncherAbstract; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; + +import brooklyn.entity.Application; +import brooklyn.entity.Entity; +import brooklyn.entity.basic.Attributes; +import brooklyn.entity.basic.Entities; +import brooklyn.entity.basic.Lifecycle; +import brooklyn.entity.basic.SoftwareProcess; +import brooklyn.entity.rebind.RebindOptions; +import brooklyn.entity.rebind.RebindTestUtils; +import brooklyn.entity.rebind.persister.FileBasedObjectStore; +import org.apache.brooklyn.launcher.BrooklynLauncher; +import org.apache.brooklyn.launcher.SimpleYamlLauncherForTests; +import org.apache.brooklyn.launcher.camp.BrooklynCampPlatformLauncher; +import brooklyn.management.ManagementContext; +import brooklyn.management.internal.LocalManagementContext; +import brooklyn.test.Asserts; +import brooklyn.test.EntityTestUtils; +import brooklyn.util.ResourceUtils; +import brooklyn.util.os.Os; + +public abstract class AbstractBlueprintTest { + + private static final Logger LOG = LoggerFactory.getLogger(AbstractBlueprintTest.class); + + protected File mementoDir; + protected ClassLoader classLoader = AbstractBlueprintTest.class.getClassLoader(); + + protected ManagementContext mgmt; + protected SimpleYamlLauncherForTests launcher; + protected BrooklynLauncher viewer; + + @BeforeMethod(alwaysRun=true) + public void setUp() throws Exception { + mementoDir = Os.newTempDir(getClass()); + mgmt = createOrigManagementContext(); + LOG.info("Test "+getClass()+" persisting to "+mementoDir); + + launcher = new SimpleYamlLauncherForTests() { + @Override + protected BrooklynCampPlatformLauncherAbstract newPlatformLauncher() { + return new BrooklynCampPlatformLauncher() { + protected ManagementContext newManagementContext() { + return AbstractBlueprintTest.this.mgmt; + } + }; + } + }; + viewer = BrooklynLauncher.newInstance() + .managementContext(mgmt) + .start(); + } + + @AfterMethod(alwaysRun=true) + public void tearDown() throws Exception { + try { + if (mgmt != null) { + for (Application app: mgmt.getApplications()) { + LOG.debug("destroying app "+app+" (managed? "+Entities.isManaged(app)+"; mgmt is "+mgmt+")"); + try { + Entities.destroy(app); + LOG.debug("destroyed app "+app+"; mgmt now "+mgmt); + } catch (Exception e) { + LOG.error("problems destroying app "+app, e); + } + } + } + if (launcher != null) launcher.destroyAll(); + if (viewer != null) viewer.terminate(); + if (mgmt != null) Entities.destroyAll(mgmt); + if (mementoDir != null) FileBasedObjectStore.deleteCompletely(mementoDir); + } catch (Throwable t) { + LOG.error("Caught exception in tearDown method", t); + } finally { + mgmt = null; + launcher = null; + } + } + + protected void runTest(String yamlFile) throws Exception { + final Application app = launcher.launchAppYaml(yamlFile); + + assertNoFires(app); + + Application newApp = rebind(); + assertNoFires(newApp); + } + + protected void runTest(Reader yaml) throws Exception { + final Application app = launcher.launchAppYaml(yaml); + + assertNoFires(app); + + Application newApp = rebind(); + assertNoFires(newApp); + } + + protected void assertNoFires(final Entity app) { + EntityTestUtils.assertAttributeEqualsEventually(app, Attributes.SERVICE_UP, true); + EntityTestUtils.assertAttributeEqualsEventually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); + + Asserts.succeedsEventually(new Runnable() { + public void run() { + for (Entity entity : Entities.descendants(app)) { + assertNotEquals(entity.getAttribute(Attributes.SERVICE_STATE_ACTUAL), Lifecycle.ON_FIRE); + assertNotEquals(entity.getAttribute(Attributes.SERVICE_UP), false); + + if (entity instanceof SoftwareProcess) { + EntityTestUtils.assertAttributeEquals(entity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); + EntityTestUtils.assertAttributeEquals(entity, Attributes.SERVICE_UP, Boolean.TRUE); + } + } + }}); + } + + protected Reader loadYaml(String url, String location) { + String yaml = + "location: "+location+"\n"+ + new ResourceUtils(this).getResourceAsString(url); + return new StringReader(yaml); + } + + + ////////////////////////////////////////////////////////////////// + // FOR REBIND // + // See brooklyn.entity.rebind.RebindTestFixture in core's tests // + ////////////////////////////////////////////////////////////////// + + /** rebinds, and sets newApp */ + protected Application rebind() throws Exception { + return rebind(RebindOptions.create()); + } + + protected Application rebind(RebindOptions options) throws Exception { + ManagementContext origMgmt = mgmt; + ManagementContext newMgmt = createNewManagementContext(); + Collection<Application> origApps = origMgmt.getApplications(); + + options = RebindOptions.create(options); + if (options.classLoader == null) options.classLoader(classLoader); + if (options.mementoDir == null) options.mementoDir(mementoDir); + if (options.origManagementContext == null) options.origManagementContext(origMgmt); + if (options.newManagementContext == null) options.newManagementContext(newMgmt); + + for (Application origApp : origApps) { + RebindTestUtils.waitForPersisted(origApp); + } + + mgmt = options.newManagementContext; + Application newApp = RebindTestUtils.rebind(options); + return newApp; + } + + /** @return A started management context */ + protected LocalManagementContext createOrigManagementContext() { + return RebindTestUtils.managementContextBuilder(mementoDir, classLoader) + .persistPeriodMillis(1) + .forLive(true) + .emptyCatalog(true) + .buildStarted(); + } + + /** @return An unstarted management context */ + protected LocalManagementContext createNewManagementContext() { + return RebindTestUtils.managementContextBuilder(mementoDir, classLoader) + .persistPeriodMillis(1) + .forLive(true) + .emptyCatalog(true) + .buildUnstarted(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6f58ef3e/usage/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/CouchbaseBlueprintTest.java ---------------------------------------------------------------------- diff --git a/usage/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/CouchbaseBlueprintTest.java b/usage/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/CouchbaseBlueprintTest.java new file mode 100644 index 0000000..fde5b41 --- /dev/null +++ b/usage/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/CouchbaseBlueprintTest.java @@ -0,0 +1,69 @@ +/* + * 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.launcher.blueprints; + +import org.testng.annotations.Test; + +public class CouchbaseBlueprintTest extends AbstractBlueprintTest { + + @Test(groups={"Live"}) + public void testCouchbaseNode() throws Exception { + runTest("couchbase-node.yaml"); + } + + @Test(groups={"Live"}) + public void testCouchbaseCluster() throws Exception { + runTest("couchbase-cluster.yaml"); + } + + @Test(groups={"Live"}) + public void testCouchbaseClusterSingleNode() throws Exception { + runTest("couchbase-cluster-singleNode.yaml"); + } + + @Test(groups={"Live"}) + public void testCouchbaseWithPillowfight() throws Exception { + runTest("couchbase-w-pillowfight.yaml"); + } + + /** + * FIXME Failed with "Unable to match required VM template constraints" - caused by NPE: + * Caused by: java.lang.NullPointerException: id + * at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:229) + * at org.jclouds.softlayer.domain.OperatingSystem.<init>(OperatingSystem.java:106) + * at org.jclouds.softlayer.domain.OperatingSystem$Builder.build(OperatingSystem.java:87) + * at org.jclouds.softlayer.domain.ContainerVirtualGuestConfiguration$4.apply(ContainerVirtualGuestConfiguration.java:209) + * at org.jclouds.softlayer.domain.ContainerVirtualGuestConfiguration$4.apply(ContainerVirtualGuestConfiguration.java:206) + * This blueprint uses {minRam: 16384, minCores: 4}. + * Suspect this is already fixed by Andrea Turli in latest jclouds. + */ + @Test(groups={"Live", "WIP"}) + public void testCouchbaseWithLoadgen() throws Exception { + runTest("couchbase-w-loadgen.yaml"); + } + + /** + * FIXME Failed with "Unable to match required VM template constraints" - caused by NPE + * (see error described at {@link #testCouchbaseWithLoadgen()}. + */ + @Test(groups={"Live", "WIP"}) + public void testCouchbaseReplicationWithPillowfight() throws Exception { + runTest("couchbase-replication-w-pillowfight.yaml"); + } +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6f58ef3e/usage/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/MongoDbBlueprintTest.java ---------------------------------------------------------------------- diff --git a/usage/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/MongoDbBlueprintTest.java b/usage/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/MongoDbBlueprintTest.java new file mode 100644 index 0000000..33c8910 --- /dev/null +++ b/usage/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/MongoDbBlueprintTest.java @@ -0,0 +1,51 @@ +/* + * 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.launcher.blueprints; + +import org.testng.annotations.Test; + +public class MongoDbBlueprintTest extends AbstractBlueprintTest { + + // TODO Some tests are failing! Needs investigated. + + @Test(groups={"Integration", "WIP"}) + public void testMongoSharded() throws Exception { + runTest("mongo-sharded.yaml"); + } + + @Test(groups={"Integration"}) + public void testMongoReplicaSet() throws Exception { + runTest("mongo-blueprint.yaml"); + } + + @Test(groups={"Integration"}) + public void testMongoClientAndSingleServer() throws Exception { + runTest("mongo-client-single-server.yaml"); + } + + @Test(groups={"Integration", "WIP"}) + public void testMongoScripts() throws Exception { + runTest("mongo-scripts.yaml"); + } + + @Test(groups="Integration") + public void testMongoSingleServer() throws Exception { + runTest("mongo-single-server-blueprint.yaml"); + } +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6f58ef3e/usage/qa/src/main/java/org/apache/brooklyn/qa/load/SimulatedTheeTierApp.java ---------------------------------------------------------------------- diff --git a/usage/qa/src/main/java/org/apache/brooklyn/qa/load/SimulatedTheeTierApp.java b/usage/qa/src/main/java/org/apache/brooklyn/qa/load/SimulatedTheeTierApp.java index 273d130..7a45b62 100644 --- a/usage/qa/src/main/java/org/apache/brooklyn/qa/load/SimulatedTheeTierApp.java +++ b/usage/qa/src/main/java/org/apache/brooklyn/qa/load/SimulatedTheeTierApp.java @@ -44,7 +44,7 @@ import brooklyn.entity.webapp.JavaWebAppService; import brooklyn.entity.webapp.WebAppService; import brooklyn.entity.webapp.WebAppServiceConstants; import brooklyn.entity.webapp.jboss.JBoss7Server; -import brooklyn.launcher.BrooklynLauncher; +import org.apache.brooklyn.launcher.BrooklynLauncher; import brooklyn.location.basic.PortRanges; import brooklyn.policy.autoscaling.AutoScalerPolicy; import brooklyn.util.CommandLineUtil; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6f58ef3e/usage/qa/src/test/java/org/apache/brooklyn/qa/brooklynnode/SoftlayerObtainPrivateLiveTest.java ---------------------------------------------------------------------- diff --git a/usage/qa/src/test/java/org/apache/brooklyn/qa/brooklynnode/SoftlayerObtainPrivateLiveTest.java b/usage/qa/src/test/java/org/apache/brooklyn/qa/brooklynnode/SoftlayerObtainPrivateLiveTest.java index 17df429..401a37a 100644 --- a/usage/qa/src/test/java/org/apache/brooklyn/qa/brooklynnode/SoftlayerObtainPrivateLiveTest.java +++ b/usage/qa/src/test/java/org/apache/brooklyn/qa/brooklynnode/SoftlayerObtainPrivateLiveTest.java @@ -38,7 +38,7 @@ import brooklyn.entity.brooklynnode.BrooklynEntityMirror; import brooklyn.entity.brooklynnode.BrooklynNode; import brooklyn.entity.brooklynnode.BrooklynNode.DeployBlueprintEffector; import brooklyn.entity.proxying.EntitySpec; -import brooklyn.launcher.BrooklynLauncher; +import org.apache.brooklyn.launcher.BrooklynLauncher; import brooklyn.location.Location; import brooklyn.location.jclouds.JcloudsLocationConfig; import brooklyn.management.ManagementContext; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6f58ef3e/usage/qa/src/test/java/org/apache/brooklyn/qa/load/LoadTest.java ---------------------------------------------------------------------- diff --git a/usage/qa/src/test/java/org/apache/brooklyn/qa/load/LoadTest.java b/usage/qa/src/test/java/org/apache/brooklyn/qa/load/LoadTest.java index d6c479c..2bed408 100644 --- a/usage/qa/src/test/java/org/apache/brooklyn/qa/load/LoadTest.java +++ b/usage/qa/src/test/java/org/apache/brooklyn/qa/load/LoadTest.java @@ -40,7 +40,7 @@ import brooklyn.entity.basic.StartableApplication; import brooklyn.entity.proxying.EntitySpec; import brooklyn.entity.rebind.persister.PersistMode; import brooklyn.entity.trait.Startable; -import brooklyn.launcher.BrooklynLauncher; +import org.apache.brooklyn.launcher.BrooklynLauncher; import brooklyn.location.Location; import brooklyn.management.ManagementContext; import brooklyn.management.ha.HighAvailabilityMode; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6f58ef3e/usage/qa/src/test/java/org/apache/brooklyn/qa/longevity/webcluster/WebClusterApp.java ---------------------------------------------------------------------- diff --git a/usage/qa/src/test/java/org/apache/brooklyn/qa/longevity/webcluster/WebClusterApp.java b/usage/qa/src/test/java/org/apache/brooklyn/qa/longevity/webcluster/WebClusterApp.java index 0d3d694..a9809c1 100644 --- a/usage/qa/src/test/java/org/apache/brooklyn/qa/longevity/webcluster/WebClusterApp.java +++ b/usage/qa/src/test/java/org/apache/brooklyn/qa/longevity/webcluster/WebClusterApp.java @@ -31,7 +31,7 @@ import brooklyn.entity.webapp.ControlledDynamicWebAppCluster; import brooklyn.entity.webapp.jboss.JBoss7Server; import brooklyn.event.AttributeSensor; import brooklyn.event.basic.Sensors; -import brooklyn.launcher.BrooklynLauncher; +import org.apache.brooklyn.launcher.BrooklynLauncher; import brooklyn.policy.EnricherSpec; import brooklyn.policy.autoscaling.AutoScalerPolicy; import brooklyn.util.CommandLineUtil;
