http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/aa828940/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GroovySackTest.groovy ---------------------------------------------------------------------- diff --git a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GroovySackTest.groovy b/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GroovySackTest.groovy deleted file mode 100644 index a478f6f..0000000 --- a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GroovySackTest.groovy +++ /dev/null @@ -1,84 +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.sideEffect - -import org.apache.tinkerpop.gremlin.process.traversal.Traversal -import org.apache.tinkerpop.gremlin.process.traversal.util.ScriptTraversal -import org.apache.tinkerpop.gremlin.structure.Vertex - -/** - * @author Marko A. Rodriguez (http://markorodriguez.com) - */ -public abstract class GroovySackTest { - - public static class Traversals extends SackTest { - - @Override - public Traversal<Vertex, String> get_g_withSackXhelloX_V_outE_sackXassignX_byXlabelX_inV_sack() { - new ScriptTraversal<>(g, "gremlin-groovy", "g.withSack('hello').V.outE.sack(assign).by(label).inV.sack") - } - - @Override - public Traversal<Vertex, Double> get_g_withSackX0X_V_outE_sackXsumX_byXweightX_inV_sack_sum() { - new ScriptTraversal<>(g, "gremlin-groovy", "g.withSack(0.0d).V.outE.sack(sum).by('weight').inV.sack.sum()") - } - - @Override - public Traversal<Vertex, Double> get_g_withSackX0X_V_repeatXoutE_sackXsumX_byXweightX_inVX_timesX2X_sack() { - new ScriptTraversal<>(g, "gremlin-groovy", "g.withSack(0.0d).V.repeat(__.outE.sack(sum).by('weight').inV).times(2).sack()") - } - - @Override - public Traversal<Vertex, Double> get_g_withSackX0X_V_outE_sackXsum_weightX_inV_sack_sum() { - new ScriptTraversal<>(g, "gremlin-groovy", "g.withSack(0.0d).V().outE.sack(sum, 'weight').inV.sack.sum()") - } - - @Override - public Traversal<Vertex, Double> get_g_withSackX0X_V_repeatXoutE_sackXsum_weightX_inVX_timesX2X_sack() { - new ScriptTraversal<>(g, "gremlin-groovy", "g.withSack(0.0d).V.repeat(__.outE.sack(sum, 'weight').inV).times(2).sack") - } - - @Override - public Traversal<Vertex, Map> get_g_withSackXmap__map_cloneX_V_out_out_sackXmap_a_nameX_sack() { - new ScriptTraversal<>(g, "gremlin-groovy", "g.withSack{[:]}{ it.clone() }.V.out().out().sack { m, v -> m['a'] = v.name; m }.sack()") - } - - @Override - public Traversal<Vertex, Double> get_g_withSackX1_sumX_VX1X_localXoutXknowsX_barrierXnormSackXX_inXknowsX_barrier_sack( - final Object v1Id) { - new ScriptTraversal<>(g, "gremlin-groovy", "g.withSack(1.0d,sum).V(v1Id).local(out('knows').barrier(normSack)).in('knows').barrier.sack", "v1Id", v1Id) - } - - @Override - public Traversal<Vertex, Integer> get_g_withBulkXfalseX_withSackX1_sumX_V_out_barrier_sack() { - new ScriptTraversal<>(g, "gremlin-groovy", "g.withBulk(false).withSack(1, sum).V.out.barrier.sack") - } - - @Override - public Traversal<Vertex, Double> get_g_withBulkXfalseX_withSackX1_sumX_VX1X_localXoutEXknowsX_barrierXnormSackX_inVX_inXknowsX_barrier_sack( - final Object v1Id) { - new ScriptTraversal<>(g, "gremlin-groovy", "g.withBulk(false).withSack(1.0d, sum).V(v1Id).local(outE('knows').barrier(normSack).inV).in('knows').barrier.sack", "v1Id", v1Id) - } - - @Override - Traversal<Vertex, BigDecimal> get_g_withSackXBigInteger_TEN_powX1000X_assignX_V_localXoutXknowsX_barrierXnormSackXX_inXknowsX_barrier_sack() { - new ScriptTraversal<>(g, "gremlin-groovy", "g.withSack(BigInteger.TEN.pow(1000), assign).V.local(out('knows').barrier(normSack)).in('knows').barrier.sack") - } - } -}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/aa828940/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GroovySideEffectCapTest.groovy ---------------------------------------------------------------------- diff --git a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GroovySideEffectCapTest.groovy b/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GroovySideEffectCapTest.groovy deleted file mode 100644 index ea69e2f..0000000 --- a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GroovySideEffectCapTest.groovy +++ /dev/null @@ -1,45 +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.sideEffect - -import org.apache.tinkerpop.gremlin.process.traversal.Traversal -import org.apache.tinkerpop.gremlin.process.traversal.util.ScriptTraversal -import org.apache.tinkerpop.gremlin.structure.Vertex - -/** - * @author Marko A. Rodriguez (http://markorodriguez.com) - */ -public abstract class GroovySideEffectCapTest { - - public static class Traversals extends SideEffectCapTest { - @Override - public Traversal<Vertex, Map<String, Long>> get_g_V_hasXageX_groupCountXaX_byXnameX_out_capXaX() { - new ScriptTraversal<>(g, "gremlin-groovy", "g.V.has('age').groupCount('a').by('name').out.cap('a')") - } - - @Override - public Traversal<Vertex, Map<String, Map<Object, Long>>> get_g_V_chooseXlabel_person__age_groupCountXaX__name_groupCountXbXX_capXa_bX() { - new ScriptTraversal<>(g, "gremlin-groovy", """ - g.V.choose(__.has(T.label, 'person'), - __.age.groupCount('a'), - __.values("name").groupCount('b')).cap('a', 'b') - """) - } - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/aa828940/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GroovySideEffectTest.groovy ---------------------------------------------------------------------- diff --git a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GroovySideEffectTest.groovy b/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GroovySideEffectTest.groovy deleted file mode 100644 index 03e1590..0000000 --- a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GroovySideEffectTest.groovy +++ /dev/null @@ -1,83 +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.sideEffect - -import org.apache.tinkerpop.gremlin.process.traversal.Traversal -import org.apache.tinkerpop.gremlin.process.traversal.util.ScriptTraversal -import org.apache.tinkerpop.gremlin.structure.Vertex - -/** - * @author Marko A. Rodriguez (http://markorodriguez.com) - */ -public abstract class GroovySideEffectTest { - - public static class Traversals extends SideEffectTest { - - @Override - public Traversal<Vertex, String> get_g_VX1X_sideEffectXstore_aX_name(final Object v1Id) { - new ScriptTraversal<>(g, "gremlin-groovy", """g.withSideEffect('a') { [] }.V(v1Id).sideEffect { - it.sideEffects('a').clear(); - it.sideEffects('a').add(it.get()); - }.name""", "v1Id", v1Id) - } - - @Override - public Traversal<Vertex, String> get_g_VX1X_out_sideEffectXincr_cX_name(final Object v1Id) { - new ScriptTraversal<>(g, "gremlin-groovy", """g.withSideEffect('c') { [0] }.V(v1Id).out.sideEffect { - temp = it.sideEffects('c')[0]; - it.sideEffects('c').clear(); - it.sideEffects('c').add(temp + 1); - }.name""", "v1Id", v1Id) - } - - @Override - public Traversal<Vertex, String> get_g_VX1X_out_sideEffectXX_name(final Object v1Id) { - new ScriptTraversal<>(g, "gremlin-groovy", "g.V(v1Id).out().sideEffect {}.name", "v1Id", v1Id) - } - - @Override - public Traversal<Vertex, Map<String, Long>> get_g_withSideEffectXa__linkedhashmapX_V_out_groupCountXaX_byXlabelX_out_out_capXaX() { - new ScriptTraversal<>(g, "gremlin-groovy", "g.withSideEffect('a'){[:] as LinkedHashMap}.V.out.groupCount('a').by(label).out.out.cap('a')"); - } - - @Override - public Traversal<Vertex, Map<String, Long>> get_g_withSideEffectsXa__linkedhashmapX_withSideEffectXb__arraylist__addAllX_withSideEffectXc__arrayList__addAllX_V_groupXaX_byXlabelX_byXcountX_sideEffectXb__1_2_3X_out_out_out_sideEffectXc__bob_danielX_capXaX() { - new ScriptTraversal<>(g, "gremlin-groovy", """ - g.withSideEffect('a'){[:] as LinkedHashMap} - .withSideEffect('b',{[:] as ArrayList},addAll) - .withSideEffect('c',{[:] as ArrayList},addAll) - .V.group('a').by(label).by(count()) - .sideEffect{it.sideEffects('b', [1,2,3] as LinkedList)} - .out.out.out - .sideEffect{it.sideEffect('c',['bob','daniel'] as LinkedList)} - .cap('a'); - """); - } - - @Override - public Traversal<Vertex, Integer> get_g_withSideEffectXa_0_sumX_V_out_sideEffectXsideEffectsXa_bulkXX_capXaX() { - new ScriptTraversal<>(g, "gremlin-groovy", "g.withSideEffect('a', 0, sum).V.out.sideEffect{it.sideEffects('a', it.bulk() as int)}.cap('a')") - } - - @Override - public Traversal<Vertex, Integer> get_g_withSideEffectXa_0X_V_out_sideEffectXsideEffectsXa_1XX_capXaX() { - new ScriptTraversal<>(g, "gremlin-groovy", "g.withSideEffect('a', 0).V.out.sideEffect{it.sideEffects('a', 1)}.cap('a')") - } - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/aa828940/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GroovyStoreTest.groovy ---------------------------------------------------------------------- diff --git a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GroovyStoreTest.groovy b/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GroovyStoreTest.groovy deleted file mode 100644 index 5a24f07..0000000 --- a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GroovyStoreTest.groovy +++ /dev/null @@ -1,53 +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.sideEffect - -import org.apache.tinkerpop.gremlin.process.traversal.Traversal -import org.apache.tinkerpop.gremlin.process.traversal.util.ScriptTraversal -import org.apache.tinkerpop.gremlin.structure.Vertex - -/** - * @author Marko A. Rodriguez (http://markorodriguez.com) - */ -public abstract class GroovyStoreTest { - - public static class Traversals extends StoreTest { - - @Override - public Traversal<Vertex, Collection> get_g_V_storeXaX_byXnameX_out_capXaX() { - new ScriptTraversal<>(g, "gremlin-groovy", "g.V().store('a').by('name').out().cap('a')") - } - - @Override - public Traversal<Vertex, Collection> get_g_VX1X_storeXaX_byXnameX_out_storeXaX_byXnameX_name_capXaX( - final Object v1Id) { - new ScriptTraversal<>(g, "gremlin-groovy", "g.V(v1Id).store('a').by('name').out().store('a').by('name').name.cap('a')", "v1Id", v1Id) - } - - @Override - public Traversal<Vertex, Set<String>> get_g_withSideEffectXa_setX_V_both_name_storeXaX_capXaX() { - new ScriptTraversal<>(g, "gremlin-groovy", "g.withSideEffect('a'){[] as Set}.V.both.name.store('a').cap('a')"); - } - - @Override - public Traversal<Vertex, Collection> get_g_V_storeXaX_byXoutEXcreatedX_countX_out_out_storeXaX_byXinEXcreatedX_weight_sumX_capXaX() { - new ScriptTraversal<>(g, "gremlin-groovy", "g.V.store('a').by(__.outE('created').count).out.out.store('a').by(__.inE('created').weight.sum).cap('a')"); - } - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/aa828940/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GroovySubgraphTest.groovy ---------------------------------------------------------------------- diff --git a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GroovySubgraphTest.groovy b/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GroovySubgraphTest.groovy deleted file mode 100644 index 7e3765a..0000000 --- a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GroovySubgraphTest.groovy +++ /dev/null @@ -1,50 +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.sideEffect - -import org.apache.tinkerpop.gremlin.process.traversal.Traversal -import org.apache.tinkerpop.gremlin.process.traversal.util.ScriptTraversal -import org.apache.tinkerpop.gremlin.structure.Graph -import org.apache.tinkerpop.gremlin.structure.Vertex - -/** - * @author Marko A. Rodriguez (http://markorodriguez.com) - */ -public abstract class GroovySubgraphTest { - - public static class Traversals extends SubgraphTest { - - @Override - public Traversal<Vertex, Graph> get_g_V_withSideEffectXsgX_outEXknowsX_subgraphXsgX_name_capXsgX( - final Object v1Id, final Graph subgraph) { - new ScriptTraversal<>(g, "gremlin-groovy", "g.withSideEffect('sg') { subgraph }.V(v1Id).outE('knows').subgraph('sg').name.cap('sg')", "v1Id", v1Id, "subgraph", subgraph) - } - - @Override - public Traversal<Vertex, String> get_g_V_withSideEffectXsgX_repeatXbothEXcreatedX_subgraphXsgX_outVX_timesX5X_name_dedup( - final Graph subgraph) { - new ScriptTraversal<>(g, "gremlin-groovy", "g.withSideEffect('sg') { subgraph }.V.repeat(__.bothE('created').subgraph('sg').outV).times(5).name.dedup", "subgraph", subgraph) - } - - @Override - public Traversal<Vertex, Vertex> get_g_withSideEffectXsgX_V_hasXname_danielX_outE_subgraphXsgX_inV(final Graph subgraph) { - new ScriptTraversal<>(g, "gremlin-groovy", "g.withSideEffect('sg') { subgraph }.V.has('name','daniel').outE.subgraph('sg').inV", "subgraph", subgraph) - } - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/aa828940/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GroovyTreeTest.groovy ---------------------------------------------------------------------- diff --git a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GroovyTreeTest.groovy b/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GroovyTreeTest.groovy deleted file mode 100644 index f1a6f83..0000000 --- a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GroovyTreeTest.groovy +++ /dev/null @@ -1,69 +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.sideEffect - -import org.apache.tinkerpop.gremlin.process.traversal.Traversal -import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree -import org.apache.tinkerpop.gremlin.process.traversal.util.ScriptTraversal -import org.apache.tinkerpop.gremlin.structure.Vertex - -/** - * @author Marko A. Rodriguez (http://markorodriguez.com) - */ -public abstract class GroovyTreeTest { - - public static class Traversals extends TreeTest { - - @Override - public Traversal<Vertex, Tree> get_g_V_out_out_tree_byXidX() { - new ScriptTraversal<>(g, "gremlin-groovy", "g.V.out.out.tree.by(id)") - } - - @Override - public Traversal<Vertex, Tree> get_g_V_out_out_treeXaX_byXidX_capXaX() { - new ScriptTraversal<>(g, "gremlin-groovy", "g.V.out.out.tree('a').by(id).cap('a')") - } - - @Override - public Traversal<Vertex, Tree> get_g_V_out_out_tree() { - new ScriptTraversal<>(g, "gremlin-groovy", "g.V.out.out.tree()") - } - - @Override - public Traversal<Vertex, Tree> get_g_V_out_out_treeXaX_capXaX() { - new ScriptTraversal<>(g, "gremlin-groovy", "g.V.out.out.tree('a').cap('a')") - } - - @Override - public Traversal<Vertex, Tree> get_g_VX1X_out_out_treeXaX_byXnameX_both_both_capXaX(final Object v1Id) { - new ScriptTraversal<>(g, "gremlin-groovy", "g.V(v1Id).out.out.tree('a').by('name').both.both.cap('a')", "v1Id", v1Id) - } - - @Override - public Traversal<Vertex, Tree> get_g_VX1X_out_out_tree_byXnameX(final Object v1Id) { - new ScriptTraversal<>(g, "gremlin-groovy", "g.V(v1Id).out.out.tree.by('name')", "v1Id", v1Id) - } - - @Override - public Traversal<Vertex, Tree> get_g_V_out_out_out_tree() { - new ScriptTraversal<>(g, "gremlin-groovy", "g.V.out.out.out.tree") - } - - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/aa828940/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/GroovyEnvironmentIntegrateSuite.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/GroovyEnvironmentIntegrateSuite.java b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/GroovyEnvironmentIntegrateSuite.java deleted file mode 100644 index ecd481f..0000000 --- a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/GroovyEnvironmentIntegrateSuite.java +++ /dev/null @@ -1,85 +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.groovy; - -import org.apache.tinkerpop.gremlin.AbstractGremlinSuite; -import org.apache.tinkerpop.gremlin.AbstractGremlinTest; -import org.apache.tinkerpop.gremlin.GraphManager; -import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngineIntegrateTest; -import org.apache.tinkerpop.gremlin.groovy.loaders.SugarLoader; -import org.apache.tinkerpop.gremlin.groovy.util.SugarTestHelper; -import org.apache.tinkerpop.gremlin.process.traversal.TraversalEngine; -import org.apache.tinkerpop.gremlin.structure.Graph; -import org.apache.tinkerpop.gremlin.structure.StructureStandardSuite; -import org.junit.runners.model.InitializationError; -import org.junit.runners.model.RunnerBuilder; - -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -/** - * The {@code GroovyEnvironmentIntegrateSuite} is a JUnit test runner that executes the Gremlin Test Suite over a - * {@link Graph} implementation. This test suite covers ensures that a vendor implementation is compliant with - * the Groovy "environment" which will typically ensure that the {@link Graph} will work as expected in the Gremlin - * Console, Gremlin Server, and other Groovy environments. - * <p/> - * Note that this suite contains "long-run" tests. At this time, this suite can be considered optional to providers. - * <p/> - * For more information on the usage of this suite, please see {@link StructureStandardSuite}. - * - * @author Stephen Mallette (http://stephen.genoprime.com) - * @deprecated As of release 3.2.4, not replaced as a test suite that Graph Providers need to implement. - */ -@Deprecated -public class GroovyEnvironmentIntegrateSuite extends AbstractGremlinSuite { - - /** - * This list of tests in the suite that will be executed. Gremlin developers should add to this list - * as needed to enforce tests upon implementations. - */ - private static final Class<?>[] allTests = new Class<?>[]{ - GremlinGroovyScriptEngineIntegrateTest.class - }; - - public GroovyEnvironmentIntegrateSuite(final Class<?> klass, final RunnerBuilder builder) throws InitializationError { - super(klass, builder, allTests, null, false, TraversalEngine.Type.STANDARD); - } - - @Override - public boolean beforeTestExecution(final Class<? extends AbstractGremlinTest> testClass) { - unloadSugar(); - SugarLoader.load(); - return true; - } - - @Override - public void afterTestExecution(final Class<? extends AbstractGremlinTest> testClass) { - unloadSugar(); - } - - private void unloadSugar() { - try { - SugarTestHelper.clearRegistry(GraphManager.getGraphProvider()); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/aa828940/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/GroovyEnvironmentSuite.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/GroovyEnvironmentSuite.java b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/GroovyEnvironmentSuite.java deleted file mode 100644 index 7fda6f9..0000000 --- a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/GroovyEnvironmentSuite.java +++ /dev/null @@ -1,92 +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.groovy; - -import org.apache.tinkerpop.gremlin.AbstractGremlinSuite; -import org.apache.tinkerpop.gremlin.AbstractGremlinTest; -import org.apache.tinkerpop.gremlin.GraphManager; -import org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutorOverGraphTest; -import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngineFileSandboxTest; -import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngineOverGraphTest; -import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngineSandboxedStandardTest; -import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngineTinkerPopSandboxTest; -import org.apache.tinkerpop.gremlin.groovy.jsr223.GroovyTranslatorTest; -import org.apache.tinkerpop.gremlin.groovy.loaders.SugarLoader; -import org.apache.tinkerpop.gremlin.groovy.loaders.SugarLoaderTest; -import org.apache.tinkerpop.gremlin.groovy.plugin.dsl.credential.CredentialGraphTest; -import org.apache.tinkerpop.gremlin.groovy.util.SugarTestHelper; -import org.apache.tinkerpop.gremlin.process.traversal.TraversalEngine; -import org.apache.tinkerpop.gremlin.structure.Graph; -import org.apache.tinkerpop.gremlin.structure.StructureStandardSuite; -import org.junit.runners.model.InitializationError; -import org.junit.runners.model.RunnerBuilder; - -/** - * The {@code GroovyEnvironmentSuite} is a JUnit test runner that executes the Gremlin Test Suite over a - * {@link Graph} implementation. This test suite covers ensures that a vendor implementation is compliant with - * the Groovy "environment" which will typically ensure that the {@link Graph} will work as expected in the Gremlin - * Console, Gremlin Server, and other Groovy environments. - * <p/> - * For more information on the usage of this suite, please see {@link StructureStandardSuite}. - * - * @author Stephen Mallette (http://stephen.genoprime.com) - * @deprecated As of release 3.2.4, not replaced as a test suite that Graph Providers need to implement. - */ -@Deprecated -public class GroovyEnvironmentSuite extends AbstractGremlinSuite { - - /** - * This list of tests in the suite that will be executed. Gremlin developers should add to this list - * as needed to enforce tests upon implementations. - */ - private static final Class<?>[] allTests = new Class<?>[]{ - CredentialGraphTest.class, - GremlinGroovyScriptEngineOverGraphTest.class, - GremlinGroovyScriptEngineSandboxedStandardTest.class, - GremlinGroovyScriptEngineTinkerPopSandboxTest.class, - GremlinGroovyScriptEngineFileSandboxTest.class, - GremlinExecutorOverGraphTest.class, - GroovyTranslatorTest.class, - SugarLoaderTest.class, - }; - - public GroovyEnvironmentSuite(final Class<?> klass, final RunnerBuilder builder) throws InitializationError { - super(klass, builder, allTests, null, false, TraversalEngine.Type.STANDARD); - } - - @Override - public boolean beforeTestExecution(final Class<? extends AbstractGremlinTest> testClass) { - unloadSugar(); - SugarLoader.load(); - return true; - } - - @Override - public void afterTestExecution(final Class<? extends AbstractGremlinTest> testClass) { - unloadSugar(); - } - - private void unloadSugar() { - try { - SugarTestHelper.clearRegistry(GraphManager.getGraphProvider()); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/aa828940/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorOverGraphTest.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorOverGraphTest.java b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorOverGraphTest.java deleted file mode 100644 index ca700a5..0000000 --- a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorOverGraphTest.java +++ /dev/null @@ -1,108 +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.groovy.engine; - -import org.apache.commons.lang3.concurrent.BasicThreadFactory; -import org.apache.tinkerpop.gremlin.AbstractGremlinTest; -import org.apache.tinkerpop.gremlin.LoadGraphWith; -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; -import org.apache.tinkerpop.gremlin.structure.Graph; -import org.junit.Test; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; - -import static org.junit.Assert.assertEquals; - -/** - * @author Stephen Mallette (http://stephen.genoprime.com) - */ -public class GremlinExecutorOverGraphTest extends AbstractGremlinTest { - private final BasicThreadFactory testingThreadFactory = new BasicThreadFactory.Builder().namingPattern("test-gremlin-executor-%d").build(); - - @Test - @LoadGraphWith(LoadGraphWith.GraphData.MODERN) - public void shouldAllowTraversalToIterateInDifferentThreadThanOriginallyEvaluatedWithAutoCommit() throws Exception { - // this test sort of simulates Gremlin Server interaction where a Traversal is eval'd in one Thread, but - // then iterated in another. note that Gremlin Server configures the script engine to auto-commit - // after evaluation. this basically tests the state of the Gremlin Server GremlinExecutor when - // being used in sessionless mode - final ExecutorService evalExecutor = Executors.newSingleThreadExecutor(testingThreadFactory); - final GremlinExecutor gremlinExecutor = GremlinExecutor.build() - .afterSuccess(b -> { - final GraphTraversalSource g = (GraphTraversalSource) b.get("g"); - if (g.getGraph().features().graph().supportsTransactions()) - g.tx().commit(); - }) - .executorService(evalExecutor).create(); - - final Map<String,Object> bindings = new HashMap<>(); - bindings.put("g", g); - - final AtomicInteger vertexCount = new AtomicInteger(0); - - final ExecutorService iterationExecutor = Executors.newSingleThreadExecutor(testingThreadFactory); - gremlinExecutor.eval("g.V().out()", bindings).thenAcceptAsync(o -> { - final Iterator itty = (Iterator) o; - itty.forEachRemaining(v -> vertexCount.incrementAndGet()); - }, iterationExecutor).join(); - - assertEquals(6, vertexCount.get()); - - gremlinExecutor.close(); - evalExecutor.shutdown(); - evalExecutor.awaitTermination(30000, TimeUnit.MILLISECONDS); - iterationExecutor.shutdown(); - iterationExecutor.awaitTermination(30000, TimeUnit.MILLISECONDS); - } - - @Test - @LoadGraphWith(LoadGraphWith.GraphData.MODERN) - public void shouldAllowTraversalToIterateInDifferentThreadThanOriginallyEvaluatedWithoutAutoCommit() throws Exception { - // this test sort of simulates Gremlin Server interaction where a Traversal is eval'd in one Thread, but - // then iterated in another. this basically tests the state of the Gremlin Server GremlinExecutor when - // being used in session mode - final ExecutorService evalExecutor = Executors.newSingleThreadExecutor(testingThreadFactory); - final GremlinExecutor gremlinExecutor = GremlinExecutor.build().executorService(evalExecutor).create(); - - final Map<String,Object> bindings = new HashMap<>(); - bindings.put("g", g); - - final AtomicInteger vertexCount = new AtomicInteger(0); - - final ExecutorService iterationExecutor = Executors.newSingleThreadExecutor(testingThreadFactory); - gremlinExecutor.eval("g.V().out()", bindings).thenAcceptAsync(o -> { - final Iterator itty = (Iterator) o; - itty.forEachRemaining(v -> vertexCount.incrementAndGet()); - }, iterationExecutor).join(); - - assertEquals(6, vertexCount.get()); - - gremlinExecutor.close(); - evalExecutor.shutdown(); - evalExecutor.awaitTermination(30000, TimeUnit.MILLISECONDS); - iterationExecutor.shutdown(); - iterationExecutor.awaitTermination(30000, TimeUnit.MILLISECONDS); - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/aa828940/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineFileSandboxTest.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineFileSandboxTest.java b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineFileSandboxTest.java deleted file mode 100644 index 3ee1306..0000000 --- a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineFileSandboxTest.java +++ /dev/null @@ -1,120 +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.groovy.jsr223; - -import org.apache.tinkerpop.gremlin.AbstractGremlinTest; -import org.apache.tinkerpop.gremlin.LoadGraphWith; -import org.apache.tinkerpop.gremlin.TestHelper; -import org.apache.tinkerpop.gremlin.groovy.CompilerCustomizerProvider; -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.CompileStaticCustomizerProvider; -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.FileSandboxExtension; -import org.codehaus.groovy.control.MultipleCompilationErrorsException; -import org.hamcrest.MatcherAssert; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; - -import javax.script.Bindings; - -import java.io.File; -import java.util.Arrays; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.greaterThan; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; - -/** - * @author Stephen Mallette (http://stephen.genoprime.com) - */ -public class GremlinGroovyScriptEngineFileSandboxTest extends AbstractGremlinTest { - @Before - public void setup() throws Exception { - super.setup(); - if (System.getProperty(FileSandboxExtension.GREMLIN_SERVER_SANDBOX) == null) { - final File f = TestHelper.generateTempFileFromResource(graph.getClass(), GremlinGroovyScriptEngineFileSandboxTest.class, "sandbox.yaml", ".yaml"); - System.setProperty(FileSandboxExtension.GREMLIN_SERVER_SANDBOX, f.getAbsolutePath()); - } - } - - @AfterClass - public static void destroy() { - System.clearProperty(FileSandboxExtension.GREMLIN_SERVER_SANDBOX); - } - - @Test - public void shouldEvalAsTheMethodIsWhiteListed() throws Exception { - final CompilerCustomizerProvider standardSandbox = new CompileStaticCustomizerProvider(FileSandboxExtension.class.getName()); - try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(standardSandbox)) { - assertEquals(123, engine.eval("java.lang.Math.abs(-123)")); - assertThat(engine.eval("new Boolean(true)"), is(true)); - assertThat(engine.eval("new Boolean(true).toString()"), is("true")); - } - } - - @Test - public void shouldEvalAsGroovyPropertiesWhenWhiteListed() throws Exception { - final CompilerCustomizerProvider standardSandbox = new CompileStaticCustomizerProvider(FileSandboxExtension.class.getName()); - try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(standardSandbox)) { - assertThat(Arrays.equals("test".getBytes(), (byte[]) engine.eval("'test'.bytes")), is(true)); - } - } - - @Test - public void shouldPreventMaliciousStuffWithSystemButAllowSomeMethodsOnSystem() throws Exception { - final CompilerCustomizerProvider standardSandbox = new CompileStaticCustomizerProvider(FileSandboxExtension.class.getName()); - try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(standardSandbox)) { - assertThat((long) engine.eval("System.currentTimeMillis()"), greaterThan(0l)); - assertThat((long) engine.eval("System.nanoTime()"), greaterThan(0l)); - - engine.eval("System.exit(0)"); - fail("Should have a compile error because class/method is not white listed"); - } catch (Exception ex) { - assertEquals(MultipleCompilationErrorsException.class, ex.getCause().getClass()); - assertThat(ex.getCause().getMessage(), containsString("Not authorized to call this method")); - } - } - - @Test - public void shouldPreventMaliciousStuffWithFile() throws Exception { - final CompilerCustomizerProvider standardSandbox = new CompileStaticCustomizerProvider(FileSandboxExtension.class.getName()); - try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(standardSandbox)) { - engine.eval("java.nio.file.FileSystems.getDefault()"); - fail("Should have a compile error because class/method is not white listed"); - } catch (Exception ex) { - assertEquals(MultipleCompilationErrorsException.class, ex.getCause().getClass()); - assertThat(ex.getCause().getMessage(), containsString("Not authorized to call this method")); - } - } - - @Test - @LoadGraphWith(LoadGraphWith.GraphData.MODERN) - public void shouldEvalOnGAsTheMethodIsWhiteListed() throws Exception { - final CompilerCustomizerProvider standardSandbox = new CompileStaticCustomizerProvider(FileSandboxExtension.class.getName()); - try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(standardSandbox)) { - final Bindings bindings = engine.createBindings(); - bindings.put("g", g); - bindings.put("marko", convertToVertexId("marko")); - assertEquals(g.V(convertToVertexId("marko")).next(), engine.eval("g.V(marko).next()", bindings)); - assertEquals(g.V(convertToVertexId("marko")).out("created").count().next(), engine.eval("g.V(marko).out(\"created\").count().next()", bindings)); - } - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/aa828940/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineIntegrateTest.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineIntegrateTest.java b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineIntegrateTest.java deleted file mode 100644 index 1cb73fc..0000000 --- a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineIntegrateTest.java +++ /dev/null @@ -1,88 +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.groovy.jsr223; - -import org.apache.tinkerpop.gremlin.AbstractGremlinTest; -import org.apache.tinkerpop.gremlin.LoadGraphWith; -import org.apache.tinkerpop.gremlin.structure.Vertex; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.script.Bindings; -import javax.script.ScriptException; - -import static org.apache.tinkerpop.gremlin.LoadGraphWith.GraphData.MODERN; -import static org.junit.Assert.fail; - -/** - * @author Stephen Mallette (http://stephen.genoprime.com) - */ -public class GremlinGroovyScriptEngineIntegrateTest extends AbstractGremlinTest { - private static final Logger logger = LoggerFactory.getLogger(GremlinGroovyScriptEngineIntegrateTest.class); - - @Test - @LoadGraphWith(MODERN) - public void shouldNotBlowTheHeapParameterized() throws ScriptException { - final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(); - - final String[] gremlins = new String[]{ - "g.V(xxx).out().toList()", - "g.V(xxx).in().toList()", - "g.V(xxx).out().out().out().toList()", - "g.V(xxx).out().groupCount()" - }; - - long parameterizedStartTime = System.currentTimeMillis(); - logger.info("Try to blow the heap with parameterized Gremlin."); - try { - for (int ix = 0; ix < 50001; ix++) { - final Bindings bindings = engine.createBindings(); - bindings.put("g", g); - bindings.put("xxx", graphProvider.convertId((ix % 4) + 1, Vertex.class)); - engine.eval(gremlins[ix % 4], bindings); - - if (ix > 0 && ix % 5000 == 0) { - logger.info(String.format("%s scripts processed in %s (ms) - rate %s (ms/q).", ix, System.currentTimeMillis() - parameterizedStartTime, Double.valueOf(System.currentTimeMillis() - parameterizedStartTime) / Double.valueOf(ix))); - } - } - } catch (OutOfMemoryError oome) { - fail("Blew the heap - the cache should prevent this from happening."); - } - } - - @Test - public void shouldNotBlowTheHeapUnparameterized() throws ScriptException { - final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(); - long notParameterizedStartTime = System.currentTimeMillis(); - logger.info("Try to blow the heap with non-parameterized Gremlin."); - try { - for (int ix = 0; ix < 15001; ix++) { - final Bindings bindings = engine.createBindings(); - engine.eval(String.format("1+%s", ix), bindings); - if (ix > 0 && ix % 5000 == 0) { - logger.info(String.format("%s scripts processed in %s (ms) - rate %s (ms/q).", ix, System.currentTimeMillis() - notParameterizedStartTime, Double.valueOf(System.currentTimeMillis() - notParameterizedStartTime) / Double.valueOf(ix))); - } - } - } catch (OutOfMemoryError oome) { - fail("Blew the heap - the cache should prevent this from happening."); - } - } - -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/aa828940/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineOverGraphTest.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineOverGraphTest.java b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineOverGraphTest.java deleted file mode 100644 index 17e1cf0..0000000 --- a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineOverGraphTest.java +++ /dev/null @@ -1,379 +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.groovy.jsr223; - -import groovy.lang.MissingPropertyException; -import org.apache.commons.lang.exception.ExceptionUtils; -import org.apache.tinkerpop.gremlin.AbstractGremlinTest; -import org.apache.tinkerpop.gremlin.FeatureRequirementSet; -import org.apache.tinkerpop.gremlin.LoadGraphWith; -import org.apache.tinkerpop.gremlin.groovy.CompilerCustomizerProvider; -import org.apache.tinkerpop.gremlin.groovy.DefaultImportCustomizerProvider; -import org.apache.tinkerpop.gremlin.groovy.NoImportCustomizerProvider; -import org.apache.tinkerpop.gremlin.process.traversal.Traversal; -import org.apache.tinkerpop.gremlin.structure.Direction; -import org.apache.tinkerpop.gremlin.structure.Vertex; -import org.apache.tinkerpop.gremlin.util.config.YamlConfiguration; -import org.junit.Assert; -import org.junit.Test; - -import javax.script.Bindings; -import javax.script.CompiledScript; -import javax.script.ScriptEngine; -import javax.script.ScriptException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Random; -import java.util.concurrent.CountDownLatch; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -/** - * @author Stephen Mallette (http://stephen.genoprime.com) - */ -public class GremlinGroovyScriptEngineOverGraphTest extends AbstractGremlinTest { - - @Test - @LoadGraphWith(LoadGraphWith.GraphData.MODERN) - public void shouldDoSomeGremlin() throws Exception { - final ScriptEngine engine = new GremlinGroovyScriptEngine(); - final List list = new ArrayList(); - final Bindings bindings = engine.createBindings(); - bindings.put("g", g); - bindings.put("marko", convertToVertexId("marko")); - bindings.put("temp", list); - assertEquals(list.size(), 0); - engine.eval("g.V(marko).out().fill(temp)",bindings); - assertEquals(list.size(), 3); - } - - @Test - @LoadGraphWith(LoadGraphWith.GraphData.MODERN) - public void shouldLoadImports() throws Exception { - final ScriptEngine engineNoImports = new GremlinGroovyScriptEngine((CompilerCustomizerProvider) NoImportCustomizerProvider.INSTANCE); - try { - engineNoImports.eval("Vertex.class.getName()"); - fail("Should have thrown an exception because no imports were supplied"); - } catch (Exception se) { - assertTrue(se instanceof ScriptException); - } - - final ScriptEngine engineWithImports = new GremlinGroovyScriptEngine((CompilerCustomizerProvider) new DefaultImportCustomizerProvider()); - engineWithImports.put("g", g); - assertEquals(Vertex.class.getName(), engineWithImports.eval("Vertex.class.getName()")); - assertEquals(2l, engineWithImports.eval("g.V().has('age',gt(30)).count().next()")); - assertEquals(Direction.IN, engineWithImports.eval("Direction.IN")); - assertEquals(Direction.OUT, engineWithImports.eval("Direction.OUT")); - assertEquals(Direction.BOTH, engineWithImports.eval("Direction.BOTH")); - } - - - @Test - @LoadGraphWith(LoadGraphWith.GraphData.MODERN) - public void shouldLoadStandardImportsAndThenAddToThem() throws Exception { - final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine((CompilerCustomizerProvider) new DefaultImportCustomizerProvider()); - engine.put("g", g); - assertEquals(Vertex.class.getName(), engine.eval("Vertex.class.getName()")); - assertEquals(2l, engine.eval("g.V().has('age',gt(30)).count().next()")); - assertEquals(Direction.IN, engine.eval("Direction.IN")); - assertEquals(Direction.OUT, engine.eval("Direction.OUT")); - assertEquals(Direction.BOTH, engine.eval("Direction.BOTH")); - - try { - engine.eval("YamlConfiguration.class.getName()"); - fail("Should have thrown an exception because no imports were supplied"); - } catch (Exception se) { - assertTrue(se instanceof ScriptException); - } - - engine.addImports(new HashSet<>(Arrays.asList("import " + YamlConfiguration.class.getCanonicalName()))); - engine.put("g", g); - assertEquals(YamlConfiguration.class.getName(), engine.eval("YamlConfiguration.class.getName()")); - assertEquals(Vertex.class.getName(), engine.eval("Vertex.class.getName()")); - assertEquals(2l, engine.eval("g.V().has('age',gt(30)).count().next()")); - assertEquals(Direction.IN, engine.eval("Direction.IN")); - assertEquals(Direction.OUT, engine.eval("Direction.OUT")); - assertEquals(Direction.BOTH, engine.eval("Direction.BOTH")); - } - - @Test - @LoadGraphWith(LoadGraphWith.GraphData.CLASSIC) - public void shouldProperlyHandleBindings() throws Exception { - final ScriptEngine engine = new GremlinGroovyScriptEngine(); - engine.put("g", g); - engine.put("marko", convertToVertexId("marko")); - Assert.assertEquals(g.V(convertToVertexId("marko")).next(), engine.eval("g.V(marko).next()")); - - final Bindings bindings = engine.createBindings(); - bindings.put("g", g); - bindings.put("s", "marko"); - bindings.put("f", 0.5f); - bindings.put("i", 1); - bindings.put("b", true); - bindings.put("l", 100l); - bindings.put("d", 1.55555d); - - assertEquals(engine.eval("g.E().has('weight',f).next()", bindings), g.E(convertToEdgeId("marko", "knows", "vadas")).next()); - assertEquals(engine.eval("g.V().has('name',s).next()", bindings), g.V(convertToVertexId("marko")).next()); - assertEquals(engine.eval("g.V().sideEffect{it.get().property('bbb',it.get().value('name')=='marko')}.iterate();g.V().has('bbb',b).next()", bindings), g.V(convertToVertexId("marko")).next()); - assertEquals(engine.eval("g.V().sideEffect{it.get().property('iii',it.get().value('name')=='marko'?1:0)}.iterate();g.V().has('iii',i).next()", bindings), g.V(convertToVertexId("marko")).next()); - assertEquals(engine.eval("g.V().sideEffect{it.get().property('lll',it.get().value('name')=='marko'?100l:0l)}.iterate();g.V().has('lll',l).next()", bindings), g.V(convertToVertexId("marko")).next()); - assertEquals(engine.eval("g.V().sideEffect{it.get().property('ddd',it.get().value('name')=='marko'?1.55555d:0)}.iterate();g.V().has('ddd',d).next()", bindings), g.V(convertToVertexId("marko")).next()); - } - - @Test - @LoadGraphWith(LoadGraphWith.GraphData.MODERN) - public void shouldClearBindingsBetweenEvals() throws Exception { - final ScriptEngine engine = new GremlinGroovyScriptEngine(); - engine.put("g", g); - engine.put("marko", convertToVertexId("marko")); - assertEquals(g.V(convertToVertexId("marko")).next(), engine.eval("g.V(marko).next()")); - - final Bindings bindings = engine.createBindings(); - bindings.put("g", g); - bindings.put("s", "marko"); - - assertEquals(engine.eval("g.V().has('name',s).next()", bindings), g.V(convertToVertexId("marko")).next()); - - try { - engine.eval("g.V().has('name',s).next()"); - fail("This should have failed because s is no longer bound"); - } catch (Exception ex) { - final Throwable t = ExceptionUtils.getRootCause(ex); - assertEquals(MissingPropertyException.class, t.getClass()); - assertTrue(t.getMessage().startsWith("No such property: s for class")); - } - - } - - @Test - @LoadGraphWith(LoadGraphWith.GraphData.MODERN) - public void shouldBeThreadSafe() throws Exception { - final ScriptEngine engine = new GremlinGroovyScriptEngine(); - - int runs = 500; - final CountDownLatch latch = new CountDownLatch(runs); - final List<String> names = Arrays.asList("marko", "peter", "josh", "vadas", "stephen", "pavel", "matthias"); - final Random random = new Random(); - - for (int i = 0; i < runs; i++) { - new Thread("test-thread-safe-" + i) { - public void run() { - String name = names.get(random.nextInt(names.size() - 1)); - try { - final Bindings bindings = engine.createBindings(); - bindings.put("g", g); - bindings.put("name", name); - final Object result = engine.eval("t = g.V().has('name',name); if(t.hasNext()) { t } else { null }", bindings); - if (name.equals("stephen") || name.equals("pavel") || name.equals("matthias")) - assertNull(result); - else - assertNotNull(result); - } catch (ScriptException e) { - assertFalse(true); - } finally { - if (graph.features().graph().supportsTransactions()) - g.tx().rollback(); - } - latch.countDown(); - } - }.start(); - } - latch.await(); - } - - @Test - @LoadGraphWith(LoadGraphWith.GraphData.MODERN) - public void shouldBeThreadSafeOnCompiledScript() throws Exception { - final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(); - final CompiledScript script = engine.compile("t = g.V().has('name',name); if(t.hasNext()) { t } else { null }"); - - int runs = 500; - final CountDownLatch latch = new CountDownLatch(runs); - final List<String> names = Arrays.asList("marko", "peter", "josh", "vadas", "stephen", "pavel", "matthias"); - final Random random = new Random(); - - for (int i = 0; i < runs; i++) { - new Thread("test-thread-safety-on-compiled-script-" + i) { - public void run() { - String name = names.get(random.nextInt(names.size() - 1)); - try { - final Bindings bindings = engine.createBindings(); - bindings.put("g", g); - bindings.put("name", name); - Object result = script.eval(bindings); - if (name.equals("stephen") || name.equals("pavel") || name.equals("matthias")) - assertNull(result); - else - assertNotNull(result); - } catch (ScriptException e) { - //System.out.println(e); - assertFalse(true); - } finally { - if (graph.features().graph().supportsTransactions()) - g.tx().rollback(); - } - latch.countDown(); - } - }.start(); - } - latch.await(); - } - - @Test - @LoadGraphWith(LoadGraphWith.GraphData.MODERN) - public void shouldEvalGlobalClosuresEvenAfterEvictionOfClass() throws ScriptException { - final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(); - - final Bindings bindings = engine.createBindings(); - bindings.put("g", g); - bindings.put("marko", convertToVertexId("marko")); - bindings.put("vadas", convertToVertexId("vadas")); - - // strong referenced global closure - engine.eval("def isVadas(v){v.value('name')=='vadas'}", bindings); - assertEquals(true, engine.eval("isVadas(g.V(vadas).next())", bindings)); - - // phantom referenced global closure - bindings.put(GremlinGroovyScriptEngine.KEY_REFERENCE_TYPE, GremlinGroovyScriptEngine.REFERENCE_TYPE_PHANTOM); - engine.eval("def isMarko(v){v.value('name')=='marko'}", bindings); - - try { - engine.eval("isMarko(g.V(marko).next())", bindings); - fail("the isMarko function should not be present"); - } catch (Exception ex) { - - } - - assertEquals(true, engine.eval("def isMarko(v){v.value('name')=='marko'}; isMarko(g.V(marko).next())", bindings)); - - try { - engine.eval("isMarko(g.V(marko" - + ").next())", bindings); - fail("the isMarko function should not be present"); - } catch (Exception ex) { - - } - - bindings.remove(GremlinGroovyScriptEngine.KEY_REFERENCE_TYPE); - - // isVadas class was a hard reference so it should still be hanging about - assertEquals(true, engine.eval("isVadas(g.V(vadas).next())", bindings)); - } - - @Test - @LoadGraphWith(LoadGraphWith.GraphData.MODERN) - public void shouldAllowFunctionsUsedInClosure() throws ScriptException { - final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(); - - final Bindings bindings = engine.createBindings(); - bindings.put("g", g); - bindings.put("#jsr223.groovy.engine.keep.globals", "phantom"); - bindings.put("vadas", convertToVertexId("vadas")); - - // this works on its own when the function and the line that uses it is in one "script". this is the - // current workaround - assertEquals(g.V(convertToVertexId("vadas")).next(), engine.eval("def isVadas(v){v.value('name')=='vadas'};g.V().filter{isVadas(it.get())}.next()", bindings)); - - // let's reset this piece and make sure isVadas is not hanging around. - engine.reset(); - - // validate that isVadas throws an exception since it is not defined - try { - engine.eval("isVadas(g.V(vadas).next())", bindings); - - // fail the test if the above doesn't throw an exception - fail(); - } catch (Exception ex) { - // this is good...we want this. it means isVadas isn't hanging about - } - - // now...define the function separately on its own in one script - bindings.remove("#jsr223.groovy.engine.keep.globals"); - engine.eval("def isVadas(v){v.value('name')=='vadas'}", bindings); - - // make sure the function works on its own...no problem - assertEquals(true, engine.eval("isVadas(g.V(vadas).next())", bindings)); - - // make sure the function works in a closure...this generates a StackOverflowError - assertEquals(g.V(convertToVertexId("vadas")).next(), engine.eval("g.V().filter{isVadas(it.get())}.next()", bindings)); - } - - @Test - @org.junit.Ignore - @LoadGraphWith(LoadGraphWith.GraphData.CLASSIC) - public void shouldAllowUseOfClasses() throws ScriptException { - GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(); - - final Bindings bindings = engine.createBindings(); - bindings.put("g", g); - bindings.put("vadas", convertToVertexId("vadas")); - - // works when it's all defined together - assertEquals(true, engine.eval("class c { static def isVadas(v){v.value('name')=='vadas'}};c.isVadas(g.V(vadas).next())", bindings)); - - // let's reset this piece and make sure isVadas is not hanging around. - engine.reset(); - - // validate that isVadas throws an exception since it is not defined - try { - engine.eval("c.isVadas(g.V(vadas).next())", bindings); - - // fail the test if the above doesn't throw an exception - fail("Function should be gone"); - } catch (Exception ex) { - // this is good...we want this. it means isVadas isn't hanging about - } - - // now...define the class separately on its own in one script... - // HERE'S an AWKWARD BIT......... - // YOU HAVE TO END WITH: null; - // ....OR ELSE YOU GET: - // javax.script.ScriptException: javax.script.ScriptException: - // org.codehaus.groovy.runtime.metaclass.MissingMethodExceptionNoStack: No signature of method: c.main() - // is applicable for argument types: ([Ljava.lang.String;) values: [[]] - // WOULD BE NICE IF WE DIDN'T HAVE TO DO THAT - engine.eval("class c { static def isVadas(v){v.name=='vadas'}};null;", bindings); - - // make sure the class works on its own...this generates: groovy.lang.MissingPropertyException: No such property: c for class: Script2 - assertEquals(true, engine.eval("c.isVadas(g.V(vadas).next())", bindings)); - } - - @Test - @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) - public void shouldProcessUTF8Query() throws Exception { - final Vertex nonUtf8 = graph.addVertex("name", "marko", "age", 29); - final Vertex utf8Name = graph.addVertex("name", "è½æ³¨", "age", 32); - - final ScriptEngine engine = new GremlinGroovyScriptEngine(); - - engine.put("g", g); - Traversal eval = (Traversal) engine.eval("g.V().has('name', 'marko')"); - assertEquals(nonUtf8, eval.next()); - eval = (Traversal) engine.eval("g.V().has('name','è½æ³¨')"); - assertEquals(utf8Name, eval.next()); - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/aa828940/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineSandboxedStandardTest.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineSandboxedStandardTest.java b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineSandboxedStandardTest.java deleted file mode 100644 index b9fd1be..0000000 --- a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineSandboxedStandardTest.java +++ /dev/null @@ -1,138 +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.groovy.jsr223; - -import org.apache.tinkerpop.gremlin.AbstractGremlinTest; -import org.apache.tinkerpop.gremlin.LoadGraphWith; -import org.apache.tinkerpop.gremlin.groovy.CompilerCustomizerProvider; -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.CompileStaticCustomizerProvider; -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.SimpleSandboxExtension; -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.TypeCheckedCustomizerProvider; -import org.codehaus.groovy.control.MultipleCompilationErrorsException; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -import javax.script.Bindings; - -import java.util.Arrays; - -import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; - -/** - * @author Stephen Mallette (http://stephen.genoprime.com) - */ -@RunWith(Parameterized.class) -public class GremlinGroovyScriptEngineSandboxedStandardTest extends AbstractGremlinTest { - @Parameterized.Parameters(name = "{0}") - public static Iterable<Object[]> data() { - return Arrays.asList(new Object[][]{ - {TypeCheckedCustomizerProvider.class.getSimpleName(), new TypeCheckedCustomizerProvider(), new TypeCheckedCustomizerProvider(SimpleSandboxExtension.class.getName())}, - {CompileStaticCustomizerProvider.class.getSimpleName(), new CompileStaticCustomizerProvider(), new CompileStaticCustomizerProvider(SimpleSandboxExtension.class.getName())}}); - } - - @Parameterized.Parameter(value = 0) - public String name; - - @Parameterized.Parameter(value = 1) - public CompilerCustomizerProvider notSandboxed; - - @Parameterized.Parameter(value = 2) - public CompilerCustomizerProvider sandboxed; - - @Test - @LoadGraphWith(LoadGraphWith.GraphData.MODERN) - public void shouldEvalGraphTraversalSource() throws Exception { - try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine()) { - final Bindings bindings = engine.createBindings(); - bindings.put("g", g); - bindings.put("marko", convertToVertexId("marko")); - assertEquals(g.V(convertToVertexId("marko")).next(), engine.eval("g.V(marko).next()", bindings)); - } - - try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(notSandboxed)) { - final Bindings bindings = engine.createBindings(); - bindings.put("g", g); - bindings.put("marko", convertToVertexId("marko")); - engine.eval("g.V(marko).next()", bindings); - fail("Type checking should have forced an error as 'g' is not defined"); - } catch (Exception ex) { - assertEquals(MultipleCompilationErrorsException.class, ex.getCause().getClass()); - assertThat(ex.getMessage(), containsString("The variable [g] is undeclared.")); - } - - try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(sandboxed)) { - final Bindings bindings = engine.createBindings(); - bindings.put("g", g); - bindings.put("marko", convertToVertexId("marko")); - assertEquals(g.V(convertToVertexId("marko")).next(), engine.eval("g.V(marko).next()", bindings)); - assertEquals(g.V(convertToVertexId("marko")).out("created").count().next(), engine.eval("g.V(marko).out(\"created\").count().next()", bindings)); - } - } - - @Test - @LoadGraphWith(LoadGraphWith.GraphData.MODERN) - public void shouldEvalGraph() throws Exception { - try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine()) { - final Bindings bindings = engine.createBindings(); - bindings.put("graph", graph); - bindings.put("marko", convertToVertexId("marko")); - assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(marko).next()", bindings)); - } - - try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(notSandboxed)) { - final Bindings bindings = engine.createBindings(); - bindings.put("graph", graph); - bindings.put("marko", convertToVertexId("marko")); - assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(marko).next()", bindings)); - fail("Type checking should have forced an error as 'graph' is not defined"); - } catch (Exception ex) { - assertEquals(MultipleCompilationErrorsException.class, ex.getCause().getClass()); - assertThat(ex.getMessage(), containsString("The variable [graph] is undeclared.")); - } - - try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(notSandboxed)) { - final Bindings bindings = engine.createBindings(); - bindings.put("graph", graph); - bindings.put("x", convertToVertexId("marko")); - assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(x).next()", bindings)); - fail("Type checking should have forced an error as 'graph' is not defined"); - } catch (Exception ex) { - assertEquals(MultipleCompilationErrorsException.class, ex.getCause().getClass()); - assertThat(ex.getMessage(), containsString("The variable [graph] is undeclared.")); - } - - try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(sandboxed)) { - final Bindings bindings = engine.createBindings(); - bindings.put("graph", graph); - bindings.put("marko", convertToVertexId("marko")); - assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(marko).next()", bindings)); - } - - try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(sandboxed)) { - final Bindings bindings = engine.createBindings(); - bindings.put("graph", graph); - bindings.put("x", convertToVertexId("marko")); - assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(x).next()", bindings)); - } - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/aa828940/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTinkerPopSandboxTest.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTinkerPopSandboxTest.java b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTinkerPopSandboxTest.java deleted file mode 100644 index 5adca8c..0000000 --- a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTinkerPopSandboxTest.java +++ /dev/null @@ -1,64 +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.groovy.jsr223; - -import org.apache.tinkerpop.gremlin.AbstractGremlinTest; -import org.apache.tinkerpop.gremlin.LoadGraphWith; -import org.apache.tinkerpop.gremlin.groovy.CompilerCustomizerProvider; -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.CompileStaticCustomizerProvider; -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.TinkerPopSandboxExtension; -import org.codehaus.groovy.control.MultipleCompilationErrorsException; -import org.junit.Test; - -import javax.script.Bindings; - -import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; - -/** - * @author Stephen Mallette (http://stephen.genoprime.com) - */ -public class GremlinGroovyScriptEngineTinkerPopSandboxTest extends AbstractGremlinTest { - @Test - public void shouldNotEvalAsTheMethodIsNotWhiteListed() throws Exception { - final CompilerCustomizerProvider standardSandbox = new CompileStaticCustomizerProvider(TinkerPopSandboxExtension.class.getName()); - try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(standardSandbox)) { - engine.eval("java.lang.Math.abs(123)"); - fail("Should have a compile error because class/method is not white listed"); - } catch (Exception ex) { - assertEquals(MultipleCompilationErrorsException.class, ex.getCause().getClass()); - assertThat(ex.getCause().getMessage(), containsString("Not authorized to call this method")); - } - } - - @Test - @LoadGraphWith(LoadGraphWith.GraphData.MODERN) - public void shouldEvalOnGAsTheMethodIsWhiteListed() throws Exception { - final CompilerCustomizerProvider standardSandbox = new CompileStaticCustomizerProvider(TinkerPopSandboxExtension.class.getName()); - try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(standardSandbox)) { - final Bindings bindings = engine.createBindings(); - bindings.put("g", g); - bindings.put("marko", convertToVertexId("marko")); - assertEquals(g.V(convertToVertexId("marko")).next(), engine.eval("g.V(marko).next()", bindings)); - assertEquals(g.V(convertToVertexId("marko")).out("created").count().next(), engine.eval("g.V(marko).out(\"created\").count().next()", bindings)); - } - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/aa828940/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslatorTest.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslatorTest.java b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslatorTest.java deleted file mode 100644 index 59903ac..0000000 --- a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslatorTest.java +++ /dev/null @@ -1,123 +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.groovy.jsr223; - -import org.apache.commons.configuration.MapConfiguration; -import org.apache.tinkerpop.gremlin.AbstractGremlinTest; -import org.apache.tinkerpop.gremlin.LoadGraphWith; -import org.apache.tinkerpop.gremlin.process.traversal.Traversal; -import org.apache.tinkerpop.gremlin.process.traversal.Traverser; -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; -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.strategy.decoration.PartitionStrategy; -import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SubgraphStrategy; -import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.TranslationStrategy; -import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReadOnlyStrategy; -import org.apache.tinkerpop.gremlin.structure.Vertex; -import org.apache.tinkerpop.gremlin.util.function.Lambda; -import org.junit.Test; - -import javax.script.Bindings; -import javax.script.SimpleBindings; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; - -/** - * @author Marko A. Rodriguez (http://markorodriguez.com) - */ -public class GroovyTranslatorTest extends AbstractGremlinTest { - - @Test - @LoadGraphWith(LoadGraphWith.GraphData.MODERN) - public void shouldHandleStrategies() throws Exception { - GraphTraversalSource g = graph.traversal(); - g = g.withStrategies(SubgraphStrategy.create(new MapConfiguration(new HashMap<String, Object>() {{ - put(SubgraphStrategy.VERTICES, __.has("name", "marko")); - }}))); - final Bindings bindings = new SimpleBindings(); - bindings.put("g", g); - Traversal.Admin<Vertex, Object> traversal = new GremlinGroovyScriptEngine().eval(g.V().values("name").asAdmin().getBytecode(), bindings); - assertEquals("marko", traversal.next()); - assertFalse(traversal.hasNext()); - // - traversal = new GremlinGroovyScriptEngine().eval(g.withoutStrategies(SubgraphStrategy.class).V().count().asAdmin().getBytecode(), bindings); - assertEquals(new Long(6), traversal.next()); - assertFalse(traversal.hasNext()); - // - traversal = new GremlinGroovyScriptEngine().eval(g.withStrategies(SubgraphStrategy.create(new MapConfiguration(new HashMap<String, Object>() {{ - put(SubgraphStrategy.VERTICES, __.has("name", "marko")); - }})), ReadOnlyStrategy.instance()).V().values("name").asAdmin().getBytecode(), bindings); - assertEquals("marko", traversal.next()); - assertFalse(traversal.hasNext()); - } - - @Test - @LoadGraphWith(LoadGraphWith.GraphData.MODERN) - public void shouldSupportStringSupplierLambdas() throws Exception { - GraphTraversalSource g = graph.traversal(); - g = g.withStrategies(new TranslationStrategy(g, GroovyTranslator.of("g"))); - GraphTraversal.Admin<Vertex, Integer> t = g.withSideEffect("lengthSum", 0).withSack(1) - .V() - .filter(Lambda.predicate("it.get().label().equals('person')")) - .flatMap(Lambda.function("it.get().vertices(Direction.OUT)")) - .map(Lambda.<Traverser<Object>, Integer>function("it.get().value('name').length()")) - .sideEffect(Lambda.consumer("{ x -> x.sideEffects(\"lengthSum\", x.<Integer>sideEffects('lengthSum') + x.get()) }")) - .order().by(Lambda.comparator("a,b -> a <=> b")) - .sack(Lambda.biFunction("{ a,b -> a + b }")) - .asAdmin(); - final List<Integer> sacks = new ArrayList<>(); - final List<Integer> lengths = new ArrayList<>(); - while (t.hasNext()) { - final Traverser.Admin<Integer> traverser = t.nextTraverser(); - sacks.add(traverser.sack()); - lengths.add(traverser.get()); - } - assertFalse(t.hasNext()); - // - assertEquals(6, lengths.size()); - assertEquals(3, lengths.get(0).intValue()); - assertEquals(3, lengths.get(1).intValue()); - assertEquals(3, lengths.get(2).intValue()); - assertEquals(4, lengths.get(3).intValue()); - assertEquals(5, lengths.get(4).intValue()); - assertEquals(6, lengths.get(5).intValue()); - /// - assertEquals(6, sacks.size()); - assertEquals(4, sacks.get(0).intValue()); - assertEquals(4, sacks.get(1).intValue()); - assertEquals(4, sacks.get(2).intValue()); - assertEquals(5, sacks.get(3).intValue()); - assertEquals(6, sacks.get(4).intValue()); - assertEquals(7, sacks.get(5).intValue()); - // - assertEquals(24, t.getSideEffects().<Number>get("lengthSum").intValue()); - } - - @Test - public void shouldHaveValidToString() { - assertEquals("translator[h:gremlin-groovy]", GroovyTranslator.of("h").toString()); - } -}