Search in sources :

Example 1 with DocumentCoder

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);
}
Also used : Write(org.apache.beam.sdk.io.elasticsearch.ElasticsearchIO.Write) Instant(org.joda.time.Instant) DocumentCoder(org.apache.beam.sdk.io.elasticsearch.ElasticsearchIO.DocumentCoder) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) Document(org.apache.beam.sdk.io.elasticsearch.ElasticsearchIO.Document)

Aggregations

PipedInputStream (java.io.PipedInputStream)1 PipedOutputStream (java.io.PipedOutputStream)1 Document (org.apache.beam.sdk.io.elasticsearch.ElasticsearchIO.Document)1 DocumentCoder (org.apache.beam.sdk.io.elasticsearch.ElasticsearchIO.DocumentCoder)1 Write (org.apache.beam.sdk.io.elasticsearch.ElasticsearchIO.Write)1 Instant (org.joda.time.Instant)1