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%2Fpersisted%2FSnapshotTest.java;h=55d9d47376ddf4ad9cf0fa6319713d50d640a0eb;hb=71a011bda9cefd9b1a3b10c375baa2e85d41fb98;hp=9f1f924252da9a9fd624973944f47ac42bb573b7;hpb=51d39ed80e64a501f3ecadfdea22389b6edd8cca;p=controller.git diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/persisted/SnapshotTest.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/persisted/SnapshotTest.java index 9f1f924252..55d9d47376 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/persisted/SnapshotTest.java +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/persisted/SnapshotTest.java @@ -9,8 +9,6 @@ package org.opendaylight.controller.cluster.raft.persisted; import static org.junit.Assert.assertEquals; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import org.apache.commons.lang.SerializationUtils; import org.junit.Test; @@ -23,27 +21,29 @@ import org.opendaylight.controller.cluster.raft.ReplicatedLogEntry; * @author Thomas Pantelis */ public class SnapshotTest { - @Test public void testSerialization() { - testSerialization(new byte[]{1, 2, 3, 4, 5, 6, 7}, Arrays.asList( - new SimpleReplicatedLogEntry(6, 2, new MockPayload("payload")))); - testSerialization(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9}, Collections.emptyList()); + testSerialization(new byte[]{1, 2, 3, 4, 5, 6, 7}, List.of( + new SimpleReplicatedLogEntry(6, 2, new MockPayload("payload"))), 548); + testSerialization(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9}, List.of(), 389); } - private static void testSerialization(final byte[] state, final List unapplied) { + private static void testSerialization(final byte[] state, final List unapplied, + final int expectedSize) { long lastIndex = 6; long lastTerm = 2; long lastAppliedIndex = 5; long lastAppliedTerm = 1; long electionTerm = 3; String electionVotedFor = "member-1"; - ServerConfigurationPayload serverConfig = new ServerConfigurationPayload(Arrays.asList( + ServerConfigurationPayload serverConfig = new ServerConfigurationPayload(List.of( new ServerInfo("1", true), new ServerInfo("2", false))); - Snapshot expected = Snapshot.create(ByteState.of(state), unapplied, lastIndex, lastTerm, lastAppliedIndex, + final var expected = Snapshot.create(ByteState.of(state), unapplied, lastIndex, lastTerm, lastAppliedIndex, lastAppliedTerm, electionTerm, electionVotedFor, serverConfig); - Snapshot cloned = (Snapshot) SerializationUtils.clone(expected); + final var bytes = SerializationUtils.serialize(expected); + assertEquals(expectedSize, bytes.length); + final var cloned = (Snapshot) SerializationUtils.deserialize(bytes); assertEquals("lastIndex", expected.getLastIndex(), cloned.getLastIndex()); assertEquals("lastTerm", expected.getLastTerm(), cloned.getLastTerm());