use of eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto in project CzechIdMng by bcvsolutions.
the class EntityEventStartProcessor method process.
@Override
public EventResult<IdmEntityEventDto> process(EntityEvent<IdmEntityEventDto> event) {
IdmEntityEventDto entity = event.getContent();
//
entity = entityEventManager.saveResult(entity.getId(), new OperationResultDto.Builder(OperationState.RUNNING).build());
event.setContent(entity);
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto in project CzechIdMng by bcvsolutions.
the class DefaultEntityEventManagerIntergationTest method testMultiThreadEventProcessing.
@Test
public void testMultiThreadEventProcessing() {
List<IdmEntityEventDto> events = new ArrayList<>();
try {
helper.setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, false);
helper.disable(EntityEventDeleteExecutedProcessor.class);
// 15s
int count = 250;
// create events
for (int i = 0; i < count; i++) {
MockOwner mockOwner = new MockOwner();
IdmEntityEventDto entityEvent = new IdmEntityEventDto();
entityEvent.setOwnerType(mockOwner.getClass().getCanonicalName());
entityEvent.setEventType("empty");
entityEvent.setOwnerId((UUID) mockOwner.getId());
entityEvent.setContent(mockOwner);
entityEvent.setInstanceId(configurationService.getInstanceId());
entityEvent.setResult(new OperationResultDto(OperationState.CREATED));
entityEvent.setPriority(PriorityType.NORMAL);
events.add(entityEventService.save(entityEvent));
}
//
IdmEntityEventFilter filter = new IdmEntityEventFilter();
filter.setOwnerType(MockOwner.class.getCanonicalName());
filter.setStates(Lists.newArrayList(OperationState.CREATED));
Assert.assertEquals(count, entityEventService.find(filter, new PageRequest(0, 1)).getTotalElements());
//
// execute
helper.setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, true);
//
// wait for executed events
helper.waitForResult(res -> {
return entityEventService.find(filter, new PageRequest(0, 1)).getTotalElements() != 0;
}, 1000, Integer.MAX_VALUE);
//
// check what happened
filter.setStates(Lists.newArrayList(OperationState.EXECUTED));
Assert.assertEquals(count, entityEventService.find(filter, new PageRequest(0, 1)).getTotalElements());
} finally {
events.forEach(e -> entityEventService.delete(e));
helper.setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, false);
helper.enable(EntityEventDeleteExecutedProcessor.class);
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto in project CzechIdMng by bcvsolutions.
the class DefaultEntityEventManagerUnitTest method testResurrectEventWithDeletedContent.
@Test(expected = EventContentDeletedException.class)
public void testResurrectEventWithDeletedContent() {
IdmEntityEventDto entityEvent = new IdmEntityEventDto(UUID.randomUUID());
entityEvent.setOwnerType(IdmIdentity.class.getCanonicalName());
entityEvent.setOwnerId(UUID.randomUUID());
entityEvent.setEventType(CoreEventType.NOTIFY.name());
//
when(lookupService.lookupDto(IdmIdentity.class, entityEvent.getOwnerId())).thenReturn(null);
//
eventManager.toEvent(entityEvent);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto in project CzechIdMng by bcvsolutions.
the class DefaultEntityEventManagerUnitTest method testCreatedEventsDistinctByOwner.
@Test
public void testCreatedEventsDistinctByOwner() {
List<IdmEntityEventDto> highEvents = new ArrayList<>();
DateTime created = new DateTime();
UUID ownerId = UUID.randomUUID();
IdmEntityEventDto highEventOne = new IdmEntityEventDto(UUID.randomUUID());
highEventOne.setCreated(created.minusMillis(11));
highEventOne.setPriority(PriorityType.HIGH);
highEventOne.setOwnerId(ownerId);
highEvents.add(highEventOne);
IdmEntityEventDto highEventTwo = new IdmEntityEventDto(UUID.randomUUID());
highEventTwo.setCreated(created.minusMillis(21));
highEventTwo.setPriority(PriorityType.HIGH);
highEventTwo.setOwnerId(ownerId);
highEvents.add(highEventTwo);
IdmEntityEventDto highEventThree = new IdmEntityEventDto(UUID.randomUUID());
highEventThree.setCreated(created.minusMillis(2));
highEventThree.setPriority(PriorityType.HIGH);
highEventThree.setOwnerId(ownerId);
highEvents.add(highEventThree);
when(entityEventService.findToExecute(any(), any(DateTime.class), eq(PriorityType.HIGH), any())).thenReturn(new PageImpl<>(highEvents));
//
List<IdmEntityEventDto> normalEvents = new ArrayList<>();
IdmEntityEventDto normalEventOne = new IdmEntityEventDto(UUID.randomUUID());
normalEventOne.setCreated(created.minusMillis(18));
normalEventOne.setPriority(PriorityType.NORMAL);
normalEventOne.setOwnerId(ownerId);
normalEvents.add(normalEventOne);
IdmEntityEventDto normalEventTwo = new IdmEntityEventDto(UUID.randomUUID());
normalEventTwo.setCreated(created.minusMillis(1));
normalEventTwo.setPriority(PriorityType.NORMAL);
normalEventTwo.setOwnerId(ownerId);
normalEvents.add(normalEventTwo);
IdmEntityEventDto normalEventThree = new IdmEntityEventDto(UUID.randomUUID());
normalEventThree.setCreated(created.minusMillis(3));
normalEventThree.setPriority(PriorityType.NORMAL);
normalEventThree.setOwnerId(ownerId);
normalEvents.add(normalEventThree);
when(entityEventService.findToExecute(any(), any(DateTime.class), eq(PriorityType.NORMAL), any())).thenReturn(new PageImpl<>(normalEvents));
//
List<IdmEntityEventDto> events = eventManager.getCreatedEvents("instance");
//
// normalEventTwo (high now)
Assert.assertEquals(1, events.size());
Assert.assertEquals(PriorityType.HIGH, events.get(0).getPriority());
Assert.assertEquals(normalEventTwo.getId(), events.get(0).getId());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto in project CzechIdMng by bcvsolutions.
the class DefaultEntityEventManagerUnitTest method testCreatedEventsRemoveOlderDuplicates.
@Test
public void testCreatedEventsRemoveOlderDuplicates() {
List<IdmEntityEventDto> highEvents = new ArrayList<>();
DateTime created = new DateTime();
UUID ownerId = UUID.randomUUID();
IdmEntityEventDto highEventOne = new IdmEntityEventDto(UUID.randomUUID());
highEventOne.setCreated(created.minusMillis(11));
highEventOne.setPriority(PriorityType.HIGH);
highEventOne.setOwnerId(UUID.randomUUID());
highEvents.add(highEventOne);
IdmEntityEventDto highEventTwo = new IdmEntityEventDto(UUID.randomUUID());
highEventTwo.setCreated(created.minusMillis(21));
highEventTwo.setPriority(PriorityType.HIGH);
highEventTwo.setOwnerId(ownerId);
highEvents.add(highEventTwo);
IdmEntityEventDto highEventThree = new IdmEntityEventDto(UUID.randomUUID());
highEventThree.setCreated(created.minusMillis(2));
highEventThree.setPriority(PriorityType.HIGH);
highEventThree.setOwnerId(ownerId);
highEvents.add(highEventThree);
when(entityEventService.findToExecute(any(), any(DateTime.class), eq(PriorityType.HIGH), any())).thenReturn(new PageImpl<>(highEvents));
//
List<IdmEntityEventDto> normalEvents = new ArrayList<>();
IdmEntityEventDto normalEventOne = new IdmEntityEventDto(UUID.randomUUID());
normalEventOne.setCreated(created.minusMillis(18));
normalEventOne.setPriority(PriorityType.NORMAL);
normalEventOne.setOwnerId(UUID.randomUUID());
normalEvents.add(normalEventOne);
IdmEntityEventDto normalEventTwo = new IdmEntityEventDto(UUID.randomUUID());
normalEventTwo.setCreated(created.minusMillis(1));
normalEventTwo.setPriority(PriorityType.NORMAL);
normalEventTwo.setOwnerId(ownerId);
normalEvents.add(normalEventTwo);
IdmEntityEventDto normalEventThree = new IdmEntityEventDto(UUID.randomUUID());
normalEventThree.setCreated(created.minusMillis(2));
normalEventThree.setPriority(PriorityType.NORMAL);
normalEventThree.setOwnerId(ownerId);
normalEvents.add(normalEventThree);
when(entityEventService.findToExecute(any(), any(DateTime.class), eq(PriorityType.NORMAL), any())).thenReturn(new PageImpl<>(normalEvents));
//
List<IdmEntityEventDto> events = eventManager.getCreatedEvents("instance");
//
// normalEventTwo (high now) - highEventOne - normalEventOne
Assert.assertEquals(3, events.size());
Assert.assertEquals(PriorityType.HIGH, events.get(0).getPriority());
Assert.assertEquals(normalEventTwo.getId(), events.get(0).getId());
Assert.assertEquals(highEventOne.getId(), events.get(1).getId());
Assert.assertEquals(normalEventOne.getId(), events.get(2).getId());
}
Aggregations