Search in sources :

Example 26 with TestingBatchConsumer

use of io.crate.testing.TestingBatchConsumer in project crate by crate.

the class MultiConsumerTest method testFirstAcceptNullIteratorDoesNotCauseNPE.

@Test
public void testFirstAcceptNullIteratorDoesNotCauseNPE() throws Exception {
    TestingBatchConsumer batchConsumer = new TestingBatchConsumer();
    BatchConsumer consumer = new CompositeCollector.MultiConsumer(2, batchConsumer, CompositeBatchIterator::new);
    consumer.accept(null, new IllegalStateException("dummy"));
    consumer.accept(RowsBatchIterator.empty(), null);
    expectedException.expect(IllegalStateException.class);
    expectedException.expectMessage("dummy");
    batchConsumer.getResult();
}
Also used : CompositeBatchIterator(io.crate.data.CompositeBatchIterator) TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) BatchConsumer(io.crate.data.BatchConsumer) TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 27 with TestingBatchConsumer

use of io.crate.testing.TestingBatchConsumer in project crate by crate.

the class FileReadingCollectorTest method testMultipleUriSupport.

@Test
public void testMultipleUriSupport() throws Throwable {
    List<String> fileUris = new ArrayList<>();
    fileUris.add(Paths.get(tmpFile.toURI()).toUri().toString());
    fileUris.add(Paths.get(tmpFileEmptyLine.toURI()).toUri().toString());
    TestingBatchConsumer consumer = getObjects(fileUris, null);
    Iterator<Row> it = consumer.getBucket().iterator();
    assertThat(it.next(), isRow("{\"name\": \"Arthur\", \"id\": 4, \"details\": {\"age\": 38}}"));
    assertThat(it.next(), isRow("{\"id\": 5, \"name\": \"Trillian\", \"details\": {\"age\": 33}}"));
    assertThat(it.next(), isRow("{\"name\": \"Arthur\", \"id\": 4, \"details\": {\"age\": 38}}"));
    assertThat(it.next(), isRow("{\"id\": 5, \"name\": \"Trillian\", \"details\": {\"age\": 33}}"));
}
Also used : TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) TestingHelpers.isRow(io.crate.testing.TestingHelpers.isRow) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 28 with TestingBatchConsumer

use of io.crate.testing.TestingBatchConsumer in project crate by crate.

the class NestedLoopBatchIteratorTest method testNestedLoopLeftAndRightEmpty.

@Test
public void testNestedLoopLeftAndRightEmpty() throws Exception {
    BatchIterator iterator = NestedLoopBatchIterator.crossJoin(RowsBatchIterator.empty(), RowsBatchIterator.empty());
    TestingBatchConsumer consumer = new TestingBatchConsumer();
    consumer.accept(iterator, null);
    assertThat(consumer.getResult(), Matchers.empty());
}
Also used : NestedLoopBatchIterator(io.crate.data.join.NestedLoopBatchIterator) TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) Test(org.junit.Test)

Example 29 with TestingBatchConsumer

use of io.crate.testing.TestingBatchConsumer in project crate by crate.

the class NestedLoopBatchIteratorTest method testNestedLoopRightEmpty.

@Test
public void testNestedLoopRightEmpty() throws Exception {
    BatchIterator iterator = NestedLoopBatchIterator.crossJoin(TestingBatchIterators.range(0, 5), RowsBatchIterator.empty());
    TestingBatchConsumer consumer = new TestingBatchConsumer();
    consumer.accept(iterator, null);
    assertThat(consumer.getResult(), Matchers.empty());
}
Also used : NestedLoopBatchIterator(io.crate.data.join.NestedLoopBatchIterator) TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) Test(org.junit.Test)

Example 30 with TestingBatchConsumer

use of io.crate.testing.TestingBatchConsumer in project crate by crate.

the class DistributingConsumerTest method testSendUsingDistributingConsumerAndReceiveWithPageDownstreamContext.

@Test
public void testSendUsingDistributingConsumerAndReceiveWithPageDownstreamContext() throws Exception {
    Streamer<?>[] streamers = { DataTypes.INTEGER.streamer() };
    TestingBatchConsumer collectingConsumer = new TestingBatchConsumer();
    PageDownstreamContext pageDownstreamContext = createPageDownstreamContext(streamers, collectingConsumer);
    TransportDistributedResultAction distributedResultAction = createFakeTransport(streamers, pageDownstreamContext);
    DistributingConsumer distributingConsumer = createDistributingConsumer(streamers, distributedResultAction);
    distributingConsumer.accept(TestingBatchIterators.range(0, 5), null);
    List<Object[]> result = collectingConsumer.getResult();
    assertThat(TestingHelpers.printedTable(new CollectionBucket(result)), is("0\n" + "1\n" + "2\n" + "3\n" + "4\n"));
    // pageSize=2 and 5 rows causes 3x pushResult
    verify(distributedResultAction, times(3)).pushResult(anyString(), any(), any());
}
Also used : PageDownstreamContext(io.crate.jobs.PageDownstreamContext) Streamer(io.crate.Streamer) TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) CollectionBucket(io.crate.data.CollectionBucket) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

TestingBatchConsumer (io.crate.testing.TestingBatchConsumer)47 Test (org.junit.Test)41 CrateUnitTest (io.crate.test.integration.CrateUnitTest)32 BytesRef (org.apache.lucene.util.BytesRef)7 CollectionBucket (io.crate.data.CollectionBucket)6 Bucket (io.crate.data.Bucket)4 PageResultListener (io.crate.operation.PageResultListener)4 RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)4 Streamer (io.crate.Streamer)3 NestedLoopBatchIterator (io.crate.data.join.NestedLoopBatchIterator)3 SQLTransportIntegrationTest (io.crate.integrationtests.SQLTransportIntegrationTest)3 Routing (io.crate.metadata.Routing)3 SharedShardContexts (io.crate.action.job.SharedShardContexts)2 InputColumn (io.crate.analyze.symbol.InputColumn)2 ArrayBucket (io.crate.data.ArrayBucket)2 BatchConsumer (io.crate.data.BatchConsumer)2 CompositeBatchIterator (io.crate.data.CompositeBatchIterator)2 PageDownstreamContext (io.crate.jobs.PageDownstreamContext)2 PartitionName (io.crate.metadata.PartitionName)2 CollectExpression (io.crate.operation.collect.CollectExpression)2