use of io.confluent.ksql.api.client.StreamedQueryResult in project ksql by confluentinc.
the class ClientMutationIntegrationTest method shouldInsertIntoTable.
@Test
public void shouldInsertIntoTable() throws Exception {
// Given
final Map<String, Object> properties = new HashMap<>();
properties.put("auto.offset.reset", "earliest");
final KsqlObject insertRow = new KsqlObject().put("K", "my_key").put("LONG", 11L);
// When
final String query = "SELECT * from " + TEST_TABLE + " WHERE K='my_key' EMIT CHANGES LIMIT 1;";
StreamedQueryResult queryResult = client.streamQuery(query, properties).get();
final Row row = assertThatEventually(() -> {
// Potentially try inserting multiple times, in case the query wasn't started by the first time
try {
client.insertInto(TEST_TABLE, insertRow).get();
} catch (Exception e) {
throw new RuntimeException(e);
}
return queryResult.poll(Duration.ofMillis(10));
}, is(notNullValue()));
// Then: a newly inserted row arrives
assertThat(row.getString("K"), is("my_key"));
assertThat(row.getLong("LONG"), is(11L));
}
use of io.confluent.ksql.api.client.StreamedQueryResult in project ksql by confluentinc.
the class ClientIntegrationTest method shouldDeliverBufferedRowsViaPollIfComplete.
@Test
public void shouldDeliverBufferedRowsViaPollIfComplete() throws Exception {
// Given
final StreamedQueryResult streamedQueryResult = client.streamQuery(PUSH_QUERY_WITH_LIMIT).get();
assertThatEventually(streamedQueryResult::isComplete, is(true));
// When / Then
for (int i = 0; i < PUSH_QUERY_LIMIT_NUM_ROWS; i++) {
final Row row = streamedQueryResult.poll();
verifyStreamRowWithIndex(row, i);
}
assertThat(streamedQueryResult.poll(), is(nullValue()));
}
use of io.confluent.ksql.api.client.StreamedQueryResult in project ksql by confluentinc.
the class ClientIntegrationTest method shouldStreamPullQueryOnStreamSync.
@Test
public void shouldStreamPullQueryOnStreamSync() throws Exception {
// When
final StreamedQueryResult streamedQueryResult = client.streamQuery(PULL_QUERY_ON_STREAM).get();
// Then
assertThat(streamedQueryResult.columnNames(), is(TEST_COLUMN_NAMES));
assertThat(streamedQueryResult.columnTypes(), is(TEST_COLUMN_TYPES));
assertThat(streamedQueryResult.queryID(), is(notNullValue()));
final List<Row> results = new LinkedList<>();
Row row;
while (true) {
row = streamedQueryResult.poll();
if (row == null) {
break;
} else {
results.add(row);
}
}
verifyStreamRows(results, 6);
assertThatEventually(streamedQueryResult::isComplete, is(true));
}
use of io.confluent.ksql.api.client.StreamedQueryResult in project ksql by confluentinc.
the class ClientIntegrationTest method shouldStreamPullQueryOnStreamAsync.
@Test
public void shouldStreamPullQueryOnStreamAsync() throws Exception {
// When
final StreamedQueryResult streamedQueryResult = client.streamQuery(PULL_QUERY_ON_STREAM).get();
// Then
assertThat(streamedQueryResult.columnNames(), is(TEST_COLUMN_NAMES));
assertThat(streamedQueryResult.columnTypes(), is(TEST_COLUMN_TYPES));
assertThat(streamedQueryResult.queryID(), is(notNullValue()));
shouldReceiveRows(streamedQueryResult, 6, rows -> verifyStreamRows(rows, 6), true);
}
use of io.confluent.ksql.api.client.StreamedQueryResult in project ksql by confluentinc.
the class ClientIntegrationTest method shouldAllowSubscribeStreamedQueryResultIfComplete.
@Test
public void shouldAllowSubscribeStreamedQueryResultIfComplete() throws Exception {
// Given
final StreamedQueryResult streamedQueryResult = client.streamQuery(PUSH_QUERY_WITH_LIMIT).get();
assertThatEventually(streamedQueryResult::isComplete, is(true));
// When
final TestSubscriber<Row> subscriber = subscribeAndWait(streamedQueryResult);
assertThat(subscriber.getValues(), hasSize(0));
subscriber.getSub().request(PUSH_QUERY_LIMIT_NUM_ROWS);
// Then
assertThatEventually(subscriber::getValues, hasSize(PUSH_QUERY_LIMIT_NUM_ROWS));
verifyStreamRows(subscriber.getValues(), PUSH_QUERY_LIMIT_NUM_ROWS);
assertThat(subscriber.getError(), is(nullValue()));
}
Aggregations