Search in sources :

Example 61 with TestingRowConsumer

use of io.crate.testing.TestingRowConsumer in project crate by crate.

the class DistResultRXTaskTest method testNonSequentialBucketIds.

@Test
public void testNonSequentialBucketIds() throws Exception {
    TestingRowConsumer batchConsumer = new TestingRowConsumer();
    DistResultRXTask ctx = getPageDownstreamContext(batchConsumer, PassThroughPagingIterator.oneShot(), 3);
    PageBucketReceiver bucketReceiver = ctx.getBucketReceiver((byte) 0);
    assertThat(bucketReceiver, notNullValue());
    final PageResultListener mockListener = mock(PageResultListener.class);
    Bucket b1 = new CollectionBucket(Collections.singletonList(new Object[] { "foo" }));
    bucketReceiver.setBucket(0, b1, true, mockListener);
    Bucket b2 = new CollectionBucket(Collections.singletonList(new Object[] { "bar" }));
    bucketReceiver.setBucket(3, b2, true, mockListener);
    Bucket b3 = new CollectionBucket(Collections.singletonList(new Object[] { "universe" }));
    CheckPageResultListener checkPageResultListener = new CheckPageResultListener();
    bucketReceiver.setBucket(42, b3, false, checkPageResultListener);
    assertThat(checkPageResultListener.needMoreResult, is(true));
    bucketReceiver.setBucket(42, b3, true, checkPageResultListener);
    assertThat(checkPageResultListener.needMoreResult, is(false));
    List<Object[]> result = batchConsumer.getResult();
    assertThat(result.toArray(), arrayContainingInAnyOrder(new Object[] { "foo" }, new Object[] { "bar" }, new Object[] { "universe" }, new Object[] { "universe" }));
}
Also used : Bucket(io.crate.data.Bucket) CollectionBucket(io.crate.data.CollectionBucket) ArrayBucket(io.crate.data.ArrayBucket) TestingRowConsumer(io.crate.testing.TestingRowConsumer) CollectionBucket(io.crate.data.CollectionBucket) Test(org.junit.Test)

Example 62 with TestingRowConsumer

use of io.crate.testing.TestingRowConsumer in project crate by crate.

the class DistResultRXTaskTest method testListenerCalledAfterOthersHasFailed.

@Test
public void testListenerCalledAfterOthersHasFailed() throws Exception {
    TestingRowConsumer consumer = new TestingRowConsumer();
    DistResultRXTask ctx = getPageDownstreamContext(consumer, PassThroughPagingIterator.oneShot(), 2);
    PageBucketReceiver bucketReceiver = ctx.getBucketReceiver((byte) 0);
    assertThat(bucketReceiver, notNullValue());
    bucketReceiver.kill(new Exception("dummy"));
    PageResultListener listener = mock(PageResultListener.class);
    bucketReceiver.setBucket(1, Bucket.EMPTY, true, listener);
    verify(listener, times(1)).needMore(false);
}
Also used : CompletionException(java.util.concurrent.CompletionException) TestingRowConsumer(io.crate.testing.TestingRowConsumer) Test(org.junit.Test)

Example 63 with TestingRowConsumer

use of io.crate.testing.TestingRowConsumer in project crate by crate.

the class DistResultRXTaskTest method testSetBucketOnAKilledCtxReleasesListener.

@Test
public void testSetBucketOnAKilledCtxReleasesListener() throws Exception {
    TestingRowConsumer consumer = new TestingRowConsumer();
    DistResultRXTask ctx = getPageDownstreamContext(consumer, PassThroughPagingIterator.oneShot(), 2);
    PageBucketReceiver bucketReceiver = ctx.getBucketReceiver((byte) 0);
    assertThat(bucketReceiver, notNullValue());
    ctx.kill(new InterruptedException("killed"));
    CompletableFuture<Void> listenerReleased = new CompletableFuture<>();
    bucketReceiver.setBucket(0, Bucket.EMPTY, false, needMore -> listenerReleased.complete(null));
    // Must not timeout
    listenerReleased.get(1, TimeUnit.SECONDS);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) TestingRowConsumer(io.crate.testing.TestingRowConsumer) Test(org.junit.Test)

Example 64 with TestingRowConsumer

use of io.crate.testing.TestingRowConsumer in project crate by crate.

the class CountTaskTest method testClose.

@Test
public void testClose() throws Exception {
    CompletableFuture<Long> future = new CompletableFuture<>();
    CountOperation countOperation = mock(CountOperation.class);
    when(countOperation.count(eq(txnCtx), any(), any(Symbol.class))).thenReturn(future);
    CountTask countTask = new CountTask(countPhaseWithId(1), txnCtx, countOperation, new TestingRowConsumer(), null);
    countTask.start();
    future.complete(1L);
    assertTrue(countTask.isClosed());
    // assure that there was no exception
    countTask.completionFuture().get();
    // on error
    future = new CompletableFuture<>();
    when(countOperation.count(eq(txnCtx), any(), any(Symbol.class))).thenReturn(future);
    countTask = new CountTask(countPhaseWithId(2), txnCtx, countOperation, new TestingRowConsumer(), null);
    countTask.start();
    future.completeExceptionally(new UnhandledServerException("dummy"));
    assertTrue(countTask.isClosed());
    expectedException.expectCause(CauseMatcher.cause(UnhandledServerException.class));
    countTask.completionFuture().get();
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Symbol(io.crate.expression.symbol.Symbol) UnhandledServerException(io.crate.exceptions.UnhandledServerException) CountOperation(io.crate.execution.engine.collect.count.CountOperation) TestingRowConsumer(io.crate.testing.TestingRowConsumer) Test(org.junit.Test)

Aggregations

TestingRowConsumer (io.crate.testing.TestingRowConsumer)64 Test (org.junit.Test)55 Row (io.crate.data.Row)24 CollectionBucket (io.crate.data.CollectionBucket)11 Bucket (io.crate.data.Bucket)10 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)10 InputColumn (io.crate.expression.symbol.InputColumn)6 BatchSimulatingIterator (io.crate.testing.BatchSimulatingIterator)6 ArrayBucket (io.crate.data.ArrayBucket)5 TestingHelpers.isRow (io.crate.testing.TestingHelpers.isRow)5 Streamer (io.crate.Streamer)4 Projector (io.crate.data.Projector)4 GroupingProjector (io.crate.execution.engine.aggregation.GroupingProjector)4 SortingProjector (io.crate.execution.engine.sort.SortingProjector)4 SortingTopNProjector (io.crate.execution.engine.sort.SortingTopNProjector)4 DistResultRXTask (io.crate.execution.jobs.DistResultRXTask)4 ArrayList (java.util.ArrayList)4 RowAccounting (io.crate.breaker.RowAccounting)3 CombinedRow (io.crate.data.join.CombinedRow)3 CompletionException (java.util.concurrent.CompletionException)3