private void onRemoveServer(RemoveServer removeServer, ActorRef sender) {
LOG.debug("{}: onRemoveServer: {}, state: {}", raftContext.getId(), removeServer, currentOperationState);
boolean isSelf = removeServer.getServerId().equals(raftActor.getId());
- if(!isSelf && !raftContext.getPeerIds().contains(removeServer.getServerId())) {
+ if(isSelf && !raftContext.hasFollowers()) {
+ sender.tell(new RemoveServerReply(ServerChangeStatus.NOT_SUPPORTED, raftActor.getLeaderId()),
+ raftActor.getSelf());
+ } else if(!isSelf && !raftContext.getPeerIds().contains(removeServer.getServerId())) {
sender.tell(new RemoveServerReply(ServerChangeStatus.DOES_NOT_EXIST, raftActor.getLeaderId()),
raftActor.getSelf());
} else {
MessageCollectorActor.expectFirstMatching(leaderCollector, ServerRemoved.class);
}
+ @Test
+ public void testRemoveServerLeaderWithNoFollowers() {
+ TestActorRef<MockLeaderRaftActor> leaderActor = actorFactory.createTestActor(
+ MockLeaderRaftActor.props(Collections.<String, String>emptyMap(),
+ new MockRaftActorContext()).withDispatcher(Dispatchers.DefaultDispatcherId()),
+ actorFactory.generateActorId(LEADER_ID));
+
+ leaderActor.tell(new RemoveServer(LEADER_ID), testKit.getRef());
+ RemoveServerReply removeServerReply = testKit.expectMsgClass(JavaTestKit.duration("5 seconds"), RemoveServerReply.class);
+ assertEquals("getStatus", ServerChangeStatus.NOT_SUPPORTED, removeServerReply.getStatus());
+ }
+
private ServerInfo votingServer(String id) {
return new ServerInfo(id, true);
}