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 2017/01/25 11:37:00 UTC

ignite git commit: IGNITE-4562 .NET: Add mapping for BinaryObjectException

Repository: ignite
Updated Branches:
  refs/heads/master eed9d6693 -> 885dc32ba


IGNITE-4562 .NET: Add mapping for BinaryObjectException

This closes #1461


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/885dc32b
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/885dc32b
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/885dc32b

Branch: refs/heads/master
Commit: 885dc32ba21d08b0f4bd6b067ad80c738173a2c4
Parents: eed9d66
Author: Pavel Tupitsyn <pt...@apache.org>
Authored: Wed Jan 25 14:36:53 2017 +0300
Committer: Pavel Tupitsyn <pt...@apache.org>
Committed: Wed Jan 25 14:36:53 2017 +0300

----------------------------------------------------------------------
 .../ignite/platform/PlatformExceptionTask.java  | 78 ++++++++++++++++++++
 .../Apache.Ignite.Core.Tests/ExceptionsTest.cs  | 38 ++++++++++
 .../Apache.Ignite.Core/Impl/ExceptionUtils.cs   |  6 +-
 3 files changed, 120 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/885dc32b/modules/core/src/test/java/org/apache/ignite/platform/PlatformExceptionTask.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/platform/PlatformExceptionTask.java b/modules/core/src/test/java/org/apache/ignite/platform/PlatformExceptionTask.java
new file mode 100644
index 0000000..c1ab991
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/platform/PlatformExceptionTask.java
@@ -0,0 +1,78 @@
+/*
+ * 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;
+
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.cache.CacheAtomicUpdateTimeoutException;
+import org.apache.ignite.cluster.ClusterGroupEmptyException;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.cluster.ClusterTopologyException;
+import org.apache.ignite.compute.*;
+import org.apache.ignite.lang.IgniteFutureCancelledException;
+import org.apache.ignite.transactions.*;
+import org.jetbrains.annotations.Nullable;
+
+import javax.cache.CacheException;
+import javax.cache.integration.CacheLoaderException;
+import javax.cache.integration.CacheWriterException;
+import javax.cache.processor.EntryProcessorException;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Task to test exception mappings.
+ */
+public class PlatformExceptionTask extends ComputeTaskAdapter<String, String> {
+    /** {@inheritDoc} */
+    @Nullable @Override public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid,
+        @Nullable String arg) {
+        switch (arg) {
+            case "IllegalArgumentException": throw new IllegalArgumentException(arg);
+            case "IllegalStateException": throw new IllegalStateException(arg);
+            case "UnsupportedOperationException": throw new UnsupportedOperationException(arg);
+            case "IgniteException": throw new IgniteException(arg);
+            case "BinaryObjectException": throw new BinaryObjectException(arg);
+            case "ClusterGroupEmptyException": throw new ClusterGroupEmptyException(arg);
+            case "ClusterTopologyException": throw new ClusterTopologyException(arg);
+            case "ComputeExecutionRejectedException": throw new ComputeExecutionRejectedException(arg);
+            case "ComputeJobFailoverException": throw new ComputeJobFailoverException(arg);
+            case "ComputeTaskCancelledException": throw new ComputeTaskCancelledException(arg);
+            case "ComputeTaskTimeoutException": throw new ComputeTaskTimeoutException(arg);
+            case "ComputeUserUndeclaredException": throw new ComputeUserUndeclaredException(arg);
+            case "CacheException": throw new CacheException(arg);
+            case "CacheLoaderException": throw new CacheLoaderException(arg);
+            case "CacheWriterException": throw new CacheWriterException(arg);
+            case "EntryProcessorException": throw new EntryProcessorException(arg);
+            case "CacheAtomicUpdateTimeoutException": throw new CacheAtomicUpdateTimeoutException(arg);
+            case "TransactionOptimisticException": throw new TransactionOptimisticException(arg);
+            case "TransactionTimeoutException": throw new TransactionTimeoutException(arg);
+            case "TransactionRollbackException": throw new TransactionRollbackException(arg);
+            case "TransactionHeuristicException": throw new TransactionHeuristicException(arg);
+            case "TransactionDeadlockException": throw new TransactionDeadlockException(arg);
+            case "IgniteFutureCancelledException": throw new IgniteFutureCancelledException(arg);
+        }
+
+        return null;
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public String reduce(List<ComputeJobResult> results) {
+        return results.get(0).getData();
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/885dc32b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ExceptionsTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ExceptionsTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ExceptionsTest.cs
index 052ff6f..8c23ab7 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ExceptionsTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ExceptionsTest.cs
@@ -28,6 +28,8 @@ namespace Apache.Ignite.Core.Tests
     using Apache.Ignite.Core.Cache;
     using Apache.Ignite.Core.Cluster;
     using Apache.Ignite.Core.Common;
+    using Apache.Ignite.Core.Compute;
+    using Apache.Ignite.Core.Transactions;
     using NUnit.Framework;
 
     /// <summary>
@@ -35,6 +37,9 @@ namespace Apache.Ignite.Core.Tests
     /// </summary>
     public class ExceptionsTest
     {
+        /** */
+        private const string ExceptionTask = "org.apache.ignite.platform.PlatformExceptionTask";
+
         /// <summary>
         /// Before test.
         /// </summary>
@@ -70,12 +75,45 @@ namespace Apache.Ignite.Core.Tests
             Assert.IsTrue(e.InnerException.Message.StartsWith(
                 "class org.apache.ignite.cluster.ClusterGroupEmptyException: Cluster group is empty."));
 
+            // Check all exceptions mapping.
+            var comp = grid.GetCompute();
+
+            CheckException<BinaryObjectException>(comp, "BinaryObjectException");
+            CheckException<IgniteException>(comp, "IgniteException");
+            CheckException<BinaryObjectException>(comp, "BinaryObjectException");
+            CheckException<ClusterTopologyException>(comp, "ClusterTopologyException");
+            CheckException<ComputeExecutionRejectedException>(comp, "ComputeExecutionRejectedException");
+            CheckException<ComputeJobFailoverException>(comp, "ComputeJobFailoverException");
+            CheckException<ComputeTaskCancelledException>(comp, "ComputeTaskCancelledException");
+            CheckException<ComputeTaskTimeoutException>(comp, "ComputeTaskTimeoutException");
+            CheckException<ComputeUserUndeclaredException>(comp, "ComputeUserUndeclaredException");
+            CheckException<TransactionOptimisticException>(comp, "TransactionOptimisticException");
+            CheckException<TransactionTimeoutException>(comp, "TransactionTimeoutException");
+            CheckException<TransactionRollbackException>(comp, "TransactionRollbackException");
+            CheckException<TransactionHeuristicException>(comp, "TransactionHeuristicException");
+            CheckException<TransactionDeadlockException>(comp, "TransactionDeadlockException");
+            CheckException<IgniteFutureCancelledException>(comp, "IgniteFutureCancelledException");
+
+            // Check stopped grid.
             grid.Dispose();
 
             Assert.Throws<InvalidOperationException>(() => grid.GetCache<object, object>("cache1"));
         }
 
         /// <summary>
+        /// Checks the exception.
+        /// </summary>
+        private static void CheckException<T>(ICompute comp, string name) where T : Exception
+        {
+            var ex = Assert.Throws<T>(() => comp.ExecuteJavaTask<string>(ExceptionTask, name));
+
+            var javaEx = ex.InnerException as JavaException;
+
+            Assert.IsNotNull(javaEx);
+            Assert.IsTrue(javaEx.Message.Contains("at " + ExceptionTask));
+        }
+
+        /// <summary>
         /// Tests CachePartialUpdateException keys propagation.
         /// </summary>
         [Test]

http://git-wip-us.apache.org/repos/asf/ignite/blob/885dc32b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/ExceptionUtils.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/ExceptionUtils.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/ExceptionUtils.cs
index ddbdd86..64f3ccc 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/ExceptionUtils.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/ExceptionUtils.cs
@@ -24,6 +24,7 @@ namespace Apache.Ignite.Core.Impl
     using System.Security;
     using System.Text.RegularExpressions;
     using System.Threading;
+    using Apache.Ignite.Core.Binary;
     using Apache.Ignite.Core.Cache;
     using Apache.Ignite.Core.Cache.Store;
     using Apache.Ignite.Core.Cluster;
@@ -62,10 +63,10 @@ namespace Apache.Ignite.Core.Impl
             Justification = "Readability")]
         static ExceptionUtils()
         {
-            // Common Java exceptions mapped to common .Net exceptions.
+            // Common Java exceptions mapped to common .NET exceptions.
             Exs["java.lang.IllegalArgumentException"] = (i, m, e) => new ArgumentException(m, e);
             Exs["java.lang.IllegalStateException"] = (i, m, e) => new InvalidOperationException(m, e);
-            Exs["java.lang.UnsupportedOperationException"] = (i, m, e) => new NotImplementedException(m, e);
+            Exs["java.lang.UnsupportedOperationException"] = (i, m, e) => new NotSupportedException(m, e);
             Exs["java.lang.InterruptedException"] = (i, m, e) => new ThreadInterruptedException(m, e);
 
             // Generic Ignite exceptions.
@@ -73,6 +74,7 @@ namespace Apache.Ignite.Core.Impl
             Exs["org.apache.ignite.IgniteCheckedException"] = (i, m, e) => new IgniteException(m, e);
             Exs["org.apache.ignite.IgniteClientDisconnectedException"] = (i, m, e) => new ClientDisconnectedException(m, e, i.GetCluster().ClientReconnectTask);
             Exs["org.apache.ignite.internal.IgniteClientDisconnectedCheckedException"] = (i, m, e) => new ClientDisconnectedException(m, e, i.GetCluster().ClientReconnectTask);
+            Exs["org.apache.ignite.binary.BinaryObjectException"] = (i, m, e) => new BinaryObjectException(m, e);
 
             // Cluster exceptions.
             Exs["org.apache.ignite.cluster.ClusterGroupEmptyException"] = (i, m, e) => new ClusterGroupEmptyException(m, e);