use of org.apache.ignite.raft.jraft.option.BootstrapOptions in project ignite-3 by apache.
the class ItNodeTest method testBootStrapWithSnapshot.
@Test
public void testBootStrapWithSnapshot() throws Exception {
Endpoint addr = new Endpoint("127.0.0.1", 5006);
MockStateMachine fsm = new MockStateMachine(addr);
for (char ch = 'a'; ch <= 'z'; ch++) fsm.getLogs().add(ByteBuffer.wrap(new byte[] { (byte) ch }));
BootstrapOptions opts = new BootstrapOptions();
opts.setServiceFactory(new DefaultJRaftServiceFactory());
opts.setLastLogIndex(fsm.getLogs().size());
opts.setRaftMetaUri(dataPath + File.separator + "meta");
opts.setLogUri(dataPath + File.separator + "log");
opts.setSnapshotUri(dataPath + File.separator + "snapshot");
opts.setGroupConf(JRaftUtils.getConfiguration("127.0.0.1:5006"));
opts.setFsm(fsm);
NodeOptions nodeOpts = createNodeOptions();
opts.setNodeOptions(nodeOpts);
assertTrue(JRaftUtils.bootstrap(opts));
nodeOpts.setRaftMetaUri(dataPath + File.separator + "meta");
nodeOpts.setLogUri(dataPath + File.separator + "log");
nodeOpts.setSnapshotUri(dataPath + File.separator + "snapshot");
nodeOpts.setFsm(fsm);
RaftGroupService service = createService("test", new PeerId(addr, 0), nodeOpts);
Node node = service.start();
assertEquals(26, fsm.getLogs().size());
for (int i = 0; i < 26; i++) assertEquals('a' + i, fsm.getLogs().get(i).get());
// Group configuration will be restored from snapshot meta.
while (!node.isLeader()) Thread.sleep(20);
sendTestTaskAndWait(node);
assertEquals(36, fsm.getLogs().size());
}
use of org.apache.ignite.raft.jraft.option.BootstrapOptions in project ignite-3 by apache.
the class ItNodeTest method testBootStrapWithoutSnapshot.
@Test
public void testBootStrapWithoutSnapshot() throws Exception {
Endpoint addr = new Endpoint("127.0.0.1", 5006);
MockStateMachine fsm = new MockStateMachine(addr);
BootstrapOptions opts = new BootstrapOptions();
opts.setServiceFactory(new DefaultJRaftServiceFactory());
opts.setLastLogIndex(0);
opts.setRaftMetaUri(dataPath + File.separator + "meta");
opts.setLogUri(dataPath + File.separator + "log");
opts.setSnapshotUri(dataPath + File.separator + "snapshot");
opts.setGroupConf(JRaftUtils.getConfiguration("127.0.0.1:5006"));
opts.setFsm(fsm);
NodeOptions nodeOpts = createNodeOptions();
opts.setNodeOptions(nodeOpts);
assertTrue(JRaftUtils.bootstrap(opts));
nodeOpts.setRaftMetaUri(dataPath + File.separator + "meta");
nodeOpts.setLogUri(dataPath + File.separator + "log");
nodeOpts.setSnapshotUri(dataPath + File.separator + "snapshot");
nodeOpts.setFsm(fsm);
RaftGroupService service = createService("test", new PeerId(addr, 0), nodeOpts);
Node node = service.start();
while (!node.isLeader()) Thread.sleep(20);
sendTestTaskAndWait(node);
assertEquals(10, fsm.getLogs().size());
}
Aggregations