use of io.confluent.ksql.rest.entity.PushQueryId in project ksql by confluentinc.
the class ApiTest method shouldExecutePushQuery.
@Test
@CoreApiTest
public void shouldExecutePushQuery() throws Exception {
// When
QueryResponse queryResponse = executePushQueryAndWaitForRows(DEFAULT_PUSH_QUERY_REQUEST_BODY);
// Then
assertThat(testEndpoints.getLastSql(), is(DEFAULT_PUSH_QUERY));
assertThat(testEndpoints.getLastProperties(), is(DEFAULT_PUSH_QUERY_REQUEST_PROPERTIES));
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.rest.entity.PushQueryId 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.rest.entity.PushQueryId 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.rest.entity.PushQueryId in project ksql by confluentinc.
the class MaxQueriesTest method shouldNotCreateMoreThanMaxQueries.
@Test
public void shouldNotCreateMoreThanMaxQueries() throws Exception {
for (int i = 0; i < MAX_QUERIES + 4; i++) {
if (i >= MAX_QUERIES) {
HttpResponse<Buffer> response = sendPostRequest("/query-stream", DEFAULT_PUSH_QUERY_REQUEST_BODY.toBuffer());
assertThat(response.statusCode(), is(400));
QueryResponse queryResponse = new QueryResponse(response.bodyAsString());
validateError(ERROR_CODE_MAX_PUSH_QUERIES_EXCEEDED, "Maximum number of push queries exceeded", queryResponse.responseObject);
} else {
// When:
QueryResponse queryResponse = executePushQueryAndWaitForRows(DEFAULT_PUSH_QUERY_REQUEST_BODY);
String queryId = queryResponse.responseObject.getString("queryId");
// Then:
assertThat(queryId, is(notNullValue()));
assertThat(server.getQueryIDs().contains(new PushQueryId(queryId)), is(true));
}
}
assertThat(server.getQueryIDs(), hasSize(MAX_QUERIES));
}
use of io.confluent.ksql.rest.entity.PushQueryId in project ksql by confluentinc.
the class ClientTest method shouldTerminatePushQueryIssuedViaStreamQuery.
@Test
public void shouldTerminatePushQueryIssuedViaStreamQuery() throws Exception {
// Given
final StreamedQueryResult streamedQueryResult = javaClient.streamQuery(DEFAULT_PUSH_QUERY, DEFAULT_PUSH_QUERY_REQUEST_PROPERTIES).get();
final String queryId = streamedQueryResult.queryID();
assertThat(queryId, is(notNullValue()));
// Query is running on server, and StreamedQueryResult is not complete
assertThat(server.getQueryIDs(), hasSize(1));
assertThat(server.getQueryIDs().contains(new PushQueryId(queryId)), is(true));
assertThat(streamedQueryResult.isComplete(), is(false));
// When
javaClient.terminatePushQuery(queryId).get();
// Then: query is no longer running on server, and StreamedQueryResult is complete
assertThat(server.getQueryIDs(), hasSize(0));
assertThatEventually(streamedQueryResult::isComplete, is(true));
}
Aggregations