Test XML persistence of task Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/a36ecc8e Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/a36ecc8e Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/a36ecc8e
Branch: refs/heads/master Commit: a36ecc8eb3f018444d50b7406b6b5ae06ce59b3f Parents: 04711a5 Author: Aled Sage <aled.s...@gmail.com> Authored: Thu Nov 10 13:19:16 2016 +0000 Committer: Aled Sage <aled.s...@gmail.com> Committed: Thu Nov 10 14:15:12 2016 +0000 ---------------------------------------------------------------------- .../mgmt/persist/XmlMementoSerializerTest.java | 36 +++++++++++++++++++- .../org/apache/brooklyn/test/LogWatcher.java | 4 +++ 2 files changed, 39 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/a36ecc8e/core/src/test/java/org/apache/brooklyn/core/mgmt/persist/XmlMementoSerializerTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/persist/XmlMementoSerializerTest.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/persist/XmlMementoSerializerTest.java index fab0059..b708eb7 100644 --- a/core/src/test/java/org/apache/brooklyn/core/mgmt/persist/XmlMementoSerializerTest.java +++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/persist/XmlMementoSerializerTest.java @@ -39,6 +39,7 @@ import org.apache.brooklyn.api.entity.EntitySpec; import org.apache.brooklyn.api.location.Location; import org.apache.brooklyn.api.location.LocationSpec; import org.apache.brooklyn.api.mgmt.ManagementContext; +import org.apache.brooklyn.api.mgmt.Task; import org.apache.brooklyn.api.mgmt.rebind.mementos.BrooklynMementoPersister.LookupContext; import org.apache.brooklyn.api.objs.BrooklynObject; import org.apache.brooklyn.api.objs.BrooklynObjectType; @@ -56,16 +57,19 @@ import org.apache.brooklyn.core.mgmt.ha.OsgiManager; import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal; import org.apache.brooklyn.core.mgmt.osgi.OsgiStandaloneTest; import org.apache.brooklyn.core.mgmt.osgi.OsgiVersionMoreEntityTest; +import org.apache.brooklyn.core.mgmt.rebind.RebindEntityTest.ReffingEntity; import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests; import org.apache.brooklyn.core.test.entity.TestApplication; import org.apache.brooklyn.core.test.entity.TestEntity; import org.apache.brooklyn.entity.group.DynamicCluster; +import org.apache.brooklyn.test.LogWatcher; +import org.apache.brooklyn.test.LogWatcher.EventPredicates; import org.apache.brooklyn.test.support.TestResourceUnavailableException; import org.apache.brooklyn.util.collections.MutableList; import org.apache.brooklyn.util.collections.MutableMap; import org.apache.brooklyn.util.collections.MutableSet; -import org.apache.brooklyn.util.core.ClassLoaderUtils; import org.apache.brooklyn.util.core.osgi.Osgis; +import org.apache.brooklyn.util.core.task.BasicTask; import org.apache.brooklyn.util.javalang.Reflections; import org.apache.brooklyn.util.net.Networking; import org.apache.brooklyn.util.net.UserAndHostAndPort; @@ -80,17 +84,21 @@ import org.testng.annotations.Test; import com.google.common.base.Joiner; import com.google.common.base.Objects; +import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import com.google.common.util.concurrent.Callables; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; +import ch.qos.logback.classic.spi.ILoggingEvent; + public class XmlMementoSerializerTest { private static final Logger LOG = LoggerFactory.getLogger(XmlMementoSerializerTest.class); @@ -518,6 +526,32 @@ public class XmlMementoSerializerTest { } } + @Test + public void testTask() throws Exception { + final TestApplication app = TestApplication.Factory.newManagedInstanceForTests(); + mgmt = app.getManagementContext(); + Task<String> completedTask = app.getExecutionContext().submit(Callables.returning("myval")); + completedTask.get(); + + String loggerName = UnwantedStateLoggingMapper.class.getName(); + ch.qos.logback.classic.Level logLevel = ch.qos.logback.classic.Level.WARN; + Predicate<ILoggingEvent> filter = EventPredicates.containsMessage("Task object serialization is not supported or recommended"); + LogWatcher watcher = new LogWatcher(loggerName, logLevel, filter); + + String serializedForm; + watcher.start(); + try { + serializedForm = serializer.toString(completedTask); + watcher.assertHasEvent(); + } finally { + watcher.close(); + } + + assertEquals(serializedForm.trim(), "<"+BasicTask.class.getName()+">myval</"+BasicTask.class.getName()+">"); + Object deserialized = serializer.fromString(serializedForm); + assertEquals(deserialized, null, "serializedForm="+serializedForm+"; deserialized="+deserialized); + } + public static class ReffingEntity { public Entity entity; public Object obj; http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/a36ecc8e/test-support/src/main/java/org/apache/brooklyn/test/LogWatcher.java ---------------------------------------------------------------------- diff --git a/test-support/src/main/java/org/apache/brooklyn/test/LogWatcher.java b/test-support/src/main/java/org/apache/brooklyn/test/LogWatcher.java index 9326f1b..6baa852 100644 --- a/test-support/src/main/java/org/apache/brooklyn/test/LogWatcher.java +++ b/test-support/src/main/java/org/apache/brooklyn/test/LogWatcher.java @@ -130,6 +130,10 @@ public class LogWatcher implements Closeable { } } + public void assertHasEvent() { + assertFalse(events.isEmpty()); + } + public void assertHasEventEventually() { Asserts.succeedsEventually(new Runnable() { public void run() {