Search in sources :

Example 36 with TestingBatchConsumer

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

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

Example 38 with TestingBatchConsumer

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

Example 39 with TestingBatchConsumer

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")));
}
Also used : QueryThenFetch(io.crate.planner.node.dql.QueryThenFetch) Merge(io.crate.planner.Merge) TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test)

Example 40 with TestingBatchConsumer

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

TestingBatchConsumer (io.crate.testing.TestingBatchConsumer)47 Test (org.junit.Test)41 CrateUnitTest (io.crate.test.integration.CrateUnitTest)32 BytesRef (org.apache.lucene.util.BytesRef)7 CollectionBucket (io.crate.data.CollectionBucket)6 Bucket (io.crate.data.Bucket)4 PageResultListener (io.crate.operation.PageResultListener)4 RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)4 Streamer (io.crate.Streamer)3 NestedLoopBatchIterator (io.crate.data.join.NestedLoopBatchIterator)3 SQLTransportIntegrationTest (io.crate.integrationtests.SQLTransportIntegrationTest)3 Routing (io.crate.metadata.Routing)3 SharedShardContexts (io.crate.action.job.SharedShardContexts)2 InputColumn (io.crate.analyze.symbol.InputColumn)2 ArrayBucket (io.crate.data.ArrayBucket)2 BatchConsumer (io.crate.data.BatchConsumer)2 CompositeBatchIterator (io.crate.data.CompositeBatchIterator)2 PageDownstreamContext (io.crate.jobs.PageDownstreamContext)2 PartitionName (io.crate.metadata.PartitionName)2 CollectExpression (io.crate.operation.collect.CollectExpression)2