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 2020/12/29 18:18:05 UTC

[ignite] branch master updated: IGNITE-13931 .NET: Add tests for overload service methods (#8626)

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 c11ce8c  IGNITE-13931 .NET: Add tests for overload service methods (#8626)
c11ce8c is described below

commit c11ce8c23837274ff243b1f451b4e019d5a2e5fb
Author: Nikolay <ni...@apache.org>
AuthorDate: Tue Dec 29 21:17:52 2020 +0300

    IGNITE-13931 .NET: Add tests for overload service methods (#8626)
---
 .../ignite/platform/PlatformDeployServiceTask.java | 27 +++++++++
 .../apache/ignite/platform/model/ParamValue.java   | 43 +++++++++++++
 .../apache/ignite/platform/model/Parameter.java    | 43 +++++++++++++
 .../Services/IJavaService.cs                       |  3 +
 .../Services/JavaServiceDynamicProxy.cs            |  6 ++
 .../Apache.Ignite.Core.Tests/Services/Model.cs     | 24 ++++++++
 .../Services/ServiceTypeAutoResolveTest.cs         | 27 ++++++---
 .../Services/ServicesTest.cs                       | 70 ++++++++++++++++++++++
 8 files changed, 235 insertions(+), 8 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 67fc13e..5208f7d 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
@@ -47,6 +47,7 @@ import org.apache.ignite.platform.model.Address;
 import org.apache.ignite.platform.model.Department;
 import org.apache.ignite.platform.model.Employee;
 import org.apache.ignite.platform.model.Key;
+import org.apache.ignite.platform.model.Parameter;
 import org.apache.ignite.platform.model.Role;
 import org.apache.ignite.platform.model.User;
 import org.apache.ignite.platform.model.Value;
@@ -465,6 +466,32 @@ public class PlatformDeployServiceTask extends ComputeTaskAdapter<String, Object
         }
 
         /** */
+        public int testOverload(int count, Parameter[] params) {
+            assertNotNull(params);
+            assertEquals(count, params.length);
+
+            assertEquals(1, params[0].getId());
+            assertEquals(2, params[0].getValues().length);
+
+            assertEquals(1, params[0].getValues()[0].getId());
+            assertEquals(42, params[0].getValues()[0].getVal());
+
+            assertEquals(2, params[0].getValues()[1].getId());
+            assertEquals(43, params[0].getValues()[1].getVal());
+
+            assertEquals(2, params[1].getId());
+            assertEquals(2, params[1].getValues().length);
+
+            assertEquals(3, params[1].getValues()[0].getId());
+            assertEquals(44, params[1].getValues()[0].getVal());
+
+            assertEquals(4, params[1].getValues()[1].getId());
+            assertEquals(45, params[1].getValues()[1].getVal());
+
+            return 43;
+        }
+
+        /** */
         public int testOverload(int first, int second) {
             return first + second;
         }
diff --git a/modules/core/src/test/java/org/apache/ignite/platform/model/ParamValue.java b/modules/core/src/test/java/org/apache/ignite/platform/model/ParamValue.java
new file mode 100644
index 0000000..f9ace0a
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/platform/model/ParamValue.java
@@ -0,0 +1,43 @@
+/*
+ * 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.
+ */
+
+package org.apache.ignite.platform.model;
+
+/** */
+public class ParamValue {
+    /** */
+    private int id;
+
+    /** */
+    private long val;
+
+    /** */
+    public ParamValue(int id, long val) {
+        this.id = id;
+        this.val = val;
+    }
+
+    /** */
+    public int getId() {
+        return id;
+    }
+
+    /** */
+    public long getVal() {
+        return val;
+    }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/platform/model/Parameter.java b/modules/core/src/test/java/org/apache/ignite/platform/model/Parameter.java
new file mode 100644
index 0000000..347d97a
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/platform/model/Parameter.java
@@ -0,0 +1,43 @@
+/*
+ * 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.
+ */
+
+package org.apache.ignite.platform.model;
+
+/** */
+public class Parameter {
+    /** */
+    private int id;
+
+    /** */
+    private ParamValue[] values;
+
+    /** */
+    public Parameter(int id, ParamValue[] values) {
+        this.id = id;
+        this.values = values;
+    }
+
+    /** */
+    public int getId() {
+        return id;
+    }
+
+    /** */
+    public ParamValue[] getValues() {
+        return values;
+    }
+}
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 11a13b8..6942c89 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/IJavaService.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/IJavaService.cs
@@ -175,6 +175,9 @@ namespace Apache.Ignite.Core.Tests.Services
         int testOverload(int first, int second);
 
         /** */
+        int testOverload(int count, Parameter[] param);
+
+        /** */
         Employee[] testEmployees(Employee[] emps);
         
         /** */
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 3f34366..bab002f 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/JavaServiceDynamicProxy.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/JavaServiceDynamicProxy.cs
@@ -326,6 +326,12 @@ namespace Apache.Ignite.Core.Tests.Services
         }
 
         /** <inheritDoc /> */
+        public int testOverload(int count, Parameter[] param)
+        {
+            return _svc.testOverload(count, param);
+        }
+
+        /** <inheritDoc /> */
         public Employee[] testEmployees(Employee[] emps)
         {
             return _svc.testEmployees(emps);
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/Model.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/Model.cs
index 275dc7d..e030098 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/Model.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/Model.cs
@@ -144,4 +144,28 @@ namespace org.apache.ignite.platform.model
         
         public Role Role { get; set; }
     }    
+    
+    /// <summary>
+    /// A class is a clone of Java class ParamValue with the same namespace.
+    /// </summary>
+    public class ParamValue 
+    {
+        /** */
+        public int Id { get; set; }
+
+        /** */
+        public long Val { get; set; }
+    }
+
+    /// <summary>
+    /// A class is a clone of Java class Parameter with the same namespace.
+    /// </summary>
+    public class Parameter
+    {
+        /** */
+        public int Id { get; set; }
+
+        /** */
+        public ParamValue[] Values { get; set; }
+    }
 }
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServiceTypeAutoResolveTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServiceTypeAutoResolveTest.cs
index 9734cfb..f27f5a6 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServiceTypeAutoResolveTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServiceTypeAutoResolveTest.cs
@@ -31,6 +31,22 @@ namespace Apache.Ignite.Core.Tests.Services
     public class ServicesTypeAutoResolveTest
     {
         /** */
+        protected internal static readonly Employee[] Emps = new[]
+        {
+            new Employee {Fio = "Sarah Connor", Salary = 1},
+            new Employee {Fio = "John Connor", Salary = 2}
+        };
+        
+        /** */
+        protected internal static readonly Parameter[] Param = new[] 
+        {
+            new Parameter()
+                {Id = 1, Values = new[] {new ParamValue() {Id = 1, Val = 42}, new ParamValue() {Id = 2, Val = 43}}},
+            new Parameter()
+                {Id = 2, Values = new[] {new ParamValue() {Id = 3, Val = 44}, new ParamValue() {Id = 4, Val = 45}}}
+        };
+
+        /** */
         private IIgnite _grid1;
 
         [TestFixtureTearDown]
@@ -127,19 +143,14 @@ namespace Apache.Ignite.Core.Tests.Services
             Assert.AreEqual("127000", addr.Zip);
             Assert.AreEqual("Moscow Akademika Koroleva 12", addr.Addr);
 
-            Employee[] emps = new[]
-            {
-                new Employee {Fio = "Sarah Connor", Salary = 1},
-                new Employee {Fio = "John Connor", Salary = 2}
-            };
-
-            Assert.AreEqual(42, svc.testOverload(2, emps));
+            Assert.AreEqual(42, svc.testOverload(2, Emps));
+            Assert.AreEqual(43, svc.testOverload(2, Param));
             Assert.AreEqual(3, svc.testOverload(1, 2));
             Assert.AreEqual(5, svc.testOverload(3, 2));
 
             Assert.IsNull(svc.testEmployees(null));
 
-            emps = svc.testEmployees(emps);
+            var emps = svc.testEmployees(Emps);
 
             Assert.NotNull(emps);
             Assert.AreEqual(1, emps.Length);
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 682f651..f5dfb17 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs
@@ -31,6 +31,7 @@ namespace Apache.Ignite.Core.Tests.Services
     using Apache.Ignite.Core.Resource;
     using Apache.Ignite.Core.Services;
     using NUnit.Framework;
+    using org.apache.ignite.platform.model;
 
     /// <summary>
     /// Services tests.
@@ -298,6 +299,12 @@ namespace Apache.Ignite.Core.Tests.Services
 
             // Check err method
             Assert.Throws<ServiceInvocationException>(() => prx.ErrMethod(123));
+ 
+            Assert.AreEqual(42, svc.TestOverload(2, ServicesTypeAutoResolveTest.Emps));
+            Assert.AreEqual(3, svc.TestOverload(1, 2));
+            Assert.AreEqual(5, svc.TestOverload(3, 2));
+
+            Assert.AreEqual(43, svc.TestOverload(2, ServicesTypeAutoResolveTest.Param));
 
             // Check local scenario (proxy should not be created for local instance)
             Assert.IsTrue(ReferenceEquals(Grid2.GetServices().GetService<ITestIgniteService>(SvcName),
@@ -358,6 +365,12 @@ namespace Apache.Ignite.Core.Tests.Services
             // Exception in service.
             ex = Assert.Throws<ServiceInvocationException>(() => prx.ErrMethod(123));
             Assert.AreEqual("ExpectedException", (ex.InnerException ?? ex).Message.Substring(0, 17));
+ 
+            Assert.AreEqual(42, svc.TestOverload(2, ServicesTypeAutoResolveTest.Emps));
+            Assert.AreEqual(3, svc.TestOverload(1, 2));
+            Assert.AreEqual(5, svc.TestOverload(3, 2));
+
+            Assert.AreEqual(43, svc.TestOverload(2, ServicesTypeAutoResolveTest.Param));
         }
 
         /// <summary>
@@ -1328,6 +1341,15 @@ namespace Apache.Ignite.Core.Tests.Services
 
             /** */
             object ErrMethod(object arg);
+
+            /** */
+            int TestOverload(int count, Employee[] emps);
+
+            /** */
+            int TestOverload(int first, int second);
+
+            /** */
+            int TestOverload(int count, Parameter[] param);
         }
 
         /// <summary>
@@ -1402,6 +1424,54 @@ namespace Apache.Ignite.Core.Tests.Services
                 throw new ArgumentNullException("arg", "ExpectedException");
             }
 
+            /** */
+            public int TestOverload(int count, Employee[] emps)
+            {
+                Assert.IsNotNull(emps);
+                Assert.AreEqual(count, emps.Length);
+
+                Assert.AreEqual("Sarah Connor", emps[0].Fio);
+                Assert.AreEqual(1, emps[0].Salary);
+
+                Assert.AreEqual("John Connor", emps[1].Fio);
+                Assert.AreEqual(2, emps[1].Salary);
+
+                return 42;
+            }
+
+            /** */
+            public int TestOverload(int first, int second)
+            {
+                return first + second;
+            }
+
+            /** */
+            public int TestOverload(int count, Parameter[] param)
+            {
+                Assert.IsNotNull(param);
+                Assert.AreEqual(count, param.Length);
+
+                Assert.AreEqual(1, param[0].Id);
+                Assert.AreEqual(2, param[0].Values.Length);
+
+                Assert.AreEqual(1, param[0].Values[0].Id);
+                Assert.AreEqual(42, param[0].Values[0].Val);
+
+                Assert.AreEqual(2, param[0].Values[1].Id);
+                Assert.AreEqual(43, param[0].Values[1].Val);
+
+                Assert.AreEqual(2, param[1].Id);
+                Assert.AreEqual(2, param[1].Values.Length);
+
+                Assert.AreEqual(3, param[1].Values[0].Id);
+                Assert.AreEqual(44, param[1].Values[0].Val);
+
+                Assert.AreEqual(4, param[1].Values[1].Id);
+                Assert.AreEqual(45, param[1].Values[1].Val);
+
+                return 43;
+            }
+
             /** <inheritdoc /> */
             public void Init(IServiceContext context)
             {