use of com.alipay.sofa.jraft.storage.snapshot.ThroughputSnapshotThrottle 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();
}
use of com.alipay.sofa.jraft.storage.snapshot.ThroughputSnapshotThrottle in project sofa-jraft by sofastack.
the class NodeTest method testInstallSnapshotWithThrottle.
@Test
public void testInstallSnapshotWithThrottle() throws Exception {
final List<PeerId> peers = TestUtils.generatePeers(3);
final TestCluster cluster = new TestCluster("unitest", this.dataPath, peers);
for (final PeerId peer : peers) {
assertTrue(cluster.start(peer.getEndpoint(), false, 200, false, new ThroughputSnapshotThrottle(1024, 1)));
}
cluster.waitLeader();
// get leader
final Node leader = cluster.getLeader();
assertNotNull(leader);
// apply tasks to leader
this.sendTestTaskAndWait(leader);
cluster.ensureSame();
// stop follower1
final List<Node> followers = cluster.getFollowers();
assertEquals(2, followers.size());
final Endpoint followerAddr = followers.get(0).getNodeId().getPeerId().getEndpoint();
assertTrue(cluster.stop(followerAddr));
cluster.waitLeader();
// apply something more
this.sendTestTaskAndWait(leader, 10, RaftError.SUCCESS);
Thread.sleep(1000);
// trigger leader snapshot
triggerLeaderSnapshot(cluster, leader);
// apply something more
this.sendTestTaskAndWait(leader, 20, RaftError.SUCCESS);
// trigger leader snapshot
triggerLeaderSnapshot(cluster, leader, 2);
// wait leader to compact logs
Thread.sleep(1000);
// restart follower.
cluster.clean(followerAddr);
assertTrue(cluster.start(followerAddr, true, 300, false, new ThroughputSnapshotThrottle(1024, 1)));
Thread.sleep(2000);
cluster.ensureSame();
assertEquals(3, cluster.getFsms().size());
for (final MockStateMachine fsm : cluster.getFsms()) {
assertEquals(30, fsm.getLogs().size());
}
cluster.stopAll();
}
Aggregations