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;
}
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);
}
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());
}
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));
}
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());
}
Aggregations