IGNITE-6997 .NET: Thin client: Move ClientStatus to public API
authorPavel Tupitsyn <ptupitsyn@apache.org>
Fri, 1 Dec 2017 11:24:49 +0000 (14:24 +0300)
committerPavel Tupitsyn <ptupitsyn@apache.org>
Fri, 1 Dec 2017 11:24:49 +0000 (14:24 +0300)
This closes #3120

modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/Cache/CacheTest.cs
modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/Cache/CreateCacheTest.cs
modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/Cache/ScanQueryTest.cs
modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/ClientConnectionTest.cs
modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/RawSocketTest.cs
modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
modules/platforms/dotnet/Apache.Ignite.Core/Client/ClientStatusCode.cs [moved from modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/ClientStatus.cs with 56% similarity]
modules/platforms/dotnet/Apache.Ignite.Core/Client/IgniteClientException.cs
modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/Cache/CacheClient.cs
modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/ClientSocket.cs

index 0d82479..f54efae 100644 (file)
@@ -840,9 +840,7 @@ namespace Apache.Ignite.Core.Tests.Client.Cache
                 var ex = Assert.Throws<IgniteClientException>(() => cache.Put(1, 1));
 
                 Assert.AreEqual("Cache doesn't exist: foobar", ex.Message);
-#if !NETCOREAPP2_0
-                Assert.AreEqual((int) Impl.Client.ClientStatus.CacheDoesNotExist, ex.ErrorCode);
-#endif
+                Assert.AreEqual(ClientStatusCode.CacheDoesNotExist, ex.StatusCode);
             }
         }
 
index 5e2ccf4..4489462 100644 (file)
@@ -87,7 +87,7 @@ namespace Apache.Ignite.Core.Tests.Client.Cache
             var ex = Assert.Throws<IgniteClientException>(() => Client.CreateCache<int, int>(cache.Name));
             Assert.AreEqual(
                 "Failed to start cache (a cache with the same name is already started): foobar", ex.Message);
-            Assert.AreEqual((int) ClientStatus.CacheExists, ex.ErrorCode);
+            Assert.AreEqual(ClientStatusCode.CacheExists, ex.StatusCode);
 
             // Template: custom configuration.
             cache = Client.CreateCache<int, int>(TemplateCacheName.Replace("*", "1"));
@@ -140,7 +140,7 @@ namespace Apache.Ignite.Core.Tests.Client.Cache
             var ex = Assert.Throws<IgniteClientException>(() => Client.CreateCache<int, int>(cfg));
             Assert.AreEqual(
                 "Failed to start cache (a cache with the same name is already started): a", ex.Message);
-            Assert.AreEqual((int) ClientStatus.CacheExists, ex.ErrorCode);
+            Assert.AreEqual(ClientStatusCode.CacheExists, ex.StatusCode);
 
             // Custom config.
             cfg = GetFullCacheConfiguration("b");
index 354b869..71c8f0f 100644 (file)
@@ -203,9 +203,7 @@ namespace Apache.Ignite.Core.Tests.Client.Cache
                 // MaxCursors = 3
                 var ex = Assert.Throws<IgniteClientException>(() => clientCache.Query(qry));
                 Assert.AreEqual("Too many open cursors", ex.Message.Substring(0, 21));
-#if !NETCOREAPP2_0
-                Assert.AreEqual((int) Impl.Client.ClientStatus.TooManyCursors, ex.ErrorCode);
-#endif
+                Assert.AreEqual(ClientStatusCode.TooManyCursors, ex.StatusCode);
 
                 var count = 0;
 
index 4b9af70..6e368a3 100644 (file)
@@ -124,7 +124,7 @@ namespace Apache.Ignite.Core.Tests.Client
                     new Impl.Client.ClientSocket(GetClientConfiguration(),
                     new Impl.Client.ClientProtocolVersion(-1, -1, -1)));
 
-                Assert.AreEqual((int) Impl.Client.ClientStatus.Fail, ex.ErrorCode);
+                Assert.AreEqual(ClientStatusCode.Fail, ex.StatusCode);
 
                 Assert.AreEqual("Client handhsake failed: 'Unsupported version.'. " +
                                 "Client version: -1.-1.-1. Server version: 1.0.0", ex.Message);
index 9aab341..b088bb6 100644 (file)
@@ -20,6 +20,7 @@ namespace Apache.Ignite.Core.Tests.Client
     using System;
     using System.Net;
     using System.Net.Sockets;
+    using Apache.Ignite.Core.Client;
     using Apache.Ignite.Core.Configuration;
     using Apache.Ignite.Core.Impl;
     using Apache.Ignite.Core.Impl.Binary;
@@ -106,7 +107,7 @@ namespace Apache.Ignite.Core.Tests.Client
                 Assert.AreEqual(11, requestId);
 
                 var status = reader.ReadInt();
-                Assert.AreEqual((int) ClientStatus.InvalidOpCode, status);
+                Assert.AreEqual((int) ClientStatusCode.InvalidOpCode, status);
 
                 var err = reader.ReadObject<string>();
                 Assert.AreEqual("Invalid request op code: -1", err);
index 5adb501..2852853 100644 (file)
     <Compile Include="Impl\Binary\IBinaryProcessor.cs" />
     <Compile Include="Impl\Client\Cache\Query\ClientQueryCursorBase.cs" />
     <Compile Include="Impl\Client\Cache\Query\StatementType.cs" />
-    <Compile Include="Impl\Client\ClientStatus.cs" />
+    <Compile Include="Client\ClientStatusCode.cs" />
     <Compile Include="Events\LocalEventListener.cs" />
     <Compile Include="Impl\DataStorageMetrics.cs" />
     <Compile Include="Impl\IIgniteInternal.cs" />
  * limitations under the License.
  */
 
-namespace Apache.Ignite.Core.Impl.Client
+namespace Apache.Ignite.Core.Client
 {
+    using Apache.Ignite.Core.Configuration;
+
     /// <summary>
-    /// Client status codes.
+    /// Client status codes (see <see cref="IgniteClientException.StatusCode"/>).
     /// </summary>
-    internal enum ClientStatus
+    public enum ClientStatusCode
     {
+        /// <summary>
+        /// Operation succeeded.
+        /// </summary>
         Success = 0,
+
+        /// <summary>
+        /// Operation failed (general-purpose code).
+        /// </summary>
         Fail = 1,
+
+        /// <summary>
+        /// Invalid request operation code.
+        /// </summary>
         InvalidOpCode = 2,
+
+        /// <summary>
+        /// Specified cache does not exist.
+        /// </summary>
         CacheDoesNotExist = 1000,
+
+        /// <summary>
+        /// Cache already exists.
+        /// </summary>
         CacheExists = 1001,
+
+        /// <summary>
+        /// The too many cursors (see <see cref="ClientConnectorConfiguration.MaxOpenCursorsPerConnection"/>).
+        /// </summary>
         TooManyCursors = 1010
     }
 }
index 2df3d1b..3165d45 100644 (file)
@@ -20,7 +20,6 @@ namespace Apache.Ignite.Core.Client
     using System;
     using System.Runtime.Serialization;
     using Apache.Ignite.Core.Common;
-    using Apache.Ignite.Core.Impl.Client;
 
     /// <summary>
     /// Ignite thin client exception.
@@ -29,17 +28,17 @@ namespace Apache.Ignite.Core.Client
     public class IgniteClientException : IgniteException
     {
         /** Error code field. */
-        private const string ErrorCodeField = "ErrorCode";
+        private const string ErrorCodeField = "StatusCode";
 
         /** Error code. */
-        private readonly int _errorCode = (int) ClientStatus.Fail;
+        private readonly ClientStatusCode _statusCode = ClientStatusCode.Fail;
 
         /// <summary>
-        /// Gets the error code.
+        /// Gets the status code code.
         /// </summary>
-        public int ErrorCode
+        public ClientStatusCode StatusCode
         {
-            get { return _errorCode; }
+            get { return _statusCode; }
         }
 
         /// <summary>
@@ -74,10 +73,11 @@ namespace Apache.Ignite.Core.Client
         /// </summary>
         /// <param name="message">The message.</param>
         /// <param name="cause">The cause.</param>
-        /// <param name="errorCode">The error code.</param>
-        public IgniteClientException(string message, Exception cause, int errorCode) : base(message, cause)
+        /// <param name="statusCode">The error code.</param>
+        public IgniteClientException(string message, Exception cause, ClientStatusCode statusCode) 
+            : base(message, cause)
         {
-            _errorCode = errorCode;
+            _statusCode = statusCode;
         }
 
         /// <summary>
@@ -87,7 +87,7 @@ namespace Apache.Ignite.Core.Client
         /// <param name="ctx">Streaming context.</param>
         protected IgniteClientException(SerializationInfo info, StreamingContext ctx) : base(info, ctx)
         {
-            _errorCode = info.GetInt32(ErrorCodeField);
+            _statusCode = (ClientStatusCode) info.GetInt32(ErrorCodeField);
         }
 
         /// <summary>
@@ -102,7 +102,7 @@ namespace Apache.Ignite.Core.Client
         {
             base.GetObjectData(info, context);
 
-            info.AddValue(ErrorCodeField, _errorCode);
+            info.AddValue(ErrorCodeField, (int) _statusCode);
         }
 
         /// <summary>
@@ -110,7 +110,7 @@ namespace Apache.Ignite.Core.Client
         /// </summary>
         public override string ToString()
         {
-            return string.Format("{0} [ErrorCode={1}]", base.ToString(), ErrorCode);
+            return string.Format("{0} [StatusCode={1}]", base.ToString(), StatusCode);
         }
     }
 }
index 0ed2c6d..45c0b0f 100644 (file)
@@ -522,15 +522,15 @@ namespace Apache.Ignite.Core.Impl.Client.Cache
         /// <summary>
         /// Handles the error.
         /// </summary>
-        private T HandleError<T>(ClientStatus status, string msg)
+        private T HandleError<T>(ClientStatusCode status, string msg)
         {
             switch (status)
             {
-                case ClientStatus.CacheDoesNotExist:
-                    throw new IgniteClientException("Cache doesn't exist: " + Name, null, (int) status);
+                case ClientStatusCode.CacheDoesNotExist:
+                    throw new IgniteClientException("Cache doesn't exist: " + Name, null, status);
 
                 default:
-                    throw new IgniteClientException(msg, null, (int) status);
+                    throw new IgniteClientException(msg, null, status);
             }
         }
 
index 078927b..b8218c1 100644 (file)
@@ -68,7 +68,7 @@ namespace Apache.Ignite.Core.Impl.Client
         /// Performs a send-receive operation.
         /// </summary>
         public T DoOutInOp<T>(ClientOp opId, Action<IBinaryStream> writeAction,
-            Func<IBinaryStream, T> readFunc, Func<ClientStatus, string, T> errorFunc = null)
+            Func<IBinaryStream, T> readFunc, Func<ClientStatusCode, string, T> errorFunc = null)
         {
             var requestId = Interlocked.Increment(ref _requestId);
 
@@ -88,9 +88,9 @@ namespace Apache.Ignite.Core.Impl.Client
                 var resRequestId = stream.ReadLong();
                 Debug.Assert(requestId == resRequestId);
 
-                var statusCode = (ClientStatus) stream.ReadInt();
+                var statusCode = (ClientStatusCode) stream.ReadInt();
 
-                if (statusCode == ClientStatus.Success)
+                if (statusCode == ClientStatusCode.Success)
                 {
                     return readFunc != null ? readFunc(stream) : default(T);
                 }
@@ -102,7 +102,7 @@ namespace Apache.Ignite.Core.Impl.Client
                     return errorFunc(statusCode, msg);
                 }
 
-                throw new IgniteClientException(msg, null, (int) statusCode);
+                throw new IgniteClientException(msg, null, statusCode);
             }
         }