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/03/13 22:15:57 UTC

[4/4] incubator-tinkerpop git commit: Add ReadOnlyStrategyTest in the process suite.

Add ReadOnlyStrategyTest in the process suite.


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

Branch: refs/heads/master
Commit: 1c44895e88a0fdaf5795f0ec6be9c69b5d9cf8c0
Parents: 52f8ead
Author: Stephen Mallette <sp...@apache.org>
Authored: Fri Mar 13 17:15:32 2015 -0400
Committer: Stephen Mallette <sp...@apache.org>
Committed: Fri Mar 13 17:15:32 2015 -0400

----------------------------------------------------------------------
 .../decoration/ReadOnlyStrategyTest.java        |  70 ++++++++++
 .../gremlin/process/ProcessComputerSuite.java   |   6 +-
 .../gremlin/process/ProcessStandardSuite.java   |   6 +-
 .../decoration/ReadOnlyStrategyTest.java        | 134 +++++++++++++++++++
 4 files changed, 214 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/1c44895e/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ReadOnlyStrategyTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ReadOnlyStrategyTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ReadOnlyStrategyTest.java
new file mode 100644
index 0000000..4edf017
--- /dev/null
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ReadOnlyStrategyTest.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration;
+
+import org.apache.tinkerpop.gremlin.process.Traversal;
+import org.apache.tinkerpop.gremlin.process.graph.traversal.__;
+import org.apache.tinkerpop.gremlin.structure.Direction;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.util.Arrays;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+@RunWith(Parameterized.class)
+public class ReadOnlyStrategyTest {
+    @Parameterized.Parameters(name = "{0}")
+    public static Iterable<Object[]> data() {
+        return Arrays.asList(new Object[][]{
+                {"addBothE()", __.addBothE("test", "x")},
+                {"addBothE(args)", __.addBothE("test", "x", "this", "that")},
+                {"addInE()", __.addInE("test", "x")},
+                {"addInE(args)", __.addInE("test", "x", "this", "that")},
+                {"addOutE()", __.addOutE("test", "x")},
+                {"addOutE(args)", __.addOutE("test", "x", "this", "that")},
+                {"addE(IN)", __.addE(Direction.IN, "test", "test")},
+                {"addE(IN,args)", __.addE(Direction.IN, "test", "test", "this", "that")},
+                {"addE(OUT)", __.addE(Direction.OUT, "test", "test")},
+                {"addE(OUT,args)", __.addE(Direction.OUT, "test", "test", "this", "that")},
+                {"addE(BOTH)", __.addE(Direction.BOTH, "test", "test")},
+                {"addE(BOTH,args)", __.addE(Direction.BOTH, "test", "test", "this", "that")}});
+    }
+
+    @Parameterized.Parameter(value = 0)
+    public String name;
+
+    @Parameterized.Parameter(value = 1)
+    public Traversal traversal;
+
+    @Test
+    public void shouldPreventMutatingStepsFromBeingInTheTraversal() {
+        try {
+            ReadOnlyStrategy.instance().apply(traversal.asAdmin());
+            fail("The strategy should have found a mutating step.");
+        } catch (IllegalStateException ise) {
+            assertEquals("The provided traversal has a mutating step and thus is not read only", ise.getMessage());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/1c44895e/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessComputerSuite.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessComputerSuite.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessComputerSuite.java
index 2b7f444..74c4275 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessComputerSuite.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessComputerSuite.java
@@ -68,6 +68,7 @@ import org.apache.tinkerpop.gremlin.process.graph.traversal.step.sideEffect.Stor
 import org.apache.tinkerpop.gremlin.process.graph.traversal.step.sideEffect.TreeTest;
 import org.apache.tinkerpop.gremlin.process.graph.traversal.strategy.TraversalVerificationStrategyTest;
 import org.apache.tinkerpop.gremlin.process.traversal.engine.StandardTraversalEngine;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.ReadOnlyStrategyTest;
 import org.junit.runners.model.InitializationError;
 import org.junit.runners.model.RunnerBuilder;
 
@@ -173,7 +174,10 @@ public class ProcessComputerSuite extends AbstractGremlinSuite {
             ComputerDataStrategyTest.class,
 
             // strategy
-            TraversalVerificationStrategyTest.ComputerTraversals.class
+            TraversalVerificationStrategyTest.ComputerTraversals.class,
+
+            // decorations
+            ReadOnlyStrategyTest.class
     };
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/1c44895e/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessStandardSuite.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessStandardSuite.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessStandardSuite.java
index a295437..c541da3 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessStandardSuite.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessStandardSuite.java
@@ -28,6 +28,7 @@ import org.apache.tinkerpop.gremlin.process.graph.traversal.step.util.TraversalS
 import org.apache.tinkerpop.gremlin.process.graph.traversal.strategy.TraversalVerificationStrategyTest;
 import org.apache.tinkerpop.gremlin.process.traversal.CoreTraversalTest;
 import org.apache.tinkerpop.gremlin.process.traversal.engine.StandardTraversalEngine;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.ReadOnlyStrategyTest;
 import org.apache.tinkerpop.gremlin.process.util.PathTest;
 import org.junit.runners.model.InitializationError;
 import org.junit.runners.model.RunnerBuilder;
@@ -134,10 +135,13 @@ public class ProcessStandardSuite extends AbstractGremlinSuite {
             PathTest.class,
 
             // strategy
-            TraversalVerificationStrategyTest.StandardTraversals.class
+            TraversalVerificationStrategyTest.StandardTraversals.class,
 
             // algorithms
             // PageRankVertexProgramTest.class
+
+            // decorations
+            ReadOnlyStrategyTest.class
     };
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/1c44895e/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ReadOnlyStrategyTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ReadOnlyStrategyTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ReadOnlyStrategyTest.java
new file mode 100644
index 0000000..7e290a6
--- /dev/null
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ReadOnlyStrategyTest.java
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration;
+
+import org.apache.tinkerpop.gremlin.FeatureRequirement;
+import org.apache.tinkerpop.gremlin.process.AbstractGremlinProcessTest;
+import org.apache.tinkerpop.gremlin.process.Traversal;
+import org.apache.tinkerpop.gremlin.process.TraversalEngine;
+import org.apache.tinkerpop.gremlin.process.UseEngine;
+import org.apache.tinkerpop.gremlin.process.graph.traversal.GraphTraversalContext;
+import org.apache.tinkerpop.gremlin.structure.Direction;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+@UseEngine(TraversalEngine.Type.STANDARD)
+@UseEngine(TraversalEngine.Type.COMPUTER)
+public class ReadOnlyStrategyTest extends AbstractGremlinProcessTest {
+    @Test
+    public void shouldTraverseV() {
+        assertTraversal(create().V(), false);
+    }
+
+    @Test
+    public void shouldTraverseV_out() {
+        assertTraversal(create().V().out(), false);
+    }
+
+    @Test
+    public void shouldTraverseV_in() {
+        assertTraversal(create().V().in(), false);
+    }
+
+    @Test
+    public void shouldTraverseV_in_in() {
+        assertTraversal(create().V().in(), false);
+    }
+
+    @Test
+    public void shouldTraverseE() {
+        assertTraversal(create().E(), false);
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
+    public void shouldNotTraverseV_out_addBothE() {
+        assertTraversal(create().V().as("a").out().addBothE("test", "a"), true);
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
+    public void shouldNotTraverseV_out_addInE() {
+        assertTraversal(create().V().as("a").out().addInE("test", "a"), true);
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
+    public void shouldNotTraverseV_out_addOutE() {
+        assertTraversal(create().V().as("a").out().addOutE("test", "a"), true);
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
+    public void shouldNotTraverseV_In_addBothE() {
+        assertTraversal(create().V().as("a").in().addBothE("test", "a"), true);
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
+    public void shouldNotTraverseV_In_addInE() {
+        assertTraversal(create().V().as("a").in().addInE("test", "a"), true);
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
+    public void shouldNotTraverseV_In_addOutE() {
+        assertTraversal(create().V().as("a").in().addOutE("test", "a"), true);
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
+    public void shouldNotTraverseV_In_addEXBOTHX() {
+        assertTraversal(create().V().as("a").in().addE(Direction.BOTH, "test", "a"), true);
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
+    public void shouldNotTraverseV_In_addEXINX() {
+        assertTraversal(create().V().as("a").in().addE(Direction.IN, "test", "a"), true);
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
+    public void shouldNotTraverseV_In_addEXOUTX() {
+        assertTraversal(create().V().as("a").in().addE(Direction.OUT, "test", "a"), true);
+    }
+
+    private GraphTraversalContext create() {
+        return graphProvider.traversal(graph, ReadOnlyStrategy.instance());
+    }
+
+    private void assertTraversal(final Traversal t, final boolean hasMutatingStep) {
+        try {
+            t.asAdmin().applyStrategies();
+            if (hasMutatingStep) fail("The strategy should have found a mutating step.");
+        } catch (IllegalStateException ise) {
+            if (!hasMutatingStep)
+                fail("The traversal should not have failed as there is no mutating step.");
+            else
+                assertEquals("The provided traversal has a mutating step and thus is not read only", ise.getMessage());
+        }
+    }
+}