use of io.confluent.ksql.api.utils.QueryResponse in project ksql by confluentinc.
the class ApiIntegrationTest method shouldFailToExecuteQuery.
private void shouldFailToExecuteQuery(final String sql, final String message) {
// When:
QueryResponse response = executeQuery(sql);
// Then:
assertThat(response.rows, hasSize(0));
assertThat(response.responseObject.getInteger("error_code"), is(ERROR_CODE_BAD_STATEMENT));
assertThat(response.responseObject.getString("message"), startsWith(message));
}
use of io.confluent.ksql.api.utils.QueryResponse in project ksql by confluentinc.
the class ServerStateTest method validateResponse.
private void validateResponse(final int expectedStatus, final int expectedErrorCode, final String expectedMessage) throws Exception {
// When:
HttpResponse<Buffer> response = sendPostRequest("/query-stream", DEFAULT_PUSH_QUERY_REQUEST_BODY.toBuffer());
// Then
assertThat(response.statusCode(), is(expectedStatus));
QueryResponse queryResponse = new QueryResponse(response.bodyAsString());
validateError(expectedErrorCode, expectedMessage, queryResponse.responseObject);
}
use of io.confluent.ksql.api.utils.QueryResponse in project ksql by confluentinc.
the class ApiTest method shouldUseDelimitedFormatWhenDelimitedAcceptHeaderQuery.
@Test
public void shouldUseDelimitedFormatWhenDelimitedAcceptHeaderQuery() throws Exception {
// When
JsonObject requestBody = new JsonObject().put("sql", DEFAULT_PULL_QUERY);
VertxCompletableFuture<HttpResponse<Buffer>> requestFuture = new VertxCompletableFuture<>();
client.post("/query-stream").putHeader("accept", "application/vnd.ksqlapi.delimited.v1").sendBuffer(requestBody.toBuffer(), requestFuture);
// Then
HttpResponse<Buffer> response = requestFuture.get();
QueryResponse queryResponse = new QueryResponse(response.bodyAsString());
assertThat(queryResponse.rows, hasSize(DEFAULT_JSON_ROWS.size()));
assertThat(response.bodyAsString().contains("\n"), is(true));
assertThat(response.statusCode(), is(200));
}
use of io.confluent.ksql.api.utils.QueryResponse in project ksql by confluentinc.
the class ApiTest method shouldExecuteMultiplePushQueries.
@Test
public void shouldExecuteMultiplePushQueries() throws Exception {
int numQueries = 10;
for (int i = 0; i < numQueries; i++) {
// When
QueryResponse queryResponse = executePushQueryAndWaitForRows(DEFAULT_PUSH_QUERY_REQUEST_BODY);
// Then
assertThat(server.getQueryIDs(), hasSize(i + 1));
String queryId = queryResponse.responseObject.getString("queryId");
assertThat(queryId, is(notNullValue()));
assertThat(server.getQueryIDs(), hasItem(new PushQueryId(queryId)));
}
}
use of io.confluent.ksql.api.utils.QueryResponse in project ksql by confluentinc.
the class ApiTest method shouldExecutePullQueryWithVariableSubstitution.
@Test
public void shouldExecutePullQueryWithVariableSubstitution() throws Exception {
// Given
JsonObject requestBody = new JsonObject().put("sql", "select * from ${name} where rowkey='1234';");
JsonObject properties = new JsonObject().put("prop1", "val1").put("prop2", 23);
JsonObject sessionVariables = new JsonObject().put("name", "foo");
requestBody.put("properties", properties).put("sessionVariables", sessionVariables);
// When
HttpResponse<Buffer> response = sendPostRequest("/query-stream", requestBody.toBuffer());
// Then
assertThat(response.statusCode(), is(200));
assertThat(response.statusMessage(), is("OK"));
assertThat(testEndpoints.getLastSql(), is("select * from ${name} where rowkey='1234';"));
assertThat(testEndpoints.getLastProperties(), is(properties));
assertThat(testEndpoints.getLastSessionVariables(), is(sessionVariables));
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"));
}
Aggregations