You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by pt...@apache.org on 2023/12/11 04:51:30 UTC

(ignite-3) branch main updated: IGNITE-20568 .NET: Add support for IgniteCheckedException in ExceptionsGenerator (#2937)

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

ptupitsyn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


The following commit(s) were added to refs/heads/main by this push:
     new 01930fecc8 IGNITE-20568 .NET: Add support for IgniteCheckedException in ExceptionsGenerator (#2937)
01930fecc8 is described below

commit 01930fecc8f701fb2e558dd34ba084e521546458
Author: Pavel Tupitsyn <pt...@apache.org>
AuthorDate: Mon Dec 11 06:51:25 2023 +0200

    IGNITE-20568 .NET: Add support for IgniteCheckedException in ExceptionsGenerator (#2937)
    
    Currently there are no public exceptions derived from `IgniteCheckedException`, but we don't want to miss them in .NET when they are added.
---
 .../ExceptionsGenerator.cs                            | 19 ++++++++++++++-----
 .../Apache.Ignite.Tests/Compute/ComputeTests.cs       | 14 ++++++++++++++
 .../dotnet/Apache.Ignite.Tests/MetricsTests.cs        |  2 ++
 .../dotnet/Apache.Ignite.Tests/Sql/SqlTests.cs        |  3 +++
 .../internal/runner/app/PlatformTestNodeRunner.java   | 14 ++++++++++++++
 5 files changed, 47 insertions(+), 5 deletions(-)

diff --git a/modules/platforms/dotnet/Apache.Ignite.Internal.Generators/ExceptionsGenerator.cs b/modules/platforms/dotnet/Apache.Ignite.Internal.Generators/ExceptionsGenerator.cs
index c3645ab134..a0451dd4e4 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Internal.Generators/ExceptionsGenerator.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Internal.Generators/ExceptionsGenerator.cs
@@ -78,28 +78,37 @@ namespace Apache.Ignite.Internal.Generators
             var template = GetExceptionClassTemplate();
 
             var classMap = new List<(string JavaClass, string DotNetClass)>();
+            var dotNetClassSet = new HashSet<string>();
 
             foreach (var javaException in javaExceptions)
             {
                 var className = javaException.Key;
+                var dotNetClassName = className.Replace("CheckedException", "Exception");
+
+                if (!dotNetClassSet.Add(dotNetClassName) || existingExceptions.Contains(dotNetClassName))
+                {
+                    // .NET does not have checked exceptions, so we map them to unchecked.
+                    // If there is already an unchecked exception with the same name - skip it.
+                    continue;
+                }
 
                 var (javaPackage, dotNetNamespace) = GetPackageAndNamespace(className, javaException.Value.Source);
 
                 var src = template
-                    .Replace("IgniteTemplateException", className)
-                    .Replace("XMLDOC", GetXmlDoc(className, javaException.Value.Source))
+                    .Replace("IgniteTemplateException", dotNetClassName)
+                    .Replace("XMLDOC", GetXmlDoc(dotNetClassName, javaException.Value.Source))
                     .Replace("NAMESPACE", dotNetNamespace);
 
-                yield return (className + ".g.cs", src);
+                yield return (dotNetClassName + ".g.cs", src);
 
-                classMap.Add((javaPackage + "." + className, dotNetNamespace + "." + className));
+                classMap.Add((javaPackage + "." + className, dotNetNamespace + "." + dotNetClassName));
             }
 
             yield return EmitClassMap(classMap);
 
             bool IsIgniteException(string? ex) =>
                 ex != null &&
-                (ex == "IgniteException" ||
+                (ex == "IgniteException" || ex == "IgniteCheckedException" ||
                  IsIgniteException(javaExceptionsWithParents.TryGetValue(ex, out var parent) ? parent.Parent : null));
         }
 
diff --git a/modules/platforms/dotnet/Apache.Ignite.Tests/Compute/ComputeTests.cs b/modules/platforms/dotnet/Apache.Ignite.Tests/Compute/ComputeTests.cs
index dce036f114..dc5a2d0e77 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Tests/Compute/ComputeTests.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Tests/Compute/ComputeTests.cs
@@ -56,6 +56,8 @@ namespace Apache.Ignite.Tests.Compute
 
         private const string ExceptionJob = PlatformTestNodeRunner + "$ExceptionJob";
 
+        private const string CheckedExceptionJob = PlatformTestNodeRunner + "$CheckedExceptionJob";
+
         private static readonly IList<DeploymentUnit> Units = Array.Empty<DeploymentUnit>();
 
         [Test]
@@ -342,6 +344,18 @@ namespace Apache.Ignite.Tests.Compute
                 str);
         }
 
+        [Test]
+        public void TestCheckedExceptionInJobPropagatesToClient()
+        {
+            var ex = Assert.ThrowsAsync<IgniteException>(async () =>
+                await Client.Compute.ExecuteAsync<object>(await GetNodeAsync(1), Units, CheckedExceptionJob, "foo-bar"));
+
+            Assert.AreEqual("TestCheckedEx: foo-bar", ex!.Message);
+            Assert.IsNotNull(ex.InnerException);
+
+            StringAssert.Contains("org.apache.ignite.lang.IgniteCheckedException: IGN-CMN-5", ex.ToString());
+        }
+
         [Test]
         public async Task TestDeploymentUnitsPropagation()
         {
diff --git a/modules/platforms/dotnet/Apache.Ignite.Tests/MetricsTests.cs b/modules/platforms/dotnet/Apache.Ignite.Tests/MetricsTests.cs
index f2dd0fffec..8218d52452 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Tests/MetricsTests.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Tests/MetricsTests.cs
@@ -20,6 +20,7 @@ namespace Apache.Ignite.Tests;
 using System;
 using System.Collections.Concurrent;
 using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
 using System.Diagnostics.Metrics;
 using System.Linq;
 using System.Runtime.CompilerServices;
@@ -91,6 +92,7 @@ public class MetricsTests
     }
 
     [Test]
+    [SuppressMessage("ReSharper", "DisposeOnUsingVariable", Justification = "Test")]
     public async Task TestConnectionsLost()
     {
         using var server = new FakeServer();
diff --git a/modules/platforms/dotnet/Apache.Ignite.Tests/Sql/SqlTests.cs b/modules/platforms/dotnet/Apache.Ignite.Tests/Sql/SqlTests.cs
index 7aee7891d5..036def252e 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Tests/Sql/SqlTests.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Tests/Sql/SqlTests.cs
@@ -19,6 +19,7 @@ namespace Apache.Ignite.Tests.Sql
 {
     using System;
     using System.Collections.Generic;
+    using System.Diagnostics.CodeAnalysis;
     using System.Linq;
     using System.Threading.Tasks;
     using Ignite.Sql;
@@ -28,6 +29,8 @@ namespace Apache.Ignite.Tests.Sql
     /// <summary>
     /// Tests for SQL API: <see cref="ISql"/>.
     /// </summary>
+    [SuppressMessage("ReSharper", "NotDisposedResource", Justification = "Tests")]
+    [SuppressMessage("ReSharper", "NotDisposedResourceIsReturned", Justification = "Tests")]
     public class SqlTests : IgniteTestsBase
     {
         [OneTimeSetUp]
diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/PlatformTestNodeRunner.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/PlatformTestNodeRunner.java
index 83c3ace812..fd4a9d7fdb 100644
--- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/PlatformTestNodeRunner.java
+++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/PlatformTestNodeRunner.java
@@ -53,6 +53,7 @@ import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionException;
 import java.util.stream.Collectors;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgnitionManager;
@@ -76,6 +77,8 @@ import org.apache.ignite.internal.table.RecordBinaryViewImpl;
 import org.apache.ignite.internal.testframework.TestIgnitionManager;
 import org.apache.ignite.internal.type.NativeTypes;
 import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.lang.ErrorGroups.Common;
+import org.apache.ignite.lang.IgniteCheckedException;
 import org.apache.ignite.sql.Session;
 import org.apache.ignite.table.Table;
 import org.apache.ignite.table.Tuple;
@@ -546,6 +549,17 @@ public class PlatformTestNodeRunner {
         }
     }
 
+    /**
+     * Compute job that throws an exception.
+     */
+    @SuppressWarnings("unused") // Used by platform tests.
+    private static class CheckedExceptionJob implements ComputeJob<String> {
+        @Override
+        public String execute(JobExecutionContext context, Object... args) {
+            throw new CompletionException(new IgniteCheckedException(Common.NODE_LEFT_ERR, "TestCheckedEx: " + args[0]));
+        }
+    }
+
     /**
      * Compute job that computes row colocation hash.
      */