From d5254a107d58e491cedd993b5e64df714d76dd1d Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Fri, 11 Dec 2020 16:05:53 +0300 Subject: [PATCH 01/37] IGNITE-12824: WIP --- .../platform/PlatformDeployServiceTask.java | 12 +++++++++ .../Services/IJavaService.cs | 3 +++ .../Services/JavaServiceDynamicProxy.cs | 6 +++++ .../Services/ServicesTest.cs | 26 +++++++++++++++++++ 4 files changed, 47 insertions(+) diff --git a/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java b/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java index 4e04131fb212f..8a2b80336f7fa 100644 --- a/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java +++ b/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java @@ -21,12 +21,14 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.UUID; import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; import org.apache.ignite.IgniteException; import org.apache.ignite.binary.BinaryObject; import org.apache.ignite.cluster.ClusterNode; @@ -42,6 +44,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import static java.util.Calendar.AUGUST; import static java.util.Calendar.JANUARY; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -94,6 +97,9 @@ private PlatformDeployServiceJob(String serviceName) { * Test service. */ public static class PlatformTestService implements Service { + @IgniteInstanceResource + private Ignite ignite; + /** */ private boolean isCancelled; @@ -494,6 +500,12 @@ public Map testMap(Map map) { return m; } + public void testDateInteroperable() { + IgniteCache dateCache = ignite.cache("net-date-cache"); + + assertEquals(new Date(1984, AUGUST, 22, 0, 0, 0), dateCache.get(1)); + } + /** */ public void sleep(long delayMs) { try { diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/IJavaService.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/IJavaService.cs index 8c9e6b6755b3e..fe4e0051480f8 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/IJavaService.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/IJavaService.cs @@ -176,6 +176,9 @@ public interface IJavaService /** */ IDictionary testMap(IDictionary dict); + + /** */ + void testDateInteroperable(); /** */ void sleep(long delayMs); diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/JavaServiceDynamicProxy.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/JavaServiceDynamicProxy.cs index 3276b838500ba..6cdf0a8fb9fa7 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/JavaServiceDynamicProxy.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/JavaServiceDynamicProxy.cs @@ -331,6 +331,12 @@ public IDictionary testMap(IDictionary dict) return _svc.testMap(dict); } + /** */ + public void testDateInteroperable() + { + _svc.testDateInteroperable(); + } + /** */ public void sleep(long delayMs) { diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs index ee0bdea7417c2..5815b0f5dc365 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs @@ -19,6 +19,7 @@ namespace Apache.Ignite.Core.Tests.Services { using System; using System.Collections.Generic; + using System.Configuration; using System.IO; using System.Linq; using System.Runtime.Serialization.Formatters.Binary; @@ -1040,6 +1041,30 @@ public void TestCallJavaServiceDynamicProxy() Assert.AreEqual(guid, svc.testArray(new Guid?[] { guid })[0]); } + /// + /// Tests Java service invocation. + /// + [Test] + public void TestJavaDateInteroperable() + { + // Deploy Java service + var javaSvcName = TestUtils.DeployJavaService(Grid1); + + // Verify descriptor + var descriptor = Services.GetServiceDescriptors().Single(x => x.Name == javaSvcName); + Assert.AreEqual(javaSvcName, descriptor.Name); + + var svc = Services.GetServiceProxy(javaSvcName, false); + var binSvc = Services.WithKeepBinary().WithServerKeepBinary() + .GetServiceProxy(javaSvcName, false); + + var cache = Grid1.CreateCache("net-date-cache"); + + cache.Put(1, new DateTime(1984, 8, 22, 0, 0, 0, 0)); + + svc.testDateInteroperable(); + } + /// /// Tests the footer setting. /// @@ -1123,6 +1148,7 @@ private IgniteConfiguration GetConfiguration(string springConfigUrl) typeof (PlatformComputeBinarizable), typeof (BinarizableObject)) { + Serializer = new BinaryReflectiveSerializer() {ForceTimestamp = true}, NameMapper = BinaryBasicNameMapper.SimpleNameInstance } }; From ca3cc3a3f73ae779f1bd7d48ec3d3d73b5d4047f Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Fri, 11 Dec 2020 17:14:29 +0300 Subject: [PATCH 02/37] IGNITE-12824: WIP --- .../platform/PlatformDeployServiceTask.java | 12 ++++--- .../Services/IJavaService.cs | 2 +- .../Services/JavaServiceDynamicProxy.cs | 4 +-- .../Services/ServicesTest.cs | 31 +++---------------- 4 files changed, 15 insertions(+), 34 deletions(-) diff --git a/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java b/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java index 8a2b80336f7fa..74de3706d4537 100644 --- a/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java +++ b/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java @@ -19,6 +19,7 @@ import java.sql.Timestamp; import java.util.ArrayList; +import java.util.Calendar; import java.util.Collection; import java.util.Collections; import java.util.Date; @@ -28,7 +29,6 @@ import java.util.Map; import java.util.UUID; import org.apache.ignite.Ignite; -import org.apache.ignite.IgniteCache; import org.apache.ignite.IgniteException; import org.apache.ignite.binary.BinaryObject; import org.apache.ignite.cluster.ClusterNode; @@ -44,7 +44,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import static java.util.Calendar.AUGUST; import static java.util.Calendar.JANUARY; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -500,10 +499,13 @@ public Map testMap(Map map) { return m; } - public void testDateInteroperable() { - IgniteCache dateCache = ignite.cache("net-date-cache"); + public Timestamp testDate(Timestamp date) { + if (date == null) + return null; + + assertEquals(new Timestamp(new Date(82, Calendar.APRIL, 1, 0, 0, 0).getTime()), date); - assertEquals(new Date(1984, AUGUST, 22, 0, 0, 0), dateCache.get(1)); + return new Timestamp(new Date(91, Calendar.OCTOBER, 1, 0, 0, 0).getTime()); } /** */ diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/IJavaService.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/IJavaService.cs index fe4e0051480f8..c74844b76a424 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/IJavaService.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/IJavaService.cs @@ -178,7 +178,7 @@ public interface IJavaService IDictionary testMap(IDictionary dict); /** */ - void testDateInteroperable(); + DateTime testDate(DateTime date); /** */ void sleep(long delayMs); diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/JavaServiceDynamicProxy.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/JavaServiceDynamicProxy.cs index 6cdf0a8fb9fa7..83f148ee78fe4 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/JavaServiceDynamicProxy.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/JavaServiceDynamicProxy.cs @@ -332,9 +332,9 @@ public IDictionary testMap(IDictionary dict) } /** */ - public void testDateInteroperable() + public DateTime testDate(DateTime date) { - _svc.testDateInteroperable(); + return _svc.testDate(date); } /** */ diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs index 5815b0f5dc365..13ee260c3a27f 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs @@ -19,7 +19,6 @@ namespace Apache.Ignite.Core.Tests.Services { using System; using System.Collections.Generic; - using System.Configuration; using System.IO; using System.Linq; using System.Runtime.Serialization.Formatters.Binary; @@ -957,6 +956,11 @@ public void TestCallJavaService() Assert.AreEqual(new[] {11, 12, 13}, binSvc.testBinaryObjectArray(binArr) .Select(x => x.GetField("Field"))); + DateTime input = new DateTime(1982, 4, 1, 0, 0, 0, 0, DateTimeKind.Utc); + DateTime expected = new DateTime(1991, 10, 1, 0, 0, 0, 0, DateTimeKind.Utc); + + Assert.AreEqual(expected, svc.testDate(input)); + Services.Cancel(javaSvcName); } @@ -1041,30 +1045,6 @@ public void TestCallJavaServiceDynamicProxy() Assert.AreEqual(guid, svc.testArray(new Guid?[] { guid })[0]); } - /// - /// Tests Java service invocation. - /// - [Test] - public void TestJavaDateInteroperable() - { - // Deploy Java service - var javaSvcName = TestUtils.DeployJavaService(Grid1); - - // Verify descriptor - var descriptor = Services.GetServiceDescriptors().Single(x => x.Name == javaSvcName); - Assert.AreEqual(javaSvcName, descriptor.Name); - - var svc = Services.GetServiceProxy(javaSvcName, false); - var binSvc = Services.WithKeepBinary().WithServerKeepBinary() - .GetServiceProxy(javaSvcName, false); - - var cache = Grid1.CreateCache("net-date-cache"); - - cache.Put(1, new DateTime(1984, 8, 22, 0, 0, 0, 0)); - - svc.testDateInteroperable(); - } - /// /// Tests the footer setting. /// @@ -1148,7 +1128,6 @@ private IgniteConfiguration GetConfiguration(string springConfigUrl) typeof (PlatformComputeBinarizable), typeof (BinarizableObject)) { - Serializer = new BinaryReflectiveSerializer() {ForceTimestamp = true}, NameMapper = BinaryBasicNameMapper.SimpleNameInstance } }; From 063b6f0a20bf6e705fdfe5aeb5146d85f5f49da0 Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Mon, 14 Dec 2020 17:06:46 +0300 Subject: [PATCH 03/37] IGNITE-12824: Fix of writing dates to the cache from the .Net --- .../platform/PlatformDeployServiceTask.java | 11 ++ .../Services/IJavaService.cs | 3 + .../Services/JavaServiceDynamicProxy.cs | 6 + .../Services/ServicesTest.cs | 172 +++++++----------- .../Binary/BinaryConfiguration.cs | 12 ++ .../Binary/BinaryReflectiveSerializer.cs | 1 + .../Impl/Binary/BinarySystemHandlers.cs | 36 +++- .../Impl/Binary/BinaryWriter.cs | 4 +- .../Impl/Binary/Marshaller.cs | 10 +- .../Impl/Services/ServiceProxySerializer.cs | 5 +- 10 files changed, 144 insertions(+), 116 deletions(-) diff --git a/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java b/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java index 74de3706d4537..a4830e233330c 100644 --- a/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java +++ b/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java @@ -29,6 +29,7 @@ import java.util.Map; import java.util.UUID; import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; import org.apache.ignite.IgniteException; import org.apache.ignite.binary.BinaryObject; import org.apache.ignite.cluster.ClusterNode; @@ -508,6 +509,16 @@ public Timestamp testDate(Timestamp date) { return new Timestamp(new Date(91, Calendar.OCTOBER, 1, 0, 0, 0).getTime()); } + public void testDateFromCache() { + IgniteCache cache = ignite.cache("net-dates"); + + cache.put(3, new Timestamp(new Date(82, Calendar.APRIL, 1, 0, 0, 0).getTime())); + cache.put(4, new Timestamp(new Date(91, Calendar.OCTOBER, 1, 0, 0, 0).getTime())); + + assertEquals(new Timestamp(new Date(82, Calendar.APRIL, 1, 0, 0, 0).getTime()), cache.get(1)); + assertEquals(new Timestamp(new Date(91, Calendar.OCTOBER, 1, 0, 0, 0).getTime()), cache.get(2)); + } + /** */ public void sleep(long delayMs) { try { diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/IJavaService.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/IJavaService.cs index c74844b76a424..8d1a5e02330dd 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/IJavaService.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/IJavaService.cs @@ -179,6 +179,9 @@ public interface IJavaService /** */ DateTime testDate(DateTime date); + + /** */ + void testDateFromCache(); /** */ void sleep(long delayMs); diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/JavaServiceDynamicProxy.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/JavaServiceDynamicProxy.cs index 83f148ee78fe4..d23b8be01b58e 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/JavaServiceDynamicProxy.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/JavaServiceDynamicProxy.cs @@ -337,6 +337,12 @@ public DateTime testDate(DateTime date) return _svc.testDate(date); } + /** */ + public void testDateFromCache() + { + _svc.testDateFromCache(); + } + /** */ public void sleep(long delayMs) { diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs index 13ee260c3a27f..97a49086db48e 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs @@ -860,11 +860,50 @@ public void TestCallJavaService() var binSvc = Services.WithKeepBinary().WithServerKeepBinary() .GetServiceProxy(javaSvcName, false); + DoTestService(svc, binSvc); + + // Binary collections + var arr = new[] {10, 11, 12}.Select( + x => new PlatformComputeBinarizable {Field = x}).ToArray(); + + Assert.AreEqual(new[] {11, 12, 13}, svc.testBinarizableCollection(arr) + .OfType().Select(x => x.Field)); + + // Binary object array. + var binArr = arr.Select(Grid1.GetBinary().ToBinary).ToArray(); + + Assert.AreEqual(new[] {11, 12, 13}, binSvc.testBinaryObjectArray(binArr) + .Select(x => x.GetField("Field"))); + + Services.Cancel(javaSvcName); + } + + /// + /// Tests Java service invocation with dynamic proxy. + /// + [Test] + public void TestCallJavaServiceDynamicProxy() + { + // Deploy Java service + var javaSvcName = TestUtils.DeployJavaService(Grid1); + var svc = Grid1.GetServices().GetDynamicServiceProxy(javaSvcName, true); + + // Binary object + var binSvc = Services.WithKeepBinary().WithServerKeepBinary().GetDynamicServiceProxy(javaSvcName); + + DoTestService(new JavaServiceDynamicProxy(svc), new JavaServiceDynamicProxy(binSvc)); + } + + /// + /// Tests java service instance. + /// + private void DoTestService(IJavaService svc, IJavaService binSvc) + { // Basics Assert.IsTrue(svc.isInitialized()); Assert.IsTrue(TestUtils.WaitForCondition(() => svc.isExecuted(), 500)); Assert.IsFalse(svc.isCancelled()); - + // Primitives Assert.AreEqual(4, svc.test((byte) 3)); Assert.AreEqual(5, svc.test((short) 4)); @@ -902,8 +941,8 @@ public void TestCallJavaService() Assert.IsNull(svc.testNull(null)); // params / varargs - Assert.AreEqual(5, svc.testParams(1, 2, 3, 4, "5")); - Assert.AreEqual(0, svc.testParams()); + Assert.AreEqual(5, svc.testParams(1, 2, 3, 4, "5")); //? + Assert.AreEqual(0, svc.testParams()); //? // Overloads Assert.AreEqual(3, svc.test(2, "1")); @@ -912,24 +951,6 @@ public void TestCallJavaService() // Binary Assert.AreEqual(7, svc.testBinarizable(new PlatformComputeBinarizable {Field = 6}).Field); - // Binary collections - var arr = new[] {10, 11, 12}.Select( - x => new PlatformComputeBinarizable {Field = x}).ToArray(); - var arrOfObj = arr.ToArray(); - - Assert.AreEqual(new[] {11, 12, 13}, svc.testBinarizableCollection(arr) - .OfType().Select(x => x.Field)); - - Assert.AreEqual(new[] {11, 12, 13}, svc.testBinarizableArrayOfObjects(arrOfObj) - .OfType().Select(x => x.Field)); - - Assert.IsNull(svc.testBinarizableArrayOfObjects(null)); - - Assert.AreEqual(new[] {11, 12, 13}, svc.testBinarizableArray(arr) - .Select(x => x.Field)); - - Assert.IsNull(svc.testBinarizableArray(null)); - // Binary object Assert.AreEqual(15, binSvc.testBinaryObject( @@ -950,99 +971,35 @@ public void TestCallJavaService() Assert.IsNull(svc.testNullUUID(null)); Assert.AreEqual(guid, svc.testArray(new Guid?[] {guid})[0]); - // Binary object array. - var binArr = arr.Select(Grid1.GetBinary().ToBinary).ToArray(); - - Assert.AreEqual(new[] {11, 12, 13}, binSvc.testBinaryObjectArray(binArr) - .Select(x => x.GetField("Field"))); - - DateTime input = new DateTime(1982, 4, 1, 0, 0, 0, 0, DateTimeKind.Utc); - DateTime expected = new DateTime(1991, 10, 1, 0, 0, 0, 0, DateTimeKind.Utc); - - Assert.AreEqual(expected, svc.testDate(input)); - - Services.Cancel(javaSvcName); - } - - /// - /// Tests Java service invocation with dynamic proxy. - /// - [Test] - public void TestCallJavaServiceDynamicProxy() - { - // Deploy Java service - var javaSvcName = TestUtils.DeployJavaService(Grid1); - var svc = Grid1.GetServices().GetDynamicServiceProxy(javaSvcName, true); - - // Basics - Assert.IsTrue(svc.isInitialized()); - Assert.IsTrue(TestUtils.WaitForCondition(() => svc.isExecuted(), 500)); - Assert.IsFalse(svc.isCancelled()); - - // Primitives - Assert.AreEqual(4, svc.test((byte)3)); - Assert.AreEqual(5, svc.test((short)4)); - Assert.AreEqual(6, svc.test(5)); - Assert.AreEqual(6, svc.test((long)5)); - Assert.AreEqual(3.8f, svc.test(2.3f)); - Assert.AreEqual(5.8, svc.test(3.3)); - Assert.IsFalse(svc.test(true)); - Assert.AreEqual('b', svc.test('a')); - Assert.AreEqual("Foo!", svc.test("Foo")); - - // Nullables (Java wrapper types) - Assert.AreEqual(4, svc.testWrapper(3)); - Assert.AreEqual(5, svc.testWrapper((short?)4)); - Assert.AreEqual(6, svc.testWrapper((int?)5)); - Assert.AreEqual(6, svc.testWrapper((long?)5)); - Assert.AreEqual(3.8f, svc.testWrapper(2.3f)); - Assert.AreEqual(5.8, svc.testWrapper(3.3)); - Assert.AreEqual(false, svc.testWrapper(true)); - Assert.AreEqual('b', svc.testWrapper('a')); + // Binary collections + var arr = new[] {10, 11, 12}.Select( + x => new PlatformComputeBinarizable {Field = x}).ToArray(); + var arrOfObj = arr.ToArray(); - // Arrays - Assert.AreEqual(new byte[] { 2, 3, 4 }, svc.testArray(new byte[] { 1, 2, 3 })); - Assert.AreEqual(new short[] { 2, 3, 4 }, svc.testArray(new short[] { 1, 2, 3 })); - Assert.AreEqual(new[] { 2, 3, 4 }, svc.testArray(new[] { 1, 2, 3 })); - Assert.AreEqual(new long[] { 2, 3, 4 }, svc.testArray(new long[] { 1, 2, 3 })); - Assert.AreEqual(new float[] { 2, 3, 4 }, svc.testArray(new float[] { 1, 2, 3 })); - Assert.AreEqual(new double[] { 2, 3, 4 }, svc.testArray(new double[] { 1, 2, 3 })); - Assert.AreEqual(new[] { "a1", "b1" }, svc.testArray(new[] { "a", "b" })); - Assert.AreEqual(new[] { 'c', 'd' }, svc.testArray(new[] { 'b', 'c' })); - Assert.AreEqual(new[] { false, true, false }, svc.testArray(new[] { true, false, true })); + Assert.AreEqual(new[] {11, 12, 13}, svc.testBinarizableArrayOfObjects(arrOfObj) + .OfType().Select(x => x.Field)); - // Nulls - Assert.AreEqual(9, svc.testNull(8)); - Assert.IsNull(svc.testNull(null)); + Assert.IsNull(svc.testBinarizableArrayOfObjects(null)); - // Overloads - Assert.AreEqual(3, svc.test(2, "1")); - Assert.AreEqual(3, svc.test("1", 2)); + Assert.AreEqual(new[] {11, 12, 13}, svc.testBinarizableArray(arr) + .Select(x => x.Field)); - // Binary - Assert.AreEqual(7, svc.testBinarizable(new PlatformComputeBinarizable { Field = 6 }).Field); + Assert.IsNull(svc.testBinarizableArray(null)); - // Binary object - var binSvc = Services.WithKeepBinary().WithServerKeepBinary().GetDynamicServiceProxy(javaSvcName); + DateTime dt1 = new DateTime(1982, 4, 1, 0, 0, 0, 0, DateTimeKind.Utc); + DateTime dt2 = new DateTime(1991, 10, 1, 0, 0, 0, 0, DateTimeKind.Utc); - Assert.AreEqual(15, - binSvc.testBinaryObject( - Grid1.GetBinary().ToBinary(new PlatformComputeBinarizable { Field = 6 })) - .GetField("Field")); + Assert.AreEqual(dt2, svc.testDate(dt1)); - DateTime dt = new DateTime(1992, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); + var cache = Grid1.GetOrCreateCache("net-dates"); - Assert.AreEqual(dt, svc.test(dt)); - Assert.AreEqual(dt, svc.testNullTimestamp(dt)); - Assert.IsNull(svc.testNullTimestamp(null)); - Assert.AreEqual(dt, svc.testArray(new DateTime?[] { dt })[0]); + cache.Put(1, dt1); + cache.Put(2, dt2); - Guid guid = Guid.NewGuid(); + svc.testDateFromCache(); - Assert.AreEqual(guid, svc.test(guid)); - Assert.AreEqual(guid, svc.testNullUUID(guid)); - Assert.IsNull(svc.testNullUUID(null)); - Assert.AreEqual(guid, svc.testArray(new Guid?[] { guid })[0]); + Assert.AreEqual(dt1, cache.Get(3)); + Assert.AreEqual(dt2, cache.Get(4)); } /// @@ -1119,7 +1076,7 @@ private IgniteConfiguration GetConfiguration(string springConfigUrl) springConfigUrl = Compute.ComputeApiTestFullFooter.ReplaceFooterSetting(springConfigUrl); } - return new IgniteConfiguration(TestUtils.GetTestConfiguration()) + var cfg = new IgniteConfiguration(TestUtils.GetTestConfiguration()) { SpringConfigUrl = springConfigUrl, BinaryConfiguration = new BinaryConfiguration( @@ -1128,9 +1085,12 @@ private IgniteConfiguration GetConfiguration(string springConfigUrl) typeof (PlatformComputeBinarizable), typeof (BinarizableObject)) { - NameMapper = BinaryBasicNameMapper.SimpleNameInstance + NameMapper = BinaryBasicNameMapper.SimpleNameInstance, + ForceTimestamp = true } }; + + return cfg; } /// diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Binary/BinaryConfiguration.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Binary/BinaryConfiguration.cs index 32d2c9d6f5d15..9815e9b5b1d18 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Binary/BinaryConfiguration.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Binary/BinaryConfiguration.cs @@ -39,6 +39,11 @@ public class BinaryConfiguration /// Default setting. /// public const bool DefaultKeepDeserialized = true; + + /// + /// Default setting. + /// + public const bool DefaultForceTimestamp = false; /** Footer setting. */ private bool? _compactFooter; @@ -49,6 +54,7 @@ public class BinaryConfiguration public BinaryConfiguration() { KeepDeserialized = DefaultKeepDeserialized; + ForceTimestamp = DefaultForceTimestamp; } /// @@ -72,6 +78,7 @@ internal void CopyLocalProperties(BinaryConfiguration cfg) IdMapper = cfg.IdMapper; NameMapper = cfg.NameMapper; KeepDeserialized = cfg.KeepDeserialized; + ForceTimestamp = cfg.ForceTimestamp; if (cfg.Serializer != null) { @@ -159,5 +166,10 @@ internal bool? CompactFooterInternal { get { return _compactFooter; } } + + /// + /// Gets or sets a value indicating whether all DateTime values should be written as Timestamp. + /// + public bool ForceTimestamp { get; set; } } } diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Binary/BinaryReflectiveSerializer.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Binary/BinaryReflectiveSerializer.cs index f9874ba23484d..4b1614429ad35 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Binary/BinaryReflectiveSerializer.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Binary/BinaryReflectiveSerializer.cs @@ -46,6 +46,7 @@ public sealed class BinaryReflectiveSerializer : IBinarySerializer private bool _isInUse; /** Force timestamp flag. */ + [Obsolete("Deprecated, use BinaryConfiguration.ForceTimestamp instead.")] private bool _forceTimestamp; /// diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinarySystemHandlers.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinarySystemHandlers.cs index cae0f5fcf9a50..5f3e163e73b31 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinarySystemHandlers.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinarySystemHandlers.cs @@ -122,12 +122,13 @@ static BinarySystemHandlers() /// Try getting write handler for type. /// /// + /// /// - public static IBinarySystemWriteHandler GetWriteHandler(Type type) + public static IBinarySystemWriteHandler GetWriteHandler(Type type, bool forceTimestamp) { return WriteHandlers.GetOrAdd(type, t => { - return FindWriteHandler(t); + return FindWriteHandler(t, forceTimestamp); }); } @@ -135,10 +136,11 @@ public static IBinarySystemWriteHandler GetWriteHandler(Type type) /// Find write handler for type. /// /// Type. + /// /// /// Write handler or NULL. /// - private static IBinarySystemWriteHandler FindWriteHandler(Type type) + private static IBinarySystemWriteHandler FindWriteHandler(Type type, bool forceTimestamp) { // 1. Well-known types. if (type == typeof(string)) @@ -147,6 +149,8 @@ private static IBinarySystemWriteHandler FindWriteHandler(Type type) return new BinarySystemWriteHandler(WriteDecimal, false); if (type == typeof(Guid)) return new BinarySystemWriteHandler(WriteGuid, false); + if (type == typeof(DateTime) && forceTimestamp) + return new BinarySystemWriteHandler(WriteTimestamp, false); if (type == typeof (BinaryObject)) return new BinarySystemWriteHandler(WriteBinary, false); if (type == typeof (BinaryEnum)) @@ -224,6 +228,8 @@ private static IBinarySystemWriteHandler FindWriteHandler(Type type) return new BinarySystemWriteHandler(WriteStringArray, true); if (elemType == typeof(Guid?)) return new BinarySystemWriteHandler(WriteGuidArray, true); + if (elemType == typeof(DateTime?) && forceTimestamp) + return new BinarySystemWriteHandler(WriteTimestampArray, true); // Enums. if (BinaryUtils.IsIgniteEnum(elemType) || elemType == typeof(BinaryEnum)) return new BinarySystemWriteHandler(WriteEnumArray, true); @@ -293,6 +299,18 @@ private static void WriteGuid(BinaryWriter ctx, Guid obj) BinaryUtils.WriteGuid(obj, ctx.Stream); } + /// + /// Write Date. + /// + /// Context. + /// Value. + private static void WriteTimestamp(BinaryWriter ctx, DateTime obj) + { + ctx.Stream.WriteByte(BinaryTypeId.Timestamp); + + BinaryUtils.WriteTimestamp(obj, ctx.Stream); + } + /// /// Write boolaen array. /// @@ -425,6 +443,18 @@ private static void WriteGuidArray(BinaryWriter ctx, Guid?[] obj) BinaryUtils.WriteGuidArray(obj, ctx.Stream); } + /// + /// Write nullable Date array. + /// + /// Context. + /// Value. + private static void WriteTimestampArray(BinaryWriter ctx, DateTime?[] obj) + { + ctx.Stream.WriteByte(BinaryTypeId.ArrayTimestamp); + + BinaryUtils.WriteTimestampArray(obj, ctx.Stream); + } + /// /// Writes the enum array. /// diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs index d09bfad8585a8..4f2dab03cd5f6 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs @@ -875,7 +875,7 @@ public void WriteEnum(T val) throw new BinaryObjectException("Type is not an enum: " + type); } - var handler = BinarySystemHandlers.GetWriteHandler(type); + var handler = BinarySystemHandlers.GetWriteHandler(type, _marsh.ForceTimestamp()); if (handler != null) { @@ -1180,7 +1180,7 @@ public void Write(T obj) return; // Are we dealing with a well-known type? - var handler = BinarySystemHandlers.GetWriteHandler(type); + var handler = BinarySystemHandlers.GetWriteHandler(type, _marsh.ForceTimestamp()); if (handler != null) { diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs index 4a61cf5eda8d5..44e1e872f7779 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs @@ -702,7 +702,7 @@ private static IBinarySerializerInternal GetSerializer(BinaryConfiguration cfg, return new SerializableSerializer(type); } - serializer = new BinaryReflectiveSerializer(); + serializer = new BinaryReflectiveSerializer() {ForceTimestamp = cfg.ForceTimestamp}; } var refSerializer = serializer as BinaryReflectiveSerializer; @@ -950,5 +950,13 @@ private static IBinaryNameMapper GetDefaultNameMapper() { return BinaryBasicNameMapper.FullNameInstance; } + + /// + /// Gets force timestamp flag value. + /// + public bool ForceTimestamp() + { + return _cfg.ForceTimestamp; + } } } diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Services/ServiceProxySerializer.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Services/ServiceProxySerializer.cs index 66998cbb114fa..16e3c4794712f 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Services/ServiceProxySerializer.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Services/ServiceProxySerializer.cs @@ -267,7 +267,7 @@ private static Action GetPlatformArgWriter(Type paramType, return (writer, o) => writer.WriteTimestampArray((DateTime?[]) o); } - var handler = BinarySystemHandlers.GetWriteHandler(type); + var handler = BinarySystemHandlers.GetWriteHandler(type, true); if (handler != null) return null; @@ -281,9 +281,6 @@ private static Action GetPlatformArgWriter(Type paramType, if (arg is ICollection) return (writer, o) => writer.WriteCollection((ICollection) o); - if (arg is DateTime) - return (writer, o) => writer.WriteTimestamp((DateTime) o); - return null; } } From 24a89edebbac56753c732068459da61ec38755c0 Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Mon, 14 Dec 2020 19:57:36 +0300 Subject: [PATCH 04/37] IGNITE-12824: Fix of writing dates to the cache from the .Net --- .../ignite/platform/PlatformDeployServiceTask.java | 10 ++++++++++ .../Services/IJavaService.cs | 3 +++ .../Services/JavaServiceDynamicProxy.cs | 6 ++++++ .../Services/ServicesTest.cs | 13 +++++++++++++ .../Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs | 3 ++- 5 files changed, 34 insertions(+), 1 deletion(-) diff --git a/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java b/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java index a4830e233330c..2687d1822bd75 100644 --- a/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java +++ b/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java @@ -519,6 +519,16 @@ public void testDateFromCache() { assertEquals(new Timestamp(new Date(91, Calendar.OCTOBER, 1, 0, 0, 0).getTime()), cache.get(2)); } + public void testDateFromCache2() { + IgniteCache cache = ignite.cache("net-dates"); + + cache.put(7, new Timestamp(new Date(82, Calendar.APRIL, 1, 0, 0, 0).getTime())); + cache.put(8, new Timestamp(new Date(91, Calendar.OCTOBER, 1, 0, 0, 0).getTime())); + + assertEquals(new Timestamp(new Date(82, Calendar.APRIL, 1, 0, 0, 0).getTime()), cache.get(5)); + assertEquals(new Timestamp(new Date(91, Calendar.OCTOBER, 1, 0, 0, 0).getTime()), cache.get(6)); + } + /** */ public void sleep(long delayMs) { try { diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/IJavaService.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/IJavaService.cs index 8d1a5e02330dd..622e7b2f3dbaa 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/IJavaService.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/IJavaService.cs @@ -182,6 +182,9 @@ public interface IJavaService /** */ void testDateFromCache(); + + /** */ + void testDateFromCache2(); /** */ void sleep(long delayMs); diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/JavaServiceDynamicProxy.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/JavaServiceDynamicProxy.cs index d23b8be01b58e..13e6e74490bbb 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/JavaServiceDynamicProxy.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/JavaServiceDynamicProxy.cs @@ -343,6 +343,12 @@ public void testDateFromCache() _svc.testDateFromCache(); } + /** */ + public void testDateFromCache2() + { + _svc.testDateFromCache2(); + } + /** */ public void sleep(long delayMs) { diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs index 97a49086db48e..9ef41003c090c 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs @@ -1000,6 +1000,19 @@ private void DoTestService(IJavaService svc, IJavaService binSvc) Assert.AreEqual(dt1, cache.Get(3)); Assert.AreEqual(dt2, cache.Get(4)); + + DateTime dt3 = new DateTime(1982, 4, 1, 0, 0, 0, 0, DateTimeKind.Local); + DateTime dt4 = new DateTime(1991, 10, 1, 0, 0, 0, 0, DateTimeKind.Local); + + Assert.AreEqual(dt4, svc.testDate(dt3)); + + cache.Put(5, dt3); + cache.Put(6, dt4); + + svc.testDateFromCache2(); + + Assert.AreEqual(dt3, cache.Get(7)); + Assert.AreEqual(dt4, cache.Get(8)); } /// diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs index 5b30c7ef69dbb..6b81b1d02d9f0 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs @@ -1614,12 +1614,13 @@ public static void ValidateProtocolVersion(byte version) */ private static void ToJavaDate(DateTime date, out long high, out int low) { +/* if (date.Kind != DateTimeKind.Utc) { throw new BinaryObjectException( "DateTime is not UTC. Only UTC DateTime can be used for interop with other platforms."); } - +*/ long diff = date.Ticks - JavaDateTicks; high = diff / TimeSpan.TicksPerMillisecond; From 17ffb017959cf262ec97672358e6eaa6d8122293 Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Mon, 14 Dec 2020 19:58:44 +0300 Subject: [PATCH 05/37] IGNITE-12824: Fix of writing dates to the cache from the .Net --- .../dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs index 6b81b1d02d9f0..4466f27e5029b 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs @@ -1614,13 +1614,6 @@ public static void ValidateProtocolVersion(byte version) */ private static void ToJavaDate(DateTime date, out long high, out int low) { -/* - if (date.Kind != DateTimeKind.Utc) - { - throw new BinaryObjectException( - "DateTime is not UTC. Only UTC DateTime can be used for interop with other platforms."); - } -*/ long diff = date.Ticks - JavaDateTicks; high = diff / TimeSpan.TicksPerMillisecond; From 317a6662433c73e7f31f1e0f0c5f36b685553339 Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Mon, 14 Dec 2020 20:00:02 +0300 Subject: [PATCH 06/37] IGNITE-12824: Fix of writing dates to the cache from the .Net --- .../dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs index 9ef41003c090c..72091917640d7 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs @@ -941,8 +941,8 @@ private void DoTestService(IJavaService svc, IJavaService binSvc) Assert.IsNull(svc.testNull(null)); // params / varargs - Assert.AreEqual(5, svc.testParams(1, 2, 3, 4, "5")); //? - Assert.AreEqual(0, svc.testParams()); //? + Assert.AreEqual(5, svc.testParams(1, 2, 3, 4, "5")); + Assert.AreEqual(0, svc.testParams()); // Overloads Assert.AreEqual(3, svc.test(2, "1")); From 2086fbf5f20bfc1b649620ceae4634a876d9298b Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Mon, 14 Dec 2020 20:01:20 +0300 Subject: [PATCH 07/37] IGNITE-12824: Fix of writing dates to the cache from the .Net --- .../dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs index 72091917640d7..eb27eda243f15 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs @@ -1089,7 +1089,7 @@ private IgniteConfiguration GetConfiguration(string springConfigUrl) springConfigUrl = Compute.ComputeApiTestFullFooter.ReplaceFooterSetting(springConfigUrl); } - var cfg = new IgniteConfiguration(TestUtils.GetTestConfiguration()) + return new IgniteConfiguration(TestUtils.GetTestConfiguration()) { SpringConfigUrl = springConfigUrl, BinaryConfiguration = new BinaryConfiguration( @@ -1102,8 +1102,6 @@ private IgniteConfiguration GetConfiguration(string springConfigUrl) ForceTimestamp = true } }; - - return cfg; } /// From d0514d34ca9d1e857ff4c302b15a7b8c88f7c9c7 Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Mon, 14 Dec 2020 20:04:27 +0300 Subject: [PATCH 08/37] IGNITE-12824: Fix of writing dates to the cache from the .Net --- .../Services/ServicesTest.cs | 181 +++++++++++++----- 1 file changed, 131 insertions(+), 50 deletions(-) diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs index eb27eda243f15..9e981def97c9c 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs @@ -860,50 +860,11 @@ public void TestCallJavaService() var binSvc = Services.WithKeepBinary().WithServerKeepBinary() .GetServiceProxy(javaSvcName, false); - DoTestService(svc, binSvc); - - // Binary collections - var arr = new[] {10, 11, 12}.Select( - x => new PlatformComputeBinarizable {Field = x}).ToArray(); - - Assert.AreEqual(new[] {11, 12, 13}, svc.testBinarizableCollection(arr) - .OfType().Select(x => x.Field)); - - // Binary object array. - var binArr = arr.Select(Grid1.GetBinary().ToBinary).ToArray(); - - Assert.AreEqual(new[] {11, 12, 13}, binSvc.testBinaryObjectArray(binArr) - .Select(x => x.GetField("Field"))); - - Services.Cancel(javaSvcName); - } - - /// - /// Tests Java service invocation with dynamic proxy. - /// - [Test] - public void TestCallJavaServiceDynamicProxy() - { - // Deploy Java service - var javaSvcName = TestUtils.DeployJavaService(Grid1); - var svc = Grid1.GetServices().GetDynamicServiceProxy(javaSvcName, true); - - // Binary object - var binSvc = Services.WithKeepBinary().WithServerKeepBinary().GetDynamicServiceProxy(javaSvcName); - - DoTestService(new JavaServiceDynamicProxy(svc), new JavaServiceDynamicProxy(binSvc)); - } - - /// - /// Tests java service instance. - /// - private void DoTestService(IJavaService svc, IJavaService binSvc) - { // Basics Assert.IsTrue(svc.isInitialized()); Assert.IsTrue(TestUtils.WaitForCondition(() => svc.isExecuted(), 500)); Assert.IsFalse(svc.isCancelled()); - + // Primitives Assert.AreEqual(4, svc.test((byte) 3)); Assert.AreEqual(5, svc.test((short) 4)); @@ -951,6 +912,24 @@ private void DoTestService(IJavaService svc, IJavaService binSvc) // Binary Assert.AreEqual(7, svc.testBinarizable(new PlatformComputeBinarizable {Field = 6}).Field); + // Binary collections + var arr = new[] {10, 11, 12}.Select( + x => new PlatformComputeBinarizable {Field = x}).ToArray(); + var arrOfObj = arr.ToArray(); + + Assert.AreEqual(new[] {11, 12, 13}, svc.testBinarizableCollection(arr) + .OfType().Select(x => x.Field)); + + Assert.AreEqual(new[] {11, 12, 13}, svc.testBinarizableArrayOfObjects(arrOfObj) + .OfType().Select(x => x.Field)); + + Assert.IsNull(svc.testBinarizableArrayOfObjects(null)); + + Assert.AreEqual(new[] {11, 12, 13}, svc.testBinarizableArray(arr) + .Select(x => x.Field)); + + Assert.IsNull(svc.testBinarizableArray(null)); + // Binary object Assert.AreEqual(15, binSvc.testBinaryObject( @@ -971,20 +950,122 @@ private void DoTestService(IJavaService svc, IJavaService binSvc) Assert.IsNull(svc.testNullUUID(null)); Assert.AreEqual(guid, svc.testArray(new Guid?[] {guid})[0]); - // Binary collections - var arr = new[] {10, 11, 12}.Select( - x => new PlatformComputeBinarizable {Field = x}).ToArray(); - var arrOfObj = arr.ToArray(); + // Binary object array. + var binArr = arr.Select(Grid1.GetBinary().ToBinary).ToArray(); - Assert.AreEqual(new[] {11, 12, 13}, svc.testBinarizableArrayOfObjects(arrOfObj) - .OfType().Select(x => x.Field)); + Assert.AreEqual(new[] {11, 12, 13}, binSvc.testBinaryObjectArray(binArr) + .Select(x => x.GetField("Field"))); - Assert.IsNull(svc.testBinarizableArrayOfObjects(null)); + DateTime dt1 = new DateTime(1982, 4, 1, 0, 0, 0, 0, DateTimeKind.Utc); + DateTime dt2 = new DateTime(1991, 10, 1, 0, 0, 0, 0, DateTimeKind.Utc); - Assert.AreEqual(new[] {11, 12, 13}, svc.testBinarizableArray(arr) - .Select(x => x.Field)); + Assert.AreEqual(dt2, svc.testDate(dt1)); - Assert.IsNull(svc.testBinarizableArray(null)); + var cache = Grid1.GetOrCreateCache("net-dates"); + + cache.Put(1, dt1); + cache.Put(2, dt2); + + svc.testDateFromCache(); + + Assert.AreEqual(dt1, cache.Get(3)); + Assert.AreEqual(dt2, cache.Get(4)); + + DateTime dt3 = new DateTime(1982, 4, 1, 0, 0, 0, 0, DateTimeKind.Local); + DateTime dt4 = new DateTime(1991, 10, 1, 0, 0, 0, 0, DateTimeKind.Local); + + Assert.AreEqual(dt4, svc.testDate(dt3)); + + cache.Put(5, dt3); + cache.Put(6, dt4); + + svc.testDateFromCache2(); + + Assert.AreEqual(dt3, cache.Get(7)); + Assert.AreEqual(dt4, cache.Get(8)); + + Services.Cancel(javaSvcName); + } + + /// + /// Tests Java service invocation with dynamic proxy. + /// + [Test] + public void TestCallJavaServiceDynamicProxy() + { + // Deploy Java service + var javaSvcName = TestUtils.DeployJavaService(Grid1); + var svc = Grid1.GetServices().GetDynamicServiceProxy(javaSvcName, true); + + // Basics + Assert.IsTrue(svc.isInitialized()); + Assert.IsTrue(TestUtils.WaitForCondition(() => svc.isExecuted(), 500)); + Assert.IsFalse(svc.isCancelled()); + + // Primitives + Assert.AreEqual(4, svc.test((byte)3)); + Assert.AreEqual(5, svc.test((short)4)); + Assert.AreEqual(6, svc.test(5)); + Assert.AreEqual(6, svc.test((long)5)); + Assert.AreEqual(3.8f, svc.test(2.3f)); + Assert.AreEqual(5.8, svc.test(3.3)); + Assert.IsFalse(svc.test(true)); + Assert.AreEqual('b', svc.test('a')); + Assert.AreEqual("Foo!", svc.test("Foo")); + + // Nullables (Java wrapper types) + Assert.AreEqual(4, svc.testWrapper(3)); + Assert.AreEqual(5, svc.testWrapper((short?)4)); + Assert.AreEqual(6, svc.testWrapper((int?)5)); + Assert.AreEqual(6, svc.testWrapper((long?)5)); + Assert.AreEqual(3.8f, svc.testWrapper(2.3f)); + Assert.AreEqual(5.8, svc.testWrapper(3.3)); + Assert.AreEqual(false, svc.testWrapper(true)); + Assert.AreEqual('b', svc.testWrapper('a')); + + // Arrays + Assert.AreEqual(new byte[] { 2, 3, 4 }, svc.testArray(new byte[] { 1, 2, 3 })); + Assert.AreEqual(new short[] { 2, 3, 4 }, svc.testArray(new short[] { 1, 2, 3 })); + Assert.AreEqual(new[] { 2, 3, 4 }, svc.testArray(new[] { 1, 2, 3 })); + Assert.AreEqual(new long[] { 2, 3, 4 }, svc.testArray(new long[] { 1, 2, 3 })); + Assert.AreEqual(new float[] { 2, 3, 4 }, svc.testArray(new float[] { 1, 2, 3 })); + Assert.AreEqual(new double[] { 2, 3, 4 }, svc.testArray(new double[] { 1, 2, 3 })); + Assert.AreEqual(new[] { "a1", "b1" }, svc.testArray(new[] { "a", "b" })); + Assert.AreEqual(new[] { 'c', 'd' }, svc.testArray(new[] { 'b', 'c' })); + Assert.AreEqual(new[] { false, true, false }, svc.testArray(new[] { true, false, true })); + + // Nulls + Assert.AreEqual(9, svc.testNull(8)); + Assert.IsNull(svc.testNull(null)); + + // Overloads + Assert.AreEqual(3, svc.test(2, "1")); + Assert.AreEqual(3, svc.test("1", 2)); + + // Binary + Assert.AreEqual(7, svc.testBinarizable(new PlatformComputeBinarizable { Field = 6 }).Field); + + // Binary object + var binSvc = Services.WithKeepBinary().WithServerKeepBinary().GetDynamicServiceProxy(javaSvcName); + + Assert.AreEqual(15, + binSvc.testBinaryObject( + Grid1.GetBinary().ToBinary(new PlatformComputeBinarizable { Field = 6 })) + .GetField("Field")); + + DateTime dt = new DateTime(1992, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); + + Assert.AreEqual(dt, svc.test(dt)); + Assert.AreEqual(dt, svc.testNullTimestamp(dt)); + Assert.IsNull(svc.testNullTimestamp(null)); + Assert.AreEqual(dt, svc.testArray(new DateTime?[] { dt })[0]); + + Guid guid = Guid.NewGuid(); + + Assert.AreEqual(guid, svc.test(guid)); + Assert.AreEqual(guid, svc.testNullUUID(guid)); + Assert.IsNull(svc.testNullUUID(null)); + Assert.AreEqual(guid, svc.testArray(new Guid?[] { guid })[0]); DateTime dt1 = new DateTime(1982, 4, 1, 0, 0, 0, 0, DateTimeKind.Utc); DateTime dt2 = new DateTime(1991, 10, 1, 0, 0, 0, 0, DateTimeKind.Utc); From 03469e9e7a9f77d370313c54581e0f86c7ee1db9 Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Mon, 14 Dec 2020 20:11:16 +0300 Subject: [PATCH 09/37] IGNITE-12824: Tests fix. --- .../Binary/BinaryDateTimeTest.cs | 18 ++++++++++-------- .../Cache/Query/Linq/CacheLinqTest.DateTime.cs | 7 ------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs index e971eeac04b3c..ee541a55abd19 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs @@ -138,23 +138,25 @@ private static void AssertDateTimeField(Action setValue, private static void AssertTimestampField(Action setValue, Func getValue, string fieldName) where T : new() { - // Non-UTC DateTime throws. + // Non-UTC DateTime works. var binary = Ignition.GetIgnite().GetBinary(); var obj = new T(); setValue(obj, DateTime.Now); + + setValue(obj, DateTime.UtcNow); + var bin = binary.ToBinary(obj); + var res = bin.Deserialize(); - var ex = Assert.Throws(() => binary.ToBinary(obj), - "Timestamp fields should throw an error on non-UTC values"); - - Assert.AreEqual("DateTime is not UTC. Only UTC DateTime can be used for interop with other platforms.", - ex.Message); + Assert.AreEqual(getValue(obj), getValue(res)); + Assert.AreEqual(getValue(obj), bin.GetField(fieldName)); + Assert.AreEqual("Timestamp", bin.GetBinaryType().GetFieldTypeName(fieldName)); // UTC DateTime works. setValue(obj, DateTime.UtcNow); - var bin = binary.ToBinary(obj); - var res = bin.Deserialize(); + bin = binary.ToBinary(obj); + res = bin.Deserialize(); Assert.AreEqual(getValue(obj), getValue(res)); Assert.AreEqual(getValue(obj), bin.GetField(fieldName)); diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Linq/CacheLinqTest.DateTime.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Linq/CacheLinqTest.DateTime.cs index b869dc4c2cf36..f4650f1813b8f 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Linq/CacheLinqTest.DateTime.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Linq/CacheLinqTest.DateTime.cs @@ -46,13 +46,6 @@ public void TestDateTime() var roles = GetRoleCache().AsCacheQueryable(); var persons = GetPersonCache().AsCacheQueryable(); - // Invalid dateTime - // ReSharper disable once ReturnValueOfPureMethodIsNotUsed - var ex = Assert.Throws(() => - roles.Where(x => x.Value.Date > DateTime.Now).ToArray()); - Assert.AreEqual("DateTime is not UTC. Only UTC DateTime can be used for interop with other platforms.", - ex.Message); - // Test retrieval var dates = roles.OrderBy(x => x.Value.Date).Select(x => x.Value.Date); var expDates = GetRoleCache().Select(x => x.Value.Date).OrderBy(x => x).ToArray(); From 75ee2ceb9888bba5f2d04f2e9f5a44cd9a282733 Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Wed, 16 Dec 2020 17:33:42 +0300 Subject: [PATCH 10/37] IGNITE-12824: Test update --- .../platform/PlatformDeployServiceTask.java | 29 +++++++++++++++---- .../Services/IJavaService.cs | 4 +-- .../Services/JavaServiceDynamicProxy.cs | 4 +-- .../Services/ServicesTest.cs | 6 ++-- 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java b/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java index 2687d1822bd75..caeb261b91b16 100644 --- a/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java +++ b/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java @@ -18,6 +18,8 @@ package org.apache.ignite.platform; import java.sql.Timestamp; +import java.time.LocalDateTime; +import java.time.ZoneId; import java.util.ArrayList; import java.util.Calendar; import java.util.Collection; @@ -45,6 +47,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import static java.time.Month.APRIL; +import static java.time.Month.OCTOBER; import static java.util.Calendar.JANUARY; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -500,6 +504,7 @@ public Map testMap(Map map) { return m; } + /** */ public Timestamp testDate(Timestamp date) { if (date == null) return null; @@ -509,7 +514,8 @@ public Timestamp testDate(Timestamp date) { return new Timestamp(new Date(91, Calendar.OCTOBER, 1, 0, 0, 0).getTime()); } - public void testDateFromCache() { + /** */ + public void testUTCDateFromCache() { IgniteCache cache = ignite.cache("net-dates"); cache.put(3, new Timestamp(new Date(82, Calendar.APRIL, 1, 0, 0, 0).getTime())); @@ -519,14 +525,25 @@ public void testDateFromCache() { assertEquals(new Timestamp(new Date(91, Calendar.OCTOBER, 1, 0, 0, 0).getTime()), cache.get(2)); } - public void testDateFromCache2() { + /** */ + public void testLocalDateFromCache() { IgniteCache cache = ignite.cache("net-dates"); - cache.put(7, new Timestamp(new Date(82, Calendar.APRIL, 1, 0, 0, 0).getTime())); - cache.put(8, new Timestamp(new Date(91, Calendar.OCTOBER, 1, 0, 0, 0).getTime())); + Timestamp dt1 = timestamp(LocalDateTime.of(1982, APRIL, 1, 0, 0, 0, 0)); + Timestamp dt2 = timestamp(LocalDateTime.of(1991, OCTOBER, 1, 0, 0, 0)); + + cache.put(7, dt1); + cache.put(8, dt2); + + assertEquals(dt1, cache.get(5)); + assertEquals(dt2, cache.get(6)); + } + + /** */ + private Timestamp timestamp(LocalDateTime ldt) { + Date dt = Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant()); - assertEquals(new Timestamp(new Date(82, Calendar.APRIL, 1, 0, 0, 0).getTime()), cache.get(5)); - assertEquals(new Timestamp(new Date(91, Calendar.OCTOBER, 1, 0, 0, 0).getTime()), cache.get(6)); + return new Timestamp(dt.getTime()); } /** */ diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/IJavaService.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/IJavaService.cs index 622e7b2f3dbaa..fbf9d6ef2cef4 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/IJavaService.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/IJavaService.cs @@ -181,10 +181,10 @@ public interface IJavaService DateTime testDate(DateTime date); /** */ - void testDateFromCache(); + void testUTCDateFromCache(); /** */ - void testDateFromCache2(); + void testLocalDateFromCache(); /** */ void sleep(long delayMs); diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/JavaServiceDynamicProxy.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/JavaServiceDynamicProxy.cs index 13e6e74490bbb..9f1aef688e4d3 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/JavaServiceDynamicProxy.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/JavaServiceDynamicProxy.cs @@ -338,13 +338,13 @@ public DateTime testDate(DateTime date) } /** */ - public void testDateFromCache() + public void testUTCDateFromCache() { _svc.testDateFromCache(); } /** */ - public void testDateFromCache2() + public void testLocalDateFromCache() { _svc.testDateFromCache2(); } diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs index 9e981def97c9c..a2ef446f4f5ee 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs @@ -966,7 +966,7 @@ public void TestCallJavaService() cache.Put(1, dt1); cache.Put(2, dt2); - svc.testDateFromCache(); + svc.testUTCDateFromCache(); Assert.AreEqual(dt1, cache.Get(3)); Assert.AreEqual(dt2, cache.Get(4)); @@ -974,12 +974,10 @@ public void TestCallJavaService() DateTime dt3 = new DateTime(1982, 4, 1, 0, 0, 0, 0, DateTimeKind.Local); DateTime dt4 = new DateTime(1991, 10, 1, 0, 0, 0, 0, DateTimeKind.Local); - Assert.AreEqual(dt4, svc.testDate(dt3)); - cache.Put(5, dt3); cache.Put(6, dt4); - svc.testDateFromCache2(); + svc.testLocalDateFromCache(); Assert.AreEqual(dt3, cache.Get(7)); Assert.AreEqual(dt4, cache.Get(8)); From 5b196fe75331c092fe83d4e6ac538a543a0e2692 Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Wed, 16 Dec 2020 17:46:39 +0300 Subject: [PATCH 11/37] IGNITE-13865: Support of DateTime as a key or value in .Net and Java --- .../platform/PlatformDeployServiceTask.java | 21 ---------------- .../Binary/BinaryDateTimeTest.cs | 18 +++++++------- .../Query/Linq/CacheLinqTest.DateTime.cs | 7 ++++++ .../Services/IJavaService.cs | 3 --- .../Services/JavaServiceDynamicProxy.cs | 6 ----- .../Services/ServicesTest.cs | 24 ------------------- .../Impl/Binary/BinaryUtils.cs | 6 +++++ 7 files changed, 21 insertions(+), 64 deletions(-) diff --git a/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java b/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java index caeb261b91b16..8fc8d0d30a6e0 100644 --- a/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java +++ b/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java @@ -525,27 +525,6 @@ public void testUTCDateFromCache() { assertEquals(new Timestamp(new Date(91, Calendar.OCTOBER, 1, 0, 0, 0).getTime()), cache.get(2)); } - /** */ - public void testLocalDateFromCache() { - IgniteCache cache = ignite.cache("net-dates"); - - Timestamp dt1 = timestamp(LocalDateTime.of(1982, APRIL, 1, 0, 0, 0, 0)); - Timestamp dt2 = timestamp(LocalDateTime.of(1991, OCTOBER, 1, 0, 0, 0)); - - cache.put(7, dt1); - cache.put(8, dt2); - - assertEquals(dt1, cache.get(5)); - assertEquals(dt2, cache.get(6)); - } - - /** */ - private Timestamp timestamp(LocalDateTime ldt) { - Date dt = Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant()); - - return new Timestamp(dt.getTime()); - } - /** */ public void sleep(long delayMs) { try { diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs index ee541a55abd19..a8426eac03f5e 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs @@ -138,25 +138,23 @@ private static void AssertDateTimeField(Action setValue, private static void AssertTimestampField(Action setValue, Func getValue, string fieldName) where T : new() { - // Non-UTC DateTime works. + // Non-UTC DateTime throws. var binary = Ignition.GetIgnite().GetBinary(); var obj = new T(); setValue(obj, DateTime.Now); - - setValue(obj, DateTime.UtcNow); - var bin = binary.ToBinary(obj); - var res = bin.Deserialize(); - Assert.AreEqual(getValue(obj), getValue(res)); - Assert.AreEqual(getValue(obj), bin.GetField(fieldName)); - Assert.AreEqual("Timestamp", bin.GetBinaryType().GetFieldTypeName(fieldName)); + var ex = Assert.Throws(() => binary.ToBinary(obj), + "Timestamp fields should throw an error on non-UTC values"); + + Assert.AreEqual("DateTime is not UTC. Only UTC DateTime can be used for interop with other platforms.", + ex.Message); // UTC DateTime works. setValue(obj, DateTime.UtcNow); - bin = binary.ToBinary(obj); - res = bin.Deserialize(); + var bin = binary.ToBinary(obj); + var res = bin.Deserialize(); Assert.AreEqual(getValue(obj), getValue(res)); Assert.AreEqual(getValue(obj), bin.GetField(fieldName)); diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Linq/CacheLinqTest.DateTime.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Linq/CacheLinqTest.DateTime.cs index f4650f1813b8f..b869dc4c2cf36 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Linq/CacheLinqTest.DateTime.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Linq/CacheLinqTest.DateTime.cs @@ -46,6 +46,13 @@ public void TestDateTime() var roles = GetRoleCache().AsCacheQueryable(); var persons = GetPersonCache().AsCacheQueryable(); + // Invalid dateTime + // ReSharper disable once ReturnValueOfPureMethodIsNotUsed + var ex = Assert.Throws(() => + roles.Where(x => x.Value.Date > DateTime.Now).ToArray()); + Assert.AreEqual("DateTime is not UTC. Only UTC DateTime can be used for interop with other platforms.", + ex.Message); + // Test retrieval var dates = roles.OrderBy(x => x.Value.Date).Select(x => x.Value.Date); var expDates = GetRoleCache().Select(x => x.Value.Date).OrderBy(x => x).ToArray(); diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/IJavaService.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/IJavaService.cs index fbf9d6ef2cef4..2c2f61cc9506f 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/IJavaService.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/IJavaService.cs @@ -183,9 +183,6 @@ public interface IJavaService /** */ void testUTCDateFromCache(); - /** */ - void testLocalDateFromCache(); - /** */ void sleep(long delayMs); } diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/JavaServiceDynamicProxy.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/JavaServiceDynamicProxy.cs index 9f1aef688e4d3..a2b5d03142833 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/JavaServiceDynamicProxy.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/JavaServiceDynamicProxy.cs @@ -343,12 +343,6 @@ public void testUTCDateFromCache() _svc.testDateFromCache(); } - /** */ - public void testLocalDateFromCache() - { - _svc.testDateFromCache2(); - } - /** */ public void sleep(long delayMs) { diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs index a2ef446f4f5ee..e9b13e754585b 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs @@ -971,17 +971,6 @@ public void TestCallJavaService() Assert.AreEqual(dt1, cache.Get(3)); Assert.AreEqual(dt2, cache.Get(4)); - DateTime dt3 = new DateTime(1982, 4, 1, 0, 0, 0, 0, DateTimeKind.Local); - DateTime dt4 = new DateTime(1991, 10, 1, 0, 0, 0, 0, DateTimeKind.Local); - - cache.Put(5, dt3); - cache.Put(6, dt4); - - svc.testLocalDateFromCache(); - - Assert.AreEqual(dt3, cache.Get(7)); - Assert.AreEqual(dt4, cache.Get(8)); - Services.Cancel(javaSvcName); } @@ -1079,19 +1068,6 @@ public void TestCallJavaServiceDynamicProxy() Assert.AreEqual(dt1, cache.Get(3)); Assert.AreEqual(dt2, cache.Get(4)); - - DateTime dt3 = new DateTime(1982, 4, 1, 0, 0, 0, 0, DateTimeKind.Local); - DateTime dt4 = new DateTime(1991, 10, 1, 0, 0, 0, 0, DateTimeKind.Local); - - Assert.AreEqual(dt4, svc.testDate(dt3)); - - cache.Put(5, dt3); - cache.Put(6, dt4); - - svc.testDateFromCache2(); - - Assert.AreEqual(dt3, cache.Get(7)); - Assert.AreEqual(dt4, cache.Get(8)); } /// diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs index 4466f27e5029b..5b30c7ef69dbb 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs @@ -1614,6 +1614,12 @@ public static void ValidateProtocolVersion(byte version) */ private static void ToJavaDate(DateTime date, out long high, out int low) { + if (date.Kind != DateTimeKind.Utc) + { + throw new BinaryObjectException( + "DateTime is not UTC. Only UTC DateTime can be used for interop with other platforms."); + } + long diff = date.Ticks - JavaDateTicks; high = diff / TimeSpan.TicksPerMillisecond; From a06e4a3bc9da5a534069c23371e0979b2bc9643a Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Wed, 16 Dec 2020 17:59:43 +0300 Subject: [PATCH 12/37] IGNITE-13865: Support of DateTime as a key or value in .Net and Java --- .../Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs index a8426eac03f5e..e971eeac04b3c 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs @@ -145,7 +145,7 @@ private static void AssertTimestampField(Action setValue, setValue(obj, DateTime.Now); - var ex = Assert.Throws(() => binary.ToBinary(obj), + var ex = Assert.Throws(() => binary.ToBinary(obj), "Timestamp fields should throw an error on non-UTC values"); Assert.AreEqual("DateTime is not UTC. Only UTC DateTime can be used for interop with other platforms.", From 18795944b37a8c714c023c93b3c9b6baad904028 Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Wed, 16 Dec 2020 18:01:23 +0300 Subject: [PATCH 13/37] IGNITE-13865: Support of DateTime as a key or value in .Net and Java --- .../dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs index e9b13e754585b..0ad69ade7cb2d 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs @@ -1064,7 +1064,7 @@ public void TestCallJavaServiceDynamicProxy() cache.Put(1, dt1); cache.Put(2, dt2); - svc.testDateFromCache(); + svc.testUTCDateFromCache(); Assert.AreEqual(dt1, cache.Get(3)); Assert.AreEqual(dt2, cache.Get(4)); From e08e09ab3564f3ca9d7c2b021892190237db2368 Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Wed, 16 Dec 2020 18:05:34 +0300 Subject: [PATCH 14/37] IGNITE-13865: Support of DateTime as a key or value in .Net and Java --- .../Apache.Ignite.Core/Impl/Binary/BinarySystemHandlers.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinarySystemHandlers.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinarySystemHandlers.cs index 5f3e163e73b31..b7e9b0a216030 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinarySystemHandlers.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinarySystemHandlers.cs @@ -136,7 +136,7 @@ public static IBinarySystemWriteHandler GetWriteHandler(Type type, bool forceTim /// Find write handler for type. /// /// Type. - /// + /// Force timestamp. /// /// Write handler or NULL. /// From ef420dac3c47b5694b8b5803ab799dd2da83b533 Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Wed, 16 Dec 2020 18:23:48 +0300 Subject: [PATCH 15/37] IGNITE-13865: Support of DateTime as a key or value in .Net and Java --- .../org/apache/ignite/platform/PlatformDeployServiceTask.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java b/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java index 8fc8d0d30a6e0..323f317959fbd 100644 --- a/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java +++ b/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java @@ -18,8 +18,6 @@ package org.apache.ignite.platform; import java.sql.Timestamp; -import java.time.LocalDateTime; -import java.time.ZoneId; import java.util.ArrayList; import java.util.Calendar; import java.util.Collection; @@ -47,8 +45,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import static java.time.Month.APRIL; -import static java.time.Month.OCTOBER; import static java.util.Calendar.JANUARY; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; From 7ac33e711f17f4ef6916bef733e27cf4fef63aea Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Thu, 17 Dec 2020 18:42:26 +0300 Subject: [PATCH 16/37] IGNITE-13865: Support of DateTime as a key or value in .Net and Java --- .../Apache.Ignite.Core/Binary/BinaryReflectiveSerializer.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Binary/BinaryReflectiveSerializer.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Binary/BinaryReflectiveSerializer.cs index 4b1614429ad35..f9874ba23484d 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Binary/BinaryReflectiveSerializer.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Binary/BinaryReflectiveSerializer.cs @@ -46,7 +46,6 @@ public sealed class BinaryReflectiveSerializer : IBinarySerializer private bool _isInUse; /** Force timestamp flag. */ - [Obsolete("Deprecated, use BinaryConfiguration.ForceTimestamp instead.")] private bool _forceTimestamp; /// From af92eb45cc27b155794f05bfbd990dbb3d4d942f Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Thu, 17 Dec 2020 18:48:56 +0300 Subject: [PATCH 17/37] IGNITE-13865: Support of DateTime as a key or value in .Net and Java --- .../dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs | 4 ++-- .../dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs index 4f2dab03cd5f6..9025b4df2d51d 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs @@ -875,7 +875,7 @@ public void WriteEnum(T val) throw new BinaryObjectException("Type is not an enum: " + type); } - var handler = BinarySystemHandlers.GetWriteHandler(type, _marsh.ForceTimestamp()); + var handler = BinarySystemHandlers.GetWriteHandler(type, _marsh.ForceTimestamp); if (handler != null) { @@ -1180,7 +1180,7 @@ public void Write(T obj) return; // Are we dealing with a well-known type? - var handler = BinarySystemHandlers.GetWriteHandler(type, _marsh.ForceTimestamp()); + var handler = BinarySystemHandlers.GetWriteHandler(type, _marsh.ForceTimestamp); if (handler != null) { diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs index 44e1e872f7779..8334081957b5c 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs @@ -78,6 +78,7 @@ internal class Marshaller public Marshaller(BinaryConfiguration cfg, ILogger log = null) { _cfg = cfg ?? new BinaryConfiguration(); + ForceTimestamp = _cfg.ForceTimestamp; _log = log; @@ -954,9 +955,6 @@ private static IBinaryNameMapper GetDefaultNameMapper() /// /// Gets force timestamp flag value. /// - public bool ForceTimestamp() - { - return _cfg.ForceTimestamp; - } + public bool ForceTimestamp { get; } } } From 3fb26e168dabd7d77712e9f0d1ce1cc1ccc8b9da Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Sat, 19 Dec 2020 00:31:10 +0300 Subject: [PATCH 18/37] IGNITE-12824: Test update --- .../Apache.Ignite.Core.Tests/Services/IJavaService.cs | 4 ++-- .../Apache.Ignite.Core/Binary/BinaryConfiguration.cs | 10 ---------- .../Impl/Binary/BinarySystemHandlers.cs | 9 ++------- 3 files changed, 4 insertions(+), 19 deletions(-) diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/IJavaService.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/IJavaService.cs index e7d5861740622..dfcaaff51e38b 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/IJavaService.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/IJavaService.cs @@ -178,10 +178,10 @@ public interface IJavaService IDictionary testMap(IDictionary dict); /** */ - DateTime testDate(DateTime date); + void testDateArray(DateTime?[] dates); /** */ - void testDateArray(DateTime?[] dates); + DateTime testDate(DateTime date); /** */ void testUTCDateFromCache(); diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Binary/BinaryConfiguration.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Binary/BinaryConfiguration.cs index ce70a39064162..2a2bb9579512e 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Binary/BinaryConfiguration.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Binary/BinaryConfiguration.cs @@ -39,11 +39,6 @@ public class BinaryConfiguration /// Default setting. /// public const bool DefaultKeepDeserialized = true; - - /// - /// Default setting. - /// - public const bool DefaultForceTimestamp = false; /// /// Default setting. @@ -186,10 +181,5 @@ internal bool? CompactFooterInternal { get { return _compactFooter; } } - - /// - /// Gets or sets a value indicating whether all DateTime values should be written as Timestamp. - /// - public bool ForceTimestamp { get; set; } } } diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinarySystemHandlers.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinarySystemHandlers.cs index 128b002afbc39..3ffb1f978b680 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinarySystemHandlers.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinarySystemHandlers.cs @@ -136,7 +136,7 @@ public static IBinarySystemWriteHandler GetWriteHandler(Type type, bool forceTim return WriteHandlers.GetOrAdd(type, t => { - return FindWriteHandler(t, forceTimestamp); + return FindWriteHandler(t); }); } @@ -144,11 +144,10 @@ public static IBinarySystemWriteHandler GetWriteHandler(Type type, bool forceTim /// Find write handler for type. /// /// Type. - /// Force timestamp. /// /// Write handler or NULL. /// - private static IBinarySystemWriteHandler FindWriteHandler(Type type, bool forceTimestamp) + private static IBinarySystemWriteHandler FindWriteHandler(Type type) { // 1. Well-known types. if (type == typeof(string)) @@ -157,8 +156,6 @@ private static IBinarySystemWriteHandler FindWriteHandler(Type type, bool forceT return new BinarySystemWriteHandler(WriteDecimal, false); if (type == typeof(Guid)) return new BinarySystemWriteHandler(WriteGuid, false); - if (type == typeof(DateTime) && forceTimestamp) - return new BinarySystemWriteHandler(WriteTimestamp, false); if (type == typeof (BinaryObject)) return new BinarySystemWriteHandler(WriteBinary, false); if (type == typeof (BinaryEnum)) @@ -236,8 +233,6 @@ private static IBinarySystemWriteHandler FindWriteHandler(Type type, bool forceT return new BinarySystemWriteHandler(WriteStringArray, true); if (elemType == typeof(Guid?)) return new BinarySystemWriteHandler(WriteGuidArray, true); - if (elemType == typeof(DateTime?) && forceTimestamp) - return new BinarySystemWriteHandler(WriteTimestampArray, true); // Enums. if (BinaryUtils.IsIgniteEnum(elemType) || elemType == typeof(BinaryEnum)) return new BinarySystemWriteHandler(WriteEnumArray, true); From d84249a0ac41644744737c9d05e4b81604c25985 Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Sat, 19 Dec 2020 22:05:05 +0300 Subject: [PATCH 19/37] IGNITE-12824: Update of the date conversion(works on Mac) --- .../platform/PlatformDeployServiceTask.java | 18 ++++++++++++++++++ .../Binary/BinaryDateTimeTest.cs | 14 ++++++++------ .../Cache/Query/Linq/CacheLinqTest.DateTime.cs | 7 ------- .../Services/IJavaService.cs | 3 +++ .../Services/JavaServiceDynamicProxy.cs | 6 ++++++ .../Services/ServicesTest.cs | 14 ++++++++++++++ .../Impl/Binary/BinaryUtils.cs | 3 +-- 7 files changed, 50 insertions(+), 15 deletions(-) diff --git a/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java b/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java index cb3f8d7c91024..1e0edeecee4c1 100644 --- a/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java +++ b/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java @@ -18,6 +18,8 @@ package org.apache.ignite.platform; import java.sql.Timestamp; +import java.time.ZoneId; +import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Calendar; import java.util.Collection; @@ -530,6 +532,22 @@ public void testUTCDateFromCache() { assertEquals(new Timestamp(new Date(91, Calendar.OCTOBER, 1, 0, 0, 0).getTime()), cache.get(2)); } + /** */ + public void testLocalDateFromCache() { + IgniteCache cache = ignite.cache("net-dates"); + + ZoneId msk = ZoneId.of("Europe/Moscow"); + + Timestamp ts1 = new Timestamp(ZonedDateTime.of(1982, 4, 1, 1, 0, 0, 0, msk).toInstant().toEpochMilli()); + Timestamp ts2 = new Timestamp(ZonedDateTime.of(1982, 3, 31, 22, 0, 0, 0, msk).toInstant().toEpochMilli()); + + assertEquals(ts1, cache.get(5)); + assertEquals(ts2, cache.get(6)); + + cache.put(7, ts1); + cache.put(8, ts2); + } + /** */ public void sleep(long delayMs) { try { diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs index e971eeac04b3c..ef15b9ca2b1f8 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs @@ -143,18 +143,20 @@ private static void AssertTimestampField(Action setValue, var obj = new T(); + // Local DateTime works. setValue(obj, DateTime.Now); - var ex = Assert.Throws(() => binary.ToBinary(obj), - "Timestamp fields should throw an error on non-UTC values"); + var bin = binary.ToBinary(obj); + var res = bin.Deserialize(); - Assert.AreEqual("DateTime is not UTC. Only UTC DateTime can be used for interop with other platforms.", - ex.Message); + Assert.AreEqual(getValue(obj), getValue(res).ToLocalTime()); + Assert.AreEqual(getValue(obj), bin.GetField(fieldName).ToLocalTime()); + Assert.AreEqual("Timestamp", bin.GetBinaryType().GetFieldTypeName(fieldName)); // UTC DateTime works. setValue(obj, DateTime.UtcNow); - var bin = binary.ToBinary(obj); - var res = bin.Deserialize(); + bin = binary.ToBinary(obj); + res = bin.Deserialize(); Assert.AreEqual(getValue(obj), getValue(res)); Assert.AreEqual(getValue(obj), bin.GetField(fieldName)); diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Linq/CacheLinqTest.DateTime.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Linq/CacheLinqTest.DateTime.cs index b869dc4c2cf36..f4650f1813b8f 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Linq/CacheLinqTest.DateTime.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Linq/CacheLinqTest.DateTime.cs @@ -46,13 +46,6 @@ public void TestDateTime() var roles = GetRoleCache().AsCacheQueryable(); var persons = GetPersonCache().AsCacheQueryable(); - // Invalid dateTime - // ReSharper disable once ReturnValueOfPureMethodIsNotUsed - var ex = Assert.Throws(() => - roles.Where(x => x.Value.Date > DateTime.Now).ToArray()); - Assert.AreEqual("DateTime is not UTC. Only UTC DateTime can be used for interop with other platforms.", - ex.Message); - // Test retrieval var dates = roles.OrderBy(x => x.Value.Date).Select(x => x.Value.Date); var expDates = GetRoleCache().Select(x => x.Value.Date).OrderBy(x => x).ToArray(); diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/IJavaService.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/IJavaService.cs index dfcaaff51e38b..07db779b2c8c4 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/IJavaService.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/IJavaService.cs @@ -186,6 +186,9 @@ public interface IJavaService /** */ void testUTCDateFromCache(); + /** */ + void testLocalDateFromCache(); + /** */ void sleep(long delayMs); } diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/JavaServiceDynamicProxy.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/JavaServiceDynamicProxy.cs index 26c06373a44e0..41566020355e9 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/JavaServiceDynamicProxy.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/JavaServiceDynamicProxy.cs @@ -349,6 +349,12 @@ public void testUTCDateFromCache() _svc.testDateFromCache(); } + /** */ + public void testLocalDateFromCache() + { + _svc.testLocalDateFromCache(); + } + /** */ public void sleep(long delayMs) { diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs index b2748aec0eb0c..80a29edeed23d 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs @@ -973,6 +973,20 @@ public void TestCallJavaService() Assert.AreEqual(dt1, cache.Get(3)); Assert.AreEqual(dt2, cache.Get(4)); + //This Date in Europe/Moscow have offset +4. + DateTime dt3 = new DateTime(1982, 4, 1, 1, 0, 0, 0, DateTimeKind.Local); + //This Date in Europe/Moscow have offset +3. + DateTime dt4 = new DateTime(1982, 3, 31, 22, 0, 0, 0, DateTimeKind.Local); + + cache.Put(5, dt3); + cache.Put(6, dt4); + + svc.testLocalDateFromCache(); + + Console.WriteLine(dt3); + Assert.AreEqual(dt3, cache.Get(7).ToLocalTime()); + Assert.AreEqual(dt4, cache.Get(8).ToLocalTime()); + Services.Cancel(javaSvcName); } diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs index 5b30c7ef69dbb..2b92c1df6daae 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs @@ -1616,8 +1616,7 @@ private static void ToJavaDate(DateTime date, out long high, out int low) { if (date.Kind != DateTimeKind.Utc) { - throw new BinaryObjectException( - "DateTime is not UTC. Only UTC DateTime can be used for interop with other platforms."); + date = date.ToUniversalTime(); } long diff = date.Ticks - JavaDateTicks; From 0b0af6fbfd5f316892c99cb10959ce8483609b22 Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Sun, 20 Dec 2020 11:34:00 +0300 Subject: [PATCH 20/37] IGNITE-12824: Allows local dates only for `ForceTimestamp` mode. --- .../platform/PlatformDeployServiceTask.java | 2 ++ .../Binary/BinarySelfTest.cs | 5 ----- .../Impl/Binary/BinarySystemHandlers.cs | 4 ++-- .../Impl/Binary/BinaryUtils.cs | 19 ++++++++++++++----- .../Impl/Binary/BinaryWriter.cs | 8 ++++---- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java b/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java index 1e0edeecee4c1..688b3b125452c 100644 --- a/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java +++ b/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java @@ -538,7 +538,9 @@ public void testLocalDateFromCache() { ZoneId msk = ZoneId.of("Europe/Moscow"); + //This Date in Europe/Moscow have offset +4. Timestamp ts1 = new Timestamp(ZonedDateTime.of(1982, 4, 1, 1, 0, 0, 0, msk).toInstant().toEpochMilli()); + //This Date in Europe/Moscow have offset +3. Timestamp ts2 = new Timestamp(ZonedDateTime.of(1982, 3, 31, 22, 0, 0, 0, msk).toInstant().toEpochMilli()); assertEquals(ts1, cache.get(5)); diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs index bf3b4747502f4..cb7288fbfd36d 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs @@ -669,11 +669,6 @@ public void TestDateTime() var timeUtc = DateTime.UtcNow; Assert.AreEqual(_marsh.Unmarshal(_marsh.Marshal(timeUtc)), timeUtc); - - // Check exception with non-UTC date - var stream = new BinaryHeapStream(128); - var writer = _marsh.StartMarshal(stream); - Assert.Throws(() => writer.WriteTimestamp(DateTime.Now)); } /** diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinarySystemHandlers.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinarySystemHandlers.cs index 3ffb1f978b680..cf18160998ab5 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinarySystemHandlers.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinarySystemHandlers.cs @@ -311,7 +311,7 @@ private static void WriteTimestamp(BinaryWriter ctx, DateTime obj) { ctx.Stream.WriteByte(BinaryTypeId.Timestamp); - BinaryUtils.WriteTimestamp(obj, ctx.Stream); + BinaryUtils.WriteTimestamp(obj, ctx.Stream, true); } /// @@ -455,7 +455,7 @@ private static void WriteTimestampArray(BinaryWriter ctx, DateTime?[] obj) { ctx.Stream.WriteByte(BinaryTypeId.ArrayTimestamp); - BinaryUtils.WriteTimestampArray(obj, ctx.Stream); + BinaryUtils.WriteTimestampArray(obj, ctx.Stream, true); } /// diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs index 2b92c1df6daae..c600bfad011d8 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs @@ -388,13 +388,14 @@ public static double[] ReadDoubleArray(IBinaryStream stream) * Write date. * Date. * Stream. + * True if non UTC dates supported */ - public static void WriteTimestamp(DateTime val, IBinaryStream stream) + public static void WriteTimestamp(DateTime val, IBinaryStream stream, bool allowLocal) { long high; int low; - ToJavaDate(val, out high, out low); + ToJavaDate(val, out high, out low, allowLocal); stream.WriteLong(high); stream.WriteInt(low); @@ -438,7 +439,8 @@ public static long DateTimeToJavaTicks(DateTime dateTime) /// /// Values. /// Stream. - public static void WriteTimestampArray(DateTime?[] vals, IBinaryStream stream) + /// True if non UTC dates supported + public static void WriteTimestampArray(DateTime?[] vals, IBinaryStream stream, bool allowLocal) { stream.WriteInt(vals.Length); @@ -448,7 +450,7 @@ public static void WriteTimestampArray(DateTime?[] vals, IBinaryStream stream) { stream.WriteByte(BinaryTypeId.Timestamp); - WriteTimestamp(val.Value, stream); + WriteTimestamp(val.Value, stream, allowLocal); } else stream.WriteByte(HdrNull); @@ -1611,9 +1613,16 @@ public static void ValidateProtocolVersion(byte version) * Date * High part (milliseconds). * Low part (nanoseconds) + * True if non UTC dates supported */ - private static void ToJavaDate(DateTime date, out long high, out int low) + private static void ToJavaDate(DateTime date, out long high, out int low, bool allowLocal) { + if (date.Kind != DateTimeKind.Utc && !allowLocal) + { + throw new BinaryObjectException( + "DateTime is not UTC. Only UTC DateTime can be used for interop with other platforms."); + } + if (date.Kind != DateTimeKind.Utc) { date = date.ToUniversalTime(); diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs index 9025b4df2d51d..f826c32dd27db 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs @@ -657,7 +657,7 @@ public void WriteTimestamp(string fieldName, DateTime? val) else { _stream.WriteByte(BinaryTypeId.Timestamp); - BinaryUtils.WriteTimestamp(val.Value, _stream); + BinaryUtils.WriteTimestamp(val.Value, _stream, _marsh.ForceTimestamp); } } @@ -672,7 +672,7 @@ public void WriteTimestamp(DateTime? val) else { _stream.WriteByte(BinaryTypeId.Timestamp); - BinaryUtils.WriteTimestamp(val.Value, _stream); + BinaryUtils.WriteTimestamp(val.Value, _stream, _marsh.ForceTimestamp); } } @@ -690,7 +690,7 @@ public void WriteTimestampArray(string fieldName, DateTime?[] val) else { _stream.WriteByte(BinaryTypeId.ArrayTimestamp); - BinaryUtils.WriteTimestampArray(val, _stream); + BinaryUtils.WriteTimestampArray(val, _stream, _marsh.ForceTimestamp); } } @@ -705,7 +705,7 @@ public void WriteTimestampArray(DateTime?[] val) else { _stream.WriteByte(BinaryTypeId.ArrayTimestamp); - BinaryUtils.WriteTimestampArray(val, _stream); + BinaryUtils.WriteTimestampArray(val, _stream, _marsh.ForceTimestamp); } } From e3ecbaaa1a8069db9ae79f65e87a6d789dca4171 Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Sun, 20 Dec 2020 11:57:10 +0300 Subject: [PATCH 21/37] IGNITE-12824: Allows local dates only for `ForceTimestamp` mode. --- .../Binary/BinaryDateTimeTest.cs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs index ef15b9ca2b1f8..e971eeac04b3c 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs @@ -143,20 +143,18 @@ private static void AssertTimestampField(Action setValue, var obj = new T(); - // Local DateTime works. setValue(obj, DateTime.Now); - var bin = binary.ToBinary(obj); - var res = bin.Deserialize(); + var ex = Assert.Throws(() => binary.ToBinary(obj), + "Timestamp fields should throw an error on non-UTC values"); - Assert.AreEqual(getValue(obj), getValue(res).ToLocalTime()); - Assert.AreEqual(getValue(obj), bin.GetField(fieldName).ToLocalTime()); - Assert.AreEqual("Timestamp", bin.GetBinaryType().GetFieldTypeName(fieldName)); + Assert.AreEqual("DateTime is not UTC. Only UTC DateTime can be used for interop with other platforms.", + ex.Message); // UTC DateTime works. setValue(obj, DateTime.UtcNow); - bin = binary.ToBinary(obj); - res = bin.Deserialize(); + var bin = binary.ToBinary(obj); + var res = bin.Deserialize(); Assert.AreEqual(getValue(obj), getValue(res)); Assert.AreEqual(getValue(obj), bin.GetField(fieldName)); From 332eb0667acc619f53222f2fb26994fe7852d9e8 Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Sun, 20 Dec 2020 11:59:05 +0300 Subject: [PATCH 22/37] IGNITE-12824: Allows local dates only for `ForceTimestamp` mode. --- .../Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs | 5 +++++ .../Cache/Query/Linq/CacheLinqTest.DateTime.cs | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs index cb7288fbfd36d..bf3b4747502f4 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs @@ -669,6 +669,11 @@ public void TestDateTime() var timeUtc = DateTime.UtcNow; Assert.AreEqual(_marsh.Unmarshal(_marsh.Marshal(timeUtc)), timeUtc); + + // Check exception with non-UTC date + var stream = new BinaryHeapStream(128); + var writer = _marsh.StartMarshal(stream); + Assert.Throws(() => writer.WriteTimestamp(DateTime.Now)); } /** diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Linq/CacheLinqTest.DateTime.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Linq/CacheLinqTest.DateTime.cs index f4650f1813b8f..b869dc4c2cf36 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Linq/CacheLinqTest.DateTime.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Linq/CacheLinqTest.DateTime.cs @@ -46,6 +46,13 @@ public void TestDateTime() var roles = GetRoleCache().AsCacheQueryable(); var persons = GetPersonCache().AsCacheQueryable(); + // Invalid dateTime + // ReSharper disable once ReturnValueOfPureMethodIsNotUsed + var ex = Assert.Throws(() => + roles.Where(x => x.Value.Date > DateTime.Now).ToArray()); + Assert.AreEqual("DateTime is not UTC. Only UTC DateTime can be used for interop with other platforms.", + ex.Message); + // Test retrieval var dates = roles.OrderBy(x => x.Value.Date).Select(x => x.Value.Date); var expDates = GetRoleCache().Select(x => x.Value.Date).OrderBy(x => x).ToArray(); From 1d1dc8642b107458957e60d26f3bd5a617f33fff Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Sun, 20 Dec 2020 12:53:46 +0300 Subject: [PATCH 23/37] IGNITE-12824: Allows local dates only for `ForceTimestamp` mode. --- .../Apache.Ignite.Core.Tests/Services/ServicesTest.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs index 80a29edeed23d..8636130782770 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs @@ -981,12 +981,18 @@ public void TestCallJavaService() cache.Put(5, dt3); cache.Put(6, dt4); + Assert.AreEqual(dt3.ToUniversalTime(), cache.Get(5).ToUniversalTime()); + Assert.AreEqual(dt4.ToUniversalTime(), cache.Get(6).ToUniversalTime()); + svc.testLocalDateFromCache(); - Console.WriteLine(dt3); Assert.AreEqual(dt3, cache.Get(7).ToLocalTime()); Assert.AreEqual(dt4, cache.Get(8).ToLocalTime()); + var now = DateTime.Now; + cache.Put(9, now); + Assert.AreEqual(now.ToUniversalTime(), cache.Get(9).ToUniversalTime()); + Services.Cancel(javaSvcName); } From c8462970a27527f98f3c19e2cb9c692b87258bba Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Sun, 20 Dec 2020 13:03:44 +0300 Subject: [PATCH 24/37] IGNITE-12824: Allows usages of Local dates but only for .NetCore applications. --- .../Services/ServicesTest.cs | 2 ++ .../Impl/Binary/BinarySystemHandlers.cs | 4 ++-- .../Impl/Binary/BinaryUtils.cs | 18 ++++++++---------- .../Impl/Binary/BinaryWriter.cs | 8 ++++---- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs index 8636130782770..f7c13c0069f3a 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs @@ -973,6 +973,7 @@ public void TestCallJavaService() Assert.AreEqual(dt1, cache.Get(3)); Assert.AreEqual(dt2, cache.Get(4)); +#if NETCOREAPP //This Date in Europe/Moscow have offset +4. DateTime dt3 = new DateTime(1982, 4, 1, 1, 0, 0, 0, DateTimeKind.Local); //This Date in Europe/Moscow have offset +3. @@ -992,6 +993,7 @@ public void TestCallJavaService() var now = DateTime.Now; cache.Put(9, now); Assert.AreEqual(now.ToUniversalTime(), cache.Get(9).ToUniversalTime()); +#endif Services.Cancel(javaSvcName); } diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinarySystemHandlers.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinarySystemHandlers.cs index cf18160998ab5..3ffb1f978b680 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinarySystemHandlers.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinarySystemHandlers.cs @@ -311,7 +311,7 @@ private static void WriteTimestamp(BinaryWriter ctx, DateTime obj) { ctx.Stream.WriteByte(BinaryTypeId.Timestamp); - BinaryUtils.WriteTimestamp(obj, ctx.Stream, true); + BinaryUtils.WriteTimestamp(obj, ctx.Stream); } /// @@ -455,7 +455,7 @@ private static void WriteTimestampArray(BinaryWriter ctx, DateTime?[] obj) { ctx.Stream.WriteByte(BinaryTypeId.ArrayTimestamp); - BinaryUtils.WriteTimestampArray(obj, ctx.Stream, true); + BinaryUtils.WriteTimestampArray(obj, ctx.Stream); } /// diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs index c600bfad011d8..0a64cfe4761ed 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs @@ -388,14 +388,13 @@ public static double[] ReadDoubleArray(IBinaryStream stream) * Write date. * Date. * Stream. - * True if non UTC dates supported */ - public static void WriteTimestamp(DateTime val, IBinaryStream stream, bool allowLocal) + public static void WriteTimestamp(DateTime val, IBinaryStream stream) { long high; int low; - ToJavaDate(val, out high, out low, allowLocal); + ToJavaDate(val, out high, out low); stream.WriteLong(high); stream.WriteInt(low); @@ -439,8 +438,7 @@ public static long DateTimeToJavaTicks(DateTime dateTime) /// /// Values. /// Stream. - /// True if non UTC dates supported - public static void WriteTimestampArray(DateTime?[] vals, IBinaryStream stream, bool allowLocal) + public static void WriteTimestampArray(DateTime?[] vals, IBinaryStream stream) { stream.WriteInt(vals.Length); @@ -450,7 +448,7 @@ public static void WriteTimestampArray(DateTime?[] vals, IBinaryStream stream, b { stream.WriteByte(BinaryTypeId.Timestamp); - WriteTimestamp(val.Value, stream, allowLocal); + WriteTimestamp(val.Value, stream); } else stream.WriteByte(HdrNull); @@ -1613,16 +1611,16 @@ public static void ValidateProtocolVersion(byte version) * Date * High part (milliseconds). * Low part (nanoseconds) - * True if non UTC dates supported */ - private static void ToJavaDate(DateTime date, out long high, out int low, bool allowLocal) + private static void ToJavaDate(DateTime date, out long high, out int low) { - if (date.Kind != DateTimeKind.Utc && !allowLocal) +#if !NETCOREAPP + if (date.Kind != DateTimeKind.Utc) { throw new BinaryObjectException( "DateTime is not UTC. Only UTC DateTime can be used for interop with other platforms."); } - +#endif if (date.Kind != DateTimeKind.Utc) { date = date.ToUniversalTime(); diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs index f826c32dd27db..9025b4df2d51d 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs @@ -657,7 +657,7 @@ public void WriteTimestamp(string fieldName, DateTime? val) else { _stream.WriteByte(BinaryTypeId.Timestamp); - BinaryUtils.WriteTimestamp(val.Value, _stream, _marsh.ForceTimestamp); + BinaryUtils.WriteTimestamp(val.Value, _stream); } } @@ -672,7 +672,7 @@ public void WriteTimestamp(DateTime? val) else { _stream.WriteByte(BinaryTypeId.Timestamp); - BinaryUtils.WriteTimestamp(val.Value, _stream, _marsh.ForceTimestamp); + BinaryUtils.WriteTimestamp(val.Value, _stream); } } @@ -690,7 +690,7 @@ public void WriteTimestampArray(string fieldName, DateTime?[] val) else { _stream.WriteByte(BinaryTypeId.ArrayTimestamp); - BinaryUtils.WriteTimestampArray(val, _stream, _marsh.ForceTimestamp); + BinaryUtils.WriteTimestampArray(val, _stream); } } @@ -705,7 +705,7 @@ public void WriteTimestampArray(DateTime?[] val) else { _stream.WriteByte(BinaryTypeId.ArrayTimestamp); - BinaryUtils.WriteTimestampArray(val, _stream, _marsh.ForceTimestamp); + BinaryUtils.WriteTimestampArray(val, _stream); } } From 2e5edb30b5b8e04d5826edb6360a05cf270125d2 Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Sun, 20 Dec 2020 13:09:56 +0300 Subject: [PATCH 25/37] IGNITE-12824: Allows usages of Local dates but only for .NetCore applications. --- .../Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs | 2 ++ .../dotnet/Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs | 2 ++ .../Cache/Query/Linq/CacheLinqTest.DateTime.cs | 2 ++ 3 files changed, 6 insertions(+) diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs index e971eeac04b3c..25d309d778973 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs @@ -143,6 +143,7 @@ private static void AssertTimestampField(Action setValue, var obj = new T(); +#if !NETCOREAPP setValue(obj, DateTime.Now); var ex = Assert.Throws(() => binary.ToBinary(obj), @@ -150,6 +151,7 @@ private static void AssertTimestampField(Action setValue, Assert.AreEqual("DateTime is not UTC. Only UTC DateTime can be used for interop with other platforms.", ex.Message); +#endif // UTC DateTime works. setValue(obj, DateTime.UtcNow); diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs index bf3b4747502f4..789ad54b370d8 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs @@ -670,10 +670,12 @@ public void TestDateTime() var timeUtc = DateTime.UtcNow; Assert.AreEqual(_marsh.Unmarshal(_marsh.Marshal(timeUtc)), timeUtc); +#if !NETCOREAPP // Check exception with non-UTC date var stream = new BinaryHeapStream(128); var writer = _marsh.StartMarshal(stream); Assert.Throws(() => writer.WriteTimestamp(DateTime.Now)); +#endif } /** diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Linq/CacheLinqTest.DateTime.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Linq/CacheLinqTest.DateTime.cs index b869dc4c2cf36..3d32891e162ae 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Linq/CacheLinqTest.DateTime.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Linq/CacheLinqTest.DateTime.cs @@ -46,12 +46,14 @@ public void TestDateTime() var roles = GetRoleCache().AsCacheQueryable(); var persons = GetPersonCache().AsCacheQueryable(); +#if !NETCOREAPP // Invalid dateTime // ReSharper disable once ReturnValueOfPureMethodIsNotUsed var ex = Assert.Throws(() => roles.Where(x => x.Value.Date > DateTime.Now).ToArray()); Assert.AreEqual("DateTime is not UTC. Only UTC DateTime can be used for interop with other platforms.", ex.Message); +#endif // Test retrieval var dates = roles.OrderBy(x => x.Value.Date).Select(x => x.Value.Date); From 078b658c8fac220512ca60d05ed033759f696db1 Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Mon, 21 Dec 2020 20:29:26 +0300 Subject: [PATCH 26/37] IGNITE-12824: IDateTimeConverter implemented --- .../Services/ServicesTest.cs | 23 ++++++++++++++ .../Binary/BinaryConfiguration.cs | 6 ++++ .../Binary/IDateTimeConverter.cs | 22 ++++++++++++++ .../Impl/Binary/BinaryReader.cs | 4 +-- .../Impl/Binary/BinarySystemHandlers.cs | 17 +++++++---- .../Impl/Binary/BinaryUtils.cs | 30 ++++++++++--------- .../Impl/Binary/BinaryWriter.cs | 4 +-- .../Impl/Binary/Marshaller.cs | 8 +++++ 8 files changed, 90 insertions(+), 24 deletions(-) create mode 100644 modules/platforms/dotnet/Apache.Ignite.Core/Binary/IDateTimeConverter.cs diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs index f7c13c0069f3a..1678793fd609f 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs @@ -27,6 +27,7 @@ namespace Apache.Ignite.Core.Tests.Services using Apache.Ignite.Core.Cluster; using Apache.Ignite.Core.Common; using Apache.Ignite.Core.Impl; + using Apache.Ignite.Core.Impl.Binary; using Apache.Ignite.Core.Resource; using Apache.Ignite.Core.Services; using NUnit.Framework; @@ -1179,6 +1180,9 @@ private IgniteConfiguration GetConfiguration(string springConfigUrl) { NameMapper = BinaryBasicNameMapper.SimpleNameInstance, ForceTimestamp = true +#if NETCOREAPP + , DateTimeConverter = new DateTimeConverter() +#endif } }; } @@ -1561,5 +1565,24 @@ public class PlatformComputeBinarizable2 /** */ public int Field { get; set; } } + +#if NETCOREAPP + class DateTimeConverter : IDateTimeConverter + { + public void ToJavaTicks(DateTime date, out long high, out int low) + { + if (date.Kind == DateTimeKind.Local) + date = date.ToUniversalTime(); + + BinaryUtils.ToJavaDate(date, out high, out low); + } + + public DateTime FromJavaTicks(long high, int low) + { + return new DateTime(BinaryUtils.JavaDateTicks + high * TimeSpan.TicksPerMillisecond + low / 100, DateTimeKind.Utc); + } + } +#endif } + } diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Binary/BinaryConfiguration.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Binary/BinaryConfiguration.cs index 2a2bb9579512e..cfefba45f2ebd 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Binary/BinaryConfiguration.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Binary/BinaryConfiguration.cs @@ -79,6 +79,7 @@ internal void CopyLocalProperties(BinaryConfiguration cfg) NameMapper = cfg.NameMapper; KeepDeserialized = cfg.KeepDeserialized; ForceTimestamp = cfg.ForceTimestamp; + DateTimeConverter = cfg.DateTimeConverter; if (cfg.Serializer != null) { @@ -136,6 +137,11 @@ public BinaryConfiguration(params Type[] binaryTypes) /// public IBinarySerializer Serializer { get; set; } + /// + /// Default date time converter. + /// + public IDateTimeConverter DateTimeConverter { get; set; } + /// /// Default keep deserialized flag. /// diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Binary/IDateTimeConverter.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Binary/IDateTimeConverter.cs new file mode 100644 index 0000000000000..0e52ed7103be6 --- /dev/null +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Binary/IDateTimeConverter.cs @@ -0,0 +1,22 @@ +namespace Apache.Ignite.Core.Binary +{ + using System; + + public interface IDateTimeConverter + { + /** + * Convert date to Java ticks. + * Date + * High part (milliseconds). + * Low part (nanoseconds) + */ + void ToJavaTicks(DateTime date, out long high, out int low); + + /** + * Convert date from Java ticks. + * High part (milliseconds). + * Low part (nanoseconds) + */ + DateTime FromJavaTicks(long high, int low); + } +} \ No newline at end of file diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReader.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReader.cs index 9153046ece52b..549a57b855ddc 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReader.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReader.cs @@ -315,13 +315,13 @@ public double[] ReadDoubleArray() /** */ public DateTime? ReadTimestamp(string fieldName) { - return ReadField(fieldName, BinaryUtils.ReadTimestamp, BinaryTypeId.Timestamp); + return ReadField(fieldName, stream => BinaryUtils.ReadTimestamp(stream, _marsh.DateTimeConverter), BinaryTypeId.Timestamp); } /** */ public DateTime? ReadTimestamp() { - return Read(BinaryUtils.ReadTimestamp, BinaryTypeId.Timestamp); + return Read(stream => BinaryUtils.ReadTimestamp(stream, _marsh.DateTimeConverter), BinaryTypeId.Timestamp); } /** */ diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinarySystemHandlers.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinarySystemHandlers.cs index 3ffb1f978b680..09f4435f3a240 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinarySystemHandlers.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinarySystemHandlers.cs @@ -54,9 +54,6 @@ static BinarySystemHandlers() ReadHandlers[BinaryTypeId.Double] = new BinarySystemReader(s => s.ReadDouble()); ReadHandlers[BinaryTypeId.Decimal] = new BinarySystemReader(BinaryUtils.ReadDecimal); - // 2. Date. - ReadHandlers[BinaryTypeId.Timestamp] = new BinarySystemReader(BinaryUtils.ReadTimestamp); - // 3. String. ReadHandlers[BinaryTypeId.String] = new BinarySystemReader(BinaryUtils.ReadString); @@ -258,8 +255,16 @@ public static bool TryReadSystemType(byte typeId, BinaryReader ctx, out T res if (handler == null) { - res = default(T); - return false; + if (typeId == BinaryTypeId.Timestamp) + { + // Date. + handler = new BinarySystemReader(stream => BinaryUtils.ReadTimestamp(stream, ctx.Marshaller.DateTimeConverter)); + } + else + { + res = default(T); + return false; + } } res = handler.Read(ctx); @@ -311,7 +316,7 @@ private static void WriteTimestamp(BinaryWriter ctx, DateTime obj) { ctx.Stream.WriteByte(BinaryTypeId.Timestamp); - BinaryUtils.WriteTimestamp(obj, ctx.Stream); + BinaryUtils.WriteTimestamp(obj, ctx.Stream, ctx.Marshaller.DateTimeConverter); } /// diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs index 0a64cfe4761ed..36aee26dd997e 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs @@ -69,7 +69,7 @@ internal static class BinaryUtils public const int ObjTypeId = -1; /** Ticks for Java epoch. */ - private static readonly long JavaDateTicks = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).Ticks; + public static readonly long JavaDateTicks = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).Ticks; /** Binding flags for static search. */ private const BindingFlags BindFlagsStatic = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; @@ -388,13 +388,17 @@ public static double[] ReadDoubleArray(IBinaryStream stream) * Write date. * Date. * Stream. + * DateTime Converter. */ - public static void WriteTimestamp(DateTime val, IBinaryStream stream) + public static void WriteTimestamp(DateTime val, IBinaryStream stream, IDateTimeConverter converter) { long high; int low; - ToJavaDate(val, out high, out low); + if (converter != null) + converter.ToJavaTicks(val, out high, out low); + else + ToJavaDate(val, out high, out low); stream.WriteLong(high); stream.WriteInt(low); @@ -403,14 +407,18 @@ public static void WriteTimestamp(DateTime val, IBinaryStream stream) /** * Read date. * Stream. + * DateTime Converter. * Date */ - public static DateTime? ReadTimestamp(IBinaryStream stream) + public static DateTime? ReadTimestamp(IBinaryStream stream, IDateTimeConverter converter) { long high = stream.ReadLong(); int low = stream.ReadInt(); - return new DateTime(JavaDateTicks + high * TimeSpan.TicksPerMillisecond + low / 100, DateTimeKind.Utc); + if (converter != null) + return converter.FromJavaTicks(high, low); + else + return new DateTime(JavaDateTicks + high * TimeSpan.TicksPerMillisecond + low / 100, DateTimeKind.Utc); } /// @@ -448,7 +456,7 @@ public static void WriteTimestampArray(DateTime?[] vals, IBinaryStream stream) { stream.WriteByte(BinaryTypeId.Timestamp); - WriteTimestamp(val.Value, stream); + WriteTimestamp(val.Value, stream, Marsh.DateTimeConverter); } else stream.WriteByte(HdrNull); @@ -1173,7 +1181,7 @@ public static T[] ReadArray(BinaryReader ctx, bool typed) DateTime?[] vals = new DateTime?[len]; for (int i = 0; i < len; i++) - vals[i] = stream.ReadByte() == HdrNull ? null : ReadTimestamp(stream); + vals[i] = stream.ReadByte() == HdrNull ? null : ReadTimestamp(stream, Marshaller.DateTimeConverter); return vals; } @@ -1612,19 +1620,13 @@ public static void ValidateProtocolVersion(byte version) * High part (milliseconds). * Low part (nanoseconds) */ - private static void ToJavaDate(DateTime date, out long high, out int low) + public static void ToJavaDate(DateTime date, out long high, out int low) { -#if !NETCOREAPP if (date.Kind != DateTimeKind.Utc) { throw new BinaryObjectException( "DateTime is not UTC. Only UTC DateTime can be used for interop with other platforms."); } -#endif - if (date.Kind != DateTimeKind.Utc) - { - date = date.ToUniversalTime(); - } long diff = date.Ticks - JavaDateTicks; diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs index 9025b4df2d51d..989a73f0f212c 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs @@ -657,7 +657,7 @@ public void WriteTimestamp(string fieldName, DateTime? val) else { _stream.WriteByte(BinaryTypeId.Timestamp); - BinaryUtils.WriteTimestamp(val.Value, _stream); + BinaryUtils.WriteTimestamp(val.Value, _stream, _marsh.DateTimeConverter); } } @@ -672,7 +672,7 @@ public void WriteTimestamp(DateTime? val) else { _stream.WriteByte(BinaryTypeId.Timestamp); - BinaryUtils.WriteTimestamp(val.Value, _stream); + BinaryUtils.WriteTimestamp(val.Value, _stream, _marsh.DateTimeConverter); } } diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs index cc9aeff992d2f..df1d7a071955b 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs @@ -144,6 +144,14 @@ public bool ForceTimestamp get { return _cfg.ForceTimestamp; } } + /// + /// Gets date time converter. + /// + public IDateTimeConverter DateTimeConverter + { + get { return _cfg.DateTimeConverter; } + } + /// /// Marshal object. /// From 969e5c517ef6dff61d7919bb559fe84ab3f25ff5 Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Mon, 21 Dec 2020 20:35:42 +0300 Subject: [PATCH 27/37] IGNITE-12824: IDateTimeConverter implemented --- .../Binary/BinaryDateTimeTest.cs | 2 -- .../Binary/BinarySelfTest.cs | 2 -- .../Query/Linq/CacheLinqTest.DateTime.cs | 2 -- .../Services/ServicesTest.cs | 1 - .../Binary/IDateTimeConverter.cs | 21 +++++++++---------- 5 files changed, 10 insertions(+), 18 deletions(-) diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs index 25d309d778973..e971eeac04b3c 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs @@ -143,7 +143,6 @@ private static void AssertTimestampField(Action setValue, var obj = new T(); -#if !NETCOREAPP setValue(obj, DateTime.Now); var ex = Assert.Throws(() => binary.ToBinary(obj), @@ -151,7 +150,6 @@ private static void AssertTimestampField(Action setValue, Assert.AreEqual("DateTime is not UTC. Only UTC DateTime can be used for interop with other platforms.", ex.Message); -#endif // UTC DateTime works. setValue(obj, DateTime.UtcNow); diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs index 789ad54b370d8..bf3b4747502f4 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs @@ -670,12 +670,10 @@ public void TestDateTime() var timeUtc = DateTime.UtcNow; Assert.AreEqual(_marsh.Unmarshal(_marsh.Marshal(timeUtc)), timeUtc); -#if !NETCOREAPP // Check exception with non-UTC date var stream = new BinaryHeapStream(128); var writer = _marsh.StartMarshal(stream); Assert.Throws(() => writer.WriteTimestamp(DateTime.Now)); -#endif } /** diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Linq/CacheLinqTest.DateTime.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Linq/CacheLinqTest.DateTime.cs index 3d32891e162ae..b869dc4c2cf36 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Linq/CacheLinqTest.DateTime.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Linq/CacheLinqTest.DateTime.cs @@ -46,14 +46,12 @@ public void TestDateTime() var roles = GetRoleCache().AsCacheQueryable(); var persons = GetPersonCache().AsCacheQueryable(); -#if !NETCOREAPP // Invalid dateTime // ReSharper disable once ReturnValueOfPureMethodIsNotUsed var ex = Assert.Throws(() => roles.Where(x => x.Value.Date > DateTime.Now).ToArray()); Assert.AreEqual("DateTime is not UTC. Only UTC DateTime can be used for interop with other platforms.", ex.Message); -#endif // Test retrieval var dates = roles.OrderBy(x => x.Value.Date).Select(x => x.Value.Date); diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs index 1678793fd609f..73542b503bcbe 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs @@ -1584,5 +1584,4 @@ public DateTime FromJavaTicks(long high, int low) } #endif } - } diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Binary/IDateTimeConverter.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Binary/IDateTimeConverter.cs index 0e52ed7103be6..d59baa1c8e8d2 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Binary/IDateTimeConverter.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Binary/IDateTimeConverter.cs @@ -2,21 +2,20 @@ namespace Apache.Ignite.Core.Binary { using System; + /// + /// Converter for DateTime objects. + /// public interface IDateTimeConverter { - /** - * Convert date to Java ticks. - * Date - * High part (milliseconds). - * Low part (nanoseconds) - */ + /// Convert date to Java ticks. + /// Date + /// High part (milliseconds). + /// Low part (nanoseconds) void ToJavaTicks(DateTime date, out long high, out int low); - /** - * Convert date from Java ticks. - * High part (milliseconds). - * Low part (nanoseconds) - */ + /// Convert date from Java ticks. + /// High part (milliseconds). + /// Low part (nanoseconds) DateTime FromJavaTicks(long high, int low); } } \ No newline at end of file From 14b44568f6bd87e01a81fd87320e4ccb6fb40773 Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Mon, 21 Dec 2020 20:36:47 +0300 Subject: [PATCH 28/37] IGNITE-12824: IDateTimeConverter implemented --- .../dotnet/Apache.Ignite.Core/Binary/IDateTimeConverter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Binary/IDateTimeConverter.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Binary/IDateTimeConverter.cs index d59baa1c8e8d2..29b7922c2bb23 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Binary/IDateTimeConverter.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Binary/IDateTimeConverter.cs @@ -18,4 +18,4 @@ public interface IDateTimeConverter /// Low part (nanoseconds) DateTime FromJavaTicks(long high, int low); } -} \ No newline at end of file +} From a93dc9fc934889630bbfd881c10a7bb8af3bd883 Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Tue, 22 Dec 2020 09:53:04 +0300 Subject: [PATCH 29/37] IGNITE-12824: License fix. --- .../Binary/IDateTimeConverter.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Binary/IDateTimeConverter.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Binary/IDateTimeConverter.cs index 29b7922c2bb23..50f3a3aee95e6 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Binary/IDateTimeConverter.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Binary/IDateTimeConverter.cs @@ -1,3 +1,20 @@ +/* + * 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. + */ + namespace Apache.Ignite.Core.Binary { using System; From 8a481daff50310133edfe82384404872294c35a4 Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Tue, 22 Dec 2020 14:05:31 +0300 Subject: [PATCH 30/37] IGNITE-12824: Code review fixes. --- .../Services/ServicesTest.cs | 4 ++-- .../Apache.Ignite.Core/Apache.Ignite.Core.csproj | 1 + .../Apache.Ignite.Core/Binary/BinaryConfiguration.cs | 12 ++++++++---- ...{IDateTimeConverter.cs => ITimestampConverter.cs} | 8 ++++---- .../IgniteClientConfigurationSection.xsd | 12 ++++++++++++ .../IgniteConfigurationSection.xsd | 12 ++++++++++++ .../Apache.Ignite.Core/Impl/Binary/BinaryReader.cs | 4 ++-- .../Impl/Binary/BinarySystemHandlers.cs | 5 +++-- .../Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs | 8 ++++---- .../Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs | 4 ++-- .../Apache.Ignite.Core/Impl/Binary/Marshaller.cs | 4 ++-- 11 files changed, 52 insertions(+), 22 deletions(-) rename modules/platforms/dotnet/Apache.Ignite.Core/Binary/{IDateTimeConverter.cs => ITimestampConverter.cs} (84%) diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs index 73542b503bcbe..4d6069faea477 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs @@ -1181,7 +1181,7 @@ private IgniteConfiguration GetConfiguration(string springConfigUrl) NameMapper = BinaryBasicNameMapper.SimpleNameInstance, ForceTimestamp = true #if NETCOREAPP - , DateTimeConverter = new DateTimeConverter() + , TimestampConverter = new TimestampConverter() #endif } }; @@ -1567,7 +1567,7 @@ public class PlatformComputeBinarizable2 } #if NETCOREAPP - class DateTimeConverter : IDateTimeConverter + class TimestampConverter : ITimestampConverter { public void ToJavaTicks(DateTime date, out long high, out int low) { diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj b/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj index c315f08166b5b..55488ceb6a663 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj @@ -52,6 +52,7 @@ + diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Binary/BinaryConfiguration.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Binary/BinaryConfiguration.cs index cfefba45f2ebd..b25a9f58420aa 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Binary/BinaryConfiguration.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Binary/BinaryConfiguration.cs @@ -79,7 +79,7 @@ internal void CopyLocalProperties(BinaryConfiguration cfg) NameMapper = cfg.NameMapper; KeepDeserialized = cfg.KeepDeserialized; ForceTimestamp = cfg.ForceTimestamp; - DateTimeConverter = cfg.DateTimeConverter; + TimestampConverter = cfg.TimestampConverter; if (cfg.Serializer != null) { @@ -138,9 +138,13 @@ public BinaryConfiguration(params Type[] binaryTypes) public IBinarySerializer Serializer { get; set; } /// - /// Default date time converter. + /// Gets or sets a converter between and Java Timestamp. + /// Called from , , + /// , . + /// + /// See also . /// - public IDateTimeConverter DateTimeConverter { get; set; } + public ITimestampConverter TimestampConverter { get; set; } /// /// Default keep deserialized flag. @@ -170,7 +174,7 @@ public bool CompactFooter /// should be written as a Timestamp. /// /// Timestamp format is required for values used in SQL and for interoperation with other platforms. - /// Only UTC values are supported in Timestamp format. Other values will cause an exception on write. + /// Only UTC values are supported in Timestamp format. Other values will cause an exception on write, unless is provided. /// /// Normally Ignite serializer uses for DateTime fields, /// keys and values. diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Binary/IDateTimeConverter.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Binary/ITimestampConverter.cs similarity index 84% rename from modules/platforms/dotnet/Apache.Ignite.Core/Binary/IDateTimeConverter.cs rename to modules/platforms/dotnet/Apache.Ignite.Core/Binary/ITimestampConverter.cs index 50f3a3aee95e6..c7604793b9360 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Binary/IDateTimeConverter.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Binary/ITimestampConverter.cs @@ -20,17 +20,17 @@ namespace Apache.Ignite.Core.Binary using System; /// - /// Converter for DateTime objects. + /// Converts values to Java Timestamp and back. /// - public interface IDateTimeConverter + public interface ITimestampConverter { - /// Convert date to Java ticks. + /// Converts date to Java ticks. /// Date /// High part (milliseconds). /// Low part (nanoseconds) void ToJavaTicks(DateTime date, out long high, out int low); - /// Convert date from Java ticks. + /// Converts date from Java ticks. /// High part (milliseconds). /// Low part (nanoseconds) DateTime FromJavaTicks(long high, int low); diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/IgniteClientConfigurationSection.xsd b/modules/platforms/dotnet/Apache.Ignite.Core/IgniteClientConfigurationSection.xsd index 42aa56b691522..b61031818a2f5 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/IgniteClientConfigurationSection.xsd +++ b/modules/platforms/dotnet/Apache.Ignite.Core/IgniteClientConfigurationSection.xsd @@ -174,6 +174,18 @@ + + + Default date time converter. + + + + + Assembly-qualified type name. + + + + diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.xsd b/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.xsd index 4bb0fef2b491c..a840d99001c13 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.xsd +++ b/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.xsd @@ -263,6 +263,18 @@ + + + Default date time converter. + + + + + Assembly-qualified type name. + + + + diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReader.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReader.cs index 549a57b855ddc..236537b119288 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReader.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReader.cs @@ -315,13 +315,13 @@ public double[] ReadDoubleArray() /** */ public DateTime? ReadTimestamp(string fieldName) { - return ReadField(fieldName, stream => BinaryUtils.ReadTimestamp(stream, _marsh.DateTimeConverter), BinaryTypeId.Timestamp); + return ReadField(fieldName, stream => BinaryUtils.ReadTimestamp(stream, _marsh.TimestampConverter), BinaryTypeId.Timestamp); } /** */ public DateTime? ReadTimestamp() { - return Read(stream => BinaryUtils.ReadTimestamp(stream, _marsh.DateTimeConverter), BinaryTypeId.Timestamp); + return Read(stream => BinaryUtils.ReadTimestamp(stream, _marsh.TimestampConverter), BinaryTypeId.Timestamp); } /** */ diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinarySystemHandlers.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinarySystemHandlers.cs index 09f4435f3a240..ac36361184728 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinarySystemHandlers.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinarySystemHandlers.cs @@ -258,7 +258,8 @@ public static bool TryReadSystemType(byte typeId, BinaryReader ctx, out T res if (typeId == BinaryTypeId.Timestamp) { // Date. - handler = new BinarySystemReader(stream => BinaryUtils.ReadTimestamp(stream, ctx.Marshaller.DateTimeConverter)); + res = TypeCaster.Cast(BinaryUtils.ReadTimestamp(ctx.Stream, ctx.Marshaller.TimestampConverter)); + return true; } else { @@ -316,7 +317,7 @@ private static void WriteTimestamp(BinaryWriter ctx, DateTime obj) { ctx.Stream.WriteByte(BinaryTypeId.Timestamp); - BinaryUtils.WriteTimestamp(obj, ctx.Stream, ctx.Marshaller.DateTimeConverter); + BinaryUtils.WriteTimestamp(obj, ctx.Stream, ctx.Marshaller.TimestampConverter); } /// diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs index 36aee26dd997e..59004572c2274 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs @@ -390,7 +390,7 @@ public static double[] ReadDoubleArray(IBinaryStream stream) * Stream. * DateTime Converter. */ - public static void WriteTimestamp(DateTime val, IBinaryStream stream, IDateTimeConverter converter) + public static void WriteTimestamp(DateTime val, IBinaryStream stream, ITimestampConverter converter) { long high; int low; @@ -410,7 +410,7 @@ public static void WriteTimestamp(DateTime val, IBinaryStream stream, IDateTimeC * DateTime Converter. * Date */ - public static DateTime? ReadTimestamp(IBinaryStream stream, IDateTimeConverter converter) + public static DateTime? ReadTimestamp(IBinaryStream stream, ITimestampConverter converter) { long high = stream.ReadLong(); int low = stream.ReadInt(); @@ -456,7 +456,7 @@ public static void WriteTimestampArray(DateTime?[] vals, IBinaryStream stream) { stream.WriteByte(BinaryTypeId.Timestamp); - WriteTimestamp(val.Value, stream, Marsh.DateTimeConverter); + WriteTimestamp(val.Value, stream, Marsh.TimestampConverter); } else stream.WriteByte(HdrNull); @@ -1181,7 +1181,7 @@ public static T[] ReadArray(BinaryReader ctx, bool typed) DateTime?[] vals = new DateTime?[len]; for (int i = 0; i < len; i++) - vals[i] = stream.ReadByte() == HdrNull ? null : ReadTimestamp(stream, Marshaller.DateTimeConverter); + vals[i] = stream.ReadByte() == HdrNull ? null : ReadTimestamp(stream, Marshaller.TimestampConverter); return vals; } diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs index 989a73f0f212c..1b200c3ea7d63 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs @@ -657,7 +657,7 @@ public void WriteTimestamp(string fieldName, DateTime? val) else { _stream.WriteByte(BinaryTypeId.Timestamp); - BinaryUtils.WriteTimestamp(val.Value, _stream, _marsh.DateTimeConverter); + BinaryUtils.WriteTimestamp(val.Value, _stream, _marsh.TimestampConverter); } } @@ -672,7 +672,7 @@ public void WriteTimestamp(DateTime? val) else { _stream.WriteByte(BinaryTypeId.Timestamp); - BinaryUtils.WriteTimestamp(val.Value, _stream, _marsh.DateTimeConverter); + BinaryUtils.WriteTimestamp(val.Value, _stream, _marsh.TimestampConverter); } } diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs index df1d7a071955b..76b9cbcbaf2a9 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs @@ -147,9 +147,9 @@ public bool ForceTimestamp /// /// Gets date time converter. /// - public IDateTimeConverter DateTimeConverter + public ITimestampConverter TimestampConverter { - get { return _cfg.DateTimeConverter; } + get { return _cfg.TimestampConverter; } } /// From e63549543e1e55b59b437770654039a940d0715c Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Tue, 22 Dec 2020 15:24:07 +0300 Subject: [PATCH 31/37] IGNITE-12824: Code review fixes. --- .../Binary/BinaryDateTimeTest.cs | 54 ++++++++++++++++++- .../Services/ServicesTest.cs | 5 ++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs index e971eeac04b3c..ed938a5c10c39 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs @@ -21,6 +21,7 @@ namespace Apache.Ignite.Core.Tests.Binary using System.Linq; using Apache.Ignite.Core.Binary; using Apache.Ignite.Core.Cache.Configuration; + using Apache.Ignite.Core.Impl.Binary; using NUnit.Framework; /// @@ -80,7 +81,7 @@ public void TestSerializerForceTimestamp() .Select(x => x.Serializer) .OfType() .Single(); - + Assert.IsTrue(ser.ForceTimestamp); AssertTimestampField((o, d) => o.Value = d, o => o.Value, "Value"); @@ -110,6 +111,34 @@ public void TestClassAttributes() AssertTimestampField((o, d) => o.Value = d, o => o.Value, "Value"); } +#if NETCOREAPP + /// + /// Tests custom timestamp converter. + /// + [Test] + public void TestCustomTimestampConverter() + { + var cfg = new IgniteConfiguration(TestUtils.GetTestConfiguration(name: "ignite-1")) + { + BinaryConfiguration = new BinaryConfiguration() + { + ForceTimestamp = true, + TimestampConverter = new TimestampConverter() + } + }; + var ignite = Ignition.Start(cfg); + var binary = ignite.GetBinary(); + + // Check config. + Assert.NotNull(ignite.GetConfiguration().BinaryConfiguration.TimestampConverter); + + AssertTimestampField((o, d) => o.Value = d, o => o.Value, "Value"); + + var ex = Assert.Throws(() => binary.ToBinary(new DateTime(1997, 8, 29)), + "Converter Error!"); + } +#endif + /// /// Asserts that specified field is serialized as DateTime object. /// @@ -201,4 +230,27 @@ private class DateTimeClassAttribute2 public DateTime Value; } } + +#if NETCOREAPP + /// + /// Adds support of the local dates to the Ignite timestamp serialization. + /// + class TimestampConverter : ITimestampConverter + { + /** */ + public void ToJavaTicks(DateTime date, out long high, out int low) + { + if (date.Year == 1997 && date.Month == 8 && date.Day == 29) + throw new BinaryObjectException("Converter Error!"); + + BinaryUtils.ToJavaDate(date, out high, out low); + } + + /** */ + public DateTime FromJavaTicks(long high, int low) + { + return new DateTime(BinaryUtils.JavaDateTicks + high * TimeSpan.TicksPerMillisecond + low / 100, DateTimeKind.Utc); + } + } +#endif } diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs index 4d6069faea477..682f651c82914 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs @@ -1567,8 +1567,12 @@ public class PlatformComputeBinarizable2 } #if NETCOREAPP + /// + /// Adds support of the local dates to the Ignite timestamp serialization. + /// class TimestampConverter : ITimestampConverter { + /** */ public void ToJavaTicks(DateTime date, out long high, out int low) { if (date.Kind == DateTimeKind.Local) @@ -1577,6 +1581,7 @@ public void ToJavaTicks(DateTime date, out long high, out int low) BinaryUtils.ToJavaDate(date, out high, out low); } + /** */ public DateTime FromJavaTicks(long high, int low) { return new DateTime(BinaryUtils.JavaDateTicks + high * TimeSpan.TicksPerMillisecond + low / 100, DateTimeKind.Utc); From c66a2f1968633600ff79627bcb9158dfa5f2d8f6 Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Wed, 23 Dec 2020 11:37:08 +0300 Subject: [PATCH 32/37] IGNITE-12824: Code review fixes. --- .../Binary/BinaryDateTimeTest.cs | 31 ++++++++++++++----- .../Impl/Binary/BinaryReader.cs | 4 +-- .../Impl/Binary/BinarySystemHandlers.cs | 17 +++++----- .../Impl/Binary/BinaryUtils.cs | 14 +++++---- .../Impl/Binary/BinaryWriter.cs | 4 +-- 5 files changed, 44 insertions(+), 26 deletions(-) diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs index ed938a5c10c39..7f3eba42fd056 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs @@ -111,7 +111,6 @@ public void TestClassAttributes() AssertTimestampField((o, d) => o.Value = d, o => o.Value, "Value"); } -#if NETCOREAPP /// /// Tests custom timestamp converter. /// @@ -134,10 +133,22 @@ public void TestCustomTimestampConverter() AssertTimestampField((o, d) => o.Value = d, o => o.Value, "Value"); - var ex = Assert.Throws(() => binary.ToBinary(new DateTime(1997, 8, 29)), - "Converter Error!"); + var dt1 = new DateTime(1997, 8, 29, 0, 0, 0, DateTimeKind.Utc); + + var ex = Assert.Throws(() => binary.ToBinary(dt1)); + Assert.AreEqual("ToJavaTicks Error!", ex.Message); + + ex = Assert.Throws(() => binary.ToBinary(new DateTime?[] {dt1})); + Assert.AreEqual("ToJavaTicks Error!", ex.Message); + + var dt2 = new DateTime(1997, 8, 4, 0, 0, 0, DateTimeKind.Utc); + + ex = Assert.Throws(() => binary.ToBinary(dt2)); + Assert.AreEqual("FromJavaTicks Error!", ex.Message); + + ex = Assert.Throws(() => binary.ToBinary(new DateTime?[] {dt2})); + Assert.AreEqual("FromJavaTicks Error!", ex.Message); } -#endif /// /// Asserts that specified field is serialized as DateTime object. @@ -231,7 +242,6 @@ private class DateTimeClassAttribute2 } } -#if NETCOREAPP /// /// Adds support of the local dates to the Ignite timestamp serialization. /// @@ -241,7 +251,7 @@ class TimestampConverter : ITimestampConverter public void ToJavaTicks(DateTime date, out long high, out int low) { if (date.Year == 1997 && date.Month == 8 && date.Day == 29) - throw new BinaryObjectException("Converter Error!"); + throw new BinaryObjectException("ToJavaTicks Error!"); BinaryUtils.ToJavaDate(date, out high, out low); } @@ -249,8 +259,13 @@ public void ToJavaTicks(DateTime date, out long high, out int low) /** */ public DateTime FromJavaTicks(long high, int low) { - return new DateTime(BinaryUtils.JavaDateTicks + high * TimeSpan.TicksPerMillisecond + low / 100, DateTimeKind.Utc); + var date = new DateTime(BinaryUtils.JavaDateTicks + high * TimeSpan.TicksPerMillisecond + low / 100, + DateTimeKind.Utc); + + if (date.Year == 1997 && date.Month == 8 && date.Day == 4) + throw new BinaryObjectException("FromJavaTicks Error!"); + + return date; } } -#endif } diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReader.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReader.cs index 236537b119288..c1a6fed02ddd2 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReader.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReader.cs @@ -327,13 +327,13 @@ public double[] ReadDoubleArray() /** */ public DateTime?[] ReadTimestampArray(string fieldName) { - return ReadField(fieldName, BinaryUtils.ReadTimestampArray, BinaryTypeId.ArrayTimestamp); + return ReadField(fieldName, stream => BinaryUtils.ReadTimestampArray(stream, _marsh.TimestampConverter), BinaryTypeId.ArrayTimestamp); } /** */ public DateTime?[] ReadTimestampArray() { - return Read(BinaryUtils.ReadTimestampArray, BinaryTypeId.ArrayTimestamp); + return Read(stream => BinaryUtils.ReadTimestampArray(stream, _marsh.TimestampConverter), BinaryTypeId.ArrayTimestamp); } /** */ diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinarySystemHandlers.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinarySystemHandlers.cs index ac36361184728..8fdf3716fe623 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinarySystemHandlers.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinarySystemHandlers.cs @@ -89,10 +89,6 @@ static BinarySystemHandlers() ReadHandlers[BinaryTypeId.ArrayDecimal] = new BinarySystemReader(BinaryUtils.ReadDecimalArray); - // 6. Date array. - ReadHandlers[BinaryTypeId.ArrayTimestamp] = - new BinarySystemReader(BinaryUtils.ReadTimestampArray); - // 7. String array. ReadHandlers[BinaryTypeId.ArrayString] = new BinarySystemTypedArrayReader(); @@ -261,11 +257,16 @@ public static bool TryReadSystemType(byte typeId, BinaryReader ctx, out T res res = TypeCaster.Cast(BinaryUtils.ReadTimestamp(ctx.Stream, ctx.Marshaller.TimestampConverter)); return true; } - else + + if (typeId == BinaryTypeId.ArrayTimestamp) { - res = default(T); - return false; + // Date array. + res = TypeCaster.Cast(BinaryUtils.ReadTimestampArray(ctx.Stream, ctx.Marshaller.TimestampConverter)); + return true; } + + res = default(T); + return false; } res = handler.Read(ctx); @@ -461,7 +462,7 @@ private static void WriteTimestampArray(BinaryWriter ctx, DateTime?[] obj) { ctx.Stream.WriteByte(BinaryTypeId.ArrayTimestamp); - BinaryUtils.WriteTimestampArray(obj, ctx.Stream); + BinaryUtils.WriteTimestampArray(obj, ctx.Stream, ctx.Marshaller.TimestampConverter); } /// diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs index 59004572c2274..82e2284c32867 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs @@ -388,7 +388,7 @@ public static double[] ReadDoubleArray(IBinaryStream stream) * Write date. * Date. * Stream. - * DateTime Converter. + * Timestamp Converter. */ public static void WriteTimestamp(DateTime val, IBinaryStream stream, ITimestampConverter converter) { @@ -407,7 +407,7 @@ public static void WriteTimestamp(DateTime val, IBinaryStream stream, ITimestamp /** * Read date. * Stream. - * DateTime Converter. + * Timestamp Converter. * Date */ public static DateTime? ReadTimestamp(IBinaryStream stream, ITimestampConverter converter) @@ -446,7 +446,8 @@ public static long DateTimeToJavaTicks(DateTime dateTime) /// /// Values. /// Stream. - public static void WriteTimestampArray(DateTime?[] vals, IBinaryStream stream) + /// Timestamp Converter. + public static void WriteTimestampArray(DateTime?[] vals, IBinaryStream stream, ITimestampConverter converter) { stream.WriteInt(vals.Length); @@ -456,7 +457,7 @@ public static void WriteTimestampArray(DateTime?[] vals, IBinaryStream stream) { stream.WriteByte(BinaryTypeId.Timestamp); - WriteTimestamp(val.Value, stream, Marsh.TimestampConverter); + WriteTimestamp(val.Value, stream, converter); } else stream.WriteByte(HdrNull); @@ -1173,15 +1174,16 @@ public static T[] ReadArray(BinaryReader ctx, bool typed) /// Read timestamp array. /// /// Stream. + /// Timestamp Converter. /// Timestamp array. - public static DateTime?[] ReadTimestampArray(IBinaryStream stream) + public static DateTime?[] ReadTimestampArray(IBinaryStream stream, ITimestampConverter converter) { int len = stream.ReadInt(); DateTime?[] vals = new DateTime?[len]; for (int i = 0; i < len; i++) - vals[i] = stream.ReadByte() == HdrNull ? null : ReadTimestamp(stream, Marshaller.TimestampConverter); + vals[i] = stream.ReadByte() == HdrNull ? null : ReadTimestamp(stream, converter); return vals; } diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs index 1b200c3ea7d63..a39bcd7e066f0 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs @@ -690,7 +690,7 @@ public void WriteTimestampArray(string fieldName, DateTime?[] val) else { _stream.WriteByte(BinaryTypeId.ArrayTimestamp); - BinaryUtils.WriteTimestampArray(val, _stream); + BinaryUtils.WriteTimestampArray(val, _stream, _marsh.TimestampConverter); } } @@ -705,7 +705,7 @@ public void WriteTimestampArray(DateTime?[] val) else { _stream.WriteByte(BinaryTypeId.ArrayTimestamp); - BinaryUtils.WriteTimestampArray(val, _stream); + BinaryUtils.WriteTimestampArray(val, _stream, _marsh.TimestampConverter); } } From be9a7dfa476419786db09818806e4d78dcb68baf Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Thu, 24 Dec 2020 00:12:41 +0300 Subject: [PATCH 33/37] IGNITE-12824: Code review fixes. --- .../Binary/BinaryDateTimeTest.cs | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs index 7f3eba42fd056..20364f7425cb0 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs @@ -29,6 +29,12 @@ namespace Apache.Ignite.Core.Tests.Binary /// public class BinaryDateTimeTest { + /** */ + internal const String FromErrMsg = "FromJavaTicks Error!"; + + /** */ + internal const String ToErrMsg = "ToJavaTicks Error!"; + /// /// Sets up the test fixture. /// @@ -131,23 +137,23 @@ public void TestCustomTimestampConverter() // Check config. Assert.NotNull(ignite.GetConfiguration().BinaryConfiguration.TimestampConverter); - AssertTimestampField((o, d) => o.Value = d, o => o.Value, "Value"); + AssertTimestampField((o, d) => o.Value = d, o => o.Value, "Value", ignite); var dt1 = new DateTime(1997, 8, 29, 0, 0, 0, DateTimeKind.Utc); var ex = Assert.Throws(() => binary.ToBinary(dt1)); - Assert.AreEqual("ToJavaTicks Error!", ex.Message); + Assert.AreEqual(ToErrMsg, ex.Message); ex = Assert.Throws(() => binary.ToBinary(new DateTime?[] {dt1})); - Assert.AreEqual("ToJavaTicks Error!", ex.Message); + Assert.AreEqual(ToErrMsg, ex.Message); var dt2 = new DateTime(1997, 8, 4, 0, 0, 0, DateTimeKind.Utc); ex = Assert.Throws(() => binary.ToBinary(dt2)); - Assert.AreEqual("FromJavaTicks Error!", ex.Message); + Assert.AreEqual(FromErrMsg, ex.Message); ex = Assert.Throws(() => binary.ToBinary(new DateTime?[] {dt2})); - Assert.AreEqual("FromJavaTicks Error!", ex.Message); + Assert.AreEqual(FromErrMsg, ex.Message); } /// @@ -176,10 +182,10 @@ private static void AssertDateTimeField(Action setValue, /// Asserts that specified field is serialized as Timestamp. /// private static void AssertTimestampField(Action setValue, - Func getValue, string fieldName) where T : new() + Func getValue, string fieldName, IIgnite ignite = null) where T : new() { // Non-UTC DateTime throws. - var binary = Ignition.GetIgnite().GetBinary(); + var binary = ignite != null ? ignite.GetBinary() : Ignition.GetIgnite().GetBinary(); var obj = new T(); @@ -251,7 +257,7 @@ class TimestampConverter : ITimestampConverter public void ToJavaTicks(DateTime date, out long high, out int low) { if (date.Year == 1997 && date.Month == 8 && date.Day == 29) - throw new BinaryObjectException("ToJavaTicks Error!"); + throw new BinaryObjectException(BinaryDateTimeTest.ToErrMsg); BinaryUtils.ToJavaDate(date, out high, out low); } @@ -263,7 +269,7 @@ public DateTime FromJavaTicks(long high, int low) DateTimeKind.Utc); if (date.Year == 1997 && date.Month == 8 && date.Day == 4) - throw new BinaryObjectException("FromJavaTicks Error!"); + throw new BinaryObjectException(BinaryDateTimeTest.FromErrMsg); return date; } From 05a244b5d872eb9fa7a1138bdc9ac10fb64e6aa8 Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Thu, 24 Dec 2020 11:21:53 +0300 Subject: [PATCH 34/37] IGNITE-12824: Code review fixes. --- .../Binary/BinaryDateTimeTest.cs | 49 ++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs index 20364f7425cb0..4d71818063f81 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs @@ -35,6 +35,10 @@ public class BinaryDateTimeTest /** */ internal const String ToErrMsg = "ToJavaTicks Error!"; + /** */ + private const String NotUtcDate = + "DateTime is not UTC. Only UTC DateTime can be used for interop with other platforms."; + /// /// Sets up the test fixture. /// @@ -131,6 +135,7 @@ public void TestCustomTimestampConverter() TimestampConverter = new TimestampConverter() } }; + var ignite = Ignition.Start(cfg); var binary = ignite.GetBinary(); @@ -154,6 +159,47 @@ public void TestCustomTimestampConverter() ex = Assert.Throws(() => binary.ToBinary(new DateTime?[] {dt2})); Assert.AreEqual(FromErrMsg, ex.Message); + + var datesCache = ignite.CreateCache("dates"); + + var check = new Action((date1, date2, errMsg) => + { + ex = Assert.Throws(() => datesCache.Put(date1, date2), "Timestamp fields should throw an error on non-UTC values"); + + Assert.AreEqual(errMsg, ex.Message); + }); + + check.Invoke(DateTime.Now, DateTime.UtcNow, NotUtcDate); + check.Invoke(DateTime.UtcNow, DateTime.Now, NotUtcDate); + check.Invoke(dt1, DateTime.UtcNow, ToErrMsg); + check.Invoke(DateTime.UtcNow, dt1, ToErrMsg); + + var now = DateTime.UtcNow; + + datesCache.Put(now, dt2); + ex = Assert.Throws(() => datesCache.Get(now), "Timestamp fields should throw an error on non-UTC values"); + Assert.AreEqual(FromErrMsg, ex.Message); + + var datesObjCache = ignite.CreateCache("datesObj"); + + check = (date1, date2, errMsg) => + { + ex = Assert.Throws(() => datesObjCache.Put(new DateTimeObj {Value = date1}, new DateTimeObj {Value = date2}), + "Timestamp fields should throw an error on non-UTC values"); + + Assert.AreEqual(errMsg, ex.Message); + }; + + check.Invoke(DateTime.Now, DateTime.UtcNow, NotUtcDate); + check.Invoke(DateTime.UtcNow, DateTime.Now, NotUtcDate); + check.Invoke(dt1, DateTime.UtcNow, ToErrMsg); + check.Invoke(DateTime.UtcNow, dt1, ToErrMsg); + + var nowObj = new DateTimeObj {Value = now}; + + datesObjCache.Put(nowObj, new DateTimeObj {Value = dt2}); + ex = Assert.Throws(() => datesObjCache.Get(nowObj), "Timestamp fields should throw an error on non-UTC values"); + Assert.AreEqual(FromErrMsg, ex.Message); } /// @@ -194,8 +240,7 @@ private static void AssertTimestampField(Action setValue, var ex = Assert.Throws(() => binary.ToBinary(obj), "Timestamp fields should throw an error on non-UTC values"); - Assert.AreEqual("DateTime is not UTC. Only UTC DateTime can be used for interop with other platforms.", - ex.Message); + Assert.AreEqual(NotUtcDate, ex.Message); // UTC DateTime works. setValue(obj, DateTime.UtcNow); From 9500998923e0e725bf636696178888bcc7a6fa83 Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Thu, 24 Dec 2020 11:24:46 +0300 Subject: [PATCH 35/37] IGNITE-12824: Code review fixes. --- .../Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs index 4d71818063f81..d767280f413be 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs @@ -179,6 +179,9 @@ public void TestCustomTimestampConverter() datesCache.Put(now, dt2); ex = Assert.Throws(() => datesCache.Get(now), "Timestamp fields should throw an error on non-UTC values"); Assert.AreEqual(FromErrMsg, ex.Message); + + datesCache.Put(now, now); + Assert.AreEqual(now, datesCache.Get(now)); var datesObjCache = ignite.CreateCache("datesObj"); @@ -200,6 +203,9 @@ public void TestCustomTimestampConverter() datesObjCache.Put(nowObj, new DateTimeObj {Value = dt2}); ex = Assert.Throws(() => datesObjCache.Get(nowObj), "Timestamp fields should throw an error on non-UTC values"); Assert.AreEqual(FromErrMsg, ex.Message); + + datesObjCache.Put(nowObj, nowObj); + Assert.AreEqual(nowObj.Value, datesObjCache.Get(nowObj).Value); } /// From fc2b7b185e99855dc974fb773a6aeac91303026e Mon Sep 17 00:00:00 2001 From: Pavel Tupitsyn Date: Thu, 24 Dec 2020 12:25:38 +0300 Subject: [PATCH 36/37] Add TestAddYearTimestampConverter --- .../Binary/BinaryDateTimeTest.cs | 102 ++++++++++++++---- 1 file changed, 81 insertions(+), 21 deletions(-) diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs index d767280f413be..57c9d5e2a2ed2 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs @@ -121,6 +121,51 @@ public void TestClassAttributes() AssertTimestampField((o, d) => o.Value = d, o => o.Value, "Value"); } + /// + /// Tests custom timestamp converter that modifies the values by adding one year on write and read. + /// This test verifies that actual converted values are used by Ignite. + /// + [Test] + public void TestAddYearTimestampConverter() + { + var cfg = new IgniteConfiguration(TestUtils.GetTestConfiguration()) + { + AutoGenerateIgniteInstanceName = true, + BinaryConfiguration = new BinaryConfiguration + { + ForceTimestamp = true, + TimestampConverter = new AddYearTimestampConverter() + } + }; + + var ignite = Ignition.Start(cfg); + + var dt = DateTime.UtcNow; + var expected = dt.AddYears(2); + + // Check key & value. + var cache = ignite.GetOrCreateCache(TestUtils.TestName); + cache[dt] = dt; + + var resEntry = cache.Single(); + + Assert.AreEqual(expected, resEntry.Key); + Assert.AreEqual(expected, resEntry.Value); + + // Check object field. + var cache2 = ignite.GetOrCreateCache( + TestUtils.TestName); + + cache2.RemoveAll(); + + var obj = new DateTimePropertyAttribute {Value = dt}; + cache2[obj] = obj; + + var resEntry2 = cache2.Single(); + Assert.AreEqual(expected, resEntry2.Key.Value); + Assert.AreEqual(expected, resEntry2.Value.Value); + } + /// /// Tests custom timestamp converter. /// @@ -129,7 +174,7 @@ public void TestCustomTimestampConverter() { var cfg = new IgniteConfiguration(TestUtils.GetTestConfiguration(name: "ignite-1")) { - BinaryConfiguration = new BinaryConfiguration() + BinaryConfiguration = new BinaryConfiguration { ForceTimestamp = true, TimestampConverter = new TimestampConverter() @@ -297,32 +342,47 @@ private class DateTimeClassAttribute2 { public DateTime Value; } - } - - /// - /// Adds support of the local dates to the Ignite timestamp serialization. - /// - class TimestampConverter : ITimestampConverter - { - /** */ - public void ToJavaTicks(DateTime date, out long high, out int low) + + private class TimestampConverter : ITimestampConverter { - if (date.Year == 1997 && date.Month == 8 && date.Day == 29) - throw new BinaryObjectException(BinaryDateTimeTest.ToErrMsg); + /** */ + public void ToJavaTicks(DateTime date, out long high, out int low) + { + if (date.Year == 1997 && date.Month == 8 && date.Day == 29) + throw new BinaryObjectException(BinaryDateTimeTest.ToErrMsg); - BinaryUtils.ToJavaDate(date, out high, out low); - } + BinaryUtils.ToJavaDate(date, out high, out low); + } + + /** */ + public DateTime FromJavaTicks(long high, int low) + { + var date = new DateTime(BinaryUtils.JavaDateTicks + high * TimeSpan.TicksPerMillisecond + low / 100, + DateTimeKind.Utc); - /** */ - public DateTime FromJavaTicks(long high, int low) + if (date.Year == 1997 && date.Month == 8 && date.Day == 4) + throw new BinaryObjectException(BinaryDateTimeTest.FromErrMsg); + + return date; + } + } + + private class AddYearTimestampConverter : ITimestampConverter { - var date = new DateTime(BinaryUtils.JavaDateTicks + high * TimeSpan.TicksPerMillisecond + low / 100, - DateTimeKind.Utc); + /** */ + public void ToJavaTicks(DateTime date, out long high, out int low) + { + BinaryUtils.ToJavaDate(date.AddYears(1), out high, out low); + } - if (date.Year == 1997 && date.Month == 8 && date.Day == 4) - throw new BinaryObjectException(BinaryDateTimeTest.FromErrMsg); + /** */ + public DateTime FromJavaTicks(long high, int low) + { + var date = new DateTime(BinaryUtils.JavaDateTicks + high * TimeSpan.TicksPerMillisecond + low / 100, + DateTimeKind.Utc); - return date; + return date.AddYears(1); + } } } } From ae70be9ac28b6f4bf14deadfc0f9a5128a77055c Mon Sep 17 00:00:00 2001 From: Pavel Tupitsyn Date: Thu, 24 Dec 2020 12:38:42 +0300 Subject: [PATCH 37/37] Add TestAddYearTimestampConverter --- .../Binary/BinaryDateTimeTest.cs | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs index 57c9d5e2a2ed2..9eae89307d24e 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDateTimeTest.cs @@ -143,7 +143,7 @@ public void TestAddYearTimestampConverter() var dt = DateTime.UtcNow; var expected = dt.AddYears(2); - // Check key & value. + // Key & value. var cache = ignite.GetOrCreateCache(TestUtils.TestName); cache[dt] = dt; @@ -152,7 +152,9 @@ public void TestAddYearTimestampConverter() Assert.AreEqual(expected, resEntry.Key); Assert.AreEqual(expected, resEntry.Value); - // Check object field. + // Key & value array. + + // Object field. var cache2 = ignite.GetOrCreateCache( TestUtils.TestName); @@ -164,6 +166,18 @@ public void TestAddYearTimestampConverter() var resEntry2 = cache2.Single(); Assert.AreEqual(expected, resEntry2.Key.Value); Assert.AreEqual(expected, resEntry2.Value.Value); + + // Object array field. + var cache3 = ignite.GetOrCreateCache(TestUtils.TestName); + cache3.RemoveAll(); + + var obj2 = new DateTimeArr {Value = new[]{dt}}; + cache3[obj2] = obj2; + cache3[obj2] = obj2; + + var resEntry3 = cache3.Single(); + Assert.AreEqual(expected, resEntry3.Key.Value.Single()); + Assert.AreEqual(expected, resEntry3.Value.Value.Single()); } /// @@ -313,6 +327,11 @@ private class DateTimeObj2 public DateTime Value { get; set; } } + private class DateTimeArr + { + public DateTime[] Value { get; set; } + } + private class DateTimePropertyAttribute { [Timestamp]