use of io.crate.operation.PageResultListener in project crate by crate.
the class PageDownstreamContextTest method testListenerCalledAfterOthersHasFailed.
@Test
public void testListenerCalledAfterOthersHasFailed() throws Exception {
TestingBatchConsumer consumer = new TestingBatchConsumer();
PageDownstreamContext ctx = getPageDownstreamContext(consumer, PassThroughPagingIterator.oneShot(), 2);
ctx.failure(0, new Exception("dummy"));
PageResultListener listener = mock(PageResultListener.class);
ctx.setBucket(1, Bucket.EMPTY, true, listener);
verify(listener, times(1)).needMore(false);
}
use of io.crate.operation.PageResultListener in project crate by crate.
the class PageDownstreamContextTest method testCantSetSameBucketTwiceWithoutReceivingFullPage.
@Test
public void testCantSetSameBucketTwiceWithoutReceivingFullPage() throws Throwable {
TestingBatchConsumer batchConsumer = new TestingBatchConsumer();
PageBucketReceiver ctx = getPageDownstreamContext(batchConsumer, PassThroughPagingIterator.oneShot(), 3);
PageResultListener pageResultListener = mock(PageResultListener.class);
Bucket bucket = new CollectionBucket(Collections.singletonList(new Object[] { "foo" }));
ctx.setBucket(1, bucket, false, pageResultListener);
ctx.setBucket(1, bucket, false, pageResultListener);
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("Same bucket of a page set more than once. node=n1 method=setBucket phaseId=1 bucket=1");
batchConsumer.getResult();
}
use of io.crate.operation.PageResultListener in project crate by crate.
the class PageDownstreamContext method fetchFromUnExhausted.
private void fetchFromUnExhausted() {
for (int idx = 0; idx < numBuckets; idx++) {
if (exhausted.get(idx)) {
setToEmptyBucket(idx);
} else {
PageResultListener resultListener = listenersByBucketIdx.remove(idx);
resultListener.needMore(true);
}
}
}
use of io.crate.operation.PageResultListener in project crate by crate.
the class PageDownstreamContext method fetchExhausted.
private void fetchExhausted(Integer exhaustedBucket) {
for (int i = 0; i < numBuckets; i++) {
if (exhaustedBucket.equals(i) == false) {
setToEmptyBucket(i);
}
}
PageResultListener pageResultListener = listenersByBucketIdx.remove(exhaustedBucket);
pageResultListener.needMore(true);
}
use of io.crate.operation.PageResultListener 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"));
}
Aggregations