You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2015/04/02 22:26:53 UTC

incubator-tinkerpop git commit: Graphs can OptOut of base test implementations per TINKERPOP3-596

Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/master 2cee03f1b -> ab5430b67


Graphs can OptOut of base test implementations per TINKERPOP3-596


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

Branch: refs/heads/master
Commit: ab5430b67060a20afd250488283f0a5e3a14d0c7
Parents: 2cee03f
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Apr 2 16:26:06 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Apr 2 16:26:06 2015 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |  1 +
 docs/src/implementations.asciidoc               |  7 ++-
 .../tinkerpop/gremlin/structure/Graph.java      |  4 +-
 .../tinkerpop/gremlin/AbstractGremlinSuite.java | 61 +++++++++++++++++---
 4 files changed, 62 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/ab5430b6/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index b146cdf..eadcaa1 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -26,6 +26,7 @@ TinkerPop 3.0.0.M8 (Release Date: April 6, 2015)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 * Removed Neo4j-Gremlin from this distribution due to GPL licensing. Working with Neo4j team to reintroduce by M9.
+* Improved `OptOut` to allow for exlcusion of a group of tests by specifying a base test class.
 * `GraphComputerTest` is now Java8 specific and much easier to extend with new test cases.
 * Merged the `gremlin-algorithm` module into `gremlin-test`.
 * Removed `LambdaVertexProgram` and `LambdaMapReduce` as it will be one less thing to maintain.

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/ab5430b6/docs/src/implementations.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/implementations.asciidoc b/docs/src/implementations.asciidoc
index 7a3b092..8341247 100644
--- a/docs/src/implementations.asciidoc
+++ b/docs/src/implementations.asciidoc
@@ -306,7 +306,12 @@ There are times when there may be a specific test in the suite that the implemen
 public class HadoopGraph implements Graph {
 ----
 
-The above examples show how to ignore individual tests.  It is also possible to ignore an entire test case (i.e. all the methods within the test) by setting the `method` to "*".  Also note that some of the tests in the Gremlin Test Suite are parameterized tests and require an additional level of specificity to be properly ignored.  To ignore these types of tests, examine the name template of the parameterized tests.  It is defined by a Java annotation that looks like this:
+The above examples show how to ignore individual tests.  It is also possible to:
+
+* Ignore an entire test case (i.e. all the methods within the test) by setting the `method` to "*".
+* Ignore a "base" test class such that test that extend from those classes will all be ignored.  This style of ignoring is useful for Gremlin "process" tests that have bases classes that are extended by various Gremlin flavors (e.g. groovy).
+
+Also note that some of the tests in the Gremlin Test Suite are parameterized tests and require an additional level of specificity to be properly ignored.  To ignore these types of tests, examine the name template of the parameterized tests.  It is defined by a Java annotation that looks like this:
 
 [source, java]
 @Parameterized.Parameters(name = "expect({0})")

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/ab5430b6/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
index 735df05..376ab45 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
@@ -1109,7 +1109,9 @@ public interface Graph extends AutoCloseable {
     @Inherited
     public @interface OptOut {
         /**
-         * The test class to opt out of.
+         * The test class to opt out of. This may be set to a base class of a test as in the case of the Gremlin
+         * process class of tests from which Gremlin flavors extend.  If the actual test class is an inner class
+         * of then use a "$" as a separator between the outer class and inner class.
          */
         public String test();
 

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/ab5430b6/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGremlinSuite.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGremlinSuite.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGremlinSuite.java
index 6f638a5..4ab600f 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGremlinSuite.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGremlinSuite.java
@@ -42,6 +42,7 @@ import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -278,8 +279,21 @@ public abstract class AbstractGremlinSuite extends Suite {
      */
     public static class OptOutTestFilter extends Filter {
 
-        private final List<Description> individualTestsToIgnore;
-        private final List<Graph.OptOut> entireTestsToIgnore;
+        /**
+         * Ignores a specific test in a specific test case.
+         */
+        private final List<Description> individualSpecificTestsToIgnore;
+
+        /**
+         * Defines a group of tests to ignore which is useful with some of the Gremlin process tests which all
+         * have the same name.  It is only possible to ignore tests that extend from certain pre-defined classes.
+         */
+        private final List<Description> testGroupToIgnore;
+
+        /**
+         * Ignores an entire specific test case.
+         */
+        private final List<Graph.OptOut> entireTestCaseToIgnore;
 
         public OptOutTestFilter(final Graph.OptOut[] optOuts) {
             // split the tests to filter into two groups - true represents those that should ignore a whole
@@ -287,25 +301,54 @@ public abstract class AbstractGremlinSuite extends Suite {
                     Collectors.groupingBy(optOut -> optOut.method().equals("*")));
 
             final List<Graph.OptOut> optOutsOfIndividualTests = split.getOrDefault(Boolean.FALSE, Collections.emptyList());
-            individualTestsToIgnore = optOutsOfIndividualTests.stream()
+            individualSpecificTestsToIgnore = optOutsOfIndividualTests.stream()
                     .filter(ignoreTest -> !ignoreTest.method().equals("*"))
+                    .filter(ignoreTest -> {
+                        try {
+                            final Class testClass = Class.forName(ignoreTest.test());
+                            return !Modifier.isAbstract(testClass.getModifiers());
+                        } catch (Exception ex) {
+                            throw new RuntimeException(ex);
+                        }
+                    })
                     .<Pair>map(ignoreTest -> Pair.with(ignoreTest.test(), ignoreTest.specific().isEmpty() ? ignoreTest.method() : String.format("%s[%s]", ignoreTest.method(), ignoreTest.specific())))
                     .<Description>map(p -> Description.createTestDescription(p.getValue0().toString(), p.getValue1().toString()))
                     .collect(Collectors.toList());
 
-            entireTestsToIgnore = split.getOrDefault(Boolean.TRUE, Collections.emptyList());
+            testGroupToIgnore = optOutsOfIndividualTests.stream()
+                    .filter(ignoreTest -> !ignoreTest.method().equals("*"))
+                    .filter(ignoreTest -> {
+                        try {
+                            final Class testClass = Class.forName(ignoreTest.test());
+                            return Modifier.isAbstract(testClass.getModifiers());
+                        } catch (Exception ex) {
+                            throw new RuntimeException(ex);
+                        }
+                    })
+                    .<Pair>map(ignoreTest -> Pair.with(ignoreTest.test(), ignoreTest.specific().isEmpty() ? ignoreTest.method() : String.format("%s[%s]", ignoreTest.method(), ignoreTest.specific())))
+                    .<Description>map(p -> Description.createTestDescription(p.getValue0().toString(), p.getValue1().toString()))
+                    .collect(Collectors.toList());
+
+            entireTestCaseToIgnore = split.getOrDefault(Boolean.TRUE, Collections.emptyList());
         }
 
         @Override
         public boolean shouldRun(final Description description) {
-            // first check if all tests from a class should be ignored
-            if (!entireTestsToIgnore.isEmpty() && entireTestsToIgnore.stream()
-                    .anyMatch(optOut -> optOut.test().equals(description.getClassName()))) {
+            // first check if all tests from a class should be ignored.
+            if (!entireTestCaseToIgnore.isEmpty() && entireTestCaseToIgnore.stream().map(optOut -> {
+                try {
+                    return Class.forName(optOut.test());
+                } catch (Exception ex) {
+                    throw new RuntimeException(ex);
+                }
+            }).anyMatch(claxx -> claxx.isAssignableFrom(description.getTestClass()))) {
                 return false;
             }
 
             if (description.isTest()) {
-                return !individualTestsToIgnore.contains(description);
+                // next check if there is a test group to consider. if not then check for a  specific test to ignore
+                return !(!testGroupToIgnore.isEmpty() && testGroupToIgnore.stream().anyMatch(optOut -> optOut.getTestClass().isAssignableFrom(description.getTestClass()) && description.getMethodName().equals(optOut.getMethodName())))
+                        && !individualSpecificTestsToIgnore.contains(description);
             }
 
             // explicitly check if any children want to run
@@ -320,7 +363,7 @@ public abstract class AbstractGremlinSuite extends Suite {
         @Override
         public String describe() {
             return String.format("Method %s",
-                    String.join(",", individualTestsToIgnore.stream().map(Description::getDisplayName).collect(Collectors.toList())));
+                    String.join(",", individualSpecificTestsToIgnore.stream().map(Description::getDisplayName).collect(Collectors.toList())));
         }
     }
 }