public static void assertHttpStatusCodeEventuallyEquals(final String url, final int expectedCode) { assertHttpStatusCodeEventuallyEquals(MutableMap.<String, Object>of(), url, expectedCode); }
protected static void waitForApps(String webConsoleUri) { HttpTestUtils.assertHttpStatusCodeEquals(webConsoleUri+"/v1/applications", 200, 403); HttpTestUtils.assertHttpStatusCodeEventuallyEquals(webConsoleUri+"/v1/applications", 200); }
private void assertAppServerRespondsEventually(Entity server) { String hostname = server.getAttribute(Attributes.HOSTNAME); int port = server.getAttribute(Attributes.HTTP_PORT); HttpTestUtils.assertHttpStatusCodeEventuallyEquals("http://"+hostname+":"+port, 200); } }
@Override protected void doTest(Location loc) throws Exception { nginx = app.createAndManageChild(EntitySpec.create(NginxController.class) .configure("portNumberSensor", WebAppService.HTTP_PORT)); app.start(ImmutableList.of(loc)); // nginx should be up, and URL reachable EntityAsserts.assertAttributeEqualsEventually(nginx, SoftwareProcess.SERVICE_UP, true); HttpTestUtils.assertHttpStatusCodeEventuallyEquals(nginx.getAttribute(NginxController.ROOT_URL), 404); }
/** * Test that the broker starts up with HTTP management enabled, and we can connect to the URL. */ @Test(groups = "Integration") public void canStartupAndShutdownWithHttpManagement() { qpid = app.createAndManageChild(EntitySpec.create(QpidBroker.class) .configure("httpManagementPort", "8888+")); qpid.start(ImmutableList.of(testLocation)); EntityAsserts.assertAttributeEqualsEventually(qpid, Startable.SERVICE_UP, true); String httpUrl = "http://"+qpid.getAttribute(QpidBroker.HOSTNAME)+":"+qpid.getAttribute(QpidBroker.HTTP_MANAGEMENT_PORT)+"/management"; HttpTestUtils.assertHttpStatusCodeEventuallyEquals(httpUrl, 200); // TODO check actual REST output qpid.stop(); assertFalse(qpid.getAttribute(Startable.SERVICE_UP)); }
@Override protected void doTest(Location loc) throws Exception { final NodeJsWebAppService server = app.createAndManageChild(EntitySpec.create(NodeJsWebAppService.class) .configure("gitRepoUrl", GIT_REPO_URL) .configure("appFileName", APP_FILE) .configure("appName", APP_NAME)); app.start(ImmutableList.of(loc)); String url = server.getAttribute(NodeJsWebAppService.ROOT_URL); HttpTestUtils.assertHttpStatusCodeEventuallyEquals(url, 200); HttpTestUtils.assertContentContainsText(url, "Hello"); }
@Override protected void doTest(Location loc) throws Exception { final Tomcat8Server server = app.createAndManageChild(EntitySpec.create(Tomcat8Server.class) .configure("war", getTestWar())); app.start(ImmutableList.of(loc)); String url = server.getAttribute(Tomcat8Server.ROOT_URL); HttpTestUtils.assertHttpStatusCodeEventuallyEquals(url, 200); HttpTestUtils.assertContentContainsText(url, "Hello"); Asserts.succeedsEventually(new Runnable() { @Override public void run() { assertNotNull(server.getAttribute(Tomcat8Server.REQUEST_COUNT)); assertNotNull(server.getAttribute(Tomcat8Server.ERROR_COUNT)); assertNotNull(server.getAttribute(Tomcat8Server.TOTAL_PROCESSING_TIME)); }}); }
@Test(groups = "Integration") public void testRestart() { serverPool = app.createAndManageChild(EntitySpec.create(DynamicCluster.class) .configure("initialSize", 0) .configure("memberSpec", EntitySpec.create(TestEntity.class))); nginx = app.createAndManageChild(EntitySpec.create(NginxController.class) .configure("serverPool", serverPool) .configure("domain", "localhost")); app.start(ImmutableList.of(localLoc)); nginx.restart(); EntityAsserts.assertAttributeEqualsEventually(nginx, SoftwareProcess.SERVICE_UP, true); assertHttpStatusCodeEventuallyEquals(nginx.getAttribute(NginxController.ROOT_URL), 404); }
@Override protected void doTest(Location loc) throws Exception { final JBoss6Server server = app.createAndManageChild(EntitySpec.create(JBoss6Server.class) .configure("war", getTestWar())); app.start(ImmutableList.of(loc)); String url = server.getAttribute(JBoss6Server.ROOT_URL); HttpTestUtils.assertHttpStatusCodeEventuallyEquals(url, 200); HttpTestUtils.assertContentContainsText(url, "Hello"); Asserts.succeedsEventually(new Runnable() { @Override public void run() { assertNotNull(server.getAttribute(JBoss6Server.REQUEST_COUNT)); assertNotNull(server.getAttribute(JBoss6Server.ERROR_COUNT)); assertNotNull(server.getAttribute(JBoss6Server.TOTAL_PROCESSING_TIME)); assertNotNull(server.getAttribute(JBoss6Server.MAX_PROCESSING_TIME)); assertNotNull(server.getAttribute(JBoss6Server.BYTES_RECEIVED)); assertNotNull(server.getAttribute(JBoss6Server.BYTES_SENT)); }}); }
@Override protected void doTest(Location loc) throws Exception { final JBoss7Server server = app.createAndManageChild(EntitySpec.create(JBoss7Server.class) .configure("war", getTestWar())); app.start(ImmutableList.of(loc)); String url = server.getAttribute(JBoss7Server.ROOT_URL); HttpTestUtils.assertHttpStatusCodeEventuallyEquals(url, 200); HttpTestUtils.assertContentContainsText(url, "Hello"); Asserts.succeedsEventually(new Runnable() { @Override public void run() { assertNotNull(server.getAttribute(JBoss7Server.REQUEST_COUNT)); assertNotNull(server.getAttribute(JBoss7Server.ERROR_COUNT)); assertNotNull(server.getAttribute(JBoss7Server.TOTAL_PROCESSING_TIME)); assertNotNull(server.getAttribute(JBoss7Server.MAX_PROCESSING_TIME)); assertNotNull(server.getAttribute(JBoss7Server.BYTES_RECEIVED)); assertNotNull(server.getAttribute(JBoss7Server.BYTES_SENT)); }}); }
@Override protected void doTest(Location loc) throws Exception { final Tomcat8Server server = app.createAndManageChild(EntitySpec.create(Tomcat8Server.class) .configure("war", getTestWar())); app.start(ImmutableList.of(loc)); String url = server.getAttribute(Tomcat8Server.ROOT_URL); HttpTestUtils.assertHttpStatusCodeEventuallyEquals(url, 200); HttpTestUtils.assertContentContainsText(url, "Hello"); Asserts.succeedsEventually(new Runnable() { @Override public void run() { assertNotNull(server.getAttribute(Tomcat8Server.REQUEST_COUNT)); assertNotNull(server.getAttribute(Tomcat8Server.ERROR_COUNT)); assertNotNull(server.getAttribute(Tomcat8Server.TOTAL_PROCESSING_TIME)); // TODO These appear not to be set in TomcatServerImpl.connectSensors // See TomcatServerEc2LiveTest, where these are also not included. // assertNotNull(server.getAttribute(TomcatServer.MAX_PROCESSING_TIME)); // assertNotNull(server.getAttribute(TomcatServer.BYTES_RECEIVED)); // assertNotNull(server.getAttribute(TomcatServer.BYTES_SENT)); }}); }
@Override protected void doTest(Location loc) throws Exception { final JBoss7Server server = app.createAndManageChild(EntitySpec.create(JBoss7Server.class) .configure("war", getTestWar())); app.start(ImmutableList.of(loc)); String url = server.getAttribute(JBoss7Server.ROOT_URL); HttpTestUtils.assertHttpStatusCodeEventuallyEquals(url, 200); HttpTestUtils.assertContentContainsText(url, "Hello"); Asserts.succeedsEventually(new Runnable() { @Override public void run() { assertNotNull(server.getAttribute(JBoss7Server.REQUEST_COUNT)); assertNotNull(server.getAttribute(JBoss7Server.ERROR_COUNT)); assertNotNull(server.getAttribute(JBoss7Server.TOTAL_PROCESSING_TIME)); assertNotNull(server.getAttribute(JBoss7Server.MAX_PROCESSING_TIME)); assertNotNull(server.getAttribute(JBoss7Server.BYTES_RECEIVED)); assertNotNull(server.getAttribute(JBoss7Server.BYTES_SENT)); }}); }
@Override protected void doTest(Location loc) throws Exception { final TomcatServer server = app.createAndManageChild(EntitySpec.create(TomcatServer.class) .configure("war", getTestWar())); app.start(ImmutableList.of(loc)); String url = server.getAttribute(TomcatServer.ROOT_URL); HttpTestUtils.assertHttpStatusCodeEventuallyEquals(url, 200); HttpTestUtils.assertContentContainsText(url, "Hello"); Asserts.succeedsEventually(new Runnable() { @Override public void run() { assertNotNull(server.getAttribute(TomcatServer.REQUEST_COUNT)); assertNotNull(server.getAttribute(TomcatServer.ERROR_COUNT)); assertNotNull(server.getAttribute(TomcatServer.TOTAL_PROCESSING_TIME)); // TODO These appear not to be set in TomcatServerImpl.connectSensors // See TomcatServerEc2LiveTest, where these are also not included. // assertNotNull(server.getAttribute(TomcatServer.MAX_PROCESSING_TIME)); // assertNotNull(server.getAttribute(TomcatServer.BYTES_RECEIVED)); // assertNotNull(server.getAttribute(TomcatServer.BYTES_SENT)); }}); }
@Override protected void doTest(Location loc) throws Exception { final JBoss7Server server = app.createAndManageChild(EntitySpec.create(JBoss7Server.class) .configure("war", getTestWar())); app.start(ImmutableList.of(loc)); String url = server.getAttribute(JBoss7Server.ROOT_URL); HttpTestUtils.assertHttpStatusCodeEventuallyEquals(url, 200); HttpTestUtils.assertContentContainsText(url, "Hello"); Asserts.succeedsEventually(new Runnable() { @Override public void run() { assertNotNull(server.getAttribute(JBoss7Server.REQUEST_COUNT)); assertNotNull(server.getAttribute(JBoss7Server.ERROR_COUNT)); assertNotNull(server.getAttribute(JBoss7Server.TOTAL_PROCESSING_TIME)); assertNotNull(server.getAttribute(JBoss7Server.MAX_PROCESSING_TIME)); assertNotNull(server.getAttribute(JBoss7Server.BYTES_RECEIVED)); assertNotNull(server.getAttribute(JBoss7Server.BYTES_SENT)); } }); }
/** * 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("memberSpec", EntitySpec.create(TestEntity.class))); nginx = app.createAndManageChild(EntitySpec.create(NginxController.class) .configure("serverPool", serverPool) .configure("domain", "localhost")); app.start(ImmutableList.of(localLoc)); EntityAsserts.assertAttributeEqualsEventually(nginx, SoftwareProcess.SERVICE_UP, true); assertHttpStatusCodeEventuallyEquals(nginx.getAttribute(NginxController.ROOT_URL), 404); }
@Test(groups="Integration") public void testConfiguresController() { ControlledDynamicWebAppCluster cluster = app.createAndManageChild(EntitySpec.create(ControlledDynamicWebAppCluster.class) .configure("initialSize", 1) .configure("memberSpec", EntitySpec.create(TomcatServer.class).configure("war", getTestWar()))); app.start(locs); String url = cluster.getController().getAttribute(NginxController.ROOT_URL); HttpTestUtils.assertHttpStatusCodeEventuallyEquals(url, 200); HttpTestUtils.assertContentEventuallyContainsText(url, "Hello"); }
@Override protected void doTest(Location loc) throws Exception { final TomcatServer server = app.createAndManageChild(EntitySpec.create(TomcatServer.class) .configure(TomcatServer.OPEN_IPTABLES, true) .configure("war", getTestWar())); app.start(ImmutableList.of(loc)); String url = server.getAttribute(TomcatServer.ROOT_URL); HttpTestUtils.assertHttpStatusCodeEventuallyEquals(url, 200); HttpTestUtils.assertContentContainsText(url, "Hello"); Asserts.succeedsEventually(new Runnable() { @Override public void run() { assertNotNull(server.getAttribute(TomcatServer.REQUEST_COUNT)); assertNotNull(server.getAttribute(TomcatServer.ERROR_COUNT)); assertNotNull(server.getAttribute(TomcatServer.TOTAL_PROCESSING_TIME)); }}); }
@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 = urlMappingsGroup.addChild(EntitySpec.create(UrlMapping.class) .configure("domain", "localhost1") .configure("target", c0)); 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); }
protected void runTest(UsesJmx.JmxAgentModes jmxAgentMode) throws Exception { final JBoss6Server server = app.createAndManageChild(EntitySpec.create(JBoss6Server.class) .configure(JBoss6Server.PORT_INCREMENT, PORT_INCREMENT) .configure(UsesJmx.JMX_AGENT_MODE, jmxAgentMode) .configure("war", getTestWarWithNoMapping())); app.start(ImmutableList.of(localhostProvisioningLocation)); String httpUrl = server.getAttribute(JBoss6Server.ROOT_URL); HttpTestUtils.assertHttpStatusCodeEventuallyEquals(httpUrl, 200); HttpTestUtils.assertContentContainsText(httpUrl, "Hello"); Asserts.succeedsEventually(new Runnable() { @Override public void run() { // TODO Could test other attributes as well; see jboss7 test assertNotNull(server.getAttribute(JBoss6Server.REQUEST_COUNT)); assertNotNull(server.getAttribute(JBoss6Server.ERROR_COUNT)); assertNotNull(server.getAttribute(JBoss6Server.TOTAL_PROCESSING_TIME)); }}); } }
@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 = urlMappingsGroup.addChild(EntitySpec.create(UrlMapping.class) .configure("domain", "localhost2") .configure("target", c0)); 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); }