Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Commit 9d342b9

Browse files
committed
Support avro-schema-3* (updated tests)
Changed only tests where a data layout is different between avro-schema-2* and avro-schema-3*. The avro_refs test triggers a flatten bug in avro-schema-2.3.2, so the data flattened manually in the case. The bug is not reported, because it is recomended to move to avro-schema-3* to use record*. Fixes #150.
1 parent 2b972dd commit 9d342b9

14 files changed

+368
-136
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ dist: trusty
77
env:
88
- SHARD_VERSION=1.2 AVRO_SCHEMA=2.3.2
99
- SHARD_VERSION=2.1 AVRO_SCHEMA=2.3.2
10+
- SHARD_VERSION=1.2 AVRO_SCHEMA=3.0.0
11+
- SHARD_VERSION=2.1 AVRO_SCHEMA=3.0.0
1012

1113
branches:
1214
only:

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ make test
155155
* For use:
156156
* tarantool,
157157
* lulpeg,
158-
* >=tarantool/avro-schema-2.0-71-gfea0ead (but < 3.0.0),
158+
* >=tarantool/avro-schema-2.0-71-gfea0ead,
159159
* >=tarantool/shard-1.1-91-gfa88bf8 (but < 2.0) or
160160
>=tarantool/shard-2.1-0-g0a7d98f (optional),
161161
* lrexlib-pcre2 or lrexlib-pcre (optional),
@@ -164,7 +164,7 @@ make test
164164
* python 2.7,
165165
* virtualenv,
166166
* luacheck,
167-
* >=tarantool/avro-schema-2.2.2-4-g1145e3e (but < 3.0.0),
167+
* >=tarantool/avro-schema-2.2.2-4-g1145e3e,
168168
* >=tarantool/shard-1.1-92-gec1a27e (but < 2.0) or
169169
>=tarantool/shard-2.1-0-g0a7d98f,
170170
* tarantool/http.

test/common/multirunner.lua

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,17 @@ local function run_conf(conf_name, opts)
110110

111111
local test_run = opts.test_run
112112
local init_function = opts.init_function
113+
local init_function_params = opts.init_function_params or {}
113114
local cleanup_function = opts.cleanup_function
115+
local cleanup_function_params = opts.cleanup_function_params or {}
114116
local workload = opts.workload
115117
local servers = opts.servers or servers -- prefer opts.servers
116118
local use_tcp = opts.use_tcp or false
117119

118120
assert(init_function ~= nil)
121+
assert(type(init_function_params) == 'table')
119122
assert(cleanup_function ~= nil)
123+
assert(type(cleanup_function_params) == 'table')
120124
assert(workload ~= nil)
121125
assert(use_tcp ~= nil)
122126
if conf_type == 'shard' then
@@ -127,9 +131,9 @@ local function run_conf(conf_name, opts)
127131
local result
128132

129133
if conf_type == 'space' then
130-
init_function()
134+
init_function(unpack(init_function_params))
131135
result = workload(conf_name, nil)
132-
cleanup_function()
136+
cleanup_function(unpack(cleanup_function_params))
133137
elseif conf_type == 'shard' then
134138
-- convert functions to string, so, that it can be executed on shards
135139
local init_script = string.dump(init_function)
@@ -139,14 +143,14 @@ local function run_conf(conf_name, opts)
139143

140144
for_each_server(shard, function(uri)
141145
local c = net_box.connect(uri)
142-
c:eval(init_script)
146+
c:eval(init_script, init_function_params)
143147
end)
144148

145149
result = workload(conf_name, shard)
146150

147151
for_each_server(shard, function(uri)
148152
local c = net_box.connect(uri)
149-
c:eval(cleanup_script)
153+
c:eval(cleanup_script, cleanup_function_params)
150154
end)
151155

152156
shard_cleanup(test_run, servers)

test/extra/to_avro_nested.test.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ box.cfg{wal_mode="none"}
1717
test:plan(4)
1818

1919
data.init_spaces()
20-
data.fill_test_data(box.space)
20+
data.fill_test_data(box.space, data.meta)
2121

2222
local accessor = graphql.accessor_space.new({
2323
schemas = data.meta.schemas,

test/extra/to_avro_nullable.test.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ box.cfg{wal_mode="none"}
1616
test:plan(4)
1717

1818
testdata.init_spaces()
19-
testdata.fill_test_data()
2019
local meta = testdata.get_test_metadata()
20+
testdata.fill_test_data(box.space, meta)
2121

2222
local accessor = graphql.accessor_space.new({
2323
schemas = meta.schemas,

test/space/nested_args.test.lua

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ local tap = require('tap')
1111
local yaml = require('yaml')
1212
local graphql = require('graphql')
1313
local utils = require('graphql.utils')
14+
local test_utils = require('test.utils')
1415
local common_testdata = require('test.testdata.common_testdata')
1516
local emails_testdata = require('test.testdata.nullable_1_1_conn_testdata')
1617

@@ -23,12 +24,16 @@ common_testdata.init_spaces()
2324
emails_testdata.init_spaces()
2425

2526
-- upload test data
26-
common_testdata.fill_test_data()
27-
emails_testdata.fill_test_data()
27+
local common_meta = common_testdata.meta or common_testdata.get_test_metadata()
28+
local emails_meta = emails_testdata.meta or emails_testdata.get_test_metadata()
29+
common_testdata.fill_test_data(box.space, common_meta)
30+
emails_testdata.fill_test_data(box.space, emails_meta)
31+
32+
local avro_version = test_utils.major_avro_schema_version()
2833

2934
local LOCALPART_FN = 1
3035
local DOMAIN_FN = 2
31-
local BODY_FN = 7
36+
local BODY_FN = avro_version == 3 and 5 or 7
3237

3338
for _, tuple in box.space.email:pairs() do
3439
local body = tuple[BODY_FN]

test/space/server.test.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ box.cfg{background = false}
1818
testdata.init_spaces()
1919

2020
-- upload test data
21-
testdata.fill_test_data()
21+
local meta = testdata.meta or testdata.get_test_metadata()
22+
testdata.fill_test_data(box.space, meta)
2223

2324
-- acquire metadata
2425
local metadata = testdata.get_test_metadata()

test/space/unflatten_tuple.test.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ local testdata = require('test.testdata.common_testdata')
2121
box.cfg{background = false}
2222
testdata.init_spaces()
2323

24-
-- upload test data
25-
testdata.fill_test_data()
26-
2724
-- acquire metadata
2825
local metadata = testdata.get_test_metadata()
2926
local schemas = metadata.schemas
3027
local collections = metadata.collections
3128
local service_fields = metadata.service_fields
3229
local indexes = metadata.indexes
3330

31+
-- upload test data
32+
testdata.fill_test_data(box.space, metadata)
33+
3434
-- build accessor and graphql schemas
3535
-- ----------------------------------
3636

test/testdata/avro_refs_testdata.lua

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ local tap = require('tap')
88
local json = require('json')
99
local yaml = require('yaml')
1010
local utils = require('graphql.utils')
11+
local test_utils = require('test.utils')
1112

1213
local testdata = {}
1314

@@ -94,25 +95,51 @@ function testdata.drop_spaces()
9495
box.space.foo:drop()
9596
end
9697

97-
function testdata.fill_test_data(virtbox)
98-
local NULL_T = 0
99-
local VALUE_T = 1
100-
98+
function testdata.fill_test_data(virtbox, meta)
10199
local x = 1000
102100
local y = 2000
103101
local a = 3000
104102
local b = 4000
105103

106-
-- non-null bar, baz and its refs
107-
virtbox.foo:replace({1, -- id
108-
x, y, x, y, VALUE_T, {x, y}, -- bar & refs
109-
VALUE_T, {a, b}, a, b, VALUE_T, {a, b}, -- baz & refs
110-
})
111-
-- null in nullable bar, baz refs
112-
virtbox.foo:replace({2, -- id
113-
x, y, x, y, NULL_T, box.NULL, -- bar & refs
114-
NULL_T, box.NULL, a, b, NULL_T, box.NULL, -- baz & refs
115-
})
104+
local avro_version = test_utils.major_avro_schema_version()
105+
106+
if avro_version == 3 then
107+
-- non-null bar, baz and its refs
108+
test_utils.replace_object(virtbox, meta, 'foo', {
109+
id = 1,
110+
bar = {x = x, y = y},
111+
bar_ref = {x = x, y = y},
112+
bar_nref = {x = x, y = y},
113+
baz = {x = a, y = b},
114+
baz_ref = {x = a, y = b},
115+
baz_nref = {x = a, y = b},
116+
})
117+
-- null in nullable bar, baz refs
118+
test_utils.replace_object(virtbox, meta, 'foo', {
119+
id = 2,
120+
bar = {x = x, y = y},
121+
bar_ref = {x = x, y = y},
122+
bar_nref = box.NULL,
123+
baz = box.NULL,
124+
baz_ref = {x = a, y = b},
125+
baz_nref = box.NULL,
126+
})
127+
else
128+
-- flatten does not work properly in the case of avro-schema-2.3.2
129+
local NULL_T = 0
130+
local VALUE_T = 1
131+
132+
-- non-null bar, baz and its refs
133+
virtbox.foo:replace({1, -- id
134+
x, y, x, y, VALUE_T, {x, y}, -- bar & refs
135+
VALUE_T, {a, b}, a, b, VALUE_T, {a, b}, -- baz & refs
136+
})
137+
-- null in nullable bar, baz refs
138+
virtbox.foo:replace({2, -- id
139+
x, y, x, y, NULL_T, box.NULL, -- bar & refs
140+
NULL_T, box.NULL, a, b, NULL_T, box.NULL, -- baz & refs
141+
})
142+
end
116143
end
117144

118145
function testdata.run_queries(gql_wrapper)

test/testdata/common_testdata.lua

Lines changed: 73 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -151,41 +151,88 @@ function common_testdata.init_spaces()
151151
end)
152152
end
153153

154-
function common_testdata.fill_test_data(shard)
155-
local shard = shard or box.space
156-
157-
local NULL_T = 0
158-
local STRING_T = 1
159-
160-
shard.user_collection:replace(
161-
{1827767717, 'user_id_1', 'Ivan', STRING_T, 'Ivanovich', 'Ivanov'})
162-
shard.user_collection:replace(
163-
{1827767717, 'user_id_2', 'Vasiliy', NULL_T, box.NULL, 'Pupkin'})
164-
shard.order_collection:replace(
165-
{'order_id_1', 'user_id_1', 'first order of Ivan', 0, 0, true})
166-
shard.order_collection:replace(
167-
{'order_id_2', 'user_id_1', 'second order of Ivan', 0, 0, false})
168-
shard.order_collection:replace(
169-
{'order_id_3', 'user_id_2', 'first order of Vasiliy', 0, 0, true})
154+
function common_testdata.fill_test_data(virtbox, meta)
155+
test_utils.replace_object(virtbox, meta, 'user_collection', {
156+
user_id = 'user_id_1',
157+
first_name = 'Ivan',
158+
middle_name = 'Ivanovich',
159+
last_name = 'Ivanov',
160+
}, {
161+
1827767717,
162+
})
163+
test_utils.replace_object(virtbox, meta, 'user_collection', {
164+
user_id = 'user_id_2',
165+
first_name = 'Vasiliy',
166+
middle_name = box.NULL,
167+
last_name = 'Pupkin',
168+
}, {
169+
1827767717,
170+
})
171+
172+
test_utils.replace_object(virtbox, meta, 'order_collection', {
173+
order_id = 'order_id_1',
174+
user_id = 'user_id_1',
175+
description = 'first order of Ivan',
176+
price = 0,
177+
discount = 0,
178+
in_stock = true,
179+
})
180+
test_utils.replace_object(virtbox, meta, 'order_collection', {
181+
order_id = 'order_id_2',
182+
user_id = 'user_id_1',
183+
description = 'second order of Ivan',
184+
price = 0,
185+
discount = 0,
186+
in_stock = false,
187+
})
188+
test_utils.replace_object(virtbox, meta, 'order_collection', {
189+
order_id = 'order_id_3',
190+
user_id = 'user_id_2',
191+
description = 'first order of Vasiliy',
192+
price = 0,
193+
discount = 0,
194+
in_stock = true,
195+
})
170196

171197
for i = 3, 100 do
172198
local s = tostring(i)
173-
shard.user_collection:replace(
174-
{1827767717, 'user_id_' .. s, 'first name ' .. s, NULL_T, box.NULL,
175-
'last name ' .. s})
199+
test_utils.replace_object(virtbox, meta, 'user_collection', {
200+
user_id = 'user_id_' .. s,
201+
first_name = 'first name ' .. s,
202+
middle_name = box.NULL,
203+
last_name = 'last name ' .. s,
204+
}, {
205+
1827767717,
206+
})
176207
for j = (4 + (i - 3) * 40), (4 + (i - 2) * 40) - 1 do
177208
local t = tostring(j)
178-
shard.order_collection:replace({
179-
'order_id_' .. t, 'user_id_' .. s, 'order of user ' .. s,
180-
i + j / 3, i + j / 3, j % 2 == 1,
209+
test_utils.replace_object(virtbox, meta, 'order_collection', {
210+
order_id = 'order_id_' .. t,
211+
user_id = 'user_id_' .. s,
212+
description = 'order of user ' .. s,
213+
price = i + j / 3,
214+
discount = i + j / 3,
215+
in_stock = j % 2 == 1,
181216
})
182217
end
183218
end
184219

185-
shard.user_collection:replace(
186-
{1827767717, 'user_id_101', 'Иван', STRING_T, 'Иванович', 'Иванов'})
187-
shard.order_collection:replace(
188-
{'order_id_3924', 'user_id_101', 'Покупка 3924', 0, 0, true})
220+
test_utils.replace_object(virtbox, meta, 'user_collection', {
221+
user_id = 'user_id_101',
222+
first_name = 'Иван',
223+
middle_name = 'Иванович',
224+
last_name = 'Иванов',
225+
}, {
226+
1827767717,
227+
})
228+
test_utils.replace_object(virtbox, meta, 'order_collection', {
229+
order_id = 'order_id_3924',
230+
user_id = 'user_id_101',
231+
description = 'Покупка 3924',
232+
price = 0,
233+
discount = 0,
234+
in_stock = true,
235+
})
189236
end
190237

191238
function common_testdata.drop_spaces()

test/testdata/nested_record_testdata.lua

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ local tap = require('tap')
66
local json = require('json')
77
local yaml = require('yaml')
88
local utils = require('graphql.utils')
9+
local test_utils = require('test.utils')
910

1011
local testdata = {}
1112

@@ -68,14 +69,22 @@ function testdata.drop_spaces()
6869
box.space.user:drop()
6970
end
7071

71-
function testdata.fill_test_data(virtbox)
72+
function testdata.fill_test_data(virtbox, meta)
7273
for i = 1, 15 do
7374
local uid = i
7475
local p1 = 'p1 ' .. tostring(i)
7576
local p2 = 'p2 ' .. tostring(i)
7677
local x = 1000 + i
7778
local y = 2000 + i
78-
virtbox.user:replace({uid, p1, p2, x, y})
79+
test_utils.replace_object(virtbox, meta, 'user', {
80+
uid = uid,
81+
p1 = p1,
82+
p2 = p2,
83+
nested = {
84+
x = x,
85+
y = y,
86+
}
87+
})
7988
end
8089
end
8190

0 commit comments

Comments
 (0)