use of eu.bcvsolutions.idm.core.scheduler.api.service.LongRunningTaskExecutor in project CzechIdMng by bcvsolutions.
the class DefaultLongRunningTaskManagerIntegrationTest method testCancelRunningTask.
@Test
public void testCancelRunningTask() throws InterruptedException, ExecutionException {
String result = "TEST_SUCCESS_04";
Long count = 30L;
LongRunningTaskExecutor<String> taskExecutor = new TestStopableLongRunningTaskExecutor(result, count);
//
LongRunningFutureTask<String> futureTask = manager.execute(taskExecutor);
//
Function<String, Boolean> continueFunction = res -> {
IdmLongRunningTaskDto longRunningTask = manager.getLongRunningTask(futureTask);
return !longRunningTask.isRunning() || !longRunningTask.getResultState().isRunnable();
};
getHelper().waitForResult(continueFunction);
//
manager.cancel(taskExecutor.getLongRunningTaskId());
//
assertEquals(result, futureTask.getFutureTask().get());
//
IdmLongRunningTaskDto longRunningTask = service.get(taskExecutor.getLongRunningTaskId());
assertEquals(OperationState.CANCELED, longRunningTask.getResult().getState());
assertEquals(count, longRunningTask.getCount());
assertNotEquals(count, longRunningTask.getCounter());
}
Aggregations