Search in sources :

Example 6 with NodeOptions

use of org.apache.ignite.raft.jraft.option.NodeOptions in project ignite-3 by apache.

the class BaseNodeRequestProcessorTest method mockNode.

protected PeerId mockNode() {
    Mockito.when(node.getGroupId()).thenReturn(this.groupId);
    final PeerId peerId = new PeerId();
    peerId.parse(this.peerIdStr);
    Mockito.when(node.getNodeId()).thenReturn(new NodeId(groupId, peerId));
    NodeOptions nodeOptions = new NodeOptions();
    executor = JRaftUtils.createCommonExecutor(nodeOptions);
    nodeOptions.setCommonExecutor(executor);
    appendEntriesExecutor = JRaftUtils.createAppendEntriesExecutor(nodeOptions);
    nodeOptions.setStripedExecutor(appendEntriesExecutor);
    Mockito.lenient().when(node.getOptions()).thenReturn(nodeOptions);
    if (asyncContext != null)
        asyncContext.getNodeManager().add(node);
    return peerId;
}
Also used : NodeId(org.apache.ignite.raft.jraft.entity.NodeId) NodeOptions(org.apache.ignite.raft.jraft.option.NodeOptions) PeerId(org.apache.ignite.raft.jraft.entity.PeerId)

Example 7 with NodeOptions

use of org.apache.ignite.raft.jraft.option.NodeOptions in project ignite-3 by apache.

the class LocalSnapshotCopierTest method setup.

@BeforeEach
public void setup() throws Exception {
    this.timerManager = new TimerManager(5);
    this.raftOptions = new RaftOptions();
    this.writer = new LocalSnapshotWriter(this.path.toString(), this.snapshotStorage, this.raftOptions);
    this.reader = new LocalSnapshotReader(this.snapshotStorage, null, new Endpoint("localhost", 8081), this.raftOptions, this.path.toString());
    Mockito.when(this.snapshotStorage.open()).thenReturn(this.reader);
    Mockito.when(this.snapshotStorage.create(true)).thenReturn(this.writer);
    this.table = new LocalSnapshotMetaTable(this.raftOptions);
    this.table.addFile("testFile", raftOptions.getRaftMessagesFactory().localFileMeta().checksum("test").build());
    this.table.setMeta(raftOptions.getRaftMessagesFactory().snapshotMeta().lastIncludedIndex(1).lastIncludedTerm(1).build());
    this.uri = "remote://" + this.hostPort + "/" + this.readerId;
    this.copier = new LocalSnapshotCopier();
    this.copyOpts = new CopyOptions();
    Mockito.when(this.raftClientService.connect(new Endpoint("localhost", 8081))).thenReturn(true);
    nodeOptions = new NodeOptions();
    nodeOptions.setCommonExecutor(JRaftUtils.createExecutor("test-executor", Utils.cpus()));
    assertTrue(this.copier.init(this.uri, new SnapshotCopierOptions(this.raftClientService, this.timerManager, this.raftOptions, nodeOptions)));
    this.copier.setStorage(this.snapshotStorage);
}
Also used : RaftOptions(org.apache.ignite.raft.jraft.option.RaftOptions) SnapshotCopierOptions(org.apache.ignite.raft.jraft.option.SnapshotCopierOptions) Endpoint(org.apache.ignite.raft.jraft.util.Endpoint) CopyOptions(org.apache.ignite.raft.jraft.option.CopyOptions) NodeOptions(org.apache.ignite.raft.jraft.option.NodeOptions) TimerManager(org.apache.ignite.raft.jraft.core.TimerManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with NodeOptions

use of org.apache.ignite.raft.jraft.option.NodeOptions in project ignite-3 by apache.

the class SnapshotExecutorTest method testDoSnapshotWithIntervalDist.

@Test
public void testDoSnapshotWithIntervalDist() throws Exception {
    final NodeOptions nodeOptions = new NodeOptions();
    nodeOptions.setSnapshotLogIndexMargin(5);
    ExecutorService testExecutor = JRaftUtils.createExecutor("test-executor", Utils.cpus());
    executorService = testExecutor;
    nodeOptions.setCommonExecutor(testExecutor);
    Mockito.when(node.getOptions()).thenReturn(nodeOptions);
    Mockito.when(fSMCaller.getLastAppliedIndex()).thenReturn(6L);
    final ArgumentCaptor<SaveSnapshotClosure> saveSnapshotClosureArg = ArgumentCaptor.forClass(SaveSnapshotClosure.class);
    Mockito.when(fSMCaller.onSnapshotSave(saveSnapshotClosureArg.capture())).thenReturn(true);
    final SynchronizedClosure done = new SynchronizedClosure();
    executor.doSnapshot(done);
    final SaveSnapshotClosure closure = saveSnapshotClosureArg.getValue();
    assertNotNull(closure);
    closure.start(raftOptions.getRaftMessagesFactory().snapshotMeta().lastIncludedIndex(6).lastIncludedTerm(1).build());
    closure.run(Status.OK());
    done.await();
    executor.join();
    assertEquals(1, executor.getLastSnapshotTerm());
    assertEquals(6, executor.getLastSnapshotIndex());
}
Also used : SynchronizedClosure(org.apache.ignite.raft.jraft.closure.SynchronizedClosure) ExecutorService(java.util.concurrent.ExecutorService) SaveSnapshotClosure(org.apache.ignite.raft.jraft.closure.SaveSnapshotClosure) NodeOptions(org.apache.ignite.raft.jraft.option.NodeOptions) Test(org.junit.jupiter.api.Test)

Example 9 with NodeOptions

use of org.apache.ignite.raft.jraft.option.NodeOptions in project ignite-3 by apache.

the class SnapshotExecutorTest method setup.

@BeforeEach
public void setup() throws Exception {
    timerManager = new TimerManager(5);
    raftOptions = new RaftOptions();
    writer = new LocalSnapshotWriter(path.toString(), snapshotStorage, raftOptions);
    reader = new LocalSnapshotReader(snapshotStorage, null, new Endpoint("localhost", 8081), raftOptions, path.toString());
    Mockito.lenient().when(snapshotStorage.open()).thenReturn(reader);
    Mockito.lenient().when(snapshotStorage.create(true)).thenReturn(writer);
    table = new LocalSnapshotMetaTable(raftOptions);
    table.addFile("testFile", raftOptions.getRaftMessagesFactory().localFileMeta().checksum("test").build());
    table.setMeta(raftOptions.getRaftMessagesFactory().snapshotMeta().lastIncludedIndex(1).lastIncludedTerm(1).build());
    uri = "remote://" + hostPort + "/" + readerId;
    copyOpts = new CopyOptions();
    Mockito.when(node.getRaftOptions()).thenReturn(new RaftOptions());
    options = new NodeOptions();
    options.setCommonExecutor(JRaftUtils.createExecutor("test-executor", Utils.cpus()));
    options.setScheduler(timerManager);
    Mockito.when(node.getOptions()).thenReturn(options);
    Mockito.when(node.getRpcClientService()).thenReturn(raftClientService);
    Mockito.when(node.getServiceFactory()).thenReturn(new DefaultJRaftServiceFactory());
    executor = new SnapshotExecutorImpl();
    final SnapshotExecutorOptions opts = new SnapshotExecutorOptions();
    opts.setFsmCaller(fSMCaller);
    opts.setInitTerm(0);
    opts.setNode(node);
    opts.setLogManager(logManager);
    opts.setUri(path.toString());
    addr = new Endpoint("localhost", 8081);
    opts.setAddr(addr);
    assertTrue(executor.init(opts));
}
Also used : RaftOptions(org.apache.ignite.raft.jraft.option.RaftOptions) Endpoint(org.apache.ignite.raft.jraft.util.Endpoint) LocalSnapshotMetaTable(org.apache.ignite.raft.jraft.storage.snapshot.local.LocalSnapshotMetaTable) LocalSnapshotReader(org.apache.ignite.raft.jraft.storage.snapshot.local.LocalSnapshotReader) SnapshotExecutorImpl(org.apache.ignite.raft.jraft.storage.snapshot.SnapshotExecutorImpl) CopyOptions(org.apache.ignite.raft.jraft.option.CopyOptions) NodeOptions(org.apache.ignite.raft.jraft.option.NodeOptions) DefaultJRaftServiceFactory(org.apache.ignite.raft.jraft.core.DefaultJRaftServiceFactory) TimerManager(org.apache.ignite.raft.jraft.core.TimerManager) LocalSnapshotWriter(org.apache.ignite.raft.jraft.storage.snapshot.local.LocalSnapshotWriter) SnapshotExecutorOptions(org.apache.ignite.raft.jraft.option.SnapshotExecutorOptions) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 10 with NodeOptions

use of org.apache.ignite.raft.jraft.option.NodeOptions in project ignite-3 by apache.

the class RemoteFileCopierTest method testInit.

@Test
public void testInit() {
    Mockito.when(rpcService.connect(new Endpoint("localhost", 8081))).thenReturn(true);
    assertTrue(copier.init("remote://localhost:8081/999", null, new SnapshotCopierOptions(rpcService, timerManager, new RaftOptions(), new NodeOptions())));
    assertEquals(999, copier.getReaderId());
    assertEquals("localhost", copier.getEndpoint().getIp());
    assertEquals(8081, copier.getEndpoint().getPort());
}
Also used : RaftOptions(org.apache.ignite.raft.jraft.option.RaftOptions) SnapshotCopierOptions(org.apache.ignite.raft.jraft.option.SnapshotCopierOptions) Endpoint(org.apache.ignite.raft.jraft.util.Endpoint) NodeOptions(org.apache.ignite.raft.jraft.option.NodeOptions) Test(org.junit.jupiter.api.Test)

Aggregations

NodeOptions (org.apache.ignite.raft.jraft.option.NodeOptions)34 PeerId (org.apache.ignite.raft.jraft.entity.PeerId)17 Test (org.junit.jupiter.api.Test)14 Endpoint (org.apache.ignite.raft.jraft.util.Endpoint)13 RaftGroupService (org.apache.ignite.raft.jraft.RaftGroupService)11 BeforeEach (org.junit.jupiter.api.BeforeEach)11 Node (org.apache.ignite.raft.jraft.Node)10 Configuration (org.apache.ignite.raft.jraft.conf.Configuration)8 RaftOptions (org.apache.ignite.raft.jraft.option.RaftOptions)8 ExecutorService (java.util.concurrent.ExecutorService)5 NodeId (org.apache.ignite.raft.jraft.entity.NodeId)4 ByteBuffer (java.nio.ByteBuffer)3 ArrayList (java.util.ArrayList)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 ClusterService (org.apache.ignite.network.ClusterService)3 NetworkAddress (org.apache.ignite.network.NetworkAddress)3 SynchronizedClosure (org.apache.ignite.raft.jraft.closure.SynchronizedClosure)3 BootstrapOptions (org.apache.ignite.raft.jraft.option.BootstrapOptions)3 File (java.io.File)2 Path (java.nio.file.Path)2