use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmProcessedTaskItemDtoServiceTest method testCreateItem.
@Test
public void testCreateItem() {
IdmScheduledTaskDto d = helper.createSchedulableTask();
IdmLongRunningTaskDto lrt = this.createLongRunningTask(d);
IdmProcessedTaskItemDto item = helper.prepareProcessedItem(lrt);
//
IdmProcessedTaskItemDto retrieved = service.get(service.saveInternal(item).getId());
//
assertNotNull(retrieved);
assertEquals(item.getReferencedDtoType(), retrieved.getReferencedDtoType());
assertEquals(item.getReferencedEntityId(), retrieved.getReferencedEntityId());
assertEquals(item.getLongRunningTask(), retrieved.getLongRunningTask());
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmProcessedTaskItemDtoServiceTest method createLongRunningTask.
public IdmLongRunningTaskDto createLongRunningTask(IdmScheduledTaskDto d) {
IdmLongRunningTaskDto lrt = new IdmLongRunningTaskDto();
lrt.setTaskDescription("task description");
lrt.setResult(new OperationResult.Builder(OperationState.CREATED).build());
lrt.setInstanceId("test instance");
lrt.setScheduledTask(d.getId());
lrt.setTaskType(TestSchedulableTask.class.getCanonicalName());
return longrunningService.saveInternal(lrt);
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmProcessedTaskItemDtoServiceTest method testImmutable.
@Test
public void testImmutable() {
IdmScheduledTaskDto d = helper.createSchedulableTask();
IdmLongRunningTaskDto lrt = this.createLongRunningTask(d);
IdmProcessedTaskItemDto item = helper.prepareProcessedItem(lrt);
IdmProcessedTaskItemDto saved = service.get(service.saveInternal(item).getId());
// set fields to new value
saved.setReferencedDtoType(IdmIdentityContractDto.class.getCanonicalName());
saved.setReferencedEntityId(UUID.randomUUID());
saved.setLongRunningTask(this.createLongRunningTask(d).getId());
//
IdmProcessedTaskItemDto retrieved = service.get(service.saveInternal(saved).getId());
// fields must not update
assertEquals(item.getLongRunningTask(), retrieved.getLongRunningTask());
assertEquals(item.getReferencedDtoType(), retrieved.getReferencedDtoType());
assertEquals(item.getReferencedEntityId(), retrieved.getReferencedEntityId());
//
assertNotEquals(item.getLongRunningTask(), saved.getLongRunningTask());
assertNotEquals(item.getReferencedDtoType(), saved.getReferencedDtoType());
assertNotEquals(item.getReferencedEntityId(), saved.getReferencedEntityId());
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmProcessedTaskItemDtoServiceTest method testItemTypeReference.
@Test
public void testItemTypeReference() {
IdmScheduledTaskDto d = helper.createSchedulableTask();
IdmLongRunningTaskDto lrt = this.createLongRunningTask(d);
IdmProcessedTaskItemDto item = helper.prepareProcessedItem(lrt);
//
try {
item.setScheduledTaskQueueOwner(d.getId());
service.get(service.saveInternal(item).getId());
fail("Both log and queue association is forbidden.");
} catch (CoreException e) {
assertNotNull(e.getMessage());
}
//
try {
item.setScheduledTaskQueueOwner(null);
item.setLongRunningTask(null);
service.get(service.saveInternal(item).getId());
fail("Empty log and queue association is forbidden.");
} catch (CoreException e) {
assertNotNull(e.getMessage());
}
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto 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);
//
Function<String, Boolean> continueFunction = res -> {
return !manager.getLongRunningTask(taskExecutor).isRunning();
};
helper.waitForResult(continueFunction);
//
IdmLongRunningTaskDto 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