use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.
the class WaitFailedChecker method refresh.
@Override
public void refresh(T waitObject) {
try {
waitObject.fetchData();
failed = false;
} catch (NotFoundException e) {
LOGGER.warn("No {} found with name: {}", waitObject.getClass().getSimpleName(), waitObject.getName(), e);
failed = true;
} catch (Exception e) {
LOGGER.error("Failed to get {} status or statusReason: {}", waitObject.getClass().getSimpleName(), e.getMessage(), e);
throw new TestFailException("Failed to get " + waitObject.getClass().getSimpleName() + " status or statusReason", e);
}
}
use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.
the class FreeIpaFindUsersAction method action.
public FreeIpaTestDto action(TestContext testContext, FreeIpaTestDto testDto, FreeIpaClient client) throws Exception {
CheckUsersV1Request checkUsersRequest = new CheckUsersV1Request();
checkUsersRequest.setEnvironmentCrn(testDto.getResponse().getEnvironmentCrn());
checkUsersRequest.setUsers(users);
Log.when(LOGGER, format(" Checking users [%s] are present at environment '%s'", users, testDto.getResponse().getEnvironmentCrn()));
Log.whenJson(LOGGER, format(" FreeIpa '%s' find users request:%n ", testDto.getResponse().getCrn()), checkUsersRequest);
if (expectedPresence) {
if (!client.getDefaultClient().getClientTestV1Endpoint().checkUsers(checkUsersRequest).getResult()) {
throw new TestFailException("Given freeipa users cannot be found, please check FMS logs for details!");
}
LOGGER.info(format(" Users [%s] are present at environment '%s'", users, testDto.getResponse().getEnvironmentCrn()));
Log.when(LOGGER, format(" Users [%s] are present at environment '%s'", users, testDto.getResponse().getEnvironmentCrn()));
} else {
if (client.getDefaultClient().getClientTestV1Endpoint().checkUsers(checkUsersRequest).getResult()) {
throw new TestFailException("Given freeipa users have been found, please check FMS logs for details!");
}
LOGGER.info(format(" Users [%s] have been removed successfully from environment '%s'", users, testDto.getResponse().getEnvironmentCrn()));
Log.when(LOGGER, format(" Users [%s] have been removed successfully from environment '%s'", users, testDto.getResponse().getEnvironmentCrn()));
}
return testDto;
}
use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.
the class AbstractUmsAction method action.
@Override
public U action(TestContext testContext, U testDto, UmsClient client) throws Exception {
Exception umsActionException = null;
int retries = 0;
int maxRetry = 10;
long pollingInterval = 7000;
while (retries <= maxRetry) {
try {
return umsAction(testContext, testDto, client);
} catch (Exception e) {
umsActionException = e;
Thread.sleep(pollingInterval);
retries++;
}
}
if (umsActionException != null) {
throw new TestFailException(String.format("EXCEEDING UMS ACTION MAX. RETRY (%s) ::: UMS action has been failed, because of: %s%n", retries, umsActionException.getMessage()), umsActionException);
} else {
throw new TestFailException(String.format("EXCEEDING UMS ACTION MAX. RETRY (%s) ::: UMS action has been failed!", retries));
}
}
use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.
the class TestContext method exceptionValidation.
private <E extends Exception> void exceptionValidation(Class<E> expectedException, Exception actualException, String entityKey, RunningParameter runningParameter, String stepKey) {
if (!actualException.getClass().equals(expectedException)) {
String message = String.format("Expected exception (%s) does not match with the actual exception (%s).", expectedException, actualException.getClass());
getExceptionMap().put(stepKey, new TestFailException(message));
LOGGER.error(message);
htmlLoggerForExceptionValidation(message, stepKey);
} else if (!isMessageEquals(actualException, runningParameter) || !isPayloadEquals(actualException, runningParameter)) {
List<String> messages = new ArrayList<>();
if (!isMessageEquals(actualException, runningParameter)) {
messages.add(String.format("Expected exception message (%s) does not match with the actual exception message (%s).", runningParameter.getExpectedMessage(), ResponseUtil.getErrorMessage(actualException)));
}
if (!isPayloadEquals(actualException, runningParameter)) {
messages.add(String.format("Expected exception payload (%s) does not match with the actual exception payload (%s).", runningParameter.getExpectedPayload(), ResponseUtil.getErrorPayload(actualException)));
}
String message = String.join("\n", messages);
getExceptionMap().put(stepKey, new TestFailException(message));
LOGGER.error(message);
htmlLoggerForExceptionValidation(message, stepKey);
} else {
String message = String.format("Expected exception conditions have met, exception: %s, message: %s", expectedException, runningParameter.getExpectedMessage());
getExceptionMap().remove(entityKey);
LOGGER.info(message);
htmlLoggerForExceptionValidation(message, stepKey);
}
}
use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.
the class TestContext method thenException.
public <E extends Exception, T extends CloudbreakTestDto> T thenException(T entity, Class<? extends MicroserviceClient> clientClass, Assertion<T, ? extends MicroserviceClient> assertion, Class<E> expectedException, RunningParameter runningParameter) {
checkShutdown();
String key = getKey(assertion.getClass(), runningParameter);
if (!getExceptionMap().isEmpty() && runningParameter.isSkipOnFail()) {
LOGGER.info("Should be skipped because of previous error. when [{}]", key);
return entity;
}
CloudbreakUser who = setActingUser(runningParameter);
LOGGER.info("then exception {} action on {} by {}, name: {}", key, entity, who, entity.getName());
Log.thenException(LOGGER, assertion.getClass().getSimpleName() + " exception assertion on " + entity + " by " + who);
try {
String message = String.format("Expected exception with message (%s) has not been thrown!", runningParameter.getExpectedMessage());
CloudbreakTestDto cloudbreakTestDto = resourceNames.get(key);
if (cloudbreakTestDto != null) {
assertion.doAssertion(this, (T) cloudbreakTestDto, getMicroserviceClient(entity.getClass(), who.getAccessKey()));
} else {
assertion.doAssertion(this, entity, getMicroserviceClient(entity.getClass(), who.getAccessKey()));
}
getExceptionMap().put("thenException", new TestFailException(message));
LOGGER.error(message);
htmlLoggerForExceptionValidation(message, "thenException");
} catch (Exception e) {
exceptionValidation(expectedException, e, key, runningParameter, "thenException");
}
return entity;
}
Aggregations