use of eu.bcvsolutions.idm.core.scheduler.api.dto.LongRunningFutureTask in project CzechIdMng by bcvsolutions.
the class DefaultLongRunningTaskManagerIntegrationTest method testCancelRunningTask.
@Test
public void testCancelRunningTask() throws InterruptedException, ExecutionException {
String result = "TEST_SUCCESS_04";
Long count = 100L;
LongRunningTaskExecutor<String> taskExecutor = new TestStopableLongRunningTaskExecutor(result, count);
//
LongRunningFutureTask<String> futureTask = manager.execute(taskExecutor);
//
Function<String, Boolean> continueFunction = res -> {
return !manager.getLongRunningTask(futureTask).isRunning();
};
helper.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());
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.LongRunningFutureTask in project CzechIdMng by bcvsolutions.
the class DefaultSchedulerManagerIntegrationTest method testDependentTaskExecution.
@Test
@SuppressWarnings("unchecked")
public void testDependentTaskExecution() throws Exception {
helper.setConfigurationValue(SchedulerConfiguration.PROPERTY_TASK_ASYNCHRONOUS_ENABLED, false);
try {
String resultValue = "dependent-task-initiator";
//
IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
filter.setOperationState(OperationState.CREATED);
filter.setTaskType(TestSchedulableTask.class.getCanonicalName());
filter.setFrom(new DateTime());
List<IdmLongRunningTaskDto> createdLrts = longRunningTaskService.find(filter, null).getContent();
Assert.assertEquals(0L, createdLrts.size());
//
Task task = createTask("dependent-task-initiator");
DependentTaskTrigger trigger = new DependentTaskTrigger();
trigger.setInitiatorTaskId(task.getId());
//
// initiator = dependent task => circular execution
manager.createTrigger(task.getId(), trigger);
manager.runTask(task.getId());
helper.waitForResult(getContinueFunction());
createdLrts = longRunningTaskService.find(filter, null).getContent();
Assert.assertEquals(1L, createdLrts.size());
// execute first task
LongRunningFutureTask<String> futureTask = (LongRunningFutureTask<String>) longRunningTaskManager.processCreated(createdLrts.get(0).getId());
Assert.assertEquals(resultValue, futureTask.getFutureTask().get());
//
helper.waitForResult(getContinueFunction());
createdLrts = longRunningTaskService.find(filter, null).getContent();
Assert.assertEquals(1L, longRunningTaskService.find(filter, null).getTotalElements());
//
longRunningTaskManager.cancel(createdLrts.get(0).getId());
//
longRunningTaskService.find(filter, null).getContent();
// cancel - clean up
Assert.assertEquals(0L, longRunningTaskService.find(filter, null).getTotalElements());
} finally {
helper.setConfigurationValue(SchedulerConfiguration.PROPERTY_TASK_ASYNCHRONOUS_ENABLED, true);
}
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.LongRunningFutureTask in project CzechIdMng by bcvsolutions.
the class DefaultSchedulerManagerIntegrationTest method testDependentTaskInDryModeExecution.
@Test
@SuppressWarnings("unchecked")
public void testDependentTaskInDryModeExecution() throws Exception {
helper.setConfigurationValue(SchedulerConfiguration.PROPERTY_TASK_ASYNCHRONOUS_ENABLED, false);
try {
String resultValue = "dependent-task-initiator-dry-run";
//
IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
filter.setOperationState(OperationState.CREATED);
filter.setTaskType(TestSchedulableDryRunTask.class.getCanonicalName());
filter.setFrom(new DateTime());
List<IdmLongRunningTaskDto> createdLrts = longRunningTaskService.find(filter, null).getContent();
Assert.assertEquals(0L, createdLrts.size());
//
Task task = createDryRunTask(resultValue);
DependentTaskTrigger trigger = new DependentTaskTrigger();
trigger.setInitiatorTaskId(task.getId());
//
// initiator = dependent task => circular execution
manager.createTrigger(task.getId(), trigger);
manager.runTask(task.getId(), true);
helper.waitForResult(getContinueFunction());
createdLrts = longRunningTaskService.find(filter, null).getContent();
Assert.assertEquals(1L, createdLrts.size());
Assert.assertTrue(createdLrts.get(0).isDryRun());
UUID firstTaskId = createdLrts.get(0).getId();
// execute first task
LongRunningFutureTask<String> futureTask = (LongRunningFutureTask<String>) longRunningTaskManager.processCreated(createdLrts.get(0).getId());
Assert.assertEquals(resultValue, futureTask.getFutureTask().get());
//
helper.waitForResult(getContinueFunction());
createdLrts = longRunningTaskService.find(filter, null).getContent();
Assert.assertEquals(1L, longRunningTaskService.find(filter, null).getTotalElements());
Assert.assertTrue(createdLrts.get(0).isDryRun());
Assert.assertNotEquals(firstTaskId, createdLrts.get(0).getId());
//
longRunningTaskManager.cancel(createdLrts.get(0).getId());
//
longRunningTaskService.find(filter, null).getContent();
// cancel - clean up
Assert.assertEquals(0L, longRunningTaskService.find(filter, null).getTotalElements());
} finally {
helper.setConfigurationValue(SchedulerConfiguration.PROPERTY_TASK_ASYNCHRONOUS_ENABLED, true);
}
}
Aggregations