Skip to content

Commit

Permalink
Merge pull request #102 from progaudi/feature/msgpacktoken-test
Browse files Browse the repository at this point in the history
Feature/msgpacktoken test
  • Loading branch information
roman-kozachenko authored Mar 21, 2017
2 parents 637a720 + 6660446 commit b539c65
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 85 deletions.
100 changes: 51 additions & 49 deletions tarantool/tarantool.lua
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
Expand All @@ -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()
Expand All @@ -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
10 changes: 5 additions & 5 deletions tests/progaudi.tarantool.tests/Index/Smoke.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class Smoke : TestBase
[Fact]
public async Task HashIndexMethods()
{
await ClearDataAsync();
await ClearDataAsync("primary_only_index");

const string spaceName = "primary_only_index";
using (var tarantoolClient = await Client.Box.Connect(ReplicationSourceFactory.GetReplicationSource()))
Expand All @@ -39,10 +39,10 @@ public async Task HashIndexMethods()
await index.Replace(TarantoolTuple.Create(2, "Car", -245.3));
await index.Update<TarantoolTuple<int, string, double>, TarantoolTuple<int>>(
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<uint>, TarantoolTuple<uint>>(TarantoolTuple.Create(6u));
result.Data[0].Item1.ShouldBe(6u);
Expand All @@ -52,7 +52,7 @@ await index.Update<TarantoolTuple<int, string, double>, TarantoolTuple<int>>(
[Fact]
public async Task TreeIndexMethods()
{
await ClearDataAsync();
await ClearDataAsync("space_TreeIndexMethods");

const string spaceName = "space_TreeIndexMethods";
using (var tarantoolClient = await Client.Box.Connect(ReplicationSourceFactory.GetReplicationSource()))
Expand Down
61 changes: 61 additions & 0 deletions tests/progaudi.tarantool.tests/Space/MsgPackTokenTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// <copyright file="MsgPackTokenTest.cs" company="eVote">
// Copyright © eVote
// </copyright>

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("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<bool>, TarantoolTuple<MsgPackToken, MsgPackToken>>(
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);
}
}
}
}
29 changes: 0 additions & 29 deletions tests/progaudi.tarantool.tests/Space/Upsert_Should.cs

This file was deleted.

5 changes: 3 additions & 2 deletions tests/progaudi.tarantool.tests/TestBase.cs
Original file line number Diff line number Diff line change
@@ -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(params 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));
}
}
}
Expand Down

0 comments on commit b539c65

Please sign in to comment.