Skip to content

Commit b5db485

Browse files
committed
test: add tests for JSON path
Part of #166 Part of #219
1 parent 416d2f7 commit b5db485

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-0
lines changed

test/entrypoint/srv_ddl.lua

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ local log = require('log')
77
local errors = require('errors')
88
local cartridge = require('cartridge')
99
local ddl = require('ddl')
10+
local crud_utils = require('crud.common.utils')
1011

1112
package.preload['customers-storage'] = function()
1213
return {
@@ -110,11 +111,50 @@ package.preload['customers-storage'] = function()
110111
}
111112
}
112113

114+
-- DDL module doesn't support map and array types and JSON path in
115+
-- sharding key, see https://github.com/tarantool/ddl/issues/81,
116+
-- so we create space with jsonpath index manually.
117+
local function create_space_with_jsonpath()
118+
local customers_jsonpath_key = box.schema.space.create('customers_jsonpath_key', {
119+
format = {
120+
{name = 'id', is_nullable = false, type = 'map'},
121+
{name = 'bucket_id', is_nullable = false, type = 'unsigned'},
122+
{name = 'name', is_nullable = false, type = 'string'},
123+
{name = 'age', is_nullable = false, type = 'number'},
124+
{name = 'data', is_nullable = false, type = 'map'},
125+
},
126+
if_not_exists = true,
127+
engine = engine,
128+
})
129+
customers_jsonpath_key:create_index('pk', {
130+
parts = {
131+
{1, 'unsigned', path = 'customer_id.unsigned'},
132+
{5, 'unsigned', path = 'customer.weight'},
133+
},
134+
if_not_exists = true,
135+
})
136+
customers_jsonpath_key:create_index('bucket_id', {
137+
parts = { 'bucket_id' },
138+
unique = false,
139+
if_not_exists = true,
140+
})
141+
box.space['_ddl_sharding_key']:insert({
142+
'customers_jsonpath_key',
143+
{'name'}
144+
})
145+
end
146+
113147
if not box.info.ro then
114148
local ok, err = ddl.set_schema(schema)
115149
if not ok then
116150
error(err)
117151
end
152+
if crud_utils.tarantool_supports_jsonpath_indexes() then
153+
local ok, err = pcall(create_space_with_jsonpath)
154+
if not ok then
155+
error(err)
156+
end
157+
end
118158
end
119159

120160
rawset(_G, 'set_sharding_key', function(space_name, sharding_key_def)

test/integration/ddl_sharding_key_test.lua

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
local fio = require('fio')
22
local crud = require('crud')
3+
local crud_utils = require('crud.common.utils')
34
local t = require('luatest')
45

56
local helpers = require('test.helper')
@@ -43,6 +44,9 @@ pgroup.before_each(function(g)
4344
helpers.truncate_space_on_cluster(g.cluster, 'customers_name_key_non_uniq_index')
4445
helpers.truncate_space_on_cluster(g.cluster, 'customers_secondary_idx_name_key')
4546
helpers.truncate_space_on_cluster(g.cluster, 'customers_age_key')
47+
if crud_utils.tarantool_supports_jsonpath_indexes() then
48+
helpers.truncate_space_on_cluster(g.cluster, 'customers_jsonpath_key')
49+
end
4650
end)
4751

4852
local function check_get(g, space_name, id, name)
@@ -569,3 +573,81 @@ pgroup.test_update_sharding_keys_cache = function(g)
569573
sharding_key = helpers.update_sharding_keys_cache(g.cluster, space_name)
570574
t.assert_equals(sharding_key, {'name'})
571575
end
576+
577+
pgroup.test_jsonpath_insert = function(g)
578+
t.skip('JSONpath is unsupported, see issue #219')
579+
580+
local space_name = 'customers_jsonpath_key'
581+
local customers = helpers.insert_objects(g, space_name, {
582+
{
583+
id = {customer_id = {unsigned = 1}},
584+
name = 'Viktor Pelevin',
585+
age = 58,
586+
data = {customer = {weight = 82}},
587+
},
588+
{
589+
id = {customer_id = {unsigned = 2}},
590+
name = 'Isaac Asimov',
591+
age = 72,
592+
data = {customer = {weight = 70}},
593+
},
594+
{
595+
id = {customer_id = {unsigned = 3}},
596+
name = 'Aleksandr Solzhenitsyn',
597+
age = 89,
598+
data = {customer = {weight = 78}},
599+
},
600+
{
601+
id = {customer_id = {unsigned = 4}},
602+
name = 'James Joyce',
603+
age = 59,
604+
data = {customer = {weight = 82}},
605+
},
606+
{
607+
id = {customer_id = {unsigned = 5}},
608+
name = 'Oscar Wilde',
609+
age = 46,
610+
data = {customer = {weight = 79}},
611+
},
612+
})
613+
t.assert_equals(#customers, 5)
614+
end
615+
616+
pgroup.test_jsonpath_delete = function(g)
617+
t.skip('JSONpath is unsupported, see issue #219')
618+
619+
local space_name = 'customers_jsonpath_key'
620+
local customers = helpers.insert_objects(g, space_name, {
621+
{
622+
id = {customer_id = {unsigned = 1}},
623+
name = 'Viktor Pelevin',
624+
age = 58,
625+
data = {customer = {weight = 82}},
626+
},
627+
{
628+
id = {customer_id = {unsigned = 2}},
629+
name = 'Isaac Asimov',
630+
age = 72,
631+
data = {customer = {weight = 70}},
632+
},
633+
{
634+
id = {customer_id = {unsigned = 3}},
635+
name = 'Aleksandr Solzhenitsyn',
636+
age = 89,
637+
data = {customer = {weight = 78}},
638+
},
639+
{
640+
id = {customer_id = {unsigned = 4}},
641+
name = 'James Joyce',
642+
age = 59,
643+
data = {customer = {weight = 82}},
644+
},
645+
{
646+
id = {customer_id = {unsigned = 5}},
647+
name = 'Oscar Wilde',
648+
age = 46,
649+
data = {customer = {weight = 79}},
650+
},
651+
})
652+
t.assert_equals(#customers, 5)
653+
end

0 commit comments

Comments
 (0)