You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by sv...@apache.org on 2016/10/21 09:20:48 UTC
[6/8] brooklyn-server git commit: Rebind tests: avoid
ClassCastException if multiple apps
Rebind tests: avoid ClassCastException if multiple apps
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/9a240b4b
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/9a240b4b
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/9a240b4b
Branch: refs/heads/master
Commit: 9a240b4bf3471a7b4bce601e5493133929dda20f
Parents: 70fd9bd
Author: Aled Sage <al...@gmail.com>
Authored: Wed Oct 19 13:21:47 2016 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Thu Oct 20 17:27:22 2016 +0100
----------------------------------------------------------------------
.../core/mgmt/rebind/RebindOptions.java | 9 +++++++++
.../mgmt/rebind/RebindTestFixtureWithApp.java | 20 ++++++++++++++++++++
.../core/mgmt/rebind/RebindTestUtils.java | 14 +++++++-------
3 files changed, 36 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/9a240b4b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindOptions.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindOptions.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindOptions.java
index 618a906..eab61cf 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindOptions.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindOptions.java
@@ -19,7 +19,9 @@
package org.apache.brooklyn.core.mgmt.rebind;
import java.io.File;
+import java.util.Collection;
+import org.apache.brooklyn.api.entity.Application;
import org.apache.brooklyn.api.mgmt.ManagementContext;
import org.apache.brooklyn.api.mgmt.ha.HighAvailabilityMode;
import org.apache.brooklyn.api.mgmt.rebind.RebindExceptionHandler;
@@ -43,6 +45,7 @@ public class RebindOptions {
public ClassLoader classLoader;
public PersistenceObjectStore objectStore;
public HighAvailabilityMode haMode;
+ public Function<Collection<Application>, Application> applicationChooserOnRebind;
public static RebindOptions create() {
return new RebindOptions();
@@ -60,6 +63,7 @@ public class RebindOptions {
result.classLoader(options.classLoader);
result.objectStore(options.objectStore);
result.haMode(options.haMode);
+ result.applicationChooserOnRebind(options.applicationChooserOnRebind);
return result;
}
public RebindOptions checkSerializable(boolean val) {
@@ -106,4 +110,9 @@ public class RebindOptions {
this.haMode = val;
return this;
}
+
+ public RebindOptions applicationChooserOnRebind(Function<Collection<Application>, Application> val) {
+ this.applicationChooserOnRebind = val;
+ return this;
+ }
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/9a240b4b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixtureWithApp.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixtureWithApp.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixtureWithApp.java
index 2a7e443..e609a02 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixtureWithApp.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixtureWithApp.java
@@ -18,14 +18,34 @@
*/
package org.apache.brooklyn.core.mgmt.rebind;
+import java.util.Collection;
+
+import org.apache.brooklyn.api.entity.Application;
import org.apache.brooklyn.api.entity.EntitySpec;
import org.apache.brooklyn.core.test.entity.TestApplication;
import org.apache.brooklyn.core.test.entity.TestApplicationNoEnrichersImpl;
+import com.google.common.base.Function;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Iterables;
+
public class RebindTestFixtureWithApp extends RebindTestFixture<TestApplication> {
protected TestApplication createApp() {
return origManagementContext.getEntityManager().createEntity(EntitySpec.create(TestApplication.class, TestApplicationNoEnrichersImpl.class));
}
+ @Override
+ protected TestApplication rebind(RebindOptions options) throws Exception {
+ if (options.applicationChooserOnRebind == null) {
+ // Some sub-classes will have added additional apps before rebind. We must return an
+ // app of type "TestApplication"; otherwise we'll get a class-cast exception.
+ options = RebindOptions.create(options);
+ options.applicationChooserOnRebind(new Function<Collection<Application>, Application>() {
+ @Override public Application apply(Collection<Application> input) {
+ return Iterables.find(input, Predicates.instanceOf(TestApplication.class));
+ }});
+ }
+ return super.rebind(options);
+ }
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/9a240b4b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestUtils.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestUtils.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestUtils.java
index af3a5e4..2283b66 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestUtils.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestUtils.java
@@ -44,13 +44,9 @@ import org.apache.brooklyn.core.mgmt.ha.ManagementPlaneSyncRecordPersisterToObje
import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
import org.apache.brooklyn.core.mgmt.persist.BrooklynMementoPersisterToObjectStore;
-import org.apache.brooklyn.core.mgmt.persist.BrooklynPersistenceUtils;
import org.apache.brooklyn.core.mgmt.persist.FileBasedObjectStore;
import org.apache.brooklyn.core.mgmt.persist.PersistMode;
import org.apache.brooklyn.core.mgmt.persist.PersistenceObjectStore;
-import org.apache.brooklyn.core.mgmt.rebind.PersistenceExceptionHandlerImpl;
-import org.apache.brooklyn.core.mgmt.rebind.RebindExceptionHandlerImpl;
-import org.apache.brooklyn.core.mgmt.rebind.RebindManagerImpl;
import org.apache.brooklyn.core.mgmt.rebind.Dumpers.Pointer;
import org.apache.brooklyn.core.mgmt.rebind.dto.MementosGenerators;
import org.apache.brooklyn.core.server.BrooklynServerConfig;
@@ -333,11 +329,15 @@ public class RebindTestUtils {
public static Application rebind(RebindOptions options) throws Exception {
Collection<Application> newApps = rebindAll(options);
- if (newApps.isEmpty()) throw new IllegalStateException("Application could not be rebinded; serialization probably failed");
- return Iterables.getFirst(newApps, null);
+ if (newApps.isEmpty()) throw new IllegalStateException("Application could not be found after rebind; serialization probably failed");
+ Function<Collection<Application>, Application> chooser = options.applicationChooserOnRebind;
+ if (chooser != null) {
+ return chooser.apply(newApps);
+ } else {
+ return Iterables.getFirst(newApps, null);
+ }
}
-
/**
* @deprecated since 0.7.0; use {@link #rebindAll(RebindOptions)}
*/