Search in sources :

Example 11 with Streamer

use of io.crate.Streamer in project crate by crate.

the class DistributingConsumerTest method testSendUsingDistributingConsumerAndReceiveWithDistResultRXTask.

@Test
public void testSendUsingDistributingConsumerAndReceiveWithDistResultRXTask() throws Exception {
    try {
        Streamer<?>[] streamers = { DataTypes.INTEGER.streamer() };
        TestingRowConsumer collectingConsumer = new TestingRowConsumer();
        DistResultRXTask distResultRXTask = createPageDownstreamContext(streamers, collectingConsumer);
        TransportDistributedResultAction distributedResultAction = createFakeTransport(streamers, distResultRXTask);
        DistributingConsumer distributingConsumer = createDistributingConsumer(streamers, distributedResultAction);
        BatchSimulatingIterator<Row> batchSimulatingIterator = new BatchSimulatingIterator<>(TestingBatchIterators.range(0, 5), 2, 3, executorService);
        distributingConsumer.accept(batchSimulatingIterator, null);
        List<Object[]> result = collectingConsumer.getResult();
        assertThat(TestingHelpers.printedTable(new CollectionBucket(result)), is("0\n" + "1\n" + "2\n" + "3\n" + "4\n"));
        // pageSize=2 and 5 rows causes 3x pushResult
        verify(distributedResultAction, times(3)).pushResult(anyString(), any(), any());
    } finally {
        executorService.shutdown();
        executorService.awaitTermination(10, TimeUnit.SECONDS);
    }
}
Also used : Streamer(io.crate.Streamer) BatchSimulatingIterator(io.crate.testing.BatchSimulatingIterator) Row(io.crate.data.Row) DistResultRXTask(io.crate.execution.jobs.DistResultRXTask) TestingRowConsumer(io.crate.testing.TestingRowConsumer) CollectionBucket(io.crate.data.CollectionBucket) Test(org.junit.Test)

Example 12 with Streamer

use of io.crate.Streamer in project crate by crate.

the class DistributingConsumerTest method testFailureOnAllLoadedIsForwarded.

@Test
public void testFailureOnAllLoadedIsForwarded() throws Exception {
    Streamer<?>[] streamers = { DataTypes.INTEGER.streamer() };
    TestingRowConsumer collectingConsumer = new TestingRowConsumer();
    DistResultRXTask distResultRXTask = createPageDownstreamContext(streamers, collectingConsumer);
    TransportDistributedResultAction distributedResultAction = createFakeTransport(streamers, distResultRXTask);
    DistributingConsumer distributingConsumer = createDistributingConsumer(streamers, distributedResultAction);
    distributingConsumer.accept(FailingBatchIterator.failOnAllLoaded(), null);
    expectedException.expect(InterruptedException.class);
    collectingConsumer.getResult();
}
Also used : Streamer(io.crate.Streamer) DistResultRXTask(io.crate.execution.jobs.DistResultRXTask) TestingRowConsumer(io.crate.testing.TestingRowConsumer) Test(org.junit.Test)

Example 13 with Streamer

use of io.crate.Streamer in project crate by crate.

the class ContextPreparer method registerContextPhases.

private void registerContextPhases(Iterable<? extends NodeOperation> nodeOperations, PreparerContext preparerContext) {
    for (NodeOperation nodeOperation : nodeOperations) {
        // context for nodeOperations without dependencies can be built immediately (e.g. FetchPhase)
        if (nodeOperation.downstreamExecutionPhaseId() == NodeOperation.NO_DOWNSTREAM) {
            logger.trace("Building context for nodeOp without downstream: {}", nodeOperation);
            if (createContexts(nodeOperation.executionPhase(), preparerContext)) {
                preparerContext.opCtx.builtNodeOperations.set(nodeOperation.executionPhase().phaseId());
            }
        }
        if (ExecutionPhases.hasDirectResponseDownstream(nodeOperation.downstreamNodes())) {
            Streamer<?>[] streamers = StreamerVisitor.streamersFromOutputs(nodeOperation.executionPhase());
            SingleBucketBuilder bucketBuilder = new SingleBucketBuilder(streamers);
            preparerContext.directResponseFutures.add(bucketBuilder.completionFuture());
            preparerContext.registerBatchConsumer(nodeOperation.downstreamExecutionPhaseId(), bucketBuilder);
        }
    }
}
Also used : Streamer(io.crate.Streamer) SingleBucketBuilder(io.crate.executor.transport.distributed.SingleBucketBuilder)

Example 14 with Streamer

use of io.crate.Streamer in project crate by crate.

the class DistributingConsumerTest method testSendUsingDistributingConsumerAndReceiveWithPageDownstreamContext.

@Test
public void testSendUsingDistributingConsumerAndReceiveWithPageDownstreamContext() throws Exception {
    Streamer<?>[] streamers = { DataTypes.INTEGER.streamer() };
    TestingBatchConsumer collectingConsumer = new TestingBatchConsumer();
    PageDownstreamContext pageDownstreamContext = createPageDownstreamContext(streamers, collectingConsumer);
    TransportDistributedResultAction distributedResultAction = createFakeTransport(streamers, pageDownstreamContext);
    DistributingConsumer distributingConsumer = createDistributingConsumer(streamers, distributedResultAction);
    distributingConsumer.accept(TestingBatchIterators.range(0, 5), null);
    List<Object[]> result = collectingConsumer.getResult();
    assertThat(TestingHelpers.printedTable(new CollectionBucket(result)), is("0\n" + "1\n" + "2\n" + "3\n" + "4\n"));
    // pageSize=2 and 5 rows causes 3x pushResult
    verify(distributedResultAction, times(3)).pushResult(anyString(), any(), any());
}
Also used : PageDownstreamContext(io.crate.jobs.PageDownstreamContext) Streamer(io.crate.Streamer) TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) CollectionBucket(io.crate.data.CollectionBucket) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 15 with Streamer

use of io.crate.Streamer in project crate by crate.

the class DistributingConsumerTest method testDistributingConsumerForwardsFailure.

@Test
public void testDistributingConsumerForwardsFailure() throws Exception {
    Streamer<?>[] streamers = { DataTypes.INTEGER.streamer() };
    TestingBatchConsumer collectingConsumer = new TestingBatchConsumer();
    PageDownstreamContext pageDownstreamContext = createPageDownstreamContext(streamers, collectingConsumer);
    TransportDistributedResultAction distributedResultAction = createFakeTransport(streamers, pageDownstreamContext);
    DistributingConsumer distributingConsumer = createDistributingConsumer(streamers, distributedResultAction);
    distributingConsumer.accept(null, new CompletionException(new IllegalArgumentException("foobar")));
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("foobar");
    collectingConsumer.getResult();
}
Also used : PageDownstreamContext(io.crate.jobs.PageDownstreamContext) Streamer(io.crate.Streamer) CompletionException(java.util.concurrent.CompletionException) TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

Streamer (io.crate.Streamer)20 Test (org.junit.Test)13 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)6 StreamInput (org.elasticsearch.common.io.stream.StreamInput)6 Row (io.crate.data.Row)4 DistResultRXTask (io.crate.execution.jobs.DistResultRXTask)4 CrateUnitTest (io.crate.test.integration.CrateUnitTest)4 TestingRowConsumer (io.crate.testing.TestingRowConsumer)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 UUID (java.util.UUID)3 IntObjectHashMap (com.carrotsearch.hppc.IntObjectHashMap)2 IntObjectMap (com.carrotsearch.hppc.IntObjectMap)2 IntCursor (com.carrotsearch.hppc.cursors.IntCursor)2 BlockBasedRamAccounting (io.crate.breaker.BlockBasedRamAccounting)2 PageDownstreamContext (io.crate.jobs.PageDownstreamContext)2 Reference (io.crate.metadata.Reference)2 RelationName (io.crate.metadata.RelationName)2 Routing (io.crate.metadata.Routing)2 Schemas (io.crate.metadata.Schemas)2