use of io.confluent.ksql.api.utils.QueryResponse in project ksql by confluentinc.
the class ApiTest method shouldExecutePushQueryWithVariableSubstitution.
@Test
public void shouldExecutePushQueryWithVariableSubstitution() throws Exception {
// When
JsonObject requestBody = new JsonObject().put("sql", "select * from ${name} emit changes;");
JsonObject properties = new JsonObject().put("prop1", "val1").put("prop2", 23);
JsonObject sessionVariables = new JsonObject().put("name", "foo");
requestBody.put("properties", properties).put("sessionVariables", sessionVariables);
QueryResponse queryResponse = executePushQueryAndWaitForRows(requestBody);
// Then
assertThat(testEndpoints.getLastSql(), is("select * from ${name} emit changes;"));
assertThat(testEndpoints.getLastProperties(), is(DEFAULT_PUSH_QUERY_REQUEST_PROPERTIES));
assertThat(testEndpoints.getLastSessionVariables(), is(sessionVariables));
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(1));
String queryId = queryResponse.responseObject.getString("queryId");
assertThat(queryId, is(notNullValue()));
assertThat(server.getQueryIDs().contains(new PushQueryId(queryId)), is(true));
}
use of io.confluent.ksql.api.utils.QueryResponse in project ksql by confluentinc.
the class ApiTest method shouldHandleQueryWithMissingSql.
@Test
public void shouldHandleQueryWithMissingSql() throws Exception {
// Given
JsonObject requestBody = new JsonObject().put("foo", "bar");
// When
HttpResponse<Buffer> response = sendPostRequest("/query-stream", requestBody.toBuffer());
// Then
assertThat(response.statusCode(), is(400));
assertThat(response.statusMessage(), is("Bad Request"));
QueryResponse queryResponse = new QueryResponse(response.bodyAsString());
validateError(ERROR_CODE_BAD_REQUEST, "Invalid JSON in request: Missing required creator property 'sql'", queryResponse.responseObject);
}
use of io.confluent.ksql.api.utils.QueryResponse in project ksql by confluentinc.
the class ApiTest method shouldCloseQueriesOnSameConnectionsWhenConnectionsAreClosed.
@Test
public void shouldCloseQueriesOnSameConnectionsWhenConnectionsAreClosed() throws Exception {
int numQueries = 10;
for (int i = 0; i < numQueries; i++) {
// When
QueryResponse queryResponse = executePushQueryAndWaitForRows(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));
}
assertThatEventually(server::queryConnectionCount, is(1));
// When
client.close();
// Then
assertThatEventually(server::queryConnectionCount, is(0));
assertThat(server.getQueryIDs().isEmpty(), is(true));
client = null;
}
use of io.confluent.ksql.api.utils.QueryResponse in project ksql by confluentinc.
the class ApiTest method shouldRejectInvalidQuery.
private void shouldRejectInvalidQuery(final String query) throws Exception {
// Given
ParseFailedException pfe = new ParseFailedException("invalid query blah");
testEndpoints.setCreateQueryPublisherException(pfe);
JsonObject requestBody = new JsonObject().put("sql", query);
// When
HttpResponse<Buffer> response = sendPostRequest("/query-stream", requestBody.toBuffer());
// Then
assertThat(response.statusCode(), is(400));
assertThat(response.statusMessage(), is("Bad Request"));
QueryResponse queryResponse = new QueryResponse(response.bodyAsString());
validateError(ERROR_CODE_BAD_STATEMENT, pfe.getMessage(), queryResponse.responseObject);
}
use of io.confluent.ksql.api.utils.QueryResponse in project ksql by confluentinc.
the class ApiTest method shouldHandleErrorInProcessingQuery.
@Test
public void shouldHandleErrorInProcessingQuery() throws Exception {
// Given
testEndpoints.setRowsBeforePublisherError(DEFAULT_JSON_ROWS.size() - 1);
// When
HttpResponse<Buffer> response = sendPostRequest("/query-stream", DEFAULT_PUSH_QUERY_REQUEST_BODY.toBuffer());
// Then
assertThat(response.statusCode(), is(200));
assertThat(response.statusMessage(), is("OK"));
QueryResponse queryResponse = new QueryResponse(response.bodyAsString());
assertThat(queryResponse.rows, hasSize(DEFAULT_JSON_ROWS.size() - 1));
validateError(ERROR_CODE_SERVER_ERROR, "java.lang.RuntimeException: Failure in processing", queryResponse.error);
assertThat(testEndpoints.getQueryPublishers(), hasSize(1));
assertThat(server.getQueryIDs().isEmpty(), is(true));
}
Aggregations