use of eu.bcvsolutions.idm.core.scheduler.event.processor.LongRunningTaskExecuteDependentProcessor in project CzechIdMng by bcvsolutions.
the class DefaultSchedulerManagerIntegrationTest method testDependentTaskNoExecutionAfterInitiatorFails.
@Test
public void testDependentTaskNoExecutionAfterInitiatorFails() throws Exception {
helper.setConfigurationValue(SchedulerConfiguration.PROPERTY_TASK_ASYNCHRONOUS_ENABLED, false);
try {
LongRunningTaskExecuteDependentProcessor processor = context.getBean(LongRunningTaskExecuteDependentProcessor.class);
//
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());
IdmLongRunningTaskDto lrt = createdLrts.get(0);
lrt.setResult(new OperationResult(OperationState.EXCEPTION));
// not executed
EventResult<IdmLongRunningTaskDto> result = processor.process(new LongRunningTaskEvent(LongRunningTaskEventType.END, lrt));
Assert.assertEquals(OperationState.NOT_EXECUTED, result.getResults().get(0).getState());
lrt.setResult(new OperationResult(OperationState.BLOCKED));
result = processor.process(new LongRunningTaskEvent(LongRunningTaskEventType.END, lrt));
Assert.assertEquals(OperationState.NOT_EXECUTED, result.getResults().get(0).getState());
lrt.setResult(new OperationResult(OperationState.NOT_EXECUTED));
result = processor.process(new LongRunningTaskEvent(LongRunningTaskEventType.END, lrt));
Assert.assertEquals(OperationState.NOT_EXECUTED, result.getResults().get(0).getState());
lrt.setResult(new OperationResult(OperationState.CANCELED));
result = processor.process(new LongRunningTaskEvent(LongRunningTaskEventType.END, lrt));
Assert.assertEquals(OperationState.NOT_EXECUTED, result.getResults().get(0).getState());
lrt.setResult(new OperationResult(OperationState.CREATED));
result = processor.process(new LongRunningTaskEvent(LongRunningTaskEventType.END, lrt));
Assert.assertEquals(OperationState.NOT_EXECUTED, result.getResults().get(0).getState());
lrt.setResult(new OperationResult(OperationState.RUNNING));
result = processor.process(new LongRunningTaskEvent(LongRunningTaskEventType.END, lrt));
Assert.assertEquals(OperationState.NOT_EXECUTED, result.getResults().get(0).getState());
//
longRunningTaskManager.cancel(lrt.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