You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2015/08/12 17:55:28 UTC
[10/35] incubator-brooklyn git commit: [BROOKLYN-162] package rename
to org.apache.brooklyn: software/webapp
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/77dff880/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxHttpsSslIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxHttpsSslIntegrationTest.java b/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxHttpsSslIntegrationTest.java
deleted file mode 100644
index faed95c..0000000
--- a/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxHttpsSslIntegrationTest.java
+++ /dev/null
@@ -1,238 +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 brooklyn.entity.proxy.nginx;
-
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertTrue;
-
-import java.io.File;
-
-import org.apache.brooklyn.test.HttpTestUtils;
-import org.apache.brooklyn.test.TestResourceUnavailableException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.Assert;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import brooklyn.entity.BrooklynAppLiveTestSupport;
-import brooklyn.entity.Entity;
-import brooklyn.entity.basic.EntityInternal;
-import brooklyn.entity.basic.SoftwareProcess;
-import brooklyn.entity.group.DynamicCluster;
-import brooklyn.entity.proxy.LoadBalancer;
-import brooklyn.entity.proxy.ProxySslConfig;
-import brooklyn.entity.proxying.EntitySpec;
-import brooklyn.entity.webapp.JavaWebAppService;
-import brooklyn.entity.webapp.WebAppService;
-import brooklyn.entity.webapp.jboss.JBoss7Server;
-import brooklyn.event.basic.PortAttributeSensorAndConfigKey;
-import brooklyn.location.Location;
-import brooklyn.location.basic.PortRanges;
-import brooklyn.test.Asserts;
-import brooklyn.util.exceptions.Exceptions;
-
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-
-/**
- * Test the operation of the {@link NginxController} class.
- */
-public class NginxHttpsSslIntegrationTest extends BrooklynAppLiveTestSupport {
-
- private static final Logger log = LoggerFactory.getLogger(NginxHttpsSslIntegrationTest.class);
-
- private NginxController nginx;
- private DynamicCluster cluster;
- private Location localLoc;
-
- private static final String CERTIFICATE_URL = "classpath://ssl/certs/localhost/server.crt";
- private static final String KEY_URL = "classpath://ssl/certs/localhost/server.key";
-
- @BeforeMethod(alwaysRun=true)
- @Override
- public void setUp() throws Exception {
- super.setUp();
- localLoc = mgmt.getLocationRegistry().resolve("localhost");
- }
-
- private static void urlContainsPort(NginxController nginx, PortAttributeSensorAndConfigKey sensor, String portRange) {
- Integer port = nginx.getAttribute(sensor);
- Assert.assertTrue(Iterables.contains(PortRanges.fromString(portRange), port), "Port "+port+" not in range "+portRange);
- String url = Preconditions.checkNotNull(nginx.getAttribute(LoadBalancer.MAIN_URI), "main uri").toString();
- Assert.assertTrue(url.contains(":"+port), "URL does not contain expected port; port "+port+", url "+url);
- }
-
- public String getTestWar() {
- TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), "/hello-world.war");
- return "classpath://hello-world.war";
- }
-
- /**
- * Test that the Nginx proxy starts up and sets SERVICE_UP correctly.
- */
- @Test(groups = "Integration")
- public void testStartsWithGlobalSsl_withCertificateAndKeyCopy() {
- cluster = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
- .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(JBoss7Server.class))
- .configure("initialSize", 1)
- .configure(JavaWebAppService.ROOT_WAR, getTestWar()));
-
- ProxySslConfig ssl = ProxySslConfig.builder()
- .certificateSourceUrl(CERTIFICATE_URL)
- .keySourceUrl(KEY_URL)
- .build();
-
- nginx = app.createAndManageChild(EntitySpec.create(NginxController.class)
- .configure("sticky", false)
- .configure("serverPool", cluster)
- .configure("domain", "localhost")
- .configure("httpsPort", "8453+")
- .configure("ssl", ssl));
-
- app.start(ImmutableList.of(localLoc));
-
- urlContainsPort(nginx, LoadBalancer.PROXY_HTTPS_PORT, "8453+");
-
- final String url = nginx.getAttribute(WebAppService.ROOT_URL);
- log.info("URL for nginx is "+url);
- if (!url.startsWith("https://")) Assert.fail("URL should be https: "+url);
-
- Asserts.succeedsEventually(new Runnable() {
- public void run() {
- // Services are running
- assertTrue(cluster.getAttribute(SoftwareProcess.SERVICE_UP));
- for (Entity member : cluster.getMembers()) {
- assertTrue(member.getAttribute(SoftwareProcess.SERVICE_UP));
- }
-
- assertTrue(nginx.getAttribute(SoftwareProcess.SERVICE_UP));
-
- // Nginx URL is available
- HttpTestUtils.assertHttpStatusCodeEquals(url, 200);
-
- // Web-server URL is available
- for (Entity member : cluster.getMembers()) {
- HttpTestUtils.assertHttpStatusCodeEquals(member.getAttribute(WebAppService.ROOT_URL), 200);
- }
- }});
-
- app.stop();
-
- // Services have stopped
- assertFalse(nginx.getAttribute(SoftwareProcess.SERVICE_UP));
- assertFalse(cluster.getAttribute(SoftwareProcess.SERVICE_UP));
- for (Entity member : cluster.getMembers()) {
- assertFalse(member.getAttribute(SoftwareProcess.SERVICE_UP));
- }
- }
-
- private String getFile(String file) {
- return new File(getClass().getResource("/" + file).getFile()).getAbsolutePath();
- }
-
- @Test(groups = "Integration")
- public void testStartsWithGlobalSsl_withPreinstalledCertificateAndKey() {
- cluster = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
- .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(JBoss7Server.class))
- .configure("initialSize", 1)
- .configure(JavaWebAppService.ROOT_WAR, getTestWar()));
-
- ProxySslConfig ssl = ProxySslConfig.builder()
- .certificateDestination(getFile("ssl/certs/localhost/server.crt"))
- .keyDestination(getFile("ssl/certs/localhost/server.key"))
- .build();
-
- nginx = app.createAndManageChild(EntitySpec.create(NginxController.class)
- .configure("sticky", false)
- .configure("serverPool", cluster)
- .configure("domain", "localhost")
- .configure("port", "8443+")
- .configure("ssl", ssl));
-
- app.start(ImmutableList.of(localLoc));
-
- final String url = nginx.getAttribute(WebAppService.ROOT_URL);
- if (!url.startsWith("https://")) Assert.fail("URL should be https: "+url);
-
- Asserts.succeedsEventually(new Runnable() {
- public void run() {
- // Services are running
- assertTrue(cluster.getAttribute(SoftwareProcess.SERVICE_UP));
- for (Entity member : cluster.getMembers()) {
- assertTrue(member.getAttribute(SoftwareProcess.SERVICE_UP));
- }
-
- assertTrue(nginx.getAttribute(SoftwareProcess.SERVICE_UP));
-
- // Nginx URL is available
- HttpTestUtils.assertHttpStatusCodeEquals(url, 200);
-
- // Web-server URL is available
- for (Entity member : cluster.getMembers()) {
- HttpTestUtils.assertHttpStatusCodeEquals(member.getAttribute(WebAppService.ROOT_URL), 200);
- }
- }});
-
- app.stop();
-
- // Services have stopped
- assertFalse(nginx.getAttribute(SoftwareProcess.SERVICE_UP));
- assertFalse(cluster.getAttribute(SoftwareProcess.SERVICE_UP));
- for (Entity member : cluster.getMembers()) {
- assertFalse(member.getAttribute(SoftwareProcess.SERVICE_UP));
- }
- }
-
- @Test(groups = "Integration")
- public void testStartsNonSslThenBecomesSsl() {
- cluster = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
- .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(JBoss7Server.class))
- .configure("initialSize", 1)
- .configure(JavaWebAppService.ROOT_WAR, getTestWar()));
-
- nginx = app.createAndManageChild(EntitySpec.create(NginxController.class)
- .configure("serverPool", cluster)
- .configure("domain", "localhost"));
-
- app.start(ImmutableList.of(localLoc));
-
- urlContainsPort(nginx, LoadBalancer.PROXY_HTTP_PORT, "8000-8100");
-
- ProxySslConfig ssl = ProxySslConfig.builder()
- .certificateDestination(getFile("ssl/certs/localhost/server.crt"))
- .keyDestination(getFile("ssl/certs/localhost/server.key"))
- .build();
- ((EntityInternal)nginx).setConfig(LoadBalancer.PROXY_HTTPS_PORT, PortRanges.fromString("8443+"));
- ((EntityInternal)nginx).setConfig(NginxController.SSL_CONFIG, ssl);
-
- try {
- log.info("restarting nginx as ssl");
- nginx.restart();
- urlContainsPort(nginx, LoadBalancer.PROXY_HTTPS_PORT, "8443-8543");
-
- app.stop();
-
- } catch (Exception e) {
- throw Exceptions.propagate(e);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/77dff880/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxIntegrationTest.java b/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxIntegrationTest.java
deleted file mode 100644
index 1cf0920..0000000
--- a/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxIntegrationTest.java
+++ /dev/null
@@ -1,453 +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 brooklyn.entity.proxy.nginx;
-
-import static org.apache.brooklyn.test.EntityTestUtils.assertAttributeEqualsEventually;
-import static org.apache.brooklyn.test.HttpTestUtils.assertHttpStatusCodeEquals;
-import static org.apache.brooklyn.test.HttpTestUtils.assertHttpStatusCodeEventuallyEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertNotEquals;
-import static org.testng.Assert.assertTrue;
-
-import java.util.Map;
-
-import org.apache.brooklyn.test.HttpTestUtils;
-import org.apache.brooklyn.test.TestResourceUnavailableException;
-import org.apache.brooklyn.test.WebAppMonitor;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import brooklyn.entity.BrooklynAppLiveTestSupport;
-import brooklyn.entity.Entity;
-import brooklyn.entity.basic.EntityFactory;
-import brooklyn.entity.basic.SoftwareProcess;
-import brooklyn.entity.group.DynamicCluster;
-import brooklyn.entity.proxying.EntitySpec;
-import brooklyn.entity.webapp.JavaWebAppService;
-import brooklyn.entity.webapp.WebAppService;
-import brooklyn.entity.webapp.jboss.JBoss7Server;
-import brooklyn.location.Location;
-import brooklyn.test.Asserts;
-import brooklyn.util.time.Duration;
-import brooklyn.util.time.Time;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-/**
- * Test the operation of the {@link NginxController} class.
- */
-public class NginxIntegrationTest extends BrooklynAppLiveTestSupport {
- private static final Logger log = LoggerFactory.getLogger(NginxIntegrationTest.class);
-
- private NginxController nginx;
- private DynamicCluster serverPool;
- private Location localLoc;
-
- @BeforeMethod(alwaysRun=true)
- @Override
- public void setUp() throws Exception {
- super.setUp();
- localLoc = mgmt.getLocationRegistry().resolve("localhost");
- }
-
- public String getTestWar() {
- TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), "/hello-world.war");
- return "classpath://hello-world.war";
- }
-
- /**
- * Test that the Nginx proxy starts up and sets SERVICE_UP correctly.
- */
- @Test(groups = "Integration")
- public void testWhenNoServersReturns404() {
- serverPool = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
- .configure("initialSize", 0)
- .configure(DynamicCluster.FACTORY, new EntityFactory<Entity>() {
- @Override public Entity newEntity(Map flags, Entity parent) {
- throw new UnsupportedOperationException();
- }}));
-
- nginx = app.createAndManageChild(EntitySpec.create(NginxController.class)
- .configure("serverPool", serverPool)
- .configure("domain", "localhost"));
-
- app.start(ImmutableList.of(localLoc));
-
- assertAttributeEqualsEventually(nginx, SoftwareProcess.SERVICE_UP, true);
- assertHttpStatusCodeEventuallyEquals(nginx.getAttribute(NginxController.ROOT_URL), 404);
- }
-
- @Test(groups = "Integration")
- public void testRestart() {
- serverPool = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
- .configure("initialSize", 0)
- .configure(DynamicCluster.FACTORY, new EntityFactory<Entity>() {
- @Override public Entity newEntity(Map flags, Entity parent) {
- throw new UnsupportedOperationException();
- }}));
-
- nginx = app.createAndManageChild(EntitySpec.create(NginxController.class)
- .configure("serverPool", serverPool)
- .configure("domain", "localhost"));
-
- app.start(ImmutableList.of(localLoc));
-
- nginx.restart();
-
- assertAttributeEqualsEventually(nginx, SoftwareProcess.SERVICE_UP, true);
- assertHttpStatusCodeEventuallyEquals(nginx.getAttribute(NginxController.ROOT_URL), 404);
- }
-
- /**
- * Test that the Nginx proxy starts up and sets SERVICE_UP correctly.
- */
- @Test(groups = "Integration")
- public void testCanStartupAndShutdown() {
- serverPool = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
- .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(JBoss7Server.class))
- .configure("initialSize", 1)
- .configure(JavaWebAppService.ROOT_WAR, getTestWar()));
-
- nginx = app.createAndManageChild(EntitySpec.create(NginxController.class)
- .configure("serverPool", serverPool)
- .configure("domain", "localhost")
- .configure("portNumberSensor", WebAppService.HTTP_PORT));
-
- app.start(ImmutableList.of(localLoc));
-
- // App-servers and nginx has started
- Asserts.succeedsEventually(new Runnable() {
- public void run() {
- for (Entity member : serverPool.getMembers()) {
- assertTrue(member.getAttribute(SoftwareProcess.SERVICE_UP));
- }
- assertTrue(nginx.getAttribute(SoftwareProcess.SERVICE_UP));
- }});
-
- // URLs reachable
- assertHttpStatusCodeEventuallyEquals(nginx.getAttribute(NginxController.ROOT_URL), 200);
- for (Entity member : serverPool.getMembers()) {
- assertHttpStatusCodeEventuallyEquals(member.getAttribute(WebAppService.ROOT_URL), 200);
- }
-
- app.stop();
-
- // Services have stopped
- assertFalse(nginx.getAttribute(SoftwareProcess.SERVICE_UP));
- assertFalse(serverPool.getAttribute(SoftwareProcess.SERVICE_UP));
- for (Entity member : serverPool.getMembers()) {
- assertFalse(member.getAttribute(SoftwareProcess.SERVICE_UP));
- }
- }
-
- /**
- * Test that the Nginx proxy starts up and sets SERVICE_UP correctly using the config file template.
- */
- @Test(groups = "Integration")
- public void testCanStartupAndShutdownUsingTemplate() {
- serverPool = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
- .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(JBoss7Server.class))
- .configure("initialSize", 1)
- .configure(JavaWebAppService.ROOT_WAR, getTestWar()));
-
- nginx = app.createAndManageChild(EntitySpec.create(NginxController.class)
- .configure("serverPool", serverPool)
- .configure("domain", "localhost")
- .configure("portNumberSensor", WebAppService.HTTP_PORT)
- .configure("configTemplate", "classpath://brooklyn/entity/proxy/nginx/server.conf"));
-
- app.start(ImmutableList.of(localLoc));
-
- // App-servers and nginx has started
- Asserts.succeedsEventually(new Runnable() {
- public void run() {
- for (Entity member : serverPool.getMembers()) {
- assertTrue(member.getAttribute(SoftwareProcess.SERVICE_UP));
- }
- assertTrue(nginx.getAttribute(SoftwareProcess.SERVICE_UP));
- }});
-
- // URLs reachable
- assertHttpStatusCodeEventuallyEquals(nginx.getAttribute(NginxController.ROOT_URL), 200);
- for (Entity member : serverPool.getMembers()) {
- assertHttpStatusCodeEventuallyEquals(member.getAttribute(WebAppService.ROOT_URL), 200);
- }
-
- app.stop();
-
- // Services have stopped
- assertFalse(nginx.getAttribute(SoftwareProcess.SERVICE_UP));
- assertFalse(serverPool.getAttribute(SoftwareProcess.SERVICE_UP));
- for (Entity member : serverPool.getMembers()) {
- assertFalse(member.getAttribute(SoftwareProcess.SERVICE_UP));
- }
- }
-
- /**
- * Test that the Nginx proxy works, serving all domains, if no domain is set
- */
- @Test(groups = "Integration")
- public void testDomainless() {
- serverPool = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
- .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(JBoss7Server.class))
- .configure("initialSize", 1)
- .configure(JavaWebAppService.ROOT_WAR, getTestWar()));
-
- nginx = app.createAndManageChild(EntitySpec.create(NginxController.class)
- .configure("serverPool", serverPool)
- .configure("domain", "localhost")
- .configure("portNumberSensor", WebAppService.HTTP_PORT));
-
- app.start(ImmutableList.of(localLoc));
-
- // App-servers and nginx has started
- assertAttributeEqualsEventually(serverPool, SoftwareProcess.SERVICE_UP, true);
- for (Entity member : serverPool.getMembers()) {
- assertAttributeEqualsEventually(member, SoftwareProcess.SERVICE_UP, true);
- }
- assertAttributeEqualsEventually(nginx, SoftwareProcess.SERVICE_UP, true);
-
- // URLs reachable
- assertHttpStatusCodeEventuallyEquals(nginx.getAttribute(NginxController.ROOT_URL), 200);
- for (Entity member : serverPool.getMembers()) {
- assertHttpStatusCodeEventuallyEquals(member.getAttribute(WebAppService.ROOT_URL), 200);
- }
-
- app.stop();
-
- // Services have stopped
- assertFalse(nginx.getAttribute(SoftwareProcess.SERVICE_UP));
- assertFalse(serverPool.getAttribute(SoftwareProcess.SERVICE_UP));
- for (Entity member : serverPool.getMembers()) {
- assertFalse(member.getAttribute(SoftwareProcess.SERVICE_UP));
- }
- }
-
- @Test(groups = "Integration")
- public void testTwoNginxesGetDifferentPorts() {
- serverPool = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
- .configure("initialSize", 0)
- .configure(DynamicCluster.FACTORY, new EntityFactory<Entity>() {
- @Override public Entity newEntity(Map flags, Entity parent) {
- throw new UnsupportedOperationException();
- }}));
-
- NginxController nginx1 = app.createAndManageChild(EntitySpec.create(NginxController.class)
- .configure("serverPool", serverPool)
- .configure("domain", "localhost")
- .configure("port", "14000+"));
-
- NginxController nginx2 = app.createAndManageChild(EntitySpec.create(NginxController.class)
- .configure("serverPool", serverPool)
- .configure("domain", "localhost")
- .configure("port", "14000+"));
-
- app.start(ImmutableList.of(localLoc));
-
- String url1 = nginx1.getAttribute(NginxController.ROOT_URL);
- String url2 = nginx2.getAttribute(NginxController.ROOT_URL);
-
- assertTrue(url1.contains(":1400"), url1);
- assertTrue(url2.contains(":1400"), url2);
- assertNotEquals(url1, url2, "Two nginxs should listen on different ports, not both on "+url1);
-
- // Nginx has started
- assertAttributeEqualsEventually(nginx1, SoftwareProcess.SERVICE_UP, true);
- assertAttributeEqualsEventually(nginx2, SoftwareProcess.SERVICE_UP, true);
-
- // Nginx reachable (returning default 404)
- assertHttpStatusCodeEventuallyEquals(url1, 404);
- assertHttpStatusCodeEventuallyEquals(url2, 404);
- }
-
- /** Test that site access does not fail even while nginx is reloaded */
- // FIXME test disabled -- reload isn't a problem, but #365 is
- @Test(enabled = false, groups = "Integration")
- public void testServiceContinuity() throws Exception {
- serverPool = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
- .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(JBoss7Server.class))
- .configure("initialSize", 1)
- .configure(JavaWebAppService.ROOT_WAR, getTestWar()));
-
- nginx = app.createAndManageChild(EntitySpec.create(NginxController.class)
- .configure("serverPool", serverPool));
-
- app.start(ImmutableList.of(localLoc));
-
- Asserts.succeedsEventually(new Runnable() {
- public void run() {
- for (Entity member : serverPool.getMembers()) {
- assertHttpStatusCodeEquals(member.getAttribute(WebAppService.ROOT_URL), 200);
- }
- assertHttpStatusCodeEquals(nginx.getAttribute(WebAppService.ROOT_URL), 200);
- }});
-
- WebAppMonitor monitor = new WebAppMonitor(nginx.getAttribute(WebAppService.ROOT_URL))
- .logFailures(log)
- .delayMillis(0);
- Thread t = new Thread(monitor);
- t.start();
-
- try {
- Thread.sleep(1*1000);
- log.info("service continuity test, startup, "+monitor.getAttempts()+" requests made");
- monitor.assertAttemptsMade(10, "startup").assertNoFailures("startup").resetCounts();
-
- for (int i=0; i<20; i++) {
- nginx.reload();
- Thread.sleep(500);
- log.info("service continuity test, iteration "+i+", "+monitor.getAttempts()+" requests made");
- monitor.assertAttemptsMade(10, "reloaded").assertNoFailures("reloaded").resetCounts();
- }
-
- } finally {
- t.interrupt();
- }
-
- app.stop();
-
- // Services have stopped
- assertFalse(nginx.getAttribute(SoftwareProcess.SERVICE_UP));
- assertFalse(serverPool.getAttribute(SoftwareProcess.SERVICE_UP));
- for (Entity member : serverPool.getMembers()) {
- assertFalse(member.getAttribute(SoftwareProcess.SERVICE_UP));
- }
- }
-
- // FIXME test disabled -- issue #365
- /*
- * This currently makes no assertions, but writes out the number of sequential reqs per sec
- * supported with nginx and jboss.
- * <p>
- * jboss is (now) steady, at 6k+, since we close the connections in HttpTestUtils.getHttpStatusCode.
- * but nginx still hits problems, after about 15k reqs, something is getting starved in nginx.
- */
- @Test(enabled=false, groups = "Integration")
- public void testContinuityNginxAndJboss() throws Exception {
- serverPool = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
- .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(JBoss7Server.class))
- .configure("initialSize", 1)
- .configure(JavaWebAppService.ROOT_WAR, getTestWar()));
-
- nginx = app.createAndManageChild(EntitySpec.create(NginxController.class)
- .configure("serverPool", serverPool));
-
- app.start(ImmutableList.of(localLoc));
-
- final String nginxUrl = nginx.getAttribute(WebAppService.ROOT_URL);
-
- Asserts.succeedsEventually(new Runnable() {
- public void run() {
- for (Entity member : serverPool.getMembers()) {
- String jbossUrl = member.getAttribute(WebAppService.ROOT_URL);
- assertHttpStatusCodeEquals(jbossUrl, 200);
- }
- assertHttpStatusCodeEquals(nginxUrl, 200);
- }});
-
- final String jbossUrl = Iterables.get(serverPool.getMembers(), 0).getAttribute(WebAppService.ROOT_URL);
-
- Thread t = new Thread(new Runnable() {
- public void run() {
- long lastReportTime = System.currentTimeMillis();
- int num = 0;
- while (true) {
- try {
- num++;
- int code = HttpTestUtils.getHttpStatusCode(nginxUrl);
- if (code!=200) log.info("NGINX GOT: "+code);
- else log.debug("NGINX GOT: "+code);
- if (System.currentTimeMillis()>=lastReportTime+1000) {
- log.info("NGINX DID "+num+" requests in last "+(System.currentTimeMillis()-lastReportTime)+"ms");
- num=0;
- lastReportTime = System.currentTimeMillis();
- }
- } catch (Exception e) {
- log.info("NGINX GOT: "+e);
- }
- }
- }});
- t.start();
-
- Thread t2 = new Thread(new Runnable() {
- public void run() {
- long lastReportTime = System.currentTimeMillis();
- int num = 0;
- while (true) {
- try {
- num++;
- int code = HttpTestUtils.getHttpStatusCode(jbossUrl);
- if (code!=200) log.info("JBOSS GOT: "+code);
- else log.debug("JBOSS GOT: "+code);
- if (System.currentTimeMillis()>=1000+lastReportTime) {
- log.info("JBOSS DID "+num+" requests in last "+(System.currentTimeMillis()-lastReportTime)+"ms");
- num=0;
- lastReportTime = System.currentTimeMillis();
- }
- } catch (Exception e) {
- log.info("JBOSS GOT: "+e);
- }
- }
- }});
- t2.start();
-
- t2.join();
- }
-
- /**
- * Test that the Nginx proxy starts up and sets SERVICE_UP correctly.
- */
- @Test(groups = "Integration")
- public void testCanRestart() {
- nginx = app.createAndManageChild(EntitySpec.create(NginxController.class)
- .configure("serverPool", serverPool)
- .configure("domain", "localhost")
- .configure("portNumberSensor", WebAppService.HTTP_PORT));
-
- app.start(ImmutableList.of(localLoc));
-
- // App-servers and nginx has started
- Asserts.succeedsEventually(new Runnable() {
- public void run() {
- assertTrue(nginx.getAttribute(SoftwareProcess.SERVICE_UP));
- }});
-
- log.info("started, will restart soon");
- Time.sleep(Duration.ONE_SECOND);
-
- nginx.restart();
-
- Time.sleep(Duration.ONE_SECOND);
- Asserts.succeedsEventually(new Runnable() {
- public void run() {
- assertTrue(nginx.getAttribute(SoftwareProcess.SERVICE_UP));
- }});
- log.info("restarted and got service up");
- }
-
-// public static void main(String[] args) {
-// NginxIntegrationTest t = new NginxIntegrationTest();
-// t.setup();
-// t.testCanRestart();
-// t.shutdown();
-// }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/77dff880/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxLightIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxLightIntegrationTest.java b/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxLightIntegrationTest.java
deleted file mode 100644
index b55e598..0000000
--- a/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxLightIntegrationTest.java
+++ /dev/null
@@ -1,74 +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 brooklyn.entity.proxy.nginx;
-
-import static org.testng.Assert.assertEquals;
-
-import java.net.URL;
-import java.util.Map;
-
-import org.testng.annotations.Test;
-
-import brooklyn.entity.BrooklynAppUnitTestSupport;
-import brooklyn.entity.Entity;
-import brooklyn.entity.basic.Attributes;
-import brooklyn.entity.basic.BasicConfigurableEntityFactory;
-import brooklyn.entity.basic.EntityFactory;
-import brooklyn.entity.group.DynamicCluster;
-import brooklyn.entity.proxy.StubAppServer;
-import brooklyn.entity.proxying.EntitySpec;
-import brooklyn.location.basic.LocalhostMachineProvisioningLocation;
-import brooklyn.test.Asserts;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Maps;
-
-public class NginxLightIntegrationTest extends BrooklynAppUnitTestSupport {
-
- private NginxController nginx;
- private DynamicCluster cluster;
-
- // FIXME Fails because getting addEntity callback for group members while nginx is still starting,
- // so important nginx fields are still null. Therefore get NPE for cluster members, and thus targets
- // is of size zero.
- @Test(groups = {"Integration", "WIP"})
- public void testNginxTargetsMatchesClusterMembers() {
- EntityFactory<StubAppServer> serverFactory = new BasicConfigurableEntityFactory<StubAppServer>(StubAppServer.class);
- final DynamicCluster cluster = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
- .configure("initialSize", 2)
- .configure("factory", serverFactory));
-
- nginx = app.createAndManageChild(EntitySpec.create(NginxController.class)
- .configure("serverPool", cluster)
- .configure("domain", "localhost"));
-
- app.start(ImmutableList.of(new LocalhostMachineProvisioningLocation()));
-
- // Wait for url-mapping to update its TARGET_ADDRESSES (through async subscription)
- Asserts.succeedsEventually(new Runnable() {
- @Override public void run() {
- Map<Entity, String> expectedTargets = Maps.newLinkedHashMap();
- for (Entity member : cluster.getMembers()) {
- expectedTargets.put(member, member.getAttribute(Attributes.HOSTNAME)+":"+member.getAttribute(Attributes.HTTP_PORT));
- }
- assertEquals(nginx.getAttribute(NginxController.SERVER_POOL_TARGETS).size(), 2);
- assertEquals(nginx.getAttribute(NginxController.SERVER_POOL_TARGETS), expectedTargets);
- }});
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/77dff880/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxRebindIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxRebindIntegrationTest.java b/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxRebindIntegrationTest.java
deleted file mode 100644
index dcaaca5..0000000
--- a/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxRebindIntegrationTest.java
+++ /dev/null
@@ -1,292 +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 brooklyn.entity.proxy.nginx;
-
-import static org.apache.brooklyn.test.EntityTestUtils.assertAttributeEqualsEventually;
-import static org.apache.brooklyn.test.HttpTestUtils.assertHttpStatusCodeEquals;
-import static org.apache.brooklyn.test.HttpTestUtils.assertHttpStatusCodeEventuallyEquals;
-import static org.testng.Assert.assertEquals;
-
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-import org.apache.brooklyn.management.ManagementContext;
-import org.apache.brooklyn.test.EntityTestUtils;
-import org.apache.brooklyn.test.TestResourceUnavailableException;
-import org.apache.brooklyn.test.WebAppMonitor;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import brooklyn.entity.Entity;
-import brooklyn.entity.Group;
-import brooklyn.entity.basic.BasicGroup;
-import brooklyn.entity.basic.Entities;
-import brooklyn.entity.basic.Lifecycle;
-import brooklyn.entity.basic.SoftwareProcess;
-import brooklyn.entity.group.DynamicCluster;
-import brooklyn.entity.proxying.EntitySpec;
-import brooklyn.entity.rebind.RebindOptions;
-import brooklyn.entity.rebind.RebindTestFixtureWithApp;
-import brooklyn.entity.webapp.tomcat.Tomcat8Server;
-import brooklyn.location.LocationSpec;
-import brooklyn.location.basic.LocalhostMachineProvisioningLocation;
-import brooklyn.test.Asserts;
-
-import com.google.common.base.Predicates;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
-
-/**
- * Test the operation of the {@link NginxController} class.
- */
-public class NginxRebindIntegrationTest extends RebindTestFixtureWithApp {
-
- private static final Logger LOG = LoggerFactory.getLogger(NginxRebindIntegrationTest.class);
-
- private LocalhostMachineProvisioningLocation localhostProvisioningLocation;
- private List<WebAppMonitor> webAppMonitors = new CopyOnWriteArrayList<WebAppMonitor>();
- private ExecutorService executor;
-
- @Override
- protected boolean useLiveManagementContext() {
- // For Aled, the test failed without own ~/.brooklyn/brooklyn.properties.
- // Suspect that was caused by local environment, with custom brooklyn.ssh.config.scriptHeader
- // to set things like correct Java on path.
- return true;
- }
-
- @BeforeMethod(alwaysRun=true)
- public void setUp() throws Exception {
- super.setUp();
- localhostProvisioningLocation = origManagementContext.getLocationManager().createLocation(LocationSpec.create(LocalhostMachineProvisioningLocation.class));
- executor = Executors.newCachedThreadPool();
- }
-
- public String getTestWar() {
- TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), "/hello-world.war");
- return "classpath://hello-world.war";
- }
-
- @AfterMethod(alwaysRun=true)
- public void tearDown() throws Exception {
- for (WebAppMonitor monitor : webAppMonitors) {
- monitor.terminate();
- }
- webAppMonitors.clear();
- if (executor != null) executor.shutdownNow();
- super.tearDown();
- }
-
- private WebAppMonitor newWebAppMonitor(String url, int expectedResponseCode) {
- WebAppMonitor monitor = new WebAppMonitor(url)
-// .delayMillis(0) FIXME Re-enable to fast polling
- .expectedResponseCode(expectedResponseCode)
- .logFailures(LOG);
- webAppMonitors.add(monitor);
- executor.execute(monitor);
- return monitor;
- }
-
- /**
- * Test can rebind to the simplest possible nginx configuration (i.e. no server pool).
- */
- @Test(groups = "Integration")
- public void testRebindsWithEmptyServerPool() throws Exception {
-
- // Set up nginx with a server pool
- DynamicCluster origServerPool = origApp.createAndManageChild(EntitySpec.create(DynamicCluster.class)
- .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(Tomcat8Server.class))
- .configure("initialSize", 0));
-
- NginxController origNginx = origApp.createAndManageChild(EntitySpec.create(NginxController.class)
- .configure("serverPool", origServerPool)
- .configure("domain", "localhost"));
-
- // Start the app, and ensure reachable; start polling the URL
- origApp.start(ImmutableList.of(localhostProvisioningLocation));
-
- String rootUrl = origNginx.getAttribute(NginxController.ROOT_URL);
- int nginxPort = origNginx.getAttribute(NginxController.PROXY_HTTP_PORT);
-
- assertHttpStatusCodeEventuallyEquals(rootUrl, 404);
- WebAppMonitor monitor = newWebAppMonitor(rootUrl, 404);
- final String origConfigFile = origNginx.getConfigFile();
-
- newApp = rebind(RebindOptions.create().terminateOrigManagementContext(true));
- final NginxController newNginx = (NginxController) Iterables.find(newApp.getChildren(), Predicates.instanceOf(NginxController.class));
-
- assertEquals(newNginx.getConfigFile(), origConfigFile);
-
- EntityTestUtils.assertAttributeEqualsEventually(newNginx, NginxController.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
- assertEquals(newNginx.getAttribute(NginxController.PROXY_HTTP_PORT), (Integer)nginxPort);
- assertEquals(newNginx.getAttribute(NginxController.ROOT_URL), rootUrl);
- assertEquals(newNginx.getAttribute(NginxController.PROXY_HTTP_PORT), origNginx.getAttribute(NginxController.PROXY_HTTP_PORT));
- assertEquals(newNginx.getConfig(NginxController.STICKY), origNginx.getConfig(NginxController.STICKY));
-
- assertAttributeEqualsEventually(newNginx, SoftwareProcess.SERVICE_UP, true);
- assertHttpStatusCodeEventuallyEquals(rootUrl, 404);
-
- assertEquals(monitor.getFailures(), 0);
- }
-
- /**
- * Test can rebind with an active server pool.
- */
- @Test(groups = "Integration")
- public void testRebindsWithoutLosingServerPool() throws Exception {
-
- // Set up nginx with a server pool
- DynamicCluster origServerPool = origApp.createAndManageChild(EntitySpec.create(DynamicCluster.class)
- .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(Tomcat8Server.class).configure("war", getTestWar()))
- .configure("initialSize", 1));
-
- NginxController origNginx = origApp.createAndManageChild(EntitySpec.create(NginxController.class)
- .configure("serverPool", origServerPool)
- .configure("domain", "localhost"));
-
- // Start the app, and ensure reachable; start polling the URL
- origApp.start(ImmutableList.of(localhostProvisioningLocation));
-
- String rootUrl = origNginx.getAttribute(NginxController.ROOT_URL);
- Tomcat8Server origServer = (Tomcat8Server) Iterables.getOnlyElement(origServerPool.getMembers());
- assertEquals(origNginx.getAttribute(NginxController.SERVER_POOL_TARGETS).keySet(), ImmutableSet.of(origServer));
-
- assertHttpStatusCodeEventuallyEquals(rootUrl, 200);
- WebAppMonitor monitor = newWebAppMonitor(rootUrl, 200);
- final String origConfigFile = origNginx.getConfigFile();
-
- // Rebind
- newApp = rebind(RebindOptions.create().terminateOrigManagementContext(true));
- ManagementContext newManagementContext = newApp.getManagementContext();
- final NginxController newNginx = (NginxController) Iterables.find(newApp.getChildren(), Predicates.instanceOf(NginxController.class));
- final DynamicCluster newServerPool = (DynamicCluster) newManagementContext.getEntityManager().getEntity(origServerPool.getId());
- final Tomcat8Server newServer = (Tomcat8Server) Iterables.getOnlyElement(newServerPool.getMembers());
-
- // Expect continually to have same nginx members; should not lose them temporarily!
- Asserts.succeedsContinually(new Runnable() {
- public void run() {
- Map<Entity, String> newNginxMemebers = newNginx.getAttribute(NginxController.SERVER_POOL_TARGETS);
- assertEquals(newNginxMemebers.keySet(), ImmutableSet.of(newServer));
- }});
-
-
- assertAttributeEqualsEventually(newNginx, SoftwareProcess.SERVICE_UP, true);
- assertHttpStatusCodeEventuallyEquals(rootUrl, 200);
-
- assertEquals(newNginx.getConfigFile(), origConfigFile);
-
- // Check that an update doesn't break things
- newNginx.update();
-
- assertHttpStatusCodeEquals(rootUrl, 200);
-
- // Resize new cluster, and confirm change takes affect.
- // - Increase size
- // - wait for nginx to definitely be updates (TODO nicer way to wait for updated?)
- // - terminate old server
- // - confirm can still route messages
- newServerPool.resize(2);
-
- Thread.sleep(10*1000);
-
- newServer.stop();
-
- assertHttpStatusCodeEventuallyEquals(rootUrl, 200);
-
- // Check that URLs have been constantly reachable
- assertEquals(monitor.getFailures(), 0);
- }
-
-
- /**
- * Test can rebind to the with server pool and URL remappings.
- * NOTE: This requires a redirection from localhost1 to 127.0.0.1 in your /etc/hosts file
- */
- @Test(groups = "Integration")
- public void testRebindsWithoutLosingUrlMappings() throws Exception {
-
- // Set up nginx with a url-mapping
- Group origUrlMappingsGroup = origApp.createAndManageChild(EntitySpec.create(BasicGroup.class)
- .configure("childrenAsMembers", true));
-
- DynamicCluster origServerPool = origApp.createAndManageChild(EntitySpec.create(DynamicCluster.class)
- .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(Tomcat8Server.class).configure("war", getTestWar()))
- .configure("initialSize", 1));
-
- UrlMapping origMapping = origApp.getManagementContext().getEntityManager().createEntity(EntitySpec.create(UrlMapping.class)
- .configure("domain", "localhost1")
- .configure("target", origServerPool)
- .configure("rewrites", ImmutableList.of(new UrlRewriteRule("/foo/(.*)", "/$1")))
- .parent(origUrlMappingsGroup));
- Entities.manage(origMapping);
-
- NginxController origNginx = origApp.createAndManageChild(EntitySpec.create(NginxController.class)
- .configure("domain", "localhost")
- .configure("urlMappings", origUrlMappingsGroup));
-
- // Start the app, and ensure reachable; start polling the URL
- origApp.start(ImmutableList.of(localhostProvisioningLocation));
-
- String mappingGroupUrl = "http://localhost1:"+origNginx.getAttribute(NginxController.PROXY_HTTP_PORT)+"/foo/";
-
- assertHttpStatusCodeEventuallyEquals(mappingGroupUrl, 200);
- WebAppMonitor monitor = newWebAppMonitor(mappingGroupUrl, 200);
- final String origConfigFile = origNginx.getConfigFile();
-
- // Create a rebinding
- newApp = rebind(RebindOptions.create().terminateOrigManagementContext(true));
- ManagementContext newManagementContext = newApp.getManagementContext();
- final NginxController newNginx = (NginxController) Iterables.find(newApp.getChildren(), Predicates.instanceOf(NginxController.class));
- DynamicCluster newServerPool = (DynamicCluster) newManagementContext.getEntityManager().getEntity(origServerPool.getId());
- Tomcat8Server newServer = (Tomcat8Server) Iterables.getOnlyElement(newServerPool.getMembers());
-
- assertAttributeEqualsEventually(newNginx, SoftwareProcess.SERVICE_UP, true);
- assertHttpStatusCodeEventuallyEquals(mappingGroupUrl, 200);
-
- assertEquals(newNginx.getConfigFile(), origConfigFile);
-
- // Check that an update doesn't break things
- newNginx.update();
-
- assertHttpStatusCodeEquals(mappingGroupUrl, 200);
-
- // Resize new cluster, and confirm change takes affect.
- // - Increase size
- // - wait for nginx to definitely be updates (TODO nicer way to wait for updated?)
- // - terminate old server
- // - confirm can still route messages
- newServerPool.resize(2);
-
- Thread.sleep(10*1000);
-
- newServer.stop();
-
- assertHttpStatusCodeEquals(mappingGroupUrl, 200);
-
- // Check that URLs have been constantly reachable
- assertEquals(monitor.getFailures(), 0);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/77dff880/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxRebindWithHaIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxRebindWithHaIntegrationTest.java b/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxRebindWithHaIntegrationTest.java
deleted file mode 100644
index 8e2681c..0000000
--- a/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxRebindWithHaIntegrationTest.java
+++ /dev/null
@@ -1,182 +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 brooklyn.entity.proxy.nginx;
-
-import java.net.URL;
-import java.util.Collection;
-import java.util.List;
-import java.util.concurrent.Callable;
-import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-import org.apache.brooklyn.management.Task;
-import org.apache.brooklyn.management.ha.HighAvailabilityMode;
-import org.apache.brooklyn.test.EntityTestUtils;
-import org.apache.brooklyn.test.TestResourceUnavailableException;
-import org.apache.brooklyn.test.WebAppMonitor;
-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 brooklyn.entity.Feed;
-import brooklyn.entity.basic.Attributes;
-import brooklyn.entity.basic.Entities;
-import brooklyn.entity.basic.EntityInternal;
-import brooklyn.entity.basic.Lifecycle;
-import brooklyn.entity.group.DynamicCluster;
-import brooklyn.entity.proxying.EntitySpec;
-import brooklyn.entity.rebind.RebindTestFixtureWithApp;
-import brooklyn.entity.rebind.RebindTestUtils;
-import brooklyn.entity.webapp.tomcat.TomcatServer;
-import brooklyn.internal.BrooklynFeatureEnablement;
-import brooklyn.location.LocationSpec;
-import brooklyn.location.basic.LocalhostMachineProvisioningLocation;
-import brooklyn.location.basic.SshMachineLocationReuseIntegrationTest.RecordingSshjTool;
-import brooklyn.management.internal.LocalManagementContext;
-import brooklyn.test.entity.TestApplication;
-import brooklyn.util.internal.ssh.SshTool;
-import brooklyn.util.net.Networking;
-import brooklyn.util.repeat.Repeater;
-import brooklyn.util.task.BasicExecutionManager;
-import brooklyn.util.time.Duration;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-
-/**
- * Test the operation of the {@link NginxController} class.
- */
-public class NginxRebindWithHaIntegrationTest extends RebindTestFixtureWithApp {
-
- private static final Logger LOG = LoggerFactory.getLogger(NginxRebindWithHaIntegrationTest.class);
-
- private List<WebAppMonitor> webAppMonitors = new CopyOnWriteArrayList<WebAppMonitor>();
- private ExecutorService executor;
- private LocalhostMachineProvisioningLocation loc;
-
- private Boolean feedRegistration;
-
- @Override
- protected boolean useLiveManagementContext() {
- // For Aled, the test failed without own ~/.brooklyn/brooklyn.properties.
- // Suspect that was caused by local environment, with custom brooklyn.ssh.config.scriptHeader
- // to set things like correct Java on path.
- return true;
- }
-
- public String getTestWar() {
- TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), "/hello-world.war");
- return "classpath://hello-world.war";
- }
-
- @BeforeMethod(alwaysRun=true)
- public void setUp() throws Exception {
- super.setUp();
- loc = origManagementContext.getLocationManager().createLocation(LocationSpec.create(LocalhostMachineProvisioningLocation.class)
- .configure("address", Networking.getLocalHost())
- .configure(SshTool.PROP_TOOL_CLASS, RecordingSshjTool.class.getName()));
- executor = Executors.newCachedThreadPool();
-
- feedRegistration = BrooklynFeatureEnablement.isEnabled(BrooklynFeatureEnablement.FEATURE_FEED_REGISTRATION_PROPERTY);
- BrooklynFeatureEnablement.setEnablement(BrooklynFeatureEnablement.FEATURE_FEED_REGISTRATION_PROPERTY, true);
- }
-
- @AfterMethod(alwaysRun=true)
- public void tearDown() throws Exception {
- try {
- if (feedRegistration!=null)
- BrooklynFeatureEnablement.setEnablement(BrooklynFeatureEnablement.FEATURE_FEED_REGISTRATION_PROPERTY, feedRegistration);
-
- for (WebAppMonitor monitor : webAppMonitors) {
- monitor.terminate();
- }
- webAppMonitors.clear();
- if (executor != null) executor.shutdownNow();
- super.tearDown();
- } finally {
- RecordingSshjTool.reset();
- }
- }
-
- @Override
- protected TestApplication createApp() {
- origManagementContext.getHighAvailabilityManager().changeMode(HighAvailabilityMode.MASTER);
- return super.createApp();
- }
-
- @Test(groups = "Integration")
- public void testChangeModeFailureStopsTasksButHappyUponResumption() throws Exception {
- DynamicCluster origServerPool = origApp.createAndManageChild(EntitySpec.create(DynamicCluster.class)
- .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(TomcatServer.class).configure("war", getTestWar()))
- .configure("initialSize", 1));
-
- NginxController origNginx = origApp.createAndManageChild(EntitySpec.create(NginxController.class)
- .configure("serverPool", origServerPool)
- .configure("domain", "localhost"));
-
- origApp.start(ImmutableList.of(loc));
- Assert.assertTrue(RecordingSshjTool.connectionCount.get()>0);
-
- Collection<Feed> origFeeds = ((EntityInternal)origNginx).feeds().getFeeds();
- LOG.info("feeds before rebind are: "+origFeeds);
- Assert.assertTrue(origFeeds.size() >= 1);
-
- origManagementContext.getRebindManager().forcePersistNow();
-
- List<Task<?>> tasksBefore = ((BasicExecutionManager)origManagementContext.getExecutionManager()).getAllTasks();
- LOG.info("tasks before disabling HA, "+tasksBefore.size()+": "+tasksBefore);
- Assert.assertFalse(tasksBefore.isEmpty());
- origManagementContext.getHighAvailabilityManager().changeMode(HighAvailabilityMode.DISABLED);
- origApp = null;
-
- Repeater.create().every(Duration.millis(20)).backoffTo(Duration.ONE_SECOND).limitTimeTo(Duration.THIRTY_SECONDS).until(new Callable<Boolean>() {
- @Override
- public Boolean call() throws Exception {
- origManagementContext.getGarbageCollector().gcIteration();
- List<Task<?>> tasksAfter = ((BasicExecutionManager)origManagementContext.getExecutionManager()).getAllTasks();
- LOG.info("tasks after disabling HA, "+tasksAfter.size()+": "+tasksAfter);
- return tasksAfter.isEmpty();
- }
- }).runRequiringTrue();
-
- // disable SSH to localhost to ensure we don't try to ssh while rebinding
-
- RecordingSshjTool.forbidden.set(true);
- newManagementContext = createNewManagementContext();
- newApp = (TestApplication) RebindTestUtils.rebind((LocalManagementContext)newManagementContext, classLoader);
-
- NginxController newNginx = Iterables.getOnlyElement(Entities.descendants(newApp, NginxController.class));
-
- Collection<Feed> newFeeds = ((EntityInternal)newNginx).feeds().getFeeds();
- LOG.info("feeds after rebind are: "+newFeeds);
- Assert.assertTrue(newFeeds.size() >= 1);
-
- // eventually goes on fire, because we disabled ssh
- EntityTestUtils.assertAttributeEqualsEventually(newNginx, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
-
- // re-enable SSH and it should right itself
- RecordingSshjTool.forbidden.set(false);
- EntityTestUtils.assertAttributeEqualsEventually(newNginx, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/77dff880/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxUrlMappingIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxUrlMappingIntegrationTest.java b/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxUrlMappingIntegrationTest.java
deleted file mode 100644
index 2ebb1e5..0000000
--- a/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxUrlMappingIntegrationTest.java
+++ /dev/null
@@ -1,525 +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 brooklyn.entity.proxy.nginx;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
-import static org.testng.Assert.fail;
-
-import java.net.Inet4Address;
-import java.net.InetAddress;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.brooklyn.management.EntityManager;
-import org.apache.brooklyn.test.HttpTestUtils;
-import org.apache.brooklyn.test.TestResourceUnavailableException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import brooklyn.entity.BrooklynAppLiveTestSupport;
-import brooklyn.entity.Entity;
-import brooklyn.entity.Group;
-import brooklyn.entity.basic.Attributes;
-import brooklyn.entity.basic.BasicGroup;
-import brooklyn.entity.basic.Entities;
-import brooklyn.entity.basic.EntityFactory;
-import brooklyn.entity.group.DynamicCluster;
-import brooklyn.entity.proxying.EntitySpec;
-import brooklyn.entity.webapp.JavaWebAppService;
-import brooklyn.entity.webapp.WebAppService;
-import brooklyn.entity.webapp.jboss.JBoss7Server;
-import brooklyn.entity.webapp.tomcat.Tomcat8Server;
-import brooklyn.entity.webapp.tomcat.Tomcat8ServerImpl;
-import brooklyn.location.basic.LocalhostMachineProvisioningLocation;
-import brooklyn.test.Asserts;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Sets;
-
-/**
- * Test the operation of the {@link NginxController} class, for URL mapped groups (two different pools).
- *
- * These tests require that /etc/hosts contains some extra entries, such as:
- * 127.0.0.1 localhost localhost1 localhost2 localhost3 localhost4
- */
-public class NginxUrlMappingIntegrationTest extends BrooklynAppLiveTestSupport {
-
- // TODO Make JBoss7Server.deploy wait for the web-app to actually be deployed.
- // That may simplify some of the tests, because we can assert some things immediately rather than in a succeedsEventually.
-
- private static final Logger log = LoggerFactory.getLogger(NginxUrlMappingIntegrationTest.class);
-
- private NginxController nginx;
- private Group urlMappingsGroup;
- private EntityManager entityManager;
- private LocalhostMachineProvisioningLocation localLoc;
-
- @BeforeMethod(alwaysRun=true)
- @Override
- public void setUp() throws Exception {
- super.setUp();
-
- urlMappingsGroup = app.createAndManageChild(EntitySpec.create(BasicGroup.class)
- .configure("childrenAsMembers", true));
- entityManager = app.getManagementContext().getEntityManager();
-
- localLoc = new LocalhostMachineProvisioningLocation();
- }
-
- public String getTestWar() {
- TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), "/hello-world.war");
- return "classpath://hello-world.war";
- }
-
- protected void checkExtraLocalhosts() throws Exception {
- Set<String> failedHosts = Sets.newLinkedHashSet();
- List<String> allHosts = ImmutableList.of("localhost", "localhost1", "localhost2", "localhost3", "localhost4");
- for (String host : allHosts) {
- try {
- InetAddress i = InetAddress.getByName(host);
- byte[] b = ((Inet4Address)i).getAddress();
- if (b[0]!=127 || b[1]!=0 || b[2]!=0 || b[3]!=1) {
- log.warn("Failed to resolve "+host+" (test will subsequently fail, but looking for more errors first; see subsequent failure for more info): wrong IP "+Arrays.asList(b));
- failedHosts.add(host);
- }
- } catch (Exception e) {
- log.warn("Failed to resolve "+host+" (test will subsequently fail, but looking for more errors first; see subsequent failure for more info): "+e, e);
- failedHosts.add(host);
- }
- }
- if (!failedHosts.isEmpty()) {
- fail("These tests (in "+this+") require special hostnames to map to 127.0.0.1, in /etc/hosts: "+failedHosts);
- }
- }
-
- @Test(groups = "Integration")
- public void testUrlMappingServerNameAndPath() throws Exception {
- nginx = app.createAndManageChild(EntitySpec.create(NginxController.class)
- .configure("urlMappings", urlMappingsGroup));
-
- //cluster 0 mounted at localhost1 /
- DynamicCluster c0 = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
- .configure("initialSize", 1)
- .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(Tomcat8Server.class).configure("httpPort", "8100+"))
- .configure(JavaWebAppService.ROOT_WAR, getTestWar()));
- UrlMapping u0 = entityManager.createEntity(EntitySpec.create(UrlMapping.class)
- .configure("domain", "localhost1")
- .configure("target", c0)
- .parent(urlMappingsGroup));
- Entities.manage(u0);
-
- //cluster 1 at localhost2 /hello-world/
- DynamicCluster c1 = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
- .configure("initialSize", 1)
- .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(Tomcat8Server.class).configure("httpPort", "8100+"))
- .configure(JavaWebAppService.NAMED_WARS, ImmutableList.of(getTestWar())));
- UrlMapping u1 = entityManager.createEntity(EntitySpec.create(UrlMapping.class)
- .configure("domain", "localhost2")
- .configure("path", "/hello-world($|/.*)")
- .configure("target", c1)
- .parent(urlMappingsGroup));
- Entities.manage(u1);
-
- // cluster 2 at localhost3 /c2/ and mapping /hello/xxx to /hello/new xxx
- DynamicCluster c2 = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
- .configure("initialSize", 1)
- .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(Tomcat8Server.class).configure("httpPort", "8100+")));
- UrlMapping u2 = entityManager.createEntity(EntitySpec.create(UrlMapping.class)
- .configure("domain", "localhost3")
- .configure("path", "/c2($|/.*)")
- .configure("target", c2)
- .configure("rewrites", ImmutableList.of(new UrlRewriteRule("(.*/|)(hello/)(.*)", "$1$2new $3").setBreak()))
- .parent(urlMappingsGroup));
- Entities.manage(u2);
- // FIXME rewrite not a config
-
- app.start(ImmutableList.of(localLoc));
- final int port = nginx.getAttribute(NginxController.PROXY_HTTP_PORT);
- for (Entity member : c2.getMembers()) {
- ((Tomcat8Server)member).deploy(getTestWar(), "c2.war");
- }
-
- Entities.dumpInfo(app);
-
- // Confirm routes requests to the correct cluster
- // Do more than one request for each in-case just lucky with round-robin...
- Asserts.succeedsEventually(new Runnable() {
- public void run() {
- //cluster 0
- for (int i = 0; i < 2; i++) {
- HttpTestUtils.assertContentContainsText("http://localhost1:"+port, "Hello");
- HttpTestUtils.assertContentContainsText("http://localhost1:"+port+"/", "Hello");
- HttpTestUtils.assertContentContainsText("http://localhost1:"+port+"/hello/frank", "http://localhost1:"+port+"/hello/frank");
- }
- //cluster 1
- for (int i = 0; i < 2; i++) {
- HttpTestUtils.assertContentContainsText("http://localhost2:"+port+"/hello-world", "Hello");
- HttpTestUtils.assertContentContainsText("http://localhost2:"+port+"/hello-world/", "Hello");
- HttpTestUtils.assertContentContainsText("http://localhost2:"+port+"/hello-world/hello/bob", "http://localhost2:"+port+"/hello-world/hello/bob");
- }
- //cluster 2
- for (int i = 0; i < 2; i++) {
- HttpTestUtils.assertContentContainsText("http://localhost3:"+port+"/c2", "Hello");
- HttpTestUtils.assertContentContainsText("http://localhost3:"+port+"/c2/", "Hello");
- HttpTestUtils.assertContentContainsText("http://localhost3:"+port+"/c2/hello/joe", "http://localhost3:"+port+"/c2/hello/new%20joe");
- }
- }});
-
- //these should *not* be available
- HttpTestUtils.assertHttpStatusCodeEquals("http://localhost:"+port+"/", 404);
- HttpTestUtils.assertHttpStatusCodeEquals("http://localhost1:"+port+"/hello-world", 404);
- HttpTestUtils.assertHttpStatusCodeEquals("http://localhost2:"+port+"/", 404);
- HttpTestUtils.assertHttpStatusCodeEquals("http://localhost2:"+port+"/hello-world/notexists", 404);
- HttpTestUtils.assertHttpStatusCodeEquals("http://localhost3:"+port+"/", 404);
-
- // TODO previously said "make sure nginx default welcome page isn't displayed",
- // but the assertion only worked because threw exception on 404 trying to read
- // stdin of http connection. If reading stderr of http connection, we do see
- // "ginx" in the output. Why were we asserting this? Can we just delete it?
- // Previous code was:
- // Asserts.assertFails { HttpTestUtils.assertContentContainsText([timeout:1], "http://localhost:${port}/", "ginx"); }
- }
-
- @Test(groups = "Integration")
- public void testUrlMappingRoutesRequestByPathToCorrectGroup() throws Exception {
- DynamicCluster c0 = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
- .configure("initialSize", 1)
- .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(Tomcat8Server.class).configure("httpPort", "8100+")));
- UrlMapping u0 = entityManager.createEntity(EntitySpec.create(UrlMapping.class)
- .configure("domain", "localhost")
- .configure("path", "/atC0($|/.*)")
- .configure("target", c0)
- .parent(urlMappingsGroup));
- Entities.manage(u0);
-
- DynamicCluster c1 = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
- .configure("initialSize", 1)
- .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(Tomcat8Server.class).configure("httpPort", "8100+")));
- UrlMapping u1 = entityManager.createEntity(EntitySpec.create(UrlMapping.class)
- .configure("domain", "localhost")
- .configure("path", "/atC1($|/.*)")
- .configure("target", c1)
- .parent(urlMappingsGroup));
- Entities.manage(u1);
-
- nginx = app.createAndManageChild(EntitySpec.create(NginxController.class)
- .configure("domain", "localhost")
- .configure("port", "8000+")
- .configure("portNumberSensor", WebAppService.HTTP_PORT)
- .configure("urlMappings", urlMappingsGroup));
-
- app.start(ImmutableList.of(localLoc));
- final int port = nginx.getAttribute(NginxController.PROXY_HTTP_PORT);
-
- for (Entity child : c0.getMembers()) {
- ((Tomcat8Server)child).deploy(getTestWar(), "atC0.war");
- }
- for (Entity child : c1.getMembers()) {
- ((Tomcat8Server)child).deploy(getTestWar(), "atC1.war");
- }
-
- // Confirm routes requests to the correct cluster
- // Do more than one request for each in-case just lucky with round-robin...
- Asserts.succeedsEventually(new Runnable() {
- public void run() {
- for (int i = 0; i < 2; i++) {
- HttpTestUtils.assertContentContainsText("http://localhost:"+port+"/atC0", "Hello");
- HttpTestUtils.assertContentContainsText("http://localhost:"+port+"/atC0/", "Hello");
- }
- for (int i = 0; i < 2; i++) {
- HttpTestUtils.assertContentContainsText("http://localhost:"+port+"/atC1", "Hello");
- HttpTestUtils.assertContentContainsText("http://localhost:"+port+"/atC1/", "Hello");
- }
- }});
- }
-
- @Test(groups = "Integration")
- public void testUrlMappingRemovedWhenMappingEntityRemoved() throws Exception {
- DynamicCluster c0 = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
- .configure("initialSize", 1)
- .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(Tomcat8Server.class).configure("httpPort", "8100+"))
- .configure(JavaWebAppService.ROOT_WAR, getTestWar()));
- UrlMapping u0 = entityManager.createEntity(EntitySpec.create(UrlMapping.class)
- .configure("domain", "localhost2")
- .configure("target", c0)
- .parent(urlMappingsGroup));
- Entities.manage(u0);
-
- nginx = app.createAndManageChild(EntitySpec.create(NginxController.class)
- .configure("domain", "localhost")
- .configure("port", "8000+")
- .configure("portNumberSensor", WebAppService.HTTP_PORT)
- .configure("urlMappings", urlMappingsGroup));
-
- app.start(ImmutableList.of(localLoc));
- int port = nginx.getAttribute(NginxController.PROXY_HTTP_PORT);
-
- // Wait for deployment to be successful
- HttpTestUtils.assertHttpStatusCodeEventuallyEquals("http://localhost2:"+port+"/", 200);
-
- // Now remove mapping; will no longer route requests
- Entities.unmanage(u0);
- HttpTestUtils.assertHttpStatusCodeEventuallyEquals("http://localhost2:"+port+"/", 404);
- }
-
- @Test(groups = "Integration")
- public void testWithCoreClusterAndUrlMappedGroup() throws Exception {
- // TODO Should use different wars, so can confirm content from each cluster
- // TODO Could also assert on: nginx.getConfigFile()
-
- checkExtraLocalhosts();
-
- DynamicCluster coreCluster = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
- .configure("initialSize", 1)
- .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(Tomcat8Server.class).configure("httpPort", "8100+"))
- .configure(JavaWebAppService.ROOT_WAR, getTestWar()));
-
- DynamicCluster c1 = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
- .configure("initialSize", 1)
- .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(Tomcat8Server.class).configure("httpPort", "8100+"))
- .configure(JavaWebAppService.NAMED_WARS, ImmutableList.of(getTestWar())));
- UrlMapping u1 = entityManager.createEntity(EntitySpec.create(UrlMapping.class)
- .configure("domain", "localhost1")
- .configure("target", c1)
- .parent(urlMappingsGroup));
- Entities.manage(u1);
-
- nginx = app.createAndManageChild(EntitySpec.create(NginxController.class)
- .configure("serverPool", coreCluster)
- .configure("domain", "localhost")
- .configure("port", "8000+")
- .configure("portNumberSensor", WebAppService.HTTP_PORT)
- .configure("urlMappings", urlMappingsGroup));
-
- app.start(ImmutableList.of(localLoc));
- final int port = nginx.getAttribute(NginxController.PROXY_HTTP_PORT);
-
- // check nginx forwards localhost1 to c1, and localhost to core group
- Asserts.succeedsEventually(new Runnable() {
- public void run() {
- HttpTestUtils.assertContentContainsText("http://localhost1:"+port+"/hello-world", "Hello");
- HttpTestUtils.assertHttpStatusCodeEquals("http://localhost1:"+port+"", 404);
-
- HttpTestUtils.assertContentContainsText("http://localhost:"+port+"", "Hello");
- HttpTestUtils.assertHttpStatusCodeEquals("http://localhost:"+port+"/hello-world", 404);
- }});
- }
-
- @Test(groups = "Integration")
- public void testUrlMappingMultipleRewrites() throws Exception {
- nginx = app.createAndManageChild(EntitySpec.create(NginxController.class)
- .configure("urlMappings", urlMappingsGroup));
-
- //cluster 0 mounted at localhost1 /
- DynamicCluster c0 = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
- .configure("initialSize", 1)
- .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(Tomcat8Server.class).configure("httpPort", "8100+"))
- .configure(JavaWebAppService.ROOT_WAR, getTestWar()));
- UrlMapping u0 = entityManager.createEntity(EntitySpec.create(UrlMapping.class)
- .configure("domain", "localhost1")
- .configure("target", c0)
- .parent(urlMappingsGroup));
- u0.addRewrite("/goodbye/al(.*)", "/hello/al$1");
- u0.addRewrite(new UrlRewriteRule("/goodbye(|/.*)$", "/hello$1").setBreak());
- u0.addRewrite("(.*)/hello/al(.*)", "$1/hello/Big Al$2");
- u0.addRewrite("/hello/an(.*)", "/hello/Sir An$1");
- Entities.manage(u0);
-
- app.start(ImmutableList.of(localLoc));
- final int port = nginx.getAttribute(NginxController.PROXY_HTTP_PORT);
-
- // Confirm routes requests to the correct cluster
- Asserts.succeedsEventually(new Runnable() {
- public void run() {
- // health check
- HttpTestUtils.assertContentContainsText("http://localhost1:"+port+"", "Hello");
- HttpTestUtils.assertContentContainsText("http://localhost1:"+port+"/hello/frank", "http://localhost1:"+port+"/hello/frank");
-
- // goodbye rewritten to hello
- HttpTestUtils.assertContentContainsText("http://localhost1:"+port+"/goodbye/frank", "http://localhost1:"+port+"/hello/frank");
- // hello al rewritten to hello Big Al
- HttpTestUtils.assertContentContainsText("http://localhost1:"+port+"/hello/aled", "http://localhost1:"+port+"/hello/Big%20Aled");
- // hello andrew rewritten to hello Sir Andrew
- HttpTestUtils.assertContentContainsText("http://localhost1:"+port+"/hello/andrew", "http://localhost1:"+port+"/hello/Sir%20Andrew");
-
- // goodbye alex rewritten to hello Big Alex (two rewrites)
- HttpTestUtils.assertContentContainsText("http://localhost1:"+port+"/goodbye/alex", "http://localhost1:"+port+"/hello/Big%20Alex");
- // but goodbye andrew rewritten only to hello Andrew -- test the "break" logic above (won't continue rewriting)
- HttpTestUtils.assertContentContainsText("http://localhost1:"+port+"/goodbye/andrew", "http://localhost1:"+port+"/hello/andrew");
-
- // al rewrite can be anywhere
- HttpTestUtils.assertContentContainsText("http://localhost1:"+port+"/hello/hello/alex", "http://localhost1:"+port+"/hello/hello/Big%20Alex");
- // but an rewrite must be at beginning
- HttpTestUtils.assertContentContainsText("http://localhost1:"+port+"/hello/hello/andrew", "http://localhost1:"+port+"/hello/hello/andrew");
- }});
- }
-
- @Test(groups = "Integration")
- public void testUrlMappingGroupRespondsToScaleOut() throws Exception {
- checkExtraLocalhosts();
-
- nginx = app.createAndManageChild(EntitySpec.create(NginxController.class)
- .configure("domain", "localhost")
- .configure("port", "8000+")
- .configure("portNumberSensor", WebAppService.HTTP_PORT)
- .configure("urlMappings", urlMappingsGroup));
-
- final DynamicCluster c1 = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
- .configure("initialSize", 1)
- .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(Tomcat8Server.class).configure("httpPort", "8100+"))
- .configure(JavaWebAppService.ROOT_WAR, getTestWar()));
- final UrlMapping u1 = entityManager.createEntity(EntitySpec.create(UrlMapping.class)
- .configure("domain", "localhost1")
- .configure("target", c1)
- .parent(urlMappingsGroup));
- Entities.manage(u1);
-
- app.start(ImmutableList.of(localLoc));
- int port = nginx.getAttribute(NginxController.PROXY_HTTP_PORT);
-
- Entity c1jboss = Iterables.getOnlyElement(c1.getMembers());
-
- // Wait for app-server to be responsive, and url-mapping to update its TARGET_ADDRESSES (through async subscription)
- Asserts.succeedsEventually(new Runnable() {
- public void run() {
- // Entities.dumpInfo(app);
- assertEquals(u1.getAttribute(UrlMapping.TARGET_ADDRESSES).size(), 1);
- }});
-
- // check nginx forwards localhost1 to c1
- HttpTestUtils.assertContentEventuallyContainsText("http://localhost1:"+port+"", "Hello");
-
- // Resize target cluster of url-mapping
- c1.resize(2);
- List c1jbosses = new ArrayList(c1.getMembers());
- c1jbosses.remove(c1jboss);
- // the unnecessary (Entity) cast is required as a work-around to an IntelliJ issue that prevents Brooklyn from launching from the IDE
- Entity c1jboss2 = (Entity)Iterables.getOnlyElement(c1jbosses);
-
- // TODO Have to wait for new app-server; should fix app-servers to block
- // Also wait for TARGET_ADDRESSES to update
- assertAppServerRespondsEventually(c1jboss2);
- Asserts.succeedsEventually(new Runnable() {
- public void run() {
- assertEquals(u1.getAttribute(UrlMapping.TARGET_ADDRESSES).size(), 2);
- }});
-
- // check jboss2 is included in nginx rules
- // TODO Should getConfigFile return the current config file, rather than recalculate?
- // This assertion isn't good enough to tell if it's been deployed.
- final String c1jboss2addr = c1jboss2.getAttribute(Attributes.HOSTNAME)+":"+c1jboss2.getAttribute(Attributes.HTTP_PORT);
- Asserts.succeedsEventually(new Runnable() {
- public void run() {
- String conf = nginx.getConfigFile();
- assertTrue(conf.contains(c1jboss2addr), "could not find "+c1jboss2addr+" in:\n"+conf);
- }});
-
- // and check forwarding to c1 by nginx still works
- for (int i = 0; i < 2; i++) {
- HttpTestUtils.assertContentContainsText("http://localhost1:"+port+"", "Hello");
- }
- }
-
- @Test(groups = "Integration")
- public void testUrlMappingWithEmptyCoreCluster() throws Exception {
- DynamicCluster nullCluster = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
- .configure("initialSize", 0)
- .configure("factory", new EntityFactory<Entity>() {
- public Entity newEntity(Map flags, Entity parent) {
- throw new UnsupportedOperationException();
- }}));
-
- DynamicCluster c0 = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
- .configure("initialSize", 1)
- .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(Tomcat8Server.class).configure("httpPort", "8100+")));
- UrlMapping u0 = entityManager.createEntity(EntitySpec.create(UrlMapping.class)
- .configure("domain", "localhost")
- .configure("path", "/atC0($|/.*)")
- .configure("target", c0)
- .parent(urlMappingsGroup));
- Entities.manage(u0);
-
- nginx = app.createAndManageChild(EntitySpec.create(NginxController.class)
- .configure("cluster", nullCluster)
- .configure("domain", "localhost")
- .configure("port", "8000+")
- .configure("portNumberSensor", WebAppService.HTTP_PORT)
- .configure("urlMappings", urlMappingsGroup));
-
- app.start(ImmutableList.of(localLoc));
- final int port = nginx.getAttribute(NginxController.PROXY_HTTP_PORT);
-
- for (Entity child : c0.getMembers()) {
- ((Tomcat8Server)child).deploy(getTestWar(), "atC0.war");
- }
-
- // Confirm routes requests to the correct cluster
- // Do more than one request for each in-case just lucky with round-robin...
- Asserts.succeedsEventually(new Runnable() {
- public void run() {
- for (int i = 0; i < 2; i++) {
- HttpTestUtils.assertContentContainsText("http://localhost:"+port+"/atC0/", "Hello");
- HttpTestUtils.assertContentContainsText("http://localhost:"+port+"/atC0", "Hello");
- }
- }});
-
- // And empty-core should return 404
- HttpTestUtils.assertHttpStatusCodeEquals("http://localhost:"+port+"", 404);
- }
-
- @Test(groups = "Integration")
- public void testDiscardUrlMapping() throws Exception {
- //cluster 0 mounted at localhost1 /
- DynamicCluster c0 = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
- .configure("initialSize", 1)
- .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(Tomcat8Server.class).configure("httpPort", "8100+"))
- .configure(JavaWebAppService.ROOT_WAR, getTestWar()));
- UrlMapping u0 = entityManager.createEntity(EntitySpec.create(UrlMapping.class)
- .configure("domain", "localhost1")
- .configure("target", c0)
- .parent(urlMappingsGroup));
- Entities.manage(u0);
-
- nginx = app.createAndManageChild(EntitySpec.create(NginxController.class)
- .configure("urlMappings", urlMappingsGroup));
-
- app.start(ImmutableList.of(localLoc));
- int port = nginx.getAttribute(NginxController.PROXY_HTTP_PORT);
-
- HttpTestUtils.assertHttpStatusCodeEventuallyEquals("http://localhost1:"+port+"", 200);
-
- // Discard, and confirm that subsequently get a 404 instead
- u0.discard();
-
- HttpTestUtils.assertHttpStatusCodeEventuallyEquals("http://localhost1:"+port+"", 404);
- }
-
- private void assertAppServerRespondsEventually(Entity server) {
- String hostname = server.getAttribute(Attributes.HOSTNAME);
- int port = server.getAttribute(Attributes.HTTP_PORT);
- HttpTestUtils.assertHttpStatusCodeEventuallyEquals("http://"+hostname+":"+port, 200);
- }
-}