use of io.confluent.ksql.rest.entity.PushQueryId in project ksql by confluentinc.
the class ClientTest method shouldTerminatePushQueryIssuedViaExecuteQuery.
@Test
public void shouldTerminatePushQueryIssuedViaExecuteQuery() throws Exception {
// Given
// Issue non-terminating push query via executeQuery(). This is NOT an expected use case
final BatchedQueryResult batchedQueryResult = javaClient.executeQuery(DEFAULT_PUSH_QUERY);
final String queryId = batchedQueryResult.queryID().get();
assertThat(queryId, is(notNullValue()));
// Query is running on server, and BatchedQueryResult is not complete
assertThat(server.getQueryIDs(), hasSize(1));
assertThat(server.getQueryIDs().contains(new PushQueryId(queryId)), is(true));
assertThat(batchedQueryResult.isDone(), is(false));
// When
javaClient.terminatePushQuery(queryId).get();
// Then: query is no longer running on server, and BatchedQueryResult is complete
assertThat(server.getQueryIDs(), hasSize(0));
assertThatEventually(batchedQueryResult::isDone, is(true));
assertThat(batchedQueryResult.isCompletedExceptionally(), is(false));
}
use of io.confluent.ksql.rest.entity.PushQueryId 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.rest.entity.PushQueryId in project ksql by confluentinc.
the class ApiTest method shouldCloseQuery.
@Test
@CoreApiTest
public void shouldCloseQuery() throws Exception {
// Create a write stream to capture the incomplete response
ReceiveStream writeStream = new ReceiveStream(vertx);
VertxCompletableFuture<HttpResponse<Void>> responseFuture = new VertxCompletableFuture<>();
// Make the request to stream a query
sendPostRequest("/query-stream", (request) -> request.as(BodyCodec.pipe(writeStream)).sendJsonObject(DEFAULT_PUSH_QUERY_REQUEST_BODY, responseFuture));
// Wait for all rows in the response to arrive
assertThatEventually(() -> {
try {
Buffer buff = writeStream.getBody();
QueryResponse queryResponse = new QueryResponse(buff.toString());
return queryResponse.rows.size();
} catch (Throwable t) {
return Integer.MAX_VALUE;
}
}, is(DEFAULT_JSON_ROWS.size()));
// The response shouldn't have ended yet
assertThat(writeStream.isEnded(), is(false));
// Assert the query is still live on the server
QueryResponse queryResponse = new QueryResponse(writeStream.getBody().toString());
String queryId = queryResponse.responseObject.getString("queryId");
assertThat(server.getQueryIDs().contains(new PushQueryId(queryId)), is(true));
assertThat(server.getQueryIDs(), hasSize(1));
assertThat(testEndpoints.getQueryPublishers(), hasSize(1));
// Now send another request to close the query
JsonObject closeQueryRequestBody = new JsonObject().put("queryId", queryId);
HttpResponse<Buffer> closeQueryResponse = sendPostRequest("/close-query", closeQueryRequestBody.toBuffer());
assertThat(closeQueryResponse.statusCode(), is(200));
// Assert the query no longer exists on the server
assertThat(server.getQueryIDs(), not(hasItem(new PushQueryId(queryId))));
assertThat(server.getQueryIDs(), hasSize(0));
// The response should now be ended
assertThatEventually(writeStream::isEnded, is(true));
HttpResponse<Void> response = responseFuture.get();
assertThat(response.statusCode(), is(200));
}
use of io.confluent.ksql.rest.entity.PushQueryId in project ksql by confluentinc.
the class ApiTest method shouldCloseMultipleQueriesOnDifferentConnectionsWhenConnectionsAreClosed.
@Test
public void shouldCloseMultipleQueriesOnDifferentConnectionsWhenConnectionsAreClosed() throws Exception {
int numConnections = 5;
int numQueries = 5;
List<WebClient> clients = new ArrayList<>();
for (int i = 0; i < numConnections; i++) {
WebClient client = createClient();
clients.add(client);
for (int j = 0; j < numQueries; j++) {
// 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));
int queries = i * numQueries + j + 1;
assertThat(server.getQueryIDs(), hasSize(queries));
assertThat(server.queryConnectionCount(), is(i + 1));
}
}
int count = 0;
for (WebClient client : clients) {
// When
client.close();
// Then
int connections = numConnections - count - 1;
assertThatEventually(server::queryConnectionCount, is(connections));
assertThat(server.getQueryIDs(), hasSize(numQueries * connections));
count++;
}
}
use of io.confluent.ksql.rest.entity.PushQueryId 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++;
}
}
Aggregations