Search in sources :

Example 11 with CollectionBucket

use of io.crate.data.CollectionBucket in project crate by crate.

the class HandlerSideLevelCollectTest method collect.

private Bucket collect(RoutedCollectPhase collectPhase) throws Exception {
    TestingRowConsumer consumer = new TestingRowConsumer();
    CollectTask collectTask = mock(CollectTask.class);
    when(collectTask.txnCtx()).thenReturn(txnCtx);
    BatchIterator<Row> bi = operation.createIterator(txnCtx, collectPhase, consumer.requiresScroll(), collectTask).get(5, TimeUnit.SECONDS);
    consumer.accept(bi, null);
    return new CollectionBucket(consumer.getResult());
}
Also used : Row(io.crate.data.Row) TestingRowConsumer(io.crate.testing.TestingRowConsumer) CollectionBucket(io.crate.data.CollectionBucket)

Example 12 with CollectionBucket

use of io.crate.data.CollectionBucket in project crate by crate.

the class DistributingConsumerTest method testSendUsingDistributingConsumerAndReceiveWithDistResultRXTask.

@Test
public void testSendUsingDistributingConsumerAndReceiveWithDistResultRXTask() throws Exception {
    try {
        Streamer<?>[] streamers = { DataTypes.INTEGER.streamer() };
        TestingRowConsumer collectingConsumer = new TestingRowConsumer();
        DistResultRXTask distResultRXTask = createPageDownstreamContext(streamers, collectingConsumer);
        TransportDistributedResultAction distributedResultAction = createFakeTransport(streamers, distResultRXTask);
        DistributingConsumer distributingConsumer = createDistributingConsumer(streamers, distributedResultAction);
        BatchSimulatingIterator<Row> batchSimulatingIterator = new BatchSimulatingIterator<>(TestingBatchIterators.range(0, 5), 2, 3, executorService);
        distributingConsumer.accept(batchSimulatingIterator, 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());
    } finally {
        executorService.shutdown();
        executorService.awaitTermination(10, TimeUnit.SECONDS);
    }
}
Also used : Streamer(io.crate.Streamer) BatchSimulatingIterator(io.crate.testing.BatchSimulatingIterator) Row(io.crate.data.Row) DistResultRXTask(io.crate.execution.jobs.DistResultRXTask) TestingRowConsumer(io.crate.testing.TestingRowConsumer) CollectionBucket(io.crate.data.CollectionBucket) Test(org.junit.Test)

Example 13 with CollectionBucket

use of io.crate.data.CollectionBucket 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)

Example 14 with CollectionBucket

use of io.crate.data.CollectionBucket in project crate by crate.

the class PageDownstreamContextTest method testPagingWithSortedPagingIterator.

@Test
public void testPagingWithSortedPagingIterator() throws Throwable {
    TestingBatchConsumer batchConsumer = new TestingBatchConsumer();
    PageDownstreamContext ctx = getPageDownstreamContext(batchConsumer, new SortedPagingIterator<>(Comparator.comparingInt(r -> (int) r.get(0)), false), 2);
    Bucket b1 = new ArrayBucket(new Object[][] { new Object[] { 1 }, new Object[] { 1 } });
    Bucket b11 = new ArrayBucket(new Object[][] { new Object[] { 2 }, new Object[] { 2 } });
    ctx.setBucket(0, b1, false, new PageResultListener() {

        @Override
        public void needMore(boolean needMore) {
            if (needMore) {
                ctx.setBucket(0, b11, true, mock(PageResultListener.class));
            }
        }
    });
    Bucket b2 = new ArrayBucket(new Object[][] { new Object[] { 4 } });
    ctx.setBucket(1, b2, true, mock(PageResultListener.class));
    List<Object[]> result = batchConsumer.getResult();
    assertThat(TestingHelpers.printedTable(new CollectionBucket(result)), is("1\n" + "1\n" + "2\n" + "2\n" + "4\n"));
}
Also used : ArrayBucket(io.crate.data.ArrayBucket) Bucket(io.crate.data.Bucket) CollectionBucket(io.crate.data.CollectionBucket) ArrayBucket(io.crate.data.ArrayBucket) PageResultListener(io.crate.operation.PageResultListener) TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) CollectionBucket(io.crate.data.CollectionBucket) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 15 with CollectionBucket

use of io.crate.data.CollectionBucket in project crate by crate.

the class MultiConsumerTest method testSuccessfulMultiConsumerUsage.

@Test
public void testSuccessfulMultiConsumerUsage() throws Exception {
    TestingBatchConsumer batchConsumer = new TestingBatchConsumer();
    BatchConsumer consumer = new CompositeCollector.MultiConsumer(2, batchConsumer, CompositeBatchIterator::new);
    consumer.accept(TestingBatchIterators.range(3, 6), null);
    consumer.accept(TestingBatchIterators.range(0, 3), null);
    List<Object[]> result = batchConsumer.getResult();
    assertThat(TestingHelpers.printedTable(new CollectionBucket(result)), is("0\n" + "1\n" + "2\n" + "3\n" + "4\n" + "5\n"));
}
Also used : CompositeBatchIterator(io.crate.data.CompositeBatchIterator) TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) BatchConsumer(io.crate.data.BatchConsumer) TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) CollectionBucket(io.crate.data.CollectionBucket) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

CollectionBucket (io.crate.data.CollectionBucket)20 Test (org.junit.Test)17 Bucket (io.crate.data.Bucket)11 TestingRowConsumer (io.crate.testing.TestingRowConsumer)11 Row (io.crate.data.Row)8 ArrayBucket (io.crate.data.ArrayBucket)7 TestingBatchConsumer (io.crate.testing.TestingBatchConsumer)6 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)5 InputColumn (io.crate.expression.symbol.InputColumn)4 CrateUnitTest (io.crate.test.integration.CrateUnitTest)4 TestingHelpers.isRow (io.crate.testing.TestingHelpers.isRow)4 Projector (io.crate.data.Projector)3 RowN (io.crate.data.RowN)3 GroupingProjector (io.crate.execution.engine.aggregation.GroupingProjector)3 SortingProjector (io.crate.execution.engine.sort.SortingProjector)3 SortingTopNProjector (io.crate.execution.engine.sort.SortingTopNProjector)3 Symbol (io.crate.expression.symbol.Symbol)3 ArrayList (java.util.ArrayList)3 Streamer (io.crate.Streamer)2 ColumnIdent (io.crate.metadata.ColumnIdent)2