Search in sources :

Example 1 with Work

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);
}
Also used : ConnectorEntity(com.redhat.service.smartevents.manager.models.ConnectorEntity) Work(com.redhat.service.smartevents.manager.models.Work)

Example 2 with Work

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());
}
Also used : Work(com.redhat.service.smartevents.manager.models.Work) Test(org.junit.jupiter.api.Test)

Example 3 with Work

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);
}
Also used : Work(com.redhat.service.smartevents.manager.models.Work) Test(org.junit.jupiter.api.Test)

Example 4 with Work

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());
}
Also used : Work(com.redhat.service.smartevents.manager.models.Work) Test(org.junit.jupiter.api.Test)

Example 5 with Work

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();
}
Also used : Work(com.redhat.service.smartevents.manager.models.Work) Bridge(com.redhat.service.smartevents.manager.models.Bridge) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) Transactional(javax.transaction.Transactional)

Aggregations

Work (com.redhat.service.smartevents.manager.models.Work)26 Transactional (javax.transaction.Transactional)14 Bridge (com.redhat.service.smartevents.manager.models.Bridge)13 Test (org.junit.jupiter.api.Test)13 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 Processor (com.redhat.service.smartevents.manager.models.Processor)8 MethodSource (org.junit.jupiter.params.provider.MethodSource)7 QuarkusTest (io.quarkus.test.junit.QuarkusTest)6 ConnectorEntity (com.redhat.service.smartevents.manager.models.ConnectorEntity)5 InternalPlatformException (com.redhat.service.smartevents.infra.exceptions.definitions.platform.InternalPlatformException)4 Connector (com.openshift.cloud.api.connector.models.Connector)2 ConnectorStatusStatus (com.openshift.cloud.api.connector.models.ConnectorStatusStatus)2 BridgeDefinition (com.redhat.service.smartevents.infra.models.bridges.BridgeDefinition)2 EnumSource (org.junit.jupiter.params.provider.EnumSource)2