Bug 2187: AddServer: check if already exists
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / test / java / org / opendaylight / controller / cluster / raft / RaftActorServerConfigurationSupportTest.java
index 3e04e4c1bb396000f3010b507cea6aecc33610c1..16acb410fb169702ee82cc7908f3e0b61abc5eb2 100644 (file)
@@ -600,6 +600,21 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest {
                 votingServer(NEW_SERVER_ID));
     }
 
+    @Test
+    public void testAddServerWithExistingServer() {
+        RaftActorContext initialActorContext = new MockRaftActorContext();
+
+        TestActorRef<MockLeaderRaftActor> leaderActor = actorFactory.createTestActor(
+                MockLeaderRaftActor.props(ImmutableMap.of(FOLLOWER_ID, followerActor.path().toString()),
+                        initialActorContext).withDispatcher(Dispatchers.DefaultDispatcherId()),
+                actorFactory.generateActorId(LEADER_ID));
+
+        leaderActor.tell(new AddServer(FOLLOWER_ID, followerActor.path().toString(), true), testKit.getRef());
+
+        AddServerReply addServerReply = testKit.expectMsgClass(JavaTestKit.duration("5 seconds"), AddServerReply.class);
+        assertEquals("getStatus", ServerChangeStatus.ALREADY_EXISTS, addServerReply.getStatus());
+    }
+
     @Test
     public void testAddServerForwardedToLeader() {
         DefaultConfigParamsImpl configParams = new DefaultConfigParamsImpl();
@@ -666,14 +681,8 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest {
         configParams.setElectionTimeoutFactor(100000);
         ElectionTermImpl termInfo = new ElectionTermImpl(NO_PERSISTENCE, id, LOG);
         termInfo.update(1, LEADER_ID);
-        RaftActorContext followerActorContext = new RaftActorContextImpl(actor, actor.underlyingActor().getContext(),
-                id, termInfo, -1, -1,
-                ImmutableMap.of(LEADER_ID, ""), configParams, NO_PERSISTENCE, LOG);
-        followerActorContext.setCommitIndex(-1);
-        followerActorContext.setLastApplied(-1);
-        followerActorContext.setReplicatedLog(new MockRaftActorContext.MockReplicatedLogBuilder().build());
-
-        return followerActorContext;
+        return new RaftActorContextImpl(actor, actor.underlyingActor().getContext(),
+                id, termInfo, -1, -1, ImmutableMap.of(LEADER_ID, ""), configParams, NO_PERSISTENCE, LOG);
     }
 
     static abstract class AbstractMockRaftActor extends MockRaftActor {