use of org.apache.ratis.statemachine.RaftSnapshotBaseTest in project incubator-ratis by apache.
the class InstallSnapshotNotificationTests method testRestartFollower.
private void testRestartFollower(CLUSTER cluster) throws Exception {
leaderSnapshotInfoRef.set(null);
int i = 0;
final RaftServer.Division leader = RaftTestUtil.waitForLeader(cluster);
final RaftPeerId leaderId = leader.getId();
try (final RaftClient client = cluster.createClient(leaderId)) {
for (; i < SNAPSHOT_TRIGGER_THRESHOLD * 2 - 1; i++) {
final RaftClientReply reply = client.io().send(new RaftTestUtil.SimpleMessage("m" + i));
Assert.assertTrue(reply.isSuccess());
}
}
// wait for the snapshot to be done
final long oldLeaderNextIndex = leader.getRaftLog().getNextIndex();
{
LOG.info("{}: oldLeaderNextIndex = {}", leaderId, oldLeaderNextIndex);
final List<File> snapshotFiles = RaftSnapshotBaseTest.getSnapshotFiles(cluster, oldLeaderNextIndex - SNAPSHOT_TRIGGER_THRESHOLD, oldLeaderNextIndex);
JavaUtils.attemptRepeatedly(() -> {
Assert.assertTrue(snapshotFiles.stream().anyMatch(RaftSnapshotBaseTest::exists));
return null;
}, 10, ONE_SECOND, "snapshotFile.exist", LOG);
}
final RaftPeerId followerId = cluster.getFollowers().get(0).getId();
cluster.killServer(followerId);
// generate some more traffic
try (final RaftClient client = cluster.createClient(leader.getId())) {
Assert.assertTrue(client.io().send(new RaftTestUtil.SimpleMessage("m" + i)).isSuccess());
}
FIVE_SECONDS.sleep();
cluster.restartServer(followerId, false);
final RaftServer.Division follower = cluster.getDivision(followerId);
JavaUtils.attempt(() -> {
final long newLeaderNextIndex = leader.getRaftLog().getNextIndex();
LOG.info("{}: newLeaderNextIndex = {}", leaderId, newLeaderNextIndex);
Assert.assertTrue(newLeaderNextIndex > oldLeaderNextIndex);
Assert.assertEquals(newLeaderNextIndex, follower.getRaftLog().getNextIndex());
}, 10, ONE_SECOND, "followerNextIndex", LOG);
}
Aggregations