use of org.apache.beam.sdk.io.elasticsearch.ElasticsearchIO.ConnectionConfiguration in project beam by apache.
the class ElasticsearchIOTestCommon method testMaxParallelRequestsPerWindow.
void testMaxParallelRequestsPerWindow() throws Exception {
List<Document> data = ElasticsearchIOTestUtils.createDocuments(numDocs, ElasticsearchIOTestUtils.InjectionMode.DO_NOT_INJECT_INVALID_DOCS).stream().map(doc -> Document.create().withInputDoc(doc).withTimestamp(Instant.now())).collect(Collectors.toList());
Write write = ElasticsearchIO.write().withConnectionConfiguration(connectionConfiguration).withMaxParallelRequestsPerWindow(1);
PCollection<KV<Integer, Iterable<Document>>> batches = pipeline.apply(Create.of(data)).apply(StatefulBatching.fromSpec(write.getBulkIO()));
PCollection<Integer> keyValues = batches.apply(MapElements.into(integers()).via((SerializableFunction<KV<Integer, Iterable<Document>>, Integer>) KV::getKey));
// Number of unique keys produced should be number of maxParallelRequestsPerWindow * numWindows
// There is only 1 request (key) per window, and 1 (global) window ie. one key total where
// key value is 0
PAssert.that(keyValues).containsInAnyOrder(0);
PAssert.that(batches).satisfies(new AssertThatHasExpectedContents(0, data));
pipeline.run();
}
Aggregations