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%2FRaftActorRecoverySupportTest.java;h=4855f42931da658d3d6f7912edb930fd78498bf8;hb=f33beecf2a10955a9219757529ba3017079816cc;hp=828e3eb89e09c3a087576bf2e9e3e338bb93caa4;hpb=2faf656bf68dd3843fd59520b27a7ec2abbdcc68;p=controller.git diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorRecoverySupportTest.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorRecoverySupportTest.java index 828e3eb89e..4855f42931 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorRecoverySupportTest.java +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorRecoverySupportTest.java @@ -10,10 +10,8 @@ package org.opendaylight.controller.cluster.raft; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Mockito.doAnswer; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.never; @@ -24,17 +22,13 @@ import akka.persistence.RecoveryCompleted; import akka.persistence.SnapshotMetadata; import akka.persistence.SnapshotOffer; import com.google.common.collect.Sets; -import java.io.Serializable; +import com.google.common.util.concurrent.MoreExecutors; import java.util.Arrays; import java.util.Collections; -import java.util.List; -import org.apache.commons.lang3.SerializationUtils; -import org.hamcrest.Description; import org.junit.Before; import org.junit.Test; -import org.mockito.ArgumentMatcher; +import org.mockito.ArgumentMatchers; import org.mockito.InOrder; -import org.mockito.Matchers; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; @@ -88,7 +82,7 @@ public class RaftActorRecoverySupportTest { context = new RaftActorContextImpl(null, null, localId, new ElectionTermImpl(mockPersistentProvider, "test", LOG), -1, -1, Collections.emptyMap(), configParams, - mockPersistence, applyState -> { }, LOG); + mockPersistence, applyState -> { }, LOG, MoreExecutors.directExecutor()); support = new RaftActorRecoverySupport(context, mockCohort); @@ -97,11 +91,11 @@ public class RaftActorRecoverySupportTest { context.setReplicatedLog(ReplicatedLogImpl.newInstance(context)); } - private void sendMessageToSupport(Object message) { + private void sendMessageToSupport(final Object message) { sendMessageToSupport(message, false); } - private void sendMessageToSupport(Object message, boolean expComplete) { + private void sendMessageToSupport(final Object message, final boolean expComplete) { boolean complete = support.handleRecoveryMessage(message, mockPersistentProvider); assertEquals("complete", expComplete, complete); } @@ -208,52 +202,6 @@ public class RaftActorRecoverySupportTest { verify(mockCohort).applyRecoverySnapshot(snapshotState); } - @Deprecated - @Test - public void testOnSnapshotOfferWithPreCarbonSnapshot() { - - ReplicatedLogEntry unAppliedEntry1 = new SimpleReplicatedLogEntry(4, 1, - new MockRaftActorContext.MockPayload("4", 4)); - - ReplicatedLogEntry unAppliedEntry2 = new SimpleReplicatedLogEntry(5, 1, - new MockRaftActorContext.MockPayload("5", 5)); - - long lastAppliedDuringSnapshotCapture = 3; - long lastIndexDuringSnapshotCapture = 5; - long electionTerm = 2; - String electionVotedFor = "member-2"; - - List snapshotData = Arrays.asList(new MockPayload("1")); - final MockSnapshotState snapshotState = new MockSnapshotState(snapshotData); - - org.opendaylight.controller.cluster.raft.Snapshot snapshot = org.opendaylight.controller.cluster.raft.Snapshot - .create(SerializationUtils.serialize((Serializable) snapshotData), - Arrays.asList(unAppliedEntry1, unAppliedEntry2), lastIndexDuringSnapshotCapture, 1, - lastAppliedDuringSnapshotCapture, 1, electionTerm, electionVotedFor, null); - - SnapshotMetadata metadata = new SnapshotMetadata("test", 6, 12345); - SnapshotOffer snapshotOffer = new SnapshotOffer(metadata , snapshot); - - doAnswer(invocation -> new MockSnapshotState(SerializationUtils.deserialize( - invocation.getArgumentAt(0, byte[].class)))) - .when(mockCohort).deserializePreCarbonSnapshot(any(byte[].class)); - - sendMessageToSupport(snapshotOffer); - - assertEquals("Journal log size", 2, context.getReplicatedLog().size()); - assertEquals("Journal data size", 9, context.getReplicatedLog().dataSize()); - assertEquals("Last index", lastIndexDuringSnapshotCapture, context.getReplicatedLog().lastIndex()); - assertEquals("Last applied", lastAppliedDuringSnapshotCapture, context.getLastApplied()); - assertEquals("Commit index", lastAppliedDuringSnapshotCapture, context.getCommitIndex()); - assertEquals("Snapshot term", 1, context.getReplicatedLog().getSnapshotTerm()); - assertEquals("Snapshot index", lastAppliedDuringSnapshotCapture, context.getReplicatedLog().getSnapshotIndex()); - assertEquals("Election term", electionTerm, context.getTermInformation().getCurrentTerm()); - assertEquals("Election votedFor", electionVotedFor, context.getTermInformation().getVotedFor()); - assertFalse("Dynamic server configuration", context.isDynamicServerConfigurationInUse()); - - verify(mockCohort).applyRecoverySnapshot(snapshotState); - } - @Test public void testOnRecoveryCompletedWithRemainingBatch() { ReplicatedLog replicatedLog = context.getReplicatedLog(); @@ -311,7 +259,7 @@ public class RaftActorRecoverySupportTest { @Test public void testDataRecoveredWithPersistenceDisabled() { - doNothing().when(mockCohort).applyRecoverySnapshot(anyObject()); + doNothing().when(mockCohort).applyRecoverySnapshot(any()); doReturn(false).when(mockPersistence).isRecoveryApplicable(); doReturn(10L).when(mockPersistentProvider).getLastSequenceNumber(); @@ -342,7 +290,7 @@ public class RaftActorRecoverySupportTest { sendMessageToSupport(RecoveryCompleted.getInstance(), true); - verify(mockCohort, never()).applyRecoverySnapshot(anyObject()); + verify(mockCohort, never()).applyRecoverySnapshot(any()); verify(mockCohort, never()).getRestoreFromSnapshot(); verifyNoMoreInteractions(mockCohort); @@ -350,18 +298,8 @@ public class RaftActorRecoverySupportTest { } static UpdateElectionTerm updateElectionTerm(final long term, final String votedFor) { - return Matchers.argThat(new ArgumentMatcher() { - @Override - public boolean matches(Object argument) { - UpdateElectionTerm other = (UpdateElectionTerm) argument; - return term == other.getCurrentTerm() && votedFor.equals(other.getVotedFor()); - } - - @Override - public void describeTo(Description description) { - description.appendValue(new UpdateElectionTerm(term, votedFor)); - } - }); + return ArgumentMatchers.argThat( + other -> term == other.getCurrentTerm() && votedFor.equals(other.getVotedFor())); } @Test