X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-akka-raft%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fraft%2Fmessages%2FInstallSnapshotTest.java;h=c7fad2a19107e05332a873c5c2bad172854be3ab;hb=refs%2Fchanges%2F09%2F83009%2F6;hp=cde180796b8eba6634971ffd22238513a6bb602e;hpb=9d5ec5cdd146a56bc03e35b6718e9492a5c8410a;p=controller.git diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/messages/InstallSnapshotTest.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/messages/InstallSnapshotTest.java index cde180796b..c7fad2a191 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/messages/InstallSnapshotTest.java +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/messages/InstallSnapshotTest.java @@ -9,15 +9,16 @@ package org.opendaylight.controller.cluster.raft.messages; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; -import com.google.common.base.Optional; + import java.io.Serializable; import java.util.Arrays; +import java.util.Optional; +import java.util.OptionalInt; import org.apache.commons.lang.SerializationUtils; import org.junit.Test; import org.opendaylight.controller.cluster.raft.RaftVersions; import org.opendaylight.controller.cluster.raft.persisted.ServerConfigurationPayload; import org.opendaylight.controller.cluster.raft.persisted.ServerInfo; -import org.opendaylight.controller.protobuff.messages.cluster.raft.InstallSnapshotMessages; /** * Unit tests for InstallSnapshot. @@ -29,53 +30,31 @@ public class InstallSnapshotTest { @Test public void testSerialization() { byte[] data = new byte[1000]; - int j = 0; - for(int i = 0; i < data.length; i++) { + for (int i = 0, j = 0; i < data.length; i++) { data[i] = (byte)j; - if(++j >= 255) { + if (++j >= 255) { j = 0; } } ServerConfigurationPayload serverConfig = new ServerConfigurationPayload(Arrays.asList( new ServerInfo("leader", true), new ServerInfo("follower", false))); - InstallSnapshot expected = new InstallSnapshot(3L, "leaderId", 11L, 2L, data, 5, 6, - Optional.of(54321), Optional.of(serverConfig)); + InstallSnapshot expected = new InstallSnapshot(3L, "leaderId", 11L, 2L, data, 5, 6, OptionalInt.of(54321), + Optional.of(serverConfig)); Object serialized = expected.toSerializable(RaftVersions.CURRENT_VERSION); assertEquals("Serialized type", InstallSnapshot.class, serialized.getClass()); - InstallSnapshot actual = InstallSnapshot.fromSerializable(SerializationUtils.clone((Serializable) serialized)); + InstallSnapshot actual = (InstallSnapshot) SerializationUtils.clone((Serializable) serialized); verifyInstallSnapshot(expected, actual); expected = new InstallSnapshot(3L, "leaderId", 11L, 2L, data, 5, 6); - actual = InstallSnapshot.fromSerializable(SerializationUtils.clone( - (Serializable) expected.toSerializable(RaftVersions.CURRENT_VERSION))); - verifyInstallSnapshot(expected, actual); - } - - @Test - public void testSerializationWithPreBoronVersion() { - byte[] data = {0,1,2,3,4,5,7,8,9}; - InstallSnapshot expected = new InstallSnapshot(3L, "leaderId", 11L, 2L, data, 5, 6, Optional.of(54321), - Optional.absent()); - - Object serialized = expected.toSerializable(RaftVersions.LITHIUM_VERSION); - assertEquals("Serialized type", InstallSnapshot.SERIALIZABLE_CLASS, serialized.getClass()); - - InstallSnapshot actual = InstallSnapshot.fromSerializable(SerializationUtils.clone((Serializable) serialized)); + actual = (InstallSnapshot) SerializationUtils.clone((Serializable) expected.toSerializable( + RaftVersions.CURRENT_VERSION)); verifyInstallSnapshot(expected, actual); } - @Test - public void testIsSerializedType() { - assertEquals("isSerializedType", true, InstallSnapshot.isSerializedType( - InstallSnapshotMessages.InstallSnapshot.newBuilder().build())); - assertEquals("isSerializedType", true, InstallSnapshot.isSerializedType(new InstallSnapshot())); - assertEquals("isSerializedType", false, InstallSnapshot.isSerializedType(new Object())); - } - - private static void verifyInstallSnapshot(InstallSnapshot expected, InstallSnapshot actual) { + private static void verifyInstallSnapshot(final InstallSnapshot expected, final InstallSnapshot actual) { assertEquals("getTerm", expected.getTerm(), actual.getTerm()); assertEquals("getChunkIndex", expected.getChunkIndex(), actual.getChunkIndex()); assertEquals("getTotalChunks", expected.getTotalChunks(), actual.getTotalChunks()); @@ -87,14 +66,14 @@ public class InstallSnapshotTest { assertEquals("getLastChunkHashCode present", expected.getLastChunkHashCode().isPresent(), actual.getLastChunkHashCode().isPresent()); - if(expected.getLastChunkHashCode().isPresent()) { - assertEquals("getLastChunkHashCode", expected.getLastChunkHashCode().get(), - actual.getLastChunkHashCode().get()); + if (expected.getLastChunkHashCode().isPresent()) { + assertEquals("getLastChunkHashCode", expected.getLastChunkHashCode(), + actual.getLastChunkHashCode()); } assertEquals("getServerConfig present", expected.getServerConfig().isPresent(), actual.getServerConfig().isPresent()); - if(expected.getServerConfig().isPresent()) { + if (expected.getServerConfig().isPresent()) { assertEquals("getServerConfig", expected.getServerConfig().get().getServerConfig(), actual.getServerConfig().get().getServerConfig()); }