use of com.alipay.sofa.jraft.option.BootstrapOptions in project sofa-jraft by sofastack.
the class NodeTest method testBootStrapWithSnapshot.
@Test
public void testBootStrapWithSnapshot() throws Exception {
final Endpoint addr = JRaftUtils.getEndPoint("127.0.0.1:5006");
final MockStateMachine fsm = new MockStateMachine(addr);
for (char ch = 'a'; ch <= 'z'; ch++) {
fsm.getLogs().add(ByteBuffer.wrap(new byte[] { (byte) ch }));
}
final BootstrapOptions opts = new BootstrapOptions();
opts.setLastLogIndex(fsm.getLogs().size());
opts.setRaftMetaUri(this.dataPath + File.separator + "meta");
opts.setLogUri(this.dataPath + File.separator + "log");
opts.setSnapshotUri(this.dataPath + File.separator + "snapshot");
opts.setGroupConf(JRaftUtils.getConfiguration("127.0.0.1:5006"));
opts.setFsm(fsm);
NodeManager.getInstance().addAddress(addr);
assertTrue(JRaftUtils.bootstrap(opts));
final NodeOptions nodeOpts = createNodeOptionsWithSharedTimer();
nodeOpts.setRaftMetaUri(this.dataPath + File.separator + "meta");
nodeOpts.setLogUri(this.dataPath + File.separator + "log");
nodeOpts.setSnapshotUri(this.dataPath + File.separator + "snapshot");
nodeOpts.setFsm(fsm);
final NodeImpl node = new NodeImpl("test", new PeerId(addr, 0));
assertTrue(node.init(nodeOpts));
assertEquals(26, fsm.getLogs().size());
for (int i = 0; i < 26; i++) {
assertEquals('a' + i, fsm.getLogs().get(i).get());
}
while (!node.isLeader()) {
Thread.sleep(20);
}
this.sendTestTaskAndWait(node);
assertEquals(36, fsm.getLogs().size());
node.shutdown();
node.join();
}
use of com.alipay.sofa.jraft.option.BootstrapOptions in project sofa-jraft by sofastack.
the class NodeTest method testBootStrapWithoutSnapshot.
@Test
public void testBootStrapWithoutSnapshot() throws Exception {
final Endpoint addr = JRaftUtils.getEndPoint("127.0.0.1:5006");
final MockStateMachine fsm = new MockStateMachine(addr);
final BootstrapOptions opts = new BootstrapOptions();
opts.setLastLogIndex(0);
opts.setRaftMetaUri(this.dataPath + File.separator + "meta");
opts.setLogUri(this.dataPath + File.separator + "log");
opts.setSnapshotUri(this.dataPath + File.separator + "snapshot");
opts.setGroupConf(JRaftUtils.getConfiguration("127.0.0.1:5006"));
opts.setFsm(fsm);
NodeManager.getInstance().addAddress(addr);
assertTrue(JRaftUtils.bootstrap(opts));
final NodeOptions nodeOpts = createNodeOptionsWithSharedTimer();
nodeOpts.setRaftMetaUri(this.dataPath + File.separator + "meta");
nodeOpts.setLogUri(this.dataPath + File.separator + "log");
nodeOpts.setSnapshotUri(this.dataPath + File.separator + "snapshot");
nodeOpts.setFsm(fsm);
final NodeImpl node = new NodeImpl("test", new PeerId(addr, 0));
assertTrue(node.init(nodeOpts));
while (!node.isLeader()) {
Thread.sleep(20);
}
this.sendTestTaskAndWait(node);
assertEquals(10, fsm.getLogs().size());
node.shutdown();
node.join();
}
Aggregations