Search in sources :

Example 16 with IdmLongRunningTaskDto

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());
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 17 with IdmLongRunningTaskDto

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());
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto)

Example 18 with IdmLongRunningTaskDto

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());
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 19 with IdmLongRunningTaskDto

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());
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 20 with IdmLongRunningTaskDto

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());
}
Also used : TestTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.TestTaskExecutor) Autowired(org.springframework.beans.factory.annotation.Autowired) ConfigurationService(eu.bcvsolutions.idm.core.api.service.ConfigurationService) Function(java.util.function.Function) DefaultLongRunningTaskManager(eu.bcvsolutions.idm.core.scheduler.service.impl.DefaultLongRunningTaskManager) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) TestHelper(eu.bcvsolutions.idm.test.api.TestHelper) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) 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) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) LongRunningTaskManager(eu.bcvsolutions.idm.core.scheduler.api.service.LongRunningTaskManager) Assert.assertNotNull(org.junit.Assert.assertNotNull) LongRunningFutureTask(eu.bcvsolutions.idm.core.scheduler.api.dto.LongRunningFutureTask) Assert.assertTrue(org.junit.Assert.assertTrue) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) Test(org.junit.Test) LongRunningTaskExecutor(eu.bcvsolutions.idm.core.scheduler.api.service.LongRunningTaskExecutor) ApplicationContext(org.springframework.context.ApplicationContext) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) ExecutionException(java.util.concurrent.ExecutionException) Assert.assertNull(org.junit.Assert.assertNull) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) Assert.assertFalse(org.junit.Assert.assertFalse) Assert.assertEquals(org.junit.Assert.assertEquals) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmLongRunningTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto)56 Test (org.junit.Test)32 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)29 IdmScheduledTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto)14 IdmProcessedTaskItemDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto)13 IdmLongRunningTaskFilter (eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter)13 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)11 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)10 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)9 Transactional (org.springframework.transaction.annotation.Transactional)7 LocalDate (org.joda.time.LocalDate)6 LongRunningFutureTask (eu.bcvsolutions.idm.core.scheduler.api.dto.LongRunningFutureTask)5 IdmPasswordDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto)4 Task (eu.bcvsolutions.idm.core.scheduler.api.dto.Task)4 UUID (java.util.UUID)4 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)3 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)3 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)3 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)3 ResultModel (eu.bcvsolutions.idm.core.api.dto.ResultModel)3