Search in sources :

Example 36 with Processor

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

the class BridgeWorkerTest method createErrorHandlerProcessor.

private static Processor createErrorHandlerProcessor(Bridge bridge) {
    Processor processor = Fixtures.createProcessor(bridge, ManagedResourceStatus.READY);
    processor.setType(ProcessorType.ERROR_HANDLER);
    return processor;
}
Also used : Processor(com.redhat.service.smartevents.manager.models.Processor)

Example 37 with Processor

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

the class ConnectorWorkerTest method handleWorkDeletingWithKnownResourceMultiplePasses.

@Transactional
@ParameterizedTest
@MethodSource("provideArgsForDeleteTest")
void handleWorkDeletingWithKnownResourceMultiplePasses(ManagedResourceStatus resourceStatus, ConnectorState connectorState, boolean useSourceConnectorEntity, RhoasTopicAccessType expectedTopicAccessType) {
    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.setStatus(new ConnectorStatusStatus().state(connectorState));
    // Managed Connector will initially be available before it is deleted
    when(connectorsApi.getConnector(connectorEntity.getConnectorExternalId())).thenReturn(connector, (Connector) null);
    ConnectorEntity refreshed = worker.handleWork(work);
    if (connectorState != ConnectorState.DELETED) {
        assertThat(refreshed.getStatus()).isEqualTo(ManagedResourceStatus.DELETING);
        assertThat(refreshed.getDependencyStatus()).isEqualTo(ManagedResourceStatus.DELETING);
        verify(rhoasService, never()).deleteTopicAndRevokeAccessFor(connectorEntity.getTopicName(), RhoasTopicAccessType.PRODUCER);
        verify(connectorsApi).deleteConnector(connectorEntity.getConnectorExternalId());
        // This emulates a subsequent invocation by WorkManager
        refreshed = worker.handleWork(work);
    }
    verify(rhoasService).deleteTopicAndRevokeAccessFor(connectorEntity.getTopicName(), expectedTopicAccessType);
    assertThat(connectorsDAO.findById(connectorEntity.getId())).isNull();
    assertThat(refreshed.getStatus()).isEqualTo(ManagedResourceStatus.DELETED);
    assertThat(refreshed.getDependencyStatus()).isEqualTo(ManagedResourceStatus.DELETED);
    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)

Example 38 with Processor

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

the class ProcessorWorkerTest method handleWorkProvisioningWithKnownResourceWithoutConnector.

@Transactional
@ParameterizedTest
@EnumSource(value = ManagedResourceStatus.class, names = { "ACCEPTED", "PREPARING" })
void handleWorkProvisioningWithKnownResourceWithoutConnector(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.READY);
    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 39 with Processor

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

the class ProcessorWorkerTest method handleWorkDeletingWithKnownResourceWithConnector.

@Transactional
@ParameterizedTest
@MethodSource("srcHandleWorkDeletingWithKnownResourceWithConnector")
void handleWorkDeletingWithKnownResourceWithConnector(ManagedResourceStatus status, ManagedResourceStatus statusWhenComplete, ManagedResourceStatus dependencyStatusWhenComplete, boolean isWorkComplete) {
    Bridge bridge = Fixtures.createBridge();
    Processor processor = Fixtures.createProcessor(bridge, ManagedResourceStatus.READY);
    processor.setStatus(status);
    ConnectorEntity connectorEntity = Fixtures.createSinkConnector(processor, ManagedResourceStatus.ACCEPTED);
    connectorEntity.setStatus(ManagedResourceStatus.ACCEPTED);
    bridgeDAO.persist(bridge);
    processorDAO.persist(processor);
    connectorsDAO.persist(connectorEntity);
    Work work = workManager.schedule(processor);
    doAnswer((i) -> {
        // Emulate ConnectorWorker completing work
        connectorEntity.setStatus(dependencyStatusWhenComplete);
        return connectorEntity;
    }).when(connectorWorker).handleWork(any(Work.class));
    Processor refreshed = worker.handleWork(work);
    assertThat(refreshed.getStatus()).isEqualTo(statusWhenComplete);
    assertThat(refreshed.getDependencyStatus()).isEqualTo(dependencyStatusWhenComplete);
    ArgumentCaptor<Work> workArgumentCaptor = ArgumentCaptor.forClass(Work.class);
    verify(connectorWorker).handleWork(workArgumentCaptor.capture());
    Work connectorWork = workArgumentCaptor.getValue();
    assertThat(connectorWork).isNotNull();
    assertThat(connectorWork.getId()).isEqualTo(work.getId());
    assertThat(connectorWork.getManagedResourceId()).isEqualTo(connectorEntity.getId());
    assertThat(connectorWork.getSubmittedAt()).isEqualTo(work.getSubmittedAt());
    assertThat(workManager.exists(work)).isNotEqualTo(isWorkComplete);
}
Also used : 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) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource) Transactional(javax.transaction.Transactional)

Example 40 with Processor

use of com.redhat.service.smartevents.manager.models.Processor 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)

Aggregations

Processor (com.redhat.service.smartevents.manager.models.Processor)82 Bridge (com.redhat.service.smartevents.manager.models.Bridge)45 QuarkusTest (io.quarkus.test.junit.QuarkusTest)36 Test (org.junit.jupiter.api.Test)36 Transactional (javax.transaction.Transactional)20 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 Action (com.redhat.service.smartevents.infra.models.gateways.Action)13 QueryProcessorResourceInfo (com.redhat.service.smartevents.infra.models.QueryProcessorResourceInfo)12 ProcessorDefinition (com.redhat.service.smartevents.infra.models.processors.ProcessorDefinition)9 MethodSource (org.junit.jupiter.params.provider.MethodSource)9 ProcessorRequest (com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest)8 ConnectorEntity (com.redhat.service.smartevents.manager.models.ConnectorEntity)8 Connector (com.openshift.cloud.api.connector.models.Connector)7 Work (com.redhat.service.smartevents.manager.models.Work)7 ConnectorStatusStatus (com.openshift.cloud.api.connector.models.ConnectorStatusStatus)6 ProcessorResponse (com.redhat.service.smartevents.manager.api.models.responses.ProcessorResponse)6 KafkaTopicAction (com.redhat.service.smartevents.processor.actions.kafkatopic.KafkaTopicAction)6 InternalPlatformException (com.redhat.service.smartevents.infra.exceptions.definitions.platform.InternalPlatformException)5 BaseFilter (com.redhat.service.smartevents.infra.models.filters.BaseFilter)5 SlackAction (com.redhat.service.smartevents.processor.actions.slack.SlackAction)5