Search in sources :

Example 21 with Work

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

Example 22 with Work

use of com.redhat.service.smartevents.manager.models.Work in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class WorkManagerImplTest method completeWhenExists.

@Test
void completeWhenExists() {
    Work work = new Work();
    work.setAttempts(0);
    when(workDAO.findById(anyString())).thenReturn(work);
    manager.complete(work);
    verify(workDAO).deleteById(work.getId());
}
Also used : Work(com.redhat.service.smartevents.manager.models.Work) Test(org.junit.jupiter.api.Test)

Example 23 with Work

use of com.redhat.service.smartevents.manager.models.Work in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class AbstractWorkerTest method workIsCompletedWhenResourceIsNotFound.

@Test
@Transactional
void workIsCompletedWhenResourceIsNotFound() {
    Bridge bridge = Fixtures.createBridge();
    // It is intentional that we do not persist the Bridge here
    Work work = workManager.schedule(bridge);
    assertThat(workManager.exists(work)).isTrue();
    assertThatThrownBy(() -> worker.handleWork(work)).isInstanceOf(IllegalStateException.class);
}
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)

Example 24 with Work

use of com.redhat.service.smartevents.manager.models.Work in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BridgeWorkerTest method testDeletionWorkWithKnownResource.

@Transactional
@ParameterizedTest
@MethodSource("deletionWorkWithKnownResourceParams")
void testDeletionWorkWithKnownResource(ManagedResourceStatus status, ManagedResourceStatus dependencyStatusWhenComplete, boolean throwRhoasError, boolean isWorkComplete) {
    Bridge bridge = Fixtures.createBridge();
    bridge.setStatus(status);
    bridgeDAO.persist(bridge);
    Work work = workManager.schedule(bridge);
    when(processorServiceMock.getHiddenProcessors(any(), any())).thenReturn(new ListResult<>(Collections.emptyList(), 0, 0));
    if (throwRhoasError) {
        doThrow(new InternalPlatformException("error")).when(rhoasServiceMock).deleteTopicAndRevokeAccessFor(eq(TEST_TOPIC_NAME), any());
    }
    Bridge refreshed = worker.handleWork(work);
    assertThat(refreshed.getDependencyStatus()).isEqualTo(dependencyStatusWhenComplete);
    assertThat(workManager.exists(work)).isNotEqualTo(isWorkComplete);
    verify(rhoasServiceMock).deleteTopicAndRevokeAccessFor(TEST_TOPIC_NAME, RhoasTopicAccessType.CONSUMER_AND_PRODUCER);
}
Also used : InternalPlatformException(com.redhat.service.smartevents.infra.exceptions.definitions.platform.InternalPlatformException) Work(com.redhat.service.smartevents.manager.models.Work) Bridge(com.redhat.service.smartevents.manager.models.Bridge) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource) Transactional(javax.transaction.Transactional)

Example 25 with Work

use of com.redhat.service.smartevents.manager.models.Work in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ConnectorWorkerTest method handleWorkProvisioningWithKnownResourceMultiplePasses.

@Transactional
@ParameterizedTest
@MethodSource("provideArgsForCreateTest")
void handleWorkProvisioningWithKnownResourceMultiplePasses(ManagedResourceStatus resourceStatus, ConnectorState connectorState, boolean useSourceConnectorEntity, RhoasTopicAccessType expectedTopicAccessType, ManagedResourceStatus expectedResourceStatus) {
    Bridge bridge = Fixtures.createBridge();
    Processor processor = Fixtures.createProcessor(bridge, ManagedResourceStatus.READY);
    ConnectorEntity connectorEntity = useSourceConnectorEntity ? Fixtures.createSourceConnector(processor, resourceStatus) : Fixtures.createSinkConnector(processor, resourceStatus);
    // The publishedAt date is set by the Worker so reset that set by the Fixture
    connectorEntity.setPublishedAt(null);
    bridgeDAO.persist(bridge);
    processorDAO.persist(processor);
    connectorsDAO.persist(connectorEntity);
    Work work = workManager.schedule(connectorEntity);
    Connector connector = new Connector();
    connector.setId(TEST_CONNECTOR_EXTERNAL_ID);
    connector.setStatus(new ConnectorStatusStatus().state(connectorState));
    when(connectorsApi.getConnector(TEST_CONNECTOR_EXTERNAL_ID)).thenReturn(null, connector);
    when(connectorsApi.createConnector(connectorEntity)).thenReturn(connector);
    ConnectorEntity refreshed = worker.handleWork(work);
    verify(rhoasService).createTopicAndGrantAccessFor(connectorEntity.getTopicName(), expectedTopicAccessType);
    verify(connectorsApi).createConnector(connectorEntity);
    assertThat(refreshed.getStatus()).isEqualTo(ManagedResourceStatus.PREPARING);
    assertThat(refreshed.getDependencyStatus()).isEqualTo(ManagedResourceStatus.PROVISIONING);
    // This emulates a subsequent invocation by WorkManager
    refreshed = worker.handleWork(work);
    verify(rhoasService, times(2)).createTopicAndGrantAccessFor(connectorEntity.getTopicName(), expectedTopicAccessType);
    verify(connectorsApi, atMostOnce()).createConnector(connectorEntity);
    assertThat(refreshed.getStatus()).isEqualTo(expectedResourceStatus);
    assertThat(refreshed.getDependencyStatus()).isEqualTo(expectedResourceStatus);
    if (expectedResourceStatus == ManagedResourceStatus.READY) {
        assertThat(refreshed.getPublishedAt()).isNotNull();
    } else {
        assertThat(refreshed.getPublishedAt()).isNull();
    }
    assertThat(workManager.exists(work)).isTrue();
}
Also used : Connector(com.openshift.cloud.api.connector.models.Connector) Processor(com.redhat.service.smartevents.manager.models.Processor) ConnectorEntity(com.redhat.service.smartevents.manager.models.ConnectorEntity) Work(com.redhat.service.smartevents.manager.models.Work) Bridge(com.redhat.service.smartevents.manager.models.Bridge) ConnectorStatusStatus(com.openshift.cloud.api.connector.models.ConnectorStatusStatus) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource) 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