Search in sources :

Example 16 with ProcessorDTO

use of com.redhat.service.smartevents.infra.models.dto.ProcessorDTO in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ManagerClientTest method notifyProcessorStatusChange.

@Test
public void notifyProcessorStatusChange() throws Exception {
    ProcessorDTO processor = TestSupport.newRequestedProcessorDTO();
    stubProcessorUpdate();
    // One update to the manager is expected
    CountDownLatch latch = new CountDownLatch(1);
    addProcessorUpdateRequestListener(latch);
    managerClient.notifyProcessorStatusChange(processor).await().atMost(Duration.ofSeconds(5));
    assertThat(latch.await(60, SECONDS)).isTrue();
    wireMockServer.verify(putRequestedFor(urlEqualTo(SHARD_API_BASE_PATH + "processors")).withRequestBody(equalToJson(objectMapper.writeValueAsString(processor), true, true)).withHeader("Content-Type", equalTo("application/json")));
}
Also used : ProcessorDTO(com.redhat.service.smartevents.infra.models.dto.ProcessorDTO) CountDownLatch(java.util.concurrent.CountDownLatch) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 17 with ProcessorDTO

use of com.redhat.service.smartevents.infra.models.dto.ProcessorDTO in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BridgeExecutorTest method fromDTO.

@Test
public void fromDTO() {
    ProcessorDTO dto = TestSupport.newRequestedProcessorDTO();
    BridgeExecutor bridgeExecutor = BridgeExecutor.fromDTO(dto, "ns", "image");
    assertThat(bridgeExecutor.getMetadata().getNamespace()).isEqualTo("ns");
    assertThat(bridgeExecutor.getMetadata().getName()).isEqualTo(BridgeExecutor.OB_RESOURCE_NAME_PREFIX + TestSupport.PROCESSOR_ID);
    assertThat(bridgeExecutor.getMetadata().getLabels().get(LabelsBuilder.CREATED_BY_LABEL)).isEqualTo(LabelsBuilder.OPERATOR_NAME);
    assertThat(bridgeExecutor.getMetadata().getLabels().get(LabelsBuilder.MANAGED_BY_LABEL)).isEqualTo(LabelsBuilder.OPERATOR_NAME);
    assertThat(bridgeExecutor.getMetadata().getLabels().get(LabelsBuilder.COMPONENT_LABEL)).isEqualTo(BridgeExecutor.COMPONENT_NAME);
    assertThat(bridgeExecutor.getSpec().getProcessorName()).isEqualTo(dto.getName());
    assertThat(bridgeExecutor.getSpec().getId()).isEqualTo(dto.getId());
    assertThat(bridgeExecutor.getSpec().getImage()).isEqualTo("image");
    assertThat(bridgeExecutor.getSpec().getBridgeId()).isEqualTo(TestSupport.BRIDGE_ID);
    assertThat(bridgeExecutor.getSpec().getOwner()).isEqualTo(dto.getOwner());
}
Also used : ProcessorDTO(com.redhat.service.smartevents.infra.models.dto.ProcessorDTO) Test(org.junit.jupiter.api.Test)

Example 18 with ProcessorDTO

use of com.redhat.service.smartevents.infra.models.dto.ProcessorDTO in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ExecutorTestUtils method createProcessor.

public static ProcessorDTO createProcessor(ProcessorType type, ProcessorDefinition definition) {
    ProcessorDTO dto = new ProcessorDTO();
    dto.setType(type);
    dto.setId("processorId-1");
    dto.setName("processorName-1");
    dto.setDefinition(definition);
    dto.setBridgeId("bridgeId-1");
    dto.setCustomerId("jrota");
    dto.setStatus(ManagedResourceStatus.READY);
    dto.setKafkaConnection(createKafkaConnection());
    return dto;
}
Also used : ProcessorDTO(com.redhat.service.smartevents.infra.models.dto.ProcessorDTO)

Example 19 with ProcessorDTO

use of com.redhat.service.smartevents.infra.models.dto.ProcessorDTO in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ManagerSyncServiceTest method testProcessorsAreDeletedWhenDeployed.

@Test
@WithPrometheus
public void testProcessorsAreDeletedWhenDeployed() throws JsonProcessingException, InterruptedException {
    // First check provisioning completed
    doProcessorDeployment();
    // Second check provisioned Processor is deleted
    ProcessorDTO processor = TestSupport.newRequestedProcessorDTO();
    processor.setStatus(ManagedResourceStatus.DEPROVISION);
    stubProcessorsToDeployOrDelete(List.of(processor));
    stubProcessorUpdate();
    String expectedJsonUpdateRequestForDeprovisioning = String.format("{\"id\": \"%s\", \"name\": \"%s\", \"bridgeId\": \"%s\", \"customerId\": \"%s\", \"status\": \"deleting\"}", processor.getId(), processor.getName(), processor.getBridgeId(), processor.getCustomerId());
    // The BridgeExecutorController delete loop does not execute so only one update can be captured
    // See https://issues.redhat.com/browse/MGDOBR-128
    CountDownLatch latch = new CountDownLatch(1);
    addProcessorUpdateRequestListener(latch);
    managerSyncService.doProcessors().await().atMost(Duration.ofSeconds(5));
    assertThat(latch.await(60, TimeUnit.SECONDS)).isTrue();
    assertJsonRequest(expectedJsonUpdateRequestForDeprovisioning, APIConstants.SHARD_API_BASE_PATH + "processors");
}
Also used : ProcessorDTO(com.redhat.service.smartevents.infra.models.dto.ProcessorDTO) CountDownLatch(java.util.concurrent.CountDownLatch) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 20 with ProcessorDTO

use of com.redhat.service.smartevents.infra.models.dto.ProcessorDTO in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ManagerSyncServiceTest method doProcessorDeployment.

private void doProcessorDeployment() throws JsonProcessingException, InterruptedException {
    ProcessorDTO processor = TestSupport.newRequestedProcessorDTO();
    stubProcessorsToDeployOrDelete(Collections.singletonList(processor));
    stubProcessorUpdate();
    // Two updates to the manager are expected (1 provisioning + 1 ready)
    CountDownLatch latch = new CountDownLatch(2);
    addProcessorUpdateRequestListener(latch);
    managerSyncService.doProcessors().await().atMost(Duration.ofSeconds(5));
    String customerNamespace = customerNamespaceProvider.resolveName(TestSupport.CUSTOMER_ID);
    String sanitizedName = BridgeExecutor.resolveResourceName(processor.getId());
    Awaitility.await().atMost(Duration.ofMinutes(3)).pollInterval(Duration.ofSeconds(5)).untilAsserted(() -> {
        kubernetesResourcePatcher.patchReadyDeploymentAsReady(sanitizedName, customerNamespace);
        kubernetesResourcePatcher.patchReadyService(sanitizedName, customerNamespace);
    });
    assertThat(latch.await(60, TimeUnit.SECONDS)).isTrue();
    processor.setStatus(ManagedResourceStatus.READY);
    // the kafka connection is not included in the shard update for the manager
    processor.setKafkaConnection(null);
    assertJsonRequest(objectMapper.writeValueAsString(processor), APIConstants.SHARD_API_BASE_PATH + "processors");
}
Also used : ProcessorDTO(com.redhat.service.smartevents.infra.models.dto.ProcessorDTO) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

ProcessorDTO (com.redhat.service.smartevents.infra.models.dto.ProcessorDTO)33 Test (org.junit.jupiter.api.Test)24 QuarkusTest (io.quarkus.test.junit.QuarkusTest)22 BridgeDTO (com.redhat.service.smartevents.infra.models.dto.BridgeDTO)5 TestSecurity (io.quarkus.test.security.TestSecurity)5 KafkaConnectionDTO (com.redhat.service.smartevents.infra.models.dto.KafkaConnectionDTO)4 Action (com.redhat.service.smartevents.infra.models.gateways.Action)4 ProcessorDefinition (com.redhat.service.smartevents.infra.models.processors.ProcessorDefinition)4 BridgeRequest (com.redhat.service.smartevents.manager.api.models.requests.BridgeRequest)4 ProcessorRequest (com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest)4 BridgeResponse (com.redhat.service.smartevents.manager.api.models.responses.BridgeResponse)4 ActionInvoker (com.redhat.service.smartevents.processor.actions.ActionInvoker)4 TypeRef (io.restassured.common.mapper.TypeRef)4 ArrayList (java.util.ArrayList)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 BaseFilter (com.redhat.service.smartevents.infra.models.filters.BaseFilter)3 StringEquals (com.redhat.service.smartevents.infra.models.filters.StringEquals)3 HashMap (java.util.HashMap)3 ItemNotFoundException (com.redhat.service.smartevents.infra.exceptions.definitions.user.ItemNotFoundException)2