From e40952f85d85d1df950b6876ad7f9cdee024d4c6 Mon Sep 17 00:00:00 2001 From: Anatoly Popov Date: Tue, 25 Oct 2016 15:49:35 +0300 Subject: [PATCH 01/16] TreeIndexMethods fix --- tarantool/tarantool.lua | 12 +++++++++++- tests/tarantool.client.tests/Index/Smoke.cs | 9 +++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/tarantool/tarantool.lua b/tarantool/tarantool.lua index 6e57b7ea..5074a79d 100644 --- a/tarantool/tarantool.lua +++ b/tarantool/tarantool.lua @@ -50,4 +50,14 @@ local function init() box.session.on_auth(log_auth_ok) end -box.once('init', init) \ No newline at end of file +local function space_TreeIndexMethods() + space = box.schema.space.create('space_TreeIndexMethods', { if_not_exists = true }) + space:create_index('treeIndex', {type='tree', parts={1, 'unsigned'}, if_not_exists = true }) + + space:auto_increment{'asdf', 10.1} + space:auto_increment{'zcxv'} + space:auto_increment{2, 3} +end + +box.once('init', init) +box.once('space_TreeIndexMethods', space_TreeIndexMethods) \ No newline at end of file diff --git a/tests/tarantool.client.tests/Index/Smoke.cs b/tests/tarantool.client.tests/Index/Smoke.cs index b84f9980..b8ecd42d 100644 --- a/tests/tarantool.client.tests/Index/Smoke.cs +++ b/tests/tarantool.client.tests/Index/Smoke.cs @@ -6,6 +6,7 @@ using ProGaudi.Tarantool.Client.Model; using ProGaudi.Tarantool.Client.Model.Responses; using ProGaudi.Tarantool.Client.Model.UpdateOperations; +using Shouldly; namespace ProGaudi.Tarantool.Client.Tests.Index { @@ -49,7 +50,7 @@ public async Task HashIndexMethods() [Fact] public async Task TreeIndexMethods() { - const string spaceName = "primary_and_secondary_index"; + const string spaceName = "space_TreeIndexMethods"; var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301"); var schema = tarantoolClient.GetSchema(); @@ -59,10 +60,14 @@ public async Task TreeIndexMethods() var index = await space.GetIndex("treeIndex"); var min2 = await index.Min, TarantoolTuple>(TarantoolTuple.Create(3)); + min2.ShouldBe(TarantoolTuple.Create(3, 2, 3)); var min = await index.Min>(); + min.ShouldBe(TarantoolTuple.Create(1, "asdf", 10.1)); var max = await index.Max>(); - var max2 = await index.Max, TarantoolTuple>(TarantoolTuple.Create(4)); + max.ShouldBe(min2); + var max2 = await index.Max, TarantoolTuple>(TarantoolTuple.Create(1)); + max2.ShouldBe(min); } } } \ No newline at end of file From 87745093e6d1eef275c5e07e1129df43c710b285 Mon Sep 17 00:00:00 2001 From: Anatoly Popov Date: Tue, 25 Oct 2016 17:54:45 +0300 Subject: [PATCH 02/16] Remove unused variables --- tests/tarantool.client.tests/Index/Smoke.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/tests/tarantool.client.tests/Index/Smoke.cs b/tests/tarantool.client.tests/Index/Smoke.cs index b8ecd42d..9f41d1c4 100644 --- a/tests/tarantool.client.tests/Index/Smoke.cs +++ b/tests/tarantool.client.tests/Index/Smoke.cs @@ -24,27 +24,26 @@ public async Task HashIndexMethods() var index = await space.GetIndex("primary"); - DataResponse[]> insertDataResponse; try { - insertDataResponse = await index.Insert(TarantoolTuple.Create(2, "Music")); + await index.Insert(TarantoolTuple.Create(2, "Music")); } catch (ArgumentException) { - var deleteResponse = await index.Delete, TarantoolTuple>(TarantoolTuple.Create(2)); - insertDataResponse = await index.Insert(TarantoolTuple.Create(2, "Music")); + await index.Delete, TarantoolTuple>(TarantoolTuple.Create(2)); + await index.Insert(TarantoolTuple.Create(2, "Music")); } - var selectResponse = await index.Select, TarantoolTuple>(TarantoolTuple.Create(1029u)); - var replaceResponse = await index.Replace(TarantoolTuple.Create(2, "Car", -245.3)); - var updateResponse = await index.Update, TarantoolTuple>( + await index.Select, TarantoolTuple>(TarantoolTuple.Create(1029u)); + await index.Replace(TarantoolTuple.Create(2, "Car", -245.3)); + await index.Update, TarantoolTuple>( TarantoolTuple.Create(2), new UpdateOperation[] { UpdateOperation.CreateAddition(100, 2) }); await index.Upsert(TarantoolTuple.Create(5u), new UpdateOperation[] { UpdateOperation.CreateAssign(2, 2) }); await index.Upsert(TarantoolTuple.Create(5u), new UpdateOperation[] { UpdateOperation.CreateAddition(-2, 2) }); - var selectResponse2 = index.Select, TarantoolTuple>(TarantoolTuple.Create(5u)); + await index.Select, TarantoolTuple>(TarantoolTuple.Create(5u)); } [Fact] From 97121832c767c0ac6858edcb42640083f4a7fca8 Mon Sep 17 00:00:00 2001 From: Anatoly Popov Date: Tue, 25 Oct 2016 18:25:55 +0300 Subject: [PATCH 03/16] Suppressing test --- tests/tarantool.client.tests/Space/Upsert_Should.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tarantool.client.tests/Space/Upsert_Should.cs b/tests/tarantool.client.tests/Space/Upsert_Should.cs index 3591c3ff..88403a4d 100644 --- a/tests/tarantool.client.tests/Space/Upsert_Should.cs +++ b/tests/tarantool.client.tests/Space/Upsert_Should.cs @@ -12,7 +12,7 @@ namespace ProGaudi.Tarantool.Client.Tests.Space { public class Upsert_Should { - [Fact] + [Fact(Skip = "Bug in tarantool: https://github.com/tarantool/tarantool/issues/1867")] public async Task throw_expection_on_space_with_secondary_index() { const string spaceName = "primary_and_secondary_index"; From 8444002fa42957495788a1b6be23e4ef7a280b5c Mon Sep 17 00:00:00 2001 From: Anatoly Popov Date: Wed, 26 Oct 2016 19:33:50 +0300 Subject: [PATCH 04/16] Do not break read cycle on bad packet. Ignore it. --- src/tarantool.client/LogicalConnection.cs | 16 ++++++--------- src/tarantool.client/ResponseReader.cs | 24 ++++++++++++++++++++++- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/tarantool.client/LogicalConnection.cs b/src/tarantool.client/LogicalConnection.cs index 507e5aa0..49f29a64 100644 --- a/src/tarantool.client/LogicalConnection.cs +++ b/src/tarantool.client/LogicalConnection.cs @@ -48,24 +48,20 @@ public async Task> SendRequest(TR return await SendRequestImpl>(request); } - public TaskCompletionSource PopResponseCompletionSource(RequestId requestId, - MemoryStream resultStream) + public TaskCompletionSource PopResponseCompletionSource(RequestId requestId, MemoryStream resultStream) { TaskCompletionSource request; - if (!_pendingRequests.TryRemove(requestId, out request)) - { - throw ExceptionHelper.WrongRequestId(requestId); - } - - return request; + return _pendingRequests.TryRemove(requestId, out request) + ? request + : null; } public static byte[] ReadFully(Stream input) { input.Position = 0; - byte[] buffer = new byte[16*1024]; - using (MemoryStream ms = new MemoryStream()) + var buffer = new byte[16*1024]; + using (var ms = new MemoryStream()) { int read; while ((read = input.Read(buffer, 0, buffer.Length)) > 0) diff --git a/src/tarantool.client/ResponseReader.cs b/src/tarantool.client/ResponseReader.cs index 57928579..4ed08728 100644 --- a/src/tarantool.client/ResponseReader.cs +++ b/src/tarantool.client/ResponseReader.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Text; using ProGaudi.MsgPack.Light; using ProGaudi.Tarantool.Client.Model; @@ -25,7 +26,7 @@ internal class ResponseReader : IResponseReader private int _parsingOffset; - private bool _disposed = false; + private bool _disposed; public ResponseReader(ILogicalConnection logicalConnection, ClientOptions clientOptions, INetworkStreamPhysicalConnection physicalConnection) { @@ -139,6 +140,27 @@ private void MatchResult(byte[] result) var header= MsgPackSerializer.Deserialize(resultStream, _clientOptions.MsgPackContext); var tcs = _logicalConnection.PopResponseCompletionSource(header.RequestId, resultStream); + if (tcs == null) + { + if (_clientOptions.LogWriter == null) + return; + + var builder = new StringBuilder("Warning: can't match request via requestId from response. Response:"); + var length = 80/3; + for (var i = 0; i < result.Length; i++) + { + if (i%length == 0) + builder.AppendLine().Append(" "); + else + builder.Append(" "); + + builder.AppendFormat("{0:X2}", result[i]); + } + + _clientOptions.LogWriter?.WriteLine(builder.ToString()); + return; + } + if ((header.Code & CommandCode.ErrorMask) == CommandCode.ErrorMask) { var errorResponse = MsgPackSerializer.Deserialize(resultStream, _clientOptions.MsgPackContext); From 02fd6f6dea2e11f1366fb252b6bebf970f12505b Mon Sep 17 00:00:00 2001 From: Anatoly Popov Date: Wed, 26 Oct 2016 19:34:06 +0300 Subject: [PATCH 05/16] Restore log functionality --- tarantool/tarantool.lua | 68 ++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 28 deletions(-) diff --git a/tarantool/tarantool.lua b/tarantool/tarantool.lua index 5074a79d..b97f2c0e 100644 --- a/tarantool/tarantool.lua +++ b/tarantool/tarantool.lua @@ -21,33 +21,6 @@ local function init() box.schema.user.create('operator', {password = 'operator', if_not_exists = true }) box.schema.user.grant('operator','read,write,execute','universe', { if_not_exists = true }) - - function log_connect () - local log = require('log') - local m = 'Connection. user=' .. box.session.user() .. ' id=' .. box.session.id() - log.info(m) - end - function log_disconnect () - local log = require('log') - local m = 'Disconnection. user=' .. box.session.user() .. ' id=' .. box.session.id() - log.info(m) - end - - function log_auth () - local log = require('log') - local m = 'Authentication attempt' - log.info(m) - end - function log_auth_ok (user_name) - local log = require('log') - local m = 'Authenticated user ' .. user_name - log.info(m) - end - - box.session.on_connect(log_connect) - box.session.on_disconnect(log_disconnect) - box.session.on_auth(log_auth) - box.session.on_auth(log_auth_ok) end local function space_TreeIndexMethods() @@ -59,5 +32,44 @@ local function space_TreeIndexMethods() space:auto_increment{2, 3} end +function return_null() + return require('msgpack').NULL +end + +function return_tuple() + return { 1, 2 } +end + +function return_scalar() + return 1 +end + box.once('init', init) -box.once('space_TreeIndexMethods', space_TreeIndexMethods) \ No newline at end of file +box.once('space_TreeIndexMethods', space_TreeIndexMethods) + +function log_connect () + local log = require('log') + local m = 'Connection. user=' .. box.session.user() .. ' id=' .. box.session.id() + log.info(m) +end +function log_disconnect () + local log = require('log') + local m = 'Disconnection. user=' .. box.session.user() .. ' id=' .. box.session.id() + log.info(m) +end + +function log_auth () + local log = require('log') + local m = 'Authentication attempt' + log.info(m) +end +function log_auth_ok (user_name) + local log = require('log') + local m = 'Authenticated user ' .. user_name + log.info(m) +end + +box.session.on_connect(log_connect) +box.session.on_disconnect(log_disconnect) +box.session.on_auth(log_auth) +box.session.on_auth(log_auth_ok) \ No newline at end of file From fbdd8c8ec61237263a3bc9b889929d92b628e66b Mon Sep 17 00:00:00 2001 From: Anatoly Popov Date: Wed, 26 Oct 2016 19:34:39 +0300 Subject: [PATCH 06/16] Prepare to implementing call_v17 --- src/tarantool.client/Box.cs | 11 ++- .../Model/Enums/CommandCode.cs | 3 +- .../Model/Requests/CallRequest.cs | 7 +- .../tarantool.client.tests/Box/Call_Should.cs | 40 +++++++++- .../tarantool.client.tests/Box/Eval_Should.cs | 18 ++++- tests/tarantool.client.tests/Index/Smoke.cs | 73 ++++++++--------- tests/tarantool.client.tests/Performance.cs | 35 +++++---- .../Schema/GetSpace_Should.cs | 55 +++++++------ .../Space/GetIndex_Should.cs | 48 ++++++------ tests/tarantool.client.tests/Space/Smoke.cs | 78 ++++++++++--------- .../Space/Upsert_Should.cs | 11 +-- 11 files changed, 224 insertions(+), 155 deletions(-) diff --git a/src/tarantool.client/Box.cs b/src/tarantool.client/Box.cs index 27963348..b13441a3 100644 --- a/src/tarantool.client/Box.cs +++ b/src/tarantool.client/Box.cs @@ -82,11 +82,18 @@ public Schema GetSchema() return new Schema(_logicalConnection); } - public async Task> Call(string functionName, TTuple request) + public async Task> Call_16(string functionName) + where TResponse : ITarantoolTuple + { + var callRequest = new CallRequest(functionName, new TarantoolTuple(), false); + return await _logicalConnection.SendRequest, TResponse>(callRequest); + } + + public async Task> Call_16(string functionName, TTuple request) where TTuple : ITarantoolTuple where TResponse : ITarantoolTuple { - var callRequest = new CallRequest(functionName, request); + var callRequest = new CallRequest(functionName, request, false); return await _logicalConnection.SendRequest, TResponse>(callRequest); } diff --git a/src/tarantool.client/Model/Enums/CommandCode.cs b/src/tarantool.client/Model/Enums/CommandCode.cs index da25ade5..e32b8377 100644 --- a/src/tarantool.client/Model/Enums/CommandCode.cs +++ b/src/tarantool.client/Model/Enums/CommandCode.cs @@ -8,10 +8,11 @@ public enum CommandCode : uint Replace = 0x03, Update = 0x04, Delete = 0x05, - Call = 0x06, + OldCall = 0x06, Auth = 0x07, Eval = 0x08, Upsert = 0x09, + Call = 0x0A, //Admin command codes Ping = 0x40, diff --git a/src/tarantool.client/Model/Requests/CallRequest.cs b/src/tarantool.client/Model/Requests/CallRequest.cs index 6af9eb74..6318b26a 100644 --- a/src/tarantool.client/Model/Requests/CallRequest.cs +++ b/src/tarantool.client/Model/Requests/CallRequest.cs @@ -5,8 +5,11 @@ namespace ProGaudi.Tarantool.Client.Model.Requests public class CallRequest : IRequest where T : ITarantoolTuple { - public CallRequest(string functionName, T tuple) + private readonly bool _use17; + + public CallRequest(string functionName, T tuple, bool use17 = true) { + _use17 = use17; FunctionName = functionName; Tuple = tuple; } @@ -15,6 +18,6 @@ public CallRequest(string functionName, T tuple) public T Tuple { get; } - public CommandCode Code => CommandCode.Call; + public CommandCode Code => _use17 ? CommandCode.Call : CommandCode.OldCall; } } \ No newline at end of file diff --git a/tests/tarantool.client.tests/Box/Call_Should.cs b/tests/tarantool.client.tests/Box/Call_Should.cs index e5b6049d..e2b0b153 100644 --- a/tests/tarantool.client.tests/Box/Call_Should.cs +++ b/tests/tarantool.client.tests/Box/Call_Should.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Threading; using System.Threading.Tasks; using Xunit; @@ -15,13 +16,44 @@ public class Call_Should [Fact] public async Task call_method() { - var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301"); + using (var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301")) + { + var result = await tarantoolClient.Call_16, TarantoolTuple>("math.sqrt", TarantoolTuple.Create(1.3)); - var result = await tarantoolClient.Call, TarantoolTuple>("math.sqrt", TarantoolTuple.Create(1.3)); + var diff = Math.Abs(result.Data.Single().Item1 - Math.Sqrt(1.3)); - var diff = Math.Abs(result.Data.Single().Item1 - Math.Sqrt(1.3)); + diff.ShouldBeLessThan(double.Epsilon); + } + } + + [Fact] + public async Task return_null_should_not_throw() + { + using (var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301")) + { + var result = await tarantoolClient.Call_16>("return_null"); + result.Data.ShouldBe(new TarantoolTuple[] {null}); + } + } - diff.ShouldBeLessThan(double.Epsilon); + [Fact] + public async Task return_tuple_should_not_throw() + { + using (var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301")) + { + var result = await tarantoolClient.Call_16>("return_tuple"); + result.Data.ShouldBe(new[] {TarantoolTuple.Create(1, 2)}); + } + } + + [Fact] + public async Task return_int_should_not_throw() + { + using (var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301")) + { + var result = await tarantoolClient.Call_16>("return_scalar"); + result.Data.ShouldBe(new[] { TarantoolTuple.Create(1) }); + } } } } \ No newline at end of file diff --git a/tests/tarantool.client.tests/Box/Eval_Should.cs b/tests/tarantool.client.tests/Box/Eval_Should.cs index 34efae19..f4e22cf3 100644 --- a/tests/tarantool.client.tests/Box/Eval_Should.cs +++ b/tests/tarantool.client.tests/Box/Eval_Should.cs @@ -13,11 +13,23 @@ public class Eval_Should [Fact] public async Task evaluate_expression() { - var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301"); + using (var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301")) + { + var result = await tarantoolClient.Eval, int>("return ...", TarantoolTuple.Create(1, 2, 3)); - var result = await tarantoolClient.Eval, int>("return ...", TarantoolTuple.Create(1, 2, 3)); + result.Data.ShouldBe(new[] {1, 2, 3}); + } + } + + [Fact] + public async Task evaluate_call_function() + { + using (var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301")) + { + var result = await tarantoolClient.Eval, TarantoolTuple>("return return_tuple()", TarantoolTuple.Create(1, 2, 3)); - result.Data.ShouldBe(new[] {1, 2, 3}); + result.Data.ShouldBe(new[] { TarantoolTuple.Create(1, 2) }); + } } } } \ No newline at end of file diff --git a/tests/tarantool.client.tests/Index/Smoke.cs b/tests/tarantool.client.tests/Index/Smoke.cs index 9f41d1c4..953fbb38 100644 --- a/tests/tarantool.client.tests/Index/Smoke.cs +++ b/tests/tarantool.client.tests/Index/Smoke.cs @@ -4,7 +4,6 @@ using Xunit; using ProGaudi.Tarantool.Client.Model; -using ProGaudi.Tarantool.Client.Model.Responses; using ProGaudi.Tarantool.Client.Model.UpdateOperations; using Shouldly; @@ -16,57 +15,59 @@ public class Smoke public async Task HashIndexMethods() { const string spaceName = "primary_only_index"; - var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301"); - - var schema = tarantoolClient.GetSchema(); + using (var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301")) + { + var schema = tarantoolClient.GetSchema(); - var space = await schema.GetSpace(spaceName); + var space = await schema.GetSpace(spaceName); - var index = await space.GetIndex("primary"); + var index = await space.GetIndex("primary"); - try - { - await index.Insert(TarantoolTuple.Create(2, "Music")); - } - catch (ArgumentException) - { - await index.Delete, TarantoolTuple>(TarantoolTuple.Create(2)); - await index.Insert(TarantoolTuple.Create(2, "Music")); - } + try + { + await index.Insert(TarantoolTuple.Create(2, "Music")); + } + catch (ArgumentException) + { + await index.Delete, TarantoolTuple>(TarantoolTuple.Create(2)); + await index.Insert(TarantoolTuple.Create(2, "Music")); + } - await index.Select, TarantoolTuple>(TarantoolTuple.Create(1029u)); - await index.Replace(TarantoolTuple.Create(2, "Car", -245.3)); - await index.Update, TarantoolTuple>( - TarantoolTuple.Create(2), - new UpdateOperation[] { UpdateOperation.CreateAddition(100, 2) }); + await index.Select, TarantoolTuple>(TarantoolTuple.Create(1029u)); + await index.Replace(TarantoolTuple.Create(2, "Car", -245.3)); + await index.Update, TarantoolTuple>( + TarantoolTuple.Create(2), + new UpdateOperation[] {UpdateOperation.CreateAddition(100, 2)}); - await index.Upsert(TarantoolTuple.Create(5u), new UpdateOperation[] { UpdateOperation.CreateAssign(2, 2) }); - await index.Upsert(TarantoolTuple.Create(5u), new UpdateOperation[] { UpdateOperation.CreateAddition(-2, 2) }); + await index.Upsert(TarantoolTuple.Create(5u), new UpdateOperation[] {UpdateOperation.CreateAssign(2, 2)}); + await index.Upsert(TarantoolTuple.Create(5u), new UpdateOperation[] {UpdateOperation.CreateAddition(-2, 2)}); - await index.Select, TarantoolTuple>(TarantoolTuple.Create(5u)); + await index.Select, TarantoolTuple>(TarantoolTuple.Create(5u)); + } } [Fact] public async Task TreeIndexMethods() { const string spaceName = "space_TreeIndexMethods"; - var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301"); - - var schema = tarantoolClient.GetSchema(); + using (var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301")) + { + var schema = tarantoolClient.GetSchema(); - var space = await schema.GetSpace(spaceName); + var space = await schema.GetSpace(spaceName); - var index = await space.GetIndex("treeIndex"); + var index = await space.GetIndex("treeIndex"); - var min2 = await index.Min, TarantoolTuple>(TarantoolTuple.Create(3)); - min2.ShouldBe(TarantoolTuple.Create(3, 2, 3)); - var min = await index.Min>(); - min.ShouldBe(TarantoolTuple.Create(1, "asdf", 10.1)); + var min2 = await index.Min, TarantoolTuple>(TarantoolTuple.Create(3)); + min2.ShouldBe(TarantoolTuple.Create(3, 2, 3)); + var min = await index.Min>(); + min.ShouldBe(TarantoolTuple.Create(1, "asdf", 10.1)); - var max = await index.Max>(); - max.ShouldBe(min2); - var max2 = await index.Max, TarantoolTuple>(TarantoolTuple.Create(1)); - max2.ShouldBe(min); + var max = await index.Max>(); + max.ShouldBe(min2); + var max2 = await index.Max, TarantoolTuple>(TarantoolTuple.Create(1)); + max2.ShouldBe(min); + } } } } \ No newline at end of file diff --git a/tests/tarantool.client.tests/Performance.cs b/tests/tarantool.client.tests/Performance.cs index accf58f1..0be23e28 100644 --- a/tests/tarantool.client.tests/Performance.cs +++ b/tests/tarantool.client.tests/Performance.cs @@ -17,31 +17,32 @@ public void MultithreadTest() var threadsCount = 100; const string spaceName = "performance"; - var tarantoolClient = new Client.Box(new ClientOptions("127.0.0.1:3301", logWriter)); - - tarantoolClient.Connect().GetAwaiter().GetResult(); + using (var tarantoolClient = new Client.Box(new ClientOptions("127.0.0.1:3301", logWriter))) + { + tarantoolClient.Connect().GetAwaiter().GetResult(); - var schema = tarantoolClient.GetSchema(); + var schema = tarantoolClient.GetSchema(); - var space = schema.GetSpace(spaceName).GetAwaiter().GetResult(); + var space = schema.GetSpace(spaceName).GetAwaiter().GetResult(); - var index = space.GetIndex("primary").GetAwaiter().GetResult(); - var startTime = DateTime.Now; + var index = space.GetIndex("primary").GetAwaiter().GetResult(); + var startTime = DateTime.Now; - logWriter.WriteLine("Before start thread"); + logWriter.WriteLine("Before start thread"); - var tasks = new Task[threadsCount]; - for (uint i = 0; i < threadsCount; i++) - { - var client = new TestClient(index, i); - tasks[i] = Task.Factory.StartNew(client.Start); - } + var tasks = new Task[threadsCount]; + for (uint i = 0; i < threadsCount; i++) + { + var client = new TestClient(index, i); + tasks[i] = Task.Factory.StartNew(client.Start); + } - Task.WaitAll(tasks); + Task.WaitAll(tasks); - var endTime = DateTime.Now; + var endTime = DateTime.Now; - logWriter.WriteLine($"Time taken:{(endTime - startTime).TotalMilliseconds} ms"); + logWriter.WriteLine($"Time taken:{(endTime - startTime).TotalMilliseconds} ms"); + } } } diff --git a/tests/tarantool.client.tests/Schema/GetSpace_Should.cs b/tests/tarantool.client.tests/Schema/GetSpace_Should.cs index 77b83644..b2b497f7 100644 --- a/tests/tarantool.client.tests/Schema/GetSpace_Should.cs +++ b/tests/tarantool.client.tests/Schema/GetSpace_Should.cs @@ -12,62 +12,67 @@ public class GetSpace_Should [Fact] public async Task throw_expection_for_non_existing_space_by_name() { - var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301"); - - var schema = tarantoolClient.GetSchema(); + using (var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301")) + { + var schema = tarantoolClient.GetSchema(); - await schema.GetSpace("non-existing").ShouldThrowAsync(); + await schema.GetSpace("non-existing").ShouldThrowAsync(); + } } [Fact] public async Task throw_expection_for_non_existing_space_by_id() { - var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301"); - - var schema = tarantoolClient.GetSchema(); + using (var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301")) + { + var schema = tarantoolClient.GetSchema(); - await schema.GetSpace(12341234).ShouldThrowAsync(); + await schema.GetSpace(12341234).ShouldThrowAsync(); + } } [Fact] public async Task returns_space_by_id() { const uint VSpaceId = 0x119; // that space always exist and contains other spaces. - var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301"); - - var schema = tarantoolClient.GetSchema(); + using (var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301")) + { + var schema = tarantoolClient.GetSchema(); - var space = await schema.GetSpace(VSpaceId); + var space = await schema.GetSpace(VSpaceId); - space.Id.ShouldBe(VSpaceId); + space.Id.ShouldBe(VSpaceId); + } } [Fact] public async Task returns_space_by_name() { const string VSpaceName = "_vspace"; // that space always exist and contains other spaces. - var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301"); - - var schema = tarantoolClient.GetSchema(); + using (var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301")) + { + var schema = tarantoolClient.GetSchema(); - var space = await schema.GetSpace(VSpaceName); + var space = await schema.GetSpace(VSpaceName); - space.Name.ShouldBe(VSpaceName); + space.Name.ShouldBe(VSpaceName); + } } [Fact] public async Task read_multiple_spaces_in_a_row() { const string VSpaceName = "_vspace"; // that space always exist and contains other spaces. - var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301"); - - var schema = tarantoolClient.GetSchema(); - - for (int i = 0; i < 10; i++) + using (var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301")) { - var space = await schema.GetSpace(VSpaceName); + var schema = tarantoolClient.GetSchema(); - space.Name.ShouldBe(VSpaceName); + for (int i = 0; i < 10; i++) + { + var space = await schema.GetSpace(VSpaceName); + + space.Name.ShouldBe(VSpaceName); + } } } } diff --git a/tests/tarantool.client.tests/Space/GetIndex_Should.cs b/tests/tarantool.client.tests/Space/GetIndex_Should.cs index 017fe2e2..c3733427 100644 --- a/tests/tarantool.client.tests/Space/GetIndex_Should.cs +++ b/tests/tarantool.client.tests/Space/GetIndex_Should.cs @@ -13,26 +13,28 @@ public class GetIndex_Should public async Task throw_expection_for_non_existing_space_by_name() { const string VSpaceName = "_vspace"; // that space always exist and contains other spaces. - var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301"); + using (var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301")) + { + var schema = tarantoolClient.GetSchema(); - var schema = tarantoolClient.GetSchema(); + var space = await schema.GetSpace(VSpaceName); - var space = await schema.GetSpace(VSpaceName); - - await space.GetIndex("non-existing").ShouldThrowAsync(); + await space.GetIndex("non-existing").ShouldThrowAsync(); + } } [Fact] public async Task throw_expection_for_non_existing_space_by_id() { const string VSpaceName = "_vspace"; // that space always exist and contains other spaces. - var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301"); - - var schema = tarantoolClient.GetSchema(); + using (var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301")) + { + var schema = tarantoolClient.GetSchema(); - var space = await schema.GetSpace(VSpaceName); + var space = await schema.GetSpace(VSpaceName); - await space.GetIndex(12341234).ShouldThrowAsync(); + await space.GetIndex(12341234).ShouldThrowAsync(); + } } [Fact] @@ -40,15 +42,16 @@ public async Task returns_space_by_id() { const string VSpaceName = "_vspace"; // that space always exist and contains other spaces. const uint indexId = 2; - var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301"); + using (var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301")) + { + var schema = tarantoolClient.GetSchema(); - var schema = tarantoolClient.GetSchema(); + var space = await schema.GetSpace(VSpaceName); - var space = await schema.GetSpace(VSpaceName); + var index = await space.GetIndex(indexId); - var index = await space.GetIndex(indexId); - - index.Id.ShouldBe(indexId); + index.Id.ShouldBe(indexId); + } } [Fact] @@ -56,15 +59,16 @@ public async Task returns_space_by_name() { const string VSpaceName = "_vspace"; // that space always exist and contains other spaces. const string indexName = "owner"; - var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301"); - - var schema = tarantoolClient.GetSchema(); + using (var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301")) + { + var schema = tarantoolClient.GetSchema(); - var space = await schema.GetSpace(VSpaceName); + var space = await schema.GetSpace(VSpaceName); - var index = await space.GetIndex(indexName); + var index = await space.GetIndex(indexName); - index.Name.ShouldBe(indexName); + index.Name.ShouldBe(indexName); + } } } } \ No newline at end of file diff --git a/tests/tarantool.client.tests/Space/Smoke.cs b/tests/tarantool.client.tests/Space/Smoke.cs index c6860446..26b5155e 100644 --- a/tests/tarantool.client.tests/Space/Smoke.cs +++ b/tests/tarantool.client.tests/Space/Smoke.cs @@ -17,30 +17,31 @@ public class Smoke public async Task Test() { const string spaceName = "primary_only_index"; - var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301"); - - var schema = tarantoolClient.GetSchema(); - - var space = await schema.GetSpace(spaceName); - - try + using (var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301")) { - await space.Insert(TarantoolTuple.Create(2, "Music")); + var schema = tarantoolClient.GetSchema(); + + var space = await schema.GetSpace(spaceName); + + try + { + await space.Insert(TarantoolTuple.Create(2, "Music")); + } + catch (ArgumentException) + { + await space.Delete, TarantoolTuple>(TarantoolTuple.Create(2u)); + await space.Insert(TarantoolTuple.Create(2, "Music")); + } + + await space.Select, TarantoolTuple>(TarantoolTuple.Create(2u)); + await space.Replace(TarantoolTuple.Create(2, "Car", -24.5)); + await space.Update, TarantoolTuple>( + TarantoolTuple.Create(2u), + new UpdateOperation[] {UpdateOperation.CreateAddition(1, 2)}); + await space.Upsert( + TarantoolTuple.Create(5u, 20), + new UpdateOperation[] {UpdateOperation.CreateAssign(1, 1)}); } - catch (ArgumentException) - { - await space.Delete, TarantoolTuple>(TarantoolTuple.Create(2u)); - await space.Insert(TarantoolTuple.Create(2, "Music")); - } - - await space.Select, TarantoolTuple>(TarantoolTuple.Create(2u)); - await space.Replace(TarantoolTuple.Create(2, "Car", -24.5)); - await space.Update, TarantoolTuple>( - TarantoolTuple.Create(2u), - new UpdateOperation[] { UpdateOperation.CreateAddition(1, 2) }); - await space.Upsert( - TarantoolTuple.Create(5u, 20), - new UpdateOperation[] { UpdateOperation.CreateAssign(1, 1) }); } @@ -49,27 +50,28 @@ public async Task LongTest() { const string spaceName = "primary_only_index"; - var tarantoolClient = new Client.Box(new ClientOptions("127.0.0.1:3301", new StringWriterLog())); + using (var tarantoolClient = new Client.Box(new ClientOptions("127.0.0.1:3301", new StringWriterLog()))) + { + await tarantoolClient.Connect(); - await tarantoolClient.Connect(); + var schema = tarantoolClient.GetSchema(); - var schema = tarantoolClient.GetSchema(); + var space = await schema.GetSpace(spaceName); - var space = await schema.GetSpace(spaceName); + var longString = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec condimentum pharetra porta. Aliquam ullamcorper ex quis mi aliquet egestas. Suspendisse dui nunc, tincidunt mattis purus ac, fringilla porttitor turpis. Nunc nunc turpis, accumsan eu mi et, scelerisque ultrices orci. Maecenas sed ornare risus. Nam ut luctus ante, id tincidunt diam. Vestibulum maximus non quam molestie rutrum. Phasellus faucibus nunc eu sapien posuere, sed imperdiet quam sollicitudin. Donec nec dui ullamcorper, tincidunt sem eget, egestas lorem. Proin egestas, sem a malesuada sodales, risus sapien aliquet leo, non commodo sem ante et tellus. Donec vel ex et elit pellentesque iaculis faucibus vel lacus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Etiam fermentum dui at ligula luctus faucibus. Nunc congue placerat dignissim. Quisque odio ipsum, viverra id faucibus sed, pellentesque id velit. Etiam a nibh non lorem vulputate volutpat.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec condimentum pharetra porta. Aliquam ullamcorper ex quis mi aliquet egestas. Suspendisse dui nunc, tincidunt mattis purus ac, fringilla porttitor turpis. Nunc nunc turpis, accumsan eu mi et, scelerisque ultrices orci. Maecenas sed ornare risus. Nam ut luctus ante, id tincidunt diam. Vestibulum maximus non quam molestie rutrum. Phasellus faucibus nunc eu sapien posuere, sed imperdiet quam sollicitudin. Donec nec dui ullamcorper, tincidunt sem eget, egestas lorem. Proin egestas, sem a malesuada sodales, risus sapien aliquet leo, non commodo sem ante et tellus. Donec vel ex et elit pellentesque iaculis faucibus vel lacus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Etiam fermentum dui at ligula luctus faucibus. Nunc congue placerat dignissim. Quisque odio ipsum, viverra id faucibus sed, pellentesque id velit. Etiam a nibh non lorem vulputate volutpat.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec condimentum pharetra porta. Aliquam ullamcorper ex quis mi aliquet egestas. Suspendisse dui nunc, tincidunt mattis purus ac, fringilla porttitor turpis. Nunc nunc turpis, accumsan eu mi et, scelerisque ultrices orci. Maecenas sed ornare risus. Nam ut luctus ante, id tincidunt diam. Vestibulum maximus non quam molestie rutrum. Phasellus faucibus nunc eu sapien posuere, sed imperdiet quam sollicitudin. Donec nec dui ullamcorper, tincidunt sem eget, egestas lorem. Proin egestas, sem a malesuada sodales, risus sapien aliquet leo, non commodo sem ante et tellus. Donec vel ex et elit pellentesque iaculis faucibus vel lacus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Etiam fermentum dui at ligula luctus faucibus. Nunc congue placerat dignissim. Quisque odio ipsum, viverra id faucibus sed, pellentesque id velit. Etiam a nibh non lorem vulputate volutpat.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec condimentum pharetra porta. Aliquam ullamcorper ex quis mi aliquet egestas. Suspendisse dui nunc, tincidunt mattis purus ac, fringilla porttitor turpis. Nunc nunc turpis, accumsan eu mi et, scelerisque ultrices orci. Maecenas sed ornare risus. Nam ut luctus ante, id tincidunt diam. Vestibulum maximus non quam molestie rutrum. Phasellus faucibus nunc eu sapien posuere, sed imperdiet quam sollicitudin. Donec nec dui ullamcorper, tincidunt sem eget, egestas lorem. Proin egestas, sem a malesuada sodales, risus sapien aliquet leo, non commodo sem ante et tellus. Donec vel ex et elit pellentesque iaculis faucibus vel lacus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Etiam fermentum dui at ligula luctus faucibus. Nunc congue placerat dignissim. Quisque odio ipsum, viverra id faucibus sed, pellentesque id velit. Etiam a nibh non lorem vulputate volutpat.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec condimentum pharetra porta. Aliquam ullamcorper ex quis mi aliquet egestas. Suspendisse dui nunc, tincidunt mattis purus ac, fringilla porttitor turpis. Nunc nunc turpis, accumsan eu mi et, scelerisque ultrices orci. Maecenas sed ornare risus. Nam ut luctus ante, id tincidunt diam. Vestibulum maximus non quam molestie rutrum. Phasellus faucibus nunc eu sapien posuere, sed imperdiet quam sollicitudin. Donec nec dui ullamcorper, tincidunt sem eget, egestas lorem. Proin egestas, sem a malesuada sodales, risus sapien aliquet leo, non commodo sem ante et tellus. Donec vel ex et elit pellentesque iaculis faucibus vel lacus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Etiam fermentum dui at ligula luctus faucibus. Nunc congue placerat dignissim. Quisque odio ipsum, viverra id faucibus sed, pellentesque id velit. Etiam a nibh non lorem vulputate volutpat.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec condimentum pharetra porta. Aliquam ullamcorper ex quis mi aliquet egestas. Suspendisse dui nunc, tincidunt mattis purus ac, fringilla porttitor turpis. Nunc nunc turpis, accumsan eu mi et, scelerisque ultrices orci. Maecenas sed ornare risus. Nam ut luctus ante, id tincidunt diam. Vestibulum maximus non quam molestie rutrum. Phasellus faucibus nunc eu sapien posuere, sed imperdiet quam sollicitudin. Donec nec dui ullamcorper, tincidunt sem eget, egestas lorem. Proin egestas, sem a malesuada sodales, risus sapien aliquet leo, non commodo sem ante et tellus. Donec vel ex et elit pellentesque iaculis faucibus vel lacus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Etiam fermentum dui at ligula luctus faucibus. Nunc congue placerat dignissim. Quisque odio ipsum, viverra id faucibus sed, pellentesque id velit. Etiam a nibh non lorem vulputate volutpat.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec condimentum pharetra porta. Aliquam ullamcorper ex quis mi aliquet egestas. Suspendisse dui nunc, tincidunt mattis purus ac, fringilla porttitor turpis. Nunc nunc turpis, accumsan eu mi et, scelerisque ultrices orci. Maecenas sed ornare risus. Nam ut luctus ante, id tincidunt diam. Vestibulum maximus non quam molestie rutrum. Phasellus faucibus nunc eu sapien posuere, sed imperdiet quam sollicitudin. Donec nec dui ullamcorper, tincidunt sem eget, egestas lorem. Proin egestas, sem a malesuada sodales, risus sapien aliquet leo, non commodo sem ante et tellus. Donec vel ex et elit pellentesque iaculis faucibus vel lacus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Etiam fermentum dui at ligula luctus faucibus. Nunc congue placerat dignissim. Quisque odio ipsum, viverra id faucibus sed, pellentesque id velit. Etiam a nibh non lorem vulputate volutpat."; + try + { + await space.Insert(TarantoolTuple.Create(222u, longString)); + } + catch (ArgumentException) + { + await space.Delete, TarantoolTuple>(TarantoolTuple.Create(222u)); + await space.Insert(TarantoolTuple.Create(222u, longString)); + } - var longString = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec condimentum pharetra porta. Aliquam ullamcorper ex quis mi aliquet egestas. Suspendisse dui nunc, tincidunt mattis purus ac, fringilla porttitor turpis. Nunc nunc turpis, accumsan eu mi et, scelerisque ultrices orci. Maecenas sed ornare risus. Nam ut luctus ante, id tincidunt diam. Vestibulum maximus non quam molestie rutrum. Phasellus faucibus nunc eu sapien posuere, sed imperdiet quam sollicitudin. Donec nec dui ullamcorper, tincidunt sem eget, egestas lorem. Proin egestas, sem a malesuada sodales, risus sapien aliquet leo, non commodo sem ante et tellus. Donec vel ex et elit pellentesque iaculis faucibus vel lacus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Etiam fermentum dui at ligula luctus faucibus. Nunc congue placerat dignissim. Quisque odio ipsum, viverra id faucibus sed, pellentesque id velit. Etiam a nibh non lorem vulputate volutpat.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec condimentum pharetra porta. Aliquam ullamcorper ex quis mi aliquet egestas. Suspendisse dui nunc, tincidunt mattis purus ac, fringilla porttitor turpis. Nunc nunc turpis, accumsan eu mi et, scelerisque ultrices orci. Maecenas sed ornare risus. Nam ut luctus ante, id tincidunt diam. Vestibulum maximus non quam molestie rutrum. Phasellus faucibus nunc eu sapien posuere, sed imperdiet quam sollicitudin. Donec nec dui ullamcorper, tincidunt sem eget, egestas lorem. Proin egestas, sem a malesuada sodales, risus sapien aliquet leo, non commodo sem ante et tellus. Donec vel ex et elit pellentesque iaculis faucibus vel lacus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Etiam fermentum dui at ligula luctus faucibus. Nunc congue placerat dignissim. Quisque odio ipsum, viverra id faucibus sed, pellentesque id velit. Etiam a nibh non lorem vulputate volutpat.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec condimentum pharetra porta. Aliquam ullamcorper ex quis mi aliquet egestas. Suspendisse dui nunc, tincidunt mattis purus ac, fringilla porttitor turpis. Nunc nunc turpis, accumsan eu mi et, scelerisque ultrices orci. Maecenas sed ornare risus. Nam ut luctus ante, id tincidunt diam. Vestibulum maximus non quam molestie rutrum. Phasellus faucibus nunc eu sapien posuere, sed imperdiet quam sollicitudin. Donec nec dui ullamcorper, tincidunt sem eget, egestas lorem. Proin egestas, sem a malesuada sodales, risus sapien aliquet leo, non commodo sem ante et tellus. Donec vel ex et elit pellentesque iaculis faucibus vel lacus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Etiam fermentum dui at ligula luctus faucibus. Nunc congue placerat dignissim. Quisque odio ipsum, viverra id faucibus sed, pellentesque id velit. Etiam a nibh non lorem vulputate volutpat.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec condimentum pharetra porta. Aliquam ullamcorper ex quis mi aliquet egestas. Suspendisse dui nunc, tincidunt mattis purus ac, fringilla porttitor turpis. Nunc nunc turpis, accumsan eu mi et, scelerisque ultrices orci. Maecenas sed ornare risus. Nam ut luctus ante, id tincidunt diam. Vestibulum maximus non quam molestie rutrum. Phasellus faucibus nunc eu sapien posuere, sed imperdiet quam sollicitudin. Donec nec dui ullamcorper, tincidunt sem eget, egestas lorem. Proin egestas, sem a malesuada sodales, risus sapien aliquet leo, non commodo sem ante et tellus. Donec vel ex et elit pellentesque iaculis faucibus vel lacus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Etiam fermentum dui at ligula luctus faucibus. Nunc congue placerat dignissim. Quisque odio ipsum, viverra id faucibus sed, pellentesque id velit. Etiam a nibh non lorem vulputate volutpat.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec condimentum pharetra porta. Aliquam ullamcorper ex quis mi aliquet egestas. Suspendisse dui nunc, tincidunt mattis purus ac, fringilla porttitor turpis. Nunc nunc turpis, accumsan eu mi et, scelerisque ultrices orci. Maecenas sed ornare risus. Nam ut luctus ante, id tincidunt diam. Vestibulum maximus non quam molestie rutrum. Phasellus faucibus nunc eu sapien posuere, sed imperdiet quam sollicitudin. Donec nec dui ullamcorper, tincidunt sem eget, egestas lorem. Proin egestas, sem a malesuada sodales, risus sapien aliquet leo, non commodo sem ante et tellus. Donec vel ex et elit pellentesque iaculis faucibus vel lacus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Etiam fermentum dui at ligula luctus faucibus. Nunc congue placerat dignissim. Quisque odio ipsum, viverra id faucibus sed, pellentesque id velit. Etiam a nibh non lorem vulputate volutpat.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec condimentum pharetra porta. Aliquam ullamcorper ex quis mi aliquet egestas. Suspendisse dui nunc, tincidunt mattis purus ac, fringilla porttitor turpis. Nunc nunc turpis, accumsan eu mi et, scelerisque ultrices orci. Maecenas sed ornare risus. Nam ut luctus ante, id tincidunt diam. Vestibulum maximus non quam molestie rutrum. Phasellus faucibus nunc eu sapien posuere, sed imperdiet quam sollicitudin. Donec nec dui ullamcorper, tincidunt sem eget, egestas lorem. Proin egestas, sem a malesuada sodales, risus sapien aliquet leo, non commodo sem ante et tellus. Donec vel ex et elit pellentesque iaculis faucibus vel lacus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Etiam fermentum dui at ligula luctus faucibus. Nunc congue placerat dignissim. Quisque odio ipsum, viverra id faucibus sed, pellentesque id velit. Etiam a nibh non lorem vulputate volutpat.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec condimentum pharetra porta. Aliquam ullamcorper ex quis mi aliquet egestas. Suspendisse dui nunc, tincidunt mattis purus ac, fringilla porttitor turpis. Nunc nunc turpis, accumsan eu mi et, scelerisque ultrices orci. Maecenas sed ornare risus. Nam ut luctus ante, id tincidunt diam. Vestibulum maximus non quam molestie rutrum. Phasellus faucibus nunc eu sapien posuere, sed imperdiet quam sollicitudin. Donec nec dui ullamcorper, tincidunt sem eget, egestas lorem. Proin egestas, sem a malesuada sodales, risus sapien aliquet leo, non commodo sem ante et tellus. Donec vel ex et elit pellentesque iaculis faucibus vel lacus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Etiam fermentum dui at ligula luctus faucibus. Nunc congue placerat dignissim. Quisque odio ipsum, viverra id faucibus sed, pellentesque id velit. Etiam a nibh non lorem vulputate volutpat."; - try - { - await space.Insert(TarantoolTuple.Create(222u, longString)); + var selectResponse = await space.Select, TarantoolTuple>(TarantoolTuple.Create(222u)); + selectResponse.Data.Single().Item2.ShouldBe(longString); } - catch (ArgumentException) - { - await space.Delete, TarantoolTuple>(TarantoolTuple.Create(222u)); - await space.Insert(TarantoolTuple.Create(222u, longString)); - } - - var selectResponse = await space.Select, TarantoolTuple>(TarantoolTuple.Create(222u)); - selectResponse.Data.Single().Item2.ShouldBe(longString); } } } \ No newline at end of file diff --git a/tests/tarantool.client.tests/Space/Upsert_Should.cs b/tests/tarantool.client.tests/Space/Upsert_Should.cs index 88403a4d..8ff94fe8 100644 --- a/tests/tarantool.client.tests/Space/Upsert_Should.cs +++ b/tests/tarantool.client.tests/Space/Upsert_Should.cs @@ -16,13 +16,14 @@ public class Upsert_Should public async Task throw_expection_on_space_with_secondary_index() { const string spaceName = "primary_and_secondary_index"; - var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301"); + using (var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301")) + { + var schema = tarantoolClient.GetSchema(); - var schema = tarantoolClient.GetSchema(); + var space = await schema.GetSpace(spaceName); - var space = await schema.GetSpace(spaceName); - - await space.Upsert(TarantoolTuple.Create(5), new UpdateOperation[] { UpdateOperation.CreateAddition(1, 2) }).ShouldThrowAsync(); + await space.Upsert(TarantoolTuple.Create(5), new UpdateOperation[] {UpdateOperation.CreateAddition(1, 2)}).ShouldThrowAsync(); + } } } } \ No newline at end of file From 1b2d3a0c5929e8191d6f8ece5e1291fa219867dc Mon Sep 17 00:00:00 2001 From: Anatoly Popov Date: Wed, 26 Oct 2016 20:25:10 +0300 Subject: [PATCH 07/16] Add ToString to Tuples. Closes #59 --- .../21fcbb60-2d73-4a67-b07c-dedd7cfe2799.tt | 14 +- .../Model/{Tuple.cs => TarantoolTuple.cs} | 225 ++++++++++-------- 2 files changed, 138 insertions(+), 101 deletions(-) rename src/tarantool.client/Model/{Tuple.cs => TarantoolTuple.cs} (65%) diff --git a/_T4Awesome/CodeItems/31c71f1f-2480-4de2-98a0-97a1c9b23c49/21fcbb60-2d73-4a67-b07c-dedd7cfe2799.tt b/_T4Awesome/CodeItems/31c71f1f-2480-4de2-98a0-97a1c9b23c49/21fcbb60-2d73-4a67-b07c-dedd7cfe2799.tt index 94f56b50..12beddc7 100644 --- a/_T4Awesome/CodeItems/31c71f1f-2480-4de2-98a0-97a1c9b23c49/21fcbb60-2d73-4a67-b07c-dedd7cfe2799.tt +++ b/_T4Awesome/CodeItems/31c71f1f-2480-4de2-98a0-97a1c9b23c49/21fcbb60-2d73-4a67-b07c-dedd7cfe2799.tt @@ -1,4 +1,4 @@ -public interface ITuple{} +public interface ITarantoolTuple{} <# var maxParametersCount = 8; var typeParameters = new Func(count => string.Join(", ", Enumerable.Range(1, count).Select(num => $"T{num}"))); @@ -38,6 +38,18 @@ for(int i=0;i < maxParametersCount; i++){ return hashCode; } } + + public override string ToString() + { + return $"<# for(int j=0; j< i+1; j++) + { + if (j != 0) + { + #>, <# + } + #>{Item<#=j+1#>}<# + } #>"; + } } <# } diff --git a/src/tarantool.client/Model/Tuple.cs b/src/tarantool.client/Model/TarantoolTuple.cs similarity index 65% rename from src/tarantool.client/Model/Tuple.cs rename to src/tarantool.client/Model/TarantoolTuple.cs index 30f9a047..da1f9262 100644 --- a/src/tarantool.client/Model/Tuple.cs +++ b/src/tarantool.client/Model/TarantoolTuple.cs @@ -10,6 +10,7 @@ public class TarantoolTuple : ITarantoolTuple { public TarantoolTuple(T1 item1) { + Item1 = item1; } @@ -30,8 +31,16 @@ public override bool Equals(object obj) public override int GetHashCode() { - var hashCode = EqualityComparer.Default.GetHashCode(Item1); - return hashCode; + unchecked + { + var hashCode = EqualityComparer.Default.GetHashCode(Item1); + return hashCode; + } + } + + public override string ToString() + { + return $"{Item1}"; } } @@ -39,17 +48,18 @@ public class TarantoolTuple : ITarantoolTuple { public TarantoolTuple(T1 item1, T2 item2) { + Item1 = item1; Item2 = item2; } public T1 Item1 { get; } - public T2 Item2 { get; } protected bool Equals(TarantoolTuple other) { - return EqualityComparer.Default.Equals(Item1, other.Item1) && EqualityComparer.Default.Equals(Item2, other.Item2); + return EqualityComparer.Default.Equals(Item1, other.Item1) && + EqualityComparer.Default.Equals(Item2, other.Item2); } public override bool Equals(object obj) @@ -65,31 +75,36 @@ public override int GetHashCode() unchecked { var hashCode = EqualityComparer.Default.GetHashCode(Item1); - hashCode = (hashCode * 397) ^ EqualityComparer.Default.GetHashCode(Item2); + hashCode = (hashCode*397) ^ EqualityComparer.Default.GetHashCode(Item2); return hashCode; } } + + public override string ToString() + { + return $"{Item1}, {Item2}"; + } } public class TarantoolTuple : ITarantoolTuple { public TarantoolTuple(T1 item1, T2 item2, T3 item3) { + Item1 = item1; Item2 = item2; Item3 = item3; } public T1 Item1 { get; } - public T2 Item2 { get; } - public T3 Item3 { get; } protected bool Equals(TarantoolTuple other) { - return EqualityComparer.Default.Equals(Item1, other.Item1) && EqualityComparer.Default.Equals(Item2, other.Item2) - && EqualityComparer.Default.Equals(Item3, other.Item3); + return EqualityComparer.Default.Equals(Item1, other.Item1) && + EqualityComparer.Default.Equals(Item2, other.Item2) && + EqualityComparer.Default.Equals(Item3, other.Item3); } public override bool Equals(object obj) @@ -105,17 +120,23 @@ public override int GetHashCode() unchecked { var hashCode = EqualityComparer.Default.GetHashCode(Item1); - hashCode = (hashCode * 397) ^ EqualityComparer.Default.GetHashCode(Item2); - hashCode = (hashCode * 397) ^ EqualityComparer.Default.GetHashCode(Item3); + hashCode = (hashCode*397) ^ EqualityComparer.Default.GetHashCode(Item2); + hashCode = (hashCode*397) ^ EqualityComparer.Default.GetHashCode(Item3); return hashCode; } } + + public override string ToString() + { + return $"{Item1}, {Item2}, {Item3}"; + } } public class TarantoolTuple : ITarantoolTuple { public TarantoolTuple(T1 item1, T2 item2, T3 item3, T4 item4) { + Item1 = item1; Item2 = item2; Item3 = item3; @@ -123,17 +144,16 @@ public TarantoolTuple(T1 item1, T2 item2, T3 item3, T4 item4) } public T1 Item1 { get; } - public T2 Item2 { get; } - public T3 Item3 { get; } - public T4 Item4 { get; } protected bool Equals(TarantoolTuple other) { - return EqualityComparer.Default.Equals(Item1, other.Item1) && EqualityComparer.Default.Equals(Item2, other.Item2) - && EqualityComparer.Default.Equals(Item3, other.Item3) && EqualityComparer.Default.Equals(Item4, other.Item4); + return EqualityComparer.Default.Equals(Item1, other.Item1) && + EqualityComparer.Default.Equals(Item2, other.Item2) && + EqualityComparer.Default.Equals(Item3, other.Item3) && + EqualityComparer.Default.Equals(Item4, other.Item4); } public override bool Equals(object obj) @@ -149,18 +169,24 @@ public override int GetHashCode() unchecked { var hashCode = EqualityComparer.Default.GetHashCode(Item1); - hashCode = (hashCode * 397) ^ EqualityComparer.Default.GetHashCode(Item2); - hashCode = (hashCode * 397) ^ EqualityComparer.Default.GetHashCode(Item3); - hashCode = (hashCode * 397) ^ EqualityComparer.Default.GetHashCode(Item4); + hashCode = (hashCode*397) ^ EqualityComparer.Default.GetHashCode(Item2); + hashCode = (hashCode*397) ^ EqualityComparer.Default.GetHashCode(Item3); + hashCode = (hashCode*397) ^ EqualityComparer.Default.GetHashCode(Item4); return hashCode; } } + + public override string ToString() + { + return $"{Item1}, {Item2}, {Item3}, {Item4}"; + } } public class TarantoolTuple : ITarantoolTuple { public TarantoolTuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5) { + Item1 = item1; Item2 = item2; Item3 = item3; @@ -169,20 +195,18 @@ public TarantoolTuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5) } public T1 Item1 { get; } - public T2 Item2 { get; } - public T3 Item3 { get; } - public T4 Item4 { get; } - public T5 Item5 { get; } protected bool Equals(TarantoolTuple other) { - return EqualityComparer.Default.Equals(Item1, other.Item1) && EqualityComparer.Default.Equals(Item2, other.Item2) - && EqualityComparer.Default.Equals(Item3, other.Item3) && EqualityComparer.Default.Equals(Item4, other.Item4) - && EqualityComparer.Default.Equals(Item5, other.Item5); + return EqualityComparer.Default.Equals(Item1, other.Item1) && + EqualityComparer.Default.Equals(Item2, other.Item2) && + EqualityComparer.Default.Equals(Item3, other.Item3) && + EqualityComparer.Default.Equals(Item4, other.Item4) && + EqualityComparer.Default.Equals(Item5, other.Item5); } public override bool Equals(object obj) @@ -198,19 +222,25 @@ public override int GetHashCode() unchecked { var hashCode = EqualityComparer.Default.GetHashCode(Item1); - hashCode = (hashCode * 397) ^ EqualityComparer.Default.GetHashCode(Item2); - hashCode = (hashCode * 397) ^ EqualityComparer.Default.GetHashCode(Item3); - hashCode = (hashCode * 397) ^ EqualityComparer.Default.GetHashCode(Item4); - hashCode = (hashCode * 397) ^ EqualityComparer.Default.GetHashCode(Item5); + hashCode = (hashCode*397) ^ EqualityComparer.Default.GetHashCode(Item2); + hashCode = (hashCode*397) ^ EqualityComparer.Default.GetHashCode(Item3); + hashCode = (hashCode*397) ^ EqualityComparer.Default.GetHashCode(Item4); + hashCode = (hashCode*397) ^ EqualityComparer.Default.GetHashCode(Item5); return hashCode; } } + + public override string ToString() + { + return $"{Item1}, {Item2}, {Item3}, {Item4}, {Item5}"; + } } public class TarantoolTuple : ITarantoolTuple { public TarantoolTuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6) { + Item1 = item1; Item2 = item2; Item3 = item3; @@ -220,22 +250,20 @@ public TarantoolTuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6 } public T1 Item1 { get; } - public T2 Item2 { get; } - public T3 Item3 { get; } - public T4 Item4 { get; } - public T5 Item5 { get; } - public T6 Item6 { get; } protected bool Equals(TarantoolTuple other) { - return EqualityComparer.Default.Equals(Item1, other.Item1) && EqualityComparer.Default.Equals(Item2, other.Item2) - && EqualityComparer.Default.Equals(Item3, other.Item3) && EqualityComparer.Default.Equals(Item4, other.Item4) - && EqualityComparer.Default.Equals(Item5, other.Item5) && EqualityComparer.Default.Equals(Item6, other.Item6); + return EqualityComparer.Default.Equals(Item1, other.Item1) && + EqualityComparer.Default.Equals(Item2, other.Item2) && + EqualityComparer.Default.Equals(Item3, other.Item3) && + EqualityComparer.Default.Equals(Item4, other.Item4) && + EqualityComparer.Default.Equals(Item5, other.Item5) && + EqualityComparer.Default.Equals(Item6, other.Item6); } public override bool Equals(object obj) @@ -251,20 +279,26 @@ public override int GetHashCode() unchecked { var hashCode = EqualityComparer.Default.GetHashCode(Item1); - hashCode = (hashCode * 397) ^ EqualityComparer.Default.GetHashCode(Item2); - hashCode = (hashCode * 397) ^ EqualityComparer.Default.GetHashCode(Item3); - hashCode = (hashCode * 397) ^ EqualityComparer.Default.GetHashCode(Item4); - hashCode = (hashCode * 397) ^ EqualityComparer.Default.GetHashCode(Item5); - hashCode = (hashCode * 397) ^ EqualityComparer.Default.GetHashCode(Item6); + hashCode = (hashCode*397) ^ EqualityComparer.Default.GetHashCode(Item2); + hashCode = (hashCode*397) ^ EqualityComparer.Default.GetHashCode(Item3); + hashCode = (hashCode*397) ^ EqualityComparer.Default.GetHashCode(Item4); + hashCode = (hashCode*397) ^ EqualityComparer.Default.GetHashCode(Item5); + hashCode = (hashCode*397) ^ EqualityComparer.Default.GetHashCode(Item6); return hashCode; } } + + public override string ToString() + { + return $"{Item1}, {Item2}, {Item3}, {Item4}, {Item5}, {Item6}"; + } } public class TarantoolTuple : ITarantoolTuple { public TarantoolTuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7) { + Item1 = item1; Item2 = item2; Item3 = item3; @@ -275,25 +309,22 @@ public TarantoolTuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6 } public T1 Item1 { get; } - public T2 Item2 { get; } - public T3 Item3 { get; } - public T4 Item4 { get; } - public T5 Item5 { get; } - public T6 Item6 { get; } - public T7 Item7 { get; } protected bool Equals(TarantoolTuple other) { - return EqualityComparer.Default.Equals(Item1, other.Item1) && EqualityComparer.Default.Equals(Item2, other.Item2) - && EqualityComparer.Default.Equals(Item3, other.Item3) && EqualityComparer.Default.Equals(Item4, other.Item4) - && EqualityComparer.Default.Equals(Item5, other.Item5) && EqualityComparer.Default.Equals(Item6, other.Item6) - && EqualityComparer.Default.Equals(Item7, other.Item7); + return EqualityComparer.Default.Equals(Item1, other.Item1) && + EqualityComparer.Default.Equals(Item2, other.Item2) && + EqualityComparer.Default.Equals(Item3, other.Item3) && + EqualityComparer.Default.Equals(Item4, other.Item4) && + EqualityComparer.Default.Equals(Item5, other.Item5) && + EqualityComparer.Default.Equals(Item6, other.Item6) && + EqualityComparer.Default.Equals(Item7, other.Item7); } public override bool Equals(object obj) @@ -309,21 +340,27 @@ public override int GetHashCode() unchecked { var hashCode = EqualityComparer.Default.GetHashCode(Item1); - hashCode = (hashCode * 397) ^ EqualityComparer.Default.GetHashCode(Item2); - hashCode = (hashCode * 397) ^ EqualityComparer.Default.GetHashCode(Item3); - hashCode = (hashCode * 397) ^ EqualityComparer.Default.GetHashCode(Item4); - hashCode = (hashCode * 397) ^ EqualityComparer.Default.GetHashCode(Item5); - hashCode = (hashCode * 397) ^ EqualityComparer.Default.GetHashCode(Item6); - hashCode = (hashCode * 397) ^ EqualityComparer.Default.GetHashCode(Item7); + hashCode = (hashCode*397) ^ EqualityComparer.Default.GetHashCode(Item2); + hashCode = (hashCode*397) ^ EqualityComparer.Default.GetHashCode(Item3); + hashCode = (hashCode*397) ^ EqualityComparer.Default.GetHashCode(Item4); + hashCode = (hashCode*397) ^ EqualityComparer.Default.GetHashCode(Item5); + hashCode = (hashCode*397) ^ EqualityComparer.Default.GetHashCode(Item6); + hashCode = (hashCode*397) ^ EqualityComparer.Default.GetHashCode(Item7); return hashCode; } } + + public override string ToString() + { + return $"{Item1}, {Item2}, {Item3}, {Item4}, {Item5}, {Item6}, {Item7}"; + } } public class TarantoolTuple : ITarantoolTuple { public TarantoolTuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7, T8 item8) { + Item1 = item1; Item2 = item2; Item3 = item3; @@ -335,27 +372,24 @@ public TarantoolTuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6 } public T1 Item1 { get; } - public T2 Item2 { get; } - public T3 Item3 { get; } - public T4 Item4 { get; } - public T5 Item5 { get; } - public T6 Item6 { get; } - public T7 Item7 { get; } - public T8 Item8 { get; } protected bool Equals(TarantoolTuple other) { - return EqualityComparer.Default.Equals(Item1, other.Item1) && EqualityComparer.Default.Equals(Item2, other.Item2) - && EqualityComparer.Default.Equals(Item3, other.Item3) && EqualityComparer.Default.Equals(Item4, other.Item4) - && EqualityComparer.Default.Equals(Item5, other.Item5) && EqualityComparer.Default.Equals(Item6, other.Item6) - && EqualityComparer.Default.Equals(Item7, other.Item7) && EqualityComparer.Default.Equals(Item8, other.Item8); + return EqualityComparer.Default.Equals(Item1, other.Item1) && + EqualityComparer.Default.Equals(Item2, other.Item2) && + EqualityComparer.Default.Equals(Item3, other.Item3) && + EqualityComparer.Default.Equals(Item4, other.Item4) && + EqualityComparer.Default.Equals(Item5, other.Item5) && + EqualityComparer.Default.Equals(Item6, other.Item6) && + EqualityComparer.Default.Equals(Item7, other.Item7) && + EqualityComparer.Default.Equals(Item8, other.Item8); } public override bool Equals(object obj) @@ -371,43 +405,26 @@ public override int GetHashCode() unchecked { var hashCode = EqualityComparer.Default.GetHashCode(Item1); - hashCode = (hashCode * 397) ^ EqualityComparer.Default.GetHashCode(Item2); - hashCode = (hashCode * 397) ^ EqualityComparer.Default.GetHashCode(Item3); - hashCode = (hashCode * 397) ^ EqualityComparer.Default.GetHashCode(Item4); - hashCode = (hashCode * 397) ^ EqualityComparer.Default.GetHashCode(Item5); - hashCode = (hashCode * 397) ^ EqualityComparer.Default.GetHashCode(Item6); - hashCode = (hashCode * 397) ^ EqualityComparer.Default.GetHashCode(Item7); - hashCode = (hashCode * 397) ^ EqualityComparer.Default.GetHashCode(Item8); + hashCode = (hashCode*397) ^ EqualityComparer.Default.GetHashCode(Item2); + hashCode = (hashCode*397) ^ EqualityComparer.Default.GetHashCode(Item3); + hashCode = (hashCode*397) ^ EqualityComparer.Default.GetHashCode(Item4); + hashCode = (hashCode*397) ^ EqualityComparer.Default.GetHashCode(Item5); + hashCode = (hashCode*397) ^ EqualityComparer.Default.GetHashCode(Item6); + hashCode = (hashCode*397) ^ EqualityComparer.Default.GetHashCode(Item7); + hashCode = (hashCode*397) ^ EqualityComparer.Default.GetHashCode(Item8); return hashCode; } } - } - - public class TarantoolTuple : ITarantoolTuple - { - protected bool Equals(TarantoolTuple other) + public override string ToString() { - return true; - } - - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - if (obj.GetType() != GetType()) return false; - return Equals((TarantoolTuple)obj); + return $"{Item1}, {Item2}, {Item3}, {Item4}, {Item5}, {Item6}, {Item7}, {Item8}"; } + } - public override int GetHashCode() - { - return string.Empty.GetHashCode(); - } - public static TarantoolTuple Create() - { - return new TarantoolTuple(); - } + public class TarantoolTuple + { public static TarantoolTuple Create(T1 item1) @@ -416,6 +433,7 @@ public static TarantoolTuple (item1); } + public static TarantoolTuple Create(T1 item1, T2 item2) { @@ -423,6 +441,7 @@ public static TarantoolTuple (item1, item2); } + public static TarantoolTuple Create(T1 item1, T2 item2, T3 item3) { @@ -430,6 +449,7 @@ public static TarantoolTuple (item1, item2, item3); } + public static TarantoolTuple Create(T1 item1, T2 item2, T3 item3, T4 item4) { @@ -437,6 +457,7 @@ public static TarantoolTuple (item1, item2, item3, item4); } + public static TarantoolTuple Create(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5) { @@ -444,6 +465,7 @@ public static TarantoolTuple (item1, item2, item3, item4, item5); } + public static TarantoolTuple Create(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6) { @@ -451,6 +473,7 @@ public static TarantoolTuple (item1, item2, item3, item4, item5, item6); } + public static TarantoolTuple Create(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7) { @@ -458,8 +481,10 @@ public static TarantoolTuple (item1, item2, item3, item4, item5, item6, item7); } + public static TarantoolTuple - Create(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7, T8 item8) + Create(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7, + T8 item8) { return new TarantoolTuple (item1, item2, item3, item4, item5, item6, item7, item8); From ba2cc2d31d743b3b8f6f44a62e248ad3d3a41631 Mon Sep 17 00:00:00 2001 From: Anatoly Popov Date: Wed, 26 Oct 2016 20:25:32 +0300 Subject: [PATCH 08/16] Move declaration closer to usage --- src/tarantool.client/Converters/ResponsePacketConverter.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/tarantool.client/Converters/ResponsePacketConverter.cs b/src/tarantool.client/Converters/ResponsePacketConverter.cs index dad2eba9..3952bf61 100644 --- a/src/tarantool.client/Converters/ResponsePacketConverter.cs +++ b/src/tarantool.client/Converters/ResponsePacketConverter.cs @@ -27,8 +27,6 @@ public void Write(DataResponse value, IMsgPackWriter writer) public DataResponse Read(IMsgPackReader reader) { - var data = default(T); - var length = reader.ReadMapLength(); if (length != 1u) { @@ -41,7 +39,7 @@ public DataResponse Read(IMsgPackReader reader) throw ExceptionHelper.UnexpectedKey(dataKey, Key.Data); } - data = _dataConverter.Read(reader); + var data = _dataConverter.Read(reader); return new DataResponse(data); } From e19b4ffc617996c0e9c6ea27d506dcb9b668deb2 Mon Sep 17 00:00:00 2001 From: Anatoly Popov Date: Wed, 26 Oct 2016 20:25:58 +0300 Subject: [PATCH 09/16] Add call v1.7. Close #71 --- src/tarantool.client/Box.cs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/tarantool.client/Box.cs b/src/tarantool.client/Box.cs index b13441a3..e93200f9 100644 --- a/src/tarantool.client/Box.cs +++ b/src/tarantool.client/Box.cs @@ -82,11 +82,10 @@ public Schema GetSchema() return new Schema(_logicalConnection); } - public async Task> Call_16(string functionName) + public Task> Call_16(string functionName) where TResponse : ITarantoolTuple { - var callRequest = new CallRequest(functionName, new TarantoolTuple(), false); - return await _logicalConnection.SendRequest, TResponse>(callRequest); + return Call_16(functionName, new TarantoolTuple()); } public async Task> Call_16(string functionName, TTuple request) @@ -97,6 +96,20 @@ public async Task> Call_16(string f return await _logicalConnection.SendRequest, TResponse>(callRequest); } + public Task> Call(string functionName) + where TResponse : ITarantoolTuple + { + return Call(functionName, new TarantoolTuple()); + } + + public async Task> Call(string functionName, TTuple request) + where TTuple : ITarantoolTuple + where TResponse : ITarantoolTuple + { + var callRequest = new CallRequest(functionName, request); + return await _logicalConnection.SendRequest, TResponse>(callRequest); + } + public async Task> Eval(string expression, TTuple request) where TTuple : ITarantoolTuple { From 76d77ab510446317798de05c428686ce0aee9e0f Mon Sep 17 00:00:00 2001 From: Anatoly Popov Date: Wed, 26 Oct 2016 20:48:55 +0300 Subject: [PATCH 10/16] Support call 1.7. Fix eval. Closes #71, #69 --- .../21fcbb60-2d73-4a67-b07c-dedd7cfe2799.tt | 7 ++- src/tarantool.client/Box.cs | 25 ++++---- .../Converters/TupleConverter.cs | 54 +++++++++++++++- src/tarantool.client/Index.cs | 4 +- src/tarantool.client/Model/TarantoolTuple.cs | 7 ++- tarantool/tarantool.lua | 30 +++++---- .../tarantool.client.tests/Box/Call_Should.cs | 63 ++++++++++++++++--- .../tarantool.client.tests/Box/Eval_Should.cs | 22 +++++++ 8 files changed, 176 insertions(+), 36 deletions(-) diff --git a/_T4Awesome/CodeItems/31c71f1f-2480-4de2-98a0-97a1c9b23c49/21fcbb60-2d73-4a67-b07c-dedd7cfe2799.tt b/_T4Awesome/CodeItems/31c71f1f-2480-4de2-98a0-97a1c9b23c49/21fcbb60-2d73-4a67-b07c-dedd7cfe2799.tt index 12beddc7..44de2512 100644 --- a/_T4Awesome/CodeItems/31c71f1f-2480-4de2-98a0-97a1c9b23c49/21fcbb60-2d73-4a67-b07c-dedd7cfe2799.tt +++ b/_T4Awesome/CodeItems/31c71f1f-2480-4de2-98a0-97a1c9b23c49/21fcbb60-2d73-4a67-b07c-dedd7cfe2799.tt @@ -55,7 +55,12 @@ for(int i=0;i < maxParametersCount; i++){ } #> -public class TarantoolTuple{ +public class TarantoolTuple : ITarantoolTuple { + private TarantoolTuple() + { + } + + public static TarantoolTuple Empty { get; } = new TarantoolTuple(); <# for(int i=0;i < maxParametersCount; i++){ #> diff --git a/src/tarantool.client/Box.cs b/src/tarantool.client/Box.cs index e93200f9..a06e254b 100644 --- a/src/tarantool.client/Box.cs +++ b/src/tarantool.client/Box.cs @@ -82,41 +82,44 @@ public Schema GetSchema() return new Schema(_logicalConnection); } - public Task> Call_16(string functionName) + public Task> Call_1_6(string functionName) where TResponse : ITarantoolTuple { - return Call_16(functionName, new TarantoolTuple()); + return Call_1_6(functionName, TarantoolTuple.Empty); } - public async Task> Call_16(string functionName, TTuple request) + public async Task> Call_1_6(string functionName, TTuple parameters) where TTuple : ITarantoolTuple where TResponse : ITarantoolTuple { - var callRequest = new CallRequest(functionName, request, false); + var callRequest = new CallRequest(functionName, parameters, false); return await _logicalConnection.SendRequest, TResponse>(callRequest); } public Task> Call(string functionName) - where TResponse : ITarantoolTuple { - return Call(functionName, new TarantoolTuple()); + return Call(functionName, TarantoolTuple.Empty); } - public async Task> Call(string functionName, TTuple request) + public async Task> Call(string functionName, TTuple parameters) where TTuple : ITarantoolTuple - where TResponse : ITarantoolTuple { - var callRequest = new CallRequest(functionName, request); + var callRequest = new CallRequest(functionName, parameters); return await _logicalConnection.SendRequest, TResponse>(callRequest); } - public async Task> Eval(string expression, TTuple request) + public async Task> Eval(string expression, TTuple parameters) where TTuple : ITarantoolTuple { - var evalRequest = new EvalRequest(expression, request); + var evalRequest = new EvalRequest(expression, parameters); return await _logicalConnection.SendRequest, TResponse>(evalRequest); } + public Task> Eval(string expression) + { + return Eval(expression, TarantoolTuple.Empty); + } + private async Task LoginIfNotGuest(GreetingsResponse greetings) { var singleNode = _clientOptions.ConnectionOptions.Nodes.Single(); diff --git a/src/tarantool.client/Converters/TupleConverter.cs b/src/tarantool.client/Converters/TupleConverter.cs index 4229df2a..7667271e 100644 --- a/src/tarantool.client/Converters/TupleConverter.cs +++ b/src/tarantool.client/Converters/TupleConverter.cs @@ -28,13 +28,18 @@ public void Write(TarantoolTuple value, IMsgPackWriter writer) public TarantoolTuple Read(IMsgPackReader reader) { var actual = reader.ReadArrayLength(); + if (actual == null) + { + return null; + } + const uint expected = 0u; if (actual != expected) { throw ExceptionHelper.InvalidArrayLength(expected, actual); } - return TarantoolTuple.Create(); + return TarantoolTuple.Empty; } } @@ -64,6 +69,12 @@ public void Write(TarantoolTuple value, IMsgPackWriter writer) public TarantoolTuple Read(IMsgPackReader reader) { var actual = reader.ReadArrayLength(); + if (actual == null) + { + return null; + } + + const uint expected = 1u; if (actual != expected) { @@ -105,6 +116,11 @@ public void Write(TarantoolTuple value, IMsgPackWriter writer) public TarantoolTuple Read(IMsgPackReader reader) { var actual = reader.ReadArrayLength(); + if (actual == null) + { + return null; + } + const uint expected = 2u; if (actual != expected) { @@ -150,6 +166,12 @@ public void Write(TarantoolTuple value, IMsgPackWriter writer) public TarantoolTuple Read(IMsgPackReader reader) { var actual = reader.ReadArrayLength(); + if (actual == null) + { + return null; + } + + const uint expected = 3u; if (actual != expected) { @@ -199,6 +221,12 @@ public void Write(TarantoolTuple value, IMsgPackWriter writer) public TarantoolTuple Read(IMsgPackReader reader) { var actual = reader.ReadArrayLength(); + if (actual == null) + { + return null; + } + + const uint expected = 4u; if (actual != expected) { @@ -252,6 +280,12 @@ public void Write(TarantoolTuple value, IMsgPackWriter write public TarantoolTuple Read(IMsgPackReader reader) { var actual = reader.ReadArrayLength(); + if (actual == null) + { + return null; + } + + const uint expected = 5u; if (actual != expected) { @@ -310,6 +344,12 @@ public TarantoolTuple Read( IMsgPackReader reader) { var actual = reader.ReadArrayLength(); + if (actual == null) + { + return null; + } + + const uint expected = 6u; if (actual != expected) { @@ -372,6 +412,12 @@ public TarantoolTuple Read( IMsgPackReader reader) { var actual = reader.ReadArrayLength(); + if (actual == null) + { + return null; + } + + const uint expected = 7u; if (actual != expected) { @@ -438,6 +484,12 @@ public TarantoolTuple Read( IMsgPackReader reader) { var actual = reader.ReadArrayLength(); + if (actual == null) + { + return null; + } + + const uint expected = 8u; if (actual != expected) { diff --git a/src/tarantool.client/Index.cs b/src/tarantool.client/Index.cs index b4938d68..ed12cbc4 100644 --- a/src/tarantool.client/Index.cs +++ b/src/tarantool.client/Index.cs @@ -82,7 +82,7 @@ public async Task> Replace(TTuple tuple) public async Task Min() where TTuple : ITarantoolTuple { - return await Min(TarantoolTuple.Create()); + return await Min(TarantoolTuple.Empty); } public async Task Min(TKey key) @@ -104,7 +104,7 @@ public async Task Min(TKey key) public async Task Max() where TTuple : ITarantoolTuple { - return await Max(TarantoolTuple.Create()); + return await Max(TarantoolTuple.Empty); } public async Task Max(TKey key = null) diff --git a/src/tarantool.client/Model/TarantoolTuple.cs b/src/tarantool.client/Model/TarantoolTuple.cs index da1f9262..f6f93c67 100644 --- a/src/tarantool.client/Model/TarantoolTuple.cs +++ b/src/tarantool.client/Model/TarantoolTuple.cs @@ -423,8 +423,13 @@ public override string ToString() } - public class TarantoolTuple + public class TarantoolTuple : ITarantoolTuple { + private TarantoolTuple() + { + } + + public static TarantoolTuple Empty { get; } = new TarantoolTuple(); public static TarantoolTuple Create(T1 item1) diff --git a/tarantool/tarantool.lua b/tarantool/tarantool.lua index b97f2c0e..554c4340 100644 --- a/tarantool/tarantool.lua +++ b/tarantool/tarantool.lua @@ -32,18 +32,6 @@ local function space_TreeIndexMethods() space:auto_increment{2, 3} end -function return_null() - return require('msgpack').NULL -end - -function return_tuple() - return { 1, 2 } -end - -function return_scalar() - return 1 -end - box.once('init', init) box.once('space_TreeIndexMethods', space_TreeIndexMethods) @@ -72,4 +60,20 @@ end box.session.on_connect(log_connect) box.session.on_disconnect(log_disconnect) box.session.on_auth(log_auth) -box.session.on_auth(log_auth_ok) \ No newline at end of file +box.session.on_auth(log_auth_ok) + +function return_null() + return require('msgpack').NULL +end + +function return_tuple_with_null() + return { require('msgpack').NULL } +end + +function return_tuple() + return { 1, 2 } +end + +function return_scalar() + return 1 +end \ No newline at end of file diff --git a/tests/tarantool.client.tests/Box/Call_Should.cs b/tests/tarantool.client.tests/Box/Call_Should.cs index e2b0b153..00bd44a3 100644 --- a/tests/tarantool.client.tests/Box/Call_Should.cs +++ b/tests/tarantool.client.tests/Box/Call_Should.cs @@ -18,7 +18,7 @@ public async Task call_method() { using (var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301")) { - var result = await tarantoolClient.Call_16, TarantoolTuple>("math.sqrt", TarantoolTuple.Create(1.3)); + var result = await tarantoolClient.Call_1_6, TarantoolTuple>("math.sqrt", TarantoolTuple.Create(1.3)); var diff = Math.Abs(result.Data.Single().Item1 - Math.Sqrt(1.3)); @@ -26,13 +26,62 @@ public async Task call_method() } } + [Fact] + public async Task return_null_v1_6_should_not_throw() + { + using (var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301")) + { + await Should.ThrowAsync(async () => await tarantoolClient.Call_1_6>("return_null")); + } + } + + [Fact] + public async Task return_tuple_v1_6_with_null_should_not_throw() + { + using (var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301")) + { + var result = await tarantoolClient.Call_1_6>("return_tuple_with_null"); + result.Data.ShouldBe(new[] { TarantoolTuple.Create(default(string)) }); + } + } + + [Fact] + public async Task return_tuple_v1_6_should_not_throw() + { + using (var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301")) + { + var result = await tarantoolClient.Call_1_6>("return_tuple"); + result.Data.ShouldBe(new[] {TarantoolTuple.Create(1, 2)}); + } + } + + [Fact] + public async Task return_int_v1_6_should_not_throw() + { + using (var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301")) + { + var result = await tarantoolClient.Call_1_6>("return_scalar"); + result.Data.ShouldBe(new[] { TarantoolTuple.Create(1) }); + } + } + [Fact] public async Task return_null_should_not_throw() { using (var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301")) { - var result = await tarantoolClient.Call_16>("return_null"); - result.Data.ShouldBe(new TarantoolTuple[] {null}); + var result = await tarantoolClient.Call>("return_null"); + result.Data.ShouldBe(new[] { default(TarantoolTuple) }); + } + } + + [Fact] + public async Task return_tuple_with_null_should_not_throw() + { + using (var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301")) + { + var result = await tarantoolClient.Call>("return_tuple_with_null"); + result.Data.ShouldBe(new[] { TarantoolTuple.Create(default(string)) }); } } @@ -41,8 +90,8 @@ public async Task return_tuple_should_not_throw() { using (var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301")) { - var result = await tarantoolClient.Call_16>("return_tuple"); - result.Data.ShouldBe(new[] {TarantoolTuple.Create(1, 2)}); + var result = await tarantoolClient.Call>("return_tuple"); + result.Data.ShouldBe(new[] { TarantoolTuple.Create(1, 2) }); } } @@ -51,8 +100,8 @@ public async Task return_int_should_not_throw() { using (var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301")) { - var result = await tarantoolClient.Call_16>("return_scalar"); - result.Data.ShouldBe(new[] { TarantoolTuple.Create(1) }); + var result = await tarantoolClient.Call("return_scalar"); + result.Data.ShouldBe(new[] { 1 }); } } } diff --git a/tests/tarantool.client.tests/Box/Eval_Should.cs b/tests/tarantool.client.tests/Box/Eval_Should.cs index f4e22cf3..4cebaa2b 100644 --- a/tests/tarantool.client.tests/Box/Eval_Should.cs +++ b/tests/tarantool.client.tests/Box/Eval_Should.cs @@ -21,6 +21,17 @@ public async Task evaluate_expression() } } + [Fact] + public async Task evaluate_scalar() + { + using (var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301")) + { + var result = await tarantoolClient.Eval("return 1"); + + result.Data.ShouldBe(new [] { 1 }); + } + } + [Fact] public async Task evaluate_call_function() { @@ -31,5 +42,16 @@ public async Task evaluate_call_function() result.Data.ShouldBe(new[] { TarantoolTuple.Create(1, 2) }); } } + + [Fact] + public async Task evaluate_return_null() + { + using (var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301")) + { + var result = await tarantoolClient.Eval>("return return_null()", TarantoolTuple.Empty); + + result.Data.ShouldBe(new[] { default(TarantoolTuple) }); + } + } } } \ No newline at end of file From c654bc95891330504c1de8e10e766ce5bdf4da81 Mon Sep 17 00:00:00 2001 From: Anatoly Popov Date: Wed, 26 Oct 2016 21:53:43 +0300 Subject: [PATCH 11/16] Fix `This platform does not support connecting sockets to DNS endpoints via the instance Connect and ConnectAsync methods` on Linux --- .../NetworkStreamPhysicalConnection.cs | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/tarantool.client/NetworkStreamPhysicalConnection.cs b/src/tarantool.client/NetworkStreamPhysicalConnection.cs index 1881812a..0f020947 100644 --- a/src/tarantool.client/NetworkStreamPhysicalConnection.cs +++ b/src/tarantool.client/NetworkStreamPhysicalConnection.cs @@ -6,6 +6,7 @@ using ProGaudi.Tarantool.Client.Model; using ProGaudi.Tarantool.Client.Utils; +using System.Net; namespace ProGaudi.Tarantool.Client { @@ -30,7 +31,7 @@ public async Task Connect(ClientOptions options) _socket = new Socket(SocketType.Stream, ProtocolType.Tcp); #if PROGAUDI_NETCORE - await _socket.ConnectAsync(singleNode.Uri.Host, singleNode.Uri.Port); + await ConnectAsync(_socket, singleNode.Uri.Host, singleNode.Uri.Port); #else await ConnectAsync(_socket, singleNode.Uri.Host, singleNode.Uri.Port); #endif @@ -57,7 +58,33 @@ public async Task ReadAsync(byte[] buffer, int offset, int count) return await _stream.ReadAsync(buffer, offset, count); } -#if !PROGAUDI_NETCORE +#if PROGAUDI_NETCORE + /// https://github.com/mongodb/mongo-csharp-driver/commit/9c2097f349d5096a04ea81b0c9ceb60c7e1acee4 + private static async Task ConnectAsync(Socket socket, string host, int port) + { + var resolved = await Dns.GetHostAddressesAsync(host); + for (int i = 0; i < resolved.Length; i++) + { + try + { + await socket.ConnectAsync(resolved[i], port); + return; + } + catch + { + // if we have tried all of them and still failed, + // then blow up. + if (i == resolved.Length - 1) + { + throw; + } + } + } + + // we should never get here... + throw new InvalidOperationException("Unabled to resolve endpoint."); + } +#else /// Stolen from corefx github private static Task ConnectAsync(Socket socket, string host, int port) { From d7ae8b7c44cb4462e652504771a293519a92dc46 Mon Sep 17 00:00:00 2001 From: Anatoly Popov Date: Thu, 27 Oct 2016 12:50:06 +0300 Subject: [PATCH 12/16] Reorder compiler directives. --- src/tarantool.client/NetworkStreamPhysicalConnection.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/tarantool.client/NetworkStreamPhysicalConnection.cs b/src/tarantool.client/NetworkStreamPhysicalConnection.cs index 0f020947..369b6b39 100644 --- a/src/tarantool.client/NetworkStreamPhysicalConnection.cs +++ b/src/tarantool.client/NetworkStreamPhysicalConnection.cs @@ -6,7 +6,10 @@ using ProGaudi.Tarantool.Client.Model; using ProGaudi.Tarantool.Client.Utils; + +#if PROGAUDI_NETCORE using System.Net; +#endif namespace ProGaudi.Tarantool.Client { @@ -30,11 +33,7 @@ public async Task Connect(ClientOptions options) var singleNode = options.ConnectionOptions.Nodes.Single(); _socket = new Socket(SocketType.Stream, ProtocolType.Tcp); -#if PROGAUDI_NETCORE await ConnectAsync(_socket, singleNode.Uri.Host, singleNode.Uri.Port); -#else - await ConnectAsync(_socket, singleNode.Uri.Host, singleNode.Uri.Port); -#endif _stream = new NetworkStream(_socket, true); options.LogWriter?.WriteLine("Socket connection established."); } From da6e15093d7ff275f539362601eaed3be481ab11 Mon Sep 17 00:00:00 2001 From: Anatoly Popov Date: Thu, 27 Oct 2016 12:50:22 +0300 Subject: [PATCH 13/16] Extract logging to separate method --- src/tarantool.client/ResponseReader.cs | 36 ++++++++++++++------------ 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/tarantool.client/ResponseReader.cs b/src/tarantool.client/ResponseReader.cs index 4ed08728..d0510f65 100644 --- a/src/tarantool.client/ResponseReader.cs +++ b/src/tarantool.client/ResponseReader.cs @@ -9,6 +9,7 @@ using ProGaudi.Tarantool.Client.Model.Responses; using ProGaudi.Tarantool.Client.Utils; using System.Threading.Tasks; +using JetBrains.Annotations; namespace ProGaudi.Tarantool.Client { @@ -142,22 +143,8 @@ private void MatchResult(byte[] result) if (tcs == null) { - if (_clientOptions.LogWriter == null) - return; - - var builder = new StringBuilder("Warning: can't match request via requestId from response. Response:"); - var length = 80/3; - for (var i = 0; i < result.Length; i++) - { - if (i%length == 0) - builder.AppendLine().Append(" "); - else - builder.Append(" "); - - builder.AppendFormat("{0:X2}", result[i]); - } - - _clientOptions.LogWriter?.WriteLine(builder.ToString()); + if (_clientOptions.LogWriter != null) + LogUnMatchedResponse(result, _clientOptions.LogWriter); return; } @@ -173,6 +160,23 @@ private void MatchResult(byte[] result) } } + private static void LogUnMatchedResponse(byte[] result, [NotNull]ILog logWriter) + { + var builder = new StringBuilder("Warning: can't match request via requestId from response. Response:"); + var length = 80/3; + for (var i = 0; i < result.Length; i++) + { + if (i%length == 0) + builder.AppendLine().Append(" "); + else + builder.Append(" "); + + builder.AppendFormat("{0:X2}", result[i]); + } + + logWriter.WriteLine(builder.ToString()); + } + private byte[] TryParseResponse() { if (AllBytesProcessed()) From 65a1eecaf6868778513ed02476fe0d6f0da8e610 Mon Sep 17 00:00:00 2001 From: Anatoly Popov Date: Thu, 27 Oct 2016 12:57:28 +0300 Subject: [PATCH 14/16] Add call overloads to call function which do not return anything --- src/tarantool.client/Box.cs | 10 ++++++++++ tarantool/tarantool.lua | 14 ++++++++++---- .../tarantool.client.tests/Box/Call_Should.cs | 18 ++++++++++++++++++ 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/tarantool.client/Box.cs b/src/tarantool.client/Box.cs index a06e254b..08e7570c 100644 --- a/src/tarantool.client/Box.cs +++ b/src/tarantool.client/Box.cs @@ -82,6 +82,11 @@ public Schema GetSchema() return new Schema(_logicalConnection); } + public async Task Call_1_6(string functionName) + { + await Call_1_6(functionName, TarantoolTuple.Empty); + } + public Task> Call_1_6(string functionName) where TResponse : ITarantoolTuple { @@ -96,6 +101,11 @@ public async Task> Call_1_6(string return await _logicalConnection.SendRequest, TResponse>(callRequest); } + public async Task Call(string functionName) + { + await Call(functionName, TarantoolTuple.Empty); + } + public Task> Call(string functionName) { return Call(functionName, TarantoolTuple.Empty); diff --git a/tarantool/tarantool.lua b/tarantool/tarantool.lua index 554c4340..b94aa9ae 100644 --- a/tarantool/tarantool.lua +++ b/tarantool/tarantool.lua @@ -35,24 +35,22 @@ end box.once('init', init) box.once('space_TreeIndexMethods', space_TreeIndexMethods) +local log = require('log') + function log_connect () - local log = require('log') local m = 'Connection. user=' .. box.session.user() .. ' id=' .. box.session.id() log.info(m) end function log_disconnect () - local log = require('log') local m = 'Disconnection. user=' .. box.session.user() .. ' id=' .. box.session.id() log.info(m) end function log_auth () - local log = require('log') local m = 'Authentication attempt' log.info(m) end function log_auth_ok (user_name) - local log = require('log') local m = 'Authenticated user ' .. user_name log.info(m) end @@ -63,17 +61,25 @@ box.session.on_auth(log_auth) box.session.on_auth(log_auth_ok) function return_null() + log.info('return_null called') return require('msgpack').NULL end function return_tuple_with_null() + log.info('return_tuple_with_null called') return { require('msgpack').NULL } end function return_tuple() + log.info('return_tuple called') return { 1, 2 } end function return_scalar() + log.info('return_scalar called') return 1 +end + +function return_nothing() + log.info('return_nothing called') end \ No newline at end of file diff --git a/tests/tarantool.client.tests/Box/Call_Should.cs b/tests/tarantool.client.tests/Box/Call_Should.cs index 00bd44a3..04c5d19a 100644 --- a/tests/tarantool.client.tests/Box/Call_Should.cs +++ b/tests/tarantool.client.tests/Box/Call_Should.cs @@ -65,6 +65,15 @@ public async Task return_int_v1_6_should_not_throw() } } + [Fact] + public async Task return_nothing_v1_6_should_not_throw() + { + using (var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301")) + { + Should.NotThrow(async () => await tarantoolClient.Call_1_6("return_nothing")); + } + } + [Fact] public async Task return_null_should_not_throw() { @@ -104,5 +113,14 @@ public async Task return_int_should_not_throw() result.Data.ShouldBe(new[] { 1 }); } } + + [Fact] + public async Task return_nothing_should_not_throw() + { + using (var tarantoolClient = await Client.Box.Connect("127.0.0.1:3301")) + { + Should.NotThrow(async () => await tarantoolClient.Call("return_nothing")); + } + } } } \ No newline at end of file From c67126389cdb71ee59a56af2266c49025ab2b896 Mon Sep 17 00:00:00 2001 From: Anatoly Popov Date: Thu, 27 Oct 2016 13:13:32 +0300 Subject: [PATCH 15/16] Fixing build --- .travis.yml | 3 ++- .travis/linux/init.sh | 1 + .travis/osx/init.sh | 4 ++++ 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100755 .travis/linux/init.sh create mode 100755 .travis/osx/init.sh diff --git a/.travis.yml b/.travis.yml index 67330eea..da381d7f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,7 @@ services: - docker before_script: + - .travis/$TRAVIS_OS_NAME/init.sh - dotnet restore - docker -v - docker-compose down @@ -28,4 +29,4 @@ before_script: script: - dotnet build -f netcoreapp1.0 src/tarantool.client - dotnet test tests/tarantool.client.tests - - curl --fail http://localhost:5000 \ No newline at end of file + - curl -o /dev/null --fail http://localhost:5000 \ No newline at end of file diff --git a/.travis/linux/init.sh b/.travis/linux/init.sh new file mode 100755 index 00000000..212c4ba2 --- /dev/null +++ b/.travis/linux/init.sh @@ -0,0 +1 @@ +#!/usr/bin/env bash \ No newline at end of file diff --git a/.travis/osx/init.sh b/.travis/osx/init.sh new file mode 100755 index 00000000..656d0db5 --- /dev/null +++ b/.travis/osx/init.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +brew tap caskroom/cask +brew cask install docker \ No newline at end of file From ba2973f58f35df00ef58bba33c0ccf94c50786ab Mon Sep 17 00:00:00 2001 From: Anatoly Popov Date: Thu, 27 Oct 2016 13:31:55 +0300 Subject: [PATCH 16/16] Remove tests from Mac build until I got mac for tests of scripts --- .travis.yml | 10 +--------- .travis/linux/init.sh | 12 +++++++++++- .travis/linux/test.sh | 6 ++++++ .travis/osx/init.sh | 1 + .travis/osx/test.sh | 3 +++ 5 files changed, 22 insertions(+), 10 deletions(-) create mode 100755 .travis/linux/test.sh create mode 100755 .travis/osx/test.sh diff --git a/.travis.yml b/.travis.yml index da381d7f..df1709a7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,15 +18,7 @@ services: before_script: - .travis/$TRAVIS_OS_NAME/init.sh - dotnet restore - - docker -v - - docker-compose down - - docker-compose up -d - - pushd samples/docker-compose - - docker-compose down - - docker-compose up -d --build - - popd script: - dotnet build -f netcoreapp1.0 src/tarantool.client - - dotnet test tests/tarantool.client.tests - - curl -o /dev/null --fail http://localhost:5000 \ No newline at end of file + - .travis/$TRAVIS_OS_NAME/test.sh \ No newline at end of file diff --git a/.travis/linux/init.sh b/.travis/linux/init.sh index 212c4ba2..bd7f12b3 100755 --- a/.travis/linux/init.sh +++ b/.travis/linux/init.sh @@ -1 +1,11 @@ -#!/usr/bin/env bash \ No newline at end of file +#!/usr/bin/env bash + +echo 'Linux init script' + +docker -v +docker-compose down +docker-compose up -d +pushd samples/docker-compose +docker-compose down +docker-compose up -d --build +popd \ No newline at end of file diff --git a/.travis/linux/test.sh b/.travis/linux/test.sh new file mode 100755 index 00000000..e2d459c3 --- /dev/null +++ b/.travis/linux/test.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +echo 'Linux test script' + +dotnet test tests/tarantool.client.tests +curl -o /dev/null --fail http://localhost:5000 \ No newline at end of file diff --git a/.travis/osx/init.sh b/.travis/osx/init.sh index 656d0db5..8739c2bd 100755 --- a/.travis/osx/init.sh +++ b/.travis/osx/init.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +echo 'Mac init script' brew tap caskroom/cask brew cask install docker \ No newline at end of file diff --git a/.travis/osx/test.sh b/.travis/osx/test.sh new file mode 100755 index 00000000..e5893c5e --- /dev/null +++ b/.travis/osx/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +echo 'Mac test script' \ No newline at end of file