use of io.crate.operation.collect.RowShardResolver 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