use of com.alipay.sofa.jraft.storage.SnapshotThrottle in project sofa-jraft by sofastack.
the class NodeTest method testInstallLargeSnapshotWithThrottle.
@Test
public void testInstallLargeSnapshotWithThrottle() throws Exception {
final List<PeerId> peers = TestUtils.generatePeers(4);
final TestCluster cluster = new TestCluster("unitest", this.dataPath, peers.subList(0, 3));
for (int i = 0; i < peers.size() - 1; i++) {
final PeerId peer = peers.get(i);
final boolean started = cluster.start(peer.getEndpoint(), false, 200, false);
assertTrue(started);
}
cluster.waitLeader();
// get leader
final Node leader = cluster.getLeader();
assertNotNull(leader);
// apply tasks to leader
sendTestTaskAndWait(leader, 0, RaftError.SUCCESS);
cluster.ensureSame();
// apply something more
for (int i = 1; i < 100; i++) {
sendTestTaskAndWait(leader, i * 10, RaftError.SUCCESS);
}
Thread.sleep(1000);
// trigger leader snapshot
triggerLeaderSnapshot(cluster, leader);
// apply something more
for (int i = 100; i < 200; i++) {
sendTestTaskAndWait(leader, i * 10, RaftError.SUCCESS);
}
// trigger leader snapshot
triggerLeaderSnapshot(cluster, leader, 2);
// wait leader to compact logs
Thread.sleep(1000);
// add follower
final PeerId newPeer = peers.get(3);
final SnapshotThrottle snapshotThrottle = new ThroughputSnapshotThrottle(128, 1);
final boolean started = cluster.start(newPeer.getEndpoint(), true, 300, false, snapshotThrottle);
assertTrue(started);
final CountDownLatch latch = new CountDownLatch(1);
leader.addPeer(newPeer, status -> {
assertTrue(status.toString(), status.isOk());
latch.countDown();
});
waitLatch(latch);
cluster.ensureSame();
assertEquals(4, cluster.getFsms().size());
for (final MockStateMachine fsm : cluster.getFsms()) {
assertEquals(2000, fsm.getLogs().size());
}
cluster.stopAll();
}
Aggregations