Search in sources :

Example 6 with QueryStreamArgs

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

the class RestApiTest method shouldExecuteScalablePushQueryOverHttp2QueryStream.

@Test
public void shouldExecuteScalablePushQueryOverHttp2QueryStream() throws InterruptedException, ExecutionException {
    QueryStreamArgs queryStreamArgs = new QueryStreamArgs("SELECT USERID, PAGEID, VIEWTIME from " + PAGE_VIEW_CSAS + " EMIT CHANGES LIMIT " + LIMIT + ";", ImmutableMap.of("auto.offset.reset", "latest"), Collections.emptyMap(), Collections.emptyMap());
    List<String> messages = new ArrayList<>();
    Semaphore start = new Semaphore(0);
    VertxCompletableFuture<Void> future = RestIntegrationTestUtil.rawRestRequest(REST_APP, HTTP_2, POST, "/query-stream", queryStreamArgs, "application/vnd.ksqlapi.delimited.v1", buffer -> {
        if (buffer == null || buffer.length() == 0) {
            return;
        }
        String str = buffer.toString();
        if (str.startsWith("{") && str.contains("\"queryId\"")) {
            start.release();
        }
        String[] parts = str.split("\n");
        messages.addAll(Arrays.asList(parts));
    }, Optional.empty());
    // Wait to get the metadata so we know we've started.
    start.acquire();
    assertExpectedScalablePushQueries(1);
    // Write some new rows
    TEST_HARNESS.produceRows(PAGE_VIEW2_TOPIC, PAGE_VIEWS2_PROVIDER, FormatFactory.KAFKA, FormatFactory.JSON);
    future.get();
    assertThat(messages.size(), is(HEADER + LIMIT));
    assertThat(messages.get(0), startsWith("{\"queryId\":\"SCALABLE_PUSH_QUERY_"));
    assertThat(messages.get(0), endsWith(",\"columnNames\":[\"USERID\",\"PAGEID\",\"VIEWTIME\"]," + "\"columnTypes\":[\"STRING\",\"STRING\",\"BIGINT\"]}"));
    assertThat(messages.get(1), is("[\"USER_4\",\"PAGE_1\",10]"));
    assertThat(messages.get(2), is("[\"USER_0\",\"PAGE_5\",11]"));
}
Also used : QueryStreamArgs(io.confluent.ksql.rest.entity.QueryStreamArgs) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) Semaphore(java.util.concurrent.Semaphore) Test(org.junit.Test) IntegrationTest(io.confluent.common.utils.IntegrationTest)

Example 7 with QueryStreamArgs

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

the class RestApiTest method shouldExecutePullQueryOverHttp2QueryStream.

@Test
public void shouldExecutePullQueryOverHttp2QueryStream() {
    QueryStreamArgs queryStreamArgs = new QueryStreamArgs("SELECT COUNT, USERID from " + AGG_TABLE + " WHERE USERID='" + AN_AGG_KEY + "';", Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap());
    QueryResponse[] queryResponse = new QueryResponse[1];
    assertThatEventually(() -> {
        try {
            HttpResponse<Buffer> resp = RestIntegrationTestUtil.rawRestRequest(REST_APP, HTTP_2, POST, "/query-stream", queryStreamArgs, "application/vnd.ksqlapi.delimited.v1", Optional.empty(), Optional.empty());
            queryResponse[0] = new QueryResponse(resp.body().toString());
            return queryResponse[0].rows.size();
        } catch (Throwable t) {
            return Integer.MAX_VALUE;
        }
    }, is(1));
    assertThat(queryResponse[0].rows.get(0).getList(), is(ImmutableList.of(1, "USER_1")));
}
Also used : Buffer(io.vertx.core.buffer.Buffer) QueryStreamArgs(io.confluent.ksql.rest.entity.QueryStreamArgs) QueryResponse(io.confluent.ksql.api.utils.QueryResponse) Test(org.junit.Test) IntegrationTest(io.confluent.common.utils.IntegrationTest)

Aggregations

QueryStreamArgs (io.confluent.ksql.rest.entity.QueryStreamArgs)7 Test (org.junit.Test)6 IntegrationTest (io.confluent.common.utils.IntegrationTest)3 ArrayList (java.util.ArrayList)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 ImmutableList (com.google.common.collect.ImmutableList)2 QueryResponse (io.confluent.ksql.api.utils.QueryResponse)2 Buffer (io.vertx.core.buffer.Buffer)2 List (java.util.List)2 KsqlEntityList (io.confluent.ksql.rest.entity.KsqlEntityList)1 KsqlRequest (io.confluent.ksql.rest.entity.KsqlRequest)1 StreamedRow (io.confluent.ksql.rest.entity.StreamedRow)1 HttpVersion (io.vertx.core.http.HttpVersion)1 Map (java.util.Map)1 Semaphore (java.util.concurrent.Semaphore)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Supplier (java.util.function.Supplier)1