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");
}
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);
}
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);
}
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);
}
Aggregations