X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Fpersisted%2FShardDataTreeSnapshotTest.java;fp=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Fpersisted%2FShardDataTreeSnapshotTest.java;h=d999620180357f9297568addbc9dd85bc05a7c2a;hb=aafb8cb044e992dd784d1f4f66508599cc4cd588;hp=e909e79a79cace27bc657465ee10cbb5bb7637a2;hpb=2f77e92af7a68b4a97dbfb709c6cc9b11a49878a;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/persisted/ShardDataTreeSnapshotTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/persisted/ShardDataTreeSnapshotTest.java index e909e79a79..d999620180 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/persisted/ShardDataTreeSnapshotTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/persisted/ShardDataTreeSnapshotTest.java @@ -15,10 +15,13 @@ import java.io.ByteArrayOutputStream; import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; +import java.io.ObjectInputStream; import java.io.ObjectOutput; +import java.io.ObjectOutputStream; import java.util.Map; import java.util.Optional; import org.junit.Test; +import org.opendaylight.controller.cluster.datastore.node.utils.stream.SerializationUtils; import org.opendaylight.controller.md.cluster.datastore.model.TestModel; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; @@ -40,10 +43,14 @@ public class ShardDataTreeSnapshotTest { MetadataShardDataTreeSnapshot snapshot = new MetadataShardDataTreeSnapshot(expectedNode); ByteArrayOutputStream bos = new ByteArrayOutputStream(); - snapshot.serialize(bos); + try (final ObjectOutputStream out = new ObjectOutputStream(bos)) { + snapshot.serialize(out); + } - ShardDataTreeSnapshot deserialized = ShardDataTreeSnapshot.deserialize( - new ByteArrayInputStream(bos.toByteArray())); + ShardDataTreeSnapshot deserialized; + try (final ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()))) { + deserialized = ShardDataTreeSnapshot.deserialize(in); + } Optional> actualNode = deserialized.getRootNode(); assertEquals("rootNode present", true, actualNode.isPresent()); @@ -62,10 +69,14 @@ public class ShardDataTreeSnapshotTest { ImmutableMap.of(TestShardDataTreeSnapshotMetadata.class, new TestShardDataTreeSnapshotMetadata("test")); MetadataShardDataTreeSnapshot snapshot = new MetadataShardDataTreeSnapshot(expectedNode, expMetadata); ByteArrayOutputStream bos = new ByteArrayOutputStream(); - snapshot.serialize(bos); + try (final ObjectOutputStream out = new ObjectOutputStream(bos)) { + snapshot.serialize(out); + } - ShardDataTreeSnapshot deserialized = ShardDataTreeSnapshot.deserialize( - new ByteArrayInputStream(bos.toByteArray())); + ShardDataTreeSnapshot deserialized; + try (final ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()))) { + deserialized = ShardDataTreeSnapshot.deserialize(in); + } Optional> actualNode = deserialized.getRootNode(); assertEquals("rootNode present", true, actualNode.isPresent()); @@ -81,11 +92,9 @@ public class ShardDataTreeSnapshotTest { .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)) .withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build(); - PreBoronShardDataTreeSnapshot snapshot = new PreBoronShardDataTreeSnapshot(expectedNode); - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - snapshot.serialize(bos); + byte[] serialized = SerializationUtils.serializeNormalizedNode(expectedNode); - ShardDataTreeSnapshot deserialized = ShardDataTreeSnapshot.deserialize(bos.toByteArray()); + ShardDataTreeSnapshot deserialized = ShardDataTreeSnapshot.deserializePreCarbon(serialized); Optional> actualNode = deserialized.getRootNode(); assertEquals("rootNode present", true, actualNode.isPresent());