}
private void ingestAndVerifyAvro(Schema schema, GenericData.Record... records) throws IOException {
deleteAllDocuments();
GenericDatumWriter datum = new GenericDatumWriter(schema);
DataFileWriter writer = new DataFileWriter(datum);
writer.setMeta("Meta-Key0", "Meta-Value0");
writer.setMeta("Meta-Key1", "Meta-Value1");
ByteArrayOutputStream bout = new ByteArrayOutputStream();
writer.create(schema, bout);
for (GenericData.Record record : records) {
writer.append(record);
}
writer.flush();
writer.close();
DataFileReader<GenericData.Record> reader = new DataFileReader(new ReadAvroContainerBuilder.ForwardOnlySeekableInputStream(new ByteArrayInputStream(bout.toByteArray())), new GenericDatumReader());
Schema schema2 = reader.getSchema();
assertEquals(schema, schema2);
for (GenericData.Record record : records) {
assertTrue(reader.hasNext());
GenericData.Record record2 = reader.next();
assertEquals(record, record2);
}
assertFalse(reader.hasNext());
reader.close();
Record event = new Record();
event.getFields().put(Fields.ATTACHMENT_BODY, new ByteArrayInputStream(bout.toByteArray()));
morphline = createMorphline("test-morphlines/readAvroContainer");
deleteAllDocuments();
assertTrue(load(event));
assertEquals(records.length, queryResultSetSize("*:*"));
GenericDatumWriter datumWriter = new GenericDatumWriter(schema);
bout = new ByteArrayOutputStream();
Encoder encoder = EncoderFactory.get().binaryEncoder(bout, null);
for (GenericData.Record record : records) {
datumWriter.write(record, encoder);
}
encoder.flush();
Decoder decoder = DecoderFactory.get().binaryDecoder(new ByteArrayInputStream(bout.toByteArray()), null);
DatumReader<GenericData.Record> datumReader = new GenericDatumReader<GenericData.Record>(schema);