Search in sources :

Example 6 with QueryResponse

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

Example 7 with QueryResponse

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);
}
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 8 with QueryResponse

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;
}
Also used : QueryResponse(io.confluent.ksql.api.utils.QueryResponse) PushQueryId(io.confluent.ksql.rest.entity.PushQueryId) Test(org.junit.Test)

Example 9 with QueryResponse

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

Example 10 with QueryResponse

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

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