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());
}
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);
}
}
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());
}
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"));
}
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"));
}
Aggregations