use of org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.TEST_PROCESS in project ignite by apache.
the class DistributedProcessCoordinatorLeftTest method testCoordinatorFailed.
/**
* Tests that coordinator failing during sending single result not cause node failure and the process finishes.
*
* <ol>
* <li>Start new process of {@link DistributedProcess}.</li>
* <li>The coordinator fails.</li>
* <li>Nodes try to send a single message to the not-alive coordinator.</li>
* <li>{@link DistributedProcess} process a node left event and reinitialize a new coordinator.</li>
* <li>Process finishes.</li>
* </ol>
*
* @throws Exception If failed.
*/
@Test
public void testCoordinatorFailed() throws Exception {
startGrids(NODES_CNT);
CountDownLatch startLatch = new CountDownLatch(NODES_CNT);
CountDownLatch finishLatch = new CountDownLatch(NODES_CNT - 1);
HashMap<String, DistributedProcess<Integer, Integer>> processes = new HashMap<>();
int processRes = 1;
for (Ignite grid : G.allGrids()) {
DistributedProcess<Integer, Integer> dp = new DistributedProcess<>(((IgniteEx) grid).context(), TEST_PROCESS, req -> {
IgniteInternalFuture<Integer> fut = runAsync(() -> {
try {
nodeLeftLatch.await();
} catch (InterruptedException ignored) {
fail("Unexpected interrupt.");
}
return req;
});
// It is guaranteed by the LIFO order of future listeners notifying.
if (!grid.name().equals(getTestIgniteInstanceName(STOP_NODE_IDX)))
fut.listen(f -> msgSendLatch.countDown());
startLatch.countDown();
return fut;
}, (uuid, res, err) -> {
if (res.values().size() == NODES_CNT - 1 && res.values().stream().allMatch(i -> i == processRes))
finishLatch.countDown();
else
fail("Unexpected process result [res=" + res + ", err=" + err + ']');
});
processes.put(grid.name(), dp);
}
processes.get(grid(STOP_NODE_IDX).name()).start(UUID.randomUUID(), processRes);
assertTrue(startLatch.await(TIMEOUT, MILLISECONDS));
stopGrid(STOP_NODE_IDX);
assertTrue(finishLatch.await(TIMEOUT, MILLISECONDS));
assertFalse(failure.get());
}
Aggregations