Search in sources :

Example 31 with QueryResponse

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));
}
Also used : QueryResponse(io.confluent.ksql.api.utils.QueryResponse)

Example 32 with QueryResponse

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

Example 33 with QueryResponse

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

Example 34 with QueryResponse

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

Example 35 with QueryResponse

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"));
}
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)

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