You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by ok...@apache.org on 2015/11/24 16:26:30 UTC

[3/3] incubator-tinkerpop git commit: we had a back('x') in one of our SugarLoader tests. Crazy. Also, tweaks the Groovy tests as recommended by @dkuppitz. Created a TinkerGraphUUIDProvider which makes sure that complex objects work right. All tests pass

we had a back('x') in one of our SugarLoader tests. Crazy. Also, tweaks the Groovy tests as recommended by @dkuppitz. Created a TinkerGraphUUIDProvider which makes sure that complex objects work right. All tests pass.


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

Branch: refs/heads/master
Commit: 4b60ff088614fba20e94739b4e479d5de5174da5
Parents: 8991f20
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Tue Nov 24 08:26:22 2015 -0700
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Tue Nov 24 08:26:22 2015 -0700

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |  1 +
 .../groovy/loaders/SugarLoaderTest.groovy       | 23 +++++---
 .../GremlinGroovyScriptEngineOverGraphTest.java | 10 ++--
 .../tinkergraph/TinkerGraphProvider.java        |  8 +--
 .../tinkergraph/TinkerGraphUUIDProvider.java    | 57 ++++++++++++++++++++
 .../TinkerGraphUUIDGroovyEnvironmentTest.java   | 38 +++++++++++++
 6 files changed, 121 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4b60ff08/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index e179533..aa4f4f5 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -26,6 +26,7 @@ image::https://raw.githubusercontent.com/apache/incubator-tinkerpop/master/docs/
 TinkerPop 3.1.1 (NOT OFFICIALLY RELEASED YET)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
+* Fixed various Gremlin-Groovy tests that assumed `toString()`-able ids.
 * Split TinkerPop documentation into different directories.
 * Added `explain()`-step which yields a `TraversalExplanation` with a pretty `toString()` detailing the compilation process.
 * Fixed a traversal strategy ordering bug in `AdjacentToIncidentStrategy` and `IncidentToAdjacentStrategy`.

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4b60ff08/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/loaders/SugarLoaderTest.groovy
----------------------------------------------------------------------
diff --git a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/loaders/SugarLoaderTest.groovy b/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/loaders/SugarLoaderTest.groovy
index d9bb8d7..5fec65a 100644
--- a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/loaders/SugarLoaderTest.groovy
+++ b/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/loaders/SugarLoaderTest.groovy
@@ -21,12 +21,13 @@ package org.apache.tinkerpop.gremlin.groovy.loaders
 import org.apache.tinkerpop.gremlin.AbstractGremlinTest
 import org.apache.tinkerpop.gremlin.LoadGraphWith
 import org.apache.tinkerpop.gremlin.groovy.util.SugarTestHelper
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal
 import org.apache.tinkerpop.gremlin.structure.*
 import org.apache.tinkerpop.gremlin.structure.util.StringFactory
 import org.junit.Test
 
+import static org.apache.tinkerpop.gremlin.process.traversal.P.eq
 import static org.junit.Assert.*
-import static org.apache.tinkerpop.gremlin.process.traversal.P.*
 
 /**
  * @author Marko A. Rodriguez (http://markorodriguez.com)
@@ -78,20 +79,26 @@ class SugarLoaderTest extends AbstractGremlinTest {
         assertEquals(6, g.V.count.next())
         assertEquals(6, g.V.out.count.next())
         assertEquals(6, g.V.out.name.count.next())
-        assertEquals(2, g.V(graphProvider.convertId(1, Vertex.class)).out.out.name.count.next());
-        g.V(graphProvider.convertId(1, Vertex.class)).next().name = 'okram'
-        assertEquals('okram', g.V(graphProvider.convertId(1, Vertex.class)).next().name);
-        g.V(graphProvider.convertId(1, Vertex.class)).next()['name'] = 'marko a. rodriguez'
-        assertEquals(["okram", "marko a. rodriguez"] as Set, g.V(graphProvider.convertId(1, Vertex.class)).values('name').toSet());
+        assertEquals(2, g.V(convertToVertexId("marko")).out.out.name.count.next());
+        final Object markoId = convertToVertexId(graph, "marko");
+        g.V(markoId).next().name = 'okram'
+        assertEquals('okram', g.V(markoId).next().name);
         assertEquals(29, g.V.age.is(eq(29)).next())
+        if (graph.features().vertex().supportsMultiProperties()) {
+            g.V(markoId).next()['name'] = 'marko a. rodriguez'
+            assertEquals(["okram", "marko a. rodriguez"] as Set, g.V(markoId).values('name').toSet());
+        }
     }
 
     @Test
     @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
     public void shouldUseTraverserCategoryCorrectly() {
         SugarLoader.load()
-        g.V.as('a').out.as('x').name.as('b').back('x').has('age').map { [it.a, it.b, it.age] }.forEach {
-            // println it;
+        final Traversal t = g.V.as('a').out.as('x').name.as('b').select('x').has('age').map {
+            [it.path().a, it.path().b, it.age]
+        };
+        assertTrue(t.hasNext())
+        t.forEachRemaining {
             assertTrue(it[0] instanceof Vertex)
             assertTrue(it[1] instanceof String)
             assertTrue(it[2] instanceof Integer)

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4b60ff08/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
index 8f2120a..f1838ce 100644
--- 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
@@ -36,6 +36,7 @@ import javax.script.Bindings;
 import javax.script.CompiledScript;
 import javax.script.ScriptEngine;
 import javax.script.ScriptException;
+import javax.script.SimpleBindings;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashSet;
@@ -61,11 +62,12 @@ public class GremlinGroovyScriptEngineOverGraphTest extends AbstractGremlinTest
     public void shouldDoSomeGremlin() throws Exception {
         final ScriptEngine engine = new GremlinGroovyScriptEngine();
         final List list = new ArrayList();
-        engine.put("g", g);
-        engine.put("marko", convertToVertexId("marko"));
-        engine.put("temp", list);
+        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)");
+        engine.eval("g.V(marko).out().fill(temp)",bindings);
         assertEquals(list.size(), 3);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4b60ff08/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/TinkerGraphProvider.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/TinkerGraphProvider.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/TinkerGraphProvider.java
index fd3c160..fcb5fe6 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/TinkerGraphProvider.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/TinkerGraphProvider.java
@@ -100,14 +100,14 @@ public class TinkerGraphProvider extends AbstractGraphProvider {
     /**
      * Determines if a test requires TinkerGraph persistence to be configured with graph location and format.
      */
-    private static boolean requiresPersistence(final Class<?> test, final String testMethodName) {
+    protected static boolean requiresPersistence(final Class<?> test, final String testMethodName) {
         return test == GraphTest.class && testMethodName.equals("shouldPersistDataOnClose");
     }
 
     /**
      * Determines if a test requires a different cardinality as the default or not.
      */
-    private static boolean requiresListCardinalityAsDefault(final LoadGraphWith.GraphData loadGraphWith,
+    protected static boolean requiresListCardinalityAsDefault(final LoadGraphWith.GraphData loadGraphWith,
                                                             final Class<?> test, final String testMethodName) {
         return loadGraphWith == LoadGraphWith.GraphData.CREW
                 || (test == StarGraphTest.class && testMethodName.equals("shouldAttachWithCreateMethod"))
@@ -117,7 +117,7 @@ public class TinkerGraphProvider extends AbstractGraphProvider {
     /**
      * Some tests require special configuration for TinkerGraph to properly configure the id manager.
      */
-    private TinkerGraph.DefaultIdManager selectIdMakerFromTest(final Class<?> test, final String testMethodName) {
+    protected TinkerGraph.DefaultIdManager selectIdMakerFromTest(final Class<?> test, final String testMethodName) {
         if (test.equals(GraphTest.class)) {
             final Set<String> testsThatNeedLongIdManager = new HashSet<String>(){{
                 add("shouldIterateVerticesWithNumericIdSupportUsingDoubleRepresentation");
@@ -180,7 +180,7 @@ public class TinkerGraphProvider extends AbstractGraphProvider {
      * Test that load with specific graph data can be configured with a specific id manager as the data type to
      * be used in the test for that graph is known.
      */
-    private TinkerGraph.DefaultIdManager selectIdMakerFromGraphData(final LoadGraphWith.GraphData loadGraphWith) {
+    protected TinkerGraph.DefaultIdManager selectIdMakerFromGraphData(final LoadGraphWith.GraphData loadGraphWith) {
         if (null == loadGraphWith) return TinkerGraph.DefaultIdManager.ANY;
         if (loadGraphWith.equals(LoadGraphWith.GraphData.CLASSIC))
             return TinkerGraph.DefaultIdManager.INTEGER;

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4b60ff08/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/TinkerGraphUUIDProvider.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/TinkerGraphUUIDProvider.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/TinkerGraphUUIDProvider.java
new file mode 100644
index 0000000..6025fe9
--- /dev/null
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/TinkerGraphUUIDProvider.java
@@ -0,0 +1,57 @@
+/*
+ * 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.tinkergraph;
+
+import org.apache.tinkerpop.gremlin.LoadGraphWith;
+import org.apache.tinkerpop.gremlin.TestHelper;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class TinkerGraphUUIDProvider extends TinkerGraphProvider {
+
+    @Override
+    public Map<String, Object> getBaseConfiguration(final String graphName, final Class<?> test, final String testMethodName,
+                                                    final LoadGraphWith.GraphData loadGraphWith) {
+        final TinkerGraph.DefaultIdManager idManager = TinkerGraph.DefaultIdManager.UUID;
+        final String idMaker = idManager.name();
+        return new HashMap<String, Object>() {{
+            put(Graph.GRAPH, TinkerGraph.class.getName());
+            put(TinkerGraph.GREMLIN_TINKERGRAPH_VERTEX_ID_MANAGER, idMaker);
+            put(TinkerGraph.GREMLIN_TINKERGRAPH_EDGE_ID_MANAGER, idMaker);
+            put(TinkerGraph.GREMLIN_TINKERGRAPH_VERTEX_PROPERTY_ID_MANAGER, idMaker);
+            if (requiresListCardinalityAsDefault(loadGraphWith, test, testMethodName))
+                put(TinkerGraph.GREMLIN_TINKERGRAPH_DEFAULT_VERTEX_PROPERTY_CARDINALITY, VertexProperty.Cardinality.list.name());
+            if (requiresPersistence(test, testMethodName)) {
+                put(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_FORMAT, "gryo");
+                final File tempDir = TestHelper.makeTestDataPath(test, "temp");
+                put(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_LOCATION,
+                        tempDir.getAbsolutePath() + File.separator + testMethodName + ".kryo");
+            }
+        }};
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4b60ff08/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/groovy/TinkerGraphUUIDGroovyEnvironmentTest.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/groovy/TinkerGraphUUIDGroovyEnvironmentTest.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/groovy/TinkerGraphUUIDGroovyEnvironmentTest.java
new file mode 100644
index 0000000..a3dfad7
--- /dev/null
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/groovy/TinkerGraphUUIDGroovyEnvironmentTest.java
@@ -0,0 +1,38 @@
+/*
+ * 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.tinkergraph.structure.groovy;
+
+import org.apache.tinkerpop.gremlin.GraphProviderClass;
+import org.apache.tinkerpop.gremlin.groovy.GroovyEnvironmentSuite;
+import org.apache.tinkerpop.gremlin.groovy.loaders.SugarLoader;
+import org.apache.tinkerpop.gremlin.tinkergraph.TinkerGraphUUIDProvider;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
+import org.junit.runner.RunWith;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+@RunWith(GroovyEnvironmentSuite.class)
+@GraphProviderClass(provider = TinkerGraphUUIDProvider.class, graph = TinkerGraph.class)
+public class TinkerGraphUUIDGroovyEnvironmentTest {
+    static {
+        SugarLoader.load();
+    }
+}
\ No newline at end of file