Further Guava Optional cleanups
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / test / java / org / opendaylight / controller / cluster / raft / MigratedMessagesTest.java
index 70f45045b71bf859ed50eff880b0ee07acc365d0..276ffb27f4f8a5faf0e206c2cdedbc807fa12fb2 100644 (file)
@@ -12,28 +12,20 @@ import static org.junit.Assert.assertEquals;
 import akka.actor.ActorRef;
 import akka.dispatch.Dispatchers;
 import akka.testkit.TestActorRef;
-import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Sets;
 import com.google.common.io.ByteSource;
 import com.google.common.util.concurrent.Uninterruptibles;
 import java.io.OutputStream;
-import java.io.Serializable;
-import java.util.Arrays;
 import java.util.List;
+import java.util.Optional;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Consumer;
-import org.apache.commons.lang3.SerializationUtils;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
-import org.opendaylight.controller.cluster.raft.MockRaftActor.MockSnapshotState;
-import org.opendaylight.controller.cluster.raft.MockRaftActorContext.MockPayload;
 import org.opendaylight.controller.cluster.raft.base.messages.CaptureSnapshotReply;
 import org.opendaylight.controller.cluster.raft.persisted.ApplyJournalEntries;
 import org.opendaylight.controller.cluster.raft.persisted.ByteState;
-import org.opendaylight.controller.cluster.raft.persisted.ServerConfigurationPayload;
-import org.opendaylight.controller.cluster.raft.persisted.ServerInfo;
 import org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry;
 import org.opendaylight.controller.cluster.raft.persisted.Snapshot;
 import org.opendaylight.controller.cluster.raft.persisted.Snapshot.State;
@@ -60,7 +52,7 @@ public class MigratedMessagesTest extends AbstractActorTest {
     }
 
     @After
-    public void tearDown() throws Exception {
+    public void tearDown() {
         factory.close();
         InMemoryJournal.clear();
         InMemorySnapshotStore.clear();
@@ -80,16 +72,16 @@ public class MigratedMessagesTest extends AbstractActorTest {
 
         RaftActorSnapshotCohort snapshotCohort = new RaftActorSnapshotCohort() {
             @Override
-            public void createSnapshot(ActorRef actorRef, java.util.Optional<OutputStream> installSnapshotStream) {
+            public void createSnapshot(final ActorRef actorRef, final Optional<OutputStream> installSnapshotStream) {
                 actorRef.tell(new CaptureSnapshotReply(ByteState.empty(), installSnapshotStream), actorRef);
             }
 
             @Override
-            public void applySnapshot(Snapshot.State snapshotState) {
+            public void applySnapshot(final Snapshot.State snapshotState) {
             }
 
             @Override
-            public State deserializeSnapshot(ByteSource snapshotBytes) {
+            public State deserializeSnapshot(final ByteSource snapshotBytes) {
                 throw new UnsupportedOperationException();
             }
         };
@@ -109,48 +101,9 @@ public class MigratedMessagesTest extends AbstractActorTest {
         TEST_LOG.info("testNoSnapshotAfterStartupWithNoMigratedMessages ending");
     }
 
-    @Test
-    public void testSnapshotAfterStartupWithMigratedSnapshot() throws Exception {
-        TEST_LOG.info("testSnapshotAfterStartupWithMigratedSnapshot starting");
-
-        String persistenceId = factory.generateActorId("test-actor-");
-
-        List<Object> snapshotData = Arrays.asList(new MockPayload("1"));
-        final MockSnapshotState snapshotState = new MockSnapshotState(snapshotData);
-
-        org.opendaylight.controller.cluster.raft.Snapshot legacy = org.opendaylight.controller.cluster.raft.Snapshot
-            .create(SerializationUtils.serialize((Serializable) snapshotData),
-                Arrays.asList(new SimpleReplicatedLogEntry(6, 2, new MockPayload("payload"))),
-                6, 2, 5, 1, 3, "member-1", new ServerConfigurationPayload(Arrays.asList(
-                        new ServerInfo(persistenceId, true), new ServerInfo("2", false))));
-        InMemorySnapshotStore.addSnapshot(persistenceId, legacy);
-
-        doTestSnapshotAfterStartupWithMigratedMessage(persistenceId, true, snapshot -> {
-            assertEquals("getLastIndex", legacy.getLastIndex(), snapshot.getLastIndex());
-            assertEquals("getLastTerm", legacy.getLastTerm(), snapshot.getLastTerm());
-            assertEquals("getLastAppliedIndex", legacy.getLastAppliedIndex(), snapshot.getLastAppliedIndex());
-            assertEquals("getLastAppliedTerm", legacy.getLastAppliedTerm(), snapshot.getLastAppliedTerm());
-            assertEquals("getState", snapshotState, snapshot.getState());
-            assertEquals("Unapplied entries size", legacy.getUnAppliedEntries().size(),
-                    snapshot.getUnAppliedEntries().size());
-            assertEquals("Unapplied entry term", legacy.getUnAppliedEntries().get(0).getTerm(),
-                    snapshot.getUnAppliedEntries().get(0).getTerm());
-            assertEquals("Unapplied entry index", legacy.getUnAppliedEntries().get(0).getIndex(),
-                    snapshot.getUnAppliedEntries().get(0).getIndex());
-            assertEquals("Unapplied entry data", legacy.getUnAppliedEntries().get(0).getData(),
-                    snapshot.getUnAppliedEntries().get(0).getData());
-            assertEquals("getElectionVotedFor", legacy.getElectionVotedFor(), snapshot.getElectionVotedFor());
-            assertEquals("getElectionTerm", legacy.getElectionTerm(), snapshot.getElectionTerm());
-            assertEquals("getServerConfiguration", Sets.newHashSet(legacy.getServerConfiguration().getServerConfig()),
-                    Sets.newHashSet(snapshot.getServerConfiguration().getServerConfig()));
-        }, snapshotState);
-
-        TEST_LOG.info("testSnapshotAfterStartupWithMigratedSnapshot ending");
-    }
-
     @SuppressWarnings("checkstyle:IllegalCatch")
-    private TestActorRef<MockRaftActor> doTestSnapshotAfterStartupWithMigratedMessage(String id, boolean persistent,
-            Consumer<Snapshot> snapshotVerifier, final State snapshotState) {
+    private TestActorRef<MockRaftActor> doTestSnapshotAfterStartupWithMigratedMessage(final String id,
+            final boolean persistent, final Consumer<Snapshot> snapshotVerifier, final State snapshotState) {
         InMemorySnapshotStore.addSnapshotSavedLatch(id);
         InMemoryJournal.addDeleteMessagesCompleteLatch(id);
         DefaultConfigParamsImpl config = new DefaultConfigParamsImpl();
@@ -158,16 +111,16 @@ public class MigratedMessagesTest extends AbstractActorTest {
 
         RaftActorSnapshotCohort snapshotCohort = new RaftActorSnapshotCohort() {
             @Override
-            public void createSnapshot(ActorRef actorRef, java.util.Optional<OutputStream> installSnapshotStream) {
+            public void createSnapshot(final ActorRef actorRef, final Optional<OutputStream> installSnapshotStream) {
                 actorRef.tell(new CaptureSnapshotReply(snapshotState, installSnapshotStream), actorRef);
             }
 
             @Override
-            public void applySnapshot(State newState) {
+            public void applySnapshot(final State newState) {
             }
 
             @Override
-            public State deserializeSnapshot(ByteSource snapshotBytes) {
+            public State deserializeSnapshot(final ByteSource snapshotBytes) {
                 throw new UnsupportedOperationException();
             }
         };