beam-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tg...@apache.org
Subject [2/3] incubator-beam git commit: Reduce Verbosity of testFlattenInputMultipleCopies
Date Fri, 11 Nov 2016 18:59:39 GMT
Reduce Verbosity of testFlattenInputMultipleCopies

It should be easy to determine what has happened in the failure -
reducing the number of outputs, and the size of the outputs, should ease
recognition of the failure that has occurred.


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

Branch: refs/heads/master
Commit: 209479253d7a2709e7536f384b178dcc58773dae
Parents: 4b97cdb
Author: Thomas Groh <tgroh@google.com>
Authored: Thu Nov 10 13:12:11 2016 -0800
Committer: Thomas Groh <tgroh@google.com>
Committed: Fri Nov 11 10:58:52 2016 -0800

----------------------------------------------------------------------
 .../apache/beam/sdk/transforms/FlattenTest.java | 38 ++++++++++++++------
 1 file changed, 27 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/20947925/sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/FlattenTest.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/FlattenTest.java
b/sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/FlattenTest.java
index 3d7ea1e..d4686a4 100644
--- a/sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/FlattenTest.java
+++ b/sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/FlattenTest.java
@@ -24,7 +24,6 @@ import static org.apache.beam.sdk.TestUtils.NO_LINES;
 import static org.apache.beam.sdk.TestUtils.NO_LINES_ARRAY;
 
 import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -39,6 +38,7 @@ import org.apache.beam.sdk.coders.ListCoder;
 import org.apache.beam.sdk.coders.SetCoder;
 import org.apache.beam.sdk.coders.StringUtf8Coder;
 import org.apache.beam.sdk.coders.VoidCoder;
+import org.apache.beam.sdk.io.CountingInput;
 import org.apache.beam.sdk.testing.NeedsRunner;
 import org.apache.beam.sdk.testing.PAssert;
 import org.apache.beam.sdk.testing.RunnableOnService;
@@ -67,6 +67,7 @@ public class FlattenTest implements Serializable {
   @Rule
   public transient ExpectedException thrown = ExpectedException.none();
 
+
   private static class ClassWithoutCoder { }
 
 
@@ -121,16 +122,31 @@ public class FlattenTest implements Serializable {
   public void testFlattenInputMultipleCopies() {
     Pipeline p = TestPipeline.create();
 
-    PCollection<String> lines = p.apply("mkLines", Create.of(LINES));
-    PCollection<String> lines2 = p.apply("mkOtherLines", Create.of(LINES2));
-
-    PCollection<String> flattened = PCollectionList.of(lines)
-        .and(lines2)
-        .and(lines)
-        .and(lines)
-        .apply(Flatten.<String>pCollections());
-
-    PAssert.that(flattened).containsInAnyOrder(Iterables.concat(LINES, LINES, LINES, LINES2));
+    int count = 5;
+    PCollection<Long> longs = p.apply("mkLines", CountingInput.upTo(count));
+    PCollection<Long> biggerLongs =
+        p.apply("mkOtherLines", CountingInput.upTo(count))
+            .apply(
+                MapElements.via(
+                    new SimpleFunction<Long, Long>() {
+                      @Override
+                      public Long apply(Long input) {
+                        return input + 10L;
+                      }
+                    }));
+
+    PCollection<Long> flattened =
+        PCollectionList.of(longs).and(longs).and(biggerLongs).apply(Flatten.<Long>pCollections());
+
+    List<Long> expectedLongs = new ArrayList<>();
+    for (int i = 0; i < count; i++) {
+      // The duplicated input
+      expectedLongs.add((long) i);
+      expectedLongs.add((long) i);
+      // The bigger longs
+      expectedLongs.add(i + 10L);
+    }
+    PAssert.that(flattened).containsInAnyOrder(expectedLongs);
 
     p.run();
   }


Mime
View raw message