Search in sources :

Example 11 with QueryResponse

use of io.confluent.ksql.api.utils.QueryResponse in project ksql by confluentinc.

the class ApiTest method shouldExecuteServerMetadataIdRequest.

@Test
@CoreApiTest
public void shouldExecuteServerMetadataIdRequest() throws Exception {
    // When
    HttpResponse<Buffer> response = sendGetRequest("/v1/metadata/id");
    // Then
    assertThat(response.statusCode(), is(200));
    assertThat(response.statusMessage(), is("OK"));
    QueryResponse queryResponse = new QueryResponse(response.bodyAsString());
    assertThat(queryResponse.responseObject.getJsonObject("scope").getJsonObject("clusters").getString("kafka-cluster"), is("kafka-cluster-id"));
    assertThat(queryResponse.responseObject.getJsonObject("scope").getJsonObject("clusters").getString("ksql-cluster"), is("ksql-service-id"));
}
Also used : Buffer(io.vertx.core.buffer.Buffer) QueryResponse(io.confluent.ksql.api.utils.QueryResponse) Test(org.junit.Test)

Example 12 with QueryResponse

use of io.confluent.ksql.api.utils.QueryResponse in project ksql by confluentinc.

the class Http2OnlyStreamTest method shouldRejectRequestUsingHttp11.

private void shouldRejectRequestUsingHttp11(final String uri, final JsonObject request) throws Exception {
    // When
    HttpResponse<Buffer> response = sendPostRequest(uri, request.toBuffer());
    // Then
    assertThat(response.statusCode(), is(400));
    QueryResponse queryResponse = new QueryResponse(response.bodyAsString());
    validateError(ERROR_CODE_HTTP2_ONLY, "This endpoint is only available when using HTTP2", queryResponse.responseObject);
}
Also used : Buffer(io.vertx.core.buffer.Buffer) QueryResponse(io.confluent.ksql.api.utils.QueryResponse)

Example 13 with QueryResponse

use of io.confluent.ksql.api.utils.QueryResponse in project ksql by confluentinc.

the class AuthTest method shouldFailCloseQuery.

private void shouldFailCloseQuery(final String username, final String password, final int expectedStatus, final String expectedMessage, final int expectedErrorCode) throws Exception {
    // Given
    JsonObject requestBody = new JsonObject().put("queryId", "foo");
    // When
    HttpResponse<Buffer> response = sendPostRequestWithCreds("/close-query", requestBody.toBuffer(), username, password);
    // 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) JsonObject(io.vertx.core.json.JsonObject)

Example 14 with QueryResponse

use of io.confluent.ksql.api.utils.QueryResponse in project ksql by confluentinc.

the class AuthTest method shouldFailQuery.

private void shouldFailQuery(final String username, final String password, final int expectedStatus, final String expectedMessage, final int expectedErrorCode) throws Exception {
    // When
    HttpResponse<Buffer> response = sendPostRequestWithCreds("/query-stream", DEFAULT_PUSH_QUERY_REQUEST_BODY.toBuffer(), username, password);
    // 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 15 with QueryResponse

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