use of com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StopExternalDatabaseRequest in project cloudbreak by hortonworks.
the class StopExternalDatabaseHandlerTest method acceptCatchErrors.
@ParameterizedTest
@ValueSource(classes = { UserBreakException.class, PollerStoppedException.class, PollerException.class, Exception.class })
@MockitoSettings(strictness = Strictness.LENIENT)
void acceptCatchErrors(Class<? extends Exception> exceptionClass) {
doAnswer(a -> {
throw exceptionClass.getDeclaredConstructor().newInstance();
}).when(stopService).stopDatabase(any(), any(DatabaseAvailabilityType.class), any());
DetailedEnvironmentResponse environment = new DetailedEnvironmentResponse();
environment.setCloudPlatform("AWS");
when(environmentClientService.getByCrn(anyString())).thenReturn(environment);
when(externalDatabaseConfig.isExternalDatabasePauseSupportedFor(any())).thenReturn(true);
Stack stack = buildStack(DatabaseAvailabilityType.HA);
stack.setType(StackType.WORKLOAD);
stack.getCluster().setDatabaseServerCrn(DATABASE_CRN);
when(stackService.getById(anyLong())).thenReturn(stack);
StopExternalDatabaseRequest request = new StopExternalDatabaseRequest(STACK_ID, "selector", "resourceName", "crn");
Event<StopExternalDatabaseRequest> event = new Event<>(EVENT_HEADERS, request);
underTest.accept(event);
verify(stopService).stopDatabase(eq(stack.getCluster()), eq(DatabaseAvailabilityType.HA), eq(environment));
verify(stackUpdaterService).updateStatus(eq(STACK_ID), eq(DetailedStackStatus.EXTERNAL_DATABASE_STOP_IN_PROGRESS), eq(ResourceEvent.CLUSTER_EXTERNAL_DATABASE_STOP_COMMANCED), eq("External database stop in progress"));
verify(stackUpdaterService, never()).updateStatus(eq(STACK_ID), eq(DetailedStackStatus.EXTERNAL_DATABASE_STOP_FINISHED), eq(ResourceEvent.CLUSTER_EXTERNAL_DATABASE_CREATION_FINISHED), anyString());
ArgumentCaptor<Event<StopExternalDatabaseFailed>> eventCaptor = ArgumentCaptor.forClass(Event.class);
verify(eventBus).notify(eq("StopExternalDatabaseFailed"), eventCaptor.capture());
Event<StopExternalDatabaseFailed> value = eventCaptor.getValue();
assertThat(value.getHeaders()).isEqualTo(EVENT_HEADERS);
assertThat(value.getData().getResourceCrn()).isEqualTo(DATABASE_CRN);
}
Aggregations