You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by lc...@apache.org on 2016/08/11 21:28:55 UTC

[2/5] incubator-beam git commit: More unit test and code style fix

More unit test and code style fix


Project: http://git-wip-us.apache.org/repos/asf/incubator-beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-beam/commit/a98bbb26
Tree: http://git-wip-us.apache.org/repos/asf/incubator-beam/tree/a98bbb26
Diff: http://git-wip-us.apache.org/repos/asf/incubator-beam/diff/a98bbb26

Branch: refs/heads/master
Commit: a98bbb26c12f96446b314f8229d9218236f0ce06
Parents: 0b5da70
Author: Mark Liu <ma...@markliu-macbookpro.roam.corp.google.com>
Authored: Thu Aug 11 11:26:28 2016 -0700
Committer: Luke Cwik <lc...@google.com>
Committed: Thu Aug 11 13:56:58 2016 -0700

----------------------------------------------------------------------
 .../beam/sdk/testing/FileChecksumMatcher.java   | 17 +++++-----
 .../sdk/testing/FileChecksumMatcherTest.java    | 34 ++++++++++++++++++--
 2 files changed, 39 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/a98bbb26/sdks/java/core/src/main/java/org/apache/beam/sdk/testing/FileChecksumMatcher.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/testing/FileChecksumMatcher.java b/sdks/java/core/src/main/java/org/apache/beam/sdk/testing/FileChecksumMatcher.java
index f4bd062..303efcb 100644
--- a/sdks/java/core/src/main/java/org/apache/beam/sdk/testing/FileChecksumMatcher.java
+++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/testing/FileChecksumMatcher.java
@@ -84,13 +84,12 @@ public class FileChecksumMatcher extends TypeSafeMatcher<PipelineResult>
       return actualChecksum.equals(expectedChecksum);
     } catch (IOException e) {
       throw new RuntimeException(
-              String.format("Failed to read from path: %s", filePath));
+          String.format("Failed to read from path: %s", filePath));
     }
   }
 
   private List<String> readLines(String path) throws IOException {
     List<String> readData = new ArrayList<>();
-
     IOChannelFactory factory = IOChannelUtils.getFactory(path);
 
     // Match inputPath which may contains glob
@@ -100,7 +99,7 @@ public class FileChecksumMatcher extends TypeSafeMatcher<PipelineResult>
     int i = 0;
     for (String file : files) {
       try (Reader reader =
-               Channels.newReader(factory.open(file), StandardCharsets.UTF_8.name())) {
+          Channels.newReader(factory.open(file), StandardCharsets.UTF_8.name())) {
         List<String> lines = CharStreams.readLines(reader);
         readData.addAll(lines);
         LOG.info(
@@ -122,16 +121,16 @@ public class FileChecksumMatcher extends TypeSafeMatcher<PipelineResult>
   @Override
   public void describeTo(Description description) {
     description
-            .appendText("Expected checksum is (")
-            .appendText(expectedChecksum)
-            .appendText(")");
+        .appendText("Expected checksum is (")
+        .appendText(expectedChecksum)
+        .appendText(")");
   }
 
   @Override
   public void describeMismatchSafely(PipelineResult pResult, Description description) {
     description
-            .appendText("was (")
-            .appendText(actualChecksum)
-            .appendText(")");
+        .appendText("was (")
+        .appendText(actualChecksum)
+        .appendText(")");
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/a98bbb26/sdks/java/core/src/test/java/org/apache/beam/sdk/testing/FileChecksumMatcherTest.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/test/java/org/apache/beam/sdk/testing/FileChecksumMatcherTest.java b/sdks/java/core/src/test/java/org/apache/beam/sdk/testing/FileChecksumMatcherTest.java
index 00417c7..eebb73e 100644
--- a/sdks/java/core/src/test/java/org/apache/beam/sdk/testing/FileChecksumMatcherTest.java
+++ b/sdks/java/core/src/test/java/org/apache/beam/sdk/testing/FileChecksumMatcherTest.java
@@ -49,25 +49,39 @@ public class FileChecksumMatcherTest {
   private PipelineResult pResult = Mockito.mock(PipelineResult.class);
 
   @Test
-  public void testPreconditionValidChecksumString() throws IOException{
+  public void testPreconditionChecksumIsNull() throws IOException {
     String tmpPath = tmpFolder.newFile().getPath();
 
     thrown.expect(IllegalArgumentException.class);
     thrown.expectMessage(containsString("Expected valid checksum, but received"));
     new FileChecksumMatcher(null, tmpPath);
+  }
+
+  @Test
+  public void testPreconditionChecksumIsEmpty() throws IOException {
+    String tmpPath = tmpFolder.newFile().getPath();
+
+    thrown.expect(IllegalArgumentException.class);
+    thrown.expectMessage(containsString("Expected valid checksum, but received"));
     new FileChecksumMatcher("", tmpPath);
   }
 
   @Test
-  public void testPreconditionValidFilePath() throws IOException {
+  public void testPreconditionFilePathIsNull() {
     thrown.expect(IllegalArgumentException.class);
     thrown.expectMessage(containsString("Expected valid file path, but received"));
     new FileChecksumMatcher("checksumString", null);
+  }
+
+  @Test
+  public void testPreconditionFilePathIsEmpty() {
+    thrown.expect(IllegalArgumentException.class);
+    thrown.expectMessage(containsString("Expected valid file path, but received"));
     new FileChecksumMatcher("checksumString", "");
   }
 
   @Test
-  public void testChecksumVerify() throws IOException{
+  public void testMatcherVerifySingleFile() throws IOException{
     File tmpFile = tmpFolder.newFile();
     Files.write("Test for file checksum verifier.", tmpFile, StandardCharsets.UTF_8);
     FileChecksumMatcher matcher =
@@ -75,4 +89,18 @@ public class FileChecksumMatcherTest {
 
     assertThat(pResult, matcher);
   }
+
+  @Test
+  public void testMatcherVerifyMultipleFilesInOneDir() throws IOException {
+    File tmpFile1 = tmpFolder.newFile();
+    File tmpFile2 = tmpFolder.newFile();
+    Files.write("To be or not to be, ", tmpFile1, StandardCharsets.UTF_8);
+    Files.write("it is not a question.", tmpFile2, StandardCharsets.UTF_8);
+    FileChecksumMatcher matcher =
+        new FileChecksumMatcher(
+            "90552392c28396935fe4f123bd0b5c2d0f6260c8",
+            tmpFolder.getRoot().getPath() + "/*");
+
+    assertThat(pResult, matcher);
+  }
  }