Skip to content

Commit d94bc20

Browse files
test: wait for schema bootstrap
The approach is similar to crud bootstrap waiting. Cartridge tests approach remains the same. Part of #412 Part of #415
1 parent fa256c4 commit d94bc20

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1388
-1210
lines changed

test/entrypoint/srv_batch_operations/cartridge_init.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require('strict').on()
44
_G.is_initialized = function() return false end
55

6+
local fio = require('fio')
67
local log = require('log')
78
local errors = require('errors')
89
local cartridge = require('cartridge')
@@ -13,10 +14,13 @@ else
1314
package.path = package.path .. debug.sourcedir() .. "/?.lua;"
1415
end
1516

17+
local root = fio.dirname(fio.dirname(fio.dirname(debug.sourcedir())))
18+
package.path = package.path .. root .. "/?.lua;"
19+
1620
package.preload['customers-storage'] = function()
1721
return {
1822
role_name = 'customers-storage',
19-
init = require('storage_init'),
23+
init = require('storage').init,
2024
}
2125
end
2226

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
local helper = require('test.helper')
2+
3+
return {
4+
init = helper.wrap_schema_init(function()
5+
local engine = os.getenv('ENGINE') or 'memtx'
6+
local customers_space = box.schema.space.create('customers', {
7+
format = {
8+
{name = 'id', type = 'unsigned'},
9+
{name = 'bucket_id', type = 'unsigned'},
10+
{name = 'name', type = 'string'},
11+
{name = 'age', type = 'number'},
12+
},
13+
if_not_exists = true,
14+
engine = engine,
15+
})
16+
customers_space:create_index('id', {
17+
parts = { {field = 'id'} },
18+
if_not_exists = true,
19+
})
20+
customers_space:create_index('bucket_id', {
21+
parts = { {field = 'bucket_id'} },
22+
unique = false,
23+
if_not_exists = true,
24+
})
25+
26+
local developers_space = box.schema.space.create('developers', {
27+
format = {
28+
{name = 'id', type = 'unsigned'},
29+
{name = 'bucket_id', type = 'unsigned'},
30+
{name = 'name', type = 'string'},
31+
{name = 'login', type = 'string'},
32+
},
33+
if_not_exists = true,
34+
engine = engine,
35+
})
36+
developers_space:create_index('id', {
37+
parts = { {field = 'id'} },
38+
if_not_exists = true,
39+
})
40+
developers_space:create_index('bucket_id', {
41+
parts = { {field = 'bucket_id'} },
42+
unique = false,
43+
if_not_exists = true,
44+
})
45+
developers_space:create_index('login', {
46+
parts = { {field = 'login'} },
47+
unique = true,
48+
if_not_exists = true,
49+
})
50+
end),
51+
wait_until_ready = helper.wait_schema_init,
52+
}

test/entrypoint/srv_batch_operations/storage_init.lua

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

test/entrypoint/srv_ddl/cartridge_init.lua

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require('strict').on()
44
_G.is_initialized = function() return false end
55

6+
local fio = require('fio')
67
local log = require('log')
78
local errors = require('errors')
89
local cartridge = require('cartridge')
@@ -13,12 +14,13 @@ else
1314
package.path = package.path .. debug.sourcedir() .. "/?.lua;"
1415
end
1516

17+
local root = fio.dirname(fio.dirname(fio.dirname(debug.sourcedir())))
18+
package.path = package.path .. root .. "/?.lua;"
19+
1620
package.preload['customers-storage'] = function()
17-
-- set sharding func in dot.notation
18-
-- in _G for sharding func tests
1921
return {
2022
role_name = 'customers-storage',
21-
init = require('storage_init'),
23+
init = require('storage').init,
2224
}
2325
end
2426

@@ -43,4 +45,6 @@ if not ok then
4345
os.exit(1)
4446
end
4547

48+
require('router').init()
49+
4650
_G.is_initialized = cartridge.is_healthy

test/entrypoint/srv_ddl/router.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
local some_module = {
2+
sharding_func = function(key)
3+
if key ~= nil and key[1] ~= nil then
4+
return key[1] % 10
5+
end
6+
end
7+
}
8+
9+
return {
10+
init = function()
11+
rawset(_G, 'some_module', some_module)
12+
end,
13+
}

test/entrypoint/srv_ddl/router_init.lua

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

test/entrypoint/srv_ddl/storage.lua

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
local ddl = require('ddl')
2+
local helper = require('test.helper')
3+
4+
local some_module = {
5+
sharding_func = function(key)
6+
if key ~= nil and key[1] ~= nil then
7+
return key[1] % 10
8+
end
9+
end
10+
}
11+
12+
return {
13+
init = function()
14+
rawset(_G, 'some_module', some_module)
15+
16+
local engine = os.getenv('ENGINE') or 'memtx'
17+
local customers_schema = {
18+
engine = engine,
19+
is_local = true,
20+
temporary = false,
21+
format = {
22+
{name = 'id', is_nullable = false, type = 'unsigned'},
23+
{name = 'bucket_id', is_nullable = false, type = 'unsigned'},
24+
{name = 'name', is_nullable = false, type = 'string'},
25+
{name = 'age', is_nullable = false, type = 'number'},
26+
},
27+
indexes = {
28+
-- This table is intentionally blank.
29+
},
30+
}
31+
32+
local primary_index = {
33+
name = 'id',
34+
type = 'TREE',
35+
unique = true,
36+
parts = {
37+
{path = 'id', is_nullable = false, type = 'unsigned'},
38+
{path = 'name', is_nullable = false, type = 'string'},
39+
},
40+
}
41+
local primary_index_id = {
42+
name = 'id',
43+
type = 'TREE',
44+
unique = true,
45+
parts = {
46+
{path = 'id', is_nullable = false, type = 'unsigned'},
47+
},
48+
}
49+
local bucket_id_index = {
50+
name = 'bucket_id',
51+
type = 'TREE',
52+
unique = false,
53+
parts = {
54+
{path = 'bucket_id', is_nullable = false, type = 'unsigned'},
55+
}
56+
}
57+
local name_index = {
58+
name = 'name',
59+
type = 'TREE',
60+
unique = true,
61+
parts = {
62+
{path = 'name', is_nullable = false, type = 'string'},
63+
},
64+
}
65+
local age_index = {
66+
name = 'age',
67+
type = 'TREE',
68+
unique = false,
69+
parts = {
70+
{path = 'age', is_nullable = false, type = 'number'},
71+
},
72+
}
73+
local secondary_index = {
74+
name = 'secondary',
75+
type = 'TREE',
76+
unique = false,
77+
parts = {
78+
{path = 'id', is_nullable = false, type = 'unsigned'},
79+
{path = 'name', is_nullable = false, type = 'string'},
80+
},
81+
}
82+
83+
local three_fields_index = {
84+
name = 'three_fields',
85+
type = 'TREE',
86+
unique = false,
87+
parts = {
88+
{path = 'age', is_nullable = false, type = 'number'},
89+
{path = 'name', is_nullable = false, type = 'string'},
90+
{path = 'id', is_nullable = false, type = 'unsigned'},
91+
},
92+
}
93+
94+
local customers_id_schema = table.deepcopy(customers_schema)
95+
customers_id_schema.sharding_key = {'id'}
96+
table.insert(customers_id_schema.indexes, primary_index_id)
97+
table.insert(customers_id_schema.indexes, bucket_id_index)
98+
table.insert(customers_id_schema.indexes, age_index)
99+
100+
local customers_name_key_schema = table.deepcopy(customers_schema)
101+
customers_name_key_schema.sharding_key = {'name'}
102+
table.insert(customers_name_key_schema.indexes, primary_index)
103+
table.insert(customers_name_key_schema.indexes, bucket_id_index)
104+
105+
local customers_name_key_uniq_index_schema = table.deepcopy(customers_schema)
106+
customers_name_key_uniq_index_schema.sharding_key = {'name'}
107+
table.insert(customers_name_key_uniq_index_schema.indexes, primary_index)
108+
table.insert(customers_name_key_uniq_index_schema.indexes, bucket_id_index)
109+
table.insert(customers_name_key_uniq_index_schema.indexes, name_index)
110+
111+
local customers_name_key_non_uniq_index_schema = table.deepcopy(customers_schema)
112+
customers_name_key_non_uniq_index_schema.sharding_key = {'name'}
113+
name_index.unique = false
114+
table.insert(customers_name_key_non_uniq_index_schema.indexes, primary_index)
115+
table.insert(customers_name_key_non_uniq_index_schema.indexes, bucket_id_index)
116+
table.insert(customers_name_key_non_uniq_index_schema.indexes, name_index)
117+
118+
local customers_secondary_idx_name_key_schema = table.deepcopy(customers_schema)
119+
customers_secondary_idx_name_key_schema.sharding_key = {'name'}
120+
table.insert(customers_secondary_idx_name_key_schema.indexes, primary_index_id)
121+
table.insert(customers_secondary_idx_name_key_schema.indexes, secondary_index)
122+
table.insert(customers_secondary_idx_name_key_schema.indexes, bucket_id_index)
123+
124+
local customers_age_key_schema = table.deepcopy(customers_schema)
125+
customers_age_key_schema.sharding_key = {'age'}
126+
table.insert(customers_age_key_schema.indexes, primary_index)
127+
table.insert(customers_age_key_schema.indexes, bucket_id_index)
128+
129+
local customers_name_age_key_different_indexes_schema = table.deepcopy(customers_schema)
130+
customers_name_age_key_different_indexes_schema.sharding_key = {'name', 'age'}
131+
table.insert(customers_name_age_key_different_indexes_schema.indexes, primary_index)
132+
table.insert(customers_name_age_key_different_indexes_schema.indexes, bucket_id_index)
133+
table.insert(customers_name_age_key_different_indexes_schema.indexes, age_index)
134+
135+
local customers_name_age_key_three_fields_index_schema = table.deepcopy(customers_schema)
136+
customers_name_age_key_three_fields_index_schema.sharding_key = {'name', 'age'}
137+
table.insert(customers_name_age_key_three_fields_index_schema.indexes, primary_index_id)
138+
table.insert(customers_name_age_key_three_fields_index_schema.indexes, bucket_id_index)
139+
table.insert(customers_name_age_key_three_fields_index_schema.indexes, three_fields_index)
140+
141+
local customers_id_key_schema = table.deepcopy(customers_schema)
142+
customers_id_key_schema.sharding_key = {'id'}
143+
table.insert(customers_id_key_schema.indexes, primary_index)
144+
table.insert(customers_id_key_schema.indexes, bucket_id_index)
145+
table.insert(customers_id_key_schema.indexes, name_index)
146+
147+
local customers_body_func_schema = table.deepcopy(customers_id_key_schema)
148+
customers_body_func_schema.sharding_func = { body = 'function(key) return key[1] % 10 end' }
149+
150+
local customers_G_func_schema = table.deepcopy(customers_id_key_schema)
151+
customers_G_func_schema.sharding_func = 'some_module.sharding_func'
152+
153+
local customers_empty_sharding_func_schema = table.deepcopy(customers_id_key_schema)
154+
155+
local customers_vshard_mpcrc32_schema = table.deepcopy(customers_id_key_schema)
156+
customers_vshard_mpcrc32_schema.sharding_func = 'vshard.router.bucket_id_mpcrc32'
157+
158+
local customers_vshard_strcrc32_schema = table.deepcopy(customers_id_key_schema)
159+
customers_vshard_strcrc32_schema.sharding_func = 'vshard.router.bucket_id_strcrc32'
160+
161+
local schema = {
162+
spaces = {
163+
customers = customers_id_schema,
164+
customers_name_key = customers_name_key_schema,
165+
customers_name_key_uniq_index = customers_name_key_uniq_index_schema,
166+
customers_name_key_non_uniq_index = customers_name_key_non_uniq_index_schema,
167+
customers_secondary_idx_name_key = customers_secondary_idx_name_key_schema,
168+
customers_age_key = customers_age_key_schema,
169+
customers_name_age_key_different_indexes = customers_name_age_key_different_indexes_schema,
170+
customers_name_age_key_three_fields_index = customers_name_age_key_three_fields_index_schema,
171+
customers_G_func = customers_G_func_schema,
172+
customers_body_func = customers_body_func_schema,
173+
customers_empty_sharding_func = customers_empty_sharding_func_schema,
174+
customers_vshard_mpcrc32 = customers_vshard_mpcrc32_schema,
175+
customers_vshard_strcrc32 = customers_vshard_strcrc32_schema,
176+
}
177+
}
178+
179+
rawset(_G, 'set_sharding_key', function(space_name, sharding_key_def)
180+
local fieldno_sharding_key = 2
181+
box.space['_ddl_sharding_key']:update(space_name, {{'=', fieldno_sharding_key, sharding_key_def}})
182+
end)
183+
rawset(_G, 'set_sharding_func', function(space_name, fieldno_sharding_func, sharding_func_def)
184+
local record = {space_name, box.NULL, box.NULL}
185+
record[fieldno_sharding_func] = sharding_func_def
186+
box.space['_ddl_sharding_func']:replace(record)
187+
end)
188+
189+
helper.wrap_schema_init(function()
190+
local ok, err = ddl.set_schema(schema)
191+
if not ok then
192+
error(err)
193+
end
194+
end)()
195+
end,
196+
wait_until_ready = helper.wait_schema_init,
197+
}

0 commit comments

Comments
 (0)