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/04/07 19:14:21 UTC

[1/2] incubator-beam git commit: Improve TestPipeline AppName detection

Repository: incubator-beam
Updated Branches:
  refs/heads/master d2b46936f -> 7f0a2f78a


Improve TestPipeline AppName detection

After encountering the TestPipeline portion of the stack, try to find
a method annotated with the org.junit.Test annotation. If such a method
is found, return it as the StackTraceElement of the calling class.

This improves TestPipeline name detection for RunnableOnService tests to
avoid duplication


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

Branch: refs/heads/master
Commit: 32863bd7a99ffe2ed050a1fcb20e493c2d639031
Parents: d2b4693
Author: Thomas Groh <tg...@google.com>
Authored: Tue Apr 5 18:09:29 2016 -0700
Committer: Luke Cwik <lc...@google.com>
Committed: Thu Apr 7 09:58:48 2016 -0700

----------------------------------------------------------------------
 .../dataflow/sdk/testing/TestPipeline.java      | 22 ++++++++++++--
 .../dataflow/sdk/testing/TestPipelineTest.java  | 30 ++++++++++++++++++++
 2 files changed, 50 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/32863bd7/sdks/java/core/src/main/java/com/google/cloud/dataflow/sdk/testing/TestPipeline.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/main/java/com/google/cloud/dataflow/sdk/testing/TestPipeline.java b/sdks/java/core/src/main/java/com/google/cloud/dataflow/sdk/testing/TestPipeline.java
index a942868..e97e90f 100644
--- a/sdks/java/core/src/main/java/com/google/cloud/dataflow/sdk/testing/TestPipeline.java
+++ b/sdks/java/core/src/main/java/com/google/cloud/dataflow/sdk/testing/TestPipeline.java
@@ -33,6 +33,7 @@ import com.google.common.collect.Iterators;
 import com.fasterxml.jackson.databind.ObjectMapper;
 
 import java.io.IOException;
+import java.lang.reflect.Method;
 import java.util.Iterator;
 
 import javax.annotation.Nullable;
@@ -183,12 +184,29 @@ public class TestPipeline extends Pipeline {
       }
     }
     // Then find the first instance after that is not the TestPipeline
+    Optional<StackTraceElement> firstInstanceAfterTestPipeline = Optional.absent();
     while (elements.hasNext()) {
       StackTraceElement next = elements.next();
       if (!TestPipeline.class.getName().equals(next.getClassName())) {
-        return Optional.of(next);
+        if (!firstInstanceAfterTestPipeline.isPresent()) {
+          firstInstanceAfterTestPipeline = Optional.of(next);
+        }
+        try {
+          Class<?> nextClass = Class.forName(next.getClassName());
+          for (Method method : nextClass.getMethods()) {
+            if (method.getName().equals(next.getMethodName())) {
+              if (method.isAnnotationPresent(org.junit.Test.class)) {
+                return Optional.of(next);
+              } else if (method.isAnnotationPresent(org.junit.Before.class)) {
+                break;
+              }
+            }
+          }
+        } catch (Throwable t) {
+          break;
+        }
       }
     }
-    return Optional.absent();
+    return firstInstanceAfterTestPipeline;
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/32863bd7/sdks/java/core/src/test/java/com/google/cloud/dataflow/sdk/testing/TestPipelineTest.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/test/java/com/google/cloud/dataflow/sdk/testing/TestPipelineTest.java b/sdks/java/core/src/test/java/com/google/cloud/dataflow/sdk/testing/TestPipelineTest.java
index b4522c3..6f119da 100644
--- a/sdks/java/core/src/test/java/com/google/cloud/dataflow/sdk/testing/TestPipelineTest.java
+++ b/sdks/java/core/src/test/java/com/google/cloud/dataflow/sdk/testing/TestPipelineTest.java
@@ -91,4 +91,34 @@ public class TestPipelineTest {
   public void testToString() {
     assertEquals("TestPipeline#TestPipelineTest-testToString", TestPipeline.create().toString());
   }
+
+  @Test
+  public void testToStringNestedMethod() {
+    TestPipeline p = nestedMethod();
+
+    assertEquals("TestPipeline#TestPipelineTest-testToStringNestedMethod", p.toString());
+    assertEquals(
+        "TestPipelineTest-testToStringNestedMethod",
+        p.getOptions().as(ApplicationNameOptions.class).getAppName());
+  }
+
+  private TestPipeline nestedMethod() {
+    return TestPipeline.create();
+  }
+
+  @Test
+  public void testToStringNestedClassMethod() {
+    TestPipeline p = new NestedTester().p();
+
+    assertEquals("TestPipeline#TestPipelineTest-testToStringNestedClassMethod", p.toString());
+    assertEquals(
+        "TestPipelineTest-testToStringNestedClassMethod",
+        p.getOptions().as(ApplicationNameOptions.class).getAppName());
+  }
+
+  private static class NestedTester {
+    public TestPipeline p() {
+      return TestPipeline.create();
+    }
+  }
 }


[2/2] incubator-beam git commit: This closes #134

Posted by lc...@apache.org.
This closes #134


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

Branch: refs/heads/master
Commit: 7f0a2f78a90909e70b51dd59fa08159b9de951f2
Parents: d2b4693 32863bd
Author: Luke Cwik <lc...@google.com>
Authored: Thu Apr 7 09:59:46 2016 -0700
Committer: Luke Cwik <lc...@google.com>
Committed: Thu Apr 7 09:59:46 2016 -0700

----------------------------------------------------------------------
 .../dataflow/sdk/testing/TestPipeline.java      | 22 ++++++++++++--
 .../dataflow/sdk/testing/TestPipelineTest.java  | 30 ++++++++++++++++++++
 2 files changed, 50 insertions(+), 2 deletions(-)
----------------------------------------------------------------------