/*
- * Copyright (c) 2016 Brocade Communications Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2016, 2017 Brocade Communications Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
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;
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;
MetadataShardDataTreeSnapshot snapshot = new MetadataShardDataTreeSnapshot(expectedNode);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
- try (final ObjectOutputStream out = new ObjectOutputStream(bos)) {
+ try (ObjectOutputStream out = new ObjectOutputStream(bos)) {
snapshot.serialize(out);
}
+ final byte[] bytes = bos.toByteArray();
+ assertEquals(236, bytes.length);
+
ShardDataTreeSnapshot deserialized;
- try (final 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());
+ 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());
ImmutableMap.of(TestShardDataTreeSnapshotMetadata.class, new TestShardDataTreeSnapshotMetadata("test"));
MetadataShardDataTreeSnapshot snapshot = new MetadataShardDataTreeSnapshot(expectedNode, expMetadata);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
- try (final ObjectOutputStream out = new ObjectOutputStream(bos)) {
+ try (ObjectOutputStream out = new ObjectOutputStream(bos)) {
snapshot.serialize(out);
}
+ final byte[] bytes = bos.toByteArray();
+ assertEquals(384, bytes.length);
+
ShardDataTreeSnapshot deserialized;
- try (final 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());
+ assertTrue("rootNode present", actualNode.isPresent());
assertEquals("rootNode", expectedNode, actualNode.get());
assertEquals("Deserialized type", MetadataShardDataTreeSnapshot.class, deserialized.getClass());
assertEquals("Metadata", expMetadata, ((MetadataShardDataTreeSnapshot)deserialized).getMetadata());
}
- @Test
- @Deprecated
- public void testPreBoronShardDataTreeSnapshot() throws Exception {
- NormalizedNode<?, ?> expectedNode = ImmutableContainerNodeBuilder.create()
- .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
- .withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();
-
- byte[] serialized = SerializationUtils.serializeNormalizedNode(expectedNode);
-
- ShardDataTreeSnapshot deserialized = ShardDataTreeSnapshot.deserializePreCarbon(serialized);
-
- Optional<NormalizedNode<?, ?>> actualNode = deserialized.getRootNode();
- assertEquals("rootNode present", true, actualNode.isPresent());
- assertEquals("rootNode", expectedNode, actualNode.get());
- assertEquals("Deserialized type", PreBoronShardDataTreeSnapshot.class, deserialized.getClass());
- }
-
static class TestShardDataTreeSnapshotMetadata
extends ShardDataTreeSnapshotMetadata<TestShardDataTreeSnapshotMetadata> {
private static final long serialVersionUID = 1L;
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();
}