Search in sources :

Example 36 with Processor

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

the class Fixtures method createProcessor.

public static Processor createProcessor(Bridge b, String name, ManagedResourceStatus status) {
    Processor p = new Processor();
    p.setName(name);
    p.setStatus(status);
    p.setPublishedAt(ZonedDateTime.now());
    p.setSubmittedAt(ZonedDateTime.now());
    p.setBridge(b);
    p.setShardId(TestConstants.SHARD_ID);
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode objectNode = mapper.createObjectNode();
    objectNode.put("definitionKey", "definitionValue");
    p.setDefinition(objectNode);
    return p;
}
Also used : Processor(com.redhat.service.bridge.manager.models.Processor) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 37 with Processor

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

the class ProcessorWorkerTest method handleWorkDeletingWithKnownResourceWithConnector.

@ParameterizedTest
@MethodSource("srcHandleWorkDeletingWithKnownResourceWithConnector")
void handleWorkDeletingWithKnownResourceWithConnector(ManagedResourceStatus status, ManagedResourceStatus connectorStatusWhenComplete, boolean isWorkComplete) {
    Work work = new Work();
    work.setManagedResourceId(RESOURCE_ID);
    work.setSubmittedAt(ZonedDateTime.now());
    Processor processor = spy(new Processor());
    processor.setStatus(status);
    ConnectorEntity connector = new ConnectorEntity();
    connector.setStatus(ManagedResourceStatus.ACCEPTED);
    when(processorDAO.findById(RESOURCE_ID)).thenReturn(processor);
    when(processorDAO.getEntityManager()).thenReturn(entityManager);
    when(entityManager.merge(processor)).thenReturn(processor);
    when(connectorsDAO.findByProcessorId(processor.getId())).thenReturn(connector);
    doAnswer((i) -> {
        // Emulate ConnectorWorker completing work
        connector.setStatus(connectorStatusWhenComplete);
        return connector;
    }).when(connectorWorker).handleWork(any(Work.class));
    worker.handleWork(work);
    assertThat(processor.getDependencyStatus()).isEqualTo(connectorStatusWhenComplete);
    verify(connectorWorker).handleWork(workArgumentCaptor.capture());
    Work connectorWork = workArgumentCaptor.getValue();
    assertThat(connectorWork).isNotNull();
    assertThat(connectorWork.getId()).isEqualTo(work.getId());
    assertThat(connectorWork.getManagedResourceId()).isEqualTo(connector.getId());
    assertThat(connectorWork.getSubmittedAt()).isEqualTo(work.getSubmittedAt());
    verify(workManager, times(isWorkComplete ? 1 : 0)).complete(any(Work.class));
    verify(processor, atLeastOnce()).setModifiedAt(any(ZonedDateTime.class));
}
Also used : Processor(com.redhat.service.bridge.manager.models.Processor) ZonedDateTime(java.time.ZonedDateTime) Work(com.redhat.service.bridge.manager.models.Work) ConnectorEntity(com.redhat.service.bridge.manager.models.ConnectorEntity) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 38 with Processor

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

the class ProcessorWorkerTest method handleWorkProvisioningWithKnownResourceWithoutConnector.

@ParameterizedTest
@EnumSource(value = ManagedResourceStatus.class, names = { "ACCEPTED", "PROVISIONING" })
void handleWorkProvisioningWithKnownResourceWithoutConnector(ManagedResourceStatus status) {
    Work work = new Work();
    work.setManagedResourceId(RESOURCE_ID);
    work.setSubmittedAt(ZonedDateTime.now());
    Processor processor = new Processor();
    processor.setStatus(status);
    when(processorDAO.findById(RESOURCE_ID)).thenReturn(processor);
    when(processorDAO.getEntityManager()).thenReturn(entityManager);
    when(entityManager.merge(processor)).thenReturn(processor);
    worker.handleWork(work);
    assertThat(processor.getDependencyStatus()).isEqualTo(ManagedResourceStatus.READY);
    verify(workManager).complete(work);
}
Also used : Processor(com.redhat.service.bridge.manager.models.Processor) Work(com.redhat.service.bridge.manager.models.Work) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 39 with Processor

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

the class ProcessorWorkerTest method handleWorkDeletingWithKnownResourceWithoutConnector.

@ParameterizedTest
@EnumSource(value = ManagedResourceStatus.class, names = { "DEPROVISION", "DELETING" })
void handleWorkDeletingWithKnownResourceWithoutConnector(ManagedResourceStatus status) {
    Work work = new Work();
    work.setManagedResourceId(RESOURCE_ID);
    work.setSubmittedAt(ZonedDateTime.now());
    Processor processor = spy(new Processor());
    processor.setStatus(status);
    when(processorDAO.findById(RESOURCE_ID)).thenReturn(processor);
    when(processorDAO.getEntityManager()).thenReturn(entityManager);
    when(entityManager.merge(processor)).thenReturn(processor);
    worker.handleWork(work);
    assertThat(processor.getDependencyStatus()).isEqualTo(ManagedResourceStatus.DELETED);
    verify(workManager).complete(work);
    verify(processor, atLeastOnce()).setModifiedAt(any(ZonedDateTime.class));
}
Also used : Processor(com.redhat.service.bridge.manager.models.Processor) ZonedDateTime(java.time.ZonedDateTime) Work(com.redhat.service.bridge.manager.models.Work) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 40 with Processor

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

the class ProcessorServiceTest method waitForProcessorAndConnectorToFail.

private void waitForProcessorAndConnectorToFail(final Processor processor) {
    // There will be 4 re-tries at 5s each. Add 5s to be certain everything completes.
    await().atMost(25, SECONDS).untilAsserted(() -> {
        Processor p = processorDAO.findById(processor.getId());
        assertThat(p).isNotNull();
        assertThat(p.getStatus()).isEqualTo(ManagedResourceStatus.FAILED);
    });
}
Also used : Processor(com.redhat.service.bridge.manager.models.Processor)

Aggregations

Processor (com.redhat.service.bridge.manager.models.Processor)52 Bridge (com.redhat.service.bridge.manager.models.Bridge)34 QuarkusTest (io.quarkus.test.junit.QuarkusTest)32 Test (org.junit.jupiter.api.Test)32 ProcessorRequest (com.redhat.service.bridge.manager.api.models.requests.ProcessorRequest)14 ConnectorEntity (com.redhat.service.bridge.manager.models.ConnectorEntity)9 BaseAction (com.redhat.service.bridge.infra.models.actions.BaseAction)7 ItemNotFoundException (com.redhat.service.bridge.infra.exceptions.definitions.user.ItemNotFoundException)6 QueryInfo (com.redhat.service.bridge.infra.models.QueryInfo)6 Transactional (javax.transaction.Transactional)6 Connector (com.openshift.cloud.api.connector.models.Connector)5 ProcessorDefinition (com.redhat.service.bridge.infra.models.processors.ProcessorDefinition)5 ConnectorStatusStatus (com.openshift.cloud.api.connector.models.ConnectorStatusStatus)4 InternalPlatformException (com.redhat.service.bridge.infra.exceptions.definitions.platform.InternalPlatformException)4 Work (com.redhat.service.bridge.manager.models.Work)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 ZonedDateTime (java.time.ZonedDateTime)3 ConnectorRequest (com.openshift.cloud.api.connector.models.ConnectorRequest)2 AlreadyExistingItemException (com.redhat.service.bridge.infra.exceptions.definitions.user.AlreadyExistingItemException)2 ProcessorDTO (com.redhat.service.bridge.infra.models.dto.ProcessorDTO)2