tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ok...@apache.org
Subject [05/14] tinkerpop git commit: Add ClassSerializer for withoutStrategies TINKERPOP-1752
Date Mon, 06 Nov 2017 16:26:43 GMT
Add ClassSerializer for withoutStrategies TINKERPOP-1752

withoutStrategies() expects Types of the Strategies as its arguments which needs this ClassSerializer.
I also found a test that was commented out which I uncommented as it works now again with
the new Bindings implementation.


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

Branch: refs/heads/TINKERPOP-1802
Commit: 31cf263493c723c8f37c8e837442a63136328a1f
Parents: 1bfca40
Author: florianhockmann <fh@florian-hockmann.de>
Authored: Wed Oct 18 17:26:37 2017 +0200
Committer: florianhockmann <fh@florian-hockmann.de>
Committed: Wed Oct 18 17:26:37 2017 +0200

----------------------------------------------------------------------
 docs/src/reference/gremlin-variants.asciidoc    |  2 +-
 .../Decoration/HaltedTraverserStrategy.cs       |  4 +++
 .../Strategy/Decoration/PartitionStrategy.cs    |  7 ++++
 .../Strategy/Decoration/SubgraphStrategy.cs     |  7 ++++
 .../Decoration/VertexProgramStrategy.cs         |  4 +++
 .../Finalization/MatchAlgorithmStrategy.cs      |  4 +++
 .../Structure/IO/GraphSON/ClassSerializer.cs    | 37 ++++++++++++++++++++
 .../Structure/IO/GraphSON/GraphSONWriter.cs     |  1 +
 .../GraphTraversalTests.cs                      | 24 ++++++-------
 .../DriverRemoteConnection/StrategiesTests.cs   | 14 ++++++++
 .../Process/Traversal/Strategy/StrategyTests.cs | 31 ++++++++++++++++
 .../IO/GraphSON/GraphSONWriterTests.cs          | 13 +++++++
 12 files changed, 135 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/31cf2634/docs/src/reference/gremlin-variants.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/gremlin-variants.asciidoc b/docs/src/reference/gremlin-variants.asciidoc
index 85fd1aa..c5f0f54 100644
--- a/docs/src/reference/gremlin-variants.asciidoc
+++ b/docs/src/reference/gremlin-variants.asciidoc
@@ -470,7 +470,7 @@ g = g.WithStrategies(new SubgraphStrategy(vertexCriterion: HasLabel("person"),
     edgeCriterion: Has("weight", Gt(0.5))));
 var names = g.V().Values("name").ToList();  // names: [marko, vadas, josh, peter]
 
-g = g.WithoutStrategies(new SubgraphStrategy());
+g = g.WithoutStrategies(typeof(SubgraphStrategy));
 names = g.V().Values("name").ToList(); // names: [marko, vadas, lop, josh, ripple, peter]
 
 var edgeValueMaps = g.V().OutE().ValueMap(true).ToList();

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/31cf2634/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Strategy/Decoration/HaltedTraverserStrategy.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Strategy/Decoration/HaltedTraverserStrategy.cs
b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Strategy/Decoration/HaltedTraverserStrategy.cs
index 688ef92..f93dcb2 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Strategy/Decoration/HaltedTraverserStrategy.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Strategy/Decoration/HaltedTraverserStrategy.cs
@@ -26,6 +26,10 @@ namespace Gremlin.Net.Process.Traversal.Strategy.Decoration
 #pragma warning disable 1591
     public class HaltedTraverserStrategy : AbstractTraversalStrategy
     {
+        public HaltedTraverserStrategy()
+        {
+        }
+
         public HaltedTraverserStrategy(string haltedTraverserFactoryName = null)
         {
             if (haltedTraverserFactoryName != null)

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/31cf2634/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Strategy/Decoration/PartitionStrategy.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Strategy/Decoration/PartitionStrategy.cs
b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Strategy/Decoration/PartitionStrategy.cs
index f89037b..729c63c 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Strategy/Decoration/PartitionStrategy.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Strategy/Decoration/PartitionStrategy.cs
@@ -33,6 +33,13 @@ namespace Gremlin.Net.Process.Traversal.Strategy.Decoration
         /// <summary>
         ///     Initializes a new instance of the <see cref="PartitionStrategy" />
class.
         /// </summary>
+        public PartitionStrategy()
+        {
+        }
+
+        /// <summary>
+        ///     Initializes a new instance of the <see cref="PartitionStrategy" />
class.
+        /// </summary>
         /// <param name="partitionKey">Specifies the partition key name.</param>
         /// <param name="writePartition">
         ///     Specifies the name of the partition to write when adding vertices, edges
and vertex

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/31cf2634/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Strategy/Decoration/SubgraphStrategy.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Strategy/Decoration/SubgraphStrategy.cs
b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Strategy/Decoration/SubgraphStrategy.cs
index 2f0d23e..1ba87d0 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Strategy/Decoration/SubgraphStrategy.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Strategy/Decoration/SubgraphStrategy.cs
@@ -31,6 +31,13 @@ namespace Gremlin.Net.Process.Traversal.Strategy.Decoration
         /// <summary>
         ///     Initializes a new instance of the <see cref="SubgraphStrategy" /> class.
         /// </summary>
+        public SubgraphStrategy()
+        {
+        }
+
+        /// <summary>
+        ///     Initializes a new instance of the <see cref="SubgraphStrategy" /> class.
+        /// </summary>
         /// <param name="vertexCriterion">Constrains vertices for the <see cref="ITraversal"
/>.</param>
         /// <param name="edgeCriterion">Constrains edges for the <see cref="ITraversal"
/>.</param>
         /// <param name="vertexPropertyCriterion">Constrains vertex properties for
the <see cref="ITraversal" />.</param>

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/31cf2634/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Strategy/Decoration/VertexProgramStrategy.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Strategy/Decoration/VertexProgramStrategy.cs
b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Strategy/Decoration/VertexProgramStrategy.cs
index 61df1c1..edacf60 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Strategy/Decoration/VertexProgramStrategy.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Strategy/Decoration/VertexProgramStrategy.cs
@@ -29,6 +29,10 @@ namespace Gremlin.Net.Process.Traversal.Strategy.Decoration
 #pragma warning disable 1591
     public class VertexProgramStrategy : AbstractTraversalStrategy
     {
+        public VertexProgramStrategy()
+        {
+        }
+
         public VertexProgramStrategy(string graphComputer = null, int? workers = null, string
persist = null,
             string result = null, ITraversal vertices = null, ITraversal edges = null,
             Dictionary<string, dynamic> configuration = null)

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/31cf2634/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Strategy/Finalization/MatchAlgorithmStrategy.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Strategy/Finalization/MatchAlgorithmStrategy.cs
b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Strategy/Finalization/MatchAlgorithmStrategy.cs
index d066c8a..96de864 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Strategy/Finalization/MatchAlgorithmStrategy.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Strategy/Finalization/MatchAlgorithmStrategy.cs
@@ -26,6 +26,10 @@ namespace Gremlin.Net.Process.Traversal.Strategy.Finalization
 #pragma warning disable 1591
     public class MatchAlgorithmStrategy : AbstractTraversalStrategy
     {
+        public MatchAlgorithmStrategy()
+        {
+        }
+
         public MatchAlgorithmStrategy(string matchAlgorithm = null)
         {
             if (matchAlgorithm != null)

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/31cf2634/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/ClassSerializer.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/ClassSerializer.cs b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/ClassSerializer.cs
new file mode 100644
index 0000000..39d1abe
--- /dev/null
+++ b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/ClassSerializer.cs
@@ -0,0 +1,37 @@
+#region License
+
+/*
+ * 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.
+ */
+
+#endregion
+
+using System;
+using System.Collections.Generic;
+
+namespace Gremlin.Net.Structure.IO.GraphSON
+{
+    internal class ClassSerializer : IGraphSONSerializer
+    {
+        public Dictionary<string, dynamic> Dictify(dynamic objectData, GraphSONWriter
writer)
+        {
+            var type = (Type) objectData;
+            return writer.ToDict(Activator.CreateInstance(type));
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/31cf2634/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/GraphSONWriter.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/GraphSONWriter.cs b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/GraphSONWriter.cs
index ba632b1..3c17d14 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/GraphSONWriter.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/GraphSONWriter.cs
@@ -51,6 +51,7 @@ namespace Gremlin.Net.Structure.IO.GraphSON
                 {typeof(double), new DoubleConverter()},
                 {typeof(Guid), new UuidSerializer()},
                 {typeof(DateTime), new DateSerializer()},
+                {typeof(Type), new ClassSerializer()},
                 {typeof(Enum), new EnumSerializer()},
                 {typeof(TraversalPredicate), new TraversalPredicateSerializer()},
                 {typeof(Vertex), new VertexSerializer()},

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/31cf2634/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Traversal/DriverRemoteConnection/GraphTraversalTests.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Traversal/DriverRemoteConnection/GraphTraversalTests.cs
b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Traversal/DriverRemoteConnection/GraphTraversalTests.cs
index 3c98904..84a44a7 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Traversal/DriverRemoteConnection/GraphTraversalTests.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Traversal/DriverRemoteConnection/GraphTraversalTests.cs
@@ -141,18 +141,18 @@ namespace Gremlin.Net.IntegrationTest.Process.Traversal.DriverRemoteConnection
             Assert.Equal(new Vertex((long) 6), shortestPath[3]);
         }
 
-        //[Fact]
-        //public void ShouldUseBindingsInTraversal()
-        //{
-        //    var graph = new Graph();
-        //    var connection = _connectionFactory.CreateRemoteConnection();
-        //    var g = graph.Traversal().WithRemote(connection);
-
-        //    var b = new Bindings();
-        //    var count = g.V().Has(b.Of("propertyKey", "name"), b.Of("propertyValue", "marko")).OutE().Count().Next();
-
-        //    Assert.Equal(3, count);
-        //}
+        [Fact]
+        public void ShouldUseBindingsInTraversal()
+        {
+            var graph = new Graph();
+            var connection = _connectionFactory.CreateRemoteConnection();
+            var g = graph.Traversal().WithRemote(connection);
+
+            var b = new Bindings();
+            var count = g.V().Has(b.Of("propertyKey", "name"), b.Of("propertyValue", "marko")).OutE().Count().Next();
+
+            Assert.Equal(3, count);
+        }
 
         [Fact]
         public async Task ShouldExecuteAsynchronouslyWhenPromiseIsCalled()

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/31cf2634/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Traversal/DriverRemoteConnection/StrategiesTests.cs
----------------------------------------------------------------------
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 21aee57..2e99778 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
@@ -189,5 +189,19 @@ namespace Gremlin.Net.IntegrationTest.Process.Traversal.DriverRemoteConnection
 
             await Assert.ThrowsAsync<ResponseException>(async () => await g.AddV("person").Promise(t
=> t.Next()));
         }
+
+        [Fact]
+        public void WithoutStrategiesShouldNeutralizeWithStrategy()
+        {
+            var graph = new Graph();
+            var connection = _connectionFactory.CreateRemoteConnection();
+            var g = graph.Traversal().WithRemote(connection)
+                .WithStrategies(new SubgraphStrategy(vertexCriterion: __.HasLabel("person")))
+                .WithoutStrategies(typeof(SubgraphStrategy));
+
+            var count = g.V().Count().Next();
+
+            Assert.Equal(6, count);
+        }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/31cf2634/gremlin-dotnet/test/Gremlin.Net.UnitTest/Process/Traversal/Strategy/StrategyTests.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/test/Gremlin.Net.UnitTest/Process/Traversal/Strategy/StrategyTests.cs
b/gremlin-dotnet/test/Gremlin.Net.UnitTest/Process/Traversal/Strategy/StrategyTests.cs
index 47adb29..fcb7cc3 100644
--- a/gremlin-dotnet/test/Gremlin.Net.UnitTest/Process/Traversal/Strategy/StrategyTests.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.UnitTest/Process/Traversal/Strategy/StrategyTests.cs
@@ -21,6 +21,10 @@
 
 #endregion
 
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
 using Gremlin.Net.Process.Traversal.Strategy;
 using Gremlin.Net.Process.Traversal.Strategy.Optimization;
 using Gremlin.Net.Process.Traversal.Strategy.Verification;
@@ -93,6 +97,33 @@ namespace Gremlin.Net.UnitTest.Process.Traversal.Strategy
 
             Assert.Equal("TestStrategy", strategyStr);
         }
+
+        [Fact]
+        public void AllStrategiesShouldHaveADefaultConstructor()
+        {
+            // We need a default constructor as the ClassWriter needs that for serialization
+            foreach (var type in _allStrategyTypes)
+            {
+                Assert.True(HasParameterlessConstructor(type), $"{type} has no parameterless
constructor");
+            }
+        }
+
+        private readonly IEnumerable<Type> _allStrategyTypes = typeof(AbstractTraversalStrategy).GetTypeInfo().Assembly
+            .GetTypes().Where(t => typeof(AbstractTraversalStrategy).IsAssignableFrom(t))
+            .Where(t => t != typeof(AbstractTraversalStrategy));
+
+        private bool HasParameterlessConstructor(Type type)
+        {
+            try
+            {
+                Activator.CreateInstance(type);
+                return true;
+            }
+            catch (Exception)
+            {
+                return false;
+            }
+        }
     }
 
     internal class TestStrategy : AbstractTraversalStrategy

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/31cf2634/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONWriterTests.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONWriterTests.cs
b/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONWriterTests.cs
index 77af255..4cd831f 100644
--- a/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONWriterTests.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONWriterTests.cs
@@ -24,6 +24,7 @@
 using System;
 using System.Collections.Generic;
 using Gremlin.Net.Process.Traversal;
+using Gremlin.Net.Process.Traversal.Strategy.Decoration;
 using Gremlin.Net.Structure;
 using Gremlin.Net.Structure.IO.GraphSON;
 using Moq;
@@ -310,6 +311,18 @@ namespace Gremlin.Net.UnitTest.Structure.IO.GraphSON
                 "{\"@type\":\"g:Vertex\",\"@value\":{\"id\":{\"@type\":\"g:Int64\",\"@value\":123},\"label\":\"project\"}}";
             Assert.Equal(expected, graphSON);
         }
+
+        [Fact]
+        public void ShouldSerializeTypeToItsObject()
+        {
+            var writer = CreateStandardGraphSONWriter();
+            var type = typeof(SubgraphStrategy);
+
+            var graphSon = writer.WriteObject(type);
+
+            const string expected = "{\"@type\":\"g:SubgraphStrategy\",\"@value\":{}}";
+            Assert.Equal(expected, graphSon);
+        }
     }
 
     internal class TestGraphSONSerializer : IGraphSONSerializer


Mime
View raw message