Repository: tinkerpop Updated Branches: refs/heads/TINKERPOP-1278 f834235bc -> c60e2132a
Added GraphSONTranslator to the test suite. It wraps JavaTranslator but before sending the Bytecode to JavaTranslator, it serializes and then deserializes the Bytecode using GraphSON. This ensures that GraphSON serialization of Bytecode is sound (at least within the range of tests in the ProcessTestSuite -- both STANDARD and COMPUTER). There are a few tests that fail around Vertex/Edge arguments that are currently ignored. We should be able to get those connected easily. Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/c60e2132 Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/c60e2132 Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/c60e2132 Branch: refs/heads/TINKERPOP-1278 Commit: c60e2132a6feb76ddf72073614b60dfa824193b4 Parents: f834235 Author: Marko A. Rodriguez <okramma...@gmail.com> Authored: Thu Jul 14 08:04:38 2016 -0600 Committer: Marko A. Rodriguez <okramma...@gmail.com> Committed: Thu Jul 14 08:04:38 2016 -0600 ---------------------------------------------------------------------- .../gremlin/process/traversal/Bytecode.java | 11 +++ .../process/traversal/util/BytecodeHelper.java | 47 ++++++++++ .../structure/io/graphson/GraphSONModule.java | 2 + .../graphson/GraphSONTraversalSerializers.java | 40 ++++++--- .../java/translator/GraphSONTranslator.java | 83 +++++++++++++++++ ...GraphGraphSONTranslatorComputerProvider.java | 37 ++++++++ ...phGraphSONTranslatorProcessComputerTest.java | 33 +++++++ ...phGraphSONTranslatorProcessStandardTest.java | 33 +++++++ .../TinkerGraphGraphSONTranslatorProvider.java | 93 ++++++++++++++++++++ 9 files changed, 367 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c60e2132/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Bytecode.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Bytecode.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Bytecode.java index f7e886b..0cc1e3d 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Bytecode.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Bytecode.java @@ -40,6 +40,7 @@ public final class Bytecode implements Cloneable, Serializable { private List<Instruction> sourceInstructions = new ArrayList<>(); private List<Instruction> stepInstructions = new ArrayList<>(); + // private transient List<Instruction> instructions = null; public void addSource(final String sourceName, final Object... arguments) { this.sourceInstructions.add(new Instruction(sourceName, flattenArguments(arguments))); @@ -57,6 +58,15 @@ public final class Bytecode implements Cloneable, Serializable { return Collections.unmodifiableList(this.stepInstructions); } + /*public List<Instruction> getInstructions() { + if (null == this.instructions) { + this.instructions = new ArrayList<>(); + this.instructions.addAll(this.sourceInstructions); + this.instructions.addAll(this.stepInstructions); + } + return this.instructions; + }*/ + @Override public String toString() { return Arrays.asList(this.sourceInstructions, this.stepInstructions).toString(); @@ -81,6 +91,7 @@ public final class Bytecode implements Cloneable, Serializable { final Bytecode clone = (Bytecode) super.clone(); clone.sourceInstructions = new ArrayList<>(this.sourceInstructions); clone.stepInstructions = new ArrayList<>(this.stepInstructions); + //clone.instructions = null; return clone; } catch (final CloneNotSupportedException e) { throw new IllegalStateException(e.getMessage(), e); http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c60e2132/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/BytecodeHelper.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/BytecodeHelper.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/BytecodeHelper.java new file mode 100644 index 0000000..516a083 --- /dev/null +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/BytecodeHelper.java @@ -0,0 +1,47 @@ +/* + * 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.util; + +import org.apache.tinkerpop.gremlin.process.traversal.Bytecode; + +import java.util.function.Predicate; + +/** + * @author Marko A. Rodriguez (http://markorodriguez.com) + */ +public final class BytecodeHelper { + + private BytecodeHelper() { + // public static methods only + } + + public static Bytecode filterInstructions(final Bytecode bytecode, final Predicate<Bytecode.Instruction> predicate) { + final Bytecode clone = new Bytecode(); + for (final Bytecode.Instruction instruction : bytecode.getSourceInstructions()) { + if (predicate.test(instruction)) + clone.addSource(instruction.getOperator(), instruction.getArguments()); + } + for (final Bytecode.Instruction instruction : bytecode.getStepInstructions()) { + if (predicate.test(instruction)) + clone.addStep(instruction.getOperator(), instruction.getArguments()); + } + return clone; + } +} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c60e2132/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java index 9af3d66..d625125 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java @@ -24,6 +24,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.Order; import org.apache.tinkerpop.gremlin.process.traversal.P; import org.apache.tinkerpop.gremlin.process.traversal.Path; import org.apache.tinkerpop.gremlin.process.traversal.Pop; +import org.apache.tinkerpop.gremlin.process.traversal.SackFunctions; import org.apache.tinkerpop.gremlin.process.traversal.Scope; import org.apache.tinkerpop.gremlin.process.traversal.Traversal; import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree; @@ -131,6 +132,7 @@ abstract class GraphSONModule extends SimpleModule { addSerializer(VertexProperty.Cardinality.class, new GraphSONTraversalSerializers.EnumJacksonSerializer()); addSerializer(Column.class, new GraphSONTraversalSerializers.EnumJacksonSerializer()); addSerializer(Direction.class, new GraphSONTraversalSerializers.EnumJacksonSerializer()); + addSerializer(SackFunctions.Barrier.class, new GraphSONTraversalSerializers.EnumJacksonSerializer()); addSerializer(Operator.class, new GraphSONTraversalSerializers.EnumJacksonSerializer()); addSerializer(Order.class, new GraphSONTraversalSerializers.EnumJacksonSerializer()); addSerializer(Pop.class, new GraphSONTraversalSerializers.EnumJacksonSerializer()); http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c60e2132/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTraversalSerializers.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTraversalSerializers.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTraversalSerializers.java index ee24bb8..78ca36e 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTraversalSerializers.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTraversalSerializers.java @@ -24,6 +24,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.Operator; import org.apache.tinkerpop.gremlin.process.traversal.Order; import org.apache.tinkerpop.gremlin.process.traversal.P; import org.apache.tinkerpop.gremlin.process.traversal.Pop; +import org.apache.tinkerpop.gremlin.process.traversal.SackFunctions; import org.apache.tinkerpop.gremlin.process.traversal.Scope; import org.apache.tinkerpop.gremlin.process.traversal.Traversal; import org.apache.tinkerpop.gremlin.process.traversal.util.AndP; @@ -47,6 +48,7 @@ import org.apache.tinkerpop.shaded.jackson.databind.ser.std.StdSerializer; import java.io.IOException; import java.util.ArrayList; +import java.util.Collection; import java.util.List; /** @@ -184,21 +186,32 @@ public final class GraphSONTraversalSerializers { for (int j = 1; j < instruction.size(); j++) { final JsonNode argument = instruction.get(j); if (argument.getNodeType().equals(JsonNodeType.OBJECT)) { - final String type = argument.get("@type").textValue(); - if (type.equals("Bytecode")) - arguments.add(oc.readValue(argument.traverse(oc), Bytecode.class)); - else if (type.equals("P")) - arguments.add(oc.readValue(argument.traverse(oc), P.class)); - else if (type.equals("Lambda")) - arguments.add(oc.readValue(argument.traverse(oc), Lambda.class)); - else - arguments.add(oc.readValue(argument.traverse(oc), Enum.class)); + if (argument.has("@type")) { + final String type = argument.get("@type").textValue(); + if (type.equals("Bytecode")) + arguments.add(oc.readValue(argument.traverse(oc), Bytecode.class)); + else if (type.equals("P")) + arguments.add(oc.readValue(argument.traverse(oc), P.class)); + else if (type.equals("Lambda")) + arguments.add(oc.readValue(argument.traverse(oc), Lambda.class)); + else + arguments.add(oc.readValue(argument.traverse(oc), Enum.class)); + } else { + arguments.add(oc.readValue(argument.traverse(oc), Object.class)); // TODO: vertices/edges/etc. don't get processed correctly + } } else if (argument.getNodeType().equals(JsonNodeType.NUMBER)) { arguments.add(argument.asInt()); // TODO } else if (argument.getNodeType().equals(JsonNodeType.STRING)) { arguments.add(argument.textValue()); } else if (argument.getNodeType().equals(JsonNodeType.BOOLEAN)) { arguments.add(argument.booleanValue()); + } else if (argument.getNodeType().equals(JsonNodeType.ARRAY)) { + final List<Object> list = new ArrayList<>(); + for (int k = 0; k < argument.size(); k++) { + list.add(oc.readValue(argument.get(k).traverse(oc), Object.class)); + //list.add(argument.get(k).textValue()); + } + arguments.add(list); } else { throw new IOException("Unknown argument: " + argument); } @@ -250,6 +263,8 @@ public final class GraphSONTraversalSerializers { return Column.valueOf(node.get("value").textValue()); else if (type.equals("Direction")) return Direction.valueOf(node.get("value").textValue()); + else if (type.equals("Barrier")) + return SackFunctions.Barrier.valueOf(node.get("value").textValue()); else if (type.equals("Operator")) return Operator.valueOf(node.get("value").textValue()); else if (type.equals("Order")) @@ -287,9 +302,10 @@ public final class GraphSONTraversalSerializers { return predicate.textValue().equals("and") ? new AndP(arguments) : new OrP(arguments); } else { try { - return (P) P.class.getMethod(predicate.textValue(), Object.class).invoke(null, oc.readValue(node.get("value").traverse(oc), Object.class)); // TODO: number stuff, eh? - } catch (Exception e) { - throw new IOException(); + final Object argument = oc.readValue(node.get("value").traverse(oc), Object.class); + return (P) P.class.getMethod(predicate.textValue(), argument instanceof Collection ? Collection.class : Object.class).invoke(null, argument); // TODO: number stuff, eh? + } catch (final Exception e) { + throw new IOException(e.getMessage(), e); } } } http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c60e2132/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/java/translator/GraphSONTranslator.java ---------------------------------------------------------------------- diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/java/translator/GraphSONTranslator.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/java/translator/GraphSONTranslator.java new file mode 100644 index 0000000..729eadf --- /dev/null +++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/java/translator/GraphSONTranslator.java @@ -0,0 +1,83 @@ +/* + * 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.java.translator; + +import org.apache.tinkerpop.gremlin.process.traversal.Bytecode; +import org.apache.tinkerpop.gremlin.process.traversal.Translator; +import org.apache.tinkerpop.gremlin.process.traversal.Traversal; +import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource; +import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.VerificationException; +import org.apache.tinkerpop.gremlin.process.traversal.util.BytecodeHelper; +import org.apache.tinkerpop.gremlin.process.traversal.util.EmptyTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.util.JavaTranslator; +import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONReader; +import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONWriter; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.util.Arrays; + +/** + * @author Marko A. Rodriguez (http://markorodriguez.com) + */ +final class GraphSONTranslator<S extends TraversalSource, T extends Traversal.Admin<?, ?>> implements Translator.StepTranslator<S, T> { + + private final JavaTranslator<S, T> wrappedTranslator; + private final GraphSONWriter writer = GraphSONWriter.build().create(); + private final GraphSONReader reader = GraphSONReader.build().create(); + + public GraphSONTranslator(final JavaTranslator<S, T> wrappedTranslator) { + this.wrappedTranslator = wrappedTranslator; + } + + @Override + public S getTraversalSource() { + return this.wrappedTranslator.getTraversalSource(); + } + + @Override + public Class getAnonymousTraversal() { + return this.wrappedTranslator.getAnonymousTraversal(); + } + + @Override + public T translate(final Bytecode bytecode) { + try { + for (final Bytecode.Instruction instruction : bytecode.getStepInstructions()) { + for (final Object argument : instruction.getArguments()) { + if (argument.toString().contains("$")) + throw new VerificationException("Lambdas are currently not supported: " + bytecode, EmptyTraversal.instance()); + } + } + final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + this.writer.writeObject(outputStream, BytecodeHelper.filterInstructions(bytecode, + instruction -> !Arrays.asList("withTranslator", "withStrategies").contains(instruction.getOperator()))); + // System.out.println(new String(outputStream.toByteArray())); + return this.wrappedTranslator.translate(this.reader.readObject(new ByteArrayInputStream(outputStream.toByteArray()), Bytecode.class)); + } catch (final Exception e) { + throw new IllegalStateException(e.getMessage(), e); + } + } + + @Override + public String getTargetLanguage() { + return this.wrappedTranslator.getTargetLanguage(); + } +} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c60e2132/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/java/translator/TinkerGraphGraphSONTranslatorComputerProvider.java ---------------------------------------------------------------------- diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/java/translator/TinkerGraphGraphSONTranslatorComputerProvider.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/java/translator/TinkerGraphGraphSONTranslatorComputerProvider.java new file mode 100644 index 0000000..4dc67d9 --- /dev/null +++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/java/translator/TinkerGraphGraphSONTranslatorComputerProvider.java @@ -0,0 +1,37 @@ +/* + * 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.java.translator; + +import org.apache.tinkerpop.gremlin.GraphProvider; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.Graph; +import org.apache.tinkerpop.gremlin.tinkergraph.process.computer.TinkerGraphComputer; + +/** + * @author Marko A. Rodriguez (http://markorodriguez.com) + */ +@GraphProvider.Descriptor(computer = TinkerGraphComputer.class) +public class TinkerGraphGraphSONTranslatorComputerProvider extends TinkerGraphGraphSONTranslatorProvider { + + @Override + public GraphTraversalSource traversal(final Graph graph) { + return super.traversal(graph).withComputer(); + } +} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c60e2132/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/java/translator/TinkerGraphGraphSONTranslatorProcessComputerTest.java ---------------------------------------------------------------------- diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/java/translator/TinkerGraphGraphSONTranslatorProcessComputerTest.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/java/translator/TinkerGraphGraphSONTranslatorProcessComputerTest.java new file mode 100644 index 0000000..50523af --- /dev/null +++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/java/translator/TinkerGraphGraphSONTranslatorProcessComputerTest.java @@ -0,0 +1,33 @@ +/* + * 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.java.translator; + +import org.apache.tinkerpop.gremlin.GraphProviderClass; +import org.apache.tinkerpop.gremlin.process.ProcessComputerSuite; +import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph; +import org.junit.runner.RunWith; + +/** + * @author Marko A. Rodriguez (http://markorodriguez.com) + */ +@RunWith(ProcessComputerSuite.class) +@GraphProviderClass(provider = TinkerGraphGraphSONTranslatorComputerProvider.class, graph = TinkerGraph.class) +public class TinkerGraphGraphSONTranslatorProcessComputerTest { +} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c60e2132/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/java/translator/TinkerGraphGraphSONTranslatorProcessStandardTest.java ---------------------------------------------------------------------- diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/java/translator/TinkerGraphGraphSONTranslatorProcessStandardTest.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/java/translator/TinkerGraphGraphSONTranslatorProcessStandardTest.java new file mode 100644 index 0000000..db95be3 --- /dev/null +++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/java/translator/TinkerGraphGraphSONTranslatorProcessStandardTest.java @@ -0,0 +1,33 @@ +/* + * 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.java.translator; + +import org.apache.tinkerpop.gremlin.GraphProviderClass; +import org.apache.tinkerpop.gremlin.process.ProcessStandardSuite; +import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph; +import org.junit.runner.RunWith; + +/** + * @author Marko A. Rodriguez (http://markorodriguez.com) + */ +@RunWith(ProcessStandardSuite.class) +@GraphProviderClass(provider = TinkerGraphGraphSONTranslatorProvider.class, graph = TinkerGraph.class) +public class TinkerGraphGraphSONTranslatorProcessStandardTest { +} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c60e2132/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/java/translator/TinkerGraphGraphSONTranslatorProvider.java ---------------------------------------------------------------------- diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/java/translator/TinkerGraphGraphSONTranslatorProvider.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/java/translator/TinkerGraphGraphSONTranslatorProvider.java new file mode 100644 index 0000000..85d8b0e --- /dev/null +++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/java/translator/TinkerGraphGraphSONTranslatorProvider.java @@ -0,0 +1,93 @@ +/* + * 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.java.translator; + +import org.apache.tinkerpop.gremlin.LoadGraphWith; +import org.apache.tinkerpop.gremlin.process.traversal.CoreTraversalTest; +import org.apache.tinkerpop.gremlin.process.traversal.TraversalInterruptionComputerTest; +import org.apache.tinkerpop.gremlin.process.traversal.TraversalInterruptionTest; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__; +import org.apache.tinkerpop.gremlin.process.traversal.step.map.PageRankTest; +import org.apache.tinkerpop.gremlin.process.traversal.step.map.ProgramTest; +import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.ElementIdStrategyProcessTest; +import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.EventStrategyProcessTest; +import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.PartitionStrategyProcessTest; +import org.apache.tinkerpop.gremlin.process.traversal.util.JavaTranslator; +import org.apache.tinkerpop.gremlin.structure.Graph; +import org.apache.tinkerpop.gremlin.tinkergraph.TinkerGraphProvider; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * @author Marko A. Rodriguez (http://markorodriguez.com) + */ +public class TinkerGraphGraphSONTranslatorProvider extends TinkerGraphProvider { + + private static Set<String> SKIP_TESTS = new HashSet<>(Arrays.asList( + "testProfileStrategyCallback", + "testProfileStrategyCallbackSideEffect", + "g_withSideEffectXa_setX_V_both_name_storeXaX_capXaX", + "g_V_both_hasLabelXpersonX_order_byXage_decrX_name", + "g_VX1X_out_injectXv2X_name", + "shouldNeverPropagateANoBulkTraverser", + "shouldNeverPropagateANullValuedTraverser", + "shouldTraversalResetProperly", + "shouldHidePartitionKeyForValues", + // + "g_VXlistXv1_v2_v3XX_name", + "g_V_hasLabelXpersonX_asXpX_VXsoftwareX_addInEXuses_pX", + "g_VXv1X_hasXage_gt_30X", + "g_V_chooseXout_countX_optionX2L__nameX_optionX3L__valueMapX", + "g_V_branchXlabelX_optionXperson__ageX_optionXsoftware__langX_optionXsoftware__nameX", + // + PageRankTest.Traversals.class.getCanonicalName(), + ProgramTest.Traversals.class.getCanonicalName(), + TraversalInterruptionTest.class.getCanonicalName(), + TraversalInterruptionComputerTest.class.getCanonicalName(), + EventStrategyProcessTest.class.getCanonicalName(), + CoreTraversalTest.class.getCanonicalName(), + PartitionStrategyProcessTest.class.getCanonicalName(), + ElementIdStrategyProcessTest.class.getCanonicalName())); + + + @Override + public Map<String, Object> getBaseConfiguration(final String graphName, final Class<?> test, final String testMethodName, + final LoadGraphWith.GraphData loadGraphWith) { + + final Map<String, Object> config = super.getBaseConfiguration(graphName, test, testMethodName, loadGraphWith); + config.put("skipTest", SKIP_TESTS.contains(testMethodName) || SKIP_TESTS.contains(test.getCanonicalName())); + return config; + } + + @Override + public GraphTraversalSource traversal(final Graph graph) { + if ((Boolean) graph.configuration().getProperty("skipTest")) + return graph.traversal(); + //throw new VerificationException("This test current does not work with Gremlin-Python", EmptyTraversal.instance()); + else { + final GraphTraversalSource g = graph.traversal(); + return g.withTranslator(new GraphSONTranslator<>(JavaTranslator.of(g, __.class))); + } + } +} \ No newline at end of file