[SERVER] [LIBRARY] moved webapp related CAMP tests to brooklyn-library
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/d49445da Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/d49445da Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/d49445da Branch: refs/heads/master Commit: d49445da7a15044cd45727029758ffc2bcd63415 Parents: 1c7e36a Author: John McCabe <[email protected]> Authored: Wed Dec 16 19:44:07 2015 +0000 Committer: Alex Heneveld <[email protected]> Committed: Mon Dec 21 16:43:35 2015 +0000 ---------------------------------------------------------------------- .../camp/EnrichersSlightlySimplerYamlTest.java | 133 +++++++++ .../test/camp/EntitiesYamlIntegrationTest.java | 70 +++++ .../test/camp/JavaWebAppsIntegrationTest.java | 273 +++++++++++++++++++ .../EnrichersSlightlySimplerYamlTest.java | 133 --------- .../brooklyn/EntitiesYamlIntegrationTest.java | 70 ----- .../brooklyn/JavaWebAppsIntegrationTest.java | 273 ------------------- 6 files changed, 476 insertions(+), 476 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/d49445da/brooklyn-library/software/webapp/src/test/java/org/apache/brooklyn/test/camp/EnrichersSlightlySimplerYamlTest.java ---------------------------------------------------------------------- diff --git a/brooklyn-library/software/webapp/src/test/java/org/apache/brooklyn/test/camp/EnrichersSlightlySimplerYamlTest.java b/brooklyn-library/software/webapp/src/test/java/org/apache/brooklyn/test/camp/EnrichersSlightlySimplerYamlTest.java new file mode 100644 index 0000000..fb46789 --- /dev/null +++ b/brooklyn-library/software/webapp/src/test/java/org/apache/brooklyn/test/camp/EnrichersSlightlySimplerYamlTest.java @@ -0,0 +1,133 @@ +/* + * 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 java.net.URI; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import org.apache.brooklyn.api.entity.Entity; +import org.apache.brooklyn.core.entity.Attributes; +import org.apache.brooklyn.core.entity.Entities; +import org.apache.brooklyn.core.entity.EntityInternal; +import org.apache.brooklyn.core.sensor.Sensors; +import org.apache.brooklyn.entity.group.DynamicCluster; +import org.apache.brooklyn.entity.webapp.JavaWebAppSoftwareProcess; +import org.apache.brooklyn.test.EntityTestUtils; +import org.apache.brooklyn.util.collections.CollectionFunctionals; +import org.apache.brooklyn.util.collections.MutableList; +import org.apache.brooklyn.util.math.MathPredicates; +import org.apache.brooklyn.util.text.StringPredicates; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.Assert; +import org.testng.annotations.Test; + +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; +import com.google.common.collect.Iterables; + +/** Tests some improvements to enricher classes to make them a bit more yaml friendly. + * Called "SlightlySimpler" as it would be nice to make enrichers a lot more yaml friendly! */ +@Test +public class EnrichersSlightlySimplerYamlTest extends AbstractYamlTest { + private static final Logger log = LoggerFactory.getLogger(EnrichersSlightlySimplerYamlTest.class); + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Test + public void testWithAppEnricher() throws Exception { + Entity app = createAndStartApplication(loadYaml("test-app-with-enrichers-slightly-simpler.yaml")); + waitForApplicationTasks(app); + log.info("Started "+app+":"); + Entities.dumpInfo(app); + + Entity cluster = Iterables.getOnlyElement( app.getChildren() ); + Collection<Entity> leafs = ((DynamicCluster)cluster).getMembers(); + Iterator<Entity> li = leafs.iterator(); + + Entity e1 = li.next(); + ((EntityInternal)e1).sensors().set(Sensors.newStringSensor("ip"), "127.0.0.1"); + EntityTestUtils.assertAttributeEqualsEventually(e1, Sensors.newStringSensor("url"), "http://127.0.0.1/"); + EntityTestUtils.assertAttributeEqualsEventually(e1, Attributes.MAIN_URI, URI.create("http://127.0.0.1/")); + + int i=2; + while (li.hasNext()) { + Entity ei = li.next(); + ((EntityInternal)ei).sensors().set(Sensors.newStringSensor("ip"), "127.0.0."+i); + i++; + } + + EntityTestUtils.assertAttributeEventually(cluster, Sensors.newSensor(Iterable.class, "urls.list"), + (Predicate)CollectionFunctionals.sizeEquals(3)); + + EntityTestUtils.assertAttributeEventually(cluster, Sensors.newSensor(String.class, "urls.list.comma_separated.max_2"), + StringPredicates.matchesRegex("\"http:\\/\\/127[^\"]*\\/\",\"http:\\/\\/127[^\"]*\\/\"")); + + EntityTestUtils.assertAttributeEventually(cluster, Attributes.MAIN_URI, Predicates.notNull()); + URI main = cluster.getAttribute(Attributes.MAIN_URI); + Assert.assertTrue(main.toString().matches("http:\\/\\/127.0.0..\\/"), "Wrong URI: "+main); + + EntityTestUtils.assertAttributeEventually(app, Attributes.MAIN_URI, Predicates.notNull()); + main = app.getAttribute(Attributes.MAIN_URI); + Assert.assertTrue(main.toString().matches("http:\\/\\/127.0.0..\\/"), "Wrong URI: "+main); + + // TODO would we want to allow "all-but-usual" as the default if nothing specified + } + + @Test(groups="Integration") + public void testWebappWithAveragingEnricher() throws Exception { + Entity app = createAndStartApplication(loadYaml("test-webapp-with-averaging-enricher.yaml")); + waitForApplicationTasks(app); + log.info("Started "+app+":"); + Entities.dumpInfo(app); + + List<JavaWebAppSoftwareProcess> appservers = MutableList.copyOf(Entities.descendants(app, JavaWebAppSoftwareProcess.class)); + Assert.assertEquals(appservers.size(), 3); + + EntityInternal srv0 = (EntityInternal) appservers.get(0); + EntityInternal dwac = (EntityInternal) srv0.getParent(); + EntityInternal cdwac = (EntityInternal) dwac.getParent(); + + srv0.sensors().set(Sensors.newDoubleSensor("my.load"), 20.0); + + EntityTestUtils.assertAttributeEventually(dwac, Sensors.newSensor(Double.class, "my.load.averaged"), + MathPredicates.equalsApproximately(20)); + EntityTestUtils.assertAttributeEventually(cdwac, Sensors.newSensor(Double.class, "my.load.averaged"), + MathPredicates.equalsApproximately(20)); + + srv0.sensors().set(Sensors.newDoubleSensor("my.load"), null); + EntityTestUtils.assertAttributeEventually(cdwac, Sensors.newSensor(Double.class, "my.load.averaged"), + Predicates.isNull()); + + ((EntityInternal) appservers.get(1)).sensors().set(Sensors.newDoubleSensor("my.load"), 10.0); + ((EntityInternal) appservers.get(2)).sensors().set(Sensors.newDoubleSensor("my.load"), 20.0); + EntityTestUtils.assertAttributeEventually(cdwac, Sensors.newSensor(Double.class, "my.load.averaged"), + MathPredicates.equalsApproximately(15)); + srv0.sensors().set(Sensors.newDoubleSensor("my.load"), 0.0); + EntityTestUtils.assertAttributeEventually(cdwac, Sensors.newSensor(Double.class, "my.load.averaged"), + MathPredicates.equalsApproximately(10)); + } + + @Override + protected Logger getLogger() { + return log; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/d49445da/brooklyn-library/software/webapp/src/test/java/org/apache/brooklyn/test/camp/EntitiesYamlIntegrationTest.java ---------------------------------------------------------------------- diff --git a/brooklyn-library/software/webapp/src/test/java/org/apache/brooklyn/test/camp/EntitiesYamlIntegrationTest.java b/brooklyn-library/software/webapp/src/test/java/org/apache/brooklyn/test/camp/EntitiesYamlIntegrationTest.java new file mode 100644 index 0000000..c511e82 --- /dev/null +++ b/brooklyn-library/software/webapp/src/test/java/org/apache/brooklyn/test/camp/EntitiesYamlIntegrationTest.java @@ -0,0 +1,70 @@ +/* + * 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.testng.Assert.*; + +import org.apache.brooklyn.api.entity.Entity; +import org.apache.brooklyn.api.entity.EntitySpec; +import org.apache.brooklyn.entity.group.DynamicCluster; +import org.apache.brooklyn.entity.proxy.nginx.NginxController; +import org.apache.brooklyn.entity.webapp.ControlledDynamicWebAppCluster; +import org.apache.brooklyn.entity.webapp.tomcat.TomcatServer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.annotations.Test; + +import com.google.common.collect.FluentIterable; +import com.google.common.collect.Iterables; + +public class EntitiesYamlIntegrationTest extends AbstractYamlTest { + + private static final Logger LOG = LoggerFactory.getLogger(EntitiesYamlIntegrationTest.class); + + @Test(groups = "Integration") + public void testStartTomcatCluster() throws Exception { + Entity app = createAndStartApplication(loadYaml("test-tomcat-cluster.yaml")); + waitForApplicationTasks(app); + + assertNotNull(app); + assertEquals(app.getChildren().size(), 1); + final Entity entity = Iterables.getOnlyElement(app.getChildren()); + assertTrue(entity instanceof ControlledDynamicWebAppCluster, "entity="+entity); + ControlledDynamicWebAppCluster cluster = (ControlledDynamicWebAppCluster) entity; + + assertTrue(cluster.getController() instanceof NginxController, "controller="+cluster.getController()); + Iterable<TomcatServer> tomcats = FluentIterable.from(cluster.getCluster().getMembers()).filter(TomcatServer.class); + assertEquals(Iterables.size(tomcats), 2); + for (TomcatServer tomcat : tomcats) { + assertTrue(tomcat.getAttribute(TomcatServer.SERVICE_UP), "serviceup"); + } + + EntitySpec<?> spec = entity.getConfig(DynamicCluster.MEMBER_SPEC); + assertNotNull(spec); + assertEquals(spec.getType(), TomcatServer.class); + assertEquals(spec.getConfig().get(DynamicCluster.QUARANTINE_FAILED_ENTITIES), Boolean.FALSE); + assertEquals(spec.getConfig().get(DynamicCluster.INITIAL_QUORUM_SIZE), 2); + } + + + @Override + protected Logger getLogger() { + return LOG; + } +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/d49445da/brooklyn-library/software/webapp/src/test/java/org/apache/brooklyn/test/camp/JavaWebAppsIntegrationTest.java ---------------------------------------------------------------------- diff --git a/brooklyn-library/software/webapp/src/test/java/org/apache/brooklyn/test/camp/JavaWebAppsIntegrationTest.java b/brooklyn-library/software/webapp/src/test/java/org/apache/brooklyn/test/camp/JavaWebAppsIntegrationTest.java new file mode 100644 index 0000000..3d991db --- /dev/null +++ b/brooklyn-library/software/webapp/src/test/java/org/apache/brooklyn/test/camp/JavaWebAppsIntegrationTest.java @@ -0,0 +1,273 @@ +/* + * 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 com.google.common.base.Preconditions.checkNotNull; + +import java.io.IOException; +import java.io.Reader; +import java.util.Iterator; +import java.util.Set; +import java.util.concurrent.Callable; +import java.util.concurrent.atomic.AtomicInteger; + +import org.apache.brooklyn.api.entity.Entity; +import org.apache.brooklyn.api.mgmt.ManagementContext; +import org.apache.brooklyn.api.mgmt.Task; +import org.apache.brooklyn.api.policy.Policy; +import org.apache.brooklyn.camp.brooklyn.BrooklynCampPlatform; +import org.apache.brooklyn.camp.brooklyn.BrooklynCampPlatformLauncherNoServer; +import org.apache.brooklyn.camp.spi.Assembly; +import org.apache.brooklyn.camp.spi.AssemblyTemplate; +import org.apache.brooklyn.camp.spi.PlatformComponent; +import org.apache.brooklyn.camp.spi.PlatformRootSummary; +import org.apache.brooklyn.camp.spi.collection.ResolvableLink; +import org.apache.brooklyn.core.entity.Attributes; +import org.apache.brooklyn.core.entity.Entities; +import org.apache.brooklyn.core.entity.lifecycle.Lifecycle; +import org.apache.brooklyn.core.mgmt.BrooklynTaskTags; +import org.apache.brooklyn.entity.webapp.DynamicWebAppCluster; +import org.apache.brooklyn.entity.webapp.JavaWebAppService; +import org.apache.brooklyn.entity.webapp.WebAppService; +import org.apache.brooklyn.test.Asserts; +import org.apache.brooklyn.test.EntityTestUtils; +import org.apache.brooklyn.util.collections.MutableMap; +import org.apache.brooklyn.util.core.ResourceUtils; +import org.apache.brooklyn.util.exceptions.Exceptions; +import org.apache.brooklyn.util.net.Urls; +import org.apache.brooklyn.util.stream.Streams; +import org.apache.brooklyn.util.time.Duration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.Assert; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import org.apache.brooklyn.policy.autoscaling.AutoScalerPolicy; + +import com.google.common.collect.Iterables; + +@Test(groups="Integration") +public class JavaWebAppsIntegrationTest { + + private static final Logger log = LoggerFactory.getLogger(JavaWebAppsIntegrationTest.class); + + private ManagementContext brooklynMgmt; + private BrooklynCampPlatform platform; + + @BeforeMethod(alwaysRun=true) + public void setup() { + BrooklynCampPlatformLauncherNoServer launcher = new BrooklynCampPlatformLauncherNoServer(); + launcher.launch(); + brooklynMgmt = launcher.getBrooklynMgmt(); + + platform = new BrooklynCampPlatform( + PlatformRootSummary.builder().name("Brooklyn CAMP Platform").build(), + brooklynMgmt); + } + + @AfterMethod + public void teardown() { + if (brooklynMgmt!=null) Entities.destroyAll(brooklynMgmt); + } + + public void testSimpleYamlDeploy() throws IOException { + Reader input = Streams.reader(new ResourceUtils(this).getResourceFromUrl("java-web-app-simple.yaml")); + AssemblyTemplate at = platform.pdp().registerDeploymentPlan(input); + + try { + Assembly assembly = at.getInstantiator().newInstance().instantiate(at, platform); + log.info("Test - created "+assembly); + + final Entity app = brooklynMgmt.getEntityManager().getEntity(assembly.getId()); + log.info("App - "+app); + Assert.assertEquals(app.getDisplayName(), "sample-single-jboss"); + + // locations set on AT in this yaml + Assert.assertEquals(app.getLocations().size(), 1); + + Set<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(brooklynMgmt.getExecutionManager(), app); + log.info("Waiting on "+tasks.size()+" task(s)"); + for (Task<?> t: tasks) { + t.blockUntilEnded(); + } + + log.info("App started:"); + Entities.dumpInfo(app); + + Assert.assertEquals(app.getChildren().size(), 1); + Assert.assertEquals(app.getChildren().iterator().next().getDisplayName(), "tomcat1"); + Assert.assertEquals(app.getChildren().iterator().next().getLocations().size(), 1); + + final String url = Asserts.succeedsEventually(MutableMap.of("timeout", Duration.TEN_SECONDS), new Callable<String>() { + @Override public String call() throws Exception { + String url = app.getChildren().iterator().next().getAttribute(JavaWebAppService.ROOT_URL); + return checkNotNull(url, "url of %s", app); + }}); + + String site = Asserts.succeedsEventually(MutableMap.of("timeout", Duration.TEN_SECONDS), new Callable<String>() { + @Override public String call() throws Exception { + return new ResourceUtils(this).getResourceAsString(url); + }}); + + log.info("App URL for "+app+": "+url); + Assert.assertTrue(url.contains("928"), "URL should be on port 9280+ based on config set in yaml, url "+url+", app "+app); + Assert.assertTrue(site.toLowerCase().contains("hello"), site); + Assert.assertTrue(!platform.assemblies().isEmpty()); + } catch (Exception e) { + log.warn("Unable to instantiate "+at+" (rethrowing): "+e); + throw Exceptions.propagate(e); + } + } + + public void testWithDbDeploy() throws IOException { + Reader input = Streams.reader(new ResourceUtils(this).getResourceFromUrl("java-web-app-and-db-with-function.yaml")); + AssemblyTemplate at = platform.pdp().registerDeploymentPlan(input); + + try { + Assembly assembly = at.getInstantiator().newInstance().instantiate(at, platform); + log.info("Test - created "+assembly); + + final Entity app = brooklynMgmt.getEntityManager().getEntity(assembly.getId()); + log.info("App - "+app); + + // locations set on individual services here + Assert.assertEquals(app.getLocations().size(), 0); + + Iterator<ResolvableLink<PlatformComponent>> pcs = assembly.getPlatformComponents().links().iterator(); + PlatformComponent pc1 = pcs.next().resolve(); + Entity cluster = brooklynMgmt.getEntityManager().getEntity(pc1.getId()); + log.info("pc1 - "+pc1+" - "+cluster); + + PlatformComponent pc2 = pcs.next().resolve(); + log.info("pc2 - "+pc2); + + Set<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(brooklynMgmt.getExecutionManager(), app); + log.info("Waiting on "+tasks.size()+" task(s)"); + AtomicInteger i = new AtomicInteger(0); + for (Task<?> t: tasks) { + t.blockUntilEnded(); + log.info("Completed task #" + i.incrementAndGet()); + } + + log.info("App started:"); + Entities.dumpInfo(app); + + EntityTestUtils.assertAttributeEqualsEventually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); + Assert.assertEquals(app.getAttribute(Attributes.SERVICE_UP), Boolean.TRUE); + + final String url = Asserts.succeedsEventually(MutableMap.of("timeout", Duration.TEN_SECONDS), new Callable<String>() { + @Override public String call() throws Exception { + Entity cluster = Iterables.getOnlyElement( Iterables.filter(app.getChildren(), WebAppService.class) ); + String url = cluster.getAttribute(JavaWebAppService.ROOT_URL); + return checkNotNull(url, "url of %s", cluster); + }}); + + String site = Asserts.succeedsEventually(MutableMap.of("timeout", Duration.TEN_SECONDS), new Callable<String>() { + @Override public String call() throws Exception { + return new ResourceUtils(this).getResourceAsString(url); + }}); + + log.info("App URL for "+app+": "+url); + Assert.assertTrue(url.contains("921"), "URL should be on port 9280+ based on config set in yaml, url "+url+", app "+app); + Assert.assertTrue(site.toLowerCase().contains("hello"), site); + Assert.assertTrue(!platform.assemblies().isEmpty()); + + String dbPage = new ResourceUtils(this).getResourceAsString(Urls.mergePaths(url, "db.jsp")); + Assert.assertTrue(dbPage.contains("Isaac Asimov"), "db.jsp does not mention Isaac Asimov, probably the DB did not get initialised:\n"+dbPage); + } catch (Exception e) { + log.warn("Unable to instantiate "+at+" (rethrowing): "+e); + throw Exceptions.propagate(e); + } + } + + public void testWithPolicyDeploy() { + Reader input = Streams.reader(new ResourceUtils(this).getResourceFromUrl("java-web-app-and-db-with-policy.yaml")); + AssemblyTemplate at = platform.pdp().registerDeploymentPlan(input); + + try { + Assembly assembly = at.getInstantiator().newInstance().instantiate(at, platform); + log.info("Test - created "+assembly); + + final Entity app = brooklynMgmt.getEntityManager().getEntity(assembly.getId()); + log.info("App - "+app); + + // locations set on individual services here + Assert.assertEquals(app.getLocations().size(), 0); + + Set<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(brooklynMgmt.getExecutionManager(), app); + log.info("Waiting on "+tasks.size()+" task(s)"); + for (Task<?> t: tasks) { + t.blockUntilEnded(); + } + + log.info("App started:"); + Entities.dumpInfo(app); + + Iterator<ResolvableLink<PlatformComponent>> pcs = assembly.getPlatformComponents().links().iterator(); + PlatformComponent clusterComponent = null; + while (pcs.hasNext() && clusterComponent == null) { + PlatformComponent component = pcs.next().resolve(); + if (component.getName().equals("My Web with Policy")) + clusterComponent = component; + } + Assert.assertNotNull(clusterComponent, "Database PlatformComponent not found"); + Entity cluster = brooklynMgmt.getEntityManager().getEntity(clusterComponent.getId()); + log.info("pc1 - "+clusterComponent+" - "+cluster); + + Assert.assertEquals(cluster.policies().size(), 1); + Policy policy = cluster.policies().iterator().next(); + Assert.assertNotNull(policy); + Assert.assertTrue(policy instanceof AutoScalerPolicy, "policy="+policy); + Assert.assertEquals(policy.getConfig(AutoScalerPolicy.MAX_POOL_SIZE), (Integer)5); + Assert.assertEquals(policy.getConfig(AutoScalerPolicy.MIN_POOL_SIZE), (Integer)1); + Assert.assertEquals(policy.getConfig(AutoScalerPolicy.METRIC), DynamicWebAppCluster.REQUESTS_PER_SECOND_IN_WINDOW_PER_NODE); + Assert.assertEquals(policy.getConfig(AutoScalerPolicy.METRIC_LOWER_BOUND), (Integer)10); + Assert.assertEquals(policy.getConfig(AutoScalerPolicy.METRIC_UPPER_BOUND), (Integer)100); + Assert.assertTrue(policy.isRunning()); + + EntityTestUtils.assertAttributeEqualsEventually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); + Assert.assertEquals(app.getAttribute(Attributes.SERVICE_UP), Boolean.TRUE); + + final String url = Asserts.succeedsEventually(MutableMap.of("timeout", Duration.TEN_SECONDS), new Callable<String>() { + @Override public String call() throws Exception { + Entity cluster = Iterables.getOnlyElement( Iterables.filter(app.getChildren(), WebAppService.class) ); + String url = cluster.getAttribute(JavaWebAppService.ROOT_URL); + return checkNotNull(url, "url of %s", cluster); + }}); + + String site = Asserts.succeedsEventually(MutableMap.of("timeout", Duration.TEN_SECONDS), new Callable<String>() { + @Override public String call() throws Exception { + return new ResourceUtils(this).getResourceAsString(url); + }}); + + log.info("App URL for "+app+": "+url); + Assert.assertTrue(url.contains("921"), "URL should be on port 9280+ based on config set in yaml, url "+url+", app "+app); + Assert.assertTrue(site.toLowerCase().contains("hello"), site); + Assert.assertTrue(!platform.assemblies().isEmpty()); + + String dbPage = new ResourceUtils(this).getResourceAsString(Urls.mergePaths(url, "db.jsp")); + Assert.assertTrue(dbPage.contains("Isaac Asimov"), "db.jsp does not mention Isaac Asimov, probably the DB did not get initialised:\n"+dbPage); + } catch (Exception e) { + log.warn("Unable to instantiate "+at+" (rethrowing): "+e); + throw Exceptions.propagate(e); + } + } + +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/d49445da/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/EnrichersSlightlySimplerYamlTest.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/EnrichersSlightlySimplerYamlTest.java b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/EnrichersSlightlySimplerYamlTest.java deleted file mode 100644 index fb46789..0000000 --- a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/EnrichersSlightlySimplerYamlTest.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * 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 java.net.URI; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - -import org.apache.brooklyn.api.entity.Entity; -import org.apache.brooklyn.core.entity.Attributes; -import org.apache.brooklyn.core.entity.Entities; -import org.apache.brooklyn.core.entity.EntityInternal; -import org.apache.brooklyn.core.sensor.Sensors; -import org.apache.brooklyn.entity.group.DynamicCluster; -import org.apache.brooklyn.entity.webapp.JavaWebAppSoftwareProcess; -import org.apache.brooklyn.test.EntityTestUtils; -import org.apache.brooklyn.util.collections.CollectionFunctionals; -import org.apache.brooklyn.util.collections.MutableList; -import org.apache.brooklyn.util.math.MathPredicates; -import org.apache.brooklyn.util.text.StringPredicates; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.google.common.base.Predicate; -import com.google.common.base.Predicates; -import com.google.common.collect.Iterables; - -/** Tests some improvements to enricher classes to make them a bit more yaml friendly. - * Called "SlightlySimpler" as it would be nice to make enrichers a lot more yaml friendly! */ -@Test -public class EnrichersSlightlySimplerYamlTest extends AbstractYamlTest { - private static final Logger log = LoggerFactory.getLogger(EnrichersSlightlySimplerYamlTest.class); - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @Test - public void testWithAppEnricher() throws Exception { - Entity app = createAndStartApplication(loadYaml("test-app-with-enrichers-slightly-simpler.yaml")); - waitForApplicationTasks(app); - log.info("Started "+app+":"); - Entities.dumpInfo(app); - - Entity cluster = Iterables.getOnlyElement( app.getChildren() ); - Collection<Entity> leafs = ((DynamicCluster)cluster).getMembers(); - Iterator<Entity> li = leafs.iterator(); - - Entity e1 = li.next(); - ((EntityInternal)e1).sensors().set(Sensors.newStringSensor("ip"), "127.0.0.1"); - EntityTestUtils.assertAttributeEqualsEventually(e1, Sensors.newStringSensor("url"), "http://127.0.0.1/"); - EntityTestUtils.assertAttributeEqualsEventually(e1, Attributes.MAIN_URI, URI.create("http://127.0.0.1/")); - - int i=2; - while (li.hasNext()) { - Entity ei = li.next(); - ((EntityInternal)ei).sensors().set(Sensors.newStringSensor("ip"), "127.0.0."+i); - i++; - } - - EntityTestUtils.assertAttributeEventually(cluster, Sensors.newSensor(Iterable.class, "urls.list"), - (Predicate)CollectionFunctionals.sizeEquals(3)); - - EntityTestUtils.assertAttributeEventually(cluster, Sensors.newSensor(String.class, "urls.list.comma_separated.max_2"), - StringPredicates.matchesRegex("\"http:\\/\\/127[^\"]*\\/\",\"http:\\/\\/127[^\"]*\\/\"")); - - EntityTestUtils.assertAttributeEventually(cluster, Attributes.MAIN_URI, Predicates.notNull()); - URI main = cluster.getAttribute(Attributes.MAIN_URI); - Assert.assertTrue(main.toString().matches("http:\\/\\/127.0.0..\\/"), "Wrong URI: "+main); - - EntityTestUtils.assertAttributeEventually(app, Attributes.MAIN_URI, Predicates.notNull()); - main = app.getAttribute(Attributes.MAIN_URI); - Assert.assertTrue(main.toString().matches("http:\\/\\/127.0.0..\\/"), "Wrong URI: "+main); - - // TODO would we want to allow "all-but-usual" as the default if nothing specified - } - - @Test(groups="Integration") - public void testWebappWithAveragingEnricher() throws Exception { - Entity app = createAndStartApplication(loadYaml("test-webapp-with-averaging-enricher.yaml")); - waitForApplicationTasks(app); - log.info("Started "+app+":"); - Entities.dumpInfo(app); - - List<JavaWebAppSoftwareProcess> appservers = MutableList.copyOf(Entities.descendants(app, JavaWebAppSoftwareProcess.class)); - Assert.assertEquals(appservers.size(), 3); - - EntityInternal srv0 = (EntityInternal) appservers.get(0); - EntityInternal dwac = (EntityInternal) srv0.getParent(); - EntityInternal cdwac = (EntityInternal) dwac.getParent(); - - srv0.sensors().set(Sensors.newDoubleSensor("my.load"), 20.0); - - EntityTestUtils.assertAttributeEventually(dwac, Sensors.newSensor(Double.class, "my.load.averaged"), - MathPredicates.equalsApproximately(20)); - EntityTestUtils.assertAttributeEventually(cdwac, Sensors.newSensor(Double.class, "my.load.averaged"), - MathPredicates.equalsApproximately(20)); - - srv0.sensors().set(Sensors.newDoubleSensor("my.load"), null); - EntityTestUtils.assertAttributeEventually(cdwac, Sensors.newSensor(Double.class, "my.load.averaged"), - Predicates.isNull()); - - ((EntityInternal) appservers.get(1)).sensors().set(Sensors.newDoubleSensor("my.load"), 10.0); - ((EntityInternal) appservers.get(2)).sensors().set(Sensors.newDoubleSensor("my.load"), 20.0); - EntityTestUtils.assertAttributeEventually(cdwac, Sensors.newSensor(Double.class, "my.load.averaged"), - MathPredicates.equalsApproximately(15)); - srv0.sensors().set(Sensors.newDoubleSensor("my.load"), 0.0); - EntityTestUtils.assertAttributeEventually(cdwac, Sensors.newSensor(Double.class, "my.load.averaged"), - MathPredicates.equalsApproximately(10)); - } - - @Override - protected Logger getLogger() { - return log; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/d49445da/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/EntitiesYamlIntegrationTest.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/EntitiesYamlIntegrationTest.java b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/EntitiesYamlIntegrationTest.java deleted file mode 100644 index c511e82..0000000 --- a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/EntitiesYamlIntegrationTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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.testng.Assert.*; - -import org.apache.brooklyn.api.entity.Entity; -import org.apache.brooklyn.api.entity.EntitySpec; -import org.apache.brooklyn.entity.group.DynamicCluster; -import org.apache.brooklyn.entity.proxy.nginx.NginxController; -import org.apache.brooklyn.entity.webapp.ControlledDynamicWebAppCluster; -import org.apache.brooklyn.entity.webapp.tomcat.TomcatServer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.annotations.Test; - -import com.google.common.collect.FluentIterable; -import com.google.common.collect.Iterables; - -public class EntitiesYamlIntegrationTest extends AbstractYamlTest { - - private static final Logger LOG = LoggerFactory.getLogger(EntitiesYamlIntegrationTest.class); - - @Test(groups = "Integration") - public void testStartTomcatCluster() throws Exception { - Entity app = createAndStartApplication(loadYaml("test-tomcat-cluster.yaml")); - waitForApplicationTasks(app); - - assertNotNull(app); - assertEquals(app.getChildren().size(), 1); - final Entity entity = Iterables.getOnlyElement(app.getChildren()); - assertTrue(entity instanceof ControlledDynamicWebAppCluster, "entity="+entity); - ControlledDynamicWebAppCluster cluster = (ControlledDynamicWebAppCluster) entity; - - assertTrue(cluster.getController() instanceof NginxController, "controller="+cluster.getController()); - Iterable<TomcatServer> tomcats = FluentIterable.from(cluster.getCluster().getMembers()).filter(TomcatServer.class); - assertEquals(Iterables.size(tomcats), 2); - for (TomcatServer tomcat : tomcats) { - assertTrue(tomcat.getAttribute(TomcatServer.SERVICE_UP), "serviceup"); - } - - EntitySpec<?> spec = entity.getConfig(DynamicCluster.MEMBER_SPEC); - assertNotNull(spec); - assertEquals(spec.getType(), TomcatServer.class); - assertEquals(spec.getConfig().get(DynamicCluster.QUARANTINE_FAILED_ENTITIES), Boolean.FALSE); - assertEquals(spec.getConfig().get(DynamicCluster.INITIAL_QUORUM_SIZE), 2); - } - - - @Override - protected Logger getLogger() { - return LOG; - } -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/d49445da/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/JavaWebAppsIntegrationTest.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/JavaWebAppsIntegrationTest.java b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/JavaWebAppsIntegrationTest.java deleted file mode 100644 index 3d991db..0000000 --- a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/JavaWebAppsIntegrationTest.java +++ /dev/null @@ -1,273 +0,0 @@ -/* - * 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 com.google.common.base.Preconditions.checkNotNull; - -import java.io.IOException; -import java.io.Reader; -import java.util.Iterator; -import java.util.Set; -import java.util.concurrent.Callable; -import java.util.concurrent.atomic.AtomicInteger; - -import org.apache.brooklyn.api.entity.Entity; -import org.apache.brooklyn.api.mgmt.ManagementContext; -import org.apache.brooklyn.api.mgmt.Task; -import org.apache.brooklyn.api.policy.Policy; -import org.apache.brooklyn.camp.brooklyn.BrooklynCampPlatform; -import org.apache.brooklyn.camp.brooklyn.BrooklynCampPlatformLauncherNoServer; -import org.apache.brooklyn.camp.spi.Assembly; -import org.apache.brooklyn.camp.spi.AssemblyTemplate; -import org.apache.brooklyn.camp.spi.PlatformComponent; -import org.apache.brooklyn.camp.spi.PlatformRootSummary; -import org.apache.brooklyn.camp.spi.collection.ResolvableLink; -import org.apache.brooklyn.core.entity.Attributes; -import org.apache.brooklyn.core.entity.Entities; -import org.apache.brooklyn.core.entity.lifecycle.Lifecycle; -import org.apache.brooklyn.core.mgmt.BrooklynTaskTags; -import org.apache.brooklyn.entity.webapp.DynamicWebAppCluster; -import org.apache.brooklyn.entity.webapp.JavaWebAppService; -import org.apache.brooklyn.entity.webapp.WebAppService; -import org.apache.brooklyn.test.Asserts; -import org.apache.brooklyn.test.EntityTestUtils; -import org.apache.brooklyn.util.collections.MutableMap; -import org.apache.brooklyn.util.core.ResourceUtils; -import org.apache.brooklyn.util.exceptions.Exceptions; -import org.apache.brooklyn.util.net.Urls; -import org.apache.brooklyn.util.stream.Streams; -import org.apache.brooklyn.util.time.Duration; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; -import org.apache.brooklyn.policy.autoscaling.AutoScalerPolicy; - -import com.google.common.collect.Iterables; - -@Test(groups="Integration") -public class JavaWebAppsIntegrationTest { - - private static final Logger log = LoggerFactory.getLogger(JavaWebAppsIntegrationTest.class); - - private ManagementContext brooklynMgmt; - private BrooklynCampPlatform platform; - - @BeforeMethod(alwaysRun=true) - public void setup() { - BrooklynCampPlatformLauncherNoServer launcher = new BrooklynCampPlatformLauncherNoServer(); - launcher.launch(); - brooklynMgmt = launcher.getBrooklynMgmt(); - - platform = new BrooklynCampPlatform( - PlatformRootSummary.builder().name("Brooklyn CAMP Platform").build(), - brooklynMgmt); - } - - @AfterMethod - public void teardown() { - if (brooklynMgmt!=null) Entities.destroyAll(brooklynMgmt); - } - - public void testSimpleYamlDeploy() throws IOException { - Reader input = Streams.reader(new ResourceUtils(this).getResourceFromUrl("java-web-app-simple.yaml")); - AssemblyTemplate at = platform.pdp().registerDeploymentPlan(input); - - try { - Assembly assembly = at.getInstantiator().newInstance().instantiate(at, platform); - log.info("Test - created "+assembly); - - final Entity app = brooklynMgmt.getEntityManager().getEntity(assembly.getId()); - log.info("App - "+app); - Assert.assertEquals(app.getDisplayName(), "sample-single-jboss"); - - // locations set on AT in this yaml - Assert.assertEquals(app.getLocations().size(), 1); - - Set<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(brooklynMgmt.getExecutionManager(), app); - log.info("Waiting on "+tasks.size()+" task(s)"); - for (Task<?> t: tasks) { - t.blockUntilEnded(); - } - - log.info("App started:"); - Entities.dumpInfo(app); - - Assert.assertEquals(app.getChildren().size(), 1); - Assert.assertEquals(app.getChildren().iterator().next().getDisplayName(), "tomcat1"); - Assert.assertEquals(app.getChildren().iterator().next().getLocations().size(), 1); - - final String url = Asserts.succeedsEventually(MutableMap.of("timeout", Duration.TEN_SECONDS), new Callable<String>() { - @Override public String call() throws Exception { - String url = app.getChildren().iterator().next().getAttribute(JavaWebAppService.ROOT_URL); - return checkNotNull(url, "url of %s", app); - }}); - - String site = Asserts.succeedsEventually(MutableMap.of("timeout", Duration.TEN_SECONDS), new Callable<String>() { - @Override public String call() throws Exception { - return new ResourceUtils(this).getResourceAsString(url); - }}); - - log.info("App URL for "+app+": "+url); - Assert.assertTrue(url.contains("928"), "URL should be on port 9280+ based on config set in yaml, url "+url+", app "+app); - Assert.assertTrue(site.toLowerCase().contains("hello"), site); - Assert.assertTrue(!platform.assemblies().isEmpty()); - } catch (Exception e) { - log.warn("Unable to instantiate "+at+" (rethrowing): "+e); - throw Exceptions.propagate(e); - } - } - - public void testWithDbDeploy() throws IOException { - Reader input = Streams.reader(new ResourceUtils(this).getResourceFromUrl("java-web-app-and-db-with-function.yaml")); - AssemblyTemplate at = platform.pdp().registerDeploymentPlan(input); - - try { - Assembly assembly = at.getInstantiator().newInstance().instantiate(at, platform); - log.info("Test - created "+assembly); - - final Entity app = brooklynMgmt.getEntityManager().getEntity(assembly.getId()); - log.info("App - "+app); - - // locations set on individual services here - Assert.assertEquals(app.getLocations().size(), 0); - - Iterator<ResolvableLink<PlatformComponent>> pcs = assembly.getPlatformComponents().links().iterator(); - PlatformComponent pc1 = pcs.next().resolve(); - Entity cluster = brooklynMgmt.getEntityManager().getEntity(pc1.getId()); - log.info("pc1 - "+pc1+" - "+cluster); - - PlatformComponent pc2 = pcs.next().resolve(); - log.info("pc2 - "+pc2); - - Set<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(brooklynMgmt.getExecutionManager(), app); - log.info("Waiting on "+tasks.size()+" task(s)"); - AtomicInteger i = new AtomicInteger(0); - for (Task<?> t: tasks) { - t.blockUntilEnded(); - log.info("Completed task #" + i.incrementAndGet()); - } - - log.info("App started:"); - Entities.dumpInfo(app); - - EntityTestUtils.assertAttributeEqualsEventually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); - Assert.assertEquals(app.getAttribute(Attributes.SERVICE_UP), Boolean.TRUE); - - final String url = Asserts.succeedsEventually(MutableMap.of("timeout", Duration.TEN_SECONDS), new Callable<String>() { - @Override public String call() throws Exception { - Entity cluster = Iterables.getOnlyElement( Iterables.filter(app.getChildren(), WebAppService.class) ); - String url = cluster.getAttribute(JavaWebAppService.ROOT_URL); - return checkNotNull(url, "url of %s", cluster); - }}); - - String site = Asserts.succeedsEventually(MutableMap.of("timeout", Duration.TEN_SECONDS), new Callable<String>() { - @Override public String call() throws Exception { - return new ResourceUtils(this).getResourceAsString(url); - }}); - - log.info("App URL for "+app+": "+url); - Assert.assertTrue(url.contains("921"), "URL should be on port 9280+ based on config set in yaml, url "+url+", app "+app); - Assert.assertTrue(site.toLowerCase().contains("hello"), site); - Assert.assertTrue(!platform.assemblies().isEmpty()); - - String dbPage = new ResourceUtils(this).getResourceAsString(Urls.mergePaths(url, "db.jsp")); - Assert.assertTrue(dbPage.contains("Isaac Asimov"), "db.jsp does not mention Isaac Asimov, probably the DB did not get initialised:\n"+dbPage); - } catch (Exception e) { - log.warn("Unable to instantiate "+at+" (rethrowing): "+e); - throw Exceptions.propagate(e); - } - } - - public void testWithPolicyDeploy() { - Reader input = Streams.reader(new ResourceUtils(this).getResourceFromUrl("java-web-app-and-db-with-policy.yaml")); - AssemblyTemplate at = platform.pdp().registerDeploymentPlan(input); - - try { - Assembly assembly = at.getInstantiator().newInstance().instantiate(at, platform); - log.info("Test - created "+assembly); - - final Entity app = brooklynMgmt.getEntityManager().getEntity(assembly.getId()); - log.info("App - "+app); - - // locations set on individual services here - Assert.assertEquals(app.getLocations().size(), 0); - - Set<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(brooklynMgmt.getExecutionManager(), app); - log.info("Waiting on "+tasks.size()+" task(s)"); - for (Task<?> t: tasks) { - t.blockUntilEnded(); - } - - log.info("App started:"); - Entities.dumpInfo(app); - - Iterator<ResolvableLink<PlatformComponent>> pcs = assembly.getPlatformComponents().links().iterator(); - PlatformComponent clusterComponent = null; - while (pcs.hasNext() && clusterComponent == null) { - PlatformComponent component = pcs.next().resolve(); - if (component.getName().equals("My Web with Policy")) - clusterComponent = component; - } - Assert.assertNotNull(clusterComponent, "Database PlatformComponent not found"); - Entity cluster = brooklynMgmt.getEntityManager().getEntity(clusterComponent.getId()); - log.info("pc1 - "+clusterComponent+" - "+cluster); - - Assert.assertEquals(cluster.policies().size(), 1); - Policy policy = cluster.policies().iterator().next(); - Assert.assertNotNull(policy); - Assert.assertTrue(policy instanceof AutoScalerPolicy, "policy="+policy); - Assert.assertEquals(policy.getConfig(AutoScalerPolicy.MAX_POOL_SIZE), (Integer)5); - Assert.assertEquals(policy.getConfig(AutoScalerPolicy.MIN_POOL_SIZE), (Integer)1); - Assert.assertEquals(policy.getConfig(AutoScalerPolicy.METRIC), DynamicWebAppCluster.REQUESTS_PER_SECOND_IN_WINDOW_PER_NODE); - Assert.assertEquals(policy.getConfig(AutoScalerPolicy.METRIC_LOWER_BOUND), (Integer)10); - Assert.assertEquals(policy.getConfig(AutoScalerPolicy.METRIC_UPPER_BOUND), (Integer)100); - Assert.assertTrue(policy.isRunning()); - - EntityTestUtils.assertAttributeEqualsEventually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); - Assert.assertEquals(app.getAttribute(Attributes.SERVICE_UP), Boolean.TRUE); - - final String url = Asserts.succeedsEventually(MutableMap.of("timeout", Duration.TEN_SECONDS), new Callable<String>() { - @Override public String call() throws Exception { - Entity cluster = Iterables.getOnlyElement( Iterables.filter(app.getChildren(), WebAppService.class) ); - String url = cluster.getAttribute(JavaWebAppService.ROOT_URL); - return checkNotNull(url, "url of %s", cluster); - }}); - - String site = Asserts.succeedsEventually(MutableMap.of("timeout", Duration.TEN_SECONDS), new Callable<String>() { - @Override public String call() throws Exception { - return new ResourceUtils(this).getResourceAsString(url); - }}); - - log.info("App URL for "+app+": "+url); - Assert.assertTrue(url.contains("921"), "URL should be on port 9280+ based on config set in yaml, url "+url+", app "+app); - Assert.assertTrue(site.toLowerCase().contains("hello"), site); - Assert.assertTrue(!platform.assemblies().isEmpty()); - - String dbPage = new ResourceUtils(this).getResourceAsString(Urls.mergePaths(url, "db.jsp")); - Assert.assertTrue(dbPage.contains("Isaac Asimov"), "db.jsp does not mention Isaac Asimov, probably the DB did not get initialised:\n"+dbPage); - } catch (Exception e) { - log.warn("Unable to instantiate "+at+" (rethrowing): "+e); - throw Exceptions.propagate(e); - } - } - -}
