You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by fl...@apache.org on 2022/01/27 08:31:29 UTC

[tinkerpop] branch master updated: Fixing .NET test failures and adding Gherkin support for VertexProperty.

This is an automated email from the ASF dual-hosted git repository.

florianhockmann pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git


The following commit(s) were added to refs/heads/master by this push:
     new 0d1d471  Fixing .NET test failures and adding Gherkin support for VertexProperty.
     new 0357a90  Merge pull request #1551 from mikepersonick/TINKERPOP-2688
0d1d471 is described below

commit 0d1d471eb0b2dacbede483ba8ad1388d5b19809e
Author: Mike Personick <mi...@supersonick.io>
AuthorDate: Tue Jan 18 09:13:20 2022 -0700

    Fixing .NET test failures and adding Gherkin support for VertexProperty.
    
      https://issues.apache.org/jira/browse/TINKERPOP-2688
      https://issues.apache.org/jira/browse/TINKERPOP-2689
---
 .../src/Gremlin.Net/Process/Traversal/Lambda.cs    | 11 ++++
 .../Process/Traversal/StringBasedLambda.cs         |  6 ++
 .../Gherkin/CommonSteps.cs                         |  6 ++
 .../Gherkin/GherkinTestRunner.cs                   |  4 +-
 .../Gherkin/IgnoreException.cs                     |  7 +-
 .../Gherkin/ScenarioData.cs                        | 77 ++++++++++++++++++++--
 .../Process/Remote/RemoteStrategyTests.cs          |  2 +-
 .../BytecodeGeneration/StrategiesTests.cs          |  2 +-
 .../DriverRemoteConnection/StrategiesTests.cs      |  2 +-
 .../Process/Traversal/TestTraversal.cs             |  2 +-
 .../Process/Traversal/TestTraversalStrategy.cs     |  2 +-
 .../src/test/scripts/generate-all.groovy           | 10 +--
 .../src/test/scripts/tinkergraph-empty.properties  |  2 +-
 .../tinkergraph/structure/TinkerFactory.java       | 24 +++----
 14 files changed, 121 insertions(+), 36 deletions(-)

diff --git a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Lambda.cs b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Lambda.cs
index 01bdbc6..6f73892 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Lambda.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Lambda.cs
@@ -61,6 +61,17 @@ namespace Gremlin.Net.Process.Traversal
         }
 
         /// <summary>
+        ///     Creates a new Groovy lambda with the specified number of lambda arguments.
+        /// </summary>
+        /// <param name="expression">The lambda expression.</param>
+        /// <param name="arguments">The number of lambda arguments.</param>
+        /// <returns>The created lambda.</returns>
+        public static ILambda Groovy(string expression, int arguments)
+        {
+            return new GroovyStringBasedLambda(expression, arguments);
+        }
+
+        /// <summary>
         ///     Creates a new Python lambda.
         /// </summary>
         /// <param name="expression">The lambda expression.</param>
diff --git a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/StringBasedLambda.cs b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/StringBasedLambda.cs
index 69f8030..f4bc51c 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/StringBasedLambda.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/StringBasedLambda.cs
@@ -51,5 +51,11 @@ namespace Gremlin.Net.Process.Traversal
             var args = expression.Substring(0, expression.IndexOf("->", StringComparison.Ordinal));
             Arguments = args.Contains(",") ? 2 : 1;
         }
+        
+        public GroovyStringBasedLambda(string expression, int arguments) : base(expression, "gremlin-groovy")
+        {
+            Arguments = arguments;
+        }
+
     }
 }
\ No newline at end of file
diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/CommonSteps.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/CommonSteps.cs
index 03b429a..7427646 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/CommonSteps.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/CommonSteps.cs
@@ -56,6 +56,7 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
         private static readonly IDictionary<Regex, Func<string, string, object>> Parsers =
             new Dictionary<string, Func<string, string, object>>
             {
+                {@"vp\[(.+)\]", ToVertexProperty},
                 {@"d\[(.*)\]\.([bsilfdmn])", ToNumber},
                 {@"D\[(.+)\]", ToDirection},
                 {@"v\[(.+)\]", ToVertex},
@@ -387,6 +388,11 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
             return ScenarioData.GetByGraphName(graphName).Edges[name];
         }
 
+        private static VertexProperty ToVertexProperty(string triplet, string graphName)
+        {
+            return ScenarioData.GetByGraphName(graphName).VertexProperties[triplet];
+        }
+
         private static Path ToPath(string value, string graphName)
         {
             return new Path(new List<ISet<string>>(0), value.Split(',').Select(x => ParseValue(x, graphName)).ToList());
diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs
index a8d8fe0..18b4fca 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs
@@ -84,9 +84,7 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
                 {
                     "g_V_hasXperson_name_markoX_bothXknowsX_groupCount_byXvaluesXnameX_foldX",
                     IgnoreReason.ArrayKeysInMapNotAssertingInGherkin
-                },
-                {"g_V_properties_order", IgnoreReason.VertexPropertyNotSupportedInGherkin},
-                {"g_V_properties_order_id", IgnoreReason.VertexPropertyNotSupportedInGherkin},
+                }
             };
 
         private static class Keywords
diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/IgnoreException.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/IgnoreException.cs
index 2fa881b..e025e2f 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/IgnoreException.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/IgnoreException.cs
@@ -65,11 +65,6 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
         /// <summary>
         /// The GLV suite does not test against a graph that has null property values enabled.
         /// </summary>
-        NullPropertyValuesNotSupportedOnTestGraph,
-
-        /// <summary>
-        /// Need a Gherkin parser for VertexProperty results: https://issues.apache.org/jira/browse/TINKERPOP-2686
-        /// </summary>
-        VertexPropertyNotSupportedInGherkin
+        NullPropertyValuesNotSupportedOnTestGraph
     }
 }
\ No newline at end of file
diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/ScenarioData.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/ScenarioData.cs
index 99731fe..b7660c3 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/ScenarioData.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/ScenarioData.cs
@@ -47,6 +47,9 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
         private static readonly IDictionary<string, Edge> EmptyEdges =
             new ReadOnlyDictionary<string, Edge>(new Dictionary<string, Edge>());
         
+        private static readonly IDictionary<string, VertexProperty> EmptyVertexProperties =
+            new ReadOnlyDictionary<string, VertexProperty>(new Dictionary<string, VertexProperty>());
+        
         private readonly RemoteConnectionFactory _connectionFactory;
 
         public Scenario CurrentScenario;
@@ -77,6 +80,7 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
             var g = Traversal().WithRemote(graphData.Connection);
             graphData.Vertices = GetVertices(g);
             graphData.Edges = GetEdges(g);
+            graphData.VertexProperties = GetVertexProperties(g);
         }
 
         private readonly IDictionary<string, ScenarioDataPerGraph> _dataPerGraph;
@@ -86,7 +90,7 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
             _connectionFactory = new RemoteConnectionFactory(messageSerializer);
             _dataPerGraph = LoadDataPerGraph();
             var empty = new ScenarioDataPerGraph("empty", _connectionFactory.CreateRemoteConnection("ggraph"),
-                new Dictionary<string, Vertex>(0), new Dictionary<string, Edge>());
+                new Dictionary<string, Vertex>(0), new Dictionary<string, Edge>(), new Dictionary<string, VertexProperty>());
             _dataPerGraph.Add("empty", empty);
         }
 
@@ -96,7 +100,7 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
             {
                 var connection = _connectionFactory.CreateRemoteConnection($"g{name}");
                 var g = Traversal().WithRemote(connection);
-                return new ScenarioDataPerGraph(name, connection, GetVertices(g), GetEdges(g));
+                return new ScenarioDataPerGraph(name, connection, GetVertices(g), GetEdges(g), GetVertexProperties(g));
             }).ToDictionary(x => x.Name);
         }
 
@@ -119,7 +123,7 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
             try
             {
                 IFunction lambda = Lambda.Groovy(
-                    "it.outVertex().value('name') + '-' + it.label() + '->' + it.inVertex().value('name')");
+                    "it.outVertex().value('name') + '-' + it.label() + '->' + it.inVertex().value('name')", 1);
 
                 return g.E().Group<string, Edge>()
                     .By(lambda)
@@ -133,6 +137,68 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
             }
         }
 
+        private static IDictionary<string, VertexProperty> GetVertexProperties(GraphTraversalSource g)
+        {
+            try
+            {
+                /*
+                 * This closure will turn a VertexProperty into a triple string of the form:
+                 * "vertexName-propKey->propVal"
+                 *
+                 * It will also take care of wrapping propVal in the appropriate Numeric format. We must do this in
+                 * case a Vertex has multiple properties with the same key and number value but in different numeric
+                 * type spaces (rare, but possible, and presumably something we may want to write tests around).
+                 */
+                var groovy = @"
+                    { vp ->
+                          def result = vp.element().value('name') + '-' + vp.key() + '->'
+                          def value = vp.value()
+                          def type = ''
+                          switch(value) {
+                            case { !(it instanceof Number) }:
+                              return result + value
+                            case Byte:
+                              type = 'b'
+                              break
+                            case Short:
+                              type = 's'
+                              break
+                            case Integer:
+                              type = 'i'
+                              break
+                            case Long:
+                              type = 'l'
+                              break
+                            case Float:
+                              type = 'f'
+                              break
+                            case Double:
+                              type = 'd'
+                              break
+                            case BigDecimal:
+                              type = 'm'
+                              break
+                            case BigInteger:
+                              type = 'n'
+                              break
+                          }
+                          return result + 'd[' + value + '].' + type
+                    }  
+                ";
+                
+                IFunction lambda = Lambda.Groovy(groovy, 1);
+
+                return g.V().Properties<VertexProperty>().Group<string, VertexProperty>()
+                    .By(lambda)
+                    .By(__.Tail<object>())
+                    .Next();
+            }
+            catch (ResponseException)
+            {
+                return EmptyVertexProperties;
+            }
+        }
+
         public void Dispose()
         {
             _connectionFactory?.Dispose();
@@ -142,12 +208,13 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
     internal class ScenarioDataPerGraph
     {
         public ScenarioDataPerGraph(string name, IRemoteConnection connection, IDictionary<string, Vertex> vertices,
-                                    IDictionary<string, Edge> edges)
+                                    IDictionary<string, Edge> edges, IDictionary<string, VertexProperty> vertexProperties)
         {
             Name = name;
             Connection = connection;
             Vertices = vertices;
             Edges = edges;
+            VertexProperties = vertexProperties;
         }
 
         public string Name { get; }
@@ -157,5 +224,7 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
         public IDictionary<string, Vertex> Vertices { get; set; }
         
         public IDictionary<string, Edge> Edges { get; set; }
+        
+        public IDictionary<string, VertexProperty> VertexProperties { get; set; }
     }
 }
\ No newline at end of file
diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Remote/RemoteStrategyTests.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Remote/RemoteStrategyTests.cs
index 5c24346..f01116d 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Remote/RemoteStrategyTests.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Remote/RemoteStrategyTests.cs
@@ -1,4 +1,4 @@
-#region License
+#region License
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Traversal/BytecodeGeneration/StrategiesTests.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Traversal/BytecodeGeneration/StrategiesTests.cs
index 54dae02..b3bf672 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Traversal/BytecodeGeneration/StrategiesTests.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Traversal/BytecodeGeneration/StrategiesTests.cs
@@ -1,4 +1,4 @@
-#region License
+#region License
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Traversal/DriverRemoteConnection/StrategiesTests.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Traversal/DriverRemoteConnection/StrategiesTests.cs
index 14c59f9..a5002f5 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Traversal/DriverRemoteConnection/StrategiesTests.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Traversal/DriverRemoteConnection/StrategiesTests.cs
@@ -1,4 +1,4 @@
-#region License
+#region License
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
diff --git a/gremlin-dotnet/test/Gremlin.Net.UnitTest/Process/Traversal/TestTraversal.cs b/gremlin-dotnet/test/Gremlin.Net.UnitTest/Process/Traversal/TestTraversal.cs
index c1b87a0..51aac86 100644
--- a/gremlin-dotnet/test/Gremlin.Net.UnitTest/Process/Traversal/TestTraversal.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.UnitTest/Process/Traversal/TestTraversal.cs
@@ -1,4 +1,4 @@
-#region License
+#region License
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
diff --git a/gremlin-dotnet/test/Gremlin.Net.UnitTest/Process/Traversal/TestTraversalStrategy.cs b/gremlin-dotnet/test/Gremlin.Net.UnitTest/Process/Traversal/TestTraversalStrategy.cs
index ded419d..f908789 100644
--- a/gremlin-dotnet/test/Gremlin.Net.UnitTest/Process/Traversal/TestTraversalStrategy.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.UnitTest/Process/Traversal/TestTraversalStrategy.cs
@@ -1,4 +1,4 @@
-#region License
+#region License
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
diff --git a/gremlin-server/src/test/scripts/generate-all.groovy b/gremlin-server/src/test/scripts/generate-all.groovy
index 464f673..bf4725b 100644
--- a/gremlin-server/src/test/scripts/generate-all.groovy
+++ b/gremlin-server/src/test/scripts/generate-all.groovy
@@ -35,20 +35,20 @@ globals << [hook : [
     // to have a special test TinkerGraph config for setting up the id manager properly, but based on how we do
     // things now, that test config would have been mixed in with release artifacts and there would have been ugly
     // exclusions to make packaging work properly.
-    allowSetOfIdManager = { graph, idManagerFieldName ->
+    allowSetOfIdManager = { graph, idManagerFieldName, idManager ->
         java.lang.reflect.Field idManagerField = graph.class.getDeclaredField(idManagerFieldName)
         idManagerField.setAccessible(true)
         java.lang.reflect.Field modifiersField = java.lang.reflect.Field.class.getDeclaredField("modifiers")
         modifiersField.setAccessible(true)
         modifiersField.setInt(idManagerField, modifiersField.getModifiers() & ~java.lang.reflect.Modifier.FINAL)
 
-        idManagerField.set(graph, TinkerGraph.DefaultIdManager.INTEGER)
+        idManagerField.set(graph, idManager)
     }
 
     [classic, modern, crew, sink, grateful].each{
-      allowSetOfIdManager(it, "vertexIdManager")
-      allowSetOfIdManager(it, "edgeIdManager")
-      allowSetOfIdManager(it, "vertexPropertyIdManager")
+      allowSetOfIdManager(it, "vertexIdManager", TinkerGraph.DefaultIdManager.INTEGER)
+      allowSetOfIdManager(it, "edgeIdManager", TinkerGraph.DefaultIdManager.INTEGER)
+      allowSetOfIdManager(it, "vertexPropertyIdManager", TinkerGraph.DefaultIdManager.LONG)
     }
     TinkerFactory.generateClassic(classic)
     TinkerFactory.generateModern(modern)
diff --git a/gremlin-server/src/test/scripts/tinkergraph-empty.properties b/gremlin-server/src/test/scripts/tinkergraph-empty.properties
index 211b9e4..591516b 100644
--- a/gremlin-server/src/test/scripts/tinkergraph-empty.properties
+++ b/gremlin-server/src/test/scripts/tinkergraph-empty.properties
@@ -17,4 +17,4 @@
 gremlin.graph=org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph
 gremlin.tinkergraph.vertexIdManager=INTEGER
 gremlin.tinkergraph.edgeIdManager=INTEGER
-gremlin.tinkergraph.vertexPropertyIdManager=INTEGER
\ No newline at end of file
+gremlin.tinkergraph.vertexPropertyIdManager=LONG
\ No newline at end of file
diff --git a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerFactory.java b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerFactory.java
index df939ec..159303c 100644
--- a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerFactory.java
+++ b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerFactory.java
@@ -88,23 +88,23 @@ public final class TinkerFactory {
      */
     public static void generateModern(final TinkerGraph g) {
         final Vertex marko = g.addVertex(T.id, 1, T.label, "person");
-        marko.property("name", "marko", T.id, 0);
-        marko.property("age", 29, T.id, 1);
+        marko.property("name", "marko", T.id, 0l);
+        marko.property("age", 29, T.id, 1l);
         final Vertex vadas = g.addVertex(T.id, 2, T.label, "person");
-        vadas.property("name", "vadas", T.id, 2);
-        vadas.property("age", 27, T.id, 3);
+        vadas.property("name", "vadas", T.id, 2l);
+        vadas.property("age", 27, T.id, 3l);
         final Vertex lop = g.addVertex(T.id, 3, T.label, "software");
-        lop.property("name", "lop", T.id, 4);
-        lop.property("lang", "java", T.id, 5);
+        lop.property("name", "lop", T.id, 4l);
+        lop.property("lang", "java", T.id, 5l);
         final Vertex josh = g.addVertex(T.id, 4, T.label, "person");
-        josh.property("name", "josh", T.id, 6);
-        josh.property("age", 32, T.id, 7);
+        josh.property("name", "josh", T.id, 6l);
+        josh.property("age", 32, T.id, 7l);
         final Vertex ripple = g.addVertex(T.id, 5, T.label, "software");
-        ripple.property("name", "ripple", T.id, 8);
-        ripple.property("lang", "java", T.id, 9);
+        ripple.property("name", "ripple", T.id, 8l);
+        ripple.property("lang", "java", T.id, 9l);
         final Vertex peter = g.addVertex(T.id, 6, T.label, "person");
-        peter.property("name", "peter", T.id, 10);
-        peter.property("age", 35, T.id, 11);
+        peter.property("name", "peter", T.id, 10l);
+        peter.property("age", 35, T.id, 11l);
 
         marko.addEdge("knows", vadas, T.id, 7, "weight", 0.5d);
         marko.addEdge("knows", josh, T.id, 8, "weight", 1.0d);