use of org.apache.ignite.raft.jraft.closure.JoinableClosure in project ignite-3 by apache.
the class ItNodeTest method testNodeTaskOverload.
@Test
public void testNodeTaskOverload() throws Exception {
Endpoint addr = new Endpoint(TestUtils.getLocalAddress(), TestUtils.INIT_PORT);
PeerId peer = new PeerId(addr, 0);
NodeOptions nodeOptions = createNodeOptions();
RaftOptions raftOptions = new RaftOptions();
raftOptions.setDisruptorBufferSize(2);
nodeOptions.setRaftOptions(raftOptions);
MockStateMachine fsm = new MockStateMachine(addr);
nodeOptions.setFsm(fsm);
nodeOptions.setLogUri(dataPath + File.separator + "log");
nodeOptions.setRaftMetaUri(dataPath + File.separator + "meta");
nodeOptions.setSnapshotUri(dataPath + File.separator + "snapshot");
nodeOptions.setInitialConf(new Configuration(Collections.singletonList(peer)));
RaftGroupService service = createService("unittest", new PeerId(addr, 0), nodeOptions);
Node node = service.start();
assertEquals(1, node.listPeers().size());
assertTrue(node.listPeers().contains(peer));
while (!node.isLeader()) ;
List<Task> tasks = new ArrayList<>();
AtomicInteger c = new AtomicInteger(0);
for (int i = 0; i < 10; i++) {
ByteBuffer data = ByteBuffer.wrap(("hello" + i).getBytes(UTF_8));
int finalI = i;
Task task = new Task(data, new JoinableClosure(status -> {
LOG.info("{} i={}", status, finalI);
if (!status.isOk()) {
assertTrue(status.getRaftError() == RaftError.EBUSY || status.getRaftError() == RaftError.EPERM);
}
c.incrementAndGet();
}));
node.apply(task);
tasks.add(task);
}
Task.joinAll(tasks, TimeUnit.SECONDS.toMillis(30));
assertEquals(10, c.get());
}
use of org.apache.ignite.raft.jraft.closure.JoinableClosure in project ignite-3 by apache.
the class Task method join.
/**
* Waiting for the task to complete, to note that throughput may be reduced, which is generally not recommended.
*
* @return done closure
* @throws InterruptedException if the current thread is interrupted while waiting
*/
public Closure join() throws InterruptedException {
final JoinableClosure joinable = castToJoinalbe(this.done);
joinable.join();
return joinable.getClosure();
}
use of org.apache.ignite.raft.jraft.closure.JoinableClosure in project ignite-3 by apache.
the class Task method join.
/**
* Waiting for the task to complete with a timeout millis, to note that throughput may be reduced, which is
* generally not recommended.
*
* @param timeoutMillis the maximum millis to wait
* @return done closure
* @throws InterruptedException if the current thread is interrupted while waiting
* @throws TimeoutException if timeout
*/
public Closure join(final long timeoutMillis) throws InterruptedException, TimeoutException {
final JoinableClosure joinable = castToJoinalbe(this.done);
joinable.join(timeoutMillis);
return joinable.getClosure();
}
Aggregations