use of com.redhat.service.smartevents.manager.models.Work in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorWorkerTest method handleWorkDeletingWithKnownResourceWithoutConnector.
@Transactional
@ParameterizedTest
@EnumSource(value = ManagedResourceStatus.class, names = { "DEPROVISION", "DELETING" })
void handleWorkDeletingWithKnownResourceWithoutConnector(ManagedResourceStatus status) {
Bridge bridge = Fixtures.createBridge();
Processor processor = Fixtures.createProcessor(bridge, ManagedResourceStatus.READY);
processor.setStatus(status);
bridgeDAO.persist(bridge);
processorDAO.persist(processor);
Work work = workManager.schedule(processor);
Processor refreshed = worker.handleWork(work);
assertThat(refreshed.getDependencyStatus()).isEqualTo(ManagedResourceStatus.DELETED);
assertThat(workManager.exists(work)).isFalse();
}
use of com.redhat.service.smartevents.manager.models.Work in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class WorkManagerImpl method recordAttempt.
@Override
@Transactional
public void recordAttempt(Work work) {
if (!exists(work)) {
return;
}
// Work has been serialised by VertX at this point and has therefore lost all affinity with
// a JPA session. We therefore need to first retrieve the entity before updating it.
Work w = workDAO.findById(work.getId());
w.setModifiedAt(ZonedDateTime.now());
w.setAttempts(w.getAttempts() + 1);
}
use of com.redhat.service.smartevents.manager.models.Work in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class WorkManagerImpl method schedule.
@Override
@Transactional(Transactional.TxType.MANDATORY)
public Work schedule(ManagedResource managedResource) {
Work w = workDAO.findByManagedResource(managedResource);
if (w == null) {
w = Work.forResource(managedResource, workerId);
workDAO.persist(w);
if (LOGGER.isInfoEnabled()) {
LOGGER.info(String.format("Scheduling work for '%s' [%s]", w.getManagedResourceId(), w.getType()));
}
}
return w;
}
use of com.redhat.service.smartevents.manager.models.Work in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class WorkManagerImplTest method scheduleDoesNotFireEventForWork.
@Test
void scheduleDoesNotFireEventForWork() {
when(resource.getId()).thenReturn(RESOURCE_ID);
when(workDAO.findByManagedResource(resource)).thenReturn(null);
manager.schedule(resource);
verify(workDAO).persist(workArgumentCaptor.capture());
Work work = workArgumentCaptor.getValue();
assertThat(work).isNotNull();
assertThat(work.getType()).contains(Processor.class.getName());
assertThat(work.getManagedResourceId()).isEqualTo(RESOURCE_ID);
verify(eventBus, never()).requestAndForget(anyString(), any(Work.class));
}
use of com.redhat.service.smartevents.manager.models.Work in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class WorkManagerImplTest method existsForExistingWork.
@Test
void existsForExistingWork() {
Work existing = mock(Work.class);
when(workDAO.findById(anyString())).thenReturn(existing);
assertThat(manager.exists(new Work())).isTrue();
}
Aggregations