package org.opendaylight.controller.cluster.datastore.persisted;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import com.google.common.collect.ImmutableMap;
import java.io.ByteArrayInputStream;
@Test
public void testShardDataTreeSnapshotWithNoMetadata() throws Exception {
- NormalizedNode<?, ?> expectedNode = ImmutableContainerNodeBuilder.create()
+ NormalizedNode expectedNode = ImmutableContainerNodeBuilder.create()
.withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
.withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();
snapshot.serialize(out);
}
+ final byte[] bytes = bos.toByteArray();
+ assertEquals(236, bytes.length);
+
ShardDataTreeSnapshot deserialized;
- try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()))) {
- deserialized = ShardDataTreeSnapshot.deserialize(in);
+ try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes))) {
+ deserialized = ShardDataTreeSnapshot.deserialize(in).getSnapshot();
}
- Optional<NormalizedNode<?, ?>> actualNode = deserialized.getRootNode();
- assertEquals("rootNode present", true, actualNode.isPresent());
+ Optional<NormalizedNode> actualNode = deserialized.getRootNode();
+ assertTrue("rootNode present", actualNode.isPresent());
assertEquals("rootNode", expectedNode, actualNode.get());
assertEquals("Deserialized type", MetadataShardDataTreeSnapshot.class, deserialized.getClass());
assertEquals("Metadata size", 0, ((MetadataShardDataTreeSnapshot)deserialized).getMetadata().size());
@Test
public void testShardDataTreeSnapshotWithMetadata() throws Exception {
- NormalizedNode<?, ?> expectedNode = ImmutableContainerNodeBuilder.create()
+ NormalizedNode expectedNode = ImmutableContainerNodeBuilder.create()
.withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
.withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();
snapshot.serialize(out);
}
+ final byte[] bytes = bos.toByteArray();
+ assertEquals(384, bytes.length);
+
ShardDataTreeSnapshot deserialized;
- try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()))) {
- deserialized = ShardDataTreeSnapshot.deserialize(in);
+ try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes))) {
+ deserialized = ShardDataTreeSnapshot.deserialize(in).getSnapshot();
}
- Optional<NormalizedNode<?, ?>> actualNode = deserialized.getRootNode();
- assertEquals("rootNode present", true, actualNode.isPresent());
+ Optional<NormalizedNode> actualNode = deserialized.getRootNode();
+ assertTrue("rootNode present", actualNode.isPresent());
assertEquals("rootNode", expectedNode, actualNode.get());
assertEquals("Deserialized type", MetadataShardDataTreeSnapshot.class, deserialized.getClass());
assertEquals("Metadata", expMetadata, ((MetadataShardDataTreeSnapshot)deserialized).getMetadata());
private final String data;
- TestShardDataTreeSnapshotMetadata(String data) {
+ TestShardDataTreeSnapshotMetadata(final String data) {
this.data = data;
}
}
@Override
- public boolean equals(Object obj) {
+ public boolean equals(final Object obj) {
return obj instanceof TestShardDataTreeSnapshotMetadata
&& data.equals(((TestShardDataTreeSnapshotMetadata)obj).data);
}
public Proxy() {
}
- Proxy(String data) {
+ Proxy(final String data) {
this.data = data;
}
@Override
- public void writeExternal(ObjectOutput out) throws IOException {
+ public void writeExternal(final ObjectOutput out) throws IOException {
out.writeObject(data);
}
@Override
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
data = (String) in.readObject();
}