use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto in project CzechIdMng by bcvsolutions.
the class AbstractSchedulableStatefulExecutorIntegrationTest method testExecute.
/**
* Tests the stateful execution method of the task by the following
* scenario:
* 1. find all identities to process
* 2. process retrieved identities
* 3. persist processing log
* 4. save processed identities into processed queue
*
* Second execution run:
* 1. find all identities to process - same as first run
* 2. call process retrieved identities - all have been processed already
* 3. check processing log - nothing new was processed, therefore must be empty
* 4. check processed items queue did not change
*
* Third run:
* 1. find all identities to process - returns empty list
* 2. check processing log - nothing was processed
* 3. check processed items queue - must be empty
* @throws Exception
*/
@Test
public void testExecute() throws Exception {
TestIdentityIntegrationExecutor executor = new TestIdentityIntegrationExecutor();
AutowireHelper.autowire(executor);
// manually prepare control entities - normally scheduler will take care of it itself
IdmScheduledTaskDto scheduledTask = createIdmScheduledTask(UUID.randomUUID().toString());
IdmLongRunningTaskDto longRunningTask = createIdmLongRunningTask(scheduledTask, TestIdentityIntegrationExecutor.class);
executor.setLongRunningTaskId(longRunningTask.getId());
// first run
List<IdmIdentityDto> itemsToProcess = findTestIdentities();
// set executor data
executor.dtos = itemsToProcess;
//
Boolean result = executor.process();
Page<IdmProcessedTaskItemDto> queueItems = itemService.findQueueItems(scheduledTask, null);
Page<IdmProcessedTaskItemDto> logItems = itemService.findLogItems(longRunningTask, null);
//
assertTrue(result);
assertEquals(longRunningTask.getScheduledTask(), scheduledTask.getId());
assertEquals(itemsToProcess.size(), queueItems.getTotalElements());
assertEquals(itemsToProcess.size(), logItems.getTotalElements());
assertEquals(Long.valueOf(itemsToProcess.size()), executor.getCount());
assertEquals(Long.valueOf(itemsToProcess.size()), executor.getCounter());
SchedulerTestUtils.checkLogItems(longRunningTask, IdmIdentityDto.class, logItems);
SchedulerTestUtils.checkQueueItems(scheduledTask, IdmIdentityDto.class, queueItems);
//
// second run
//
longRunningTask = createIdmLongRunningTask(scheduledTask, TestIdentityIntegrationExecutor.class);
executor.setLongRunningTaskId(longRunningTask.getId());
executor.dtos = itemsToProcess;
//
result = executor.process();
queueItems = itemService.findQueueItems(scheduledTask, null);
logItems = itemService.findLogItems(longRunningTask, null);
//
assertTrue(result);
assertEquals(itemsToProcess.size(), queueItems.getTotalElements());
assertEquals(0, logItems.getTotalElements());
assertEquals(Long.valueOf(0), executor.getCount());
assertEquals(Long.valueOf(0), executor.getCounter());
SchedulerTestUtils.checkQueueItems(scheduledTask, IdmIdentityDto.class, queueItems);
//
// third run
//
longRunningTask = createIdmLongRunningTask(scheduledTask, TestIdentityIntegrationExecutor.class);
executor.setLongRunningTaskId(longRunningTask.getId());
//
result = executor.process();
queueItems = itemService.findQueueItems(scheduledTask, null);
logItems = itemService.findLogItems(longRunningTask, null);
longRunningTask = longRunningTaskManager.getLongRunningTask(longRunningTask.getId());
//
assertTrue(result);
assertEquals(0, queueItems.getTotalElements());
assertEquals(0, logItems.getTotalElements());
assertEquals(Long.valueOf(0), executor.getCount());
assertEquals(Long.valueOf(0), executor.getCounter());
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto in project CzechIdMng by bcvsolutions.
the class AbstractSchedulableStatefulExecutorUnitTest method testIsInProcessedQueue.
@Test
public void testIsInProcessedQueue() {
IdmScheduledTaskDto scheduledTask = new IdmScheduledTaskDto();
UUID randomId = UUID.randomUUID();
scheduledTask.setId(randomId);
when(scheduledTaskService.findByLongRunningTaskId(randomId)).thenReturn(scheduledTask);
//
List<IdmProcessedTaskItemDto> items = Lists.newArrayList(new IdmProcessedTaskItemDto());
//
when(itemService.find(ArgumentMatchers.any(IdmProcessedTaskItemFilter.class), ArgumentMatchers.any(Pageable.class))).thenReturn(new PageImpl<>(items));
//
when(executor.getLongRunningTaskId()).thenReturn(randomId);
//
boolean inProcessedQueue = executor.isInProcessedQueue(getTestIdentityDto());
assertTrue(inProcessedQueue);
//
when(itemService.find(ArgumentMatchers.any(IdmProcessedTaskItemFilter.class), ArgumentMatchers.any(Pageable.class))).thenReturn(new PageImpl<>(Lists.newArrayList()));
//
inProcessedQueue = executor.isInProcessedQueue(getTestIdentityDto());
assertFalse(inProcessedQueue);
//
verify(executor, times(2)).isInProcessedQueue(ArgumentMatchers.any(IdmIdentityDto.class));
verify(scheduledTaskService, times(1)).findByLongRunningTaskId(randomId);
verify(itemService, times(2)).find(ArgumentMatchers.any(IdmProcessedTaskItemFilter.class), ArgumentMatchers.any(Pageable.class));
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto in project CzechIdMng by bcvsolutions.
the class AbstractSchedulableStatefulExecutorUnitTest method testDontTouchProcessed.
@Test
public void testDontTouchProcessed() {
IdmLongRunningTaskDto lrt = new IdmLongRunningTaskDto();
lrt.setResult(new OperationResult.Builder(OperationState.RUNNING).build());
IdmScheduledTaskDto scheduledTask = new IdmScheduledTaskDto();
scheduledTask.setId(UUID.randomUUID());
//
IdmIdentityDto dto1 = getTestIdentityDto();
IdmIdentityDto dto2 = getTestIdentityDto();
// stubs
doReturn(true).when(executor).isInProcessedQueue(ArgumentMatchers.any(IdmIdentityDto.class));
doReturn(Lists.newArrayList(dto1.getId(), dto2.getId())).when(executor).getProcessedItemRefsFromQueue();
// matchers
when(longRunningTaskService.get(ArgumentMatchers.any())).thenReturn(lrt);
when(executor.getItemsToProcess((Pageable) ArgumentMatchers.any())).thenReturn(new PageImpl<>(Lists.newArrayList(dto1, dto2))).thenReturn(new PageImpl<>(Lists.newArrayList()));
when(entityManager.getDelegate()).thenReturn(hiberanteSession);
when(hiberanteSession.isOpen()).thenReturn(false);
//
//
Boolean processingResult = executor.process();
assertTrue(processingResult);
//
//
verify(longRunningTaskService, times(2)).get(ArgumentMatchers.any());
//
verify(executor, times(1)).getItemsToProcess((Pageable) ArgumentMatchers.any());
verify(executor, times(1)).isInProcessedQueue(dto1);
verify(executor, times(1)).isInProcessedQueue(dto2);
verify(executor, times(1)).getProcessedItemRefsFromQueue();
verify(entityManager, times(2)).getDelegate();
verify(hiberanteSession, times(2)).isOpen();
verify(executor, never()).getScheduledTaskId();
verify(executor, never()).removeFromProcessedQueue(ArgumentMatchers.any(UUID.class));
verify(executor, never()).addToProcessedQueue(ArgumentMatchers.any(IdmIdentityDto.class), ArgumentMatchers.any(OperationResult.class));
verify(executor, never()).processItem(ArgumentMatchers.any(IdmIdentityDto.class));
verify(itemService, never()).saveInternal(ArgumentMatchers.any(IdmProcessedTaskItemDto.class));
verify(itemService, never()).deleteInternal(ArgumentMatchers.any(IdmProcessedTaskItemDto.class));
verify(itemService, never()).find(ArgumentMatchers.any(IdmProcessedTaskItemFilter.class), ArgumentMatchers.any(Pageable.class));
}
Aggregations