TestActorRef<MockRaftActor> noLeaderActor = actorFactory.createTestActor(
MockRaftActor.props(LEADER_ID, ImmutableMap.<String,String>of(FOLLOWER_ID, followerActor.path().toString()),
- Optional.<ConfigParams>of(configParams), NO_PERSISTENCE).withDispatcher(Dispatchers.DefaultDispatcherId()),
+ configParams, NO_PERSISTENCE).withDispatcher(Dispatchers.DefaultDispatcherId()),
actorFactory.generateActorId(LEADER_ID));
noLeaderActor.underlyingActor().waitForInitializeBehaviorComplete();
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();
TestActorRef<MockRaftActor> followerRaftActor = actorFactory.createTestActor(
MockRaftActor.props(FOLLOWER_ID, ImmutableMap.<String,String>of(LEADER_ID, leaderActor.path().toString()),
- Optional.<ConfigParams>of(configParams), NO_PERSISTENCE).withDispatcher(Dispatchers.DefaultDispatcherId()),
+ configParams, NO_PERSISTENCE).withDispatcher(Dispatchers.DefaultDispatcherId()),
actorFactory.generateActorId(FOLLOWER_ID));
followerRaftActor.underlyingActor().waitForInitializeBehaviorComplete();
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 {
AbstractMockRaftActor(String id, Map<String, String> peerAddresses, Optional<ConfigParams> config,
DataPersistenceProvider dataPersistenceProvider, TestActorRef<MessageCollectorActor> collectorActor) {
- super(id, peerAddresses, config, dataPersistenceProvider);
+ super(builder().id(id).peerAddresses(peerAddresses).config(config.get()).
+ dataPersistenceProvider(dataPersistenceProvider));
this.collectorActor = collectorActor;
}