Search in sources :

Example 1 with WritableByteChannelFactory

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());
}
Also used : Path(java.nio.file.Path) WritableByteChannelFactory(org.apache.beam.sdk.io.FileBasedSink.WritableByteChannelFactory) ArrayList(java.util.ArrayList) DisplayData(org.apache.beam.sdk.transforms.display.DisplayData) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Aggregations

Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 WritableByteChannelFactory (org.apache.beam.sdk.io.FileBasedSink.WritableByteChannelFactory)1 DisplayData (org.apache.beam.sdk.transforms.display.DisplayData)1 Test (org.junit.Test)1 Category (org.junit.experimental.categories.Category)1