use of org.elasticsearch.action.bulk.BulkShardProcessor in project crate by crate.
the class IndexWriterCountBatchIteratorTest method getBulkShardProcessor.
private BulkShardProcessor<ShardUpsertRequest> getBulkShardProcessor() {
UUID jobId = UUID.randomUUID();
ShardUpsertRequest.Builder builder = new ShardUpsertRequest.Builder(CrateSettings.BULK_REQUEST_TIMEOUT.extractTimeValue(Settings.EMPTY), false, true, null, new Reference[] { new Reference(new ReferenceIdent(bulkImportIdent, DocSysColumns.RAW), RowGranularity.DOC, DataTypes.STRING) }, jobId, false);
IndexNameExpressionResolver indexNameExpressionResolver = new IndexNameExpressionResolver(Settings.EMPTY);
return new BulkShardProcessor<>(internalCluster().getInstance(ClusterService.class), internalCluster().getInstance(TransportBulkCreateIndicesAction.class), indexNameExpressionResolver, Settings.EMPTY, internalCluster().getInstance(BulkRetryCoordinatorPool.class), false, 2, builder, internalCluster().getInstance(TransportShardUpsertAction.class)::execute, jobId);
}
use of org.elasticsearch.action.bulk.BulkShardProcessor 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