You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by jo...@apache.org on 2017/12/05 13:09:03 UTC
[1/3] tinkerpop git commit: Gremlin.Net: Use DateTimeOffset for
g:Date and g:Timestamp
Repository: tinkerpop
Updated Branches:
refs/heads/master fa0a0ee64 -> 1c041d1bb
Gremlin.Net: Use DateTimeOffset for g:Date and g:Timestamp
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/f1153077
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/f1153077
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/f1153077
Branch: refs/heads/master
Commit: f1153077546bc1226309e1d04273e7912a744532
Parents: be86be0
Author: Jorge Bay Gondra <jo...@gmail.com>
Authored: Fri Dec 1 15:04:26 2017 +0100
Committer: Jorge Bay Gondra <jo...@gmail.com>
Committed: Fri Dec 1 15:04:26 2017 +0100
----------------------------------------------------------------------
.../Structure/IO/GraphSON/DateDeserializer.cs | 43 --------------------
.../Structure/IO/GraphSON/DateSerializer.cs | 16 +++++---
.../Structure/IO/GraphSON/GraphSONReader.cs | 4 +-
.../Structure/IO/GraphSON/GraphSONWriter.cs | 2 +-
.../IO/GraphSON/GraphSONReaderTests.cs | 16 ++++----
.../IO/GraphSON/GraphSONWriterTests.cs | 6 +--
.../Structure/IO/GraphSON/TestUtils.cs | 8 ++--
7 files changed, 28 insertions(+), 67 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f1153077/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/DateDeserializer.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/DateDeserializer.cs b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/DateDeserializer.cs
deleted file mode 100644
index d8879f8..0000000
--- a/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/DateDeserializer.cs
+++ /dev/null
@@ -1,43 +0,0 @@
-#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 Newtonsoft.Json.Linq;
-
-namespace Gremlin.Net.Structure.IO.GraphSON
-{
- internal class DateDeserializer : IGraphSONDeserializer
- {
- public dynamic Objectify(JToken graphsonObject, GraphSONReader reader)
- {
- var javaTimestamp = graphsonObject.ToObject<long>();
- return FromJavaTime(javaTimestamp);
- }
-
- private DateTime FromJavaTime(long javaTimestamp)
- {
- var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
- return epoch.AddMilliseconds(javaTimestamp);
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f1153077/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/DateSerializer.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/DateSerializer.cs b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/DateSerializer.cs
index 1438e02..3333f0c 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/DateSerializer.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/DateSerializer.cs
@@ -23,21 +23,25 @@
using System;
using System.Collections.Generic;
+using Newtonsoft.Json.Linq;
namespace Gremlin.Net.Structure.IO.GraphSON
{
- internal class DateSerializer : IGraphSONSerializer
+ internal class DateSerializer : IGraphSONSerializer, IGraphSONDeserializer
{
+ private static readonly DateTimeOffset UnixStart = new DateTimeOffset(1970, 1, 1, 0, 0, 0, 0, TimeSpan.Zero);
+
public Dictionary<string, dynamic> Dictify(dynamic objectData, GraphSONWriter writer)
{
- DateTime dateTime = objectData;
- return GraphSONUtil.ToTypedValue("Date", ToJavaTimestamp(dateTime));
+ DateTimeOffset value = objectData;
+ var ticks = (value - UnixStart).Ticks;
+ return GraphSONUtil.ToTypedValue("Date", ticks / TimeSpan.TicksPerMillisecond);
}
- private long ToJavaTimestamp(DateTime dateTime)
+ public dynamic Objectify(JToken graphsonObject, GraphSONReader reader)
{
- var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
- return Convert.ToInt64((dateTime - epoch).TotalMilliseconds);
+ var milliseconds = graphsonObject.ToObject<long>();
+ return UnixStart.AddTicks(TimeSpan.TicksPerMillisecond * milliseconds);
}
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f1153077/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/GraphSONReader.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/GraphSONReader.cs b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/GraphSONReader.cs
index aa1fc48..6402c43 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/GraphSONReader.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/GraphSONReader.cs
@@ -42,8 +42,8 @@ namespace Gremlin.Net.Structure.IO.GraphSON
{"g:Float", new FloatConverter()},
{"g:Double", new DoubleConverter()},
{"g:UUID", new UuidDeserializer()},
- {"g:Date", new DateDeserializer()},
- {"g:Timestamp", new DateDeserializer()},
+ {"g:Date", new DateSerializer()},
+ {"g:Timestamp", new DateSerializer()},
{"g:Vertex", new VertexDeserializer()},
{"g:Edge", new EdgeDeserializer()},
{"g:Property", new PropertyDeserializer()},
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f1153077/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 3c17d14..4d99864 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/GraphSONWriter.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/GraphSONWriter.cs
@@ -50,7 +50,7 @@ namespace Gremlin.Net.Structure.IO.GraphSON
{typeof(float), new FloatConverter()},
{typeof(double), new DoubleConverter()},
{typeof(Guid), new UuidSerializer()},
- {typeof(DateTime), new DateSerializer()},
+ {typeof(DateTimeOffset), new DateSerializer()},
{typeof(Type), new ClassSerializer()},
{typeof(Enum), new EnumSerializer()},
{typeof(TraversalPredicate), new TraversalPredicateSerializer()},
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f1153077/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONReaderTests.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONReaderTests.cs b/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONReaderTests.cs
index 747a94e..cb70530 100644
--- a/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONReaderTests.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONReaderTests.cs
@@ -72,15 +72,15 @@ namespace Gremlin.Net.UnitTest.Structure.IO.GraphSON
}
[Fact]
- public void ShouldDeserializeDateToDateTime()
+ public void ShouldDeserializeDateToDateTimeOffset()
{
var graphSon = "{\"@type\":\"g:Date\",\"@value\":1475583442552}";
var reader = CreateStandardGraphSONReader();
- DateTime readDateTime = reader.ToObject(JObject.Parse(graphSon));
+ DateTimeOffset deserializedValue = reader.ToObject(JObject.Parse(graphSon));
- var expectedDateTime = TestUtils.FromJavaTime(1475583442552);
- Assert.Equal(expectedDateTime, readDateTime);
+ var expectedDateTimeOffset = TestUtils.FromJavaTime(1475583442552);
+ Assert.Equal(expectedDateTimeOffset, deserializedValue);
}
[Fact]
@@ -211,15 +211,15 @@ namespace Gremlin.Net.UnitTest.Structure.IO.GraphSON
}
[Fact]
- public void ShouldDeserializeTimestampToDateTime()
+ public void ShouldDeserializeTimestampToDateTimeOffset()
{
var graphSon = "{\"@type\":\"g:Timestamp\",\"@value\":1475583442558}";
var reader = CreateStandardGraphSONReader();
- DateTime readDateTime = reader.ToObject(JObject.Parse(graphSon));
+ DateTimeOffset deserializedValue = reader.ToObject(JObject.Parse(graphSon));
- var expectedDateTime = TestUtils.FromJavaTime(1475583442558);
- Assert.Equal(expectedDateTime, readDateTime);
+ var expectedDateTimeOffset = TestUtils.FromJavaTime(1475583442558);
+ Assert.Equal(expectedDateTimeOffset, deserializedValue);
}
[Fact]
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f1153077/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 4cd831f..1f5e087 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
@@ -145,12 +145,12 @@ namespace Gremlin.Net.UnitTest.Structure.IO.GraphSON
}
[Fact]
- public void ShouldSerializeDateTime()
+ public void ShouldSerializeDateTimeOffset()
{
var writer = CreateStandardGraphSONWriter();
- var dateTime = TestUtils.FromJavaTime(1475583442552);
+ var dateTimeOffset = TestUtils.FromJavaTime(1475583442552);
- var graphSon = writer.WriteObject(dateTime);
+ var graphSon = writer.WriteObject(dateTimeOffset);
const string expected = "{\"@type\":\"g:Date\",\"@value\":1475583442552}";
Assert.Equal(expected, graphSon);
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f1153077/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/TestUtils.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/TestUtils.cs b/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/TestUtils.cs
index 7ed7542..78e2386 100644
--- a/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/TestUtils.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/TestUtils.cs
@@ -25,12 +25,12 @@ using System;
namespace Gremlin.Net.UnitTest.Structure.IO.GraphSON
{
- internal class TestUtils
+ internal static class TestUtils
{
- public static DateTime FromJavaTime(long javaTimestamp)
+ public static DateTimeOffset FromJavaTime(long milliseconds)
{
- var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
- return epoch.AddMilliseconds(javaTimestamp);
+ var epoch = new DateTimeOffset(1970, 1, 1, 0, 0, 0, 0, TimeSpan.Zero);
+ return epoch.AddTicks(TimeSpan.TicksPerMillisecond * milliseconds);
}
}
}
\ No newline at end of file
[2/3] tinkerpop git commit: Merge branch 'TINKERPOP-1745' into tp32
Posted by jo...@apache.org.
Merge branch 'TINKERPOP-1745' into tp32
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/7e17d4fa
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/7e17d4fa
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/7e17d4fa
Branch: refs/heads/master
Commit: 7e17d4fa0887a4918984e8bc0cdf701152a93d38
Parents: a883746 f115307
Author: Jorge Bay Gondra <jo...@gmail.com>
Authored: Tue Dec 5 14:03:16 2017 +0100
Committer: Jorge Bay Gondra <jo...@gmail.com>
Committed: Tue Dec 5 14:03:16 2017 +0100
----------------------------------------------------------------------
.../Structure/IO/GraphSON/DateDeserializer.cs | 43 --------------------
.../Structure/IO/GraphSON/DateSerializer.cs | 16 +++++---
.../Structure/IO/GraphSON/GraphSONReader.cs | 4 +-
.../Structure/IO/GraphSON/GraphSONWriter.cs | 2 +-
.../IO/GraphSON/GraphSONReaderTests.cs | 16 ++++----
.../IO/GraphSON/GraphSONWriterTests.cs | 6 +--
.../Structure/IO/GraphSON/TestUtils.cs | 8 ++--
7 files changed, 28 insertions(+), 67 deletions(-)
----------------------------------------------------------------------
[3/3] tinkerpop git commit: Merge branch 'tp32'
Posted by jo...@apache.org.
Merge branch 'tp32'
Conflicts:
gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONReaderTests.cs
gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONWriterTests.cs
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/1c041d1b
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/1c041d1b
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/1c041d1b
Branch: refs/heads/master
Commit: 1c041d1bbc8452c1a6b6e2aa266c345cfcb94dd6
Parents: fa0a0ee 7e17d4f
Author: Jorge Bay Gondra <jo...@gmail.com>
Authored: Tue Dec 5 14:06:04 2017 +0100
Committer: Jorge Bay Gondra <jo...@gmail.com>
Committed: Tue Dec 5 14:06:04 2017 +0100
----------------------------------------------------------------------
.../Structure/IO/GraphSON/DateDeserializer.cs | 43 --------------------
.../Structure/IO/GraphSON/DateSerializer.cs | 16 +++++---
.../Structure/IO/GraphSON/GraphSONReader.cs | 4 +-
.../Structure/IO/GraphSON/GraphSONWriter.cs | 2 +-
.../IO/GraphSON/GraphSONReaderTests.cs | 16 ++++----
.../IO/GraphSON/GraphSONWriterTests.cs | 6 +--
.../Structure/IO/GraphSON/TestUtils.cs | 8 ++--
7 files changed, 28 insertions(+), 67 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/1c041d1b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/GraphSONReader.cs
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/1c041d1b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/GraphSONWriter.cs
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/1c041d1b/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONReaderTests.cs
----------------------------------------------------------------------
diff --cc gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONReaderTests.cs
index e958e06,cb70530..3a2e21f
--- a/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONReaderTests.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONReaderTests.cs
@@@ -92,23 -71,23 +92,23 @@@ namespace Gremlin.Net.UnitTest.Structur
customSerializerMock.Verify(m => m.Objectify(It.IsAny<JToken>(), It.IsAny<GraphSONReader>()));
}
- [Fact]
- public void ShouldDeserializeDateToDateTimeOffset()
+ [Theory, MemberData(nameof(Versions))]
- public void ShouldDeserializeDateToDateTime(int version)
++ public void ShouldDeserializeDateToDateTimeOffset(int version)
{
var graphSon = "{\"@type\":\"g:Date\",\"@value\":1475583442552}";
- var reader = CreateStandardGraphSONReader();
+ var reader = CreateStandardGraphSONReader(version);
- DateTime readDateTime = reader.ToObject(JObject.Parse(graphSon));
+ DateTimeOffset deserializedValue = reader.ToObject(JObject.Parse(graphSon));
- var expectedDateTime = TestUtils.FromJavaTime(1475583442552);
- Assert.Equal(expectedDateTime, readDateTime);
+ var expectedDateTimeOffset = TestUtils.FromJavaTime(1475583442552);
+ Assert.Equal(expectedDateTimeOffset, deserializedValue);
}
- [Fact]
- public void ShouldDeserializeDictionary()
+ [Theory, MemberData(nameof(Versions))]
+ public void ShouldDeserializeDictionary(int version)
{
var serializedDict = "{\"age\":[{\"@type\":\"g:Int32\",\"@value\":29}],\"name\":[\"marko\"]}";
- var reader = CreateStandardGraphSONReader();
+ var reader = CreateStandardGraphSONReader(version);
var jObject = JObject.Parse(serializedDict);
var deserializedDict = reader.ToObject(jObject);
@@@ -247,23 -210,23 +247,23 @@@
Assert.Equal("y", edge.OutV.Id);
}
- [Fact]
- public void ShouldDeserializeTimestampToDateTimeOffset()
+ [Theory, MemberData(nameof(Versions))]
- public void ShouldDeserializeTimestampToDateTime(int version)
++ public void ShouldDeserializeTimestampToDateTimeOffset(int version)
{
var graphSon = "{\"@type\":\"g:Timestamp\",\"@value\":1475583442558}";
- var reader = CreateStandardGraphSONReader();
+ var reader = CreateStandardGraphSONReader(version);
- DateTime readDateTime = reader.ToObject(JObject.Parse(graphSon));
+ DateTimeOffset deserializedValue = reader.ToObject(JObject.Parse(graphSon));
- var expectedDateTime = TestUtils.FromJavaTime(1475583442558);
- Assert.Equal(expectedDateTime, readDateTime);
+ var expectedDateTimeOffset = TestUtils.FromJavaTime(1475583442558);
+ Assert.Equal(expectedDateTimeOffset, deserializedValue);
}
- [Fact]
- public void ShouldDeserializeGuid()
+ [Theory, MemberData(nameof(Versions))]
+ public void ShouldDeserializeGuid(int version)
{
var graphSon = "{\"@type\":\"g:UUID\",\"@value\":\"41d2e28a-20a4-4ab0-b379-d810dede3786\"}";
- var reader = CreateStandardGraphSONReader();
+ var reader = CreateStandardGraphSONReader(version);
Guid readGuid = reader.ToObject(JObject.Parse(graphSon));
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/1c041d1b/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONWriterTests.cs
----------------------------------------------------------------------
diff --cc gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONWriterTests.cs
index ca38555,1f5e087..4b347fe
--- a/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONWriterTests.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONWriterTests.cs
@@@ -165,13 -144,13 +165,13 @@@ namespace Gremlin.Net.UnitTest.Structur
customSerializerMock.Verify(m => m.Dictify(It.Is<int>(v => v == 12), It.IsAny<GraphSONWriter>()));
}
- [Fact]
- public void ShouldSerializeDateTimeOffset()
+ [Theory, MemberData(nameof(Versions))]
- public void ShouldSerializeDateTime(int version)
++ public void ShouldSerializeDateTimeOffset(int version)
{
- var writer = CreateStandardGraphSONWriter();
+ var writer = CreateGraphSONWriter(version);
- var dateTime = TestUtils.FromJavaTime(1475583442552);
+ var dateTimeOffset = TestUtils.FromJavaTime(1475583442552);
- var graphSon = writer.WriteObject(dateTime);
+ var graphSon = writer.WriteObject(dateTimeOffset);
const string expected = "{\"@type\":\"g:Date\",\"@value\":1475583442552}";
Assert.Equal(expected, graphSon);