You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by gr...@apache.org on 2014/08/21 18:01:21 UTC
[06/11] git commit: Added simple integration and live tests
Added simple integration and live tests
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/a694716f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/a694716f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/a694716f
Branch: refs/heads/master
Commit: a694716ff09f21da8fa5f0192d92dd61d3ebc21a
Parents: a68f429
Author: Andrew Kennedy <gr...@apache.org>
Authored: Thu Jul 31 16:21:46 2014 +0100
Committer: Andrew Kennedy <gr...@apache.org>
Committed: Thu Aug 21 14:50:27 2014 +0100
----------------------------------------------------------------------
.../webapp/nodejs/NodeJsWebAppEc2LiveTest.java | 41 ++++++++++
.../NodeJsWebAppFixtureIntegrationTest.java | 44 +++++++++++
.../NodeJsWebAppSimpleIntegrationTest.java | 82 ++++++++++++++++++++
.../nodejs/NodeJsWebAppSoftlayerLiveTest.java | 48 ++++++++++++
4 files changed, 215 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a694716f/software/webapp/src/test/java/brooklyn/entity/webapp/nodejs/NodeJsWebAppEc2LiveTest.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/entity/webapp/nodejs/NodeJsWebAppEc2LiveTest.java b/software/webapp/src/test/java/brooklyn/entity/webapp/nodejs/NodeJsWebAppEc2LiveTest.java
new file mode 100644
index 0000000..7738516
--- /dev/null
+++ b/software/webapp/src/test/java/brooklyn/entity/webapp/nodejs/NodeJsWebAppEc2LiveTest.java
@@ -0,0 +1,41 @@
+package brooklyn.entity.webapp.nodejs;
+
+import static brooklyn.entity.webapp.nodejs.NodeJsWebAppFixtureIntegrationTest.*;
+import static org.testng.Assert.assertNotNull;
+
+import brooklyn.entity.AbstractEc2LiveTest;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.location.Location;
+import brooklyn.test.Asserts;
+import brooklyn.test.HttpTestUtils;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * A simple test of installing+running on AWS-EC2, using various OS distros and versions.
+ */
+public class NodeJsWebAppEc2LiveTest extends AbstractEc2LiveTest {
+
+ @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");
+
+ Asserts.succeedsEventually(new Runnable() {
+ @Override public void run() {
+ assertNotNull(server.getAttribute(NodeJsWebAppService.REQUEST_COUNT));
+ assertNotNull(server.getAttribute(NodeJsWebAppService.ERROR_COUNT));
+ assertNotNull(server.getAttribute(NodeJsWebAppService.TOTAL_PROCESSING_TIME));
+ }});
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a694716f/software/webapp/src/test/java/brooklyn/entity/webapp/nodejs/NodeJsWebAppFixtureIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/entity/webapp/nodejs/NodeJsWebAppFixtureIntegrationTest.java b/software/webapp/src/test/java/brooklyn/entity/webapp/nodejs/NodeJsWebAppFixtureIntegrationTest.java
new file mode 100644
index 0000000..af6a593
--- /dev/null
+++ b/software/webapp/src/test/java/brooklyn/entity/webapp/nodejs/NodeJsWebAppFixtureIntegrationTest.java
@@ -0,0 +1,44 @@
+package brooklyn.entity.webapp.nodejs;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.DataProvider;
+
+import brooklyn.entity.basic.SoftwareProcess;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.entity.webapp.AbstractWebAppFixtureIntegrationTest;
+import brooklyn.entity.webapp.WebAppService;
+import brooklyn.location.basic.PortRanges;
+import brooklyn.test.entity.TestApplication;
+
+public class NodeJsWebAppFixtureIntegrationTest extends AbstractWebAppFixtureIntegrationTest {
+
+ private static final Logger LOG = LoggerFactory.getLogger(NodeJsWebAppFixtureIntegrationTest.class);
+
+ public static final String GIT_REPO_URL = "https://github.com/grkvlt/node-hello-world.git";
+ public static final String APP_FILE = "app.js";
+ public static final String APP_NAME = "node-hello-world";
+
+ @DataProvider(name = "basicEntities")
+ public Object[][] basicEntities() {
+ TestApplication nodejsApp = newTestApplication();
+ NodeJsWebAppService nodejs = nodejsApp.createAndManageChild(EntitySpec.create(NodeJsWebAppService.class)
+ .configure(NodeJsWebAppService.HTTP_PORT, PortRanges.fromString(DEFAULT_HTTP_PORT))
+ .configure("gitRepoUrl", GIT_REPO_URL)
+ .configure("appFileName", APP_FILE)
+ .configure("appName", APP_NAME));
+
+ return new WebAppService[][] {
+ new WebAppService[] { nodejs }
+ };
+ }
+
+ public static void main(String ...args) throws Exception {
+ NodeJsWebAppFixtureIntegrationTest t = new NodeJsWebAppFixtureIntegrationTest();
+ t.setUp();
+ t.testReportsServiceDownWhenKilled((SoftwareProcess) t.basicEntities()[0][0]);
+ t.shutdownApp();
+ t.shutdownMgmt();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a694716f/software/webapp/src/test/java/brooklyn/entity/webapp/nodejs/NodeJsWebAppSimpleIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/entity/webapp/nodejs/NodeJsWebAppSimpleIntegrationTest.java b/software/webapp/src/test/java/brooklyn/entity/webapp/nodejs/NodeJsWebAppSimpleIntegrationTest.java
new file mode 100644
index 0000000..1ad8cf8
--- /dev/null
+++ b/software/webapp/src/test/java/brooklyn/entity/webapp/nodejs/NodeJsWebAppSimpleIntegrationTest.java
@@ -0,0 +1,82 @@
+package brooklyn.entity.webapp.nodejs;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.fail;
+
+import java.net.ServerSocket;
+import java.util.Iterator;
+
+import org.jclouds.util.Throwables2;
+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.basic.ApplicationBuilder;
+import brooklyn.entity.basic.Entities;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.location.PortRange;
+import brooklyn.location.basic.LocalhostMachineProvisioningLocation;
+import brooklyn.location.basic.PortRanges;
+import brooklyn.test.entity.TestApplication;
+import brooklyn.util.net.Networking;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * This tests the operation of the {@link NodeJsWebAppService} entity.
+ *
+ * FIXME this test is largely superseded by WebApp*IntegrationTest which tests inter alia Tomcat
+ */
+public class NodeJsWebAppSimpleIntegrationTest {
+ @SuppressWarnings("unused")
+ private static final Logger LOG = LoggerFactory.getLogger(NodeJsWebAppSimpleIntegrationTest.class);
+
+ /** don't use 8080 since that is commonly used by testing software; use different from other tests. */
+ static PortRange DEFAULT_HTTP_PORT_RANGE = PortRanges.fromString("7880-7980");
+
+ private TestApplication app;
+ private NodeJsWebAppService nodejs;
+ private int httpPort;
+
+ @BeforeMethod(alwaysRun=true)
+ public void pickFreePort() {
+ for (Iterator<Integer> iter = DEFAULT_HTTP_PORT_RANGE.iterator(); iter.hasNext();) {
+ Integer port = iter.next();
+ if (Networking.isPortAvailable(port)) {
+ httpPort = port;
+ return;
+ }
+ }
+ fail("someone is already listening on ports "+DEFAULT_HTTP_PORT_RANGE+"; tests assume that port is free on localhost");
+ }
+
+ @AfterMethod(alwaysRun=true)
+ public void tearDown() throws Exception {
+ if (app != null) Entities.destroyAll(app.getManagementContext());
+ }
+
+ @Test(groups="Integration")
+ public void detectFailureIfTomcanodejsantBindToPort() throws Exception {
+ ServerSocket listener = new ServerSocket(httpPort);
+ try {
+ app = ApplicationBuilder.newManagedApp(TestApplication.class);
+ nodejs = app.createAndManageChild(EntitySpec.create(NodeJsWebAppService.class).configure("httpPort", httpPort));
+
+ try {
+ nodejs.start(ImmutableList.of(app.getManagementContext().getLocationManager().manage(new LocalhostMachineProvisioningLocation())));
+ fail("Should have thrown start-exception");
+ } catch (Exception e) {
+ // LocalhostMachineProvisioningLocation does NetworkUtils.isPortAvailable, so get -1
+ IllegalArgumentException iae = Throwables2.getFirstThrowableOfType(e, IllegalArgumentException.class);
+ if (iae == null || iae.getMessage() == null || !iae.getMessage().equals("port for httpPort is null")) throw e;
+ } finally {
+ nodejs.stop();
+ }
+ assertFalse(nodejs.getAttribute(NodeJsWebAppServiceImpl.SERVICE_UP));
+ } finally {
+ listener.close();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a694716f/software/webapp/src/test/java/brooklyn/entity/webapp/nodejs/NodeJsWebAppSoftlayerLiveTest.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/entity/webapp/nodejs/NodeJsWebAppSoftlayerLiveTest.java b/software/webapp/src/test/java/brooklyn/entity/webapp/nodejs/NodeJsWebAppSoftlayerLiveTest.java
new file mode 100644
index 0000000..3aa13ca
--- /dev/null
+++ b/software/webapp/src/test/java/brooklyn/entity/webapp/nodejs/NodeJsWebAppSoftlayerLiveTest.java
@@ -0,0 +1,48 @@
+package brooklyn.entity.webapp.nodejs;
+
+import static brooklyn.entity.webapp.nodejs.NodeJsWebAppFixtureIntegrationTest.*;
+import static org.testng.Assert.assertNotNull;
+
+import org.testng.annotations.Test;
+
+import brooklyn.entity.AbstractSoftlayerLiveTest;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.location.Location;
+import brooklyn.test.Asserts;
+import brooklyn.test.HttpTestUtils;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * A simple test of installing+running on Softlayer, using various OS distros and versions.
+ */
+public class NodeJsWebAppSoftlayerLiveTest extends AbstractSoftlayerLiveTest {
+
+ @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");
+
+ Asserts.succeedsEventually(new Runnable() {
+ @Override public void run() {
+ assertNotNull(server.getAttribute(NodeJsWebAppService.REQUEST_COUNT));
+ assertNotNull(server.getAttribute(NodeJsWebAppService.ERROR_COUNT));
+ assertNotNull(server.getAttribute(NodeJsWebAppService.TOTAL_PROCESSING_TIME));
+ }});
+ }
+
+ @Test(groups = {"Live", "Live-sanity"})
+ @Override
+ public void test_Ubuntu_12_0_4() throws Exception {
+ super.test_Ubuntu_12_0_4();
+ }
+}