use of org.apache.druid.testing.utils.QueryWithResults in project druid by druid-io.
the class ITQueryRetryTestOnMissingSegments method testQueries.
private void testQueries(List<QueryWithResults> queries, Expectation expectation) throws Exception {
int querySuccess = 0;
int queryFailure = 0;
int resultMatches = 0;
int resultMismatches = 0;
for (int i = 0; i < TIMES_TO_RUN; i++) {
for (QueryWithResults queryWithResult : queries) {
final StatusResponseHolder responseHolder = queryClient.queryAsync(queryHelper.getQueryURL(config.getBrokerUrl()), queryWithResult.getQuery()).get();
if (responseHolder.getStatus().getCode() == HttpResponseStatus.OK.getCode()) {
querySuccess++;
List<Map<String, Object>> result = jsonMapper.readValue(responseHolder.getContent(), new TypeReference<List<Map<String, Object>>>() {
});
if (!QueryResultVerifier.compareResults(result, queryWithResult.getExpectedResults(), queryWithResult.getFieldsToTest())) {
if (expectation != Expectation.INCORRECT_RESULT) {
throw new ISE("Incorrect query results for query %s \n expectedResults: %s \n actualResults : %s", queryWithResult.getQuery(), jsonMapper.writeValueAsString(queryWithResult.getExpectedResults()), jsonMapper.writeValueAsString(result));
} else {
resultMismatches++;
}
} else {
resultMatches++;
}
} else if (responseHolder.getStatus().getCode() == HttpResponseStatus.INTERNAL_SERVER_ERROR.getCode() && expectation == Expectation.QUERY_FAILURE) {
final Map<String, Object> response = jsonMapper.readValue(responseHolder.getContent(), Map.class);
final String errorMessage = (String) response.get("errorMessage");
Assert.assertNotNull(errorMessage, "errorMessage");
Assert.assertTrue(errorMessage.contains("No results found for segments"));
queryFailure++;
} else {
throw new ISE("Unexpected failure, code: [%s], content: [%s]", responseHolder.getStatus(), responseHolder.getContent());
}
}
}
switch(expectation) {
case ALL_SUCCESS:
Assert.assertEquals(querySuccess, ITQueryRetryTestOnMissingSegments.TIMES_TO_RUN);
Assert.assertEquals(queryFailure, 0);
Assert.assertEquals(resultMatches, ITQueryRetryTestOnMissingSegments.TIMES_TO_RUN);
Assert.assertEquals(resultMismatches, 0);
break;
case QUERY_FAILURE:
Assert.assertTrue(querySuccess > 0, "At least one query is expected to succeed.");
Assert.assertTrue(queryFailure > 0, "At least one query is expected to fail.");
Assert.assertEquals(querySuccess, resultMatches);
Assert.assertEquals(resultMismatches, 0);
break;
case INCORRECT_RESULT:
Assert.assertEquals(querySuccess, ITQueryRetryTestOnMissingSegments.TIMES_TO_RUN);
Assert.assertEquals(queryFailure, 0);
Assert.assertTrue(resultMatches > 0, "At least one query is expected to return correct results.");
Assert.assertTrue(resultMismatches > 0, "At least one query is expected to return less results.");
break;
default:
throw new ISE("Unknown expectation[%s]", expectation);
}
}
Aggregations