Search in sources :

Example 1 with TestingBatchConsumer

use of io.crate.testing.TestingBatchConsumer 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 TestingBatchConsumer

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

the class PageDownstreamContextTest method testKillCallsDownstream.

@Test
public void testKillCallsDownstream() throws Throwable {
    TestingBatchConsumer batchConsumer = new TestingBatchConsumer();
    PageDownstreamContext ctx = getPageDownstreamContext(batchConsumer, PassThroughPagingIterator.oneShot(), 3);
    final AtomicReference<Throwable> throwable = new AtomicReference<>();
    ctx.completionFuture().whenComplete((r, t) -> {
        if (t != null) {
            assertTrue(throwable.compareAndSet(null, t));
        } else {
            fail("Expected exception");
        }
    });
    ctx.kill(null);
    assertThat(throwable.get(), instanceOf(InterruptedException.class));
    expectedException.expect(InterruptedException.class);
    batchConsumer.getResult();
}
Also used : TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 3 with TestingBatchConsumer

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

the class CountContextTest method testClose.

@Test
public void testClose() throws Exception {
    SettableFuture<Long> future = SettableFuture.create();
    CountOperation countOperation = mock(CountOperation.class);
    when(countOperation.count(anyMap(), any(WhereClause.class))).thenReturn(future);
    CountContext countContext = new CountContext(1, countOperation, new TestingBatchConsumer(), null, WhereClause.MATCH_ALL);
    countContext.prepare();
    countContext.start();
    future.set(1L);
    assertTrue(countContext.future.closed());
    // assure that there was no exception
    countContext.completionFuture().get();
    // on error
    future = SettableFuture.create();
    when(countOperation.count(anyMap(), any(WhereClause.class))).thenReturn(future);
    countContext = new CountContext(2, countOperation, new TestingBatchConsumer(), null, WhereClause.MATCH_ALL);
    countContext.prepare();
    countContext.start();
    future.setException(new UnknownUpstreamFailure());
    assertTrue(countContext.future.closed());
    expectedException.expectCause(CauseMatcher.cause(UnknownUpstreamFailure.class));
    countContext.completionFuture().get();
}
Also used : UnknownUpstreamFailure(io.crate.exceptions.UnknownUpstreamFailure) WhereClause(io.crate.analyze.WhereClause) TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) CountOperation(io.crate.operation.count.CountOperation) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 4 with TestingBatchConsumer

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

the class JobExecutionContextTest method testFailureClosesAllSubContexts.

@Test
public void testFailureClosesAllSubContexts() throws Exception {
    String localNodeId = "localNodeId";
    RoutedCollectPhase collectPhase = Mockito.mock(RoutedCollectPhase.class);
    Routing routing = Mockito.mock(Routing.class);
    when(routing.containsShards(localNodeId)).thenReturn(false);
    when(collectPhase.routing()).thenReturn(routing);
    when(collectPhase.maxRowGranularity()).thenReturn(RowGranularity.DOC);
    JobExecutionContext.Builder builder = new JobExecutionContext.Builder(UUID.randomUUID(), coordinatorNode, Collections.emptyList(), mock(JobsLogs.class));
    JobCollectContext jobCollectContext = new JobCollectContext(collectPhase, mock(MapSideDataCollectOperation.class), localNodeId, mock(RamAccountingContext.class), new TestingBatchConsumer(), mock(SharedShardContexts.class));
    TestingBatchConsumer batchConsumer = new TestingBatchConsumer();
    PageDownstreamContext pageDownstreamContext = spy(new PageDownstreamContext(Loggers.getLogger(PageDownstreamContext.class), "n1", 2, "dummy", batchConsumer, PassThroughPagingIterator.oneShot(), new Streamer[] { IntegerType.INSTANCE.streamer() }, mock(RamAccountingContext.class), 1));
    builder.addSubContext(jobCollectContext);
    builder.addSubContext(pageDownstreamContext);
    JobExecutionContext jobExecutionContext = builder.build();
    Exception failure = new Exception("failure!");
    jobCollectContext.close(failure);
    // other contexts must be killed with same failure
    verify(pageDownstreamContext, times(1)).innerKill(failure);
    final Field subContexts = JobExecutionContext.class.getDeclaredField("subContexts");
    subContexts.setAccessible(true);
    int size = ((ConcurrentMap<Integer, ExecutionSubContext>) subContexts.get(jobExecutionContext)).size();
    assertThat(size, is(0));
}
Also used : RamAccountingContext(io.crate.breaker.RamAccountingContext) MapSideDataCollectOperation(io.crate.operation.collect.MapSideDataCollectOperation) ConcurrentMap(java.util.concurrent.ConcurrentMap) Routing(io.crate.metadata.Routing) JobCollectContext(io.crate.operation.collect.JobCollectContext) Field(java.lang.reflect.Field) SharedShardContexts(io.crate.action.job.SharedShardContexts) Streamer(io.crate.Streamer) TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) JobsLogs(io.crate.operation.collect.stats.JobsLogs) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 5 with TestingBatchConsumer

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

the class PageDownstreamContextTest method testSetBucketOnAKilledCtxReleasesListener.

@Test
public void testSetBucketOnAKilledCtxReleasesListener() throws Exception {
    TestingBatchConsumer consumer = new TestingBatchConsumer();
    PageDownstreamContext ctx = getPageDownstreamContext(consumer, PassThroughPagingIterator.oneShot(), 2);
    ctx.kill(new InterruptedException("killed"));
    CompletableFuture<Void> listenerReleased = new CompletableFuture<>();
    ctx.setBucket(0, Bucket.EMPTY, false, needMore -> listenerReleased.complete(null));
    // Must not timeout
    listenerReleased.get(1, TimeUnit.SECONDS);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) 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