Search in sources :

Example 21 with BatchIteratorTester

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

the class RowsBatchIteratorTest method testCollectRowsWithSimulatedBatches.

@Test
public void testCollectRowsWithSimulatedBatches() throws Exception {
    Iterable<Row> rows = RowGenerator.range(0, 50);
    Supplier<BatchIterator> batchIteratorSupplier = () -> new CloseAssertingBatchIterator(new BatchSimulatingIterator(RowsBatchIterator.newInstance(rows, 1), 10, 5, null));
    BatchIteratorTester tester = new BatchIteratorTester(batchIteratorSupplier);
    List<Object[]> expectedResult = StreamSupport.stream(rows.spliterator(), false).map(Row::materialize).collect(Collectors.toList());
    tester.verifyResultAndEdgeCaseBehaviour(expectedResult);
}
Also used : BatchSimulatingIterator(io.crate.testing.BatchSimulatingIterator) BatchIteratorTester(io.crate.testing.BatchIteratorTester) Test(org.junit.Test)

Example 22 with BatchIteratorTester

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

the class SkippingBatchIteratorTest method testSkippingBatchIteratorWithBatchedSource.

@Test
public void testSkippingBatchIteratorWithBatchedSource() throws Exception {
    BatchIteratorTester tester = new BatchIteratorTester(() -> {
        BatchIterator source = TestingBatchIterators.range(0, 10);
        source = new CloseAssertingBatchIterator(new BatchSimulatingIterator(source, 2, 5, null));
        return new SkippingBatchIterator(source, offset);
    });
    tester.verifyResultAndEdgeCaseBehaviour(expectedResult);
}
Also used : BatchSimulatingIterator(io.crate.testing.BatchSimulatingIterator) BatchIteratorTester(io.crate.testing.BatchIteratorTester) Test(org.junit.Test)

Example 23 with BatchIteratorTester

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

the class AsyncCompositeBatchIteratorTest method testCompositeBatchIterator.

@Test
public void testCompositeBatchIterator() throws Exception {
    Supplier<BatchIterator> batchSimulatingItSupplier = () -> new CloseAssertingBatchIterator(new BatchSimulatingIterator(TestingBatchIterators.range(5, 10), 2, 2, null));
    ExecutorService executorService = Executors.newFixedThreadPool(3);
    try {
        BatchIteratorTester tester = new BatchIteratorTester(() -> new AsyncCompositeBatchIterator(executorService, TestingBatchIterators.range(0, 5), batchSimulatingItSupplier.get()));
        tester.verifyResultAndEdgeCaseBehaviour(expectedResult);
    } finally {
        executorService.shutdown();
        executorService.awaitTermination(10, TimeUnit.SECONDS);
    }
}
Also used : BatchSimulatingIterator(io.crate.testing.BatchSimulatingIterator) ExecutorService(java.util.concurrent.ExecutorService) BatchIteratorTester(io.crate.testing.BatchIteratorTester) Test(org.junit.Test)

Example 24 with BatchIteratorTester

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

the class LimitingBatchIteratorTest method testLimitingBatchIterator.

@Test
public void testLimitingBatchIterator() throws Exception {
    BatchIteratorTester tester = new BatchIteratorTester(() -> LimitingBatchIterator.newInstance(TestingBatchIterators.range(0, 10), limit));
    tester.verifyResultAndEdgeCaseBehaviour(expectedResult);
}
Also used : BatchIteratorTester(io.crate.testing.BatchIteratorTester) Test(org.junit.Test)

Example 25 with BatchIteratorTester

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

the class IndexWriterCountBatchIteratorTest method testIndexWriterIterator.

@Test
public void testIndexWriterIterator() throws Exception {
    execute("create table bulk_import (id int primary key) with (number_of_replicas=0)");
    ensureGreen();
    Supplier<BatchIterator> sourceSupplier = () -> RowsBatchIterator.newInstance(RowGenerator.fromSingleColValues(() -> IntStream.range(0, 10).mapToObj(i -> new BytesRef("{\"id\": " + i + "}")).iterator()), 1);
    Supplier<String> indexNameResolver = IndexNameResolver.forTable(new TableIdent(null, "bulk_import"));
    Input<?> sourceInput = new InputCollectExpression(0);
    List<CollectExpression<Row, ?>> collectExpressions = Collections.singletonList((InputCollectExpression) sourceInput);
    RowShardResolver rowShardResolver = getRowShardResolver();
    BulkShardProcessor bulkShardProcessor = getBulkShardProcessor();
    Supplier<ShardUpsertRequest.Item> updateItemSupplier = () -> new ShardUpsertRequest.Item(rowShardResolver.id(), null, new Object[] { sourceInput.value() }, null);
    List<Object[]> expectedResult = Collections.singletonList(new Object[] { 10L });
    BatchIteratorTester tester = new BatchIteratorTester(() -> IndexWriterCountBatchIterator.newIndexInstance(sourceSupplier.get(), indexNameResolver, collectExpressions, rowShardResolver, bulkShardProcessor, updateItemSupplier));
    tester.verifyResultAndEdgeCaseBehaviour(expectedResult);
}
Also used : CrateSettings(io.crate.metadata.settings.CrateSettings) TransportBulkCreateIndicesAction(org.elasticsearch.action.admin.indices.create.TransportBulkCreateIndicesAction) IntStream(java.util.stream.IntStream) Input(io.crate.data.Input) Arrays(java.util.Arrays) BulkShardProcessor(org.elasticsearch.action.bulk.BulkShardProcessor) InputColumn(io.crate.analyze.symbol.InputColumn) BatchIterator(io.crate.data.BatchIterator) BatchIteratorTester(io.crate.testing.BatchIteratorTester) Supplier(java.util.function.Supplier) SQLTransportIntegrationTest(io.crate.integrationtests.SQLTransportIntegrationTest) CollectExpression(io.crate.operation.collect.CollectExpression) Settings(org.elasticsearch.common.settings.Settings) Symbol(io.crate.analyze.symbol.Symbol) ClusterService(org.elasticsearch.cluster.ClusterService) io.crate.metadata(io.crate.metadata) DocSysColumns(io.crate.metadata.doc.DocSysColumns) RowsBatchIterator(io.crate.data.RowsBatchIterator) RowShardResolver(io.crate.operation.collect.RowShardResolver) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test) UUID(java.util.UUID) RowGenerator(io.crate.testing.RowGenerator) ShardUpsertRequest(io.crate.executor.transport.ShardUpsertRequest) TransportShardUpsertAction(io.crate.executor.transport.TransportShardUpsertAction) List(java.util.List) Row(io.crate.data.Row) DataTypes(io.crate.types.DataTypes) BulkRetryCoordinatorPool(org.elasticsearch.action.bulk.BulkRetryCoordinatorPool) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) InputCollectExpression(io.crate.operation.collect.InputCollectExpression) Collections(java.util.Collections) BatchIterator(io.crate.data.BatchIterator) RowsBatchIterator(io.crate.data.RowsBatchIterator) CollectExpression(io.crate.operation.collect.CollectExpression) InputCollectExpression(io.crate.operation.collect.InputCollectExpression) BulkShardProcessor(org.elasticsearch.action.bulk.BulkShardProcessor) InputCollectExpression(io.crate.operation.collect.InputCollectExpression) BatchIteratorTester(io.crate.testing.BatchIteratorTester) BytesRef(org.apache.lucene.util.BytesRef) RowShardResolver(io.crate.operation.collect.RowShardResolver) SQLTransportIntegrationTest(io.crate.integrationtests.SQLTransportIntegrationTest) Test(org.junit.Test)

Aggregations

BatchIteratorTester (io.crate.testing.BatchIteratorTester)27 Test (org.junit.Test)26 BatchSimulatingIterator (io.crate.testing.BatchSimulatingIterator)9 NestedLoopBatchIterator (io.crate.data.join.NestedLoopBatchIterator)6 CrateUnitTest (io.crate.test.integration.CrateUnitTest)4 BytesRef (org.apache.lucene.util.BytesRef)3 Symbol (io.crate.analyze.symbol.Symbol)2 BatchIterator (io.crate.data.BatchIterator)2 Row (io.crate.data.Row)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 IntStream (java.util.stream.IntStream)2 OrderBy (io.crate.analyze.OrderBy)1 InputColumn (io.crate.analyze.symbol.InputColumn)1 RamAccountingContext (io.crate.breaker.RamAccountingContext)1 Input (io.crate.data.Input)1 RowsBatchIterator (io.crate.data.RowsBatchIterator)1 ShardUpsertRequest (io.crate.executor.transport.ShardUpsertRequest)1 TransportShardUpsertAction (io.crate.executor.transport.TransportShardUpsertAction)1 SQLTransportIntegrationTest (io.crate.integrationtests.SQLTransportIntegrationTest)1