You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2016/08/27 00:54:40 UTC

[25/50] [abbrv] tinkerpop git commit: added gremlin-server-modern-secure-py to the test resources of gremlin-python for testing authentification. added DriverConnectionTest which uses bash python to test Gremlin-Python (CPython). Basic tests to ensure th

added gremlin-server-modern-secure-py to the test resources of gremlin-python for testing authentification. added DriverConnectionTest which uses bash python to test Gremlin-Python (CPython). Basic tests to ensure that the protocol works.


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

Branch: refs/heads/master
Commit: 901ecb6deea0ac515beebd3d3e552200b89983f4
Parents: 2804e45
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Thu Aug 25 14:18:31 2016 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Thu Aug 25 14:18:31 2016 -0600

----------------------------------------------------------------------
 .../driver/DriverRemoteConnectionTest.java      | 127 +++++++++----------
 .../gremlin/python/driver/credentials.kryo      | Bin 0 -> 138 bytes
 .../python/driver/generate-modern.groovy        |  33 +++++
 .../python/driver/gremlin-server-modern-py.yaml |  66 ++++++++++
 .../driver/tinkergraph-credentials.properties   |  22 ++++
 .../python/driver/tinkergraph-empty.properties  |  18 +++
 6 files changed, 202 insertions(+), 64 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/901ecb6d/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/driver/DriverRemoteConnectionTest.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/driver/DriverRemoteConnectionTest.java b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/driver/DriverRemoteConnectionTest.java
index cec9be5..f12d986 100644
--- a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/driver/DriverRemoteConnectionTest.java
+++ b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/driver/DriverRemoteConnectionTest.java
@@ -19,18 +19,22 @@
 
 package org.apache.tinkerpop.gremlin.python.driver;
 
-import org.apache.tinkerpop.gremlin.python.jsr223.JythonScriptEngineSetup;
+import org.apache.tinkerpop.gremlin.TestHelper;
 import org.apache.tinkerpop.gremlin.server.GremlinServer;
 import org.apache.tinkerpop.gremlin.server.Settings;
-import org.apache.tinkerpop.gremlin.util.ScriptEngineCache;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
-import javax.script.ScriptContext;
-import javax.script.ScriptEngine;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Writer;
 import java.util.Arrays;
 import java.util.List;
-import java.util.Set;
+import java.util.stream.Collectors;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
@@ -40,82 +44,77 @@ import static org.junit.Assert.assertTrue;
  */
 public class DriverRemoteConnectionTest {
 
-    private static final ScriptEngine jython = ScriptEngineCache.get("jython");
-
-    private final List<String> aliases = Arrays.asList("g", "j");
+    private static boolean PYTHON_EXISTS = false;
 
     @BeforeClass
     public static void setup() {
         try {
-            JythonScriptEngineSetup.setup();
-            jython.getContext().getBindings(ScriptContext.ENGINE_SCOPE)
-                    .put("g", jython.eval("Graph().traversal().withRemote(DriverRemoteConnection('ws://localhost:8182','g'))"));
-            jython.getContext().getBindings(ScriptContext.ENGINE_SCOPE)
-                    .put("j", jython.eval("Graph().traversal().withRemote(DriverRemoteConnection('ws://localhost:8182','g'))"));
-            new GremlinServer(Settings.read(DriverRemoteConnectionTest.class.getResourceAsStream("gremlin-server-rest-modern.yaml"))).start().join();
+            PYTHON_EXISTS = new BufferedReader(new InputStreamReader(Runtime.getRuntime().exec("python --version").getErrorStream())).lines().filter(line -> line.trim().startsWith("Python ")).findAny().isPresent();
+            System.out.println("Python exists: " + PYTHON_EXISTS);
+            if (PYTHON_EXISTS)
+                new GremlinServer(Settings.read(DriverRemoteConnectionTest.class.getResourceAsStream("gremlin-server-modern-py.yaml"))).start().join();
         } catch (final Exception ex) {
             ex.printStackTrace();
         }
     }
 
-    @Test
-    @org.junit.Ignore
-    public void testGraphTraversalNext() throws Exception {
-        for (final String alias : this.aliases) {
-            final String result = (String) jython.eval(alias + ".V().repeat(__.out()).times(2).name.next()");
-            assertTrue(result.equals("lop") || result.equals("ripple"));
-        }
-    }
+    private static List<String> submit(final String traversal) throws IOException {
+        final StringBuilder script = new StringBuilder();
+        script.append("from gremlin_python import statics\n");
+        script.append("from gremlin_python.structure.graph import Graph\n");
+        script.append("from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection\n");
+        script.append("from gremlin_python.structure.io.graphson import GraphSONWriter\n\n");
+        script.append("statics.load_statics(globals())\n");
+        script.append("graph = Graph()\n");
+        script.append("g = graph.traversal().withRemote(DriverRemoteConnection('ws://localhost:8182','g',username='stephen', password='password'))\n");
+        script.append("results = " + traversal + ".toList()\n");
+        script.append("print results\n\n");
 
-    @Test
-    @org.junit.Ignore
-    public void testGraphTraversalToList() throws Exception {
-        for (final String alias : this.aliases) {
-            final List<String> results = (List) jython.eval(alias + ".V().repeat(__.out()).times(2).name.toList()");
-            assertEquals(2, results.size());
-            assertTrue(results.contains("lop"));
-            assertTrue(results.contains("ripple"));
-        }
-    }
+        File file = TestHelper.generateTempFile(DriverRemoteConnectionTest.class, "temp", "py");
+        final Writer writer = new BufferedWriter(new FileWriter(file.getAbsoluteFile()));
+        writer.write(script.toString());
+        writer.flush();
+        writer.close();
+
+        final BufferedReader reader = new BufferedReader(new InputStreamReader(Runtime.getRuntime().exec("python " + file.getAbsolutePath()).getInputStream()));
+        final List<String> lines = reader.lines()
+                .map(line -> line.substring(1, line.length() - 1))
+                .flatMap(line -> Arrays.stream(line.split(",")))
+                .map(String::trim)
+                .collect(Collectors.toList());
+        reader.close();
+        file.delete();
+        return lines;
 
-    @Test
-    @org.junit.Ignore
-    public void testGraphTraversalToSet() throws Exception {
-        for (final String alias : this.aliases) {
-            final Set<String> results = (Set) jython.eval(alias + ".V().repeat(__.both()).times(4).hasLabel('software').name.toSet()");
-            assertEquals(2, results.size());
-            assertTrue(results.contains("lop"));
-            assertTrue(results.contains("ripple"));
-        }
     }
 
     @Test
-    @org.junit.Ignore
-    public void testGraphTraversalNextAmount() throws Exception {
-        for (final String alias : this.aliases) {
-            List<String> results = (List) jython.eval(alias + ".V().repeat(__.out()).times(2).name.next(2)");
-            assertEquals(2, results.size());
-            assertTrue(results.contains("lop"));
-            assertTrue(results.contains("ripple"));
-            //
-            results = (List) jython.eval(alias + ".V().repeat(__.out()).times(2).name.next(4)");
-            assertEquals(2, results.size());
-            assertTrue(results.contains("lop"));
-            assertTrue(results.contains("ripple"));
-        }
+    public void testTraversals() throws Exception {
+        if (!PYTHON_EXISTS) return;
+
+        List<String> result = DriverRemoteConnectionTest.submit("g.V().count()");
+        assertEquals(1, result.size());
+        assertEquals("6L", result.get(0));
+        //
+        result = DriverRemoteConnectionTest.submit("g.V(1).out('created').name");
+        assertEquals(1, result.size());
+        assertEquals("u'lop'", result.get(0));
+        //
+        result = DriverRemoteConnectionTest.submit("g.V(1).out()");
+        assertEquals(3, result.size());
+        assertTrue(result.contains("v[4]"));
+        assertTrue(result.contains("v[2]"));
+        assertTrue(result.contains("v[3]"));
     }
 
     @Test
-    @org.junit.Ignore
-    public void testRemoteConnectionBindings() throws Exception {
-        for (final String alias : this.aliases) {
-            final String traversalScript = jython.eval(alias + ".V().out(('a','knows'),'created')").toString();
-            assertEquals(traversalScript, "g.V().out(a, \"created\")"); // ensure the traversal string is binding based
-            final List<String> results = (List) jython.eval(alias + ".V().out(('a','knows')).out('created').name.next(2)");
-            assertEquals(2, results.size());
-            assertTrue(results.contains("lop"));
-            assertTrue(results.contains("ripple"));
+    public void testAnonymousTraversals() throws Exception {
+        if (!PYTHON_EXISTS) return;
 
-        }
+        List<String> result = DriverRemoteConnectionTest.submit("g.V().repeat(out()).times(2).name");
+        assertEquals(2, result.size());
+        assertTrue(result.contains("u'lop'"));
+        assertTrue(result.contains("u'ripple'"));
     }
+
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/901ecb6d/gremlin-python/src/test/resources/org/apache/tinkerpop/gremlin/python/driver/credentials.kryo
----------------------------------------------------------------------
diff --git a/gremlin-python/src/test/resources/org/apache/tinkerpop/gremlin/python/driver/credentials.kryo b/gremlin-python/src/test/resources/org/apache/tinkerpop/gremlin/python/driver/credentials.kryo
new file mode 100644
index 0000000..163d2ef
Binary files /dev/null and b/gremlin-python/src/test/resources/org/apache/tinkerpop/gremlin/python/driver/credentials.kryo differ

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/901ecb6d/gremlin-python/src/test/resources/org/apache/tinkerpop/gremlin/python/driver/generate-modern.groovy
----------------------------------------------------------------------
diff --git a/gremlin-python/src/test/resources/org/apache/tinkerpop/gremlin/python/driver/generate-modern.groovy b/gremlin-python/src/test/resources/org/apache/tinkerpop/gremlin/python/driver/generate-modern.groovy
new file mode 100644
index 0000000..23b4a61
--- /dev/null
+++ b/gremlin-python/src/test/resources/org/apache/tinkerpop/gremlin/python/driver/generate-modern.groovy
@@ -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.
+ */
+
+// an init script that returns a Map allows explicit setting of global bindings.
+def globals = [:]
+
+// Generates the modern graph into an "empty" TinkerGraph via LifeCycleHook.
+// Note that the name of the key in the "global" map is unimportant.
+globals << [hook : [
+  onStartUp: { ctx ->
+    ctx.logger.info("Loading 'modern' graph data.")
+    TinkerFactory.generateModern(graph)
+  }
+] as LifeCycleHook]
+
+// define the default TraversalSource to bind queries to - this one will be named "g".
+globals << [g : graph.traversal()]
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/901ecb6d/gremlin-python/src/test/resources/org/apache/tinkerpop/gremlin/python/driver/gremlin-server-modern-py.yaml
----------------------------------------------------------------------
diff --git a/gremlin-python/src/test/resources/org/apache/tinkerpop/gremlin/python/driver/gremlin-server-modern-py.yaml b/gremlin-python/src/test/resources/org/apache/tinkerpop/gremlin/python/driver/gremlin-server-modern-py.yaml
new file mode 100644
index 0000000..a1b28a9
--- /dev/null
+++ b/gremlin-python/src/test/resources/org/apache/tinkerpop/gremlin/python/driver/gremlin-server-modern-py.yaml
@@ -0,0 +1,66 @@
+# 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.
+
+# Note that TinkerPop does not include gremlin-python dependencies in
+# its distributions. This file cannot be used as a configuration file
+# to Gremlin Server unless those dependencies are installed on the
+# Gremlin Server path with:
+#
+# bin/gremlin-server.sh -i org.apache.tinkerpop gremlin-python x.y.z
+#
+# The primary change in this file to enable the GremlinJythonScriptEngine
+# is the addition of "gremlin-jython" to the "scriptEngines" field.
+
+host: localhost
+port: 8182
+threadPoolWorker: 1
+gremlinPool: 8
+scriptEvaluationTimeout: 30000
+graphs: {
+  graph: src/test/resources/org/apache/tinkerpop/gremlin/python/driver/tinkergraph-empty.properties}
+plugins:
+  - tinkerpop.tinkergraph
+scriptEngines: {
+  gremlin-groovy: {
+    imports: [java.lang.Math],
+    staticImports: [java.lang.Math.PI],
+    scripts: [src/test/resources/org/apache/tinkerpop/gremlin/python/driver/generate-modern.groovy]},
+  gremlin-jython: {},
+  gremlin-python: {}
+}
+serializers:
+  - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { useMapperFromGraph: graph }}            # application/vnd.gremlin-v1.0+gryo
+  - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoLiteMessageSerializerV1d0, config: { useMapperFromGraph: graph }}        # application/vnd.gremlin-v1.0+gryo-lite
+  - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { serializeResultToString: true }}        # application/vnd.gremlin-v1.0+gryo-stringd
+  - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+json
+  - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v2.0+json
+  - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0, config: { useMapperFromGraph: graph }}        # application/json
+metrics: {
+  slf4jReporter: {enabled: true, interval: 180000}}
+strictTransactionManagement: false
+threadPoolBoss: 1
+maxInitialLineLength: 4096
+maxHeaderSize: 8192
+maxChunkSize: 8192
+maxContentLength: 65536
+maxAccumulationBufferComponents: 1024
+resultIterationBatchSize: 64
+authentication: {
+  className: org.apache.tinkerpop.gremlin.server.auth.SimpleAuthenticator,
+  config: {
+    credentialsDb: src/test/resources/org/apache/tinkerpop/gremlin/python/driver/tinkergraph-credentials.properties}}
+

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/901ecb6d/gremlin-python/src/test/resources/org/apache/tinkerpop/gremlin/python/driver/tinkergraph-credentials.properties
----------------------------------------------------------------------
diff --git a/gremlin-python/src/test/resources/org/apache/tinkerpop/gremlin/python/driver/tinkergraph-credentials.properties b/gremlin-python/src/test/resources/org/apache/tinkerpop/gremlin/python/driver/tinkergraph-credentials.properties
new file mode 100644
index 0000000..909b92b
--- /dev/null
+++ b/gremlin-python/src/test/resources/org/apache/tinkerpop/gremlin/python/driver/tinkergraph-credentials.properties
@@ -0,0 +1,22 @@
+#
+#  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.
+#
+gremlin.graph=org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph
+gremlin.tinkergraph.vertexIdManager=LONG
+gremlin.tinkergraph.graphLocation=src/test/resources/org/apache/tinkerpop/gremlin/python/driver/credentials.kryo
+gremlin.tinkergraph.graphFormat=gryo
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/901ecb6d/gremlin-python/src/test/resources/org/apache/tinkerpop/gremlin/python/driver/tinkergraph-empty.properties
----------------------------------------------------------------------
diff --git a/gremlin-python/src/test/resources/org/apache/tinkerpop/gremlin/python/driver/tinkergraph-empty.properties b/gremlin-python/src/test/resources/org/apache/tinkerpop/gremlin/python/driver/tinkergraph-empty.properties
new file mode 100644
index 0000000..e09a13d
--- /dev/null
+++ b/gremlin-python/src/test/resources/org/apache/tinkerpop/gremlin/python/driver/tinkergraph-empty.properties
@@ -0,0 +1,18 @@
+# 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.
+gremlin.graph=org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph
+gremlin.tinkergraph.vertexIdManager=LONG
\ No newline at end of file