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 2018/06/08 11:46:05 UTC

tinkerpop git commit: TINKERPOP-1518 Minor refactoring - extracted requirement check function

Repository: tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-1518 aec170982 -> 221fda584


TINKERPOP-1518 Minor refactoring - extracted requirement check function


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

Branch: refs/heads/TINKERPOP-1518
Commit: 221fda584c6baf7c65eb4e6eebf72bb0ba251de4
Parents: aec1709
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Jun 8 07:45:29 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Jun 8 07:45:29 2018 -0400

----------------------------------------------------------------------
 .../tinkerpop/gremlin/AbstractGremlinTest.java  | 52 ++++++++++----------
 1 file changed, 26 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/221fda58/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGremlinTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGremlinTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGremlinTest.java
index 8f55329..7ca44ba 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGremlinTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGremlinTest.java
@@ -37,6 +37,7 @@ import org.junit.rules.TestName;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -64,8 +65,6 @@ import static org.junit.Assume.assumeThat;
 public abstract class AbstractGremlinTest {
     private static final Logger logger = LoggerFactory.getLogger(AbstractGremlinTest.class);
 
-    protected static final Map<Pair<Class<?>, String>, Boolean> featureCache = new HashMap<>();
-
     protected Graph graph;
     protected GraphTraversalSource g;
     protected Configuration config;
@@ -84,20 +83,10 @@ public abstract class AbstractGremlinTest {
 
         graphProvider = GraphManager.getGraphProvider();
 
+        // pre-check if available from graph provider to avoid graph creation
         final Optional<Graph.Features> staticFeatures = graphProvider.getStaticFeatures();
         if (staticFeatures.isPresent()) {
-            for (FeatureRequirement fr : featureRequirementSet) {
-                try {
-                    assumeThat(String.format("StaticFeatures of the graph do not support all of the features required by this test so it will be ignored: %s.%s=%s",
-                            fr.featureClass().getSimpleName(), fr.feature(), fr.supported()),
-                            staticFeatures.get().supports(fr.featureClass(), fr.feature()), is(fr.supported()));
-                } catch (NoSuchMethodException nsme) {
-                    throw new NoSuchMethodException(String.format("[supports%s] is not a valid feature on %s", fr.feature(), fr.featureClass()));
-                } catch (UnsupportedOperationException uoe) {
-                    // no worries - it just means that we can't use the cache to support this check and will have to
-                    // incur the cost of instantiating a graph instance directly
-                }
-            }
+            assumeRequirementsAreMetForTest(featureRequirementSet, staticFeatures.get(), true);
         }
 
         graphProvider.getTestListener().ifPresent(l -> l.onTestStart(this.getClass(), name.getMethodName()));
@@ -110,18 +99,10 @@ public abstract class AbstractGremlinTest {
         graph = graphProvider.openTestGraph(config);
         g = graphProvider.traversal(graph);
 
-        for (FeatureRequirement fr : featureRequirementSet) {
-            try {
-                // even if we checked static features above it's of little cost to recheck again with the real graph
-                // once it is instantiated. the real cost savings is preventing graph creation in the first place so
-                // let's double check that all is legit.
-                assumeThat(String.format("%s does not support all of the features required by this test so it will be ignored: %s.%s=%s",
-                                graph.getClass().getSimpleName(), fr.featureClass().getSimpleName(), fr.feature(), fr.supported()),
-                        graph.features().supports(fr.featureClass(), fr.feature()), is(fr.supported()));
-            } catch (NoSuchMethodException nsme) {
-                throw new NoSuchMethodException(String.format("[supports%s] is not a valid feature on %s", fr.feature(), fr.featureClass()));
-            }
-        }
+        // even if we checked static features earlier it's of little cost to recheck again with the real graph
+        // once it is instantiated. the real cost savings is preventing graph creation in the first place so
+        // let's double check that all is legit.
+        assumeRequirementsAreMetForTest(featureRequirementSet, graph.features(), false);
 
         beforeLoadGraphWith(graph);
 
@@ -131,6 +112,25 @@ public abstract class AbstractGremlinTest {
         afterLoadGraphWith(graph);
     }
 
+    private static void assumeRequirementsAreMetForTest(final Set<FeatureRequirement> featureRequirementSet,
+                                                        final Graph.Features features, final boolean staticCheck)
+            throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
+        for (FeatureRequirement fr : featureRequirementSet) {
+            try {
+                assumeThat(String.format("Features of the graph do not support all of the features required by this test so it will be ignored: %s.%s=%s",
+                        fr.featureClass().getSimpleName(), fr.feature(), fr.supported()),
+                        features.supports(fr.featureClass(), fr.feature()), is(fr.supported()));
+            } catch (NoSuchMethodException nsme) {
+                throw new NoSuchMethodException(String.format("[supports%s] is not a valid feature on %s", fr.feature(), fr.featureClass()));
+            } catch (UnsupportedOperationException uoe) {
+                // no worries if this is a check of static features - it just means that we can't use the cache to
+                // support this check and will have to incur the cost of instantiating a graph instance directly. but,
+                // if this is not a static check then something else is amiss and we should throw.
+                if (staticCheck) throw uoe;
+            }
+        }
+    }
+
     protected void beforeLoadGraphWith(final Graph g) throws Exception {
         // do nothing
     }