Skip to content

Commit

Permalink
IGNITE-6997 .NET: Thin client: Move ClientStatus to public API
Browse files Browse the repository at this point in the history
This closes apache#3120
  • Loading branch information
ptupitsyn authored and zstan committed Dec 20, 2017
1 parent 54af722 commit a55e6b8
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -840,9 +840,7 @@ public void TestExceptions()
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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void TestCreateFromTemplate()
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"));
Expand Down Expand Up @@ -140,7 +140,7 @@ public void TestCreateFromConfiguration()
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,7 @@ public void TestMultipleCursors()
// 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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void TestIncorrectProtocolVersionError()
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -106,7 +107,7 @@ public void TestInvalidOpCode()
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,43 @@
* 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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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>
Expand Down Expand Up @@ -74,10 +73,11 @@ public IgniteClientException(string message, Exception cause) : base(message, ca
/// </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>
Expand All @@ -87,7 +87,7 @@ public IgniteClientException(string message, Exception cause, int errorCode) : b
/// <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>
Expand All @@ -102,15 +102,15 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont
{
base.GetObjectData(info, context);

info.AddValue(ErrorCodeField, _errorCode);
info.AddValue(ErrorCodeField, (int) _statusCode);
}

/// <summary>
/// Returns a <see cref="string" /> that represents this instance.
/// </summary>
public override string ToString()
{
return string.Format("{0} [ErrorCode={1}]", base.ToString(), ErrorCode);
return string.Format("{0} [StatusCode={1}]", base.ToString(), StatusCode);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -522,15 +522,15 @@ private static void WriteSqlFieldsQuery(IBinaryRawWriter writer, SqlFieldsQuery
/// <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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public ClientSocket(IgniteClientConfiguration clientConfiguration, ClientProtoco
/// 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);

Expand All @@ -88,9 +88,9 @@ public ClientSocket(IgniteClientConfiguration clientConfiguration, ClientProtoco
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);
}
Expand All @@ -102,7 +102,7 @@ public ClientSocket(IgniteClientConfiguration clientConfiguration, ClientProtoco
return errorFunc(statusCode, msg);
}

throw new IgniteClientException(msg, null, (int) statusCode);
throw new IgniteClientException(msg, null, statusCode);
}
}

Expand Down

0 comments on commit a55e6b8

Please sign in to comment.