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