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);
}
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);
}
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);
}
}
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);
}
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);
}
Aggregations