Search in sources :

Example 46 with TestingRowConsumer

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

the class DistributingConsumerTest method test_exception_on_loadNextBatch_is_forwarded.

@Test
public void test_exception_on_loadNextBatch_is_forwarded() 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);
    BatchSimulatingIterator<Row> batchSimulatingIterator = new BatchSimulatingIterator<>(TestingBatchIterators.range(0, 5), 2, 3, executorService) {

        @Override
        public CompletionStage<?> loadNextBatch() {
            throw new CircuitBreakingException("data too large");
        }
    };
    distributingConsumer.accept(batchSimulatingIterator, null);
    expectedException.expect(CircuitBreakingException.class);
    collectingConsumer.getResult();
}
Also used : Streamer(io.crate.Streamer) BatchSimulatingIterator(io.crate.testing.BatchSimulatingIterator) CircuitBreakingException(org.elasticsearch.common.breaker.CircuitBreakingException) Row(io.crate.data.Row) DistResultRXTask(io.crate.execution.jobs.DistResultRXTask) TestingRowConsumer(io.crate.testing.TestingRowConsumer) Test(org.junit.Test)

Example 47 with TestingRowConsumer

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

the class IndexWriterProjectorUnitTest method testNullPKValue.

@Test
public void testNullPKValue() throws Throwable {
    InputCollectExpression sourceInput = new InputCollectExpression(0);
    List<CollectExpression<Row, ?>> collectExpressions = Collections.<CollectExpression<Row, ?>>singletonList(sourceInput);
    TransportCreatePartitionsAction transportCreatePartitionsAction = mock(TransportCreatePartitionsAction.class);
    IndexWriterProjector indexWriter = new IndexWriterProjector(clusterService, new NodeLimits(new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)), new NoopCircuitBreaker("dummy"), RamAccounting.NO_ACCOUNTING, scheduler, executor, CoordinatorTxnCtx.systemTransactionContext(), createNodeContext(), Settings.EMPTY, 5, 1, transportCreatePartitionsAction, (request, listener) -> {
    }, IndexNameResolver.forTable(BULK_IMPORT_IDENT), RAW_SOURCE_REFERENCE, Collections.singletonList(ID_IDENT), Collections.<Symbol>singletonList(new InputColumn(1)), null, null, sourceInput, collectExpressions, 20, null, null, false, false, UUID.randomUUID(), UpsertResultContext.forRowCount(), false);
    RowN rowN = new RowN(new Object[] { new BytesRef("{\"y\": \"x\"}"), null });
    BatchIterator<Row> batchIterator = InMemoryBatchIterator.of(Collections.singletonList(rowN), SENTINEL, true);
    batchIterator = indexWriter.apply(batchIterator);
    TestingRowConsumer testingBatchConsumer = new TestingRowConsumer();
    testingBatchConsumer.accept(batchIterator, null);
    List<Object[]> result = testingBatchConsumer.getResult();
    // Zero affected rows as a NULL as a PK value will result in an exception.
    // It must never bubble up as other rows might already have been written.
    assertThat(result.get(0)[0], is(0L));
}
Also used : TransportCreatePartitionsAction(org.elasticsearch.action.admin.indices.create.TransportCreatePartitionsAction) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) CollectExpression(io.crate.execution.engine.collect.CollectExpression) InputCollectExpression(io.crate.execution.engine.collect.InputCollectExpression) RowN(io.crate.data.RowN) InputCollectExpression(io.crate.execution.engine.collect.InputCollectExpression) InputColumn(io.crate.expression.symbol.InputColumn) NodeLimits(io.crate.execution.jobs.NodeLimits) Row(io.crate.data.Row) NoopCircuitBreaker(org.elasticsearch.common.breaker.NoopCircuitBreaker) BytesRef(org.apache.lucene.util.BytesRef) TestingRowConsumer(io.crate.testing.TestingRowConsumer) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 48 with TestingRowConsumer

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

the class HashInnerJoinBatchIteratorBehaviouralTest method testDistributed_SwitchToRightEvenIfLeftBatchDoesNotDeliverAllRowsExpectedByOneBatch.

@Test
public void testDistributed_SwitchToRightEvenIfLeftBatchDoesNotDeliverAllRowsExpectedByOneBatch() throws Exception {
    BatchSimulatingIterator<Row> leftIterator = new BatchSimulatingIterator<>(TestingBatchIterators.ofValues(Arrays.asList(1, 2, 4)), 1, 2, null);
    BatchSimulatingIterator<Row> rightIterator = new BatchSimulatingIterator<>(TestingBatchIterators.ofValues(Arrays.asList(2, 0, 4, 5)), 2, 1, null);
    BatchIterator<Row> batchIterator = new HashInnerJoinBatchIterator(leftIterator, rightIterator, mock(RowAccounting.class), new CombinedRow(1, 1), row -> Objects.equals(row.get(0), row.get(1)), row -> Objects.hash(row.get(0)), row -> Objects.hash(row.get(0)), () -> 2);
    TestingRowConsumer consumer = new TestingRowConsumer();
    consumer.accept(batchIterator, null);
    List<Object[]> result = consumer.getResult();
    assertThat(result, contains(new Object[] { 2, 2 }, new Object[] { 4, 4 }));
    // as the blocksize is defined of 2 but the left batch size 1, normally it would call left loadNextBatch until
    // the blocksize is reached. we don't want that as parallel running hash iterators must call loadNextBatch always
    // on the same side synchronously as the upstreams will only send new data after all downstreams responded.
    // to validate this, the right must be repeated 3 times
    assertThat(rightIterator.getMovetoStartCalls(), is(2));
}
Also used : RowAccounting(io.crate.breaker.RowAccounting) BatchSimulatingIterator(io.crate.testing.BatchSimulatingIterator) Row(io.crate.data.Row) CombinedRow(io.crate.data.join.CombinedRow) CombinedRow(io.crate.data.join.CombinedRow) TestingRowConsumer(io.crate.testing.TestingRowConsumer) Test(org.junit.Test)

Example 49 with TestingRowConsumer

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

the class RemoteCollectorTest method prepare.

@Before
public void prepare() {
    MockitoAnnotations.initMocks(this);
    UUID jobId = UUID.randomUUID();
    RoutedCollectPhase collectPhase = new RoutedCollectPhase(jobId, 0, "remoteCollect", new Routing(Map.of("remoteNode", Map.of("dummyTable", IntArrayList.from(1)))), RowGranularity.DOC, Collections.singletonList(createReference("name", DataTypes.STRING)), Collections.emptyList(), WhereClause.MATCH_ALL.queryOrFallback(), DistributionInfo.DEFAULT_BROADCAST);
    transportJobAction = mock(TransportJobAction.class);
    TasksService tasksService = new TasksService(clusterService, new JobsLogs(() -> true));
    numBroadcastCalls = new AtomicInteger(0);
    transportKillJobsNodeAction = new TransportKillJobsNodeAction(tasksService, clusterService, mock(TransportService.class)) {

        @Override
        public void broadcast(KillJobsRequest request, ActionListener<Long> listener) {
            numBroadcastCalls.incrementAndGet();
        }
    };
    consumer = new TestingRowConsumer();
    remoteCollector = new RemoteCollector(jobId, new SessionSettings("dummyUser", SearchPath.createSearchPathFrom("dummySchema")), "localNode", "remoteNode", transportJobAction, transportKillJobsNodeAction, Runnable::run, tasksService, RamAccounting.NO_ACCOUNTING, consumer, collectPhase);
}
Also used : TransportJobAction(io.crate.execution.jobs.transport.TransportJobAction) TransportKillJobsNodeAction(io.crate.execution.jobs.kill.TransportKillJobsNodeAction) Routing(io.crate.metadata.Routing) TasksService(io.crate.execution.jobs.TasksService) SessionSettings(io.crate.metadata.settings.SessionSettings) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) KillJobsRequest(io.crate.execution.jobs.kill.KillJobsRequest) JobsLogs(io.crate.execution.engine.collect.stats.JobsLogs) UUID(java.util.UUID) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) TestingRowConsumer(io.crate.testing.TestingRowConsumer) Before(org.junit.Before)

Example 50 with TestingRowConsumer

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

the class MapSideDataCollectOperationTest method testFileUriCollect.

@Test
public void testFileUriCollect() throws Exception {
    FileCollectSource fileCollectSource = new FileCollectSource(createNodeContext(), clusterService, Collections.emptyMap());
    File tmpFile = temporaryFolder.newFile("fileUriCollectOperation.json");
    try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(tmpFile), StandardCharsets.UTF_8)) {
        writer.write("{\"name\": \"Arthur\", \"id\": 4, \"details\": {\"age\": 38}}\n");
        writer.write("{\"id\": 5, \"name\": \"Trillian\", \"details\": {\"age\": 33}}\n");
    }
    FileUriCollectPhase collectNode = new FileUriCollectPhase(UUID.randomUUID(), 0, "test", Collections.singletonList("noop_id"), Literal.of(Paths.get(tmpFile.toURI()).toUri().toString()), Arrays.asList(createReference("name", DataTypes.STRING), createReference(new ColumnIdent("details", "age"), DataTypes.INTEGER)), Collections.emptyList(), null, false, CopyFromParserProperties.DEFAULT, FileUriCollectPhase.InputFormat.JSON, Settings.EMPTY);
    TestingRowConsumer consumer = new TestingRowConsumer();
    CollectTask collectTask = mock(CollectTask.class);
    BatchIterator<Row> iterator = fileCollectSource.getIterator(CoordinatorTxnCtx.systemTransactionContext(), collectNode, collectTask, false).get(5, TimeUnit.SECONDS);
    consumer.accept(iterator, null);
    assertThat(new CollectionBucket(consumer.getResult()), contains(isRow("Arthur", 38), isRow("Trillian", 33)));
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) FileCollectSource(io.crate.execution.engine.collect.sources.FileCollectSource) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) FileUriCollectPhase(io.crate.execution.dsl.phases.FileUriCollectPhase) TestingHelpers.isRow(io.crate.testing.TestingHelpers.isRow) Row(io.crate.data.Row) File(java.io.File) TestingRowConsumer(io.crate.testing.TestingRowConsumer) CollectionBucket(io.crate.data.CollectionBucket) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) 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