Search in sources :

Example 6 with LongRunningTaskExecutor

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());
}
Also used : IdmProcessedTaskItemDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto) TestTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.TestTaskExecutor) Autowired(org.springframework.beans.factory.annotation.Autowired) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) ConfigurationService(eu.bcvsolutions.idm.core.api.service.ConfigurationService) Function(java.util.function.Function) IdmProcessedTaskItemService(eu.bcvsolutions.idm.core.scheduler.api.service.IdmProcessedTaskItemService) ArrayList(java.util.ArrayList) AutowireHelper(eu.bcvsolutions.idm.core.api.utils.AutowireHelper) IdentityDeleteBulkAction(eu.bcvsolutions.idm.core.bulk.action.impl.IdentityDeleteBulkAction) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) After(org.junit.After) IdmLongRunningTaskFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter) ConcurrentExecutionException(eu.bcvsolutions.idm.core.scheduler.api.exception.ConcurrentExecutionException) AbstractLongRunningTaskExecutor(eu.bcvsolutions.idm.core.scheduler.api.service.AbstractLongRunningTaskExecutor) IdmLongRunningTaskService(eu.bcvsolutions.idm.core.scheduler.api.service.IdmLongRunningTaskService) Before(org.junit.Before) EntityNotFoundException(eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) SchedulerConfiguration(eu.bcvsolutions.idm.core.scheduler.api.config.SchedulerConfiguration) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) Assert.assertNotNull(org.junit.Assert.assertNotNull) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) LongRunningFutureTask(eu.bcvsolutions.idm.core.scheduler.api.dto.LongRunningFutureTask) Assert.assertTrue(org.junit.Assert.assertTrue) Set(java.util.Set) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) Test(org.junit.Test) LongRunningTaskExecutor(eu.bcvsolutions.idm.core.scheduler.api.service.LongRunningTaskExecutor) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) ApplicationContext(org.springframework.context.ApplicationContext) TaskNotRecoverableException(eu.bcvsolutions.idm.core.scheduler.exception.TaskNotRecoverableException) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) ExecutionException(java.util.concurrent.ExecutionException) IdmProcessedTaskItemFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmProcessedTaskItemFilter) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) Assert.assertFalse(org.junit.Assert.assertFalse) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test)

Aggregations

LongRunningTaskExecutor (eu.bcvsolutions.idm.core.scheduler.api.service.LongRunningTaskExecutor)6 IdmLongRunningTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto)5 LongRunningFutureTask (eu.bcvsolutions.idm.core.scheduler.api.dto.LongRunningFutureTask)5 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)4 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)4 CoreException (eu.bcvsolutions.idm.core.api.exception.CoreException)4 ConfigurationService (eu.bcvsolutions.idm.core.api.service.ConfigurationService)4 ConcurrentExecutionException (eu.bcvsolutions.idm.core.scheduler.api.exception.ConcurrentExecutionException)4 AbstractLongRunningTaskExecutor (eu.bcvsolutions.idm.core.scheduler.api.service.AbstractLongRunningTaskExecutor)4 IdmLongRunningTaskService (eu.bcvsolutions.idm.core.scheduler.api.service.IdmLongRunningTaskService)4 TestTaskExecutor (eu.bcvsolutions.idm.core.scheduler.task.impl.TestTaskExecutor)4 ExecutionException (java.util.concurrent.ExecutionException)4 Function (java.util.function.Function)4 Assert.assertEquals (org.junit.Assert.assertEquals)4 Assert.assertFalse (org.junit.Assert.assertFalse)4 Assert.assertNotEquals (org.junit.Assert.assertNotEquals)4 Assert.assertNotNull (org.junit.Assert.assertNotNull)4 Assert.assertNull (org.junit.Assert.assertNull)4 Assert.assertTrue (org.junit.Assert.assertTrue)4 Before (org.junit.Before)4