use of io.crate.testing.TestingBatchConsumer 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.testing.TestingBatchConsumer in project crate by crate.
the class CountContextTest method testKillOperationFuture.
@Test
public void testKillOperationFuture() throws Exception {
ListenableFuture<Long> future = mock(ListenableFuture.class);
CountOperation countOperation = new FakeCountOperation(future);
CountContext countContext = new CountContext(1, countOperation, new TestingBatchConsumer(), null, WhereClause.MATCH_ALL);
countContext.prepare();
countContext.start();
countContext.kill(null);
verify(future, times(1)).cancel(true);
assertTrue(countContext.future.closed());
}
use of io.crate.testing.TestingBatchConsumer in project crate by crate.
the class PageDownstreamContextTest method testListenersCalledWhenOtherUpstreamIsFailing.
@Test
public void testListenersCalledWhenOtherUpstreamIsFailing() throws Exception {
TestingBatchConsumer consumer = new TestingBatchConsumer();
PageDownstreamContext ctx = getPageDownstreamContext(consumer, PassThroughPagingIterator.oneShot(), 2);
PageResultListener listener = mock(PageResultListener.class);
ctx.setBucket(0, Bucket.EMPTY, true, listener);
ctx.failure(1, new Exception("dummy"));
verify(listener, times(1)).needMore(false);
}
use of io.crate.testing.TestingBatchConsumer in project crate by crate.
the class FetchOperationIntegrationTest method testFetchProjection.
@SuppressWarnings("ConstantConditions")
@Test
public void testFetchProjection() throws Exception {
setUpCharacters();
PlanForNode plan = plan("select id, name, substr(name, 2) from characters order by id");
QueryThenFetch qtf = ((QueryThenFetch) plan.plan);
assertThat(qtf.subPlan(), instanceOf(Merge.class));
Merge merge = (Merge) qtf.subPlan();
assertThat(((FetchProjection) merge.mergePhase().projections().get(0)).nodeReaders(), notNullValue());
assertThat(((FetchProjection) merge.mergePhase().projections().get(0)).readerIndices(), notNullValue());
TestingBatchConsumer consumer = execute(plan);
List<Object[]> result = consumer.getResult();
assertThat(result.size(), is(2));
assertThat(result.get(0).length, is(3));
assertThat(result.get(0)[0], is(1));
assertThat(result.get(0)[1], is(new BytesRef("Arthur")));
assertThat(result.get(0)[2], is(new BytesRef("rthur")));
assertThat(result.get(1)[0], is(2));
assertThat(result.get(1)[1], is(new BytesRef("Ford")));
assertThat(result.get(1)[2], is(new BytesRef("ord")));
}
use of io.crate.testing.TestingBatchConsumer 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