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 2014/08/21 18:02:45 UTC
[2/5] git commit: NginxRebindIntegrationTest: use live
brooklyn.properties
NginxRebindIntegrationTest: use live brooklyn.properties
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/42ba635b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/42ba635b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/42ba635b
Branch: refs/heads/master
Commit: 42ba635b59c8f77f9df7185e7ccba198f049ad8a
Parents: 4d86f06
Author: Aled Sage <al...@gmail.com>
Authored: Wed Aug 6 13:22:54 2014 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Thu Aug 21 16:49:43 2014 +0100
----------------------------------------------------------------------
.../entity/rebind/RebindTestFixture.java | 20 +++++--
.../brooklyn/entity/rebind/RebindTestUtils.java | 18 ++++++-
.../proxy/nginx/NginxRebindIntegrationTest.java | 55 +++++++-------------
3 files changed, 50 insertions(+), 43 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/42ba635b/core/src/test/java/brooklyn/entity/rebind/RebindTestFixture.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/rebind/RebindTestFixture.java b/core/src/test/java/brooklyn/entity/rebind/RebindTestFixture.java
index 605f32d..9a33e73 100644
--- a/core/src/test/java/brooklyn/entity/rebind/RebindTestFixture.java
+++ b/core/src/test/java/brooklyn/entity/rebind/RebindTestFixture.java
@@ -30,7 +30,6 @@ import brooklyn.entity.basic.StartableApplication;
import brooklyn.entity.rebind.persister.BrooklynMementoPersisterToObjectStore;
import brooklyn.entity.rebind.persister.FileBasedObjectStore;
import brooklyn.entity.rebind.persister.PersistMode;
-import brooklyn.internal.BrooklynFeatureEnablement;
import brooklyn.management.ManagementContext;
import brooklyn.management.ha.HighAvailabilityMode;
import brooklyn.management.internal.LocalManagementContext;
@@ -64,7 +63,14 @@ public abstract class RebindTestFixture<T extends StartableApplication> {
}
protected LocalManagementContext createOrigManagementContext() {
- return RebindTestUtils.newPersistingManagementContext(mementoDir, classLoader, getPersistPeriodMillis());
+ return RebindTestUtils.managementContextBuilder(mementoDir, classLoader)
+ .persistPeriodMillis(getPersistPeriodMillis())
+ .forLive(useLiveManagementContext())
+ .buildStarted();
+ }
+
+ protected boolean useLiveManagementContext() {
+ return false;
}
protected int getPersistPeriodMillis() {
@@ -110,19 +116,23 @@ public abstract class RebindTestFixture<T extends StartableApplication> {
if (terminateOrigManagementContext) {
origManagementContext.terminate();
}
- return (T) RebindTestUtils.rebind(mementoDir, getClass().getClassLoader());
+ LocalManagementContext newManagementContext = RebindTestUtils.managementContextBuilder(mementoDir, classLoader)
+ .forLive(useLiveManagementContext())
+ .buildUnstarted();
+
+ return (T) RebindTestUtils.rebind(newManagementContext, classLoader);
}
@SuppressWarnings("unchecked")
protected T rebind(RebindExceptionHandler exceptionHandler) throws Exception {
RebindTestUtils.waitForPersisted(origApp);
- return (T) RebindTestUtils.rebind(mementoDir, getClass().getClassLoader(), exceptionHandler);
+ return (T) RebindTestUtils.rebind(mementoDir, classLoader, exceptionHandler);
}
@SuppressWarnings("unchecked")
protected T rebind(ManagementContext newManagementContext, RebindExceptionHandler exceptionHandler) throws Exception {
RebindTestUtils.waitForPersisted(origApp);
- return (T) RebindTestUtils.rebind(newManagementContext, mementoDir, getClass().getClassLoader(), exceptionHandler);
+ return (T) RebindTestUtils.rebind(newManagementContext, mementoDir, classLoader, exceptionHandler);
}
protected BrooklynMementoManifest loadMementoManifest() throws Exception {
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/42ba635b/core/src/test/java/brooklyn/entity/rebind/RebindTestUtils.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/rebind/RebindTestUtils.java b/core/src/test/java/brooklyn/entity/rebind/RebindTestUtils.java
index 018e4d8..5e739c5 100644
--- a/core/src/test/java/brooklyn/entity/rebind/RebindTestUtils.java
+++ b/core/src/test/java/brooklyn/entity/rebind/RebindTestUtils.java
@@ -211,8 +211,18 @@ public class RebindTestUtils {
return rebind(mementoDir, classLoader, null);
}
+ public static Application rebind(LocalManagementContext newManagementContext, ClassLoader classLoader) throws Exception {
+ return rebind(newManagementContext, classLoader, null);
+ }
+
+ public static Application rebind(LocalManagementContext newManagementContext, ClassLoader classLoader, RebindExceptionHandler exceptionHandler) throws Exception {
+ Collection<Application> newApps = rebindAll(newManagementContext, classLoader, exceptionHandler);
+ if (newApps.isEmpty()) throw new IllegalStateException("Application could not be rebinded; serialization probably failed");
+ return Iterables.getFirst(newApps, null);
+ }
+
public static Application rebind(File mementoDir, ClassLoader classLoader, RebindExceptionHandler exceptionHandler) throws Exception {
- Collection<Application> newApps = rebindAll(mementoDir, classLoader);
+ Collection<Application> newApps = rebindAll(mementoDir, classLoader, exceptionHandler);
if (newApps.isEmpty()) throw new IllegalStateException("Application could not be rebinded; serialization probably failed");
return Iterables.getFirst(newApps, null);
}
@@ -223,8 +233,12 @@ public class RebindTestUtils {
public static Collection<Application> rebindAll(File mementoDir, ClassLoader classLoader, RebindExceptionHandler exceptionHandler) throws Exception {
LOG.info("Rebinding app, using directory "+mementoDir);
+ return rebindAll(newPersistingManagementContextUnstarted(mementoDir, classLoader), classLoader, exceptionHandler);
+ }
+
+ public static Collection<Application> rebindAll(LocalManagementContext newManagementContext, ClassLoader classLoader, RebindExceptionHandler exceptionHandler) throws Exception {
+ LOG.info("Rebinding app");
- LocalManagementContext newManagementContext = newPersistingManagementContextUnstarted(mementoDir, classLoader);
List<Application> newApps;
if (exceptionHandler == null) {
newApps = newManagementContext.getRebindManager().rebind(classLoader);
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/42ba635b/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
index a119130..74e23b5 100644
--- a/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxRebindIntegrationTest.java
+++ b/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxRebindIntegrationTest.java
@@ -23,7 +23,6 @@ import static brooklyn.test.HttpTestUtils.assertHttpStatusCodeEquals;
import static brooklyn.test.HttpTestUtils.assertHttpStatusCodeEventuallyEquals;
import static org.testng.Assert.assertEquals;
-import java.io.File;
import java.net.URL;
import java.util.List;
import java.util.Map;
@@ -39,55 +38,50 @@ import org.testng.annotations.Test;
import brooklyn.entity.Entity;
import brooklyn.entity.Group;
-import brooklyn.entity.basic.ApplicationBuilder;
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.RebindTestUtils;
+import brooklyn.entity.rebind.RebindTestFixtureWithApp;
import brooklyn.entity.webapp.jboss.JBoss7Server;
+import brooklyn.location.LocationSpec;
import brooklyn.location.basic.LocalhostMachineProvisioningLocation;
import brooklyn.management.ManagementContext;
-import brooklyn.management.internal.LocalManagementContext;
import brooklyn.test.Asserts;
import brooklyn.test.WebAppMonitor;
-import brooklyn.test.entity.TestApplication;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
-import com.google.common.io.Files;
/**
* Test the operation of the {@link NginxController} class.
*/
-public class NginxRebindIntegrationTest {
+public class NginxRebindIntegrationTest extends RebindTestFixtureWithApp {
+
private static final Logger LOG = LoggerFactory.getLogger(NginxRebindIntegrationTest.class);
private URL warUrl;
private LocalhostMachineProvisioningLocation localhostProvisioningLocation;
- private ClassLoader classLoader = getClass().getClassLoader();
- private LocalManagementContext origManagementContext;
- private File mementoDir;
- private TestApplication origApp;
- private TestApplication newApp;
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(groups = "Integration")
- public void setUp() {
+ public void setUp() throws Exception {
+ super.setUp();
warUrl = getClass().getClassLoader().getResource("hello-world.war");
-
- mementoDir = Files.createTempDir();
- origManagementContext = RebindTestUtils.newPersistingManagementContext(mementoDir, classLoader);
- origApp = ApplicationBuilder.newManagedApp(TestApplication.class, origManagementContext);
-
- localhostProvisioningLocation = new LocalhostMachineProvisioningLocation();
-
+ localhostProvisioningLocation = origManagementContext.getLocationManager().createLocation(LocationSpec.create(LocalhostMachineProvisioningLocation.class));
executor = Executors.newCachedThreadPool();
}
@@ -97,18 +91,7 @@ public class NginxRebindIntegrationTest {
monitor.terminate();
}
if (executor != null) executor.shutdownNow();
- if (newApp != null) Entities.destroyAll(newApp.getManagementContext());
- if (origApp != null && origManagementContext.isRunning()) Entities.destroyAll(origApp.getManagementContext());
- if (mementoDir != null) RebindTestUtils.deleteMementoDir(mementoDir);
- }
-
- private TestApplication rebind() throws Exception {
- RebindTestUtils.waitForPersisted(origApp);
-
- // Stop the old management context, so original nginx won't interfere
- origManagementContext.terminate();
-
- return (TestApplication) RebindTestUtils.rebind(mementoDir, getClass().getClassLoader());
+ super.tearDown();
}
private WebAppMonitor newWebAppMonitor(String url, int expectedResponseCode) {
@@ -146,7 +129,7 @@ public class NginxRebindIntegrationTest {
WebAppMonitor monitor = newWebAppMonitor(rootUrl, 404);
final String origConfigFile = origNginx.getConfigFile();
- newApp = rebind();
+ newApp = rebind(false, true);
final NginxController newNginx = (NginxController) Iterables.find(newApp.getChildren(), Predicates.instanceOf(NginxController.class));
assertEquals(newNginx.getConfigFile(), origConfigFile);
@@ -190,7 +173,7 @@ public class NginxRebindIntegrationTest {
final String origConfigFile = origNginx.getConfigFile();
// Rebind
- newApp = rebind();
+ newApp = rebind(false, 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());
@@ -268,7 +251,7 @@ public class NginxRebindIntegrationTest {
final String origConfigFile = origNginx.getConfigFile();
// Create a rebinding
- newApp = rebind();
+ newApp = rebind(false, 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());