Search in sources :

Example 56 with DBStack

use of com.sequenceiq.redbeams.domain.stack.DBStack in project cloudbreak by hortonworks.

the class UpdateDatabaseServerRegistrationHandlerTest method doAcceptTestWhenFailureDatabaseServerConfigNotFound.

@Test
void doAcceptTestWhenFailureDatabaseServerConfigNotFound() throws Exception {
    DBStack dbStack = getDBStack();
    when(dbStackService.getById(anyLong())).thenReturn(dbStack);
    UpdateDatabaseServerRegistrationRequest request = getRequest();
    when(event.getData()).thenReturn(request);
    when(databaseServerConfigService.getByCrn(CRN)).thenReturn(Optional.empty());
    Selectable selectable = new ExceptionCatcherEventHandlerTestSupport<>(underTest).doAccept(event);
    verifyFailureEvent(selectable);
    Exception e = extractException(selectable);
    assertThat(e).isInstanceOf(IllegalStateException.class);
    assertThat(e).hasMessage("Cannot find database server " + CRN);
}
Also used : UpdateDatabaseServerRegistrationRequest(com.sequenceiq.redbeams.flow.redbeams.provision.event.register.UpdateDatabaseServerRegistrationRequest) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) Test(org.junit.jupiter.api.Test)

Example 57 with DBStack

use of com.sequenceiq.redbeams.domain.stack.DBStack in project cloudbreak by hortonworks.

the class UpdateDatabaseServerRegistrationHandlerTest method doAcceptTestWhenFailureCloudResourcePortNotFound.

@Test
void doAcceptTestWhenFailureCloudResourcePortNotFound() throws Exception {
    DBStack dbStack = getDBStack();
    when(dbStackService.getById(anyLong())).thenReturn(dbStack);
    UpdateDatabaseServerRegistrationRequest request = getRequest();
    when(event.getData()).thenReturn(request);
    when(cloudResourceHelper.getResourceTypeFromList(eq(ResourceType.RDS_HOSTNAME), any())).thenReturn(Optional.of(mock(CloudResource.class)));
    when(cloudResourceHelper.getResourceTypeFromList(eq(ResourceType.RDS_PORT), any())).thenReturn(Optional.empty());
    DatabaseServerConfig originalDatabaseServerConfig = getOriginalDatabaseServerConfig();
    when(databaseServerConfigService.getByCrn(CRN)).thenReturn(Optional.of(originalDatabaseServerConfig));
    Selectable selectable = new ExceptionCatcherEventHandlerTestSupport<>(underTest).doAccept(event);
    verifyFailureEvent(selectable);
    Exception e = extractException(selectable);
    assertThat(e).isInstanceOf(IllegalStateException.class);
    assertThat(e).hasMessage("DB port not found for allocated database.");
}
Also used : UpdateDatabaseServerRegistrationRequest(com.sequenceiq.redbeams.flow.redbeams.provision.event.register.UpdateDatabaseServerRegistrationRequest) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) DatabaseServerConfig(com.sequenceiq.redbeams.domain.DatabaseServerConfig) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) Test(org.junit.jupiter.api.Test)

Example 58 with DBStack

use of com.sequenceiq.redbeams.domain.stack.DBStack in project cloudbreak by hortonworks.

the class StartDatabaseServerFailedActionTest method shouldUpdateStatusWithUknownErrorAndIncrementMetricOnPrepare.

@Test
public void shouldUpdateStatusWithUknownErrorAndIncrementMetricOnPrepare() {
    RedbeamsFailureEvent event = new RedbeamsFailureEvent(RESOURCE_ID, null);
    Optional<DBStack> dbStackOptional = Optional.of(dbStack);
    when(dbStackStatusUpdater.updateStatus(RESOURCE_ID, DetailedDBStackStatus.START_FAILED, "Unknown error")).thenReturn(dbStackOptional);
    victim.prepareExecution(event, null);
    verify(metricService).incrementMetricCounter(MetricType.DB_START_FAILED, dbStackOptional);
}
Also used : RedbeamsFailureEvent(com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsFailureEvent) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) Test(org.junit.jupiter.api.Test)

Example 59 with DBStack

use of com.sequenceiq.redbeams.domain.stack.DBStack in project cloudbreak by hortonworks.

the class StartDatabaseServerFailedActionTest method shouldUpdateStatusAndIncrementMetricOnPrepare.

@Test
public void shouldUpdateStatusAndIncrementMetricOnPrepare() {
    RedbeamsFailureEvent event = new RedbeamsFailureEvent(RESOURCE_ID, exception);
    Optional<DBStack> dbStackOptional = Optional.of(dbStack);
    when(dbStackStatusUpdater.updateStatus(RESOURCE_ID, DetailedDBStackStatus.START_FAILED, null)).thenReturn(dbStackOptional);
    victim.prepareExecution(event, null);
    verify(metricService).incrementMetricCounter(MetricType.DB_START_FAILED, dbStackOptional);
}
Also used : RedbeamsFailureEvent(com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsFailureEvent) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) Test(org.junit.jupiter.api.Test)

Example 60 with DBStack

use of com.sequenceiq.redbeams.domain.stack.DBStack in project cloudbreak by hortonworks.

the class StartDatabaseServerFinishedActionTest method shouldUpdateStatusOnPrepare.

@Test
public void shouldUpdateStatusOnPrepare() {
    Optional<DBStack> dbStackOptional = Optional.of(dbStack);
    when(dbStackStatusUpdater.updateStatus(RESOURCE_ID, DetailedDBStackStatus.STARTED)).thenReturn(dbStackOptional);
    StartDatabaseServerSuccess event = new StartDatabaseServerSuccess(RESOURCE_ID);
    victim.prepareExecution(event, null);
    verify(dbStackStatusUpdater).updateStatus(RESOURCE_ID, DetailedDBStackStatus.STARTED);
    verify(metricService).incrementMetricCounter(MetricType.DB_START_FINISHED, dbStackOptional);
}
Also used : StartDatabaseServerSuccess(com.sequenceiq.redbeams.flow.redbeams.start.event.StartDatabaseServerSuccess) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) Test(org.junit.jupiter.api.Test)

Aggregations

DBStack (com.sequenceiq.redbeams.domain.stack.DBStack)83 Test (org.junit.jupiter.api.Test)28 DatabaseServerConfig (com.sequenceiq.redbeams.domain.DatabaseServerConfig)17 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)17 Test (org.junit.Test)13 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)8 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)7 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)7 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)7 DatabaseStack (com.sequenceiq.cloudbreak.cloud.model.DatabaseStack)7 DatabaseServerV4Response (com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response)7 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)6 SslConfig (com.sequenceiq.redbeams.domain.stack.SslConfig)6 Credential (com.sequenceiq.redbeams.dto.Credential)6 RedbeamsFailureEvent (com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsFailureEvent)6 Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)5 CloudDatabaseServerSslCertificate (com.sequenceiq.cloudbreak.cloud.model.database.CloudDatabaseServerSslCertificate)5 RedbeamsEvent (com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 Location (com.sequenceiq.cloudbreak.cloud.model.Location)4