Skip to content

Commit

Permalink
test: add tests for JSON path
Browse files Browse the repository at this point in the history
Part of #166
Part of #219
  • Loading branch information
ligurio committed Oct 1, 2021
1 parent f75fbdf commit 0df99f7
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 0 deletions.
40 changes: 40 additions & 0 deletions test/entrypoint/srv_ddl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ local log = require('log')
local errors = require('errors')
local cartridge = require('cartridge')
local ddl = require('ddl')
local crud_utils = require('crud.common.utils')

package.preload['customers-storage'] = function()
return {
Expand Down Expand Up @@ -110,11 +111,50 @@ package.preload['customers-storage'] = function()
}
}

-- DDL module doesn't support map and array types and JSON path in
-- sharding key, see https://github.com/tarantool/ddl/issues/81,
-- so we create space with jsonpath index manually.
local function create_space_with_jsonpath()
local customers_jsonpath_key = box.schema.space.create('customers_jsonpath_key', {
format = {
{name = 'id', is_nullable = false, type = 'map'},
{name = 'bucket_id', is_nullable = false, type = 'unsigned'},
{name = 'name', is_nullable = false, type = 'string'},
{name = 'age', is_nullable = false, type = 'number'},
{name = 'data', is_nullable = false, type = 'map'},
},
if_not_exists = true,
engine = engine,
})
customers_jsonpath_key:create_index('pk', {
parts = {
{1, 'unsigned', path = 'customer_id.unsigned'},
{5, 'unsigned', path = 'customer.weight'},
},
if_not_exists = true,
})
customers_jsonpath_key:create_index('bucket_id', {
parts = { 'bucket_id' },
unique = false,
if_not_exists = true,
})
box.space['_ddl_sharding_key']:insert({
'customers_jsonpath_key',
{'name'}
})
end

if not box.info.ro then
local ok, err = ddl.set_schema(schema)
if not ok then
error(err)
end
if crud_utils.tarantool_supports_jsonpath_indexes() then
local ok, err = pcall(create_space_with_jsonpath)
if not ok then
error(err)
end
end
end

rawset(_G, 'set_sharding_key', function(space_name, sharding_key_def)
Expand Down
82 changes: 82 additions & 0 deletions test/integration/ddl_sharding_key_test.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local fio = require('fio')
local crud = require('crud')
local crud_utils = require('crud.common.utils')
local t = require('luatest')

local helpers = require('test.helper')
Expand Down Expand Up @@ -43,6 +44,9 @@ pgroup.before_each(function(g)
helpers.truncate_space_on_cluster(g.cluster, 'customers_name_key_non_uniq_index')
helpers.truncate_space_on_cluster(g.cluster, 'customers_secondary_idx_name_key')
helpers.truncate_space_on_cluster(g.cluster, 'customers_age_key')
if crud_utils.tarantool_supports_jsonpath_indexes() then
helpers.truncate_space_on_cluster(g.cluster, 'customers_jsonpath_key')
end
end)

local function check_get(g, space_name, id, name)
Expand Down Expand Up @@ -569,3 +573,81 @@ pgroup.test_update_cache = function(g)
sharding_key_as_index_obj = helpers.update_cache(g.cluster, space_name)
t.assert_equals(sharding_key_as_index_obj, {parts = {{fieldno = 3}}})
end

pgroup.test_jsonpath_insert = function(g)
t.skip('JSONpath is unsupported, see issue #219')

local space_name = 'customers_jsonpath_key'
local customers = helpers.insert_objects(g, space_name, {
{
id = {customer_id = {unsigned = 1}},
name = 'Viktor Pelevin',
age = 58,
data = {customer = {weight = 82}},
},
{
id = {customer_id = {unsigned = 2}},
name = 'Isaac Asimov',
age = 72,
data = {customer = {weight = 70}},
},
{
id = {customer_id = {unsigned = 3}},
name = 'Aleksandr Solzhenitsyn',
age = 89,
data = {customer = {weight = 78}},
},
{
id = {customer_id = {unsigned = 4}},
name = 'James Joyce',
age = 59,
data = {customer = {weight = 82}},
},
{
id = {customer_id = {unsigned = 5}},
name = 'Oscar Wilde',
age = 46,
data = {customer = {weight = 79}},
},
})
t.assert_equals(#customers, 5)
end

pgroup.test_jsonpath_delete = function(g)
t.skip('JSONpath is unsupported, see issue #219')

local space_name = 'customers_jsonpath_key'
local customers = helpers.insert_objects(g, space_name, {
{
id = {customer_id = {unsigned = 1}},
name = 'Viktor Pelevin',
age = 58,
data = {customer = {weight = 82}},
},
{
id = {customer_id = {unsigned = 2}},
name = 'Isaac Asimov',
age = 72,
data = {customer = {weight = 70}},
},
{
id = {customer_id = {unsigned = 3}},
name = 'Aleksandr Solzhenitsyn',
age = 89,
data = {customer = {weight = 78}},
},
{
id = {customer_id = {unsigned = 4}},
name = 'James Joyce',
age = 59,
data = {customer = {weight = 82}},
},
{
id = {customer_id = {unsigned = 5}},
name = 'Oscar Wilde',
age = 46,
data = {customer = {weight = 79}},
},
})
t.assert_equals(#customers, 5)
end

0 comments on commit 0df99f7

Please sign in to comment.