Search in sources :

Example 6 with StopExternalDatabaseRequest

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);
}
Also used : StopExternalDatabaseFailed(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StopExternalDatabaseFailed) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) Event(reactor.bus.Event) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) StopExternalDatabaseRequest(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StopExternalDatabaseRequest) DatabaseAvailabilityType(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.database.DatabaseAvailabilityType) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings)

Aggregations

Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)6 StopExternalDatabaseRequest (com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StopExternalDatabaseRequest)6 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)6 ResourceEvent (com.sequenceiq.cloudbreak.event.ResourceEvent)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 Event (reactor.bus.Event)5 Test (org.junit.jupiter.api.Test)4 DatabaseAvailabilityType (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.database.DatabaseAvailabilityType)2 StopExternalDatabaseResult (com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StopExternalDatabaseResult)2 PollerException (com.dyngr.exception.PollerException)1 PollerStoppedException (com.dyngr.exception.PollerStoppedException)1 UserBreakException (com.dyngr.exception.UserBreakException)1 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)1 StopExternalDatabaseFailed (com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StopExternalDatabaseFailed)1 ValueSource (org.junit.jupiter.params.provider.ValueSource)1 MockitoSettings (org.mockito.junit.jupiter.MockitoSettings)1