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();
}
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);
}
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);
}
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);
}
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);
}
Aggregations