Search in sources :

Example 6 with ComputeTaskView

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

the class SystemViewSelfTest method testComputeAffinityCall.

/**
 * Tests work of {@link SystemView} for compute grid
 * {@link IgniteCompute#affinityCallAsync(String, Object, IgniteCallable)} call.
 */
@Test
public void testComputeAffinityCall() throws Exception {
    CyclicBarrier barrier = new CyclicBarrier(2);
    try (IgniteEx g1 = startGrid(0)) {
        SystemView<ComputeTaskView> tasks = g1.context().systemView().view(TASKS_VIEW);
        IgniteCache<Integer, Integer> cache = g1.createCache("test-cache");
        cache.put(1, 1);
        g1.compute().affinityCallAsync("test-cache", 1, () -> {
            try {
                barrier.await();
                barrier.await();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            return 0;
        });
        barrier.await();
        assertEquals(1, tasks.size());
        ComputeTaskView t = tasks.iterator().next();
        assertFalse(t.internal());
        assertEquals("test-cache", t.affinityCacheName());
        assertEquals(1, t.affinityPartitionId());
        assertTrue(t.taskClassName().startsWith(getClass().getName()));
        assertTrue(t.taskName().startsWith(getClass().getName()));
        assertEquals(g1.localNode().id(), t.taskNodeId());
        assertEquals("0", t.userVersion());
        barrier.await();
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteEx(org.apache.ignite.internal.IgniteEx) ComputeTaskView(org.apache.ignite.spi.systemview.view.ComputeTaskView) CyclicBarrier(java.util.concurrent.CyclicBarrier) Test(org.junit.Test) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)

Example 7 with ComputeTaskView

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

the class SystemViewSelfTest method testComputeBroadcast.

/**
 * Tests work of {@link SystemView} for compute grid {@link IgniteCompute#broadcastAsync(IgniteRunnable)} call.
 */
@Test
public void testComputeBroadcast() throws Exception {
    CyclicBarrier barrier = new CyclicBarrier(6);
    try (IgniteEx g1 = startGrid(0)) {
        SystemView<ComputeTaskView> tasks = g1.context().systemView().view(TASKS_VIEW);
        for (int i = 0; i < 5; i++) {
            g1.compute().broadcastAsync(() -> {
                try {
                    barrier.await();
                    barrier.await();
                } catch (InterruptedException | BrokenBarrierException e) {
                    throw new RuntimeException(e);
                }
            });
        }
        barrier.await();
        assertEquals(5, tasks.size());
        ComputeTaskView t = tasks.iterator().next();
        assertFalse(t.internal());
        assertNull(t.affinityCacheName());
        assertEquals(-1, t.affinityPartitionId());
        assertTrue(t.taskClassName().startsWith(getClass().getName()));
        assertTrue(t.taskName().startsWith(getClass().getName()));
        assertEquals(g1.localNode().id(), t.taskNodeId());
        assertEquals("0", t.userVersion());
        barrier.await();
    }
}
Also used : BrokenBarrierException(java.util.concurrent.BrokenBarrierException) IgniteEx(org.apache.ignite.internal.IgniteEx) ComputeTaskView(org.apache.ignite.spi.systemview.view.ComputeTaskView) CyclicBarrier(java.util.concurrent.CyclicBarrier) Test(org.junit.Test) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)

Aggregations

CyclicBarrier (java.util.concurrent.CyclicBarrier)7 ComputeTaskView (org.apache.ignite.spi.systemview.view.ComputeTaskView)7 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)7 Test (org.junit.Test)7 IgniteEx (org.apache.ignite.internal.IgniteEx)6 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ComputeJobView (org.apache.ignite.spi.systemview.view.ComputeJobView)2 Map (java.util.Map)1 TimeoutException (java.util.concurrent.TimeoutException)1 IgniteException (org.apache.ignite.IgniteException)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 ComputeJob (org.apache.ignite.compute.ComputeJob)1 ComputeJobResult (org.apache.ignite.compute.ComputeJobResult)1 ComputeJobResultPolicy (org.apache.ignite.compute.ComputeJobResultPolicy)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1