use of org.junit.Assert.assertEquals in project CzechIdMng by bcvsolutions.
the class AbstractSchedulableStatefulExecutorIntegrationTest method testContinueWithRequiresNewAsync.
@Test
public void testContinueWithRequiresNewAsync() throws Exception {
getHelper().setConfigurationValue(SchedulerConfiguration.PROPERTY_TASK_ASYNCHRONOUS_ENABLED, true);
try {
List<IdmIdentityDto> identities = createTestIdentities(3);
//
TestIdentityIntegrationExecutor executor = new TestIdentityIntegrationExecutor();
executor.dtos = identities;
executor.continueOnException = true;
executor.requireNewTransaction = true;
String changeLastName = "last-name-update";
executor.changeLastName = changeLastName;
executor.exceptionOnItem = 2;
//
longRunningTaskManager.execute(executor);
Function<String, Boolean> continueFunction = res -> {
return longRunningTaskManager.getLongRunningTask(executor).getResultState() != OperationState.EXECUTED;
};
getHelper().waitForResult(continueFunction);
//
IdmLongRunningTaskDto taskDto = longRunningTaskService.get(executor.getLongRunningTaskId(), getContext());
Assert.assertEquals(3, taskDto.getCount().intValue());
Assert.assertEquals(2, taskDto.getSuccessItemCount().intValue());
Assert.assertEquals(1, taskDto.getFailedItemCount().intValue());
// TODO: asynchronously => in new transaction each item => commited. How to solve it?
} finally {
getHelper().setConfigurationValue(SchedulerConfiguration.PROPERTY_TASK_ASYNCHRONOUS_ENABLED, false);
}
}
use of org.junit.Assert.assertEquals in project CzechIdMng by bcvsolutions.
the class AbstractSchedulableStatefulExecutorIntegrationTest method testContinueWithoutRequiresNewAsync.
@Test
public void testContinueWithoutRequiresNewAsync() throws Exception {
getHelper().setConfigurationValue(SchedulerConfiguration.PROPERTY_TASK_ASYNCHRONOUS_ENABLED, true);
try {
List<IdmIdentityDto> identities = createTestIdentities(3);
//
TestIdentityIntegrationExecutor executor = new TestIdentityIntegrationExecutor();
executor.dtos = identities;
executor.continueOnException = true;
executor.requireNewTransaction = false;
String changeLastName = "last-name-update";
executor.changeLastName = changeLastName;
executor.exceptionOnItem = 2;
//
longRunningTaskManager.execute(executor);
// wait for start (with optimization, when task was already processed)
Function<String, Boolean> continueFunction = res -> {
return longRunningTaskManager.getLongRunningTask(executor).getResultState() != OperationState.EXECUTED;
};
getHelper().waitForResult(continueFunction);
//
Assert.assertNotNull(executor.getLongRunningTaskId());
IdmLongRunningTaskDto taskDto = longRunningTaskService.get(executor.getLongRunningTaskId(), getContext());
Assert.assertEquals(3, taskDto.getCount().intValue());
Assert.assertEquals(2, taskDto.getSuccessItemCount().intValue());
Assert.assertEquals(1, taskDto.getFailedItemCount().intValue());
// TODO: asynchronously => in new transaction each item => commited. How to solve it?
} finally {
getHelper().setConfigurationValue(SchedulerConfiguration.PROPERTY_TASK_ASYNCHRONOUS_ENABLED, false);
}
}
use of org.junit.Assert.assertEquals in project CzechIdMng by bcvsolutions.
the class AbstractSchedulableStatefulExecutorIntegrationTest method testNotContinueWithoutRequiresNewAsync.
@Test
public void testNotContinueWithoutRequiresNewAsync() throws Exception {
getHelper().setConfigurationValue(SchedulerConfiguration.PROPERTY_TASK_ASYNCHRONOUS_ENABLED, true);
try {
List<IdmIdentityDto> identities = createTestIdentities(3);
//
TestIdentityIntegrationExecutor executor = new TestIdentityIntegrationExecutor();
executor.dtos = identities;
executor.continueOnException = false;
executor.requireNewTransaction = false;
String changeLastName = "last-name-update";
executor.changeLastName = changeLastName;
executor.exceptionOnItem = 2;
//
longRunningTaskManager.execute(executor);
Function<String, Boolean> continueFunction = res -> {
return longRunningTaskManager.getLongRunningTask(executor).getResultState() != OperationState.EXCEPTION;
};
getHelper().waitForResult(continueFunction);
//
IdmLongRunningTaskDto taskDto = longRunningTaskService.get(executor.getLongRunningTaskId(), getContext());
Assert.assertEquals(3, taskDto.getCount().intValue());
Assert.assertEquals(1, taskDto.getSuccessItemCount().intValue());
Assert.assertEquals(1, taskDto.getFailedItemCount().intValue());
// TODO: asynchronously => in new transaction each item => commited. How to solve it?
} finally {
getHelper().setConfigurationValue(SchedulerConfiguration.PROPERTY_TASK_ASYNCHRONOUS_ENABLED, false);
}
}
use of org.junit.Assert.assertEquals in project CzechIdMng by bcvsolutions.
the class AbstractSchedulableStatefulExecutorIntegrationTest method testNotContinueWithRequiresNewAsync.
@Test
public void testNotContinueWithRequiresNewAsync() throws Exception {
getHelper().setConfigurationValue(SchedulerConfiguration.PROPERTY_TASK_ASYNCHRONOUS_ENABLED, true);
try {
List<IdmIdentityDto> identities = createTestIdentities(3);
//
TestIdentityIntegrationExecutor executor = new TestIdentityIntegrationExecutor();
executor.dtos = identities;
executor.continueOnException = false;
executor.requireNewTransaction = true;
String changeLastName = "last-name-update";
executor.changeLastName = changeLastName;
executor.exceptionOnItem = 2;
//
longRunningTaskManager.execute(executor);
Function<String, Boolean> continueFunction = res -> {
return longRunningTaskManager.getLongRunningTask(executor).getResultState() != OperationState.EXCEPTION;
};
getHelper().waitForResult(continueFunction);
//
IdmLongRunningTaskDto taskDto = longRunningTaskService.get(executor.getLongRunningTaskId(), getContext());
Assert.assertEquals(3, taskDto.getCount().intValue());
Assert.assertEquals(1, taskDto.getSuccessItemCount().intValue());
Assert.assertEquals(1, taskDto.getFailedItemCount().intValue());
// TODO: asynchronously => in new transaction each item => commited. How to solve it?
} finally {
getHelper().setConfigurationValue(SchedulerConfiguration.PROPERTY_TASK_ASYNCHRONOUS_ENABLED, false);
}
}
use of org.junit.Assert.assertEquals in project CzechIdMng by bcvsolutions.
the class DefaultLongRunningTaskManagerIntegrationTest method testInterruptRunningTask.
@Test
public void testInterruptRunningTask() throws InterruptedException, ExecutionException {
String result = "TEST_SUCCESS_05";
Long count = 100L;
LongRunningTaskExecutor<String> taskExecutor = new TestStopableLongRunningTaskExecutor(result, count);
//
manager.execute(taskExecutor);
IdmLongRunningTaskDto longRunningTask = manager.getLongRunningTask(taskExecutor);
// task has to be marked as running immediately
Assert.assertEquals(OperationState.RUNNING, longRunningTask.getResult().getState());
//
Function<String, Boolean> continueFunction = res -> {
return !manager.getLongRunningTask(taskExecutor).isRunning();
};
getHelper().waitForResult(continueFunction);
//
longRunningTask = service.get(taskExecutor.getLongRunningTaskId());
assertEquals(OperationState.RUNNING, longRunningTask.getResult().getState());
assertEquals(count, longRunningTask.getCount());
assertTrue(longRunningTask.isRunning());
//
assertTrue(manager.interrupt(taskExecutor.getLongRunningTaskId()));
//
longRunningTask = service.get(taskExecutor.getLongRunningTaskId());
assertNotEquals(OperationState.RUNNING, longRunningTask.getResult().getState());
assertEquals(count, longRunningTask.getCount());
assertNotEquals(count, longRunningTask.getCounter());
assertFalse(longRunningTask.isRunning());
}
Aggregations