Skip to content

Commit b539c65

Browse files
Merge pull request #102 from progaudi/feature/msgpacktoken-test
Feature/msgpacktoken test
2 parents 637a720 + 6660446 commit b539c65

File tree

5 files changed

+120
-85
lines changed

5 files changed

+120
-85
lines changed

tarantool/tarantool.lua

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,44 @@
11
box.cfg
22
{
3-
pid_file = nil,
4-
background = false,
5-
log_level = 5,
6-
listen = 3301
3+
pid_file = nil,
4+
background = false,
5+
log_level = 5,
6+
listen = 3301
77
}
88
local function create_spaces_and_indecies()
9-
space1 = box.schema.space.create('primary_only_index', { if_not_exists = true })
10-
space1:create_index('primary', {type='hash', parts={1, 'unsigned'}, if_not_exists = true})
9+
space1 = box.schema.space.create('primary_only_index', { if_not_exists = true })
10+
space1:create_index('primary', {type='hash', parts={1, 'unsigned'}, if_not_exists = true})
1111

12-
performanceSpace = box.schema.space.create('performance', { if_not_exists = true })
13-
performanceSpace:create_index('primary', {type='hash', parts={1, 'unsigned'}, if_not_exists = true})
12+
performanceSpace = box.schema.space.create('performance', { if_not_exists = true })
13+
performanceSpace:create_index('primary', {type='hash', parts={1, 'unsigned'}, if_not_exists = true})
1414

15-
space2 = box.schema.space.create('primary_and_secondary_index', { if_not_exists = true })
16-
space2:create_index('hashIndex', {type='hash', parts={1, 'unsigned'}, if_not_exists = true })
17-
space2:create_index('treeIndex', {type='tree', parts={1, 'unsigned'}, if_not_exists = true })
15+
space2 = box.schema.space.create('primary_and_secondary_index', { if_not_exists = true })
16+
space2:create_index('hashIndex', {type='hash', parts={1, 'unsigned'}, if_not_exists = true })
17+
space2:create_index('treeIndex', {type='tree', parts={1, 'unsigned'}, if_not_exists = true })
18+
19+
space3 = box.schema.space.create('with_scalar_index', { if_not_exists = true })
20+
space3:create_index('primary', {type='tree', parts={1, 'scalar'}, if_not_exists = true})
1821
end
1922

2023
local function init()
21-
create_spaces_and_indecies()
24+
create_spaces_and_indecies()
2225

23-
box.schema.user.create('notSetPassword', { if_not_exists = true })
24-
box.schema.user.create('emptyPassword', { password = '', if_not_exists = true })
26+
box.schema.user.create('notSetPassword', { if_not_exists = true })
27+
box.schema.user.create('emptyPassword', { password = '', if_not_exists = true })
2528

26-
box.schema.user.create('operator', {password = 'operator', if_not_exists = true })
27-
box.schema.user.grant('operator','read,write,execute','universe', { if_not_exists = true })
28-
box.schema.user.grant('guest','read,write,execute','universe', { if_not_exists = true })
29-
box.schema.user.passwd('admin', 'adminPassword')
29+
box.schema.user.create('operator', {password = 'operator', if_not_exists = true })
30+
box.schema.user.grant('operator','read,write,execute','universe', { if_not_exists = true })
31+
box.schema.user.grant('guest','read,write,execute','universe', { if_not_exists = true })
32+
box.schema.user.passwd('admin', 'adminPassword')
3033
end
3134

3235
local function space_TreeIndexMethods()
33-
space = box.schema.space.create('space_TreeIndexMethods', { if_not_exists = true })
34-
space:create_index('treeIndex', {type='tree', parts={1, 'unsigned'}, if_not_exists = true })
36+
space = box.schema.space.create('space_TreeIndexMethods', { if_not_exists = true })
37+
space:create_index('treeIndex', {type='tree', parts={1, 'unsigned'}, if_not_exists = true })
3538

36-
space:auto_increment{'asdf', 10.1}
37-
space:auto_increment{'zcxv'}
38-
space:auto_increment{2, 3}
39+
space:auto_increment{'asdf', 10.1}
40+
space:auto_increment{'zcxv'}
41+
space:auto_increment{2, 3}
3942
end
4043

4144
box.once('init', init)
@@ -44,21 +47,21 @@ box.once('space_TreeIndexMethods', space_TreeIndexMethods)
4447
local log = require('log')
4548

4649
function log_connect ()
47-
local m = 'Connection. user=' .. box.session.user() .. ' id=' .. box.session.id()
48-
log.info(m)
50+
local m = 'Connection. user=' .. box.session.user() .. ' id=' .. box.session.id()
51+
log.info(m)
4952
end
5053
function log_disconnect ()
51-
local m = 'Disconnection. user=' .. box.session.user() .. ' id=' .. box.session.id()
52-
log.info(m)
54+
local m = 'Disconnection. user=' .. box.session.user() .. ' id=' .. box.session.id()
55+
log.info(m)
5356
end
5457

5558
function log_auth ()
56-
local m = 'Authentication attempt'
57-
log.info(m)
59+
local m = 'Authentication attempt'
60+
log.info(m)
5861
end
5962
function log_auth_ok (user_name)
60-
local m = 'Authenticated user ' .. user_name
61-
log.info(m)
63+
local m = 'Authenticated user ' .. user_name
64+
log.info(m)
6265
end
6366

6467
box.session.on_connect(log_connect)
@@ -67,37 +70,38 @@ box.session.on_auth(log_auth)
6770
box.session.on_auth(log_auth_ok)
6871

6972
function return_null()
70-
log.info('return_null called')
71-
return require('msgpack').NULL
73+
log.info('return_null called')
74+
return require('msgpack').NULL
7275
end
7376

7477
function return_tuple_with_null()
75-
log.info('return_tuple_with_null called')
76-
return { require('msgpack').NULL }
78+
log.info('return_tuple_with_null called')
79+
return { require('msgpack').NULL }
7780
end
7881

7982
function return_tuple()
80-
log.info('return_tuple called')
81-
return { 1, 2 }
83+
log.info('return_tuple called')
84+
return { 1, 2 }
8285
end
8386

8487

8588
function return_array()
86-
log.info('return_array called')
87-
return {{ "abc", "def" }}
89+
log.info('return_array called')
90+
return {{ "abc", "def" }}
8891
end
8992

9093
function return_scalar()
91-
log.info('return_scalar called')
92-
return 1
94+
log.info('return_scalar called')
95+
return 1
9396
end
9497

9598
function return_nothing()
96-
log.info('return_nothing called')
99+
log.info('return_nothing called')
97100
end
98101

99102
local truncate_space = function(name)
100103
local space = box.space[name]
104+
101105
if space then
102106
log.info("Truncating space %s...", name)
103107
space:truncate()
@@ -107,11 +111,9 @@ local truncate_space = function(name)
107111
end
108112
end
109113

110-
function clear_data()
111-
log.info('clearing data...')
112-
113-
truncate_space('primary_only_index')
114-
truncate_space('performance')
115-
truncate_space('primary_and_secondary_index')
116-
truncate_space('space_TreeIndexMethods')
114+
function clear_data(spaceNames)
115+
log.info('clearing data...')
116+
for _, spaceName in ipairs(spaceNames) do
117+
truncate_space(spaceName)
118+
end
117119
end

tests/progaudi.tarantool.tests/Index/Smoke.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class Smoke : TestBase
1414
[Fact]
1515
public async Task HashIndexMethods()
1616
{
17-
await ClearDataAsync();
17+
await ClearDataAsync("primary_only_index");
1818

1919
const string spaceName = "primary_only_index";
2020
using (var tarantoolClient = await Client.Box.Connect(ReplicationSourceFactory.GetReplicationSource()))
@@ -39,10 +39,10 @@ public async Task HashIndexMethods()
3939
await index.Replace(TarantoolTuple.Create(2, "Car", -245.3));
4040
await index.Update<TarantoolTuple<int, string, double>, TarantoolTuple<int>>(
4141
TarantoolTuple.Create(2),
42-
new UpdateOperation[] {UpdateOperation.CreateAddition(100, 2)});
42+
new UpdateOperation[] { UpdateOperation.CreateAddition(100, 2) });
4343

44-
await index.Upsert(TarantoolTuple.Create(6u), new UpdateOperation[] {UpdateOperation.CreateAssign(2, 2)});
45-
await index.Upsert(TarantoolTuple.Create(6u), new UpdateOperation[] {UpdateOperation.CreateAddition(-2, 2)});
44+
await index.Upsert(TarantoolTuple.Create(6u), new UpdateOperation[] { UpdateOperation.CreateAssign(2, 2) });
45+
await index.Upsert(TarantoolTuple.Create(6u), new UpdateOperation[] { UpdateOperation.CreateAddition(-2, 2) });
4646

4747
var result = await index.Select<TarantoolTuple<uint>, TarantoolTuple<uint>>(TarantoolTuple.Create(6u));
4848
result.Data[0].Item1.ShouldBe(6u);
@@ -52,7 +52,7 @@ await index.Update<TarantoolTuple<int, string, double>, TarantoolTuple<int>>(
5252
[Fact]
5353
public async Task TreeIndexMethods()
5454
{
55-
await ClearDataAsync();
55+
await ClearDataAsync("space_TreeIndexMethods");
5656

5757
const string spaceName = "space_TreeIndexMethods";
5858
using (var tarantoolClient = await Client.Box.Connect(ReplicationSourceFactory.GetReplicationSource()))
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// <copyright file="MsgPackTokenTest.cs" company="eVote">
2+
// Copyright © eVote
3+
// </copyright>
4+
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using ProGaudi.MsgPack.Light;
8+
using ProGaudi.Tarantool.Client.Model;
9+
using Shouldly;
10+
using Xunit;
11+
12+
namespace ProGaudi.Tarantool.Client.Tests.Space
13+
{
14+
public class MsgPackTokenTest
15+
: TestBase
16+
{
17+
[Fact]
18+
public async Task Smoke()
19+
{
20+
await ClearDataAsync("with_scalar_index");
21+
22+
const string spaceName = "with_scalar_index";
23+
var clientOptions = new ClientOptions(ReplicationSourceFactory.GetReplicationSource());
24+
using (var tarantoolClient = new Tarantool.Client.Box(clientOptions))
25+
{
26+
await tarantoolClient.Connect();
27+
var schema = tarantoolClient.GetSchema();
28+
29+
var space = await schema.GetSpace(spaceName);
30+
31+
await space.Insert(TarantoolTuple.Create(2f, new[] { 1, 2, 3 }));
32+
await space.Insert(TarantoolTuple.Create(true, "Music"));
33+
await space.Insert(TarantoolTuple.Create(1u, 2f));
34+
await space.Insert(TarantoolTuple.Create("false", (string)null));
35+
36+
var index = await space.GetIndex(0);
37+
var result = await index.Select<TarantoolTuple<bool>, TarantoolTuple<MsgPackToken, MsgPackToken>>(
38+
TarantoolTuple.Create(false),
39+
new SelectOptions
40+
{
41+
Iterator = Model.Enums.Iterator.All
42+
});
43+
44+
result.Data.ShouldNotBeNull();
45+
46+
var data = result.Data;
47+
((bool)data[0].Item1).ShouldBe(true);
48+
((string)data[0].Item2).ShouldBe("Music");
49+
50+
((ulong)data[1].Item1).ShouldBe(1u);
51+
((double)data[1].Item2).ShouldBe(2f);
52+
53+
((double)data[2].Item1).ShouldBe(2f);
54+
((MsgPackToken[])data[2].Item2).Select(t => (int)t).ToArray().ShouldBe(new[] { 1, 2, 3 });
55+
56+
((string)data[3].Item1).ShouldBe("false");
57+
((MsgPackToken[])data[3].Item2).ShouldBe(null);
58+
}
59+
}
60+
}
61+
}

tests/progaudi.tarantool.tests/Space/Upsert_Should.cs

Lines changed: 0 additions & 29 deletions
This file was deleted.

tests/progaudi.tarantool.tests/TestBase.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
using System;
22
using System.Threading.Tasks;
3+
using ProGaudi.Tarantool.Client.Model;
34

45
namespace ProGaudi.Tarantool.Client.Tests
56
{
67
public class TestBase
78
{
8-
public async Task ClearDataAsync()
9+
public async Task ClearDataAsync(params string[] spaceNames)
910
{
1011
using (var tarantoolClient = await Client.Box.Connect(ReplicationSourceFactory.GetReplicationSource("admin:adminPassword")))
1112
{
12-
await tarantoolClient.Call("clear_data");
13+
await tarantoolClient.Call("clear_data", TarantoolTuple.Create(spaceNames));
1314
}
1415
}
1516
}

0 commit comments

Comments
 (0)