You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ni...@apache.org on 2021/03/16 14:08:57 UTC

[ignite] branch master updated: IGNITE-14320 .NET: Fix namespace handling in TypeNameParser (#8883)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new c607850  IGNITE-14320 .NET: Fix namespace handling in TypeNameParser (#8883)
c607850 is described below

commit c607850c16a5c6180323c0fee3e662b0e0567da8
Author: Nikolay <ni...@apache.org>
AuthorDate: Tue Mar 16 17:08:32 2021 +0300

    IGNITE-14320 .NET: Fix namespace handling in TypeNameParser (#8883)
    
    Co-authored-by: Pavel Tupitsyn <pt...@apache.org>
---
 .../Binary/BinaryDynamicRegistrationTest.cs        | 47 +++++++++++-----
 .../Binary/BinaryNameMapperTest.cs                 | 62 +++++++++++++++++++++-
 .../Services/ServicesTypeAutoResolveTest.cs        |  2 +
 .../Impl/Binary/TypeNameParser.cs                  |  2 +-
 4 files changed, 99 insertions(+), 14 deletions(-)

diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDynamicRegistrationTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDynamicRegistrationTest.cs
index d8d706e..eab8d93 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDynamicRegistrationTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryDynamicRegistrationTest.cs
@@ -225,9 +225,9 @@ namespace Apache.Ignite.Core.Tests.Binary
         /// Tests the single grid scenario.
         /// </summary>
         [Test]
-        public void TestSingleGrid()
+        public void TestSingleGrid([Values(false, true)] bool customMapper)
         {
-            using (var ignite = Ignition.Start(TestUtils.GetTestConfiguration()))
+            using (var ignite = Ignition.Start(GetConfig(false, customMapper)))
             {
                 Test(ignite, ignite);
             }
@@ -237,23 +237,20 @@ namespace Apache.Ignite.Core.Tests.Binary
         /// Tests the two grid scenario.
         /// </summary>
         [Test]
-        public void TestTwoGrids([Values(false, true)] bool clientMode)
+        public void TestTwoGrids([Values(false, true)] bool clientMode, [Values(false, true)] bool customMapper)
         {
-            using (var ignite1 = Ignition.Start(TestUtils.GetTestConfiguration()))
-            {
-                var cfg = new IgniteConfiguration(TestUtils.GetTestConfiguration())
-                {
-                    IgniteInstanceName = "grid2",
-                    ClientMode = clientMode
-                };
+            var cfg1 = GetConfig(false, customMapper);
+            var cfg2 = GetConfig(clientMode, customMapper, "grid2");
 
-                using (var ignite2 = Ignition.Start(cfg))
+            using (var ignite1 = Ignition.Start(cfg1))
+            {
+                using (var ignite2 = Ignition.Start(cfg2))
                 {
                     Test(ignite1, ignite2);
                 }
 
                 // Test twice to verify double registration.
-                using (var ignite2 = Ignition.Start(cfg))
+                using (var ignite2 = Ignition.Start(cfg2))
                 {
                     Test(ignite1, ignite2);
                 }
@@ -473,6 +470,32 @@ namespace Apache.Ignite.Core.Tests.Binary
             files.ToList().ForEach(File.Delete);
         }
 
+        /// <summary>
+        /// Gets the config.
+        /// </summary>
+        private static IgniteConfiguration GetConfig(bool client, bool customMapper, string name = null)
+        {
+            var cfg = new IgniteConfiguration(TestUtils.GetTestConfiguration())
+            {
+                ClientMode = client,
+                IgniteInstanceName = name
+            };
+
+            if (customMapper)
+            {
+                cfg.BinaryConfiguration = new BinaryConfiguration
+                {
+                    NameMapper = new BinaryBasicNameMapper
+                    {
+                        NamespaceToLower = true,
+                        NamespacePrefix = "foo.bar."
+                    }
+                };
+            }
+
+            return cfg;
+        }
+
         private interface ITest
         {
             int Int { get; set; }
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryNameMapperTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryNameMapperTest.cs
index 1974caf..b0fb79e 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryNameMapperTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryNameMapperTest.cs
@@ -115,6 +115,18 @@ namespace Apache.Ignite.Core.Tests.Binary
 
             Assert.AreEqual("apache.ignite.platform.model.Address[]", 
                 mapper.GetTypeName(typeof(Address[]).FullName));
+
+            Assert.AreEqual("system.collections.generic.List`1",
+                mapper.GetTypeName(typeof(List<>).AssemblyQualifiedName));
+
+            Assert.AreEqual("system.collections.generic.List`1[[apache.ignite.platform.model.Address]]",
+                mapper.GetTypeName(typeof(List<Address>).AssemblyQualifiedName));
+
+            Assert.AreEqual("system.collections.generic.Dictionary`2",
+                mapper.GetTypeName(typeof(Dictionary<,>).AssemblyQualifiedName));
+
+            Assert.AreEqual("system.collections.generic.Dictionary`2[[system.Int32],[apache.ignite.platform.model.Address]]",
+                mapper.GetTypeName(typeof(Dictionary<int,Address>).AssemblyQualifiedName));
         }
 
         /// <summary>
@@ -131,6 +143,18 @@ namespace Apache.Ignite.Core.Tests.Binary
             Assert.AreEqual("MyClass", mapper.GetTypeName("Org.Company.MyClass"));
             Assert.AreEqual("URL", mapper.GetTypeName("Org.Company.URL"));
 
+            Assert.AreEqual("List`1",
+                mapper.GetTypeName(typeof(List<>).AssemblyQualifiedName));
+
+            Assert.AreEqual("List`1[[Address]]",
+                mapper.GetTypeName(typeof(List<Address>).AssemblyQualifiedName));
+
+            Assert.AreEqual("Dictionary`2",
+                mapper.GetTypeName(typeof(Dictionary<,>).AssemblyQualifiedName));
+
+            Assert.AreEqual("Dictionary`2[[Int32],[Address]]",
+                mapper.GetTypeName(typeof(Dictionary<int,Address>).AssemblyQualifiedName));
+
             mapper = new BinaryBasicNameMapper {IsSimpleName = true, NamespacePrefix = "org."};
             Assert.IsTrue(mapper.IsSimpleName);
 
@@ -138,6 +162,18 @@ namespace Apache.Ignite.Core.Tests.Binary
             Assert.AreEqual("Class", mapper.GetTypeName("Org.MyCompany.Class"));
             Assert.AreEqual("MyClass", mapper.GetTypeName("Org.Company.MyClass"));
             Assert.AreEqual("URL", mapper.GetTypeName("Org.Company.URL"));
+
+            Assert.AreEqual("List`1",
+                mapper.GetTypeName(typeof(List<>).AssemblyQualifiedName));
+
+            Assert.AreEqual("List`1[[Address]]",
+                mapper.GetTypeName(typeof(List<Address>).AssemblyQualifiedName));
+
+            Assert.AreEqual("Dictionary`2",
+                mapper.GetTypeName(typeof(Dictionary<,>).AssemblyQualifiedName));
+
+            Assert.AreEqual("Dictionary`2[[Int32],[Address]]",
+                mapper.GetTypeName(typeof(Dictionary<int, Address>).AssemblyQualifiedName));
         }
 
         /// <summary>
@@ -159,7 +195,19 @@ namespace Apache.Ignite.Core.Tests.Binary
 
             Assert.AreEqual("org.apache.ignite.platform.model.Address[]", 
                 mapper.GetTypeName(typeof(Address[]).FullName));
-                
+
+            Assert.AreEqual("org.system.collections.generic.List`1[[org.apache.ignite.platform.model.Address]]",
+                mapper.GetTypeName(typeof(List<Address>).AssemblyQualifiedName));
+
+            Assert.AreEqual("org.system.collections.generic.List`1",
+                mapper.GetTypeName(typeof(List<>).AssemblyQualifiedName));
+
+            Assert.AreEqual("org.system.collections.generic.Dictionary`2",
+                mapper.GetTypeName(typeof(Dictionary<,>).AssemblyQualifiedName));
+
+            Assert.AreEqual("org.system.collections.generic.Dictionary`2[[org.system.Int32],[org.apache.ignite.platform.model.Address]]",
+                mapper.GetTypeName(typeof(Dictionary<int, Address>).AssemblyQualifiedName));
+
             mapper = new BinaryBasicNameMapper {NamespacePrefix = "Org.", NamespaceToLower = false};
             Assert.IsFalse(mapper.IsSimpleName);
 
@@ -173,6 +221,18 @@ namespace Apache.Ignite.Core.Tests.Binary
 
             Assert.AreEqual("Org.Apache.Ignite.Platform.Model.Address[]", 
                 mapper.GetTypeName(typeof(Address[]).FullName));
+
+            Assert.AreEqual("Org.System.Collections.Generic.List`1[[Org.Apache.Ignite.Platform.Model.Address]]",
+                mapper.GetTypeName(typeof(List<Address>).AssemblyQualifiedName));
+
+            Assert.AreEqual("Org.System.Collections.Generic.List`1",
+                mapper.GetTypeName(typeof(List<>).AssemblyQualifiedName));
+
+            Assert.AreEqual("Org.System.Collections.Generic.Dictionary`2",
+                mapper.GetTypeName(typeof(Dictionary<,>).AssemblyQualifiedName));
+
+            Assert.AreEqual("Org.System.Collections.Generic.Dictionary`2[[Org.System.Int32],[Org.Apache.Ignite.Platform.Model.Address]]",
+                mapper.GetTypeName(typeof(Dictionary<int, Address>).AssemblyQualifiedName));
         }
 
         /// <summary>
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTypeAutoResolveTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTypeAutoResolveTest.cs
index 2d666ab..09ce3c5 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTypeAutoResolveTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTypeAutoResolveTest.cs
@@ -110,6 +110,8 @@ namespace Apache.Ignite.Core.Tests.Services
 
             DoTestService(svc);
 
+            DoTestDepartments(svc);
+
             _grid1.GetServices().Cancel(platformSvcName);
         }
 
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/TypeNameParser.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/TypeNameParser.cs
index f3ea08f..0042675 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/TypeNameParser.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/TypeNameParser.cs
@@ -172,7 +172,7 @@ namespace Apache.Ignite.Core.Impl.Binary
         /// </summary>
         public string GetNamespace()
         {
-            return NameStart == 0 ? null : _typeName.Substring(_start, NameStart);
+            return NameStart == 0 ? null : _typeName.Substring(_start, NameStart - _start);
         }
 
         /// <summary>