Search in sources :

Example 11 with StreamedQueryResult

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));
}
Also used : HashMap(java.util.HashMap) KsqlObject(io.confluent.ksql.api.client.KsqlObject) Matchers.containsString(org.hamcrest.Matchers.containsString) Row(io.confluent.ksql.api.client.Row) ZooKeeperClientException(kafka.zookeeper.ZooKeeperClientException) KsqlClientException(io.confluent.ksql.api.client.exception.KsqlClientException) ExecutionException(java.util.concurrent.ExecutionException) KsqlObject(io.confluent.ksql.api.client.KsqlObject) StreamedQueryResult(io.confluent.ksql.api.client.StreamedQueryResult) IntegrationTest(io.confluent.common.utils.IntegrationTest) Test(org.junit.Test)

Example 12 with StreamedQueryResult

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()));
}
Also used : Row(io.confluent.ksql.api.client.Row) GenericRow(io.confluent.ksql.GenericRow) StreamedQueryResult(io.confluent.ksql.api.client.StreamedQueryResult) Test(org.junit.Test) IntegrationTest(io.confluent.common.utils.IntegrationTest)

Example 13 with StreamedQueryResult

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));
}
Also used : Row(io.confluent.ksql.api.client.Row) GenericRow(io.confluent.ksql.GenericRow) LinkedList(java.util.LinkedList) StreamedQueryResult(io.confluent.ksql.api.client.StreamedQueryResult) Test(org.junit.Test) IntegrationTest(io.confluent.common.utils.IntegrationTest)

Example 14 with StreamedQueryResult

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);
}
Also used : StreamedQueryResult(io.confluent.ksql.api.client.StreamedQueryResult) Test(org.junit.Test) IntegrationTest(io.confluent.common.utils.IntegrationTest)

Example 15 with StreamedQueryResult

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()));
}
Also used : Row(io.confluent.ksql.api.client.Row) GenericRow(io.confluent.ksql.GenericRow) StreamedQueryResult(io.confluent.ksql.api.client.StreamedQueryResult) Test(org.junit.Test) IntegrationTest(io.confluent.common.utils.IntegrationTest)

Aggregations

StreamedQueryResult (io.confluent.ksql.api.client.StreamedQueryResult)20 Test (org.junit.Test)20 IntegrationTest (io.confluent.common.utils.IntegrationTest)16 Row (io.confluent.ksql.api.client.Row)10 GenericRow (io.confluent.ksql.GenericRow)8 LinkedList (java.util.LinkedList)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 KsqlObject (io.confluent.ksql.api.client.KsqlObject)2 KsqlClientException (io.confluent.ksql.api.client.exception.KsqlClientException)2 ClientImpl (io.confluent.ksql.api.client.impl.ClientImpl)2 HashMap (java.util.HashMap)2 ExecutionException (java.util.concurrent.ExecutionException)2 ZooKeeperClientException (kafka.zookeeper.ZooKeeperClientException)2 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)2 KsqlArray (io.confluent.ksql.api.client.KsqlArray)1 BigDecimal (java.math.BigDecimal)1