@Test public void testHandleInstallSnapshotReplyWithInvalidChunkIndex() { logStart("testHandleInstallSnapshotReplyWithInvalidChunkIndex"); MockRaftActorContext actorContext = createActorContextWithFollower(); final int commitIndex = 3; final int snapshotIndex = 2; final int snapshotTerm = 1; final int currentTerm = 2; actorContext.setConfigParams(new DefaultConfigParamsImpl() { @Override public int getSnapshotChunkSize() { return 50; } }); actorContext.setCommitIndex(commitIndex); leader = new Leader(actorContext); leader.getFollower(FOLLOWER_ID).setMatchIndex(-1); leader.getFollower(FOLLOWER_ID).setNextIndex(0); Map<String, String> leadersSnapshot = new HashMap<>(); leadersSnapshot.put("1", "A"); leadersSnapshot.put("2", "B"); leadersSnapshot.put("3", "C"); actorContext.getReplicatedLog().setSnapshotIndex(snapshotIndex); actorContext.getReplicatedLog().setSnapshotTerm(snapshotTerm); actorContext.getTermInformation().update(currentTerm, leaderActor.path().toString()); ByteString bs = toByteString(leadersSnapshot); Snapshot snapshot = Snapshot.create(ByteState.of(bs.toByteArray()), Collections.<ReplicatedLogEntry>emptyList(), commitIndex, snapshotTerm, commitIndex, snapshotTerm, -1, null, null); Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS); leader.handleMessage(leaderActor, new SendInstallSnapshot(snapshot, ByteSource.wrap(bs.toByteArray()))); InstallSnapshot installSnapshot = MessageCollectorActor.expectFirstMatching(followerActor, InstallSnapshot.class); assertEquals(1, installSnapshot.getChunkIndex()); assertEquals(3, installSnapshot.getTotalChunks()); followerActor.underlyingActor().clear(); leader.handleMessage(followerActor, new InstallSnapshotReply(actorContext.getTermInformation().getCurrentTerm(), FOLLOWER_ID, -1, false)); Uninterruptibles.sleepUninterruptibly(actorContext.getConfigParams().getHeartBeatInterval().toMillis(), TimeUnit.MILLISECONDS); leader.handleMessage(leaderActor, SendHeartBeat.INSTANCE); installSnapshot = MessageCollectorActor.expectFirstMatching(followerActor, InstallSnapshot.class); assertEquals(1, installSnapshot.getChunkIndex()); assertEquals(3, installSnapshot.getTotalChunks()); }
@Override public RaftActorBehavior handleMessage(final ActorRef sender, final Object originalMessage) { requireNonNull(sender, "sender should not be null"); if (ISOLATED_LEADER_CHECK.equals(originalMessage)) { if (isLeaderIsolated()) { log.warn("{}: At least {} followers need to be active, Switching {} from Leader to IsolatedLeader", context.getId(), getMinIsolatedLeaderPeerCount(), getLeaderId()); return internalSwitchBehavior(new IsolatedLeader(context, this)); } else { return this; } } else { return super.handleMessage(sender, originalMessage); } }
Leader extends AbstractLeader { @Override public RaftActorBehavior handleMessage(final ActorRef sender, final Object originalMessage) { requireNonNull(sender, "sender should not be null"); if (ISOLATED_LEADER_CHECK.equals(originalMessage)) { if (isLeaderIsolated()) { log.warn("{}: At least {} followers need to be active, Switching {} from Leader to IsolatedLeader", context.getId(), getMinIsolatedLeaderPeerCount(), getLeaderId()); return internalSwitchBehavior(new IsolatedLeader(context, this)); } else { return this; } } else { return super.handleMessage(sender, originalMessage); } } }
Leader extends AbstractLeader { @Override public RaftActorBehavior handleMessage(final ActorRef sender, final Object originalMessage) { requireNonNull(sender, "sender should not be null"); if (ISOLATED_LEADER_CHECK.equals(originalMessage)) { if (isLeaderIsolated()) { log.warn("{}: At least {} followers need to be active, Switching {} from Leader to IsolatedLeader", context.getId(), getMinIsolatedLeaderPeerCount(), getLeaderId()); return internalSwitchBehavior(new IsolatedLeader(context, this)); } else { return this; } } else { return super.handleMessage(sender, originalMessage); } } Leader(final RaftActorContext context, @Nullable final AbstractLeader initializeFromLeader);  Leader(final RaftActorContext context); }
Leader extends AbstractLeader { @Override public RaftActorBehavior handleMessage(final ActorRef sender, final Object originalMessage) { requireNonNull(sender, "sender should not be null"); if (ISOLATED_LEADER_CHECK.equals(originalMessage)) { if (isLeaderIsolated()) { log.warn("{}: At least {} followers need to be active, Switching {} from Leader to IsolatedLeader", context.getId(), getMinIsolatedLeaderPeerCount(), getLeaderId()); return internalSwitchBehavior(new IsolatedLeader(context, this)); } else { return this; } } else { return super.handleMessage(sender, originalMessage); } } Leader(final RaftActorContext context, @Nullable final AbstractLeader initializeFromLeader);  Leader(final RaftActorContext context); @Override RaftActorBehavior handleMessage(final ActorRef sender, final Object originalMessage); void transferLeadership(@NonNull final RaftActorLeadershipTransferCohort leadershipTransferCohort); @Override void close(); }
Leader extends AbstractLeader { @Override public RaftActorBehavior handleMessage(final ActorRef sender, final Object originalMessage) { requireNonNull(sender, "sender should not be null"); if (ISOLATED_LEADER_CHECK.equals(originalMessage)) { if (isLeaderIsolated()) { log.warn("{}: At least {} followers need to be active, Switching {} from Leader to IsolatedLeader", context.getId(), getMinIsolatedLeaderPeerCount(), getLeaderId()); return internalSwitchBehavior(new IsolatedLeader(context, this)); } else { return this; } } else { return super.handleMessage(sender, originalMessage); } } Leader(final RaftActorContext context, @Nullable final AbstractLeader initializeFromLeader);  Leader(final RaftActorContext context); @Override RaftActorBehavior handleMessage(final ActorRef sender, final Object originalMessage); void transferLeadership(@NonNull final RaftActorLeadershipTransferCohort leadershipTransferCohort); @Override void close();  }