From b67027390ad95c678b7a458045a659d096213c8e Mon Sep 17 00:00:00 2001 From: Roman Kozachenko Date: Tue, 21 Mar 2017 15:26:30 +0300 Subject: [PATCH 1/4] Add MsgPackToken test --- .../Space/MsgPackTokenTest.cs | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 tests/progaudi.tarantool.tests/Space/MsgPackTokenTest.cs diff --git a/tests/progaudi.tarantool.tests/Space/MsgPackTokenTest.cs b/tests/progaudi.tarantool.tests/Space/MsgPackTokenTest.cs new file mode 100644 index 00000000..ef627dde --- /dev/null +++ b/tests/progaudi.tarantool.tests/Space/MsgPackTokenTest.cs @@ -0,0 +1,61 @@ +// +// Copyright © eVote +// + +using System.Linq; +using System.Threading.Tasks; +using ProGaudi.MsgPack.Light; +using ProGaudi.Tarantool.Client.Model; +using Shouldly; +using Xunit; + +namespace ProGaudi.Tarantool.Client.Tests.Space +{ + public class MsgPackTokenTest + : TestBase + { + [Fact] + public async Task Smoke() + { + await ClearDataAsync(new[] { "with_scalar_index" }); + + const string spaceName = "with_scalar_index"; + var clientOptions = new ClientOptions(ReplicationSourceFactory.GetReplicationSource()); + using (var tarantoolClient = new Tarantool.Client.Box(clientOptions)) + { + await tarantoolClient.Connect(); + var schema = tarantoolClient.GetSchema(); + + var space = await schema.GetSpace(spaceName); + + await space.Insert(TarantoolTuple.Create(2f, new[] { 1, 2, 3 })); + await space.Insert(TarantoolTuple.Create(true, "Music")); + await space.Insert(TarantoolTuple.Create(1u, 2f)); + await space.Insert(TarantoolTuple.Create("false", (string)null)); + + var index = await space.GetIndex(0); + var result = await index.Select, TarantoolTuple>( + TarantoolTuple.Create(false), + new SelectOptions + { + Iterator = Model.Enums.Iterator.All + }); + + result.Data.ShouldNotBeNull(); + + var data = result.Data; + ((bool)data[0].Item1).ShouldBe(true); + ((string)data[0].Item2).ShouldBe("Music"); + + ((ulong)data[1].Item1).ShouldBe(1u); + ((double)data[1].Item2).ShouldBe(2f); + + ((double)data[2].Item1).ShouldBe(2f); + ((MsgPackToken[])data[2].Item2).Select(t => (int)t).ToArray().ShouldBe(new[] { 1, 2, 3 }); + + ((string)data[3].Item1).ShouldBe("false"); + ((MsgPackToken[])data[3].Item2).ShouldBe(null); + } + } + } +} \ No newline at end of file From fa5f33ca8e488e0abcb30626e1ba55eb8a405dbd Mon Sep 17 00:00:00 2001 From: Roman Kozachenko Date: Tue, 21 Mar 2017 15:26:35 +0300 Subject: [PATCH 2/4] Fix tests --- tarantool/tarantool.lua | 100 +++++++++--------- tests/progaudi.tarantool.tests/Index/Smoke.cs | 10 +- tests/progaudi.tarantool.tests/TestBase.cs | 5 +- .../progaudi.tarantool.tests.csproj | 4 + 4 files changed, 63 insertions(+), 56 deletions(-) diff --git a/tarantool/tarantool.lua b/tarantool/tarantool.lua index 8474b7bc..14100a95 100644 --- a/tarantool/tarantool.lua +++ b/tarantool/tarantool.lua @@ -1,41 +1,44 @@ box.cfg { - pid_file = nil, - background = false, - log_level = 5, - listen = 3301 + pid_file = nil, + background = false, + log_level = 5, + listen = 3301 } local function create_spaces_and_indecies() - space1 = box.schema.space.create('primary_only_index', { if_not_exists = true }) - space1:create_index('primary', {type='hash', parts={1, 'unsigned'}, if_not_exists = true}) + space1 = box.schema.space.create('primary_only_index', { if_not_exists = true }) + space1:create_index('primary', {type='hash', parts={1, 'unsigned'}, if_not_exists = true}) - performanceSpace = box.schema.space.create('performance', { if_not_exists = true }) - performanceSpace:create_index('primary', {type='hash', parts={1, 'unsigned'}, if_not_exists = true}) + performanceSpace = box.schema.space.create('performance', { if_not_exists = true }) + performanceSpace:create_index('primary', {type='hash', parts={1, 'unsigned'}, if_not_exists = true}) - space2 = box.schema.space.create('primary_and_secondary_index', { if_not_exists = true }) - space2:create_index('hashIndex', {type='hash', parts={1, 'unsigned'}, if_not_exists = true }) - space2:create_index('treeIndex', {type='tree', parts={1, 'unsigned'}, if_not_exists = true }) + space2 = box.schema.space.create('primary_and_secondary_index', { if_not_exists = true }) + space2:create_index('hashIndex', {type='hash', parts={1, 'unsigned'}, if_not_exists = true }) + space2:create_index('treeIndex', {type='tree', parts={1, 'unsigned'}, if_not_exists = true }) + + space3 = box.schema.space.create('with_scalar_index', { if_not_exists = true }) + space3:create_index('primary', {type='tree', parts={1, 'scalar'}, if_not_exists = true}) end local function init() - create_spaces_and_indecies() + create_spaces_and_indecies() - box.schema.user.create('notSetPassword', { if_not_exists = true }) - box.schema.user.create('emptyPassword', { password = '', if_not_exists = true }) + box.schema.user.create('notSetPassword', { if_not_exists = true }) + box.schema.user.create('emptyPassword', { password = '', if_not_exists = true }) - box.schema.user.create('operator', {password = 'operator', if_not_exists = true }) - box.schema.user.grant('operator','read,write,execute','universe', { if_not_exists = true }) - box.schema.user.grant('guest','read,write,execute','universe', { if_not_exists = true }) - box.schema.user.passwd('admin', 'adminPassword') + box.schema.user.create('operator', {password = 'operator', if_not_exists = true }) + box.schema.user.grant('operator','read,write,execute','universe', { if_not_exists = true }) + box.schema.user.grant('guest','read,write,execute','universe', { if_not_exists = true }) + box.schema.user.passwd('admin', 'adminPassword') end 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 = 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} + space:auto_increment{'asdf', 10.1} + space:auto_increment{'zcxv'} + space:auto_increment{2, 3} end box.once('init', init) @@ -44,21 +47,21 @@ box.once('space_TreeIndexMethods', space_TreeIndexMethods) local log = require('log') function log_connect () - local m = 'Connection. user=' .. box.session.user() .. ' id=' .. box.session.id() - log.info(m) + local m = 'Connection. user=' .. box.session.user() .. ' id=' .. box.session.id() + log.info(m) end function log_disconnect () - local m = 'Disconnection. user=' .. box.session.user() .. ' id=' .. box.session.id() - log.info(m) + local m = 'Disconnection. user=' .. box.session.user() .. ' id=' .. box.session.id() + log.info(m) end function log_auth () - local m = 'Authentication attempt' - log.info(m) + local m = 'Authentication attempt' + log.info(m) end function log_auth_ok (user_name) - local m = 'Authenticated user ' .. user_name - log.info(m) + local m = 'Authenticated user ' .. user_name + log.info(m) end box.session.on_connect(log_connect) @@ -67,37 +70,38 @@ 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 + 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 } + log.info('return_tuple_with_null called') + return { require('msgpack').NULL } end function return_tuple() - log.info('return_tuple called') - return { 1, 2 } + log.info('return_tuple called') + return { 1, 2 } end function return_array() - log.info('return_array called') - return {{ "abc", "def" }} + log.info('return_array called') + return {{ "abc", "def" }} end function return_scalar() - log.info('return_scalar called') - return 1 + log.info('return_scalar called') + return 1 end function return_nothing() - log.info('return_nothing called') + log.info('return_nothing called') end local truncate_space = function(name) local space = box.space[name] + if space then log.info("Truncating space %s...", name) space:truncate() @@ -107,11 +111,9 @@ local truncate_space = function(name) end end -function clear_data() - log.info('clearing data...') - - truncate_space('primary_only_index') - truncate_space('performance') - truncate_space('primary_and_secondary_index') - truncate_space('space_TreeIndexMethods') +function clear_data(spaceNames) + log.info('clearing data...') + for _, spaceName in ipairs(spaceNames) do + truncate_space(spaceName) + end end \ No newline at end of file diff --git a/tests/progaudi.tarantool.tests/Index/Smoke.cs b/tests/progaudi.tarantool.tests/Index/Smoke.cs index a0a5543c..f8ab471a 100644 --- a/tests/progaudi.tarantool.tests/Index/Smoke.cs +++ b/tests/progaudi.tarantool.tests/Index/Smoke.cs @@ -14,7 +14,7 @@ public class Smoke : TestBase [Fact] public async Task HashIndexMethods() { - await ClearDataAsync(); + await ClearDataAsync(new[] { "primary_only_index" }); const string spaceName = "primary_only_index"; using (var tarantoolClient = await Client.Box.Connect(ReplicationSourceFactory.GetReplicationSource())) @@ -39,10 +39,10 @@ public async Task HashIndexMethods() await index.Replace(TarantoolTuple.Create(2, "Car", -245.3)); await index.Update, TarantoolTuple>( TarantoolTuple.Create(2), - new UpdateOperation[] {UpdateOperation.CreateAddition(100, 2)}); + new UpdateOperation[] { UpdateOperation.CreateAddition(100, 2) }); - await index.Upsert(TarantoolTuple.Create(6u), new UpdateOperation[] {UpdateOperation.CreateAssign(2, 2)}); - await index.Upsert(TarantoolTuple.Create(6u), new UpdateOperation[] {UpdateOperation.CreateAddition(-2, 2)}); + await index.Upsert(TarantoolTuple.Create(6u), new UpdateOperation[] { UpdateOperation.CreateAssign(2, 2) }); + await index.Upsert(TarantoolTuple.Create(6u), new UpdateOperation[] { UpdateOperation.CreateAddition(-2, 2) }); var result = await index.Select, TarantoolTuple>(TarantoolTuple.Create(6u)); result.Data[0].Item1.ShouldBe(6u); @@ -52,7 +52,7 @@ await index.Update, TarantoolTuple>( [Fact] public async Task TreeIndexMethods() { - await ClearDataAsync(); + await ClearDataAsync(new[] { "space_TreeIndexMethods" }); const string spaceName = "space_TreeIndexMethods"; using (var tarantoolClient = await Client.Box.Connect(ReplicationSourceFactory.GetReplicationSource())) diff --git a/tests/progaudi.tarantool.tests/TestBase.cs b/tests/progaudi.tarantool.tests/TestBase.cs index 2ca2f69f..0cf6bb7b 100644 --- a/tests/progaudi.tarantool.tests/TestBase.cs +++ b/tests/progaudi.tarantool.tests/TestBase.cs @@ -1,15 +1,16 @@ using System; using System.Threading.Tasks; +using ProGaudi.Tarantool.Client.Model; namespace ProGaudi.Tarantool.Client.Tests { public class TestBase { - public async Task ClearDataAsync() + public async Task ClearDataAsync(string[] spaceNames) { using (var tarantoolClient = await Client.Box.Connect(ReplicationSourceFactory.GetReplicationSource("admin:adminPassword"))) { - await tarantoolClient.Call("clear_data"); + await tarantoolClient.Call("clear_data", TarantoolTuple.Create(spaceNames)); } } } diff --git a/tests/progaudi.tarantool.tests/progaudi.tarantool.tests.csproj b/tests/progaudi.tarantool.tests/progaudi.tarantool.tests.csproj index 38471183..4efff569 100644 --- a/tests/progaudi.tarantool.tests/progaudi.tarantool.tests.csproj +++ b/tests/progaudi.tarantool.tests/progaudi.tarantool.tests.csproj @@ -27,5 +27,9 @@ + + + + \ No newline at end of file From e294de7dd56ec850b3b521670088bf96fb0ba1f2 Mon Sep 17 00:00:00 2001 From: Roman Kozachenko Date: Tue, 21 Mar 2017 15:33:04 +0300 Subject: [PATCH 3/4] Delete non-actual test --- .../Space/Upsert_Should.cs | 29 ------------------- 1 file changed, 29 deletions(-) delete mode 100644 tests/progaudi.tarantool.tests/Space/Upsert_Should.cs diff --git a/tests/progaudi.tarantool.tests/Space/Upsert_Should.cs b/tests/progaudi.tarantool.tests/Space/Upsert_Should.cs deleted file mode 100644 index 202d4a7e..00000000 --- a/tests/progaudi.tarantool.tests/Space/Upsert_Should.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Threading.Tasks; - -using Xunit; - -using Shouldly; - -using ProGaudi.Tarantool.Client.Model; -using ProGaudi.Tarantool.Client.Model.UpdateOperations; - -namespace ProGaudi.Tarantool.Client.Tests.Space -{ - public class Upsert_Should : TestBase - { - [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"; - using (var tarantoolClient = await Client.Box.Connect(ReplicationSourceFactory.GetReplicationSource())) - { - var schema = tarantoolClient.GetSchema(); - - var space = await schema.GetSpace(spaceName); - - await space.Upsert(TarantoolTuple.Create(5), new UpdateOperation[] {UpdateOperation.CreateAddition(1, 2)}).ShouldThrowAsync(); - } - } - } -} \ No newline at end of file From 666044649190123d11130986c49c6cc94819f228 Mon Sep 17 00:00:00 2001 From: Roman Kozachenko Date: Tue, 21 Mar 2017 15:53:44 +0300 Subject: [PATCH 4/4] Fix PR remarks --- tests/progaudi.tarantool.tests/Index/Smoke.cs | 4 ++-- tests/progaudi.tarantool.tests/Space/MsgPackTokenTest.cs | 2 +- tests/progaudi.tarantool.tests/TestBase.cs | 2 +- .../progaudi.tarantool.tests/progaudi.tarantool.tests.csproj | 4 ---- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/tests/progaudi.tarantool.tests/Index/Smoke.cs b/tests/progaudi.tarantool.tests/Index/Smoke.cs index f8ab471a..7bedd040 100644 --- a/tests/progaudi.tarantool.tests/Index/Smoke.cs +++ b/tests/progaudi.tarantool.tests/Index/Smoke.cs @@ -14,7 +14,7 @@ public class Smoke : TestBase [Fact] public async Task HashIndexMethods() { - await ClearDataAsync(new[] { "primary_only_index" }); + await ClearDataAsync("primary_only_index"); const string spaceName = "primary_only_index"; using (var tarantoolClient = await Client.Box.Connect(ReplicationSourceFactory.GetReplicationSource())) @@ -52,7 +52,7 @@ await index.Update, TarantoolTuple>( [Fact] public async Task TreeIndexMethods() { - await ClearDataAsync(new[] { "space_TreeIndexMethods" }); + await ClearDataAsync("space_TreeIndexMethods"); const string spaceName = "space_TreeIndexMethods"; using (var tarantoolClient = await Client.Box.Connect(ReplicationSourceFactory.GetReplicationSource())) diff --git a/tests/progaudi.tarantool.tests/Space/MsgPackTokenTest.cs b/tests/progaudi.tarantool.tests/Space/MsgPackTokenTest.cs index ef627dde..cedd85ad 100644 --- a/tests/progaudi.tarantool.tests/Space/MsgPackTokenTest.cs +++ b/tests/progaudi.tarantool.tests/Space/MsgPackTokenTest.cs @@ -17,7 +17,7 @@ public class MsgPackTokenTest [Fact] public async Task Smoke() { - await ClearDataAsync(new[] { "with_scalar_index" }); + await ClearDataAsync("with_scalar_index"); const string spaceName = "with_scalar_index"; var clientOptions = new ClientOptions(ReplicationSourceFactory.GetReplicationSource()); diff --git a/tests/progaudi.tarantool.tests/TestBase.cs b/tests/progaudi.tarantool.tests/TestBase.cs index 0cf6bb7b..33c3983f 100644 --- a/tests/progaudi.tarantool.tests/TestBase.cs +++ b/tests/progaudi.tarantool.tests/TestBase.cs @@ -6,7 +6,7 @@ namespace ProGaudi.Tarantool.Client.Tests { public class TestBase { - public async Task ClearDataAsync(string[] spaceNames) + public async Task ClearDataAsync(params string[] spaceNames) { using (var tarantoolClient = await Client.Box.Connect(ReplicationSourceFactory.GetReplicationSource("admin:adminPassword"))) { diff --git a/tests/progaudi.tarantool.tests/progaudi.tarantool.tests.csproj b/tests/progaudi.tarantool.tests/progaudi.tarantool.tests.csproj index 4efff569..38471183 100644 --- a/tests/progaudi.tarantool.tests/progaudi.tarantool.tests.csproj +++ b/tests/progaudi.tarantool.tests/progaudi.tarantool.tests.csproj @@ -27,9 +27,5 @@ - - - - \ No newline at end of file