Search in sources :

Example 6 with ComputeJobView

use of org.apache.ignite.spi.systemview.view.ComputeJobView in project ignite by apache.

the class KillCommandsCommandShTest method testCancelConsistencyTask.

/**
 */
@Test
public void testCancelConsistencyTask() throws InterruptedException {
    String consistencyCacheName = "consistencyCache";
    CacheConfiguration<Integer, Integer> cfg = new CacheConfiguration<>();
    cfg.setName(consistencyCacheName);
    cfg.setBackups(SERVER_NODE_CNT - 1);
    cfg.setAffinity(new RendezvousAffinityFunction().setPartitions(1));
    IgniteCache<Integer, Integer> cache = client.getOrCreateCache(cfg);
    int entries = 10_000;
    for (int i = 0; i < entries; i++) cache.put(i, i);
    AtomicInteger getCnt = new AtomicInteger();
    CountDownLatch thLatch = new CountDownLatch(1);
    Thread th = new Thread(() -> {
        IgnitePredicate<ComputeJobView> repairJobFilter = job -> job.taskClassName().equals(VisorConsistencyRepairTask.class.getName());
        for (IgniteEx node : srvs) {
            SystemView<ComputeJobView> jobs = node.context().systemView().view(JOBS_VIEW);
            // Found.
            assertTrue(F.iterator0(jobs, true, repairJobFilter).hasNext());
        }
        int res = execute("--consistency", "status");
        assertEquals(EXIT_CODE_OK, res);
        assertContains(log, testOut.toString(), "Status: 1024/" + entries);
        assertNotContains(log, testOut.toString(), VisorConsistencyStatusTask.NOTHING_FOUND);
        testOut.reset();
        res = execute("--kill", "consistency");
        assertEquals(EXIT_CODE_OK, res);
        try {
            assertTrue(GridTestUtils.waitForCondition(() -> {
                for (IgniteEx node : srvs) {
                    SystemView<ComputeJobView> jobs = node.context().systemView().view(JOBS_VIEW);
                    if (// Found.
                    F.iterator0(jobs, true, repairJobFilter).hasNext())
                        return false;
                }
                return true;
            }, // Missed.
            5000L));
        } catch (IgniteInterruptedCheckedException e) {
            fail();
        }
        thLatch.countDown();
    });
    // GridNearGetRequest messages count required to pefrom getAll() with readRepair from all nodes twice.
    // First will be finished (which generates status), second will be frozen.
    int twiceGetMsgCnt = SERVER_NODE_CNT * (SERVER_NODE_CNT - 1) * 2;
    for (IgniteEx server : srvs) {
        TestRecordingCommunicationSpi spi = ((TestRecordingCommunicationSpi) server.configuration().getCommunicationSpi());
        AtomicInteger locLimit = new AtomicInteger(SERVER_NODE_CNT - 1);
        spi.blockMessages((node, message) -> {
            if (message instanceof GridNearGetRequest) {
                // Each node should perform get twice.
                if (getCnt.incrementAndGet() == twiceGetMsgCnt)
                    th.start();
                // Cancellation should stop the process.
                assertTrue(getCnt.get() <= twiceGetMsgCnt);
                // Blocking to freeze '--consistency repair' operation (except first get).
                return locLimit.decrementAndGet() < 0;
            }
            return false;
        });
    }
    injectTestSystemOut();
    assertEquals(EXIT_CODE_UNEXPECTED_ERROR, execute("--consistency", "repair", ConsistencyCommand.STRATEGY, ReadRepairStrategy.LWW.toString(), ConsistencyCommand.PARTITION, "0", ConsistencyCommand.CACHE, consistencyCacheName));
    assertContains(log, testOut.toString(), "Operation execution cancelled.");
    assertContains(log, testOut.toString(), VisorConsistencyRepairTask.NOTHING_FOUND);
    assertNotContains(log, testOut.toString(), VisorConsistencyRepairTask.CONSISTENCY_VIOLATIONS_FOUND);
    thLatch.await();
    for (IgniteEx server : srvs) {
        // Restoring messaging for other tests.
        TestRecordingCommunicationSpi spi = ((TestRecordingCommunicationSpi) server.configuration().getCommunicationSpi());
        spi.stopBlock();
    }
    testOut.reset();
    int res = execute("--consistency", "status");
    assertEquals(EXIT_CODE_OK, res);
    assertContains(log, testOut.toString(), VisorConsistencyStatusTask.NOTHING_FOUND);
    assertNotContains(log, testOut.toString(), "Status");
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) KillCommandsTests.doTestScanQueryCancel(org.apache.ignite.util.KillCommandsTests.doTestScanQueryCancel) KillCommandsTests.doTestCancelService(org.apache.ignite.util.KillCommandsTests.doTestCancelService) IgniteEx(org.apache.ignite.internal.IgniteEx) EXIT_CODE_OK(org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) ArrayList(java.util.ArrayList) KillCommandsTests.doTestCancelSQLQuery(org.apache.ignite.util.KillCommandsTests.doTestCancelSQLQuery) KillCommandsTests.doTestCancelTx(org.apache.ignite.util.KillCommandsTests.doTestCancelTx) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) VisorConsistencyStatusTask(org.apache.ignite.internal.visor.consistency.VisorConsistencyStatusTask) GridTestUtils.assertNotContains(org.apache.ignite.testframework.GridTestUtils.assertNotContains) GridNearGetRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearGetRequest) F(org.apache.ignite.internal.util.typedef.F) KillCommandsTests.doTestCancelComputeTask(org.apache.ignite.util.KillCommandsTests.doTestCancelComputeTask) SystemView(org.apache.ignite.spi.systemview.view.SystemView) JOBS_VIEW(org.apache.ignite.internal.processors.job.GridJobProcessor.JOBS_VIEW) ReadRepairStrategy(org.apache.ignite.cache.ReadRepairStrategy) Test(org.junit.Test) UUID(java.util.UUID) IgniteCache(org.apache.ignite.IgniteCache) ConsistencyCommand(org.apache.ignite.internal.commandline.consistency.ConsistencyCommand) EXIT_CODE_UNEXPECTED_ERROR(org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_UNEXPECTED_ERROR) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) GridTestUtils.assertContains(org.apache.ignite.testframework.GridTestUtils.assertContains) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) PAGES_CNT(org.apache.ignite.util.KillCommandsTests.PAGES_CNT) AbstractSnapshotSelfTest.doSnapshotCancellationTest(org.apache.ignite.internal.processors.cache.persistence.snapshot.AbstractSnapshotSelfTest.doSnapshotCancellationTest) VisorConsistencyRepairTask(org.apache.ignite.internal.visor.consistency.VisorConsistencyRepairTask) ComputeJobView(org.apache.ignite.spi.systemview.view.ComputeJobView) KillCommandsTests.doTestCancelContinuousQuery(org.apache.ignite.util.KillCommandsTests.doTestCancelContinuousQuery) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) PAGE_SZ(org.apache.ignite.util.KillCommandsTests.PAGE_SZ) IgniteUuid(org.apache.ignite.lang.IgniteUuid) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ComputeJobView(org.apache.ignite.spi.systemview.view.ComputeJobView) SystemView(org.apache.ignite.spi.systemview.view.SystemView) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteEx(org.apache.ignite.internal.IgniteEx) VisorConsistencyRepairTask(org.apache.ignite.internal.visor.consistency.VisorConsistencyRepairTask) GridNearGetRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearGetRequest) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Test(org.junit.Test) AbstractSnapshotSelfTest.doSnapshotCancellationTest(org.apache.ignite.internal.processors.cache.persistence.snapshot.AbstractSnapshotSelfTest.doSnapshotCancellationTest)

Example 7 with ComputeJobView

use of org.apache.ignite.spi.systemview.view.ComputeJobView in project ignite by apache.

the class SystemViewComputeJobTest method testComputeAffinityCall.

/**
 * Tests work of {@link SystemView} for compute grid
 * {@link IgniteCompute#affinityCallAsync(String, Object, IgniteCallable)} call.
 */
@Test
public void testComputeAffinityCall() throws Exception {
    barrier = new CyclicBarrier(2);
    SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
    client.compute().affinityCallAsync("test-cache", 1, () -> {
        try {
            barrier.await(TIMEOUT, MILLISECONDS);
            barrier.await(TIMEOUT, MILLISECONDS);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return 0;
    });
    barrier.await(TIMEOUT, MILLISECONDS);
    assertEquals(1, jobs.size());
    ComputeJobView t = jobs.iterator().next();
    assertFalse(t.isInternal());
    assertEquals(String.valueOf(CU.cacheId("test-cache")), t.affinityCacheIds());
    assertEquals(1, t.affinityPartitionId());
    assertTrue(t.taskClassName().startsWith(getClass().getName()));
    assertTrue(t.taskName().startsWith(getClass().getName()));
    assertEquals(client.localNode().id(), t.originNodeId());
    barrier.await(TIMEOUT, MILLISECONDS);
    boolean res = waitForCondition(() -> jobs.size() == 0, TIMEOUT);
    assertTrue(res);
}
Also used : ComputeJobView(org.apache.ignite.spi.systemview.view.ComputeJobView) CyclicBarrier(java.util.concurrent.CyclicBarrier) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 8 with ComputeJobView

use of org.apache.ignite.spi.systemview.view.ComputeJobView in project ignite by apache.

the class SystemViewComputeJobTest method testCancelComputeTask.

/**
 */
@Test
public void testCancelComputeTask() throws Exception {
    barrier = new CyclicBarrier(2);
    SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
    client.compute().withName("cancel-task").executeAsync(new ComputeTask<Object, Object>() {

        @Override
        @NotNull
        public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, @Nullable Object arg) throws IgniteException {
            return Collections.singletonMap(new ComputeJob() {

                @Override
                public void cancel() {
                // No-op.
                }

                @Override
                public Object execute() throws IgniteException {
                    try {
                        Thread.sleep(60_000);
                    } catch (InterruptedException e) {
                        throw new IgniteException(e);
                    }
                    return null;
                }
            }, subgrid.get(0));
        }

        @Override
        public ComputeJobResultPolicy result(ComputeJobResult res, List<ComputeJobResult> rcvd) throws IgniteException {
            return null;
        }

        @Nullable
        @Override
        public Object reduce(List<ComputeJobResult> results) throws IgniteException {
            return 1;
        }
    }, 1);
    barrier.await(TIMEOUT, MILLISECONDS);
    assertEquals(1, jobs.size());
    checkJobView(jobs.iterator().next(), "cancel-task", PASSIVE);
    barrier.await(TIMEOUT, MILLISECONDS);
    barrier.await(TIMEOUT, MILLISECONDS);
    assertEquals(1, jobs.size());
    checkJobView(jobs.iterator().next(), "cancel-task", CANCELED);
    barrier.await(TIMEOUT, MILLISECONDS);
    boolean res = waitForCondition(() -> jobs.size() == 0, TIMEOUT);
    assertTrue(res);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) NotNull(org.jetbrains.annotations.NotNull) CyclicBarrier(java.util.concurrent.CyclicBarrier) ComputeJobView(org.apache.ignite.spi.systemview.view.ComputeJobView) ComputeJob(org.apache.ignite.compute.ComputeJob) ComputeJobResultPolicy(org.apache.ignite.compute.ComputeJobResultPolicy) IgniteException(org.apache.ignite.IgniteException) Map(java.util.Map) Nullable(org.jetbrains.annotations.Nullable) ComputeJobResult(org.apache.ignite.compute.ComputeJobResult) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 9 with ComputeJobView

use of org.apache.ignite.spi.systemview.view.ComputeJobView in project ignite by apache.

the class SystemViewComputeJobTest method testComputeTask.

/**
 */
@Test
public void testComputeTask() throws Exception {
    barrier = new CyclicBarrier(2);
    SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
    client.compute().executeAsync(new ComputeTask<Object, Object>() {

        @Override
        @NotNull
        public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, @Nullable Object arg) throws IgniteException {
            return Collections.singletonMap(new ComputeJob() {

                @Override
                public void cancel() {
                // No-op.
                }

                @Override
                public Object execute() throws IgniteException {
                    try {
                        barrier.await(TIMEOUT, MILLISECONDS);
                        barrier.await(TIMEOUT, MILLISECONDS);
                    } catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
                        throw new RuntimeException(e);
                    }
                    return 1;
                }
            }, subgrid.get(0));
        }

        @Override
        public ComputeJobResultPolicy result(ComputeJobResult res, List<ComputeJobResult> rcvd) throws IgniteException {
            return null;
        }

        @Nullable
        @Override
        public Object reduce(List<ComputeJobResult> results) throws IgniteException {
            return 1;
        }
    }, 1);
    barrier.await(TIMEOUT, MILLISECONDS);
    assertEquals(1, jobs.size());
    ComputeJobView t = jobs.iterator().next();
    checkJobView(t);
    barrier.await(TIMEOUT, MILLISECONDS);
    boolean res = waitForCondition(() -> jobs.size() == 0, TIMEOUT);
    assertTrue(res);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) NotNull(org.jetbrains.annotations.NotNull) CyclicBarrier(java.util.concurrent.CyclicBarrier) ComputeJobView(org.apache.ignite.spi.systemview.view.ComputeJobView) ComputeJob(org.apache.ignite.compute.ComputeJob) ComputeJobResultPolicy(org.apache.ignite.compute.ComputeJobResultPolicy) IgniteException(org.apache.ignite.IgniteException) Map(java.util.Map) Nullable(org.jetbrains.annotations.Nullable) TimeoutException(java.util.concurrent.TimeoutException) ComputeJobResult(org.apache.ignite.compute.ComputeJobResult) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

ComputeJobView (org.apache.ignite.spi.systemview.view.ComputeJobView)9 Test (org.junit.Test)9 CyclicBarrier (java.util.concurrent.CyclicBarrier)8 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)8 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)5 TimeoutException (java.util.concurrent.TimeoutException)5 Map (java.util.Map)2 IgniteException (org.apache.ignite.IgniteException)2 ClusterNode (org.apache.ignite.cluster.ClusterNode)2 ComputeJob (org.apache.ignite.compute.ComputeJob)2 ComputeJobResult (org.apache.ignite.compute.ComputeJobResult)2 ComputeJobResultPolicy (org.apache.ignite.compute.ComputeJobResultPolicy)2 IgniteEx (org.apache.ignite.internal.IgniteEx)2 ComputeTaskView (org.apache.ignite.spi.systemview.view.ComputeTaskView)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 UUID (java.util.UUID)1 CountDownLatch (java.util.concurrent.CountDownLatch)1