use of com.redhat.service.bridge.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.bridge.manager.models.Work in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class WorkManagerImplTest method scheduleDoesNotFireEventForExistingWork.
@Test
void scheduleDoesNotFireEventForExistingWork() {
Work existing = mock(Work.class);
when(workDAO.findByManagedResource(resource)).thenReturn(existing);
manager.schedule(resource);
verify(eventBus, never()).requestAndForget(anyString(), any(Work.class));
}
use of com.redhat.service.bridge.manager.models.Work in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ConnectorWorkerTest method handleWorkProvisioningWithKnownResourceMultiplePasses.
@ParameterizedTest
@EnumSource(value = ManagedResourceStatus.class, names = { "ACCEPTED", "PROVISIONING" })
void handleWorkProvisioningWithKnownResourceMultiplePasses(ManagedResourceStatus status) {
Work work = new Work();
work.setManagedResourceId(RESOURCE_ID);
work.setSubmittedAt(ZonedDateTime.now());
ConnectorEntity connectorEntity = spy(new ConnectorEntity());
connectorEntity.setStatus(status);
Connector connector = new Connector();
connector.setStatus(new ConnectorStatusStatus().state(ConnectorState.READY));
when(connectorsDAO.findById(RESOURCE_ID)).thenReturn(connectorEntity);
when(connectorsDAO.getEntityManager()).thenReturn(entityManager);
when(entityManager.merge(connectorEntity)).thenReturn(connectorEntity);
// Managed Connector will not be available immediately
when(connectorsApi.getConnector(connectorEntity)).thenReturn(null, connector);
worker.handleWork(work);
verify(rhoasService).createTopicAndGrantAccessFor(connectorEntity.getTopicName(), RhoasTopicAccessType.PRODUCER);
verify(connectorsApi).createConnector(connectorEntity);
assertThat(connectorEntity.getStatus()).isEqualTo(ManagedResourceStatus.PROVISIONING);
assertThat(connectorEntity.getDependencyStatus()).isEqualTo(ManagedResourceStatus.PROVISIONING);
// This emulates a subsequent invocation by WorkManager
worker.handleWork(work);
verify(rhoasService, times(2)).createTopicAndGrantAccessFor(connectorEntity.getTopicName(), RhoasTopicAccessType.PRODUCER);
verify(connectorsApi, atMostOnce()).createConnector(connectorEntity);
assertThat(connectorEntity.getPublishedAt()).isNotNull();
assertThat(connectorEntity.getStatus()).isEqualTo(ManagedResourceStatus.READY);
assertThat(connectorEntity.getDependencyStatus()).isEqualTo(ManagedResourceStatus.READY);
verify(workManager, never()).complete(work);
verify(connectorEntity, atLeastOnce()).setModifiedAt(any(ZonedDateTime.class));
}
use of com.redhat.service.bridge.manager.models.Work in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorWorkerTest method handleWorkProvisioningWithKnownResourceWithConnector.
@ParameterizedTest
@MethodSource("srcHandleWorkProvisioningWithKnownResourceWithConnector")
void handleWorkProvisioningWithKnownResourceWithConnector(ManagedResourceStatus status, ManagedResourceStatus connectorStatusWhenComplete, boolean isWorkComplete) {
Work work = new Work();
work.setManagedResourceId(RESOURCE_ID);
work.setSubmittedAt(ZonedDateTime.now());
Processor processor = new Processor();
processor.setStatus(status);
ConnectorEntity connector = new ConnectorEntity();
connector.setStatus(ManagedResourceStatus.ACCEPTED);
when(processorDAO.findById(RESOURCE_ID)).thenReturn(processor);
when(processorDAO.getEntityManager()).thenReturn(entityManager);
when(entityManager.merge(processor)).thenReturn(processor);
when(connectorsDAO.findByProcessorId(processor.getId())).thenReturn(connector);
doAnswer((i) -> {
// Emulate ConnectorWorker completing work
connector.setStatus(connectorStatusWhenComplete);
return connector;
}).when(connectorWorker).handleWork(any(Work.class));
worker.handleWork(work);
assertThat(processor.getDependencyStatus()).isEqualTo(connectorStatusWhenComplete);
verify(connectorWorker).handleWork(workArgumentCaptor.capture());
Work connectorWork = workArgumentCaptor.getValue();
assertThat(connectorWork).isNotNull();
assertThat(connectorWork.getId()).isEqualTo(work.getId());
assertThat(connectorWork.getManagedResourceId()).isEqualTo(connector.getId());
assertThat(connectorWork.getSubmittedAt()).isEqualTo(work.getSubmittedAt());
verify(workManager, times(isWorkComplete ? 1 : 0)).complete(any(Work.class));
}
use of com.redhat.service.bridge.manager.models.Work in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class WorkManagerImplTest method scheduleFiresEventForNewWork.
@Test
void scheduleFiresEventForNewWork() {
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).requestAndForget(anyString(), eq(work));
}
Aggregations