use of org.apache.ignite.internal.processors.job.GridJobProcessor.JOBS_VIEW 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");
}
Aggregations