use of org.apache.ignite.spi.systemview.view.ComputeTaskView in project ignite by apache.
the class SystemViewSelfTest method testComputeTask.
/**
*/
@Test
public void testComputeTask() 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().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 {
return 1;
}
}, subgrid.get(0));
}
@Override
public ComputeJobResultPolicy result(ComputeJobResult res, List<ComputeJobResult> rcvd) throws IgniteException {
try {
barrier.await();
barrier.await();
} catch (InterruptedException | BrokenBarrierException e) {
throw new RuntimeException(e);
}
return null;
}
@Nullable
@Override
public Object reduce(List<ComputeJobResult> results) throws IgniteException {
return 1;
}
}, 1);
barrier.await();
assertEquals(1, 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();
}
}
use of org.apache.ignite.spi.systemview.view.ComputeTaskView 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);
}
use of org.apache.ignite.spi.systemview.view.ComputeTaskView 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);
}
}
use of org.apache.ignite.spi.systemview.view.ComputeTaskView in project ignite by apache.
the class SystemViewSelfTest method testComputeRunnable.
/**
* Tests work of {@link SystemView} for compute grid {@link IgniteCompute#runAsync(IgniteRunnable)} call.
*/
@Test
public void testComputeRunnable() throws Exception {
CyclicBarrier barrier = new CyclicBarrier(2);
try (IgniteEx g1 = startGrid(0)) {
SystemView<ComputeTaskView> tasks = g1.context().systemView().view(TASKS_VIEW);
g1.compute().runAsync(() -> {
try {
barrier.await();
barrier.await();
} catch (InterruptedException | BrokenBarrierException e) {
throw new RuntimeException(e);
}
});
barrier.await();
assertEquals(1, 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();
}
}
use of org.apache.ignite.spi.systemview.view.ComputeTaskView in project ignite by apache.
the class SystemViewSelfTest method testComputeApply.
/**
* Tests work of {@link SystemView} for compute grid {@link IgniteCompute#apply(IgniteClosure, Object)} call.
*/
@Test
public void testComputeApply() throws Exception {
CyclicBarrier barrier = new CyclicBarrier(2);
try (IgniteEx g1 = startGrid(0)) {
SystemView<ComputeTaskView> tasks = g1.context().systemView().view(TASKS_VIEW);
GridTestUtils.runAsync(() -> {
g1.compute().apply(x -> {
try {
barrier.await();
barrier.await();
} catch (InterruptedException | BrokenBarrierException e) {
throw new RuntimeException(e);
}
return 0;
}, 1);
});
barrier.await();
assertEquals(1, 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();
}
}
Aggregations