use of io.confluent.ksql.api.utils.QueryResponse in project ksql by confluentinc.
the class ApiTest method shouldExecutePullQuery.
@Test
@CoreApiTest
public void shouldExecutePullQuery() throws Exception {
// Given
JsonObject requestBody = new JsonObject().put("sql", DEFAULT_PULL_QUERY);
JsonObject properties = new JsonObject().put("prop1", "val1").put("prop2", 23);
requestBody.put("properties", properties);
// When
HttpResponse<Buffer> response = sendPostRequest("/query-stream", requestBody.toBuffer());
// Then
assertThat(response.statusCode(), is(200));
assertThat(response.statusMessage(), is("OK"));
assertThat(testEndpoints.getLastSql(), is(DEFAULT_PULL_QUERY));
assertThat(testEndpoints.getLastProperties(), is(properties));
QueryResponse queryResponse = new QueryResponse(response.bodyAsString());
assertThat(queryResponse.responseObject.getJsonArray("columnNames"), is(DEFAULT_COLUMN_NAMES));
assertThat(queryResponse.responseObject.getJsonArray("columnTypes"), is(DEFAULT_COLUMN_TYPES));
assertThat(queryResponse.rows, is(DEFAULT_JSON_ROWS));
assertThat(server.getQueryIDs(), hasSize(0));
String queryId = queryResponse.responseObject.getString("queryId");
assertThat(queryId, is("queryId"));
}
use of io.confluent.ksql.api.utils.QueryResponse in project ksql by confluentinc.
the class ApiTest method shouldCloseQueriesOnDifferentConnectionsWhenConnectionsAreClosed.
@Test
public void shouldCloseQueriesOnDifferentConnectionsWhenConnectionsAreClosed() throws Exception {
int numQueries = 10;
List<WebClient> clients = new ArrayList<>();
for (int i = 0; i < numQueries; i++) {
// We use different clients to ensure requests are sent on different connections
WebClient client = createClient();
clients.add(client);
// When
QueryResponse queryResponse = executePushQueryAndWaitForRows(client, DEFAULT_PUSH_QUERY_REQUEST_BODY);
// Then
String queryId = queryResponse.responseObject.getString("queryId");
assertThat(queryId, is(notNullValue()));
assertThat(server.getQueryIDs().contains(new PushQueryId(queryId)), is(true));
assertThat(server.getQueryIDs(), hasSize(i + 1));
assertThat(server.queryConnectionCount(), is(i + 1));
}
// Now close them one by one and make sure queries are cleaned up
int count = 0;
for (WebClient client : clients) {
// Given
client.close();
// Then
int num = numQueries - count - 1;
assertThatEventually(server::queryConnectionCount, is(num));
assertThat(server.getQueryIDs(), hasSize(num));
count++;
}
}
use of io.confluent.ksql.api.utils.QueryResponse in project ksql by confluentinc.
the class ApiTest method shouldRejectWhenInternalErrorInProcessingQuery.
private void shouldRejectWhenInternalErrorInProcessingQuery(final String query) throws Exception {
// Given
NullPointerException npe = new NullPointerException("oops");
testEndpoints.setCreateQueryPublisherException(npe);
JsonObject requestBody = new JsonObject().put("sql", query);
// When
HttpResponse<Buffer> response = sendPostRequest("/query-stream", requestBody.toBuffer());
// Then
assertThat(response.statusCode(), is(500));
assertThat(response.statusMessage(), is("Internal Server Error"));
QueryResponse queryResponse = new QueryResponse(response.bodyAsString());
validateError(ERROR_CODE_SERVER_ERROR, "The server encountered an internal error when processing the query." + " Please consult the server logs for more information.", queryResponse.responseObject);
}
Aggregations