Search in sources :

Example 31 with Processor

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

the class ProcessorDAOTest method testGetProcessorsFilterByNameAndStatus.

@Test
@Transactional
void testGetProcessorsFilterByNameAndStatus() {
    Bridge b = createBridge();
    Processor p = createProcessor(b, "foo");
    createProcessor(b, "bar");
    p.setStatus(READY);
    processorDAO.persist(p);
    ListResult<Processor> results = processorDAO.findByBridgeIdAndCustomerId(b.getId(), b.getCustomerId(), new QueryProcessorResourceInfo(0, 100, filter().by(p.getName()).by(p.getStatus()).build()));
    assertThat(results.getPage()).isZero();
    assertThat(results.getSize()).isEqualTo(1L);
    assertThat(results.getTotal()).isEqualTo(1L);
    assertThat(results.getItems().get(0).getId()).isEqualTo(p.getId());
}
Also used : QueryProcessorResourceInfo(com.redhat.service.smartevents.infra.models.QueryProcessorResourceInfo) Processor(com.redhat.service.smartevents.manager.models.Processor) 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 32 with Processor

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

the class MetricsServiceImplTest method onOperationComplete_forProcessor.

@ParameterizedTest
@EnumSource(MetricsOperation.class)
public void onOperationComplete_forProcessor(MetricsOperation metricsOperation) {
    Bridge bridge = Fixtures.createBridge();
    ManagedResourceStatus status = metricsOperation == MetricsOperation.DELETE ? ManagedResourceStatus.DELETED : ManagedResourceStatus.READY;
    Processor processor = Fixtures.createProcessor(bridge, status);
    processor.setSubmittedAt(ZonedDateTime.now().minusMinutes(4));
    processor.setPublishedAt(ZonedDateTime.now().minusMinutes(3));
    processor.setModifiedAt(ZonedDateTime.now().minusMinutes(2));
    processor.setDeletionRequestedAt(ZonedDateTime.now().minusMinutes(1));
    metricsService.onOperationComplete(processor, metricsOperation);
    List<Tag> expectedTags = createdExpectedTags(processor, metricsOperation);
    assertThat(meterRegistry.counter(operationTotalSuccessCountMetricName, expectedTags).count()).isEqualTo(1.0);
    assertThat(meterRegistry.timer(operatonDurationMetricName, expectedTags).totalTime(TimeUnit.MINUTES)).isNotEqualTo(0);
}
Also used : Processor(com.redhat.service.smartevents.manager.models.Processor) ManagedResourceStatus(com.redhat.service.smartevents.infra.models.dto.ManagedResourceStatus) Tag(io.micrometer.core.instrument.Tag) Bridge(com.redhat.service.smartevents.manager.models.Bridge) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 33 with Processor

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

the class Fixtures method createProcessor.

public static Processor createProcessor(Bridge b, ManagedResourceStatus status) {
    Processor p = new Processor();
    p.setType(ProcessorType.SINK);
    p.setName(TestConstants.DEFAULT_PROCESSOR_NAME);
    p.setStatus(status);
    p.setPublishedAt(ZonedDateTime.now());
    p.setSubmittedAt(ZonedDateTime.now());
    p.setBridge(b);
    p.setShardId(TestConstants.SHARD_ID);
    p.setOwner(TestConstants.DEFAULT_USER_NAME);
    p.setDefinition(new ProcessorDefinition());
    return p;
}
Also used : Processor(com.redhat.service.smartevents.manager.models.Processor) ProcessorDefinition(com.redhat.service.smartevents.infra.models.processors.ProcessorDefinition)

Example 34 with Processor

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

the class TestUtils method waitForProcessorDependenciesToBeReady.

public static Processor waitForProcessorDependenciesToBeReady(ProcessorDAO processorDAO, Processor processor) {
    final List<Processor> processors = new ArrayList<>();
    await().atMost(5, SECONDS).untilAsserted(() -> {
        processors.clear();
        Processor p = processorDAO.findById(processor.getId());
        assertThat(p).isNotNull();
        assertThat(p.getDependencyStatus()).isEqualTo(ManagedResourceStatus.READY);
        processors.add(p);
    });
    return processors.get(0);
}
Also used : Processor(com.redhat.service.smartevents.manager.models.Processor) ArrayList(java.util.ArrayList)

Example 35 with Processor

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

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