use of org.apache.beam.sdk.io.elasticsearch.ElasticsearchIO.DocumentCoder in project beam by apache.
the class ElasticsearchIOTestCommon method testDocumentCoder.
void testDocumentCoder() throws Exception {
List<String> data = ElasticsearchIOTestUtils.createDocuments(numDocs, InjectionMode.DO_NOT_INJECT_INVALID_DOCS);
int randomNum = ThreadLocalRandom.current().nextInt(0, data.size());
Instant now = Instant.now();
Write write = ElasticsearchIO.write().withConnectionConfiguration(connectionConfiguration);
Document expected = serializeDocs(write, data).get(randomNum).withTimestamp(now).withHasError(randomNum % 2 == 0);
PipedInputStream in = new PipedInputStream();
PipedOutputStream out = new PipedOutputStream(in);
DocumentCoder coder = DocumentCoder.of();
coder.encode(expected, out);
Document actual = coder.decode(in);
assertEquals(expected, actual);
}
Aggregations