From 3dc4405c8c948b265c46cf13633549eaaaf0f6aa Mon Sep 17 00:00:00 2001 From: Aled Sage Date: Tue, 4 Nov 2014 16:36:33 +0000 Subject: [PATCH] Adds RebindOptions for RebindTestUtils etc - Changes RebindTestFixture default to not checkSerializable. - Deprecates crazy number of overloaded methods --- .../RebindEntityDynamicTypeInfoTest.java | 5 - .../entity/rebind/RebindEntityTest.java | 11 +- .../entity/rebind/RebindFailuresTest.java | 24 +- .../entity/rebind/RebindFeedTest.java | 6 +- .../brooklyn/entity/rebind/RebindOptions.java | 92 +++++++ .../entity/rebind/RebindTestFixture.java | 136 +++++----- .../entity/rebind/RebindTestUtils.java | 249 +++++++++++++++--- .../transformer/CompoundTransformerTest.java | 8 +- .../access/PortForwardManagerRebindTest.java | 2 +- ...sterDatabaseExampleAppIntegrationTest.java | 3 +- .../entity/pool/ServerPoolRebindTest.java | 3 +- .../event/feed/jmx/RebindJmxFeedTest.java | 2 +- .../bind/BindDnsServerIntegrationTest.java | 19 +- ...sandraDatacenterRebindIntegrationTest.java | 3 +- .../nginx/NginxRebindIntegrationTest.java | 7 +- .../JBoss7ServerRebindingIntegrationTest.java | 3 +- 16 files changed, 412 insertions(+), 161 deletions(-) create mode 100644 core/src/test/java/brooklyn/entity/rebind/RebindOptions.java diff --git a/core/src/test/java/brooklyn/entity/rebind/RebindEntityDynamicTypeInfoTest.java b/core/src/test/java/brooklyn/entity/rebind/RebindEntityDynamicTypeInfoTest.java index f12ead8f47..e9e05e6509 100644 --- a/core/src/test/java/brooklyn/entity/rebind/RebindEntityDynamicTypeInfoTest.java +++ b/core/src/test/java/brooklyn/entity/rebind/RebindEntityDynamicTypeInfoTest.java @@ -45,11 +45,6 @@ public class RebindEntityDynamicTypeInfoTest extends RebindTestFixtureWithApp { private static final Logger log = LoggerFactory.getLogger(RebindEntityDynamicTypeInfoTest.class); - @Override - protected TestApplication rebind() throws Exception { - return rebind(false); - } - public static class SayHiBody extends EffectorBody { public static final ConfigKey NAME_KEY = ConfigKeys.newStringConfigKey("name"); public static final Effector EFFECTOR = Effectors.effector(String.class, "say_hi").description("says hello") diff --git a/core/src/test/java/brooklyn/entity/rebind/RebindEntityTest.java b/core/src/test/java/brooklyn/entity/rebind/RebindEntityTest.java index 464fe65915..d6faccf44a 100644 --- a/core/src/test/java/brooklyn/entity/rebind/RebindEntityTest.java +++ b/core/src/test/java/brooklyn/entity/rebind/RebindEntityTest.java @@ -247,7 +247,7 @@ public void testHandlesReferencingOtherEntitiesInPojoField() throws Exception { reffer.myEntity = origE; origApp.setConfig(TestEntity.CONF_OBJECT, reffer); - newApp = rebind(false); + newApp = rebind(); MyEntity newE = (MyEntity) Iterables.find(newApp.getChildren(), Predicates.instanceOf(MyEntity.class)); ReffingEntity reffer2 = (ReffingEntity)newApp.getConfig(TestEntity.CONF_OBJECT); @@ -267,7 +267,7 @@ public void testHandlesReferencingOtherEntityInPojoFieldsOfOtherTypes() throws E reffer.resizable = origE; origApp.setConfig(TestEntity.CONF_OBJECT, reffer); - newApp = rebind(false); + newApp = rebind(); MyEntityWithMultipleInterfaces newE = (MyEntityWithMultipleInterfaces) Iterables.find(newApp.getChildren(), Predicates.instanceOf(MyEntityWithMultipleInterfaces.class)); ReffingEntity newReffer = (ReffingEntity)newApp.getConfig(TestEntity.CONF_OBJECT); @@ -281,7 +281,7 @@ public void testEntityTags() throws Exception { origE.tags().addTag("foo"); origE.tags().addTag(origApp); - newApp = rebind(false); + newApp = rebind(); MyEntity newE = Iterables.getOnlyElement( Entities.descendants(newApp, MyEntity.class) ); assertTrue(newE.tags().containsTag("foo"), "tags are "+newE.tags().getTags()); @@ -390,7 +390,10 @@ public void testSubscriptionAndPublishingOnlyActiveWhenEntityIsManaged() throws Thread thread = new Thread() { public void run() { try { - RebindTestUtils.rebind(newManagementContext, mementoDir, getClass().getClassLoader()); + RebindTestUtils.rebind(RebindOptions.create() + .newManagementContext(newManagementContext) + .mementoDir(mementoDir) + .classLoader(RebindEntityTest.class.getClassLoader())); } catch (Exception e) { throw Throwables.propagate(e); } diff --git a/core/src/test/java/brooklyn/entity/rebind/RebindFailuresTest.java b/core/src/test/java/brooklyn/entity/rebind/RebindFailuresTest.java index 045d91c8ca..c522b59e3f 100644 --- a/core/src/test/java/brooklyn/entity/rebind/RebindFailuresTest.java +++ b/core/src/test/java/brooklyn/entity/rebind/RebindFailuresTest.java @@ -44,6 +44,8 @@ import brooklyn.entity.trait.Identifiable; import brooklyn.event.AttributeSensor; import brooklyn.management.EntityManager; +import brooklyn.management.ManagementContext; +import brooklyn.management.internal.LocalManagementContext; import brooklyn.policy.Enricher; import brooklyn.policy.EnricherSpec; import brooklyn.policy.Policy; @@ -70,7 +72,7 @@ public void testFailureGeneratingMementoStillPersistsOtherEntities() throws Exce .impl(MyEntityFailingImpl.class) .configure(MyEntityFailingImpl.FAIL_ON_GENERATE_MEMENTO, true)); - newApp = rebind(false); + newApp = rebind(); MyEntity newE = (MyEntity) Iterables.find(newApp.getChildren(), EntityPredicates.idEqualTo(origE.getId())); Optional newFailingE = Iterables.tryFind(newApp.getChildren(), EntityPredicates.idEqualTo(origFailingE.getId())); @@ -93,11 +95,11 @@ public void testFailureRebindingEntityWhenFailAtEnd() throws Exception { .impl(MyEntityFailingImpl.class) .configure(MyEntityFailingImpl.FAIL_ON_REBIND, true)); - newManagementContext = LocalManagementContextForTests.newInstance(); + ManagementContext newManagementContext = LocalManagementContextForTests.newInstance(); EntityManager newEntityManager = newManagementContext.getEntityManager(); RecordingRebindExceptionHandler exceptionHandler = new RecordingRebindExceptionHandler(danglingRefFailureMode, rebindFailureMode); try { - newApp = rebind(newManagementContext, exceptionHandler); + newApp = rebind(RebindOptions.create().newManagementContext(newManagementContext).exceptionHandler(exceptionHandler)); fail(); } catch (Exception e) { assertFailureRebindingError(e); @@ -120,11 +122,11 @@ public void testFailureRebindingEntityWhenFailFast() throws Exception { .impl(MyEntityFailingImpl.class) .configure(MyEntityFailingImpl.FAIL_ON_REBIND, true)); - newManagementContext = LocalManagementContextForTests.newInstance(); + ManagementContext newManagementContext = LocalManagementContextForTests.newInstance(); EntityManager newEntityManager = newManagementContext.getEntityManager(); RecordingRebindExceptionHandler exceptionHandler = new RecordingRebindExceptionHandler(danglingRefFailureMode, rebindFailureMode); try { - newApp = rebind(newManagementContext, exceptionHandler); + newApp = rebind(RebindOptions.create().newManagementContext(newManagementContext).exceptionHandler(exceptionHandler)); fail(); } catch (Exception e) { assertFailureRebindingError(e); @@ -147,10 +149,10 @@ public void testFailureRebindingEntityWhenContinue() throws Exception { .impl(MyEntityFailingImpl.class) .configure(MyEntityFailingImpl.FAIL_ON_REBIND, true)); - newManagementContext = LocalManagementContextForTests.newInstance(); + ManagementContext newManagementContext = LocalManagementContextForTests.newInstance(); EntityManager newEntityManager = newManagementContext.getEntityManager(); RecordingRebindExceptionHandler exceptionHandler = new RecordingRebindExceptionHandler(danglingRefFailureMode, rebindFailureMode); - newApp = rebind(newManagementContext, exceptionHandler); + newApp = rebind(RebindOptions.create().newManagementContext(newManagementContext).exceptionHandler(exceptionHandler)); // exception handler should have been told about failure assertEquals(toIds(exceptionHandler.rebindFailures.keySet()), ImmutableSet.of(origFailingE.getId())); @@ -169,10 +171,10 @@ public void testFailureRebindingBecauseDirectoryCorrupt() throws Exception { File entitiesDir = Os.mkdirs(new File(mementoDir, "entities")); Files.write("invalid text", new File(entitiesDir, "mycorruptfile"), Charsets.UTF_8); - newManagementContext = LocalManagementContextForTests.newInstance(); + LocalManagementContext newManagementContext = LocalManagementContextForTests.newInstance(); RecordingRebindExceptionHandler exceptionHandler = new RecordingRebindExceptionHandler(danglingRefFailureMode, rebindFailureMode); try { - newApp = rebind(newManagementContext, exceptionHandler); + newApp = rebind(RebindOptions.create().newManagementContext(newManagementContext).exceptionHandler(exceptionHandler)); fail(); } catch (Exception e) { assertFailureRebindingError(e); @@ -195,7 +197,7 @@ public void testRebindWithFailingPolicyContinuesWithoutPolicy() throws Exception origApp.addPolicy(PolicySpec.create(MyPolicyFailingImpl.class) .configure(MyPolicyFailingImpl.FAIL_ON_REBIND, true)); - newApp = rebind(false); + newApp = rebind(); Optional newPolicy = Iterables.tryFind(newApp.getPolicies(), Predicates.instanceOf(MyPolicyFailingImpl.class)); assertFalse(newPolicy.isPresent(), "policy="+newPolicy); @@ -206,7 +208,7 @@ public void testRebindWithFailingEnricherContinuesWithoutEnricher() throws Excep origApp.addEnricher(EnricherSpec.create(MyEnricherFailingImpl.class) .configure(MyEnricherFailingImpl.FAIL_ON_REBIND, true)); - newApp = rebind(false); + newApp = rebind(); Optional newEnricher = Iterables.tryFind(newApp.getEnrichers(), Predicates.instanceOf(MyEnricherFailingImpl.class)); assertFalse(newEnricher.isPresent(), "enricher="+newEnricher); diff --git a/core/src/test/java/brooklyn/entity/rebind/RebindFeedTest.java b/core/src/test/java/brooklyn/entity/rebind/RebindFeedTest.java index c0be0fbd77..5717ed122e 100644 --- a/core/src/test/java/brooklyn/entity/rebind/RebindFeedTest.java +++ b/core/src/test/java/brooklyn/entity/rebind/RebindFeedTest.java @@ -108,7 +108,7 @@ public void testHttpFeedRegisteredInInitIsPersistedAndFeedsStop() throws Excepti log.info("Tasks before rebind: "+ ((BasicExecutionManager)origManagementContext.getExecutionManager()).getAllTasks()); - newApp = rebind(false); + newApp = rebind(); TestEntity newEntity = (TestEntity) Iterables.getOnlyElement(newApp.getChildren()); Collection newFeeds = newEntity.feeds().getFeeds(); @@ -152,7 +152,7 @@ public void testFunctionFeedRegisteredInInitIsPersisted() throws Exception { EntityTestUtils.assertAttributeEqualsEventually(origEntity, SENSOR_INT, (Integer)1); assertEquals(origEntity.feeds().getFeeds().size(), 2); - newApp = rebind(false); + newApp = rebind(); TestEntity newEntity = (TestEntity) Iterables.getOnlyElement(newApp.getChildren()); Collection newFeeds = newEntity.feeds().getFeeds(); @@ -176,7 +176,7 @@ public void testSshFeedRegisteredInStartIsPersisted() throws Exception { EntityTestUtils.assertAttributeEqualsEventually(origEntity, SENSOR_INT, (Integer)0); assertEquals(origEntity.feeds().getFeeds().size(), 1); - newApp = rebind(false); + newApp = rebind(); TestEntity newEntity = (TestEntity) Iterables.getOnlyElement(newApp.getChildren()); Collection newFeeds = newEntity.feeds().getFeeds(); diff --git a/core/src/test/java/brooklyn/entity/rebind/RebindOptions.java b/core/src/test/java/brooklyn/entity/rebind/RebindOptions.java new file mode 100644 index 0000000000..63bd1ccca2 --- /dev/null +++ b/core/src/test/java/brooklyn/entity/rebind/RebindOptions.java @@ -0,0 +1,92 @@ +/* + * 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.rebind; + +import java.io.File; + +import brooklyn.entity.rebind.persister.PersistenceObjectStore; +import brooklyn.management.ManagementContext; + +/** + * See {@link RebindTestFixture#rebind(RebindOptions)} and {@link RebindTestUtils#rebind(RebindOptions}}. + */ +public class RebindOptions { + boolean checkSerializable; + boolean terminateOrigManagementContext; + RebindExceptionHandler exceptionHandler; + ManagementContext origManagementContext; + ManagementContext newManagementContext; + File mementoDir; + File mementoDirBackup; + ClassLoader classLoader; + PersistenceObjectStore objectStore; + + public static RebindOptions create() { + return new RebindOptions(); + } + public static RebindOptions create(RebindOptions options) { + RebindOptions result = create(); + result.checkSerializable(options.checkSerializable); + result.terminateOrigManagementContext(options.terminateOrigManagementContext); + result.exceptionHandler(options.exceptionHandler); + result.origManagementContext(options.origManagementContext); + result.newManagementContext(options.newManagementContext); + result.mementoDir(options.mementoDir); + result.mementoDirBackup(options.mementoDirBackup); + result.classLoader(options.classLoader); + result.objectStore(options.objectStore); + return result; + } + public RebindOptions checkSerializable(boolean val) { + this.checkSerializable = val; + return this; + } + public RebindOptions terminateOrigManagementContext(boolean val) { + this.terminateOrigManagementContext = val; + return this; + } + public RebindOptions exceptionHandler(RebindExceptionHandler val) { + this.exceptionHandler = val; + return this; + } + public RebindOptions origManagementContext(ManagementContext val) { + this.origManagementContext = val; + return this; + } + public RebindOptions newManagementContext(ManagementContext val) { + this.newManagementContext = val; + return this; + } + public RebindOptions mementoDir(File val) { + this.mementoDir = val; + return this; + } + public RebindOptions mementoDirBackup(File val) { + this.mementoDirBackup = val; + return this; + } + public RebindOptions classLoader(ClassLoader val) { + this.classLoader = val; + return this; + } + public RebindOptions objectStore(PersistenceObjectStore val) { + this.objectStore = val; + return this; + } +} diff --git a/core/src/test/java/brooklyn/entity/rebind/RebindTestFixture.java b/core/src/test/java/brooklyn/entity/rebind/RebindTestFixture.java index 2b221d1862..24bf3572df 100644 --- a/core/src/test/java/brooklyn/entity/rebind/RebindTestFixture.java +++ b/core/src/test/java/brooklyn/entity/rebind/RebindTestFixture.java @@ -21,8 +21,6 @@ import static org.testng.Assert.assertEquals; import java.io.File; -import java.util.List; -import java.util.Map; import java.util.Set; import org.slf4j.Logger; @@ -33,7 +31,6 @@ import brooklyn.catalog.BrooklynCatalog; import brooklyn.catalog.CatalogItem; import brooklyn.catalog.internal.CatalogUtils; -import brooklyn.config.BrooklynProperties; import brooklyn.entity.basic.Entities; import brooklyn.entity.basic.EntityFunctions; import brooklyn.entity.basic.StartableApplication; @@ -45,17 +42,12 @@ import brooklyn.management.internal.LocalManagementContext; import brooklyn.management.internal.ManagementContextInternal; import brooklyn.mementos.BrooklynMementoManifest; -import brooklyn.mementos.BrooklynMementoRawData; -import brooklyn.test.entity.LocalManagementContextForTests; -import brooklyn.util.io.FileUtil; import brooklyn.util.os.Os; import brooklyn.util.text.Identifiers; import brooklyn.util.time.Duration; import com.google.api.client.util.Sets; -import com.google.common.annotations.Beta; import com.google.common.collect.FluentIterable; -import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; public abstract class RebindTestFixture { @@ -73,6 +65,7 @@ public abstract class RebindTestFixture { protected T newApp; protected ManagementContext newManagementContext; + @BeforeMethod(alwaysRun=true) public void setUp() throws Exception { mementoDir = Os.newTempDir(getClass()); @@ -132,94 +125,83 @@ public void tearDown() throws Exception { origManagementContext = null; } + /** rebinds, and sets newApp */ + protected T rebind() throws Exception { + return rebind(RebindOptions.create()); + } + /** - * Dumps out the persisted mementos that are at the given directory. - * - * Binds to the persisted state (as a "hot standby") to load the raw data (as strings), and to write out the - * entity, location, policy, enricher, feed and catalog-item data. + * Checking serializable is overly strict. + * State only needs to be xstream-serializable, which does not require `implements Serializable`. + * Also, the xstream serializer has some special hooks that replaces an entity reference with + * a marker for that entity, etc. * - * @param dir The directory containing the persisted state (e.g. {@link #mementoDir} or {@link #mementoDirBackup}) + * @deprecated since 0.7.0; use {@link #rebind()} or {@link #rebind(RebindOptions)}) */ - protected void dumpMementoDir(File dir) { - LocalManagementContextForTests mgmt = new LocalManagementContextForTests(BrooklynProperties.Factory.newEmpty()); - FileBasedObjectStore store = null; - BrooklynMementoPersisterToObjectStore persister = null; - try { - store = new FileBasedObjectStore(dir); - store.injectManagementContext(mgmt); - store.prepareForSharedUse(PersistMode.AUTO, HighAvailabilityMode.HOT_STANDBY); - persister = new BrooklynMementoPersisterToObjectStore(store, BrooklynProperties.Factory.newEmpty(), classLoader); - BrooklynMementoRawData data = persister.loadMementoRawData(RebindExceptionHandlerImpl.builder().build()); - List types = ImmutableList.of(BrooklynObjectType.ENTITY, BrooklynObjectType.LOCATION, - BrooklynObjectType.POLICY, BrooklynObjectType.ENRICHER, BrooklynObjectType.FEED, - BrooklynObjectType.CATALOG_ITEM); - for (BrooklynObjectType type : types) { - LOG.info(type+" ("+data.getObjectsOfType(type).keySet()+"):"); - for (Map.Entry entry : data.getObjectsOfType(type).entrySet()) { - LOG.info("\t"+type+" "+entry.getKey()+": "+entry.getValue()); - } - } - } finally { - if (persister != null) persister.stop(false); - if (store != null) store.close(); - mgmt.terminate(); - } + @Deprecated + protected T rebind(boolean checkSerializable) throws Exception { + return rebind(RebindOptions.create().checkSerializable(checkSerializable)); } - /** rebinds, and sets newApp */ - protected T rebind() throws Exception { - return rebind(true); + /** + * Checking serializable is overly strict. + * State only needs to be xstream-serializable, which does not require `implements Serializable`. + * Also, the xstream serializer has some special hooks that replaces an entity reference with + * a marker for that entity, etc. + * + * @deprecated since 0.7.0; use {@link #rebind(RebindOptions)}) + */ + @Deprecated + protected T rebind(boolean checkSerializable, boolean terminateOrigManagementContext) throws Exception { + return rebind(RebindOptions.create() + .checkSerializable(checkSerializable) + .terminateOrigManagementContext(terminateOrigManagementContext)); } /** - * TODO We should (probably?!) change everywhere from asserting that they are serializable. - * They only need to be xstream-serializable, which does not require `implements Serializable`. - * Also, the xstream serializer has some special hooks that replaces an entity reference with - * a marker for that entity, etc. Suggest we change the default {@link #rebind()} to use - * {@code checkSerializable==false}, and deprecate this + the other overloaded methods? + * @deprecated since 0.7.0; use {@link #rebind(RebindOptions)}) */ - protected T rebind(boolean checkSerializable) throws Exception { - // TODO What are sensible defaults?! - return rebind(checkSerializable, false); + @Deprecated + protected T rebind(RebindExceptionHandler exceptionHandler) throws Exception { + return rebind(RebindOptions.create().exceptionHandler(exceptionHandler)); } - protected T rebind(boolean checkSerializable, boolean terminateOrigManagementContext) throws Exception { - return rebind(checkSerializable, terminateOrigManagementContext, (File)null); + /** + * @deprecated since 0.7.0; use {@link #rebind(RebindOptions)}) + */ + @Deprecated + protected T rebind(ManagementContext newManagementContext, RebindExceptionHandler exceptionHandler) throws Exception { + return rebind(RebindOptions.create() + .newManagementContext(newManagementContext) + .exceptionHandler(exceptionHandler)); } - @Beta // temporary method while debugging; Aled will refactor all of this soon! @SuppressWarnings("unchecked") - protected T rebind(boolean checkSerializable, boolean terminateOrigManagementContext, File backupDir) throws Exception { - if (newApp!=null || newManagementContext!=null) throw new IllegalStateException("already rebound"); + protected T rebind(RebindOptions options) throws Exception { + if (newApp != null || newManagementContext != null) { + throw new IllegalStateException("already rebound"); + } + + options = RebindOptions.create(options); + if (options.classLoader == null) options.classLoader(classLoader); + if (options.mementoDir == null) options.mementoDir(mementoDir); + if (options.origManagementContext == null) options.origManagementContext(origManagementContext); + if (options.newManagementContext == null) options.newManagementContext(createNewManagementContext()); RebindTestUtils.waitForPersisted(origApp); - if (checkSerializable) { - RebindTestUtils.checkCurrentMementoSerializable(origApp); - } - if (terminateOrigManagementContext) { - origManagementContext.terminate(); - } - - if (backupDir != null) { - FileUtil.copyDir(mementoDir, backupDir); - FileUtil.setFilePermissionsTo700(backupDir); - } - - newManagementContext = createNewManagementContext(); - newApp = (T) RebindTestUtils.rebind((LocalManagementContext)newManagementContext, classLoader); + + newManagementContext = options.newManagementContext; + newApp = (T) RebindTestUtils.rebind(options); return newApp; } - @SuppressWarnings("unchecked") - protected T rebind(RebindExceptionHandler exceptionHandler) throws Exception { - RebindTestUtils.waitForPersisted(origApp); - 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, classLoader, exceptionHandler); + /** + * Dumps out the persisted mementos that are at the given directory. + * + * @param dir The directory containing the persisted state (e.g. {@link #mementoDir} or {@link #mementoDirBackup}) + */ + protected void dumpMementoDir(File dir) { + RebindTestUtils.dumpMementoDir(dir); } protected BrooklynMementoManifest loadMementoManifest() throws Exception { diff --git a/core/src/test/java/brooklyn/entity/rebind/RebindTestUtils.java b/core/src/test/java/brooklyn/entity/rebind/RebindTestUtils.java index d3bdeff10b..daafe58bfd 100644 --- a/core/src/test/java/brooklyn/entity/rebind/RebindTestUtils.java +++ b/core/src/test/java/brooklyn/entity/rebind/RebindTestUtils.java @@ -49,11 +49,14 @@ import brooklyn.management.internal.LocalManagementContext; import brooklyn.management.internal.ManagementContextInternal; import brooklyn.mementos.BrooklynMemento; +import brooklyn.mementos.BrooklynMementoRawData; import brooklyn.test.entity.LocalManagementContextForTests; +import brooklyn.util.io.FileUtil; import brooklyn.util.javalang.Serializers; import brooklyn.util.javalang.Serializers.ObjectReplacer; import brooklyn.util.time.Duration; +import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import com.google.common.collect.Maps; @@ -221,71 +224,197 @@ public LocalManagementContext buildStarted() { } + /** + * Convenience for common call; delegates to {@link #rebind(RebindOptions)} + */ public static Application rebind(File mementoDir, ClassLoader classLoader) throws Exception { - return rebind(mementoDir, classLoader, null); + return rebind(RebindOptions.create() + .mementoDir(mementoDir) + .classLoader(classLoader)); } - public static Application rebind(LocalManagementContext newManagementContext, ClassLoader classLoader) throws Exception { - return rebind(newManagementContext, classLoader, null); + /** + * @deprecated since 0.7.0; use {@link #rebind(RebindOptions)} + */ + @Deprecated + public static Application rebind(File mementoDir, ClassLoader classLoader, RebindExceptionHandler exceptionHandler) throws Exception { + return rebind(RebindOptions.create() + .mementoDir(mementoDir) + .classLoader(classLoader) + .exceptionHandler(exceptionHandler)); } - public static Application rebind(LocalManagementContext newManagementContext, ClassLoader classLoader, RebindExceptionHandler exceptionHandler) throws Exception { - Collection newApps = rebindAll(newManagementContext, classLoader, exceptionHandler); - if (newApps.isEmpty()) throw new IllegalStateException("Application could not be rebinded; serialization probably failed"); - return Iterables.getFirst(newApps, null); + /** + * @deprecated since 0.7.0; use {@link #rebind(RebindOptions)} + */ + @Deprecated + public static Application rebind(ManagementContext newManagementContext, ClassLoader classLoader) throws Exception { + return rebind(RebindOptions.create() + .newManagementContext(newManagementContext) + .classLoader(classLoader)); } - public static Application rebind(File mementoDir, ClassLoader classLoader, RebindExceptionHandler exceptionHandler) throws Exception { - Collection newApps = rebindAll(mementoDir, classLoader, exceptionHandler); - if (newApps.isEmpty()) throw new IllegalStateException("Application could not be rebinded; serialization probably failed"); - return Iterables.getFirst(newApps, null); + /** + * @deprecated since 0.7.0; use {@link #rebind(RebindOptions)} + */ + @Deprecated + public static Application rebind(ManagementContext newManagementContext, ClassLoader classLoader, RebindExceptionHandler exceptionHandler) throws Exception { + return rebind(RebindOptions.create() + .newManagementContext(newManagementContext) + .classLoader(classLoader) + .exceptionHandler(exceptionHandler)); } - public static Collection rebindAll(File mementoDir, ClassLoader classLoader) throws Exception { - return rebindAll(mementoDir, classLoader, null); + /** + * @deprecated since 0.7.0; use {@link #rebind(RebindOptions)} + */ + @Deprecated + public static Application rebind(ManagementContext newManagementContext, File mementoDir, ClassLoader classLoader) throws Exception { + return rebind(RebindOptions.create() + .newManagementContext(newManagementContext) + .mementoDir(mementoDir) + .classLoader(classLoader)); } - public static Collection rebindAll(File mementoDir, ClassLoader classLoader, RebindExceptionHandler exceptionHandler) throws Exception { - LOG.info("Rebinding app, using directory "+mementoDir); - return rebindAll(newPersistingManagementContextUnstarted(mementoDir, classLoader), classLoader, exceptionHandler); + /** + * @deprecated since 0.7.0; use {@link #rebind(RebindOptions)} + */ + @Deprecated + public static Application rebind(ManagementContext newManagementContext, File mementoDir, ClassLoader classLoader, RebindExceptionHandler exceptionHandler) throws Exception { + return rebind(RebindOptions.create() + .newManagementContext(newManagementContext) + .mementoDir(mementoDir) + .classLoader(classLoader) + .exceptionHandler(exceptionHandler)); } - public static Collection rebindAll(LocalManagementContext newManagementContext, ClassLoader classLoader, RebindExceptionHandler exceptionHandler) throws Exception { - LOG.info("Rebinding app"); - - List newApps = newManagementContext.getRebindManager().rebind(classLoader, exceptionHandler, ManagementNodeState.MASTER); - + /** + * @deprecated since 0.7.0; use {@link #rebind(RebindOptions)} + */ + @Deprecated + public static Application rebind(ManagementContext newManagementContext, File mementoDir, + ClassLoader classLoader, RebindExceptionHandler exceptionHandler, PersistenceObjectStore objectStore) throws Exception { + return rebind(RebindOptions.create() + .newManagementContext(newManagementContext) + .mementoDir(mementoDir) + .classLoader(classLoader) + .exceptionHandler(exceptionHandler) + .objectStore(objectStore)); + } + + public static Application rebind(RebindOptions options) throws Exception { + Collection newApps = rebindAll(options); if (newApps.isEmpty()) throw new IllegalStateException("Application could not be rebinded; serialization probably failed"); - newManagementContext.getRebindManager().startPersistence(); - return newApps; + return Iterables.getFirst(newApps, null); } - public static Application rebind(ManagementContext newManagementContext, File mementoDir, ClassLoader classLoader) throws Exception { - return rebind(newManagementContext, mementoDir, classLoader, null); + + /** + * @deprecated since 0.7.0; use {@link #rebindAll(RebindOptions)} + */ + @Deprecated + public static Collection rebindAll(File mementoDir, ClassLoader classLoader) throws Exception { + return rebindAll(RebindOptions.create() + .mementoDir(mementoDir) + .classLoader(classLoader)); } - public static Application rebind(ManagementContext newManagementContext, File mementoDir, ClassLoader classLoader, RebindExceptionHandler exceptionHandler) throws Exception { - PersistenceObjectStore objectStore = new FileBasedObjectStore(mementoDir); - objectStore.injectManagementContext(newManagementContext); - objectStore.prepareForSharedUse(PersistMode.AUTO, HighAvailabilityMode.DISABLED); - return rebind(newManagementContext, mementoDir, classLoader, exceptionHandler, objectStore); + /** + * @deprecated since 0.7.0; use {@link #rebind(RebindOptions)} + */ + @Deprecated + public static Collection rebindAll(File mementoDir, ClassLoader classLoader, RebindExceptionHandler exceptionHandler) throws Exception { + return rebindAll(RebindOptions.create() + .mementoDir(mementoDir) + .classLoader(classLoader) + .exceptionHandler(exceptionHandler)); } - public static Application rebind(ManagementContext newManagementContext, File mementoDir, - ClassLoader classLoader, RebindExceptionHandler exceptionHandler, PersistenceObjectStore objectStore) throws Exception { - return Iterables.getFirst(rebindAll(newManagementContext, mementoDir, classLoader, exceptionHandler, objectStore), null); + + /** + * @deprecated since 0.7.0; use {@link #rebind(RebindOptions)} + */ + @Deprecated + public static Collection rebindAll(LocalManagementContext newManagementContext, ClassLoader classLoader, RebindExceptionHandler exceptionHandler) throws Exception { + return rebindAll(RebindOptions.create() + .newManagementContext(newManagementContext) + .classLoader(classLoader) + .exceptionHandler(exceptionHandler)); } + + /** + * @deprecated since 0.7.0; use {@link #rebind(RebindOptions)} + */ + @Deprecated public static Collection rebindAll(ManagementContext newManagementContext, File mementoDir, ClassLoader classLoader) throws Exception { - return rebindAll(newManagementContext, mementoDir, classLoader, null, new FileBasedObjectStore(mementoDir)); + return rebindAll(RebindOptions.create() + .newManagementContext(newManagementContext) + .mementoDir(mementoDir) + .classLoader(classLoader)); } + /** + * @deprecated since 0.7.0; use {@link #rebind(RebindOptions)} + */ + @Deprecated public static Collection rebindAll(ManagementContext newManagementContext, File mementoDir, ClassLoader classLoader, RebindExceptionHandler exceptionHandler, PersistenceObjectStore objectStore) throws Exception { - LOG.info("Rebinding app, using directory "+mementoDir); + return rebindAll(RebindOptions.create() + .newManagementContext(newManagementContext) + .mementoDir(mementoDir) + .classLoader(classLoader) + .exceptionHandler(exceptionHandler) + .objectStore(objectStore)); + } + + public static Collection rebindAll(RebindOptions options) throws Exception { + File mementoDir = options.mementoDir; + File mementoDirBackup = options.mementoDirBackup; + ClassLoader classLoader = checkNotNull(options.classLoader, "classLoader"); + ManagementContextInternal origManagementContext = (ManagementContextInternal) options.origManagementContext; + ManagementContextInternal newManagementContext = (ManagementContextInternal) options.newManagementContext; + PersistenceObjectStore objectStore = options.objectStore; + RebindExceptionHandler exceptionHandler = options.exceptionHandler; + boolean hasPersister = newManagementContext != null && newManagementContext.getRebindManager().getPersister() != null; + boolean checkSerializable = options.checkSerializable; + boolean terminateOrigManagementContext = options.terminateOrigManagementContext; + + LOG.info("Rebinding app, using mementoDir " + mementoDir + "; object store " + objectStore); + + if (newManagementContext == null) { + // TODO Could use empty properties, to save reading brooklyn.properties file. + // Would that affect any tests? + newManagementContext = new LocalManagementContextForTests(BrooklynProperties.Factory.newDefault()); + } + if (!hasPersister) { + if (objectStore == null) { + objectStore = new FileBasedObjectStore(checkNotNull(mementoDir, "mementoDir and objectStore must not both be null")); + } + objectStore.injectManagementContext(newManagementContext); + objectStore.prepareForSharedUse(PersistMode.AUTO, HighAvailabilityMode.DISABLED); + + BrooklynMementoPersisterToObjectStore newPersister = new BrooklynMementoPersisterToObjectStore( + objectStore, + newManagementContext.getBrooklynProperties(), + classLoader); + newManagementContext.getRebindManager().setPersister(newPersister, PersistenceExceptionHandlerImpl.builder().build()); + } else { + if (objectStore != null) throw new IllegalStateException("Must not supply ManagementContext with persister and an object store"); + } + + if (checkSerializable) { + checkNotNull(origManagementContext, "must supply origManagementContext with checkSerializable"); + RebindTestUtils.checkCurrentMementoSerializable(origManagementContext); + } - BrooklynMementoPersisterToObjectStore newPersister = new BrooklynMementoPersisterToObjectStore( - objectStore, - ((ManagementContextInternal)newManagementContext).getBrooklynProperties(), - classLoader); - newManagementContext.getRebindManager().setPersister(newPersister, PersistenceExceptionHandlerImpl.builder().build()); + if (terminateOrigManagementContext) { + checkNotNull(origManagementContext, "must supply origManagementContext with terminateOrigManagementContext"); + origManagementContext.terminate(); + } + + if (mementoDirBackup != null) { + FileUtil.copyDir(mementoDir, mementoDirBackup); + FileUtil.setFilePermissionsTo700(mementoDirBackup); + } + List newApps = newManagementContext.getRebindManager().rebind(classLoader, exceptionHandler, ManagementNodeState.MASTER); newManagementContext.getRebindManager().startPersistence(); return newApps; @@ -300,7 +429,45 @@ public static void waitForPersisted(ManagementContext managementContext) throws } public static void checkCurrentMementoSerializable(Application app) throws Exception { - BrooklynMemento memento = MementosGenerators.newBrooklynMemento(app.getManagementContext()); + checkCurrentMementoSerializable(app.getManagementContext()); + } + + public static void checkCurrentMementoSerializable(ManagementContext mgmt) throws Exception { + BrooklynMemento memento = MementosGenerators.newBrooklynMemento(mgmt); serializeAndDeserialize(memento); } + + /** + * Dumps out the persisted mementos that are at the given directory. + * + * Binds to the persisted state (as a "hot standby") to load the raw data (as strings), and to write out the + * entity, location, policy, enricher, feed and catalog-item data. + * + * @param dir The directory containing the persisted state + */ + public static void dumpMementoDir(File dir) { + LocalManagementContextForTests mgmt = new LocalManagementContextForTests(BrooklynProperties.Factory.newEmpty()); + FileBasedObjectStore store = null; + BrooklynMementoPersisterToObjectStore persister = null; + try { + store = new FileBasedObjectStore(dir); + store.injectManagementContext(mgmt); + store.prepareForSharedUse(PersistMode.AUTO, HighAvailabilityMode.HOT_STANDBY); + persister = new BrooklynMementoPersisterToObjectStore(store, BrooklynProperties.Factory.newEmpty(), RebindTestUtils.class.getClassLoader()); + BrooklynMementoRawData data = persister.loadMementoRawData(RebindExceptionHandlerImpl.builder().build()); + List types = ImmutableList.of(BrooklynObjectType.ENTITY, BrooklynObjectType.LOCATION, + BrooklynObjectType.POLICY, BrooklynObjectType.ENRICHER, BrooklynObjectType.FEED, + BrooklynObjectType.CATALOG_ITEM); + for (BrooklynObjectType type : types) { + LOG.info(type+" ("+data.getObjectsOfType(type).keySet()+"):"); + for (Map.Entry entry : data.getObjectsOfType(type).entrySet()) { + LOG.info("\t"+type+" "+entry.getKey()+": "+entry.getValue()); + } + } + } finally { + if (persister != null) persister.stop(false); + if (store != null) store.close(); + mgmt.terminate(); + } + } } diff --git a/core/src/test/java/brooklyn/entity/rebind/transformer/CompoundTransformerTest.java b/core/src/test/java/brooklyn/entity/rebind/transformer/CompoundTransformerTest.java index 9474cd8cb8..c8cc39dd35 100644 --- a/core/src/test/java/brooklyn/entity/rebind/transformer/CompoundTransformerTest.java +++ b/core/src/test/java/brooklyn/entity/rebind/transformer/CompoundTransformerTest.java @@ -35,6 +35,7 @@ import brooklyn.entity.rebind.PersistenceExceptionHandler; import brooklyn.entity.rebind.PersistenceExceptionHandlerImpl; import brooklyn.entity.rebind.RebindExceptionHandler; +import brooklyn.entity.rebind.RebindOptions; import brooklyn.entity.rebind.RebindManager.RebindFailureMode; import brooklyn.entity.rebind.RebindTestFixtureWithApp; import brooklyn.entity.rebind.RebindTestUtils; @@ -68,7 +69,7 @@ public void tearDown() throws Exception { super.tearDown(); if (newMementoDir != null) FileBasedObjectStore.deleteCompletely(mementoDir); } - + @Test public void testNoopTransformation() throws Exception { CompoundTransformer transformer = CompoundTransformer.builder() @@ -155,7 +156,10 @@ protected TestApplication rebind(File newMementoDir) throws Exception { .forLive(useLiveManagementContext()) .buildUnstarted(); - return (TestApplication) RebindTestUtils.rebind((LocalManagementContext)newManagementContext, classLoader); + return (TestApplication) RebindTestUtils.rebind(RebindOptions.create() + .newManagementContext(newManagementContext) + .classLoader(classLoader) + .mementoDir(newMementoDir)); } public static class OrigType { diff --git a/core/src/test/java/brooklyn/location/access/PortForwardManagerRebindTest.java b/core/src/test/java/brooklyn/location/access/PortForwardManagerRebindTest.java index 8ae81ce524..913e92d797 100644 --- a/core/src/test/java/brooklyn/location/access/PortForwardManagerRebindTest.java +++ b/core/src/test/java/brooklyn/location/access/PortForwardManagerRebindTest.java @@ -80,7 +80,7 @@ public void testHostAndPortTransformingEnricher() throws Exception { origPortForwardManager.acquirePublicPortExplicit(publicIpId, 40080); origPortForwardManager.associate(publicIpId, 40080, origSimulatedMachine, 80); - newApp = rebind(false); + newApp = rebind(); TestEntity newEntity = (TestEntity) Iterables.find(newApp.getChildren(), Predicates.instanceOf(TestEntity.class)); Location newSimulatedMachine = newApp.getManagementContext().getLocationManager().getLocation(origSimulatedMachine.getId()); diff --git a/examples/simple-web-cluster/src/test/java/brooklyn/demo/RebindWebClusterDatabaseExampleAppIntegrationTest.java b/examples/simple-web-cluster/src/test/java/brooklyn/demo/RebindWebClusterDatabaseExampleAppIntegrationTest.java index f113ca0c8a..19edba99fc 100644 --- a/examples/simple-web-cluster/src/test/java/brooklyn/demo/RebindWebClusterDatabaseExampleAppIntegrationTest.java +++ b/examples/simple-web-cluster/src/test/java/brooklyn/demo/RebindWebClusterDatabaseExampleAppIntegrationTest.java @@ -45,6 +45,7 @@ import brooklyn.entity.java.JavaEntityMethods; import brooklyn.entity.proxy.nginx.NginxController; import brooklyn.entity.proxying.EntitySpec; +import brooklyn.entity.rebind.RebindOptions; import brooklyn.entity.rebind.RebindTestFixture; import brooklyn.entity.webapp.ControlledDynamicWebAppCluster; import brooklyn.entity.webapp.DynamicWebAppCluster; @@ -121,7 +122,7 @@ public void testRestoresSimpleApp() throws Exception { String clusterUrl = checkNotNull(origApp.getAttribute(WebClusterDatabaseExampleApp.ROOT_URL), "cluster url"); WebAppMonitor monitor = newWebAppMonitor(clusterUrl, 200); - newApp = rebind(false, true); + newApp = rebind(RebindOptions.create().terminateOrigManagementContext(true)); assertAppFunctional(newApp); // expect no failures during rebind diff --git a/software/base/src/test/java/brooklyn/entity/pool/ServerPoolRebindTest.java b/software/base/src/test/java/brooklyn/entity/pool/ServerPoolRebindTest.java index 842b3fa88a..87feeff80c 100644 --- a/software/base/src/test/java/brooklyn/entity/pool/ServerPoolRebindTest.java +++ b/software/base/src/test/java/brooklyn/entity/pool/ServerPoolRebindTest.java @@ -32,6 +32,7 @@ import brooklyn.entity.Application; import brooklyn.entity.Entity; import brooklyn.entity.basic.Attributes; +import brooklyn.entity.rebind.RebindOptions; import brooklyn.entity.rebind.RebindTestUtils; import brooklyn.management.ManagementContext; import brooklyn.management.internal.LocalManagementContext; @@ -66,7 +67,7 @@ private Collection rebind(TestApplication app) throws Exception { LOG.info("Rebind start"); RebindTestUtils.waitForPersisted(app); ((LocalManagementContext) app.getManagementContext()).terminate(); - Collection r = RebindTestUtils.rebindAll(mementoDir, getClass().getClassLoader()); + Collection r = RebindTestUtils.rebindAll(RebindOptions.create().mementoDir(mementoDir).classLoader(classLoader)); LOG.info("Rebind complete"); return r; } diff --git a/software/base/src/test/java/brooklyn/event/feed/jmx/RebindJmxFeedTest.java b/software/base/src/test/java/brooklyn/event/feed/jmx/RebindJmxFeedTest.java index b9e187352e..4e82e74b32 100644 --- a/software/base/src/test/java/brooklyn/event/feed/jmx/RebindJmxFeedTest.java +++ b/software/base/src/test/java/brooklyn/event/feed/jmx/RebindJmxFeedTest.java @@ -103,7 +103,7 @@ protected void runJmxFeedIsPersisted(boolean preCreateJmxHelper) throws Exceptio EntityTestUtils.assertAttributeEqualsEventually(origEntity, SENSOR_STRING, "myval"); assertEquals(origEntity.feeds().getFeeds().size(), 1); - newApp = rebind(false); + newApp = rebind(); TestEntity newEntity = (TestEntity) Iterables.getOnlyElement(newApp.getChildren()); Collection newFeeds = newEntity.feeds().getFeeds(); diff --git a/software/network/src/test/java/brooklyn/entity/network/bind/BindDnsServerIntegrationTest.java b/software/network/src/test/java/brooklyn/entity/network/bind/BindDnsServerIntegrationTest.java index f6f9fd802e..b6b9aba763 100644 --- a/software/network/src/test/java/brooklyn/entity/network/bind/BindDnsServerIntegrationTest.java +++ b/software/network/src/test/java/brooklyn/entity/network/bind/BindDnsServerIntegrationTest.java @@ -24,18 +24,13 @@ import org.slf4j.LoggerFactory; import org.testng.annotations.Test; -import com.google.common.base.Joiner; -import com.google.common.base.Predicate; -import com.google.common.base.Predicates; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; - import brooklyn.entity.basic.ApplicationBuilder; import brooklyn.entity.basic.Attributes; import brooklyn.entity.basic.EmptySoftwareProcess; import brooklyn.entity.basic.Entities; import brooklyn.entity.group.DynamicCluster; import brooklyn.entity.proxying.EntitySpec; +import brooklyn.entity.rebind.RebindOptions; import brooklyn.entity.rebind.RebindTestFixture; import brooklyn.location.LocationSpec; import brooklyn.location.basic.LocalhostMachineProvisioningLocation; @@ -43,6 +38,12 @@ import brooklyn.test.EntityTestUtils; import brooklyn.test.entity.TestApplication; +import com.google.common.base.Joiner; +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Iterables; + public class BindDnsServerIntegrationTest extends RebindTestFixture { private static final Logger LOG = LoggerFactory.getLogger(BindDnsServerIntegrationTest.class); @@ -65,7 +66,7 @@ protected TestApplication createApp() { return app; } - @Test(invocationCount=1, groups = "Integration") + @Test(groups = "Integration") public void testRebindDns() throws Throwable { LocationSpec.create(LocalhostMachineProvisioningLocation.class); origApp.start(ImmutableList.of(new LocalhostMachineProvisioningLocation())); @@ -73,7 +74,7 @@ public void testRebindDns() throws Throwable { assertEquals(dns.getAttribute(BindDnsServer.ADDRESS_MAPPINGS).keySet().size(), 1); assertMapSizes(3, 1, 2, 1); - rebind(false, true, mementoDirBackup); + rebind(RebindOptions.create().mementoDirBackup(mementoDirBackup)); try { dns = (BindDnsServer) Iterables.getOnlyElement(Iterables.filter(newApp.getChildren(), Predicates.instanceOf(BindDnsServer.class))); cluster = (DynamicCluster) Iterables.getOnlyElement(Iterables.filter(newApp.getChildren(), Predicates.instanceOf(DynamicCluster.class))); @@ -92,7 +93,7 @@ public void testRebindDns() throws Throwable { EntityTestUtils.assertAttributeEqualsEventually(cluster, DynamicCluster.GROUP_SIZE, 5); assertMapSizes(5, 1, 4, 1); } catch (Throwable t) { - // Failing in jenkins occassionally; don't know why and can't reproduce. + // Failing in jenkins occasionally; don't know why and can't reproduce. // Therefore dumping out lots more info on failure. LOG.error("Test failed; dumping out contents of original persistence dir used for rebind...", t); dumpMementoDir(mementoDirBackup); diff --git a/software/nosql/src/test/java/brooklyn/entity/nosql/cassandra/CassandraDatacenterRebindIntegrationTest.java b/software/nosql/src/test/java/brooklyn/entity/nosql/cassandra/CassandraDatacenterRebindIntegrationTest.java index 0b53216836..8f917cb28a 100644 --- a/software/nosql/src/test/java/brooklyn/entity/nosql/cassandra/CassandraDatacenterRebindIntegrationTest.java +++ b/software/nosql/src/test/java/brooklyn/entity/nosql/cassandra/CassandraDatacenterRebindIntegrationTest.java @@ -31,6 +31,7 @@ import brooklyn.entity.proxy.nginx.NginxController; import brooklyn.entity.proxying.EntitySpec; +import brooklyn.entity.rebind.RebindOptions; import brooklyn.entity.rebind.RebindTestFixtureWithApp; import brooklyn.entity.trait.Startable; import brooklyn.location.basic.LocalhostMachineProvisioningLocation; @@ -81,7 +82,7 @@ public void testRebindDatacenterOfSizeOne() throws Exception { Set origTokens = origNode.getAttribute(CassandraNode.TOKENS); assertNotNull(origToken); - newApp = rebind(false, true); + newApp = rebind(RebindOptions.create().terminateOrigManagementContext(true)); final CassandraDatacenter newDatacenter = (CassandraDatacenter) Iterables.find(newApp.getChildren(), Predicates.instanceOf(CassandraDatacenter.class)); final CassandraNode newNode = (CassandraNode) Iterables.find(newDatacenter.getMembers(), Predicates.instanceOf(CassandraNode.class)); 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 364ef4743e..3556548317 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 @@ -44,6 +44,7 @@ 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.jboss.JBoss7Server; import brooklyn.location.LocationSpec; @@ -131,7 +132,7 @@ public void testRebindsWithEmptyServerPool() throws Exception { WebAppMonitor monitor = newWebAppMonitor(rootUrl, 404); final String origConfigFile = origNginx.getConfigFile(); - newApp = rebind(false, true); + newApp = rebind(RebindOptions.create().terminateOrigManagementContext(true)); final NginxController newNginx = (NginxController) Iterables.find(newApp.getChildren(), Predicates.instanceOf(NginxController.class)); assertEquals(newNginx.getConfigFile(), origConfigFile); @@ -175,7 +176,7 @@ public void testRebindsWithoutLosingServerPool() throws Exception { final String origConfigFile = origNginx.getConfigFile(); // Rebind - newApp = rebind(false, true); + 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()); @@ -253,7 +254,7 @@ public void testRebindsWithoutLosingUrlMappings() throws Exception { final String origConfigFile = origNginx.getConfigFile(); // Create a rebinding - newApp = rebind(false, true); + 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()); diff --git a/software/webapp/src/test/java/brooklyn/entity/webapp/jboss/JBoss7ServerRebindingIntegrationTest.java b/software/webapp/src/test/java/brooklyn/entity/webapp/jboss/JBoss7ServerRebindingIntegrationTest.java index 12b08437d7..61d92d7059 100644 --- a/software/webapp/src/test/java/brooklyn/entity/webapp/jboss/JBoss7ServerRebindingIntegrationTest.java +++ b/software/webapp/src/test/java/brooklyn/entity/webapp/jboss/JBoss7ServerRebindingIntegrationTest.java @@ -34,6 +34,7 @@ import brooklyn.entity.basic.SoftwareProcess; import brooklyn.entity.proxying.EntitySpec; +import brooklyn.entity.rebind.RebindOptions; import brooklyn.entity.rebind.RebindTestFixtureWithApp; import brooklyn.location.basic.LocalhostMachineProvisioningLocation; import brooklyn.test.EntityTestUtils; @@ -95,7 +96,7 @@ public void testRebindsToRunningServer() throws Exception { WebAppMonitor monitor = newWebAppMonitor(origServer.getAttribute(JBoss7Server.ROOT_URL)); // Rebind - newApp = rebind(false, true); + newApp = rebind(RebindOptions.create().terminateOrigManagementContext(true)); JBoss7Server newServer = (JBoss7Server) Iterables.find(newApp.getChildren(), Predicates.instanceOf(JBoss7Server.class)); String newRootUrl = newServer.getAttribute(JBoss7Server.ROOT_URL);