Search in sources :

Example 1 with PushQueryId

use of io.confluent.ksql.rest.entity.PushQueryId in project ksql by confluentinc.

the class ApiTest method shouldExecutePushQuery.

@Test
@CoreApiTest
public void shouldExecutePushQuery() throws Exception {
    // When
    QueryResponse queryResponse = executePushQueryAndWaitForRows(DEFAULT_PUSH_QUERY_REQUEST_BODY);
    // Then
    assertThat(testEndpoints.getLastSql(), is(DEFAULT_PUSH_QUERY));
    assertThat(testEndpoints.getLastProperties(), is(DEFAULT_PUSH_QUERY_REQUEST_PROPERTIES));
    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) PushQueryId(io.confluent.ksql.rest.entity.PushQueryId) Test(org.junit.Test)

Example 2 with PushQueryId

use of io.confluent.ksql.rest.entity.PushQueryId 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 3 with PushQueryId

use of io.confluent.ksql.rest.entity.PushQueryId 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 4 with PushQueryId

use of io.confluent.ksql.rest.entity.PushQueryId 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)

Example 5 with PushQueryId

use of io.confluent.ksql.rest.entity.PushQueryId in project ksql by confluentinc.

the class ClientTest method shouldTerminatePushQueryIssuedViaStreamQuery.

@Test
public void shouldTerminatePushQueryIssuedViaStreamQuery() throws Exception {
    // Given
    final StreamedQueryResult streamedQueryResult = javaClient.streamQuery(DEFAULT_PUSH_QUERY, DEFAULT_PUSH_QUERY_REQUEST_PROPERTIES).get();
    final String queryId = streamedQueryResult.queryID();
    assertThat(queryId, is(notNullValue()));
    // Query is running on server, and StreamedQueryResult is not complete
    assertThat(server.getQueryIDs(), hasSize(1));
    assertThat(server.getQueryIDs().contains(new PushQueryId(queryId)), is(true));
    assertThat(streamedQueryResult.isComplete(), is(false));
    // When
    javaClient.terminatePushQuery(queryId).get();
    // Then: query is no longer running on server, and StreamedQueryResult is complete
    assertThat(server.getQueryIDs(), hasSize(0));
    assertThatEventually(streamedQueryResult::isComplete, is(true));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) PushQueryId(io.confluent.ksql.rest.entity.PushQueryId) BaseApiTest(io.confluent.ksql.api.BaseApiTest) Test(org.junit.Test)

Aggregations

PushQueryId (io.confluent.ksql.rest.entity.PushQueryId)10 Test (org.junit.Test)10 QueryResponse (io.confluent.ksql.api.utils.QueryResponse)8 BaseApiTest (io.confluent.ksql.api.BaseApiTest)2 Buffer (io.vertx.core.buffer.Buffer)2 JsonObject (io.vertx.core.json.JsonObject)2 WebClient (io.vertx.ext.web.client.WebClient)2 ArrayList (java.util.ArrayList)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 ReceiveStream (io.confluent.ksql.api.utils.ReceiveStream)1 VertxCompletableFuture (io.confluent.ksql.util.VertxCompletableFuture)1 HttpResponse (io.vertx.ext.web.client.HttpResponse)1