Search in sources :

Example 1 with BootstrapOptions

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());
}
Also used : Endpoint(org.apache.ignite.raft.jraft.util.Endpoint) RaftGroupService(org.apache.ignite.raft.jraft.RaftGroupService) Node(org.apache.ignite.raft.jraft.Node) BootstrapOptions(org.apache.ignite.raft.jraft.option.BootstrapOptions) NodeOptions(org.apache.ignite.raft.jraft.option.NodeOptions) Endpoint(org.apache.ignite.raft.jraft.util.Endpoint) PeerId(org.apache.ignite.raft.jraft.entity.PeerId) Test(org.junit.jupiter.api.Test)

Example 2 with BootstrapOptions

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());
}
Also used : Endpoint(org.apache.ignite.raft.jraft.util.Endpoint) RaftGroupService(org.apache.ignite.raft.jraft.RaftGroupService) Node(org.apache.ignite.raft.jraft.Node) BootstrapOptions(org.apache.ignite.raft.jraft.option.BootstrapOptions) NodeOptions(org.apache.ignite.raft.jraft.option.NodeOptions) PeerId(org.apache.ignite.raft.jraft.entity.PeerId) Test(org.junit.jupiter.api.Test)

Aggregations

Node (org.apache.ignite.raft.jraft.Node)2 RaftGroupService (org.apache.ignite.raft.jraft.RaftGroupService)2 PeerId (org.apache.ignite.raft.jraft.entity.PeerId)2 BootstrapOptions (org.apache.ignite.raft.jraft.option.BootstrapOptions)2 NodeOptions (org.apache.ignite.raft.jraft.option.NodeOptions)2 Endpoint (org.apache.ignite.raft.jraft.util.Endpoint)2 Test (org.junit.jupiter.api.Test)2