Add ServerConfigPayload to InstallSnapshot message
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / test / java / org / opendaylight / controller / cluster / raft / messages / InstallSnapshotTest.java
index b2d518e1ede8be15470701a12144d32a06d8d349..7b123741b6e6b52700db1cb68d5f508c603afd73 100644 (file)
@@ -11,9 +11,12 @@ 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 org.apache.commons.lang.SerializationUtils;
 import org.junit.Test;
 import org.opendaylight.controller.cluster.raft.RaftVersions;
+import org.opendaylight.controller.cluster.raft.ServerConfigurationPayload;
+import org.opendaylight.controller.cluster.raft.ServerConfigurationPayload.ServerInfo;
 import org.opendaylight.controller.protobuff.messages.cluster.raft.InstallSnapshotMessages;
 
 /**
@@ -34,7 +37,10 @@ public class InstallSnapshotTest {
             }
         }
 
-        InstallSnapshot expected = new InstallSnapshot(3L, "leaderId", 11L, 2L, data, 5, 6, Optional.<Integer>of(54321));
+        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.<Integer>of(54321), Optional.of(serverConfig));
 
         Object serialized = expected.toSerializable(RaftVersions.CURRENT_VERSION);
         assertEquals("Serialized type", InstallSnapshot.class, serialized.getClass());
@@ -51,7 +57,8 @@ public class InstallSnapshotTest {
     @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.<Integer>of(54321));
+        InstallSnapshot expected = new InstallSnapshot(3L, "leaderId", 11L, 2L, data, 5, 6, Optional.<Integer>of(54321),
+                Optional.<ServerConfigurationPayload>absent());
 
         Object serialized = expected.toSerializable(RaftVersions.LITHIUM_VERSION);
         assertEquals("Serialized type", InstallSnapshot.SERIALIZABLE_CLASS, serialized.getClass());
@@ -68,7 +75,7 @@ public class InstallSnapshotTest {
         assertEquals("isSerializedType", false, InstallSnapshot.isSerializedType(new Object()));
     }
 
-    private void verifyInstallSnapshot(InstallSnapshot expected, InstallSnapshot actual) {
+    private static void verifyInstallSnapshot(InstallSnapshot expected, InstallSnapshot actual) {
         assertEquals("getTerm", expected.getTerm(), actual.getTerm());
         assertEquals("getChunkIndex", expected.getChunkIndex(), actual.getChunkIndex());
         assertEquals("getTotalChunks", expected.getTotalChunks(), actual.getTotalChunks());
@@ -77,11 +84,19 @@ public class InstallSnapshotTest {
         assertEquals("getLeaderId", expected.getLeaderId(), actual.getLeaderId());
         assertEquals("getChunkIndex", expected.getChunkIndex(), actual.getChunkIndex());
         assertArrayEquals("getData", expected.getData(), actual.getData());
+
         assertEquals("getLastChunkHashCode present", expected.getLastChunkHashCode().isPresent(),
                 actual.getLastChunkHashCode().isPresent());
         if(expected.getLastChunkHashCode().isPresent()) {
             assertEquals("getLastChunkHashCode", expected.getLastChunkHashCode().get(),
                     actual.getLastChunkHashCode().get());
         }
+
+        assertEquals("getServerConfig present", expected.getServerConfig().isPresent(),
+                actual.getServerConfig().isPresent());
+        if(expected.getServerConfig().isPresent()) {
+            assertEquals("getServerConfig", expected.getServerConfig().get().getServerConfig(),
+                    actual.getServerConfig().get().getServerConfig());
+        }
     }
 }