/** * Build a {@link org.apache.gobblin.writer.DataWriter}. * * @return the built {@link org.apache.gobblin.writer.DataWriter} * @throws java.io.IOException if there is anything wrong building the writer */ @Override public DataWriter<Object> build() throws IOException { return new MetadataWriterWrapper<byte[]>(new SimpleDataWriter(this, this.destination.getProperties()), byte[].class, this.branches, this.branch, this.destination.getProperties()); }
@BeforeMethod public void setUp() { state = new WorkUnitState(); dummyWriter = new DummyWriter(); writer = new MetadataWriterWrapper<>(dummyWriter, byte[].class, 1, 0, state.getJobState()); }
@Test public void testAppendsMetadataWithNormalRecord() throws IOException { state = new WorkUnitState(); dummyWriter = new MetadataDummyWriter(); writer = new MetadataWriterWrapper<>(dummyWriter, byte[].class, 1, 0, state.getJobState()); byte[] recordBytes = new byte[]{'a', 'b', 'c', 'd'}; writer.write(recordBytes); writer.commit(); String writerMetadata = state.getProp(ConfigurationKeys.WRITER_METADATA_KEY); Assert.assertNotNull(writerMetadata, "Expected there to be metadata"); Assert.assertNotEquals(writerMetadata.indexOf("\"default-encoding\""), -1, "Expected to find default metadata in metadata"); }
@Test public void testAppendsDefaultMetadata() throws IOException { state = new WorkUnitState(); dummyWriter = new MetadataDummyWriter(); writer = new MetadataWriterWrapper<>(dummyWriter, byte[].class, 1, 0, state.getJobState()); byte[] recordBytes = new byte[]{'a', 'b', 'c', 'd'}; Metadata md = new Metadata(); md.getGlobalMetadata().addTransferEncoding("first"); writer.write(new RecordWithMetadata<>(recordBytes, md)); writer.commit(); String writerMetadata = state.getProp(ConfigurationKeys.WRITER_METADATA_KEY); Assert.assertNotNull(writerMetadata, "Expected there to be metadata"); int firstOccurrence = writerMetadata.indexOf("\"first\""); Assert.assertNotEquals(firstOccurrence, -1, "Expected to find record-level encoding in metadata"); int secondOccurrence = writerMetadata.indexOf("\"default-encoding\""); Assert.assertNotEquals(secondOccurrence, -1, "Expected to find default metadata in metadata"); Assert.assertTrue(firstOccurrence < secondOccurrence, "Expected recordBytes encoding to be present before default encoding"); }
/** * Build a {@link org.apache.gobblin.writer.DataWriter}. * * @return the built {@link org.apache.gobblin.writer.DataWriter} * @throws java.io.IOException if there is anything wrong building the writer */ @Override public DataWriter<Object> build() throws IOException { return new MetadataWriterWrapper<byte[]>(new SimpleDataWriter(this, this.destination.getProperties()), byte[].class, this.branches, this.branch, this.destination.getProperties()); }