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%2FRaftActorContextImplTest.java;h=2dd1c211af37d42e2c251d81db5cc329e1d9b153;hb=06931155aa9709d40784f98bd5e68a5fd854e0d5;hp=e957551dadfcbb8ad66ca1f826eaad14dd55273d;hpb=9d5ec5cdd146a56bc03e35b6718e9492a5c8410a;p=controller.git 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 e957551dad..2dd1c211af 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 @@ -16,6 +16,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; + import akka.actor.Props; import akka.testkit.TestActorRef; import com.google.common.collect.ImmutableMap; @@ -25,6 +26,7 @@ import java.util.HashMap; 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; @@ -43,7 +45,7 @@ public class RaftActorContextImplTest extends AbstractActorTest { private final TestActorRef actor = actorFactory.createTestActor( Props.create(DoNothingActor.class), actorFactory.generateActorId("actor")); - private final Logger log = LoggerFactory.getLogger(RaftActorContextImplTest.class); + private static final Logger LOG = LoggerFactory.getLogger(RaftActorContextImplTest.class); @After public void tearDown() { @@ -57,8 +59,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(), log); + "test", new ElectionTermImpl(createProvider(), "test", LOG), -1, -1, + peerMap, configParams, createProvider(), applyState -> { }, LOG); assertEquals("getPeerAddress", "peerAddress1", context.getPeerAddress("peer1")); assertEquals("getPeerAddress", null, context.getPeerAddress("peer2")); @@ -81,9 +83,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, + "test", new ElectionTermImpl(createProvider(), "test", LOG), -1, -1, Maps.newHashMap(ImmutableMap.of("peer1", "peerAddress1")), configParams, - new NonPersistentDataProvider(), log); + createProvider(), applyState -> { }, LOG); context.setPeerAddress("peer1", "peerAddress1_1"); assertEquals("getPeerAddress", "peerAddress1_1", context.getPeerAddress("peer1")); @@ -95,9 +97,9 @@ 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, + "self", new ElectionTermImpl(createProvider(), "test", LOG), -1, -1, Maps.newHashMap(ImmutableMap.of("peer1", "peerAddress1")), - new DefaultConfigParamsImpl(), new NonPersistentDataProvider(), log); + new DefaultConfigParamsImpl(), createProvider(), applyState -> { }, LOG); context.updatePeerIds(new ServerConfigurationPayload(Arrays.asList(new ServerInfo("self", false), new ServerInfo("peer2", true), new ServerInfo("peer3", false)))); @@ -119,12 +121,16 @@ public class RaftActorContextImplTest extends AbstractActorTest { 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) { + if (voting != null) { assertNotNull("Expected peer " + peerId, peerInfo); - assertEquals("getVotingState for " + peerId, voting.booleanValue() ? VotingState.VOTING : VotingState.NON_VOTING, - peerInfo.getVotingState()); + assertEquals("getVotingState for " + peerId, voting.booleanValue() + ? VotingState.VOTING : VotingState.NON_VOTING, peerInfo.getVotingState()); } else { assertNull("Unexpected peer " + peerId, peerInfo); }