Search in sources :

Example 16 with Work

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();
}
Also used : Processor(com.redhat.service.smartevents.manager.models.Processor) Work(com.redhat.service.smartevents.manager.models.Work) Bridge(com.redhat.service.smartevents.manager.models.Bridge) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Transactional(javax.transaction.Transactional)

Example 17 with Work

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

Example 18 with Work

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

Example 19 with Work

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

Example 20 with Work

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

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