Search in sources :

Example 1 with ComputeJobView

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

the class SystemViewComputeJobTest method testComputeApply.

/**
 * Tests work of {@link SystemView} for compute grid {@link IgniteCompute#apply(IgniteClosure, Object)} call.
 */
@Test
public void testComputeApply() throws Exception {
    barrier = new CyclicBarrier(2);
    SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
    GridTestUtils.runAsync(() -> {
        client.compute().apply(x -> {
            try {
                barrier.await(TIMEOUT, MILLISECONDS);
                barrier.await(TIMEOUT, MILLISECONDS);
            } catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
                throw new RuntimeException(e);
            }
            return 0;
        }, 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 : ComputeJobView(org.apache.ignite.spi.systemview.view.ComputeJobView) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) CyclicBarrier(java.util.concurrent.CyclicBarrier) TimeoutException(java.util.concurrent.TimeoutException) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 2 with ComputeJobView

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

the class SystemViewComputeJobTest method testComputeAffinityCallJobAndTask.

/**
 * Tests work of {@link SystemView} for compute grid {@link IgniteCompute#runAsync(IgniteRunnable)} call.
 */
@Test
public void testComputeAffinityCallJobAndTask() throws Exception {
    barrier = new CyclicBarrier(2);
    SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
    SystemView<ComputeTaskView> tasks = client.context().systemView().view(TASKS_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, tasks.size());
    assertEquals(1, jobs.size());
    checkTaskAndJob(tasks.iterator().next(), jobs.iterator().next());
    barrier.await(TIMEOUT, MILLISECONDS);
    boolean res = waitForCondition(() -> jobs.size() == 0, TIMEOUT);
    assertTrue(res);
    res = waitForCondition(() -> tasks.size() == 0, TIMEOUT);
    assertTrue(res);
}
Also used : ComputeJobView(org.apache.ignite.spi.systemview.view.ComputeJobView) ComputeTaskView(org.apache.ignite.spi.systemview.view.ComputeTaskView) CyclicBarrier(java.util.concurrent.CyclicBarrier) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 3 with ComputeJobView

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

the class SystemViewComputeJobTest method testComputeRunnable.

/**
 * Tests work of {@link SystemView} for compute grid {@link IgniteCompute#runAsync(IgniteRunnable)} call.
 */
@Test
public void testComputeRunnable() throws Exception {
    barrier = new CyclicBarrier(2);
    SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
    client.compute().runAsync(() -> {
        try {
            barrier.await(TIMEOUT, MILLISECONDS);
            barrier.await(TIMEOUT, MILLISECONDS);
        } catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
            throw new RuntimeException(e);
        }
    });
    barrier.await(TIMEOUT, MILLISECONDS);
    assertEquals(1, jobs.size());
    for (ComputeJobView job : jobs) checkJobView(job);
    barrier.await(TIMEOUT, MILLISECONDS);
    boolean res = waitForCondition(() -> jobs.size() == 0, TIMEOUT);
    assertTrue(res);
}
Also used : ComputeJobView(org.apache.ignite.spi.systemview.view.ComputeJobView) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) CyclicBarrier(java.util.concurrent.CyclicBarrier) TimeoutException(java.util.concurrent.TimeoutException) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 4 with ComputeJobView

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

the class SystemViewComputeJobTest method testComputeRunnableJobAndTask.

/**
 * Tests work of {@link SystemView} for compute grid {@link IgniteCompute#runAsync(IgniteRunnable)} call.
 */
@Test
public void testComputeRunnableJobAndTask() throws Exception {
    try (IgniteEx server2 = startGrid(2)) {
        barrier = new CyclicBarrier(3);
        SystemView<ComputeJobView> jobs1 = server.context().systemView().view(JOBS_VIEW);
        SystemView<ComputeJobView> jobs2 = server2.context().systemView().view(JOBS_VIEW);
        SystemView<ComputeTaskView> tasks = client.context().systemView().view(TASKS_VIEW);
        client.compute().broadcastAsync(() -> {
            try {
                barrier.await(TIMEOUT, MILLISECONDS);
                barrier.await(TIMEOUT, MILLISECONDS);
            } catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
                throw new RuntimeException(e);
            }
        });
        barrier.await(TIMEOUT, MILLISECONDS);
        assertEquals(1, tasks.size());
        assertEquals(1, jobs1.size());
        assertEquals(1, jobs2.size());
        ComputeTaskView task = tasks.iterator().next();
        checkTaskAndJob(task, jobs1.iterator().next());
        checkTaskAndJob(task, jobs2.iterator().next());
        barrier.await(TIMEOUT, MILLISECONDS);
        boolean res = waitForCondition(() -> jobs1.size() == 0, TIMEOUT);
        assertTrue(res);
        res = waitForCondition(() -> jobs2.size() == 0, TIMEOUT);
        assertTrue(res);
        res = waitForCondition(() -> tasks.size() == 0, TIMEOUT);
        assertTrue(res);
    }
}
Also used : ComputeJobView(org.apache.ignite.spi.systemview.view.ComputeJobView) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) IgniteEx(org.apache.ignite.internal.IgniteEx) ComputeTaskView(org.apache.ignite.spi.systemview.view.ComputeTaskView) CyclicBarrier(java.util.concurrent.CyclicBarrier) TimeoutException(java.util.concurrent.TimeoutException) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 5 with ComputeJobView

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

the class SystemViewComputeJobTest method testComputeBroadcast.

/**
 * Tests work of {@link SystemView} for compute grid {@link IgniteCompute#broadcastAsync(IgniteRunnable)} call.
 */
@Test
public void testComputeBroadcast() throws Exception {
    barrier = new CyclicBarrier(6);
    SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
    for (int i = 0; i < 5; i++) {
        client.compute().broadcastAsync(() -> {
            try {
                barrier.await(TIMEOUT, MILLISECONDS);
                barrier.await(TIMEOUT, MILLISECONDS);
            } catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
                throw new RuntimeException(e);
            }
        });
    }
    barrier.await(TIMEOUT, MILLISECONDS);
    assertEquals(5, jobs.size());
    for (ComputeJobView job : jobs) checkJobView(job);
    barrier.await(TIMEOUT, MILLISECONDS);
    boolean res = waitForCondition(() -> jobs.size() == 0, TIMEOUT);
    assertTrue(res);
}
Also used : ComputeJobView(org.apache.ignite.spi.systemview.view.ComputeJobView) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) CyclicBarrier(java.util.concurrent.CyclicBarrier) TimeoutException(java.util.concurrent.TimeoutException) 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