Repository: ignite Updated Branches: refs/heads/ignite-zk 73cea1642 -> 74330bc14
IGNITE-6997 .NET: Thin client: Move ClientStatus to public API This closes #3120 Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/3979e6a9 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/3979e6a9 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/3979e6a9 Branch: refs/heads/ignite-zk Commit: 3979e6a9b561f3ada2ca0e108c76885725ebacb6 Parents: 23b106d Author: Pavel Tupitsyn <[email protected]> Authored: Fri Dec 1 14:24:49 2017 +0300 Committer: Pavel Tupitsyn <[email protected]> Committed: Fri Dec 1 14:24:49 2017 +0300 ---------------------------------------------------------------------- .../Client/Cache/CacheTest.cs | 4 +- .../Client/Cache/CreateCacheTest.cs | 4 +- .../Client/Cache/ScanQueryTest.cs | 4 +- .../Client/ClientConnectionTest.cs | 2 +- .../Client/RawSocketTest.cs | 3 +- .../Apache.Ignite.Core.csproj | 2 +- .../Client/ClientStatusCode.cs | 57 ++++++++++++++++++++ .../Client/IgniteClientException.cs | 24 ++++----- .../Impl/Client/Cache/CacheClient.cs | 8 +-- .../Impl/Client/ClientSocket.cs | 8 +-- .../Impl/Client/ClientStatus.cs | 32 ----------- 11 files changed, 85 insertions(+), 63 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/3979e6a9/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/Cache/CacheTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/Cache/CacheTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/Cache/CacheTest.cs index 0d82479..f54efae 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/Cache/CacheTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/Cache/CacheTest.cs @@ -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); } } http://git-wip-us.apache.org/repos/asf/ignite/blob/3979e6a9/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/Cache/CreateCacheTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/Cache/CreateCacheTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/Cache/CreateCacheTest.cs index 5e2ccf4..4489462 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/Cache/CreateCacheTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/Cache/CreateCacheTest.cs @@ -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"); http://git-wip-us.apache.org/repos/asf/ignite/blob/3979e6a9/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/Cache/ScanQueryTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/Cache/ScanQueryTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/Cache/ScanQueryTest.cs index 354b869..71c8f0f 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/Cache/ScanQueryTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/Cache/ScanQueryTest.cs @@ -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; http://git-wip-us.apache.org/repos/asf/ignite/blob/3979e6a9/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/ClientConnectionTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/ClientConnectionTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/ClientConnectionTest.cs index 4b9af70..6e368a3 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/ClientConnectionTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/ClientConnectionTest.cs @@ -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); http://git-wip-us.apache.org/repos/asf/ignite/blob/3979e6a9/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/RawSocketTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/RawSocketTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/RawSocketTest.cs index 9aab341..b088bb6 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/RawSocketTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/RawSocketTest.cs @@ -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); http://git-wip-us.apache.org/repos/asf/ignite/blob/3979e6a9/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj b/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj index 5adb501..2852853 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj @@ -129,7 +129,7 @@ <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" /> http://git-wip-us.apache.org/repos/asf/ignite/blob/3979e6a9/modules/platforms/dotnet/Apache.Ignite.Core/Client/ClientStatusCode.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Client/ClientStatusCode.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Client/ClientStatusCode.cs new file mode 100644 index 0000000..3f5ee8e --- /dev/null +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Client/ClientStatusCode.cs @@ -0,0 +1,57 @@ +/* + * 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. + */ + +namespace Apache.Ignite.Core.Client +{ + using Apache.Ignite.Core.Configuration; + + /// <summary> + /// Client status codes (see <see cref="IgniteClientException.StatusCode"/>). + /// </summary> + 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 + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/3979e6a9/modules/platforms/dotnet/Apache.Ignite.Core/Client/IgniteClientException.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Client/IgniteClientException.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Client/IgniteClientException.cs index 2df3d1b..3165d45 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Client/IgniteClientException.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Client/IgniteClientException.cs @@ -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); } } } http://git-wip-us.apache.org/repos/asf/ignite/blob/3979e6a9/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/Cache/CacheClient.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/Cache/CacheClient.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/Cache/CacheClient.cs index 0ed2c6d..45c0b0f 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/Cache/CacheClient.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/Cache/CacheClient.cs @@ -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); } } http://git-wip-us.apache.org/repos/asf/ignite/blob/3979e6a9/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/ClientSocket.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/ClientSocket.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/ClientSocket.cs index 078927b..b8218c1 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/ClientSocket.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/ClientSocket.cs @@ -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); } } http://git-wip-us.apache.org/repos/asf/ignite/blob/3979e6a9/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/ClientStatus.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/ClientStatus.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/ClientStatus.cs deleted file mode 100644 index 294a202..0000000 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/ClientStatus.cs +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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. - */ - -namespace Apache.Ignite.Core.Impl.Client -{ - /// <summary> - /// Client status codes. - /// </summary> - internal enum ClientStatus - { - Success = 0, - Fail = 1, - InvalidOpCode = 2, - CacheDoesNotExist = 1000, - CacheExists = 1001, - TooManyCursors = 1010 - } -}
