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%2FLeadershipTransferIntegrationTest.java;h=e99215ddbaa8cee74d457b2ef1f55e098653a8f4;hb=3859df9beca8f13f1ff2b2744ed3470a1715bec3;hp=7ed45956c17f77f16cc6f60493de4097680d31c1;hpb=0c05dff15e4f36c5ecbd26e82309de21f67c8cd5;p=controller.git diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/LeadershipTransferIntegrationTest.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/LeadershipTransferIntegrationTest.java index 7ed45956c1..e99215ddba 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/LeadershipTransferIntegrationTest.java +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/LeadershipTransferIntegrationTest.java @@ -14,11 +14,12 @@ import static org.opendaylight.controller.cluster.raft.utils.MessageCollectorAct import static org.opendaylight.controller.cluster.raft.utils.MessageCollectorActor.expectMatching; import akka.actor.ActorRef; -import akka.actor.Props; import akka.actor.Status; import akka.pattern.Patterns; import akka.testkit.TestActorRef; +import akka.testkit.javadsl.TestKit; import com.google.common.collect.ImmutableMap; +import java.util.Arrays; import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -31,6 +32,10 @@ import org.opendaylight.controller.cluster.raft.client.messages.Shutdown; import org.opendaylight.controller.cluster.raft.messages.AppendEntries; import org.opendaylight.controller.cluster.raft.messages.AppendEntriesReply; import org.opendaylight.controller.cluster.raft.messages.RequestLeadership; +import org.opendaylight.controller.cluster.raft.persisted.EmptyState; +import org.opendaylight.controller.cluster.raft.persisted.ServerInfo; +import org.opendaylight.controller.cluster.raft.persisted.Snapshot; +import org.opendaylight.controller.cluster.raft.utils.InMemorySnapshotStore; import org.opendaylight.controller.cluster.raft.utils.MessageCollectorActor; import scala.concurrent.Await; import scala.concurrent.Future; @@ -44,10 +49,10 @@ import scala.concurrent.duration.FiniteDuration; public class LeadershipTransferIntegrationTest extends AbstractRaftActorIntegrationTest { private final String follower3Id = factory.generateActorId("follower"); - private TestActorRef leaderNotifierActor; - private TestActorRef follower1NotifierActor; - private TestActorRef follower2NotifierActor; - private TestActorRef follower3NotifierActor; + private ActorRef leaderNotifierActor; + private ActorRef follower1NotifierActor; + private ActorRef follower2NotifierActor; + private ActorRef follower3NotifierActor; private TestActorRef follower3Actor; private ActorRef follower3CollectorActor; private ActorRef requestLeadershipResultCollectorActor; @@ -67,7 +72,7 @@ public class LeadershipTransferIntegrationTest extends AbstractRaftActorIntegrat testLog.info("testLeaderTransferOnShutDown ending"); } - private void sendShutDown(ActorRef actor) throws Exception { + private void sendShutDown(final ActorRef actor) throws Exception { testLog.info("sendShutDown for {} starting", actor.path()); FiniteDuration duration = FiniteDuration.create(5, TimeUnit.SECONDS); @@ -138,21 +143,31 @@ public class LeadershipTransferIntegrationTest extends AbstractRaftActorIntegrat private void createRaftActors() { testLog.info("createRaftActors starting"); - follower1NotifierActor = factory.createTestActor(Props.create(MessageCollectorActor.class), + final Snapshot snapshot = Snapshot.create(EmptyState.INSTANCE, Collections.emptyList(), -1, -1, -1, -1, + 1, null, new org.opendaylight.controller.cluster.raft.persisted.ServerConfigurationPayload( + Arrays.asList(new ServerInfo(leaderId, true), new ServerInfo(follower1Id, true), + new ServerInfo(follower2Id, true), new ServerInfo(follower3Id, false)))); + + InMemorySnapshotStore.addSnapshot(leaderId, snapshot); + InMemorySnapshotStore.addSnapshot(follower1Id, snapshot); + InMemorySnapshotStore.addSnapshot(follower2Id, snapshot); + InMemorySnapshotStore.addSnapshot(follower3Id, snapshot); + + follower1NotifierActor = factory.createActor(MessageCollectorActor.props(), factory.generateActorId(follower1Id + "-notifier")); follower1Actor = newTestRaftActor(follower1Id, TestRaftActor.newBuilder().peerAddresses( ImmutableMap.of(leaderId, testActorPath(leaderId), follower2Id, testActorPath(follower2Id), follower3Id, testActorPath(follower3Id))) .config(newFollowerConfigParams()).roleChangeNotifier(follower1NotifierActor)); - follower2NotifierActor = factory.createTestActor(Props.create(MessageCollectorActor.class), + follower2NotifierActor = factory.createActor(MessageCollectorActor.props(), factory.generateActorId(follower2Id + "-notifier")); follower2Actor = newTestRaftActor(follower2Id,TestRaftActor.newBuilder().peerAddresses( ImmutableMap.of(leaderId, testActorPath(leaderId), follower1Id, follower1Actor.path().toString(), follower3Id, testActorPath(follower3Id))) .config(newFollowerConfigParams()).roleChangeNotifier(follower2NotifierActor)); - follower3NotifierActor = factory.createTestActor(Props.create(MessageCollectorActor.class), + follower3NotifierActor = factory.createActor(MessageCollectorActor.props(), factory.generateActorId(follower3Id + "-notifier")); follower3Actor = newTestRaftActor(follower3Id,TestRaftActor.newBuilder().peerAddresses( ImmutableMap.of(leaderId, testActorPath(leaderId), follower1Id, follower1Actor.path().toString(), @@ -166,7 +181,7 @@ public class LeadershipTransferIntegrationTest extends AbstractRaftActorIntegrat leaderConfigParams = newLeaderConfigParams(); leaderConfigParams.setElectionTimeoutFactor(3); - leaderNotifierActor = factory.createTestActor(Props.create(MessageCollectorActor.class), + leaderNotifierActor = factory.createActor(MessageCollectorActor.props(), factory.generateActorId(leaderId + "-notifier")); leaderActor = newTestRaftActor(leaderId, TestRaftActor.newBuilder().peerAddresses(peerAddresses) .config(leaderConfigParams).roleChangeNotifier(leaderNotifierActor)); @@ -177,19 +192,18 @@ public class LeadershipTransferIntegrationTest extends AbstractRaftActorIntegrat leaderCollectorActor = leaderActor.underlyingActor().collectorActor(); leaderContext = leaderActor.underlyingActor().getRaftActorContext(); - leaderContext.getPeerInfo(follower3Id).setVotingState(VotingState.NON_VOTING); waitUntilLeader(leaderActor); testLog.info("createRaftActors starting"); } - private static void verifyRaftState(ActorRef raftActor, final RaftState expState) { + private static void verifyRaftState(final ActorRef raftActor, final RaftState expState) { verifyRaftState(raftActor, rs -> assertEquals("getRaftState", expState.toString(), rs.getRaftState())); } - private void verifyLeaderStateChangedMessages(TestActorRef notifierActor, - String... expLeaderIds) { + private static void verifyLeaderStateChangedMessages(final ActorRef notifierActor, + final String... expLeaderIds) { List leaderStateChanges = expectMatching(notifierActor, LeaderStateChanged.class, expLeaderIds.length); @@ -283,6 +297,7 @@ public class LeadershipTransferIntegrationTest extends AbstractRaftActorIntegrat testLog.info("testRequestLeadershipTransferToFollower2WithFollower2Lagging ending"); } + @Test public void testRequestLeadershipTransferToFollower2WithFollower2Shutdown() throws Exception { testLog.info("testRequestLeadershipTransferToFollower2WithFollower2Shutdown starting"); @@ -302,4 +317,24 @@ public class LeadershipTransferIntegrationTest extends AbstractRaftActorIntegrat testLog.info("testRequestLeadershipTransferToFollower2WithFollower2Shutdown ending"); } + + @Test + public void testRequestLeadershipTransferToFollower2WithOtherFollowersDown() { + testLog.info("testRequestLeadershipTransferToFollower2WithOtherFollowersDown starting"); + + createRaftActors(); + createRequestLeadershipResultCollectorActor(); + + factory.killActor(follower1Actor, new TestKit(getSystem())); + factory.killActor(follower3Actor, new TestKit(getSystem())); + + sendFollower2RequestLeadershipTransferToLeader(); + + expectFirstMatching(requestLeadershipResultCollectorActor, Status.Success.class); + + verifyRaftState(follower2Actor, RaftState.Leader); + verifyRaftState(leaderActor, RaftState.Follower); + + testLog.info("testRequestLeadershipTransferToFollower2WithOtherFollowersDown ending"); + } }