Search in sources :

Example 6 with Work

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

the class AbstractWorkerTest method workIsCompletedWhenMaxRetriedExceeded.

@Test
@Transactional
void workIsCompletedWhenMaxRetriedExceeded() {
    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.setAttempts(maxRetries + 1);
    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)

Example 7 with Work

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

the class BridgeWorkerTest method doTestProvisionworkWithKnownResourceAndErrorHandler.

private void doTestProvisionworkWithKnownResourceAndErrorHandler(ManagedResourceStatus status, ManagedResourceStatus dependencyStatusWhenComplete, boolean throwRhoasError, boolean isWorkComplete, boolean errorHandlerProcessorPresent) {
    Bridge bridge = Fixtures.createBridge();
    bridge.setId(TestConstants.DEFAULT_BRIDGE_ID);
    bridge.setStatus(status);
    bridge.setDefinition(new BridgeDefinition(createWebhookAction()));
    bridgeDAO.persist(bridge);
    Work work = workManager.schedule(bridge);
    List<Processor> processors = errorHandlerProcessorPresent ? List.of(createErrorHandlerProcessor(bridge)) : Collections.emptyList();
    when(processorServiceMock.getHiddenProcessors(TestConstants.DEFAULT_BRIDGE_ID, TestConstants.DEFAULT_CUSTOMER_ID)).thenReturn(new ListResult<>(processors, 0, processors.size()));
    if (throwRhoasError) {
        when(rhoasServiceMock.createTopicAndGrantAccessFor(any(), any())).thenThrow(new InternalPlatformException("error"));
    }
    Bridge refreshed = worker.handleWork(work);
    verify(rhoasServiceMock).createTopicAndGrantAccessFor(TEST_TOPIC_NAME, RhoasTopicAccessType.CONSUMER_AND_PRODUCER);
    verify(rhoasServiceMock, times(throwRhoasError ? 0 : 1)).createTopicAndGrantAccessFor(TEST_ERROR_HANDLER_TOPIC_NAME, RhoasTopicAccessType.CONSUMER_AND_PRODUCER);
    verify(processorServiceMock, times(throwRhoasError || errorHandlerProcessorPresent ? 0 : 1)).createErrorHandlerProcessor(eq(bridge.getId()), eq(TestConstants.DEFAULT_CUSTOMER_ID), eq(TestConstants.DEFAULT_USER_NAME), any());
    assertThat(refreshed.getDependencyStatus()).isEqualTo(dependencyStatusWhenComplete);
    assertThat(workManager.exists(work)).isNotEqualTo(isWorkComplete);
}
Also used : Processor(com.redhat.service.smartevents.manager.models.Processor) InternalPlatformException(com.redhat.service.smartevents.infra.exceptions.definitions.platform.InternalPlatformException) Work(com.redhat.service.smartevents.manager.models.Work) BridgeDefinition(com.redhat.service.smartevents.infra.models.bridges.BridgeDefinition) Bridge(com.redhat.service.smartevents.manager.models.Bridge)

Example 8 with Work

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

the class BridgeWorkerTest method testDeletionWorkWithKnownResourceAndErrorHandler.

@Transactional
@ParameterizedTest
@MethodSource("deletionWorkWithKnownResourceParams")
void testDeletionWorkWithKnownResourceAndErrorHandler(ManagedResourceStatus status, ManagedResourceStatus dependencyStatusWhenComplete, boolean throwRhoasError, boolean isWorkComplete) {
    Bridge bridge = Fixtures.createBridge();
    bridge.setId(TestConstants.DEFAULT_BRIDGE_ID);
    bridge.setStatus(status);
    bridge.setDefinition(new BridgeDefinition(createWebhookAction()));
    bridgeDAO.persist(bridge);
    Work work = workManager.schedule(bridge);
    when(processorServiceMock.getHiddenProcessors(TestConstants.DEFAULT_BRIDGE_ID, TestConstants.DEFAULT_CUSTOMER_ID)).thenReturn(new ListResult<>(List.of(createErrorHandlerProcessor(bridge)), 0, 1));
    Bridge refreshed = worker.handleWork(work);
    assertThat(refreshed.getDependencyStatus()).isNotEqualTo(dependencyStatusWhenComplete);
    assertThat(workManager.exists(work)).isTrue();
    when(processorServiceMock.getHiddenProcessors(TestConstants.DEFAULT_BRIDGE_ID, TestConstants.DEFAULT_CUSTOMER_ID)).thenReturn(new ListResult<>(Collections.emptyList(), 0, 0));
    if (throwRhoasError) {
        doThrow(new InternalPlatformException("error")).when(rhoasServiceMock).deleteTopicAndRevokeAccessFor(any(), any());
        Bridge refreshed2 = worker.handleWork(work);
        verify(rhoasServiceMock).deleteTopicAndRevokeAccessFor(TEST_TOPIC_NAME, RhoasTopicAccessType.CONSUMER_AND_PRODUCER);
        verify(rhoasServiceMock, never()).deleteTopicAndRevokeAccessFor(TEST_ERROR_HANDLER_TOPIC_NAME, RhoasTopicAccessType.CONSUMER_AND_PRODUCER);
        assertThat(refreshed2.getDependencyStatus()).isEqualTo(dependencyStatusWhenComplete);
    } else {
        Bridge refreshed2 = worker.handleWork(work);
        verify(rhoasServiceMock).deleteTopicAndRevokeAccessFor(TEST_TOPIC_NAME, RhoasTopicAccessType.CONSUMER_AND_PRODUCER);
        verify(rhoasServiceMock).deleteTopicAndRevokeAccessFor(TEST_ERROR_HANDLER_TOPIC_NAME, RhoasTopicAccessType.CONSUMER_AND_PRODUCER);
        assertThat(refreshed2.getDependencyStatus()).isEqualTo(dependencyStatusWhenComplete);
    }
    assertThat(workManager.exists(work)).isNotEqualTo(isWorkComplete);
}
Also used : InternalPlatformException(com.redhat.service.smartevents.infra.exceptions.definitions.platform.InternalPlatformException) Work(com.redhat.service.smartevents.manager.models.Work) BridgeDefinition(com.redhat.service.smartevents.infra.models.bridges.BridgeDefinition) 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 9 with Work

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

the class BridgeWorkerTest method handleWorkProvisioningWithUnknownResource.

@Test
void handleWorkProvisioningWithUnknownResource() {
    Work work = new Work();
    work.setManagedResourceId(TEST_RESOURCE_ID);
    assertThatCode(() -> worker.handleWork(work)).isInstanceOf(IllegalStateException.class);
}
Also used : Work(com.redhat.service.smartevents.manager.models.Work) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with Work

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

the class BridgeWorkerTest method testProvisionWorkWithKnownResource.

@Transactional
@ParameterizedTest
@MethodSource("provisionWorkWithKnownResourceParams")
void testProvisionWorkWithKnownResource(ManagedResourceStatus status, ManagedResourceStatus dependencyStatusWhenComplete, boolean throwRhoasError, boolean isWorkComplete) {
    Bridge bridge = Fixtures.createBridge();
    bridge.setStatus(status);
    bridgeDAO.persist(bridge);
    Work work = workManager.schedule(bridge);
    if (throwRhoasError) {
        when(rhoasServiceMock.createTopicAndGrantAccessFor(any(), any())).thenThrow(new InternalPlatformException("error"));
    }
    Bridge refreshed = worker.handleWork(work);
    assertThat(refreshed.getDependencyStatus()).isEqualTo(dependencyStatusWhenComplete);
    assertThat(workManager.exists(work)).isNotEqualTo(isWorkComplete);
    verify(rhoasServiceMock).createTopicAndGrantAccessFor(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)

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