Search in sources :

Example 41 with QueryResponse

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"));
}
Also used : Buffer(io.vertx.core.buffer.Buffer) QueryResponse(io.confluent.ksql.api.utils.QueryResponse) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 42 with QueryResponse

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++;
    }
}
Also used : QueryResponse(io.confluent.ksql.api.utils.QueryResponse) ArrayList(java.util.ArrayList) PushQueryId(io.confluent.ksql.rest.entity.PushQueryId) WebClient(io.vertx.ext.web.client.WebClient) Test(org.junit.Test)

Example 43 with QueryResponse

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);
}
Also used : Buffer(io.vertx.core.buffer.Buffer) QueryResponse(io.confluent.ksql.api.utils.QueryResponse) JsonObject(io.vertx.core.json.JsonObject)

Aggregations

QueryResponse (io.confluent.ksql.api.utils.QueryResponse)43 Test (org.junit.Test)30 Buffer (io.vertx.core.buffer.Buffer)29 JsonObject (io.vertx.core.json.JsonObject)21 IntegrationTest (io.confluent.common.utils.IntegrationTest)10 PushQueryId (io.confluent.ksql.rest.entity.PushQueryId)8 VertxCompletableFuture (io.confluent.ksql.util.VertxCompletableFuture)7 HttpResponse (io.vertx.ext.web.client.HttpResponse)7 Matchers.containsString (org.hamcrest.Matchers.containsString)7 JsonArray (io.vertx.core.json.JsonArray)6 ReceiveStream (io.confluent.ksql.api.utils.ReceiveStream)4 ArrayList (java.util.ArrayList)4 WebClient (io.vertx.ext.web.client.WebClient)3 ImmutableList (com.google.common.collect.ImmutableList)2 KsqlEngine (io.confluent.ksql.engine.KsqlEngine)2 QueryStreamArgs (io.confluent.ksql.rest.entity.QueryStreamArgs)2 KsqlException (io.confluent.ksql.util.KsqlException)2 HttpVersion (io.vertx.core.http.HttpVersion)2 List (java.util.List)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2