use of org.apache.beam.sdk.io.FileBasedSink.WritableByteChannelFactory in project beam by apache.
the class TextIOTest method testWriteWithWritableByteChannelFactory.
@Test
@Category(NeedsRunner.class)
public void testWriteWithWritableByteChannelFactory() throws Exception {
Coder<String> coder = StringUtf8Coder.of();
String outputName = "file.txt";
Path baseDir = Files.createTempDirectory(tempFolder, "testwrite");
PCollection<String> input = p.apply(Create.of(Arrays.asList(LINES2_ARRAY)).withCoder(coder));
final WritableByteChannelFactory writableByteChannelFactory = new DrunkWritableByteChannelFactory();
TextIO.Write write = TextIO.write().to(baseDir.resolve(outputName).toString()).withoutSharding().withWritableByteChannelFactory(writableByteChannelFactory);
DisplayData displayData = DisplayData.from(write);
assertThat(displayData, hasDisplayItem("writableByteChannelFactory", "DRUNK"));
input.apply(write);
p.run();
final List<String> drunkElems = new ArrayList<>(LINES2_ARRAY.length * 2 + 2);
for (String elem : LINES2_ARRAY) {
drunkElems.add(elem);
drunkElems.add(elem);
}
assertOutputFiles(drunkElems.toArray(new String[0]), null, null, 1, baseDir, outputName + writableByteChannelFactory.getFilenameSuffix(), write.getShardTemplate());
}
Aggregations