beam-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From k...@apache.org
Subject [2/3] incubator-beam git commit: Empty TestPipeline need not be run
Date Sat, 17 Dec 2016 22:24:03 GMT
Empty TestPipeline need not be run


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

Branch: refs/heads/master
Commit: 0d54a4c6708516170cb045b5e0d1d33443973c6e
Parents: 443b25a
Author: Kenneth Knowles <klk@google.com>
Authored: Sat Dec 17 13:57:07 2016 -0800
Committer: Kenneth Knowles <klk@google.com>
Committed: Sat Dec 17 14:12:23 2016 -0800

----------------------------------------------------------------------
 .../apache/beam/sdk/testing/TestPipeline.java   | 20 +++++++++++++++++++-
 .../beam/sdk/testing/TestPipelineTest.java      |  3 +++
 2 files changed, 22 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/0d54a4c6/sdks/java/core/src/main/java/org/apache/beam/sdk/testing/TestPipeline.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/testing/TestPipeline.java b/sdks/java/core/src/main/java/org/apache/beam/sdk/testing/TestPipeline.java
index 49ac3af..b707a81 100644
--- a/sdks/java/core/src/main/java/org/apache/beam/sdk/testing/TestPipeline.java
+++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/testing/TestPipeline.java
@@ -169,7 +169,12 @@ public class TestPipeline extends Pipeline implements TestRule {
           throw new AbandonedNodeException("The pipeline contains abandoned PTransform(s).");
         }
       } else if (runVisitedNodes == null && !enableAutoRunIfMissing) {
-        throw new PipelineRunMissingException("The pipeline has not been run.");
+        IsEmptyVisitor isEmptyVisitor = new IsEmptyVisitor();
+        pipeline.traverseTopologically(isEmptyVisitor);
+
+        if (!isEmptyVisitor.isEmpty()) {
+          throw new PipelineRunMissingException("The pipeline has not been run.");
+        }
       }
     }
 
@@ -389,4 +394,17 @@ public class TestPipeline extends Pipeline implements TestRule {
     }
     return firstInstanceAfterTestPipeline;
   }
+
+  private static class IsEmptyVisitor extends PipelineVisitor.Defaults {
+    private boolean empty = true;
+
+    public boolean isEmpty() {
+      return empty;
+    }
+
+    @Override
+    public void visitPrimitiveTransform(TransformHierarchy.Node node) {
+      empty = false;
+    }
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/0d54a4c6/sdks/java/core/src/test/java/org/apache/beam/sdk/testing/TestPipelineTest.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/test/java/org/apache/beam/sdk/testing/TestPipelineTest.java
b/sdks/java/core/src/test/java/org/apache/beam/sdk/testing/TestPipelineTest.java
index d1797e7..f484566 100644
--- a/sdks/java/core/src/test/java/org/apache/beam/sdk/testing/TestPipelineTest.java
+++ b/sdks/java/core/src/test/java/org/apache/beam/sdk/testing/TestPipelineTest.java
@@ -74,6 +74,9 @@ public class TestPipelineTest implements Serializable {
   @Rule public transient RuleChain ruleOrder = RuleChain.outerRule(exception).around(pipeline);
 
   @Test
+  public void testNoTestPipelineUsed() { }
+
+  @Test
   public void testCreationUsingDefaults() {
     assertNotNull(TestPipeline.create());
   }


Mime
View raw message