use of com.redhat.service.smartevents.manager.models.Work in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorWorker method delegate.
private Processor delegate(Work work, Processor processor) {
// Get Processor's Connector for which work needs completing
final ConnectorEntity connectorEntity = getConnectorEntity(processor);
// Delegate to the ConnectorWorker however mimic that the Work originated from the Processor.
Work connectorEntityWork = Work.forDependentResource(connectorEntity, work);
ConnectorEntity updatedConnectorEntity = connectorWorker.handleWork(connectorEntityWork);
processor.setDependencyStatus(updatedConnectorEntity.getStatus());
// If the Connector failed we should mark the Processor as failed too
if (updatedConnectorEntity.getStatus() == ManagedResourceStatus.FAILED) {
processor.setStatus(ManagedResourceStatus.FAILED);
}
return persist(processor);
}
use of com.redhat.service.smartevents.manager.models.Work in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class WorkManagerImplTest method completeWhenNotExists.
@Test
void completeWhenNotExists() {
when(workDAO.findById(anyString())).thenReturn(null);
manager.complete(new Work());
verify(workDAO, never()).deleteById(anyString());
}
use of com.redhat.service.smartevents.manager.models.Work in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class WorkManagerImplTest method processWorkQueue.
@Test
void processWorkQueue() {
Work work1 = new Work();
work1.setType("Type1");
Work work2 = new Work();
work2.setType("Type2");
when(workDAO.findByWorkerId(anyString())).thenReturn(List.of(work1, work2));
manager.processWorkQueue();
verify(eventBus).requestAndForget("Type1", work1);
verify(eventBus).requestAndForget("Type2", work2);
}
use of com.redhat.service.smartevents.manager.models.Work in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class WorkManagerImplTest method recordAttemptIncreasesRetry.
@Test
void recordAttemptIncreasesRetry() {
Work work = new Work();
work.setAttempts(0);
when(workDAO.findById(anyString())).thenReturn(work);
manager.recordAttempt(work);
assertThat(work.getAttempts()).isEqualTo(1);
// A bit of an overkill checking our mocked invocation was called... but it is important
verify(workDAO, atLeastOnce()).findById(work.getId());
}
use of com.redhat.service.smartevents.manager.models.Work in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class AbstractWorkerTest method workIsCompletedWhenTimedOut.
@Test
@Transactional
void workIsCompletedWhenTimedOut() {
Bridge bridge = Fixtures.createBridge();
// Persist Bridge so that it can be found by the Worker
bridgeDAO.persist(bridge);
Work work = workManager.schedule(bridge);
assertThat(workManager.exists(work)).isTrue();
work.setSubmittedAt(ZonedDateTime.now().minusSeconds(timeoutSeconds * 2L));
worker.handleWork(work);
assertThat(bridge.getStatus()).isEqualTo(ManagedResourceStatus.FAILED);
assertThat(workManager.exists(work)).isFalse();
}
Aggregations