Search in sources :

Example 16 with TestFailException

use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.

the class DistroXTestDtoBase method withPreferredSubnetsForInstanceNetworkIfMultiAzEnabledOrJustFirst.

public DistroXTestDtoBase<T> withPreferredSubnetsForInstanceNetworkIfMultiAzEnabledOrJustFirst() {
    if (StringUtils.isEmpty(getRequest().getEnvironmentName())) {
        throw new TestFailException("Cannot fetch the preferred subnet without env name, please add it");
    }
    try {
        EnvironmentClient envClient = getTestContext().getMicroserviceClient(EnvironmentClient.class);
        DetailedEnvironmentResponse envResponse = envClient.getDefaultClient().environmentV1Endpoint().getByName(getRequest().getEnvironmentName());
        InstanceGroupNetworkV1Request instanceGroupNetworkV1Request = new InstanceGroupNetworkV1Request();
        InstanceGroupAwsNetworkV1Parameters awsNetworkV1Parameters = new InstanceGroupAwsNetworkV1Parameters();
        if ("AWS_NATIVE".equals(getRequest().getVariant())) {
            awsNetworkV1Parameters.setSubnetIds(new ArrayList<>(envResponse.getNetwork().getPreferedSubnetIds()));
        } else {
            envResponse.getNetwork().getPreferedSubnetIds().stream().filter(s -> !s.equals(envResponse.getNetwork().getPreferedSubnetId())).findFirst().ifPresent(s -> awsNetworkV1Parameters.setSubnetIds(List.of(s)));
        }
        instanceGroupNetworkV1Request.setAws(awsNetworkV1Parameters);
        getRequest().getInstanceGroups().forEach(s -> s.setNetwork(instanceGroupNetworkV1Request));
    } catch (Exception e) {
        String message = "Cannot fetch preferred subnets from " + getRequest().getEnvironmentName();
        throw new TestFailException(message, e);
    }
    return this;
}
Also used : InstanceGroupAwsNetworkV1Parameters(com.sequenceiq.distrox.api.v1.distrox.model.network.aws.InstanceGroupAwsNetworkV1Parameters) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) EnvironmentClient(com.sequenceiq.it.cloudbreak.EnvironmentClient) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) InstanceGroupNetworkV1Request(com.sequenceiq.distrox.api.v1.distrox.model.network.InstanceGroupNetworkV1Request) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException)

Example 17 with TestFailException

use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.

the class DefaultResponseConfigure method thenReturn.

public T thenReturn(R retValue, String message, int statusCode, int times, String clss) {
    if (!parameters.isEmpty()) {
        throw new TestFailException("Mock thenReturn will not take into account url parameters.");
    }
    String crn = testDto.getCrn();
    if (crn != null) {
        pathVariable("mockUuid", crn);
    }
    String retType = clss;
    if (retType == null && retValue != null) {
        retType = retValue.getClass().getName();
    }
    MockResponse body = new MockResponse(retValue, message, getMethod().getHttpMethod().name(), getPath(), times, statusCode, retType);
    executeQuery.executeConfigure(pathVariables(), body);
    return testDto;
}
Also used : MockResponse(com.sequenceiq.it.cloudbreak.testcase.mock.response.MockResponse) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException)

Example 18 with TestFailException

use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.

the class DefaultResponseConfigure method verify.

public T verify() {
    String callsJson;
    if (crnless) {
        callsJson = executeQuery.execute("/tests/calls", w -> w.queryParam("path", pathReplaced(path)), r -> r.readEntity(String.class));
    } else {
        callsJson = executeQuery.execute("/tests/calls/" + testDto.getCrn(), w -> w.queryParam("path", pathReplaced(path)), r -> r.readEntity(String.class));
    }
    Call[] calls;
    try {
        calls = new ObjectMapper().readValue(callsJson, Call[].class);
    } catch (JsonProcessingException e) {
        throw new TestFailException("Cannot deserialize calls: " + e.getMessage(), e);
    }
    if (calls == null) {
        calls = new Call[0];
    }
    List<Call> collect = Arrays.stream(calls).filter(this::isPathMatched).filter(call -> call.getMethod().equalsIgnoreCase(method.toString())).filter(call -> parameterCheck(call.getParameters())).collect(Collectors.toList());
    VerificationContext verificationContext = new VerificationContext(collect);
    verifications.forEach(v -> {
        v.handle(path, method, verificationContext);
    });
    List<String> errors = verificationContext.getErrors();
    if (!errors.isEmpty()) {
        throw new TestFailException("URL verification failed: " + System.lineSeparator() + String.join(System.lineSeparator(), errors));
    }
    return testDto;
}
Also used : Arrays(java.util.Arrays) Method(com.sequenceiq.it.cloudbreak.dto.mock.Method) CloudbreakTestDto(com.sequenceiq.it.cloudbreak.dto.CloudbreakTestDto) TextBodyContainsVerification(com.sequenceiq.it.cloudbreak.dto.mock.verification.TextBodyContainsVerification) ExecuteQueryToMockInfrastructure(com.sequenceiq.it.cloudbreak.mock.ExecuteQueryToMockInfrastructure) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HashMap(java.util.HashMap) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Entity(javax.ws.rs.client.Entity) Consumer(java.util.function.Consumer) Call(com.sequenceiq.it.verification.Call) List(java.util.List) Response(javax.ws.rs.core.Response) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) Map(java.util.Map) Verification(com.sequenceiq.it.cloudbreak.dto.mock.Verification) Optional(java.util.Optional) VerificationContext(com.sequenceiq.it.cloudbreak.dto.mock.verification.VerificationContext) LinkedList(java.util.LinkedList) CheckCount(com.sequenceiq.it.cloudbreak.dto.mock.CheckCount) MockResponse(com.sequenceiq.it.cloudbreak.testcase.mock.response.MockResponse) Call(com.sequenceiq.it.verification.Call) VerificationContext(com.sequenceiq.it.cloudbreak.dto.mock.verification.VerificationContext) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 19 with TestFailException

use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.

the class DistroxStopStartScaleDurationAssertions method doAssertion.

@Override
public DistroXTestDto doAssertion(TestContext testContext, DistroXTestDto testDto, CloudbreakClient client) throws Exception {
    String startMessage = scalingUp ? "Scaling up (via instance start) for host group" : "Scaling down (via instance stop) for host group";
    String stopMessage = scalingUp ? "Scaled up (via instance start) host group" : "Scaled down (via instance stop) host group";
    StructuredEventContainer structuredEventContainer = client.getDefaultClient().eventV4Endpoint().structured(testDto.getName(), testContext.getActingUserCrn().getAccountId());
    List<StructuredNotificationEvent> structuredNotificationEvents = structuredEventContainer.getNotification();
    long startTime = getTimestampForEvent(structuredNotificationEvents, startMessage);
    long endTime = getTimestampForEvent(structuredNotificationEvents, stopMessage);
    long actualDuration = endTime - startTime;
    LOGGER.info(String.format("[%s] event duration '%s' minutes.", startMessage, TimeUnit.MILLISECONDS.toMinutes(actualDuration)));
    String message = String.format("Distrox last scale have been took (%d) more than the expected %d minutes!", TimeUnit.MILLISECONDS.toMinutes(actualDuration), expectedDuration);
    if (actualDuration > TimeUnit.MINUTES.toMillis(expectedDuration)) {
        LOGGER.error(message);
        throw new TestFailException(message);
    }
    return testDto;
}
Also used : StructuredEventContainer(com.sequenceiq.cloudbreak.structuredevent.event.StructuredEventContainer) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) StructuredNotificationEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredNotificationEvent)

Example 20 with TestFailException

use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.

the class DistroxStopStartScaleDurationAssertions method getTimestampForEvent.

private long getTimestampForEvent(List<StructuredNotificationEvent> structuredNotificationEvents, String message) {
    OperationDetails latestEvent = structuredNotificationEvents.stream().filter(events -> StringUtils.containsIgnoreCase(events.getNotificationDetails().getNotification(), message)).map(StructuredEvent::getOperation).max(Comparator.comparing(OperationDetails::getTimestamp)).orElseThrow(() -> new TestFailException(String.format("Cannot find Structured Event for '%s' message!", message)));
    long latestEventTimestamp = latestEvent.getTimestamp();
    LOGGER.info(String.format("[%s] event time '%s'.", message, LocalDateTime.ofInstant(Instant.ofEpochMilli(latestEventTimestamp), ZoneId.systemDefault())));
    return latestEventTimestamp;
}
Also used : Logger(org.slf4j.Logger) TestContext(com.sequenceiq.it.cloudbreak.context.TestContext) LocalDateTime(java.time.LocalDateTime) LoggerFactory(org.slf4j.LoggerFactory) Instant(java.time.Instant) StringUtils(org.apache.commons.lang3.StringUtils) ZoneId(java.time.ZoneId) DistroXTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto) TimeUnit(java.util.concurrent.TimeUnit) OperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails) Assertion(com.sequenceiq.it.cloudbreak.assertion.Assertion) List(java.util.List) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) StructuredEventContainer(com.sequenceiq.cloudbreak.structuredevent.event.StructuredEventContainer) StructuredNotificationEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredNotificationEvent) StructuredEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredEvent) Comparator(java.util.Comparator) CloudbreakClient(com.sequenceiq.it.cloudbreak.CloudbreakClient) OperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails) StructuredEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredEvent) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException)

Aggregations

TestFailException (com.sequenceiq.it.cloudbreak.exception.TestFailException)101 List (java.util.List)15 Inject (javax.inject.Inject)14 Map (java.util.Map)13 Description (com.sequenceiq.it.cloudbreak.context.Description)12 TestContext (com.sequenceiq.it.cloudbreak.context.TestContext)12 Logger (org.slf4j.Logger)12 LoggerFactory (org.slf4j.LoggerFactory)12 Test (org.testng.annotations.Test)12 DistroXTestDto (com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto)10 WebApplicationException (javax.ws.rs.WebApplicationException)10 Log (com.sequenceiq.it.cloudbreak.log.Log)9 String.format (java.lang.String.format)9 Collectors (java.util.stream.Collectors)9 FreeIpaTestDto (com.sequenceiq.it.cloudbreak.dto.freeipa.FreeIpaTestDto)8 SdxTestDto (com.sequenceiq.it.cloudbreak.dto.sdx.SdxTestDto)8 IOException (java.io.IOException)8 URISyntaxException (java.net.URISyntaxException)8 ArrayList (java.util.ArrayList)8 Set (java.util.Set)8