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=fdc72ed573e2350e18d34824e3d28d99c3e1d72a;hb=24a5bafd22b83c4d838b7c3fc5225934fe969561;hp=f2903983e930490a37478fda36e2f64b2fa70a42;hpb=8882e6077db69d22bcc57fcf12dd4a02a81a4967;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 f2903983e9..fdc72ed573 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 @@ -8,6 +8,8 @@ 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.Mockito.doReturn; import static org.mockito.Mockito.mock; @@ -18,11 +20,13 @@ 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 java.util.HashMap; import java.util.Map; import org.junit.After; import org.junit.Test; import org.opendaylight.controller.cluster.NonPersistentDataProvider; +import org.opendaylight.controller.cluster.raft.ServerConfigurationPayload.ServerInfo; import org.opendaylight.controller.cluster.raft.utils.DoNothingActor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -86,4 +90,42 @@ public class RaftActorContextImplTest extends AbstractActorTest { context.setPeerAddress("peer2", "peerAddress2"); assertEquals("getPeerAddress", null, context.getPeerAddress("peer2")); } + + @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(), log); + + context.updatePeerIds(new ServerConfigurationPayload(Arrays.asList(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), + 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), + 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) { + PeerInfo peerInfo = context.getPeerInfo(peerId); + if(voting != null) { + assertNotNull("Expected peer " + peerId, peerInfo); + assertEquals("getVotingState for " + peerId, voting.booleanValue() ? VotingState.VOTING : VotingState.NON_VOTING, + peerInfo.getVotingState()); + } else { + assertNull("Unexpected peer " + peerId, peerInfo); + } + } }