From 5cc0441d1e2e57be6a2b7c80d4c477657f004104 Mon Sep 17 00:00:00 2001 From: Jeffrey Scott Keone Payne Date: Fri, 14 Oct 2016 13:33:16 -0700 Subject: [PATCH] [BEAM-697] TextIO.Write.Bound.withHeader() and withFooter() now use the current value of validate for the returned Bound instance, added supporting tests --- .../java/org/apache/beam/sdk/io/TextIO.java | 4 +-- .../org/apache/beam/sdk/io/TextIOTest.java | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/io/TextIO.java b/sdks/java/core/src/main/java/org/apache/beam/sdk/io/TextIO.java index 3ae2a0c742d9..fbff3ba86091 100644 --- a/sdks/java/core/src/main/java/org/apache/beam/sdk/io/TextIO.java +++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/io/TextIO.java @@ -667,7 +667,7 @@ public Bound withoutValidation() { */ public Bound withHeader(@Nullable String header) { return new Bound<>(name, filenamePrefix, filenameSuffix, header, footer, coder, numShards, - shardTemplate, false, writableByteChannelFactory); + shardTemplate, validate, writableByteChannelFactory); } /** @@ -682,7 +682,7 @@ public Bound withHeader(@Nullable String header) { */ public Bound withFooter(@Nullable String footer) { return new Bound<>(name, filenamePrefix, filenameSuffix, header, footer, coder, numShards, - shardTemplate, false, writableByteChannelFactory); + shardTemplate, validate, writableByteChannelFactory); } /** diff --git a/sdks/java/core/src/test/java/org/apache/beam/sdk/io/TextIOTest.java b/sdks/java/core/src/test/java/org/apache/beam/sdk/io/TextIOTest.java index 2131ece955bb..dc71693acbe5 100644 --- a/sdks/java/core/src/test/java/org/apache/beam/sdk/io/TextIOTest.java +++ b/sdks/java/core/src/test/java/org/apache/beam/sdk/io/TextIOTest.java @@ -35,6 +35,7 @@ import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.startsWith; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -556,6 +557,30 @@ public void testWriteDisplayData() { assertThat(displayData, hasDisplayItem("writableByteChannelFactory", "UNCOMPRESSED")); } + @Test + public void testWriteDisplayDataValidateThenHeader() { + TextIO.Write.Bound write = TextIO.Write + .to("foo") + .withHeader("myHeader"); + + DisplayData displayData = DisplayData.from(write); + + assertThat(displayData, hasDisplayItem("fileHeader", "myHeader")); + assertThat(displayData, not(hasDisplayItem("validation", false))); + } + + @Test + public void testWriteDisplayDataValidateThenFooter() { + TextIO.Write.Bound write = TextIO.Write + .to("foo") + .withFooter("myFooter"); + + DisplayData displayData = DisplayData.from(write); + + assertThat(displayData, hasDisplayItem("fileFooter", "myFooter")); + assertThat(displayData, not(hasDisplayItem("validation", false))); + } + @Test @Category(RunnableOnService.class) @Ignore("[BEAM-436] DirectRunner RunnableOnService tempLocation configuration insufficient")