X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-akka-raft%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fraft%2FRaftActorContextImplTest.java;h=fabfc6c280468792da400318a8fe42b8c72c00d5;hp=8945de6bafcb16651768335f79bce74b50c180c9;hb=HEAD;hpb=f6d4d8759fcce4d35f38f5a5a056acf1d3e0b4b2 diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorContextImplTest.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorContextImplTest.java index 8945de6baf..fabfc6c280 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorContextImplTest.java +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorContextImplTest.java @@ -10,7 +10,7 @@ package org.opendaylight.controller.cluster.raft; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -19,13 +19,13 @@ import static org.mockito.Mockito.verify; import akka.actor.Props; import akka.testkit.TestActorRef; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Maps; -import java.util.Arrays; +import com.google.common.util.concurrent.MoreExecutors; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.junit.After; import org.junit.Test; +import org.opendaylight.controller.cluster.DataPersistenceProvider; import org.opendaylight.controller.cluster.NonPersistentDataProvider; import org.opendaylight.controller.cluster.raft.persisted.ServerConfigurationPayload; import org.opendaylight.controller.cluster.raft.persisted.ServerInfo; @@ -58,8 +58,8 @@ public class RaftActorContextImplTest extends AbstractActorTest { peerMap.put("peer2", null); DefaultConfigParamsImpl configParams = new DefaultConfigParamsImpl(); RaftActorContextImpl context = new RaftActorContextImpl(actor, actor.underlyingActor().getContext(), - "test", new ElectionTermImpl(new NonPersistentDataProvider(), "test", LOG), -1, -1, - peerMap, configParams, new NonPersistentDataProvider(), applyState -> { }, LOG); + "test", new ElectionTermImpl(createProvider(), "test", LOG), -1, -1, + peerMap, configParams, createProvider(), applyState -> { }, LOG, MoreExecutors.directExecutor()); assertEquals("getPeerAddress", "peerAddress1", context.getPeerAddress("peer1")); assertEquals("getPeerAddress", null, context.getPeerAddress("peer2")); @@ -82,9 +82,9 @@ public class RaftActorContextImplTest extends AbstractActorTest { public void testSetPeerAddress() { DefaultConfigParamsImpl configParams = new DefaultConfigParamsImpl(); RaftActorContextImpl context = new RaftActorContextImpl(actor, actor.underlyingActor().getContext(), - "test", new ElectionTermImpl(new NonPersistentDataProvider(), "test", LOG), -1, -1, - Maps.newHashMap(ImmutableMap.of("peer1", "peerAddress1")), configParams, - new NonPersistentDataProvider(), applyState -> { }, LOG); + "test", new ElectionTermImpl(createProvider(), "test", LOG), -1, -1, + Map.of("peer1", "peerAddress1"), configParams, + createProvider(), applyState -> { }, LOG, MoreExecutors.directExecutor()); context.setPeerAddress("peer1", "peerAddress1_1"); assertEquals("getPeerAddress", "peerAddress1_1", context.getPeerAddress("peer1")); @@ -96,35 +96,40 @@ public class RaftActorContextImplTest extends AbstractActorTest { @Test public void testUpdatePeerIds() { RaftActorContextImpl context = new RaftActorContextImpl(actor, actor.underlyingActor().getContext(), - "self", new ElectionTermImpl(new NonPersistentDataProvider(), "test", LOG), -1, -1, - Maps.newHashMap(ImmutableMap.of("peer1", "peerAddress1")), - new DefaultConfigParamsImpl(), new NonPersistentDataProvider(), applyState -> { }, LOG); + "self", new ElectionTermImpl(createProvider(), "test", LOG), -1, -1, + Map.of("peer1", "peerAddress1"), + new DefaultConfigParamsImpl(), createProvider(), applyState -> { }, LOG, + MoreExecutors.directExecutor()); - context.updatePeerIds(new ServerConfigurationPayload(Arrays.asList(new ServerInfo("self", false), + context.updatePeerIds(new ServerConfigurationPayload(List.of(new ServerInfo("self", false), new ServerInfo("peer2", true), new ServerInfo("peer3", false)))); verifyPeerInfo(context, "peer1", null); verifyPeerInfo(context, "peer2", true); verifyPeerInfo(context, "peer3", false); assertEquals("isVotingMember", false, context.isVotingMember()); - context.updatePeerIds(new ServerConfigurationPayload(Arrays.asList(new ServerInfo("self", true), + context.updatePeerIds(new ServerConfigurationPayload(List.of(new ServerInfo("self", true), new ServerInfo("peer2", true), new ServerInfo("peer3", true)))); verifyPeerInfo(context, "peer2", true); verifyPeerInfo(context, "peer3", true); assertEquals("isVotingMember", true, context.isVotingMember()); - context.updatePeerIds(new ServerConfigurationPayload(Arrays.asList(new ServerInfo("peer2", true), + context.updatePeerIds(new ServerConfigurationPayload(List.of(new ServerInfo("peer2", true), new ServerInfo("peer3", true)))); verifyPeerInfo(context, "peer2", true); verifyPeerInfo(context, "peer3", true); assertEquals("isVotingMember", false, context.isVotingMember()); } - private static void verifyPeerInfo(RaftActorContextImpl context, String peerId, Boolean voting) { + private static DataPersistenceProvider createProvider() { + return new NonPersistentDataProvider(Runnable::run); + } + + private static void verifyPeerInfo(final RaftActorContextImpl context, final String peerId, final Boolean voting) { PeerInfo peerInfo = context.getPeerInfo(peerId); if (voting != null) { assertNotNull("Expected peer " + peerId, peerInfo); - assertEquals("getVotingState for " + peerId, voting.booleanValue() + assertEquals("getVotingState for " + peerId, voting ? VotingState.VOTING : VotingState.NON_VOTING, peerInfo.getVotingState()); } else { assertNull("Unexpected peer " + peerId, peerInfo);