You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by ok...@apache.org on 2015/03/11 17:32:31 UTC
incubator-tinkerpop git commit: fixed ScriptRecordReaderWriterTest to
NOT use traversals off of vertex/edge. Stubbed strategy/decorations with
@spmallette.
Repository: incubator-tinkerpop
Updated Branches:
refs/heads/newapi 66e66c17a -> a8c46c5b5
fixed ScriptRecordReaderWriterTest to NOT use traversals off of vertex/edge. Stubbed strategy/decorations with @spmallette.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/a8c46c5b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/a8c46c5b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/a8c46c5b
Branch: refs/heads/newapi
Commit: a8c46c5b571fcb3a5667fa643afcad4aad73aa8f
Parents: 66e66c1
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Wed Mar 11 10:32:25 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Wed Mar 11 10:32:25 2015 -0600
----------------------------------------------------------------------
.../gremlin/process/TraversalStrategies.java | 12 --
.../traversal/step/HasContainerHolder.java | 2 +
.../graph/traversal/step/filter/HasStep.java | 5 +
.../traversal/step/sideEffect/GraphStep.java | 8 +-
.../traversal/step/SideEffectRegistrar.java | 27 ----
.../strategy/decoration/ElementIdStrategy.java | 67 ++++++++
.../strategy/decoration/ReadOnlyStrategy.java | 50 ++++++
.../structure/io/script/script-output.groovy | 12 +-
.../traversal/GraphTraversalMethodsTest.java | 161 -------------------
.../io/script/ScriptRecordReaderWriterTest.java | 18 +--
.../gremlin/neo4j/structure/Neo4jGraphTest.java | 43 ++---
.../traversal/sideEffect/TinkerGraphStep.java | 12 +-
.../tinkergraph/structure/TinkerGraphTest.java | 10 +-
13 files changed, 183 insertions(+), 244 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a8c46c5b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/TraversalStrategies.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/TraversalStrategies.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/TraversalStrategies.java
index d9b56df..3bb6c5c 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/TraversalStrategies.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/TraversalStrategies.java
@@ -31,10 +31,7 @@ import org.apache.tinkerpop.gremlin.process.graph.traversal.strategy.RangeByIsCo
import org.apache.tinkerpop.gremlin.process.graph.traversal.strategy.TraversalVerificationStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.DefaultTraversalStrategies;
import org.apache.tinkerpop.gremlin.process.traverser.TraverserGeneratorFactory;
-import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Graph;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.tinkerpop.gremlin.structure.VertexProperty;
import org.apache.tinkerpop.gremlin.util.tools.MultiMap;
import java.io.Serializable;
@@ -176,9 +173,6 @@ public interface TraversalStrategies extends Serializable, Cloneable {
ConjunctionStrategy.instance());
try {
CACHE.put(Graph.class, coreStrategies.clone());
- CACHE.put(Vertex.class, coreStrategies.clone());
- CACHE.put(Edge.class, coreStrategies.clone());
- CACHE.put(VertexProperty.class, coreStrategies.clone());
CACHE.put(__.class, new DefaultTraversalStrategies());
} catch (final CloneNotSupportedException e) {
throw new IllegalStateException(e.getMessage(), e);
@@ -196,12 +190,6 @@ public interface TraversalStrategies extends Serializable, Cloneable {
return CACHE.get(__.class);
else if (Graph.class.isAssignableFrom(emanatingClass))
return CACHE.get(Graph.class);
- else if (Vertex.class.isAssignableFrom(emanatingClass))
- return CACHE.get(Vertex.class);
- else if (Edge.class.isAssignableFrom(emanatingClass))
- return CACHE.get(Edge.class);
- else if (VertexProperty.class.isAssignableFrom(emanatingClass))
- return CACHE.get(VertexProperty.class);
else
return new DefaultTraversalStrategies();
// throw new IllegalStateException("The provided class has no registered traversal strategies: " + emanatingClass);
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a8c46c5b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/HasContainerHolder.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/HasContainerHolder.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/HasContainerHolder.java
index 8b4d357..52db804 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/HasContainerHolder.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/HasContainerHolder.java
@@ -28,4 +28,6 @@ import java.util.List;
public interface HasContainerHolder {
public List<HasContainer> getHasContainers();
+
+ public void addHasContainer(final HasContainer hasContainer);
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a8c46c5b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/filter/HasStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/filter/HasStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/filter/HasStep.java
index 6b5e170..8376139 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/filter/HasStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/filter/HasStep.java
@@ -59,6 +59,11 @@ public class HasStep<S extends Element> extends FilterStep<S> implements HasCont
}
@Override
+ public void addHasContainer(final HasContainer hasContainer) {
+ throw new UnsupportedOperationException(this.getClass().getSimpleName() + " does not support adding new HasContainers");
+ }
+
+ @Override
public Set<TraverserRequirement> getRequirements() {
return Collections.singleton(TraverserRequirement.OBJECT);
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a8c46c5b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/sideEffect/GraphStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/sideEffect/GraphStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/sideEffect/GraphStep.java
index 51582d9..203d983 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/sideEffect/GraphStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/sideEffect/GraphStep.java
@@ -40,7 +40,7 @@ import java.util.function.Supplier;
public class GraphStep<S extends Element> extends StartStep<S> implements EngineDependent {
protected final Class<S> returnClass;
- protected final Object[] ids;
+ protected Object[] ids;
protected transient Graph graph;
protected transient Supplier<Iterator<S>> iteratorSupplier;
@@ -59,7 +59,7 @@ public class GraphStep<S extends Element> extends StartStep<S> implements Engine
}
public String toString() {
- return TraversalHelper.makeStepString(this, Arrays.asList(this.ids), this.returnClass.getSimpleName().toLowerCase());
+ return TraversalHelper.makeStepString(this, Arrays.toString(this.ids), this.returnClass.getSimpleName().toLowerCase());
}
public boolean returnsVertices() {
@@ -86,6 +86,10 @@ public class GraphStep<S extends Element> extends StartStep<S> implements Engine
return this.ids;
}
+ public void clearIds() {
+ this.ids = new Object[0];
+ }
+
@Override
public void onEngine(final TraversalEngine traversalEngine) {
if (traversalEngine.isComputer()) {
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a8c46c5b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/SideEffectRegistrar.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/SideEffectRegistrar.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/SideEffectRegistrar.java
deleted file mode 100644
index 949c862..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/SideEffectRegistrar.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * 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.step;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public interface SideEffectRegistrar {
-
- public void registerSideEffects();
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a8c46c5b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ElementIdStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ElementIdStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ElementIdStrategy.java
new file mode 100644
index 0000000..3df6c2f
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ElementIdStrategy.java
@@ -0,0 +1,67 @@
+/*
+ * 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.T;
+import org.apache.tinkerpop.gremlin.process.Traversal;
+import org.apache.tinkerpop.gremlin.process.graph.traversal.step.HasContainerHolder;
+import org.apache.tinkerpop.gremlin.process.graph.traversal.step.filter.HasStep;
+import org.apache.tinkerpop.gremlin.process.graph.traversal.step.sideEffect.GraphStep;
+import org.apache.tinkerpop.gremlin.process.graph.traversal.strategy.AbstractTraversalStrategy;
+import org.apache.tinkerpop.gremlin.process.graph.util.HasContainer;
+import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
+import org.apache.tinkerpop.gremlin.structure.Contains;
+import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
+
+import java.util.Arrays;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public final class ElementIdStrategy extends AbstractTraversalStrategy {
+
+ private final String idPropertyKey;
+
+ public ElementIdStrategy(final String idPropertyKey) {
+ this.idPropertyKey = idPropertyKey;
+ }
+
+ @Override
+ public void apply(final Traversal.Admin<?, ?> traversal) {
+ TraversalHelper.getStepsOfAssignableClass(HasStep.class, traversal).stream()
+ .filter(hasStep -> ((HasStep<?>) hasStep).getHasContainers().get(0).key.equals(T.id.getAccessor()))
+ .forEach(hasStep -> ((HasStep<?>) hasStep).getHasContainers().get(0).key = this.idPropertyKey);
+
+ if (traversal.getStartStep() instanceof GraphStep) {
+ final GraphStep graphStep = (GraphStep) traversal.getStartStep();
+ if (graphStep instanceof HasContainerHolder)
+ ((HasContainerHolder) graphStep).addHasContainer(new HasContainer(this.idPropertyKey, Contains.within, Arrays.asList(graphStep.getIds())));
+ else
+ TraversalHelper.insertAfterStep(new HasStep(traversal, new HasContainer(this.idPropertyKey, Contains.within, Arrays.asList(graphStep.getIds()))), graphStep, traversal);
+ graphStep.clearIds();
+ }
+
+
+ }
+
+ @Override
+ public String toString() {
+ return StringFactory.traversalStrategyString(this);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a8c46c5b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ReadOnlyStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ReadOnlyStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ReadOnlyStrategy.java
new file mode 100644
index 0000000..f8af029
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ReadOnlyStrategy.java
@@ -0,0 +1,50 @@
+/*
+ * 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.step.sideEffect.AddEdgeStep;
+import org.apache.tinkerpop.gremlin.process.graph.traversal.strategy.AbstractTraversalStrategy;
+import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public final class ReadOnlyStrategy extends AbstractTraversalStrategy {
+
+ private static final ReadOnlyStrategy INSTANCE = new ReadOnlyStrategy();
+
+ private ReadOnlyStrategy() {
+ }
+
+ @Override
+ public void apply(final Traversal.Admin<?, ?> traversal) {
+ if (traversal.getSteps().stream().filter(step -> step instanceof AddEdgeStep).findAny().isPresent())
+ throw new IllegalStateException("The provided traversal has a mutating step and thus is not read only");
+ }
+
+ public static ReadOnlyStrategy instance() {
+ return INSTANCE;
+ }
+
+ @Override
+ public String toString() {
+ return StringFactory.traversalStrategyString(this);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a8c46c5b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/script/script-output.groovy
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/script/script-output.groovy b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/script/script-output.groovy
index cb593d8..d8a14bf 100644
--- a/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/script/script-output.groovy
+++ b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/script/script-output.groovy
@@ -1,3 +1,5 @@
+import org.apache.tinkerpop.gremlin.structure.Direction
+
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -20,11 +22,13 @@ def stringify(vertex) {
def edgeMap = { vdir ->
return {
def e = it.get()
- e.values("weight").inject(e.label(), e."${vdir}V"().next().id()).join(":")
+ def g = e.graph().traversal(standard)
+ g.E(e).values("weight").inject(e.label(), g.E(e).toV(Direction.valueOf(vdir.toUpperCase())).next().id()).join(":")
}
}
- def v = vertex.values("name", "age", "lang").inject(vertex.id(), vertex.label()).join(":")
- def outE = vertex.outE().map(edgeMap("in")).join(",")
- def inE = vertex.inE().map(edgeMap("out")).join(",")
+ def g = vertex.graph().traversal(standard)
+ def v = g.V(vertex).values("name", "age", "lang").inject(vertex.id(), vertex.label()).join(":")
+ def outE = g.V(vertex).outE().map(edgeMap("in")).join(",")
+ def inE = g.V(vertex).inE().map(edgeMap("out")).join(",")
return [v, outE, inE].join("\t")
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a8c46c5b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/graph/traversal/GraphTraversalMethodsTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/graph/traversal/GraphTraversalMethodsTest.java b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/graph/traversal/GraphTraversalMethodsTest.java
deleted file mode 100644
index 21f7967..0000000
--- a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/graph/traversal/GraphTraversalMethodsTest.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * 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.graph.traversal;
-
-import org.apache.tinkerpop.gremlin.process.graph.traversal.GraphTraversal;
-import org.apache.tinkerpop.gremlin.structure.Edge;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.tinkerpop.gremlin.structure.VertexProperty;
-import org.junit.Test;
-
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.stream.Collectors;
-
-import static org.junit.Assert.fail;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public class GraphTraversalMethodsTest {
-
- @Test
- public void shouldHaveAllGraphTraversalMethodsOff__() {
- final List<Method> graphTraversalMethods = Arrays.asList(GraphTraversal.class.getMethods()).stream()
- .filter(m -> !Modifier.isStatic(m.getModifiers()))
- .filter(m -> !m.getName().equals("by"))
- .filter(m -> !m.getName().equals("option"))
- .filter(m -> !m.getName().equals("asAdmin"))
- .filter(m -> GraphTraversal.class.isAssignableFrom(m.getReturnType())).collect(Collectors.toList());
-
- final List<Method> vertexMethods = new ArrayList<>(Arrays.asList(__.class.getMethods()));
-
- final List<Method> nonExistent = graphTraversalMethods.stream()
- .filter(m -> !existsInList(m, vertexMethods))
- .collect(Collectors.toList());
- if (nonExistent.size() > 0) {
- for (Method method : nonExistent) {
- System.out.println("Requirement implementation: " + method);
- }
- fail("The following methods are not implemented by __: " + nonExistent);
- }
- }
-
- @Test
- public void shouldHaveAllGraphTraversalMethodsOffVertex() {
- final List<Method> graphTraversalMethods = Arrays.asList(GraphTraversal.class.getMethods()).stream()
- .filter(m -> !Modifier.isStatic(m.getModifiers()))
- .filter(m -> !m.getName().equals("value"))
- .filter(m -> !m.getName().equals("id"))
- .filter(m -> !m.getName().equals("label"))
- .filter(m -> !m.getName().equals("key"))
- .filter(m -> !m.getName().equals("by"))
- .filter(m -> !m.getName().equals("option"))
- .filter(m -> !m.getName().equals("asAdmin"))
- .filter(m -> GraphTraversal.class.isAssignableFrom(m.getReturnType())).collect(Collectors.toList());
-
- final List<Method> vertexMethods = new ArrayList<>(Arrays.asList(Vertex.class.getMethods()));
-
- final List<Method> nonExistent = graphTraversalMethods.stream()
- .filter(m -> !existsInList(m, vertexMethods))
- .collect(Collectors.toList());
- if (nonExistent.size() > 0) {
- for (Method method : nonExistent) {
- System.out.println("Requirement implementation: " + method);
- }
- fail("The following methods are not implemented by Vertex: " + nonExistent);
- }
- }
-
- @Test
- public void shouldHaveAllGraphTraversalMethodsOffEdge() {
- final List<Method> graphTraversalMethods = Arrays.asList(GraphTraversal.class.getMethods()).stream()
- .filter(m -> !Modifier.isStatic(m.getModifiers()))
- .filter(m -> !m.getName().equals("value"))
- .filter(m -> !m.getName().equals("id"))
- .filter(m -> !m.getName().equals("label"))
- .filter(m -> !m.getName().equals("key"))
- .filter(m -> !m.getName().equals("by"))
- .filter(m -> !m.getName().equals("option"))
- .filter(m -> !m.getName().equals("asAdmin"))
- .filter(m -> GraphTraversal.class.isAssignableFrom(m.getReturnType())).collect(Collectors.toList());
-
- final List<Method> edgeMethods = new ArrayList<>(Arrays.asList(Edge.class.getMethods()));
-
- final List<Method> nonExistent = graphTraversalMethods.stream()
- .filter(m -> !existsInList(m, edgeMethods))
- .collect(Collectors.toList());
- if (nonExistent.size() > 0) {
- for (Method method : nonExistent) {
- System.out.println("Requirement implementation: " + method);
- }
- fail("The following methods are not implemented by Edge: " + nonExistent);
- }
-
- }
-
- @Test
- public void shouldHaveAllGraphTraversalMethodsOffVertexProperty() {
- final List<Method> graphTraversalMethods = Arrays.asList(GraphTraversal.class.getMethods()).stream()
- .filter(m -> !Modifier.isStatic(m.getModifiers()))
- .filter(m -> !m.getName().equals("value"))
- .filter(m -> !m.getName().equals("id"))
- .filter(m -> !m.getName().equals("label"))
- .filter(m -> !m.getName().equals("key"))
- .filter(m -> !m.getName().equals("by"))
- .filter(m -> !m.getName().equals("option"))
- .filter(m -> !m.getName().equals("asAdmin"))
- .filter(m -> GraphTraversal.class.isAssignableFrom(m.getReturnType())).collect(Collectors.toList());
-
- final List<Method> vertexPropertyMethods = new ArrayList<>(Arrays.asList(VertexProperty.class.getMethods()));
-
- final List<Method> nonExistent = graphTraversalMethods.stream()
- .filter(m -> !existsInList(m, vertexPropertyMethods))
- .collect(Collectors.toList());
- if (nonExistent.size() > 0) {
- for (Method method : nonExistent) {
- System.out.println("Requirement implementation: " + method);
- }
- fail("The following methods are not implemented by Edge: " + nonExistent);
- }
-
- }
-
-
- private static boolean existsInList(final Method method, final List<Method> methods) {
- final List<Method> nonMatches = methods.stream()
- .filter(m -> m.getName().equals(method.getName()))
- .filter(m -> m.getReturnType().equals(method.getReturnType()))
- .filter(m -> m.getParameterCount() == method.getParameterCount())
- .filter(m -> {
- boolean equals = true;
- for (int i = 0; i < m.getParameters().length; i++) {
- if (!m.getParameters()[i].getType().equals(method.getParameters()[i].getType())) {
- equals = false;
- }
- }
- return equals;
- })
- .collect(Collectors.toList());
- return nonMatches.size() == 1;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a8c46c5b/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReaderWriterTest.java
----------------------------------------------------------------------
diff --git a/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReaderWriterTest.java b/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReaderWriterTest.java
index bda26cb..aeacfc9 100644
--- a/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReaderWriterTest.java
+++ b/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReaderWriterTest.java
@@ -18,10 +18,6 @@
*/
package org.apache.tinkerpop.gremlin.hadoop.structure.io.script;
-import org.apache.tinkerpop.gremlin.hadoop.HadoopGraphProvider;
-import org.apache.tinkerpop.gremlin.hadoop.structure.io.VertexWritable;
-import org.apache.tinkerpop.gremlin.structure.Property;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.LocalFileSystem;
import org.apache.hadoop.fs.Path;
@@ -32,6 +28,11 @@ import org.apache.hadoop.mapreduce.TaskAttemptContext;
import org.apache.hadoop.mapreduce.TaskAttemptID;
import org.apache.hadoop.mapreduce.lib.input.FileSplit;
import org.apache.hadoop.util.ReflectionUtils;
+import org.apache.tinkerpop.gremlin.hadoop.HadoopGraphProvider;
+import org.apache.tinkerpop.gremlin.hadoop.structure.io.VertexWritable;
+import org.apache.tinkerpop.gremlin.structure.Property;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.junit.Ignore;
import org.junit.Test;
import java.io.ByteArrayOutputStream;
@@ -106,14 +107,5 @@ public class ScriptRecordReaderWriterTest {
assertTrue(line4.contains("created:5:1.0"));
//assertTrue(line4.contains("knows:person:1:1.0")); // TODO: requires edge-copy
}
-
- private <T> long count(final Iterable<T> iter) {
- long count = 0;
- for (T anIter : iter) {
- count++;
- }
-
- return count;
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a8c46c5b/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jGraphTest.java
----------------------------------------------------------------------
diff --git a/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jGraphTest.java b/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jGraphTest.java
index 06eeeef..48d62f2 100644
--- a/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jGraphTest.java
+++ b/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jGraphTest.java
@@ -22,6 +22,7 @@ import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine;
import org.apache.tinkerpop.gremlin.neo4j.BaseNeo4jGraphTest;
import org.apache.tinkerpop.gremlin.process.T;
import org.apache.tinkerpop.gremlin.process.graph.traversal.GraphTraversal;
+import org.apache.tinkerpop.gremlin.process.graph.traversal.GraphTraversalContext;
import org.apache.tinkerpop.gremlin.structure.Contains;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
@@ -282,7 +283,7 @@ public class Neo4jGraphTest extends BaseNeo4jGraphTest {
public void shouldEnsureTraverseRelationshipNeedsTx() throws ScriptException {
final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine();
final Bindings bindings = engine.createBindings();
- bindings.put("g", graph);
+ bindings.put("g", graph.traversal(GraphTraversalContext.standard));
bindings.put("#jsr223.groovy.engine.keep.globals", "phantom");
Vertex marko = this.graph.addVertex(T.label, "Person", "name", "marko");
@@ -303,7 +304,7 @@ public class Neo4jGraphTest extends BaseNeo4jGraphTest {
public void shouldEnsureTraversalOfVerticesNeedsTx() throws ScriptException {
final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine();
final Bindings bindings = engine.createBindings();
- bindings.put("g", graph);
+ bindings.put("g", graph.traversal(GraphTraversalContext.standard));
bindings.put("#jsr223.groovy.engine.keep.globals", "phantom");
Vertex marko = this.graph.addVertex(T.label, "Person", "name", "marko");
@@ -541,10 +542,10 @@ public class Neo4jGraphTest extends BaseNeo4jGraphTest {
tryCommit(graph, graph -> {
assertEquals(2, graph.traversal().V().count().next().intValue());
- // assertEquals(2, a.properties("name").count().next().intValue());
- // assertEquals(1, b.properties("name").count().next().intValue());
- // assertEquals(1, b.properties("location").count().next().intValue());
- // assertEquals(0, g.E().count().next().intValue());
+ // assertEquals(2, a.properties("name").count().next().intValue());
+ // assertEquals(1, b.properties("name").count().next().intValue());
+ // assertEquals(1, b.properties("location").count().next().intValue());
+ // assertEquals(0, g.E().count().next().intValue());
assertEquals(4l, cypher.execute("MATCH n RETURN COUNT(n)").iterator().next().get("COUNT(n)"));
assertEquals(2l, cypher.execute("MATCH (n)-[r]->(m) RETURN COUNT(r)").iterator().next().get("COUNT(r)"));
@@ -579,10 +580,10 @@ public class Neo4jGraphTest extends BaseNeo4jGraphTest {
a.property(VertexProperty.Cardinality.single, "name", "the marko");
tryCommit(graph, g -> {
assertEquals(2, g.traversal().V().count().next().intValue());
- //assertEquals(1, a.properties().count().next().intValue());
- // assertEquals(1, b.properties("name").count().next().intValue());
- // assertEquals(1, b.properties("location").count().next().intValue());
- // assertEquals(0, g.E().count().next().intValue());
+ //assertEquals(1, a.properties().count().next().intValue());
+ // assertEquals(1, b.properties("name").count().next().intValue());
+ // assertEquals(1, b.properties("location").count().next().intValue());
+ // assertEquals(0, g.E().count().next().intValue());
assertEquals(2l, cypher.execute("MATCH n RETURN COUNT(n)").iterator().next().get("COUNT(n)"));
assertEquals(0l, cypher.execute("MATCH (n)-[r]->(m) RETURN COUNT(r)").iterator().next().get("COUNT(r)"));
@@ -597,9 +598,9 @@ public class Neo4jGraphTest extends BaseNeo4jGraphTest {
a.property("name").remove();
tryCommit(graph, g -> {
assertEquals(2, g.traversal().V().count().next().intValue());
- // assertEquals(0, a.properties().count().next().intValue());
- // assertEquals(2, b.properties().count().next().intValue());
- // assertEquals(0, g.E().count().next().intValue());
+ // assertEquals(0, a.properties().count().next().intValue());
+ // assertEquals(2, b.properties().count().next().intValue());
+ // assertEquals(0, g.E().count().next().intValue());
assertEquals(2l, cypher.execute("MATCH n RETURN COUNT(n)").iterator().next().get("COUNT(n)"));
assertEquals(0l, cypher.execute("MATCH (n)-[r]->(m) RETURN COUNT(r)").iterator().next().get("COUNT(r)"));
assertEquals(0, StreamFactory.stream(a.getBaseVertex().getPropertyKeys()).count());
@@ -609,10 +610,10 @@ public class Neo4jGraphTest extends BaseNeo4jGraphTest {
a.property(VertexProperty.Cardinality.single, "name", "the marko", "acl", "private");
tryCommit(graph, g -> {
assertEquals(2, g.traversal().V().count().next().intValue());
- // assertEquals(1, a.properties("name").count().next().intValue());
- // assertEquals(1, b.properties("name").count().next().intValue());
- // assertEquals(1, b.properties("location").count().next().intValue());
- // assertEquals(0, g.E().count().next().intValue());
+ // assertEquals(1, a.properties("name").count().next().intValue());
+ // assertEquals(1, b.properties("name").count().next().intValue());
+ // assertEquals(1, b.properties("location").count().next().intValue());
+ // assertEquals(0, g.E().count().next().intValue());
assertEquals(3l, cypher.execute("MATCH n RETURN COUNT(n)").iterator().next().get("COUNT(n)"));
assertEquals(1l, cypher.execute("MATCH (n)-[r]->(m) RETURN COUNT(r)").iterator().next().get("COUNT(r)"));
@@ -655,10 +656,10 @@ public class Neo4jGraphTest extends BaseNeo4jGraphTest {
a.property(VertexProperty.Cardinality.single, "name", "the marko", "acl", "private");
tryCommit(graph, g -> {
assertEquals(2, g.traversal().V().count().next().intValue());
- // assertEquals(1, a.properties("name").count().next().intValue());
- // assertEquals(1, b.properties("name").count().next().intValue());
- // assertEquals(1, b.properties("location").count().next().intValue());
- // assertEquals(0, g.E().count().next().intValue());
+ // assertEquals(1, a.properties("name").count().next().intValue());
+ // assertEquals(1, b.properties("name").count().next().intValue());
+ // assertEquals(1, b.properties("location").count().next().intValue());
+ // assertEquals(0, g.E().count().next().intValue());
assertEquals(3l, cypher.execute("MATCH n RETURN COUNT(n)").iterator().next().get("COUNT(n)"));
assertEquals(1l, cypher.execute("MATCH (n)-[r]->(m) RETURN COUNT(r)").iterator().next().get("COUNT(r)"));
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a8c46c5b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/graph/traversal/sideEffect/TinkerGraphStep.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/graph/traversal/sideEffect/TinkerGraphStep.java b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/graph/traversal/sideEffect/TinkerGraphStep.java
index 66d328f..a6117a4 100644
--- a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/graph/traversal/sideEffect/TinkerGraphStep.java
+++ b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/graph/traversal/sideEffect/TinkerGraphStep.java
@@ -18,6 +18,7 @@
*/
package org.apache.tinkerpop.gremlin.tinkergraph.process.graph.traversal.sideEffect;
+import org.apache.tinkerpop.gremlin.process.graph.traversal.step.HasContainerHolder;
import org.apache.tinkerpop.gremlin.process.graph.traversal.step.sideEffect.GraphStep;
import org.apache.tinkerpop.gremlin.process.graph.util.HasContainer;
import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
@@ -38,7 +39,7 @@ import java.util.stream.Collectors;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
-public class TinkerGraphStep<S extends Element> extends GraphStep<S> {
+public class TinkerGraphStep<S extends Element> extends GraphStep<S> implements HasContainerHolder {
public final List<HasContainer> hasContainers = new ArrayList<>();
@@ -102,4 +103,13 @@ public class TinkerGraphStep<S extends Element> extends GraphStep<S> {
return list.iterator();
}
+ @Override
+ public List<HasContainer> getHasContainers() {
+ return this.hasContainers;
+ }
+
+ @Override
+ public void addHasContainer(final HasContainer hasContainer) {
+ this.hasContainers.add(hasContainer);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a8c46c5b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java
index 9030381..86572a2 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java
@@ -23,7 +23,8 @@ import org.apache.tinkerpop.gremlin.AbstractGremlinTest;
import org.apache.tinkerpop.gremlin.process.T;
import org.apache.tinkerpop.gremlin.process.Traversal;
import org.apache.tinkerpop.gremlin.process.graph.traversal.GraphTraversalContext;
-import org.apache.tinkerpop.gremlin.process.traversal.engine.StandardTraversalEngine;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.ElementIdStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.ReadOnlyStrategy;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Graph;
@@ -146,8 +147,11 @@ public class TinkerGraphTest {
@Ignore
public void testPlay3() throws Exception {
Graph graph = TinkerFactory.createModern();
- GraphTraversalContext g = graph.traversal(GraphTraversalContext.build().engine(StandardTraversalEngine.builder()));
- g.V().out().out().values("name").forEachRemaining(System.out::println);
+ GraphTraversalContext g = graph.traversal(GraphTraversalContext.build().strategy(new ElementIdStrategy("name")));
+ Traversal t = g.V("marko").out("knows").in("knows").has(T.id,"marko");
+ System.out.println(t);
+ t.forEachRemaining(System.out::println);
+ System.out.println(t);
}
@Test