Search in sources :

Example 1 with TEST_PROCESS

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());
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) G(org.apache.ignite.internal.util.typedef.G) DistributedProcess(org.apache.ignite.internal.util.distributed.DistributedProcess) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) EVT_NODE_LEFT(org.apache.ignite.events.EventType.EVT_NODE_LEFT) TEST_PROCESS(org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.TEST_PROCESS) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) FailureHandler(org.apache.ignite.failure.FailureHandler) IgniteEx(org.apache.ignite.internal.IgniteEx) Test(org.junit.Test) UUID(java.util.UUID) Ignite(org.apache.ignite.Ignite) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) GridTestUtils.runAsync(org.apache.ignite.testframework.GridTestUtils.runAsync) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) EVT_NODE_FAILED(org.apache.ignite.events.EventType.EVT_NODE_FAILED) FailureContext(org.apache.ignite.failure.FailureContext) Collections(java.util.Collections) DistributedProcess(org.apache.ignite.internal.util.distributed.DistributedProcess) HashMap(java.util.HashMap) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 UUID (java.util.UUID)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 MILLISECONDS (java.util.concurrent.TimeUnit.MILLISECONDS)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Ignite (org.apache.ignite.Ignite)1 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)1 EVT_NODE_FAILED (org.apache.ignite.events.EventType.EVT_NODE_FAILED)1 EVT_NODE_LEFT (org.apache.ignite.events.EventType.EVT_NODE_LEFT)1 FailureContext (org.apache.ignite.failure.FailureContext)1 FailureHandler (org.apache.ignite.failure.FailureHandler)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)1 DistributedProcess (org.apache.ignite.internal.util.distributed.DistributedProcess)1 TEST_PROCESS (org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.TEST_PROCESS)1 G (org.apache.ignite.internal.util.typedef.G)1 GridTestUtils.runAsync (org.apache.ignite.testframework.GridTestUtils.runAsync)1 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)1 Test (org.junit.Test)1