You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by ri...@apache.org on 2015/06/23 14:26:23 UTC
[07/16] incubator-brooklyn git commit: Use LocalManagementContext “ForTests”
Use LocalManagementContext “ForTests”
And extend BrooklynAppLiveTestSupport, where appropriate.
And change deprecated code to use config().set(...)
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/35e50e65
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/35e50e65
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/35e50e65
Branch: refs/heads/master
Commit: 35e50e65494b8f9ba1d9a9efe0c20cb15418cac0
Parents: e2dfb3b
Author: Aled Sage <al...@gmail.com>
Authored: Mon Jun 22 00:29:11 2015 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Mon Jun 22 00:29:11 2015 +0100
----------------------------------------------------------------------
...SoftwareProcessSshDriverIntegrationTest.java | 70 ++++++++------------
.../AbstractWebAppFixtureIntegrationTest.java | 15 +++--
...Boss7ServerNonInheritingIntegrationTest.java | 14 ++--
3 files changed, 44 insertions(+), 55 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/35e50e65/software/base/src/test/java/brooklyn/entity/java/JavaSoftwareProcessSshDriverIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/base/src/test/java/brooklyn/entity/java/JavaSoftwareProcessSshDriverIntegrationTest.java b/software/base/src/test/java/brooklyn/entity/java/JavaSoftwareProcessSshDriverIntegrationTest.java
index 021e2ac..167838c 100644
--- a/software/base/src/test/java/brooklyn/entity/java/JavaSoftwareProcessSshDriverIntegrationTest.java
+++ b/software/base/src/test/java/brooklyn/entity/java/JavaSoftwareProcessSshDriverIntegrationTest.java
@@ -25,40 +25,34 @@ import static org.testng.Assert.assertTrue;
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 com.google.common.base.Optional;
-import com.google.common.collect.ImmutableList;
-
-import brooklyn.entity.basic.ApplicationBuilder;
+import brooklyn.entity.BrooklynAppLiveTestSupport;
import brooklyn.entity.basic.BrooklynConfigKeys;
-import brooklyn.entity.basic.Entities;
import brooklyn.entity.basic.EntityLocal;
import brooklyn.entity.basic.SoftwareProcess;
import brooklyn.entity.basic.lifecycle.MyEntity;
import brooklyn.entity.proxying.EntitySpec;
import brooklyn.location.LocationSpec;
import brooklyn.location.MachineProvisioningLocation;
-import brooklyn.location.basic.LocalhostMachineProvisioningLocation;
import brooklyn.location.basic.SshMachineLocation;
-import brooklyn.management.ManagementContext;
-import brooklyn.management.internal.LocalManagementContext;
import brooklyn.test.Asserts;
-import brooklyn.test.entity.TestApplication;
+import brooklyn.test.entity.LocalManagementContextForTests;
import brooklyn.util.collections.MutableMap;
import brooklyn.util.os.Os;
import brooklyn.util.text.Strings;
-public class JavaSoftwareProcessSshDriverIntegrationTest {
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableList;
+
+public class JavaSoftwareProcessSshDriverIntegrationTest extends BrooklynAppLiveTestSupport {
private static final long TIMEOUT_MS = 10 * 1000;
private static final Logger LOG = LoggerFactory.getLogger(JavaSoftwareProcessSshDriverIntegrationTest.class);
private MachineProvisioningLocation<?> localhost;
- private TestApplication app;
private static class ConcreteJavaSoftwareProcessSshDriver extends JavaSoftwareProcessSshDriver {
public ConcreteJavaSoftwareProcessSshDriver(EntityLocal entity, SshMachineLocation machine) {
@@ -73,23 +67,14 @@ public class JavaSoftwareProcessSshDriverIntegrationTest {
}
@BeforeMethod(alwaysRun=true)
- public void setup() {
- setup(new LocalManagementContext());
- }
-
- protected void setup(ManagementContext mgmt) {
- app = ApplicationBuilder.newManagedApp(TestApplication.class, mgmt);
- localhost = mgmt.getLocationManager().createLocation(
- LocationSpec.create(LocalhostMachineProvisioningLocation.class).configure("name", "localhost"));
- }
-
- @AfterMethod(alwaysRun=true)
- public void shutdown() {
- if (app != null) Entities.destroyAll(app.getManagementContext());
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ localhost = app.newLocalhostProvisioningLocation();
}
@Test(groups = "Integration")
- public void testJavaStartStopSshDriverStartsAndStopsApp() {
+ public void testJavaStartStopSshDriverStartsAndStopsApp() throws Exception {
final MyEntity entity = app.createAndManageChild(EntitySpec.create(MyEntity.class));
app.start(ImmutableList.of(localhost));
Asserts.succeedsEventually(MutableMap.of("timeout", TIMEOUT_MS), new Runnable() {
@@ -102,7 +87,7 @@ public class JavaSoftwareProcessSshDriverIntegrationTest {
}
@Test(groups = "Integration")
- public void testGetJavaVersion() {
+ public void testGetJavaVersion() throws Exception {
SshMachineLocation sshLocation = app.getManagementContext().getLocationManager().createLocation(
LocationSpec.create(SshMachineLocation.class).configure("address", "localhost"));
JavaSoftwareProcessSshDriver driver = new ConcreteJavaSoftwareProcessSshDriver(app, sshLocation);
@@ -113,22 +98,22 @@ public class JavaSoftwareProcessSshDriverIntegrationTest {
}
@Test(groups = "Integration")
- public void testStartsInMgmtSpecifiedDirectory() {
+ public void testStartsInMgmtSpecifiedDirectory() throws Exception {
String dir = Os.mergePathsUnix(Os.tmp(), "/brooklyn-test-"+Strings.makeRandomId(4));
- shutdown();
- LocalManagementContext mgmt = new LocalManagementContext();
+ tearDown();
+ mgmt = new LocalManagementContextForTests();
mgmt.getBrooklynProperties().put(BrooklynConfigKeys.ONBOX_BASE_DIR, dir);
- setup(mgmt);
+ setUp();
doTestSpecifiedDirectory(dir, dir);
Os.deleteRecursively(dir);
}
@Test(groups = "Integration")
- public void testStartsInAppSpecifiedDirectoryUnderHome() {
+ public void testStartsInAppSpecifiedDirectoryUnderHome() throws Exception {
String dir = Os.mergePathsUnix("~/.brooklyn-test-"+Strings.makeRandomId(4));
try {
- app.setConfig(BrooklynConfigKeys.ONBOX_BASE_DIR, dir);
+ app.config().set(BrooklynConfigKeys.ONBOX_BASE_DIR, dir);
doTestSpecifiedDirectory(dir, dir);
} finally {
Os.deleteRecursively(dir);
@@ -136,33 +121,33 @@ public class JavaSoftwareProcessSshDriverIntegrationTest {
}
@Test(groups = "Integration")
- public void testStartsInDifferentRunAndInstallSpecifiedDirectories() {
+ public void testStartsInDifferentRunAndInstallSpecifiedDirectories() throws Exception {
String dir1 = Os.mergePathsUnix(Os.tmp(), "/brooklyn-test-"+Strings.makeRandomId(4));
String dir2 = Os.mergePathsUnix(Os.tmp(), "/brooklyn-test-"+Strings.makeRandomId(4));
- app.setConfig(BrooklynConfigKeys.INSTALL_DIR, dir1);
- app.setConfig(BrooklynConfigKeys.RUN_DIR, dir2);
+ app.config().set(BrooklynConfigKeys.INSTALL_DIR, dir1);
+ app.config().set(BrooklynConfigKeys.RUN_DIR, dir2);
doTestSpecifiedDirectory(dir1, dir2);
Os.deleteRecursively(dir1);
Os.deleteRecursively(dir2);
}
@Test(groups = "Integration")
- public void testStartsInLegacySpecifiedDirectory() {
+ public void testStartsInLegacySpecifiedDirectory() throws Exception {
String dir1 = Os.mergePathsUnix(Os.tmp(), "/brooklyn-test-"+Strings.makeRandomId(4));
String dir2 = Os.mergePathsUnix(Os.tmp(), "/brooklyn-test-"+Strings.makeRandomId(4));
- shutdown();
- LocalManagementContext mgmt = new LocalManagementContext();
+ tearDown();
+ mgmt = new LocalManagementContextForTests();
mgmt.getBrooklynProperties().put("brooklyn.dirs.install", dir1);
mgmt.getBrooklynProperties().put("brooklyn.dirs.run", dir2);
- setup(mgmt);
+ setUp();
- app.setConfig(BrooklynConfigKeys.RUN_DIR, dir2);
+ app.config().set(BrooklynConfigKeys.RUN_DIR, dir2);
doTestSpecifiedDirectory(dir1, dir2);
Os.deleteRecursively(dir1);
Os.deleteRecursively(dir2);
}
- protected void doTestSpecifiedDirectory(final String installDirPrefix, final String runDirPrefix) {
+ protected void doTestSpecifiedDirectory(final String installDirPrefix, final String runDirPrefix) throws Exception {
final MyEntity entity = app.createAndManageChild(EntitySpec.create(MyEntity.class));
app.start(ImmutableList.of(localhost));
Asserts.succeedsEventually(MutableMap.of("timeout", TIMEOUT_MS), new Runnable() {
@@ -185,5 +170,4 @@ public class JavaSoftwareProcessSshDriverIntegrationTest {
entity.stop();
assertFalse(entity.getAttribute(SoftwareProcess.SERVICE_UP));
}
-
}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/35e50e65/software/webapp/src/test/java/brooklyn/entity/webapp/AbstractWebAppFixtureIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/entity/webapp/AbstractWebAppFixtureIntegrationTest.java b/software/webapp/src/test/java/brooklyn/entity/webapp/AbstractWebAppFixtureIntegrationTest.java
index 3811849..7bc175c 100644
--- a/software/webapp/src/test/java/brooklyn/entity/webapp/AbstractWebAppFixtureIntegrationTest.java
+++ b/software/webapp/src/test/java/brooklyn/entity/webapp/AbstractWebAppFixtureIntegrationTest.java
@@ -37,7 +37,6 @@ import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
-import brooklyn.test.TestResourceUnavailableException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.AfterClass;
@@ -46,6 +45,7 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
+import brooklyn.config.BrooklynProperties;
import brooklyn.entity.Application;
import brooklyn.entity.Entity;
import brooklyn.entity.basic.ApplicationBuilder;
@@ -62,10 +62,11 @@ import brooklyn.location.basic.LocalhostMachineProvisioningLocation;
import brooklyn.management.ManagementContext;
import brooklyn.management.SubscriptionContext;
import brooklyn.management.SubscriptionHandle;
-import brooklyn.management.internal.LocalManagementContext;
import brooklyn.test.Asserts;
import brooklyn.test.EntityTestUtils;
import brooklyn.test.HttpTestUtils;
+import brooklyn.test.TestResourceUnavailableException;
+import brooklyn.test.entity.LocalManagementContextForTests;
import brooklyn.test.entity.TestApplication;
import brooklyn.util.collections.MutableMap;
import brooklyn.util.crypto.FluentKeySigner;
@@ -101,14 +102,13 @@ public abstract class AbstractWebAppFixtureIntegrationTest {
protected synchronized ManagementContext getMgmt() {
if (mgmt==null)
- mgmt = new LocalManagementContext();
+ mgmt = new LocalManagementContextForTests(BrooklynProperties.Factory.newDefault());
return mgmt;
}
@BeforeMethod(alwaysRun=true)
public void setUp() throws Exception {
- loc = getMgmt().getLocationManager().createLocation(LocationSpec.create(LocalhostMachineProvisioningLocation.class)
- .configure("name", "london"));
+ loc = getMgmt().getLocationManager().createLocation(LocationSpec.create(LocalhostMachineProvisioningLocation.class));
}
/*
@@ -143,8 +143,9 @@ public abstract class AbstractWebAppFixtureIntegrationTest {
@AfterClass(alwaysRun=true)
public synchronized void shutdownMgmt() {
- if (mgmt != null) {
- Entities.destroyAll(mgmt);
+ try {
+ if (mgmt != null) Entities.destroyAll(mgmt);
+ } finally {
mgmt = null;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/35e50e65/software/webapp/src/test/java/brooklyn/entity/webapp/jboss/JBoss7ServerNonInheritingIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/entity/webapp/jboss/JBoss7ServerNonInheritingIntegrationTest.java b/software/webapp/src/test/java/brooklyn/entity/webapp/jboss/JBoss7ServerNonInheritingIntegrationTest.java
index 0c056ca..948a9d6 100644
--- a/software/webapp/src/test/java/brooklyn/entity/webapp/jboss/JBoss7ServerNonInheritingIntegrationTest.java
+++ b/software/webapp/src/test/java/brooklyn/entity/webapp/jboss/JBoss7ServerNonInheritingIntegrationTest.java
@@ -22,12 +22,13 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import java.io.File;
+import java.net.URI;
-import brooklyn.test.TestResourceUnavailableException;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import brooklyn.entity.BrooklynAppLiveTestSupport;
import brooklyn.entity.basic.Entities;
import brooklyn.entity.proxying.EntitySpec;
import brooklyn.entity.webapp.AbstractWebAppFixtureIntegrationTest;
@@ -35,6 +36,7 @@ import brooklyn.entity.webapp.HttpsSslConfig;
import brooklyn.location.basic.LocalhostMachineProvisioningLocation;
import brooklyn.test.Asserts;
import brooklyn.test.HttpTestUtils;
+import brooklyn.test.TestResourceUnavailableException;
import brooklyn.test.entity.TestApplication;
import com.google.common.collect.ImmutableList;
@@ -43,21 +45,23 @@ import com.google.common.collect.ImmutableSet;
/**
* TODO re-write this like WebAppIntegrationTest, inheriting, rather than being jboss7 specific.
*/
-public class JBoss7ServerNonInheritingIntegrationTest {
+public class JBoss7ServerNonInheritingIntegrationTest extends BrooklynAppLiveTestSupport {
private LocalhostMachineProvisioningLocation localhostProvisioningLocation;
- private TestApplication app;
private File keystoreFile;
@BeforeMethod(alwaysRun=true)
+ @Override
public void setUp() throws Exception {
- localhostProvisioningLocation = new LocalhostMachineProvisioningLocation();
- app = TestApplication.Factory.newManagedInstanceForTests();
+ super.setUp();
+ localhostProvisioningLocation = app.newLocalhostProvisioningLocation();
keystoreFile = AbstractWebAppFixtureIntegrationTest.createTemporaryKeyStore("myname", "mypass");
}
@AfterMethod(alwaysRun=true)
+ @Override
public void tearDown() throws Exception {
+ super.tearDown();
if (app != null) Entities.destroyAll(app.getManagementContext());
if (keystoreFile != null) keystoreFile.delete();
}