use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto in project CzechIdMng by bcvsolutions.
the class DefaultLongRunningTaskManagerIntegrationTest method testRunSimpleTaskSync.
@Test
public void testRunSimpleTaskSync() throws InterruptedException, ExecutionException {
String expectedResult = "TEST_SUCCESS_01_S";
LongRunningTaskExecutor<String> taskExecutor = new TestSimpleLongRunningTaskExecutor(expectedResult);
assertNull(taskExecutor.getLongRunningTaskId());
//
String result = manager.executeSync(taskExecutor);
//
IdmLongRunningTaskDto longRunningTask = service.get(taskExecutor.getLongRunningTaskId());
assertNotNull(longRunningTask);
assertEquals(expectedResult, longRunningTask.getTaskDescription());
assertEquals(taskExecutor.getClass().getCanonicalName(), longRunningTask.getTaskType());
assertEquals(configurationService.getInstanceId(), longRunningTask.getInstanceId());
//
assertEquals(expectedResult, result);
//
longRunningTask = service.get(longRunningTask.getId());
assertEquals(OperationState.EXECUTED, longRunningTask.getResult().getState());
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto in project CzechIdMng by bcvsolutions.
the class DefaultLongRunningTaskManagerIntegrationTest method testCancelTaskBeforeStart.
// TODO: locking - start event override canceled state
// @Test
public void testCancelTaskBeforeStart() throws InterruptedException, ExecutionException {
String result = "TEST_SUCCESS_03";
Long count = 50L;
LongRunningTaskExecutor<String> taskExecutor = new TestStopableLongRunningTaskExecutor(result, count);
//
LongRunningFutureTask<String> futureTask = manager.execute(taskExecutor);
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.IdmLongRunningTaskDto in project CzechIdMng by bcvsolutions.
the class DefaultLongRunningTaskManagerIntegrationTest method testRunCountableTask.
@Test
public void testRunCountableTask() throws InterruptedException, ExecutionException {
String result = "TEST_SUCCESS_02";
Long count = 10L;
LongRunningTaskExecutor<String> taskExecutor = new TestCountableLongRunningTaskExecutor(result, count);
//
LongRunningFutureTask<String> futureTask = manager.execute(taskExecutor);
//
assertEquals(result, futureTask.getFutureTask().get());
//
IdmLongRunningTaskDto longRunningTask = service.get(taskExecutor.getLongRunningTaskId());
assertEquals(OperationState.EXECUTED, longRunningTask.getResult().getState());
assertEquals(count, longRunningTask.getCount());
assertEquals(count, longRunningTask.getCounter());
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto in project CzechIdMng by bcvsolutions.
the class DefaultLongRunningTaskManagerIntegrationTest method testRunSimpleTaskAsync.
@Test
public void testRunSimpleTaskAsync() throws InterruptedException, ExecutionException {
String result = "TEST_SUCCESS_01";
LongRunningTaskExecutor<String> taskExecutor = new TestSimpleLongRunningTaskExecutor(result);
assertNull(taskExecutor.getLongRunningTaskId());
//
LongRunningFutureTask<String> futureTask = manager.execute(taskExecutor);
//
IdmLongRunningTaskDto longRunningTask = service.get(taskExecutor.getLongRunningTaskId());
assertNotNull(longRunningTask);
assertEquals(result, longRunningTask.getTaskDescription());
assertEquals(taskExecutor.getClass().getCanonicalName(), longRunningTask.getTaskType());
assertEquals(configurationService.getInstanceId(), longRunningTask.getInstanceId());
//
assertEquals(result, futureTask.getFutureTask().get());
//
longRunningTask = service.get(longRunningTask.getId());
assertEquals(OperationState.EXECUTED, longRunningTask.getResult().getState());
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto 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());
}
Aggregations