Search in sources :

Example 1 with PageResultListener

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);
}
Also used : PageResultListener(io.crate.operation.PageResultListener) TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 2 with PageResultListener

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();
}
Also used : 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 3 with PageResultListener

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);
        }
    }
}
Also used : PageResultListener(io.crate.operation.PageResultListener)

Example 4 with PageResultListener

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);
}
Also used : PageResultListener(io.crate.operation.PageResultListener)

Example 5 with PageResultListener

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

Aggregations

PageResultListener (io.crate.operation.PageResultListener)6 CrateUnitTest (io.crate.test.integration.CrateUnitTest)4 TestingBatchConsumer (io.crate.testing.TestingBatchConsumer)4 Test (org.junit.Test)4 ArrayBucket (io.crate.data.ArrayBucket)2 Bucket (io.crate.data.Bucket)2 CollectionBucket (io.crate.data.CollectionBucket)2