Search in sources :

Example 1 with StreamedRow

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

the class ConsoleTest method testPrintErrorStreamedRow.

@Test
public void testPrintErrorStreamedRow() throws IOException {
    StreamedRow row = new StreamedRow(new FakeException());
    terminal.printStreamedRow(row);
}
Also used : StreamedRow(io.confluent.ksql.rest.entity.StreamedRow) FakeException(io.confluent.ksql.FakeException) Test(org.junit.Test)

Example 2 with StreamedRow

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

the class QueryStreamWriter method write.

private void write(OutputStream output, GenericRow row) throws IOException {
    objectMapper.writeValue(output, new StreamedRow(row));
    output.write("\n".getBytes(StandardCharsets.UTF_8));
    output.flush();
}
Also used : StreamedRow(io.confluent.ksql.rest.entity.StreamedRow)

Example 3 with StreamedRow

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

the class KsqlRestClientTest method testStreamRowFromServer.

@Test
public void testStreamRowFromServer() throws InterruptedException {
    MockStreamedQueryResource sqr = mockApplication.getStreamedQueryResource();
    RestResponse<KsqlRestClient.QueryStream> queryResponse = ksqlRestClient.makeQueryRequest("Select *");
    Assert.assertNotNull(queryResponse);
    Assert.assertTrue(queryResponse.isSuccessful());
    // Get the stream writer from the mock server and load it up with a row
    List<MockStreamedQueryResource.TestStreamWriter> writers = sqr.getWriters();
    Assert.assertEquals(1, writers.size());
    MockStreamedQueryResource.TestStreamWriter writer = writers.get(0);
    try {
        writer.enq("hello");
        // Try and receive the row. Do this from another thread to avoid blocking indefinitely
        KsqlRestClient.QueryStream queryStream = queryResponse.getResponse();
        Thread t = new Thread(() -> queryStream.hasNext());
        t.setDaemon(true);
        t.start();
        t.join(10000);
        Assert.assertFalse(t.isAlive());
        Assert.assertTrue(queryStream.hasNext());
        StreamedRow sr = queryStream.next();
        Assert.assertNotNull(sr);
        GenericRow row = sr.getRow();
        Assert.assertEquals(1, row.getColumns().size());
        Assert.assertEquals("hello", row.getColumns().get(0));
    } finally {
        writer.finished();
    }
}
Also used : GenericRow(io.confluent.ksql.GenericRow) StreamedRow(io.confluent.ksql.rest.entity.StreamedRow) MockStreamedQueryResource(io.confluent.ksql.rest.server.mock.MockStreamedQueryResource) Test(org.junit.Test)

Example 4 with StreamedRow

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

the class ConsoleTest method testPrintGenericStreamedRow.

@Test
public void testPrintGenericStreamedRow() throws IOException {
    StreamedRow row = new StreamedRow(new GenericRow(Arrays.asList("col_1", "col_2")));
    terminal.printStreamedRow(row);
}
Also used : GenericRow(io.confluent.ksql.GenericRow) StreamedRow(io.confluent.ksql.rest.entity.StreamedRow) Test(org.junit.Test)

Aggregations

StreamedRow (io.confluent.ksql.rest.entity.StreamedRow)4 Test (org.junit.Test)3 GenericRow (io.confluent.ksql.GenericRow)2 FakeException (io.confluent.ksql.FakeException)1 MockStreamedQueryResource (io.confluent.ksql.rest.server.mock.MockStreamedQueryResource)1