From e31a9d51a9ac941ae2d250c9110e3914fd296208 Mon Sep 17 00:00:00 2001 From: Georgy Moiseev Date: Mon, 22 Jan 2024 18:49:04 +0300 Subject: [PATCH] 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 --- .../srv_batch_operations/cartridge_init.lua | 5 +- .../srv_batch_operations/storage.lua | 52 +++++ .../srv_batch_operations/storage_init.lua | 51 ----- test/entrypoint/srv_ddl/cartridge_init.lua | 5 +- test/entrypoint/srv_ddl/router.lua | 13 ++ test/entrypoint/srv_ddl/router_init.lua | 11 - test/entrypoint/srv_ddl/storage.lua | 197 ++++++++++++++++++ test/entrypoint/srv_ddl/storage_init.lua | 193 ----------------- .../srv_ddl_reload/cartridge_init.lua | 5 +- test/entrypoint/srv_ddl_reload/router.lua | 19 ++ .../entrypoint/srv_ddl_reload/router_init.lua | 17 -- test/entrypoint/srv_ddl_reload/storage.lua | 187 +++++++++++++++++ .../srv_ddl_reload/storage_init.lua | 186 ----------------- .../srv_migration/cartridge_init.lua | 5 +- test/entrypoint/srv_migration/storage.lua | 17 ++ .../entrypoint/srv_migration/storage_init.lua | 15 -- .../srv_not_initialized/cartridge_init.lua | 5 +- .../srv_not_initialized/storage.lua | 25 +++ .../srv_not_initialized/storage_init.lua | 24 --- .../srv_read_calls_strategies/all.lua | 31 +++ .../srv_read_calls_strategies/all_init.lua | 29 --- .../cartridge_init.lua | 7 +- .../srv_read_calls_strategies/storage.lua | 22 ++ .../storage_init.lua | 21 -- test/entrypoint/srv_say_hi/all.lua | 72 +++++++ test/entrypoint/srv_say_hi/all_init.lua | 63 ------ test/entrypoint/srv_say_hi/cartridge_init.lua | 5 +- test/entrypoint/srv_schema/cartridge_init.lua | 5 +- test/entrypoint/srv_schema/storage.lua | 86 ++++++++ test/entrypoint/srv_schema/storage_init.lua | 84 -------- test/entrypoint/srv_select/cartridge_init.lua | 5 +- test/entrypoint/srv_select/storage.lua | 195 +++++++++++++++++ test/entrypoint/srv_select/storage_init.lua | 195 ----------------- .../srv_simple_operations/cartridge_init.lua | 5 +- .../srv_simple_operations/storage.lua | 135 ++++++++++++ .../srv_simple_operations/storage_init.lua | 134 ------------ test/entrypoint/srv_stats/cartridge_init.lua | 5 +- test/entrypoint/srv_stats/storage.lua | 36 ++++ test/entrypoint/srv_stats/storage_init.lua | 35 ---- .../srv_update_schema/cartridge_init.lua | 5 +- test/entrypoint/srv_update_schema/storage.lua | 72 +++++++ .../srv_update_schema/storage_init.lua | 74 ------- test/helper.lua | 69 +++++- .../read_calls_strategies_test.lua | 14 +- test/integration/stats_test.lua | 20 +- test/performance/perf_test.lua | 2 +- test/unit/call_test.lua | 2 +- test/unit/not_initialized_test.lua | 2 +- test/unit/select_dropped_indexes_test.lua | 1 + test/unit/select_executor_test.lua | 1 + test/unit/select_filters_test.lua | 1 + test/unit/select_filters_uuid_test.lua | 1 + test/unit/select_plan_bad_indexes_test.lua | 1 + test/unit/select_plan_test.lua | 1 + test/unit/serialization_test.lua | 1 + test/unit/sharding_metadata_test.lua | 13 +- test/vshard_helpers/vtest.lua | 81 ++++--- 57 files changed, 1364 insertions(+), 1199 deletions(-) create mode 100644 test/entrypoint/srv_batch_operations/storage.lua delete mode 100644 test/entrypoint/srv_batch_operations/storage_init.lua create mode 100644 test/entrypoint/srv_ddl/router.lua delete mode 100644 test/entrypoint/srv_ddl/router_init.lua create mode 100644 test/entrypoint/srv_ddl/storage.lua delete mode 100644 test/entrypoint/srv_ddl/storage_init.lua create mode 100644 test/entrypoint/srv_ddl_reload/router.lua delete mode 100644 test/entrypoint/srv_ddl_reload/router_init.lua create mode 100644 test/entrypoint/srv_ddl_reload/storage.lua delete mode 100644 test/entrypoint/srv_ddl_reload/storage_init.lua create mode 100644 test/entrypoint/srv_migration/storage.lua delete mode 100644 test/entrypoint/srv_migration/storage_init.lua create mode 100644 test/entrypoint/srv_not_initialized/storage.lua delete mode 100644 test/entrypoint/srv_not_initialized/storage_init.lua create mode 100644 test/entrypoint/srv_read_calls_strategies/all.lua delete mode 100644 test/entrypoint/srv_read_calls_strategies/all_init.lua create mode 100644 test/entrypoint/srv_read_calls_strategies/storage.lua delete mode 100644 test/entrypoint/srv_read_calls_strategies/storage_init.lua create mode 100644 test/entrypoint/srv_say_hi/all.lua delete mode 100644 test/entrypoint/srv_say_hi/all_init.lua create mode 100644 test/entrypoint/srv_schema/storage.lua delete mode 100644 test/entrypoint/srv_schema/storage_init.lua create mode 100644 test/entrypoint/srv_select/storage.lua delete mode 100644 test/entrypoint/srv_select/storage_init.lua create mode 100644 test/entrypoint/srv_simple_operations/storage.lua delete mode 100644 test/entrypoint/srv_simple_operations/storage_init.lua create mode 100644 test/entrypoint/srv_stats/storage.lua delete mode 100644 test/entrypoint/srv_stats/storage_init.lua create mode 100644 test/entrypoint/srv_update_schema/storage.lua delete mode 100644 test/entrypoint/srv_update_schema/storage_init.lua diff --git a/test/entrypoint/srv_batch_operations/cartridge_init.lua b/test/entrypoint/srv_batch_operations/cartridge_init.lua index a5bb8d62..c9118edc 100755 --- a/test/entrypoint/srv_batch_operations/cartridge_init.lua +++ b/test/entrypoint/srv_batch_operations/cartridge_init.lua @@ -3,6 +3,7 @@ require('strict').on() _G.is_initialized = function() return false end +local fio = require('fio') local log = require('log') local errors = require('errors') local cartridge = require('cartridge') @@ -10,13 +11,15 @@ local cartridge = require('cartridge') if package.setsearchroot ~= nil then package.setsearchroot() else + local root = fio.dirname(fio.dirname(fio.dirname(fio.dirname(debug.sourcedir())))) + package.path = package.path .. root .. "/?.lua;" package.path = package.path .. debug.sourcedir() .. "/?.lua;" end package.preload['customers-storage'] = function() return { role_name = 'customers-storage', - init = require('storage_init'), + init = require('storage').init, } end diff --git a/test/entrypoint/srv_batch_operations/storage.lua b/test/entrypoint/srv_batch_operations/storage.lua new file mode 100644 index 00000000..8bec46e2 --- /dev/null +++ b/test/entrypoint/srv_batch_operations/storage.lua @@ -0,0 +1,52 @@ +local helper = require('test.helper') + +return { + init = helper.wrap_schema_init(function() + local engine = os.getenv('ENGINE') or 'memtx' + local customers_space = box.schema.space.create('customers', { + format = { + {name = 'id', type = 'unsigned'}, + {name = 'bucket_id', type = 'unsigned'}, + {name = 'name', type = 'string'}, + {name = 'age', type = 'number'}, + }, + if_not_exists = true, + engine = engine, + }) + customers_space:create_index('id', { + parts = { {field = 'id'} }, + if_not_exists = true, + }) + customers_space:create_index('bucket_id', { + parts = { {field = 'bucket_id'} }, + unique = false, + if_not_exists = true, + }) + + local developers_space = box.schema.space.create('developers', { + format = { + {name = 'id', type = 'unsigned'}, + {name = 'bucket_id', type = 'unsigned'}, + {name = 'name', type = 'string'}, + {name = 'login', type = 'string'}, + }, + if_not_exists = true, + engine = engine, + }) + developers_space:create_index('id', { + parts = { {field = 'id'} }, + if_not_exists = true, + }) + developers_space:create_index('bucket_id', { + parts = { {field = 'bucket_id'} }, + unique = false, + if_not_exists = true, + }) + developers_space:create_index('login', { + parts = { {field = 'login'} }, + unique = true, + if_not_exists = true, + }) + end), + wait_until_ready = helper.wait_schema_init, +} diff --git a/test/entrypoint/srv_batch_operations/storage_init.lua b/test/entrypoint/srv_batch_operations/storage_init.lua deleted file mode 100644 index 8aaa6ef9..00000000 --- a/test/entrypoint/srv_batch_operations/storage_init.lua +++ /dev/null @@ -1,51 +0,0 @@ -return function() - if box.info.ro == true then - return - end - - local engine = os.getenv('ENGINE') or 'memtx' - local customers_space = box.schema.space.create('customers', { - format = { - {name = 'id', type = 'unsigned'}, - {name = 'bucket_id', type = 'unsigned'}, - {name = 'name', type = 'string'}, - {name = 'age', type = 'number'}, - }, - if_not_exists = true, - engine = engine, - }) - customers_space:create_index('id', { - parts = { {field = 'id'} }, - if_not_exists = true, - }) - customers_space:create_index('bucket_id', { - parts = { {field = 'bucket_id'} }, - unique = false, - if_not_exists = true, - }) - - local developers_space = box.schema.space.create('developers', { - format = { - {name = 'id', type = 'unsigned'}, - {name = 'bucket_id', type = 'unsigned'}, - {name = 'name', type = 'string'}, - {name = 'login', type = 'string'}, - }, - if_not_exists = true, - engine = engine, - }) - developers_space:create_index('id', { - parts = { {field = 'id'} }, - if_not_exists = true, - }) - developers_space:create_index('bucket_id', { - parts = { {field = 'bucket_id'} }, - unique = false, - if_not_exists = true, - }) - developers_space:create_index('login', { - parts = { {field = 'login'} }, - unique = true, - if_not_exists = true, - }) -end diff --git a/test/entrypoint/srv_ddl/cartridge_init.lua b/test/entrypoint/srv_ddl/cartridge_init.lua index df5d952c..82ab296f 100755 --- a/test/entrypoint/srv_ddl/cartridge_init.lua +++ b/test/entrypoint/srv_ddl/cartridge_init.lua @@ -3,6 +3,7 @@ require('strict').on() _G.is_initialized = function() return false end +local fio = require('fio') local log = require('log') local errors = require('errors') local cartridge = require('cartridge') @@ -10,6 +11,8 @@ local cartridge = require('cartridge') if package.setsearchroot ~= nil then package.setsearchroot() else + local root = fio.dirname(fio.dirname(fio.dirname(fio.dirname(debug.sourcedir())))) + package.path = package.path .. root .. "/?.lua;" package.path = package.path .. debug.sourcedir() .. "/?.lua;" end @@ -18,7 +21,7 @@ package.preload['customers-storage'] = function() -- in _G for sharding func tests return { role_name = 'customers-storage', - init = require('storage_init'), + init = require('storage').init, } end diff --git a/test/entrypoint/srv_ddl/router.lua b/test/entrypoint/srv_ddl/router.lua new file mode 100644 index 00000000..44d01064 --- /dev/null +++ b/test/entrypoint/srv_ddl/router.lua @@ -0,0 +1,13 @@ +return { + init = function() + local some_module = { + sharding_func = + function(key) + if key ~= nil and key[1] ~= nil then + return key[1] % 10 + end + end + } + rawset(_G, 'some_module', some_module) + end, +} diff --git a/test/entrypoint/srv_ddl/router_init.lua b/test/entrypoint/srv_ddl/router_init.lua deleted file mode 100644 index bc30930e..00000000 --- a/test/entrypoint/srv_ddl/router_init.lua +++ /dev/null @@ -1,11 +0,0 @@ -return function() - local some_module = { - sharding_func = - function(key) - if key ~= nil and key[1] ~= nil then - return key[1] % 10 - end - end - } - rawset(_G, 'some_module', some_module) -end diff --git a/test/entrypoint/srv_ddl/storage.lua b/test/entrypoint/srv_ddl/storage.lua new file mode 100644 index 00000000..ef5b8453 --- /dev/null +++ b/test/entrypoint/srv_ddl/storage.lua @@ -0,0 +1,197 @@ +local ddl = require('ddl') +local helper = require('test.helper') + +return { + init = function() + local some_module = { + sharding_func = + function(key) + if key ~= nil and key[1] ~= nil then + return key[1] % 10 + end + end + } + rawset(_G, 'some_module', some_module) + + local engine = os.getenv('ENGINE') or 'memtx' + local customers_schema = { + engine = engine, + is_local = true, + temporary = false, + format = { + {name = 'id', is_nullable = false, type = 'unsigned'}, + {name = 'bucket_id', is_nullable = false, type = 'unsigned'}, + {name = 'name', is_nullable = false, type = 'string'}, + {name = 'age', is_nullable = false, type = 'number'}, + }, + indexes = { + -- This table is intentionally blank. + }, + } + + local primary_index = { + name = 'id', + type = 'TREE', + unique = true, + parts = { + {path = 'id', is_nullable = false, type = 'unsigned'}, + {path = 'name', is_nullable = false, type = 'string'}, + }, + } + local primary_index_id = { + name = 'id', + type = 'TREE', + unique = true, + parts = { + {path = 'id', is_nullable = false, type = 'unsigned'}, + }, + } + local bucket_id_index = { + name = 'bucket_id', + type = 'TREE', + unique = false, + parts = { + {path = 'bucket_id', is_nullable = false, type = 'unsigned'}, + } + } + local name_index = { + name = 'name', + type = 'TREE', + unique = true, + parts = { + {path = 'name', is_nullable = false, type = 'string'}, + }, + } + local age_index = { + name = 'age', + type = 'TREE', + unique = false, + parts = { + {path = 'age', is_nullable = false, type = 'number'}, + }, + } + local secondary_index = { + name = 'secondary', + type = 'TREE', + unique = false, + parts = { + {path = 'id', is_nullable = false, type = 'unsigned'}, + {path = 'name', is_nullable = false, type = 'string'}, + }, + } + + local three_fields_index = { + name = 'three_fields', + type = 'TREE', + unique = false, + parts = { + {path = 'age', is_nullable = false, type = 'number'}, + {path = 'name', is_nullable = false, type = 'string'}, + {path = 'id', is_nullable = false, type = 'unsigned'}, + }, + } + + local customers_id_schema = table.deepcopy(customers_schema) + customers_id_schema.sharding_key = {'id'} + table.insert(customers_id_schema.indexes, primary_index_id) + table.insert(customers_id_schema.indexes, bucket_id_index) + table.insert(customers_id_schema.indexes, age_index) + + local customers_name_key_schema = table.deepcopy(customers_schema) + customers_name_key_schema.sharding_key = {'name'} + table.insert(customers_name_key_schema.indexes, primary_index) + table.insert(customers_name_key_schema.indexes, bucket_id_index) + + local customers_name_key_uniq_index_schema = table.deepcopy(customers_schema) + customers_name_key_uniq_index_schema.sharding_key = {'name'} + table.insert(customers_name_key_uniq_index_schema.indexes, primary_index) + table.insert(customers_name_key_uniq_index_schema.indexes, bucket_id_index) + table.insert(customers_name_key_uniq_index_schema.indexes, name_index) + + local customers_name_key_non_uniq_index_schema = table.deepcopy(customers_schema) + customers_name_key_non_uniq_index_schema.sharding_key = {'name'} + name_index.unique = false + table.insert(customers_name_key_non_uniq_index_schema.indexes, primary_index) + table.insert(customers_name_key_non_uniq_index_schema.indexes, bucket_id_index) + table.insert(customers_name_key_non_uniq_index_schema.indexes, name_index) + + local customers_secondary_idx_name_key_schema = table.deepcopy(customers_schema) + customers_secondary_idx_name_key_schema.sharding_key = {'name'} + table.insert(customers_secondary_idx_name_key_schema.indexes, primary_index_id) + table.insert(customers_secondary_idx_name_key_schema.indexes, secondary_index) + table.insert(customers_secondary_idx_name_key_schema.indexes, bucket_id_index) + + local customers_age_key_schema = table.deepcopy(customers_schema) + customers_age_key_schema.sharding_key = {'age'} + table.insert(customers_age_key_schema.indexes, primary_index) + table.insert(customers_age_key_schema.indexes, bucket_id_index) + + local customers_name_age_key_different_indexes_schema = table.deepcopy(customers_schema) + customers_name_age_key_different_indexes_schema.sharding_key = {'name', 'age'} + table.insert(customers_name_age_key_different_indexes_schema.indexes, primary_index) + table.insert(customers_name_age_key_different_indexes_schema.indexes, bucket_id_index) + table.insert(customers_name_age_key_different_indexes_schema.indexes, age_index) + + local customers_name_age_key_three_fields_index_schema = table.deepcopy(customers_schema) + customers_name_age_key_three_fields_index_schema.sharding_key = {'name', 'age'} + table.insert(customers_name_age_key_three_fields_index_schema.indexes, primary_index_id) + table.insert(customers_name_age_key_three_fields_index_schema.indexes, bucket_id_index) + table.insert(customers_name_age_key_three_fields_index_schema.indexes, three_fields_index) + + local customers_id_key_schema = table.deepcopy(customers_schema) + customers_id_key_schema.sharding_key = {'id'} + table.insert(customers_id_key_schema.indexes, primary_index) + table.insert(customers_id_key_schema.indexes, bucket_id_index) + table.insert(customers_id_key_schema.indexes, name_index) + + local customers_body_func_schema = table.deepcopy(customers_id_key_schema) + customers_body_func_schema.sharding_func = { body = 'function(key) return key[1] % 10 end' } + + local customers_G_func_schema = table.deepcopy(customers_id_key_schema) + customers_G_func_schema.sharding_func = 'some_module.sharding_func' + + local customers_empty_sharding_func_schema = table.deepcopy(customers_id_key_schema) + + local customers_vshard_mpcrc32_schema = table.deepcopy(customers_id_key_schema) + customers_vshard_mpcrc32_schema.sharding_func = 'vshard.router.bucket_id_mpcrc32' + + local customers_vshard_strcrc32_schema = table.deepcopy(customers_id_key_schema) + customers_vshard_strcrc32_schema.sharding_func = 'vshard.router.bucket_id_strcrc32' + + local schema = { + spaces = { + customers = customers_id_schema, + customers_name_key = customers_name_key_schema, + customers_name_key_uniq_index = customers_name_key_uniq_index_schema, + customers_name_key_non_uniq_index = customers_name_key_non_uniq_index_schema, + customers_secondary_idx_name_key = customers_secondary_idx_name_key_schema, + customers_age_key = customers_age_key_schema, + customers_name_age_key_different_indexes = customers_name_age_key_different_indexes_schema, + customers_name_age_key_three_fields_index = customers_name_age_key_three_fields_index_schema, + customers_G_func = customers_G_func_schema, + customers_body_func = customers_body_func_schema, + customers_empty_sharding_func = customers_empty_sharding_func_schema, + customers_vshard_mpcrc32 = customers_vshard_mpcrc32_schema, + customers_vshard_strcrc32 = customers_vshard_strcrc32_schema, + } + } + + rawset(_G, 'set_sharding_key', function(space_name, sharding_key_def) + local fieldno_sharding_key = 2 + box.space['_ddl_sharding_key']:update(space_name, {{'=', fieldno_sharding_key, sharding_key_def}}) + end) + rawset(_G, 'set_sharding_func', function(space_name, fieldno_sharding_func, sharding_func_def) + local record = {space_name, box.NULL, box.NULL} + record[fieldno_sharding_func] = sharding_func_def + box.space['_ddl_sharding_func']:replace(record) + end) + + helper.wrap_schema_init(function() + local ok, err = ddl.set_schema(schema) + if not ok then + error(err) + end + end)() + end, + wait_until_ready = helper.wait_schema_init, +} diff --git a/test/entrypoint/srv_ddl/storage_init.lua b/test/entrypoint/srv_ddl/storage_init.lua deleted file mode 100644 index 57ea212e..00000000 --- a/test/entrypoint/srv_ddl/storage_init.lua +++ /dev/null @@ -1,193 +0,0 @@ -local ddl = require('ddl') - -local some_module = { - sharding_func = - function(key) - if key ~= nil and key[1] ~= nil then - return key[1] % 10 - end - end -} -rawset(_G, 'some_module', some_module) - -return function() - local engine = os.getenv('ENGINE') or 'memtx' - local customers_schema = { - engine = engine, - is_local = true, - temporary = false, - format = { - {name = 'id', is_nullable = false, type = 'unsigned'}, - {name = 'bucket_id', is_nullable = false, type = 'unsigned'}, - {name = 'name', is_nullable = false, type = 'string'}, - {name = 'age', is_nullable = false, type = 'number'}, - }, - indexes = { - -- This table is intentionally blank. - }, - } - - local primary_index = { - name = 'id', - type = 'TREE', - unique = true, - parts = { - {path = 'id', is_nullable = false, type = 'unsigned'}, - {path = 'name', is_nullable = false, type = 'string'}, - }, - } - local primary_index_id = { - name = 'id', - type = 'TREE', - unique = true, - parts = { - {path = 'id', is_nullable = false, type = 'unsigned'}, - }, - } - local bucket_id_index = { - name = 'bucket_id', - type = 'TREE', - unique = false, - parts = { - {path = 'bucket_id', is_nullable = false, type = 'unsigned'}, - } - } - local name_index = { - name = 'name', - type = 'TREE', - unique = true, - parts = { - {path = 'name', is_nullable = false, type = 'string'}, - }, - } - local age_index = { - name = 'age', - type = 'TREE', - unique = false, - parts = { - {path = 'age', is_nullable = false, type = 'number'}, - }, - } - local secondary_index = { - name = 'secondary', - type = 'TREE', - unique = false, - parts = { - {path = 'id', is_nullable = false, type = 'unsigned'}, - {path = 'name', is_nullable = false, type = 'string'}, - }, - } - - local three_fields_index = { - name = 'three_fields', - type = 'TREE', - unique = false, - parts = { - {path = 'age', is_nullable = false, type = 'number'}, - {path = 'name', is_nullable = false, type = 'string'}, - {path = 'id', is_nullable = false, type = 'unsigned'}, - }, - } - - local customers_id_schema = table.deepcopy(customers_schema) - customers_id_schema.sharding_key = {'id'} - table.insert(customers_id_schema.indexes, primary_index_id) - table.insert(customers_id_schema.indexes, bucket_id_index) - table.insert(customers_id_schema.indexes, age_index) - - local customers_name_key_schema = table.deepcopy(customers_schema) - customers_name_key_schema.sharding_key = {'name'} - table.insert(customers_name_key_schema.indexes, primary_index) - table.insert(customers_name_key_schema.indexes, bucket_id_index) - - local customers_name_key_uniq_index_schema = table.deepcopy(customers_schema) - customers_name_key_uniq_index_schema.sharding_key = {'name'} - table.insert(customers_name_key_uniq_index_schema.indexes, primary_index) - table.insert(customers_name_key_uniq_index_schema.indexes, bucket_id_index) - table.insert(customers_name_key_uniq_index_schema.indexes, name_index) - - local customers_name_key_non_uniq_index_schema = table.deepcopy(customers_schema) - customers_name_key_non_uniq_index_schema.sharding_key = {'name'} - name_index.unique = false - table.insert(customers_name_key_non_uniq_index_schema.indexes, primary_index) - table.insert(customers_name_key_non_uniq_index_schema.indexes, bucket_id_index) - table.insert(customers_name_key_non_uniq_index_schema.indexes, name_index) - - local customers_secondary_idx_name_key_schema = table.deepcopy(customers_schema) - customers_secondary_idx_name_key_schema.sharding_key = {'name'} - table.insert(customers_secondary_idx_name_key_schema.indexes, primary_index_id) - table.insert(customers_secondary_idx_name_key_schema.indexes, secondary_index) - table.insert(customers_secondary_idx_name_key_schema.indexes, bucket_id_index) - - local customers_age_key_schema = table.deepcopy(customers_schema) - customers_age_key_schema.sharding_key = {'age'} - table.insert(customers_age_key_schema.indexes, primary_index) - table.insert(customers_age_key_schema.indexes, bucket_id_index) - - local customers_name_age_key_different_indexes_schema = table.deepcopy(customers_schema) - customers_name_age_key_different_indexes_schema.sharding_key = {'name', 'age'} - table.insert(customers_name_age_key_different_indexes_schema.indexes, primary_index) - table.insert(customers_name_age_key_different_indexes_schema.indexes, bucket_id_index) - table.insert(customers_name_age_key_different_indexes_schema.indexes, age_index) - - local customers_name_age_key_three_fields_index_schema = table.deepcopy(customers_schema) - customers_name_age_key_three_fields_index_schema.sharding_key = {'name', 'age'} - table.insert(customers_name_age_key_three_fields_index_schema.indexes, primary_index_id) - table.insert(customers_name_age_key_three_fields_index_schema.indexes, bucket_id_index) - table.insert(customers_name_age_key_three_fields_index_schema.indexes, three_fields_index) - - local customers_id_key_schema = table.deepcopy(customers_schema) - customers_id_key_schema.sharding_key = {'id'} - table.insert(customers_id_key_schema.indexes, primary_index) - table.insert(customers_id_key_schema.indexes, bucket_id_index) - table.insert(customers_id_key_schema.indexes, name_index) - - local customers_body_func_schema = table.deepcopy(customers_id_key_schema) - customers_body_func_schema.sharding_func = { body = 'function(key) return key[1] % 10 end' } - - local customers_G_func_schema = table.deepcopy(customers_id_key_schema) - customers_G_func_schema.sharding_func = 'some_module.sharding_func' - - local customers_empty_sharding_func_schema = table.deepcopy(customers_id_key_schema) - - local customers_vshard_mpcrc32_schema = table.deepcopy(customers_id_key_schema) - customers_vshard_mpcrc32_schema.sharding_func = 'vshard.router.bucket_id_mpcrc32' - - local customers_vshard_strcrc32_schema = table.deepcopy(customers_id_key_schema) - customers_vshard_strcrc32_schema.sharding_func = 'vshard.router.bucket_id_strcrc32' - - local schema = { - spaces = { - customers = customers_id_schema, - customers_name_key = customers_name_key_schema, - customers_name_key_uniq_index = customers_name_key_uniq_index_schema, - customers_name_key_non_uniq_index = customers_name_key_non_uniq_index_schema, - customers_secondary_idx_name_key = customers_secondary_idx_name_key_schema, - customers_age_key = customers_age_key_schema, - customers_name_age_key_different_indexes = customers_name_age_key_different_indexes_schema, - customers_name_age_key_three_fields_index = customers_name_age_key_three_fields_index_schema, - customers_G_func = customers_G_func_schema, - customers_body_func = customers_body_func_schema, - customers_empty_sharding_func = customers_empty_sharding_func_schema, - customers_vshard_mpcrc32 = customers_vshard_mpcrc32_schema, - customers_vshard_strcrc32 = customers_vshard_strcrc32_schema, - } - } - - if not box.info.ro then - local ok, err = ddl.set_schema(schema) - if not ok then - error(err) - end - end - - rawset(_G, 'set_sharding_key', function(space_name, sharding_key_def) - local fieldno_sharding_key = 2 - box.space['_ddl_sharding_key']:update(space_name, {{'=', fieldno_sharding_key, sharding_key_def}}) - end) - rawset(_G, 'set_sharding_func', function(space_name, fieldno_sharding_func, sharding_func_def) - local record = {space_name, box.NULL, box.NULL} - record[fieldno_sharding_func] = sharding_func_def - box.space['_ddl_sharding_func']:replace(record) - end) -end diff --git a/test/entrypoint/srv_ddl_reload/cartridge_init.lua b/test/entrypoint/srv_ddl_reload/cartridge_init.lua index c847d322..f37349cb 100755 --- a/test/entrypoint/srv_ddl_reload/cartridge_init.lua +++ b/test/entrypoint/srv_ddl_reload/cartridge_init.lua @@ -3,6 +3,7 @@ require('strict').on() _G.is_initialized = function() return false end +local fio = require('fio') local log = require('log') local errors = require('errors') local cartridge = require('cartridge') @@ -12,6 +13,8 @@ local crud_utils = require('crud.common.utils') if package.setsearchroot ~= nil then package.setsearchroot() else + local root = fio.dirname(fio.dirname(fio.dirname(fio.dirname(debug.sourcedir())))) + package.path = package.path .. root .. "/?.lua;" package.path = package.path .. debug.sourcedir() .. "/?.lua;" end @@ -34,7 +37,7 @@ package.preload['customers-storage'] = function() return { role_name = 'customers-storage', - init = require('storage_init') + init = require('storage').init, } end diff --git a/test/entrypoint/srv_ddl_reload/router.lua b/test/entrypoint/srv_ddl_reload/router.lua new file mode 100644 index 00000000..286c9f1c --- /dev/null +++ b/test/entrypoint/srv_ddl_reload/router.lua @@ -0,0 +1,19 @@ +return { + init = function() + local customers_module = { + sharding_func_default = function(key) + local id = key[1] + assert(id ~= nil) + + return id % 3000 + 1 + end, + sharding_func_new = function(key) + local id = key[1] + assert(id ~= nil) + + return (id + 42) % 3000 + 1 + end, + } + rawset(_G, 'customers_module', customers_module) + end, +} diff --git a/test/entrypoint/srv_ddl_reload/router_init.lua b/test/entrypoint/srv_ddl_reload/router_init.lua deleted file mode 100644 index f64cd4c8..00000000 --- a/test/entrypoint/srv_ddl_reload/router_init.lua +++ /dev/null @@ -1,17 +0,0 @@ -return function() - local customers_module = { - sharding_func_default = function(key) - local id = key[1] - assert(id ~= nil) - - return id % 3000 + 1 - end, - sharding_func_new = function(key) - local id = key[1] - assert(id ~= nil) - - return (id + 42) % 3000 + 1 - end, - } - rawset(_G, 'customers_module', customers_module) -end diff --git a/test/entrypoint/srv_ddl_reload/storage.lua b/test/entrypoint/srv_ddl_reload/storage.lua new file mode 100644 index 00000000..57a82f10 --- /dev/null +++ b/test/entrypoint/srv_ddl_reload/storage.lua @@ -0,0 +1,187 @@ +local ddl = require('ddl') + +return { + init = function() + local customers_module = { + sharding_func_default = function(key) + local id = key[1] + assert(id ~= nil) + + return id % 3000 + 1 + end, + sharding_func_new = function(key) + local id = key[1] + assert(id ~= nil) + + return (id + 42) % 3000 + 1 + end, + } + rawset(_G, 'customers_module', customers_module) + + local engine = os.getenv('ENGINE') or 'memtx' + + local customers_schema_raw = { + engine = engine, + temporary = false, + is_local = false, + format = { + {name = 'id', is_nullable = false, type = 'unsigned'}, + {name = 'bucket_id', is_nullable = false, type = 'unsigned'}, + {name = 'name', is_nullable = false, type = 'string'}, + {name = 'age', is_nullable = false, type = 'number'}, + }, + indexes = { + { + name = 'id', + type = 'TREE', + unique = true, + parts = { + {path = 'id', is_nullable = false, type = 'unsigned'}, + }, + }, + { + name = 'bucket_id', + type = 'TREE', + unique = false, + parts = { + {path = 'bucket_id', is_nullable = false, type = 'unsigned'}, + }, + }, + { + name = 'name', + type = 'TREE', + unique = false, + parts = { + {path = 'name', is_nullable = false, type = 'string'}, + }, + }, + { + name = 'age', + type = 'TREE', + unique = false, + parts = { + {path = 'age', is_nullable = false, type = 'number'}, + }, + }, + }, + sharding_key = { 'name' }, + } + + local customers_schema = table.deepcopy(customers_schema_raw) + customers_schema.sharding_key = { 'name' } + + local customers_pk_schema = table.deepcopy(customers_schema_raw) + customers_pk_schema.sharding_key = { 'id' } + customers_pk_schema.sharding_func = 'customers_module.sharding_func_default' + + local schema = { + spaces = { + ['customers'] = customers_schema, + ['customers_pk'] = customers_pk_schema, + } + } + + rawset(_G, 'reset_to_default_schema', function() + if box.info.ro == true then + return + end + + if box.space['_ddl_sharding_key'] ~= nil then + box.space['_ddl_sharding_key']:truncate() + box.space['_ddl_sharding_key']:insert{'customers', customers_schema.sharding_key} + box.space['_ddl_sharding_key']:insert{'customers_pk', customers_pk_schema.sharding_key} + end + + if box.space['_ddl_sharding_func'] ~= nil then + box.space['_ddl_sharding_func']:truncate() + box.space['_ddl_sharding_func']:insert{'customers_pk', customers_pk_schema.sharding_func, box.NULL} + end + + local _, err = ddl.set_schema(schema) + if err ~= nil then + error(err) + end + end) + + rawset(_G, 'set_sharding_key', function(space_name, sharding_key_def) + if box.info.ro == true then + return + end + + local current_schema, err = ddl.get_schema() + if err ~= nil then + error(err) + end + + box.space['_ddl_sharding_key']:replace{space_name, sharding_key_def} + current_schema.spaces[space_name].sharding_key = sharding_key_def + + local _, err = ddl.set_schema(current_schema) + if err ~= nil then + error(err) + end + end) + + rawset(_G, 'set_sharding_func_name', function(space_name, sharding_func_name) + if box.info.ro == true then + return + end + + local current_schema, err = ddl.get_schema() + if err ~= nil then + error(err) + end + + local t = {space_name, sharding_func_name, box.NULL} + box.space['_ddl_sharding_func']:replace(t) + current_schema.spaces[space_name].sharding_func = sharding_func_name + + local _, err = ddl.set_schema(current_schema) + if err ~= nil then + error(err) + end + end) + + rawset(_G, 'set_sharding_func_body', function(space_name, sharding_func_body) + if box.info.ro == true then + return + end + + local current_schema, err = ddl.get_schema() + if err ~= nil then + error(err) + end + + local t = {space_name, box.NULL, sharding_func_body} + box.space['_ddl_sharding_func']:replace(t) + current_schema.spaces[space_name].sharding_func = { body = sharding_func_body } + + local _, err = ddl.set_schema(current_schema) + if err ~= nil then + error(err) + end + end) + + rawset(_G, 'create_new_space', function() + if box.info.ro == true then + return + end + + local new_schema = table.deepcopy(schema) + new_schema.spaces['customers_new'] = table.deepcopy(customers_schema_raw) + new_schema.spaces['customers_new'].sharding_func = { + body = [[ + function(key) + local vshard = require('vshard') + return vshard.router.bucket_id_mpcrc32(key) + end + ]] + } + + local _, err = ddl.set_schema(new_schema) + if err ~= nil then + error(err) + end + end) + end, +} diff --git a/test/entrypoint/srv_ddl_reload/storage_init.lua b/test/entrypoint/srv_ddl_reload/storage_init.lua deleted file mode 100644 index 203b0767..00000000 --- a/test/entrypoint/srv_ddl_reload/storage_init.lua +++ /dev/null @@ -1,186 +0,0 @@ -local ddl = require('ddl') - -local customers_module = { - sharding_func_default = function(key) - local id = key[1] - assert(id ~= nil) - - return id % 3000 + 1 - end, - sharding_func_new = function(key) - local id = key[1] - assert(id ~= nil) - - return (id + 42) % 3000 + 1 - end, -} -rawset(_G, 'customers_module', customers_module) - -return function() - local engine = os.getenv('ENGINE') or 'memtx' - - local customers_schema_raw = { - engine = engine, - temporary = false, - is_local = false, - format = { - {name = 'id', is_nullable = false, type = 'unsigned'}, - {name = 'bucket_id', is_nullable = false, type = 'unsigned'}, - {name = 'name', is_nullable = false, type = 'string'}, - {name = 'age', is_nullable = false, type = 'number'}, - }, - indexes = { - { - name = 'id', - type = 'TREE', - unique = true, - parts = { - {path = 'id', is_nullable = false, type = 'unsigned'}, - }, - }, - { - name = 'bucket_id', - type = 'TREE', - unique = false, - parts = { - {path = 'bucket_id', is_nullable = false, type = 'unsigned'}, - }, - }, - { - name = 'name', - type = 'TREE', - unique = false, - parts = { - {path = 'name', is_nullable = false, type = 'string'}, - }, - }, - { - name = 'age', - type = 'TREE', - unique = false, - parts = { - {path = 'age', is_nullable = false, type = 'number'}, - }, - }, - }, - sharding_key = { 'name' }, - } - - local customers_schema = table.deepcopy(customers_schema_raw) - customers_schema.sharding_key = { 'name' } - - local customers_pk_schema = table.deepcopy(customers_schema_raw) - customers_pk_schema.sharding_key = { 'id' } - customers_pk_schema.sharding_func = 'customers_module.sharding_func_default' - - local schema = { - spaces = { - ['customers'] = customers_schema, - ['customers_pk'] = customers_pk_schema, - } - } - - - rawset(_G, 'reset_to_default_schema', function() - if box.info.ro == true then - return - end - - if box.space['_ddl_sharding_key'] ~= nil then - box.space['_ddl_sharding_key']:truncate() - box.space['_ddl_sharding_key']:insert{'customers', customers_schema.sharding_key} - box.space['_ddl_sharding_key']:insert{'customers_pk', customers_pk_schema.sharding_key} - end - - if box.space['_ddl_sharding_func'] ~= nil then - box.space['_ddl_sharding_func']:truncate() - box.space['_ddl_sharding_func']:insert{'customers_pk', customers_pk_schema.sharding_func, box.NULL} - end - - local _, err = ddl.set_schema(schema) - if err ~= nil then - error(err) - end - end) - - rawset(_G, 'set_sharding_key', function(space_name, sharding_key_def) - if box.info.ro == true then - return - end - - local current_schema, err = ddl.get_schema() - if err ~= nil then - error(err) - end - - box.space['_ddl_sharding_key']:replace{space_name, sharding_key_def} - current_schema.spaces[space_name].sharding_key = sharding_key_def - - local _, err = ddl.set_schema(current_schema) - if err ~= nil then - error(err) - end - end) - - rawset(_G, 'set_sharding_func_name', function(space_name, sharding_func_name) - if box.info.ro == true then - return - end - - local current_schema, err = ddl.get_schema() - if err ~= nil then - error(err) - end - - local t = {space_name, sharding_func_name, box.NULL} - box.space['_ddl_sharding_func']:replace(t) - current_schema.spaces[space_name].sharding_func = sharding_func_name - - local _, err = ddl.set_schema(current_schema) - if err ~= nil then - error(err) - end - end) - - rawset(_G, 'set_sharding_func_body', function(space_name, sharding_func_body) - if box.info.ro == true then - return - end - - local current_schema, err = ddl.get_schema() - if err ~= nil then - error(err) - end - - local t = {space_name, box.NULL, sharding_func_body} - box.space['_ddl_sharding_func']:replace(t) - current_schema.spaces[space_name].sharding_func = { body = sharding_func_body } - - local _, err = ddl.set_schema(current_schema) - if err ~= nil then - error(err) - end - end) - - rawset(_G, 'create_new_space', function() - if box.info.ro == true then - return - end - - local new_schema = table.deepcopy(schema) - new_schema.spaces['customers_new'] = table.deepcopy(customers_schema_raw) - new_schema.spaces['customers_new'].sharding_func = { - body = [[ - function(key) - local vshard = require('vshard') - return vshard.router.bucket_id_mpcrc32(key) - end - ]] - } - - local _, err = ddl.set_schema(new_schema) - if err ~= nil then - error(err) - end - end) -end diff --git a/test/entrypoint/srv_migration/cartridge_init.lua b/test/entrypoint/srv_migration/cartridge_init.lua index 37c18409..d8d0b8d9 100755 --- a/test/entrypoint/srv_migration/cartridge_init.lua +++ b/test/entrypoint/srv_migration/cartridge_init.lua @@ -3,6 +3,7 @@ require('strict').on() _G.is_initialized = function() return false end +local fio = require('fio') local log = require('log') local errors = require('errors') local cartridge = require('cartridge') @@ -10,13 +11,15 @@ local cartridge = require('cartridge') if package.setsearchroot ~= nil then package.setsearchroot() else + local root = fio.dirname(fio.dirname(fio.dirname(fio.dirname(debug.sourcedir())))) + package.path = package.path .. root .. "/?.lua;" package.path = package.path .. debug.sourcedir() .. "/?.lua;" end package.preload['customers-storage'] = function() return { role_name = 'customers-storage', - init = require('storage_init') + init = require('storage').init, } end diff --git a/test/entrypoint/srv_migration/storage.lua b/test/entrypoint/srv_migration/storage.lua new file mode 100644 index 00000000..11908e41 --- /dev/null +++ b/test/entrypoint/srv_migration/storage.lua @@ -0,0 +1,17 @@ +local helper = require('test.helper') + +return { + init = helper.wrap_schema_init(function() + box.schema.space.create('customers', {if_not_exists = true}) + + box.space['customers']:format{ + {name = 'id', is_nullable = false, type = 'unsigned'}, + {name = 'bucket_id', is_nullable = false, type = 'unsigned'}, + {name = 'sharding_key', is_nullable = false, type = 'unsigned'}, + } + + box.space['customers']:create_index('pk', {parts = { 'id' }, if_not_exists = true}) + box.space['customers']:create_index('bucket_id', {parts = { 'bucket_id' }, if_not_exists = true}) + end), + wait_until_ready = helper.wait_schema_init, +} diff --git a/test/entrypoint/srv_migration/storage_init.lua b/test/entrypoint/srv_migration/storage_init.lua deleted file mode 100644 index 71d94d71..00000000 --- a/test/entrypoint/srv_migration/storage_init.lua +++ /dev/null @@ -1,15 +0,0 @@ -return function() - if box.info.ro == true then - return - end - box.schema.space.create('customers') - - box.space['customers']:format{ - {name = 'id', is_nullable = false, type = 'unsigned'}, - {name = 'bucket_id', is_nullable = false, type = 'unsigned'}, - {name = 'sharding_key', is_nullable = false, type = 'unsigned'}, - } - - box.space['customers']:create_index('pk', {parts = { 'id' }}) - box.space['customers']:create_index('bucket_id', {parts = { 'bucket_id' }}) -end diff --git a/test/entrypoint/srv_not_initialized/cartridge_init.lua b/test/entrypoint/srv_not_initialized/cartridge_init.lua index 7d82a7b1..ec28b067 100755 --- a/test/entrypoint/srv_not_initialized/cartridge_init.lua +++ b/test/entrypoint/srv_not_initialized/cartridge_init.lua @@ -3,6 +3,7 @@ require('strict').on() _G.is_initialized = function() return false end +local fio = require('fio') local log = require('log') local errors = require('errors') local cartridge = require('cartridge') @@ -10,13 +11,15 @@ local cartridge = require('cartridge') if package.setsearchroot ~= nil then package.setsearchroot() else + local root = fio.dirname(fio.dirname(fio.dirname(fio.dirname(debug.sourcedir())))) + package.path = package.path .. root .. "/?.lua;" package.path = package.path .. debug.sourcedir() .. "/?.lua;" end package.preload['customers-storage'] = function() return { role_name = 'customers-storage', - init = require('storage_init'), + init = require('storage').init, dependencies = {'cartridge.roles.vshard-storage'}, } end diff --git a/test/entrypoint/srv_not_initialized/storage.lua b/test/entrypoint/srv_not_initialized/storage.lua new file mode 100644 index 00000000..5f2e5fef --- /dev/null +++ b/test/entrypoint/srv_not_initialized/storage.lua @@ -0,0 +1,25 @@ +local helper = require('test.helper') + +return { + init = helper.wrap_schema_init(function() + local customers_space = box.schema.space.create('customers', { + format = { + {name = 'id', type = 'unsigned'}, + {name = 'bucket_id', type = 'unsigned'}, + {name = 'name', type = 'string'}, + {name = 'age', type = 'number'}, + }, + if_not_exists = true, + }) + customers_space:create_index('id', { + parts = { {field = 'id' } }, + if_not_exists = true, + }) + customers_space:create_index('bucket_id', { + parts = { {field = 'bucket_id' } }, + unique = false, + if_not_exists = true, + }) + end), + wait_until_ready = helper.wait_schema_init, +} diff --git a/test/entrypoint/srv_not_initialized/storage_init.lua b/test/entrypoint/srv_not_initialized/storage_init.lua deleted file mode 100644 index c4a74517..00000000 --- a/test/entrypoint/srv_not_initialized/storage_init.lua +++ /dev/null @@ -1,24 +0,0 @@ -return function() - if box.info.ro == true then - return - end - - local customers_space = box.schema.space.create('customers', { - format = { - {name = 'id', type = 'unsigned'}, - {name = 'bucket_id', type = 'unsigned'}, - {name = 'name', type = 'string'}, - {name = 'age', type = 'number'}, - }, - if_not_exists = true, - }) - customers_space:create_index('id', { - parts = { {field = 'id' } }, - if_not_exists = true, - }) - customers_space:create_index('bucket_id', { - parts = { {field = 'bucket_id' } }, - unique = false, - if_not_exists = true, - }) -end diff --git a/test/entrypoint/srv_read_calls_strategies/all.lua b/test/entrypoint/srv_read_calls_strategies/all.lua new file mode 100644 index 00000000..24691819 --- /dev/null +++ b/test/entrypoint/srv_read_calls_strategies/all.lua @@ -0,0 +1,31 @@ +return { + init = function() + rawset(_G, 'vshard_calls', {}) + + rawset(_G, 'clear_vshard_calls', function() + table.clear(_G.vshard_calls) + end) + + rawset(_G, 'patch_vshard_calls', function(vshard_call_names) + local vshard = require('vshard') + + local replicasets = vshard.router.routeall() + + local _, replicaset = next(replicasets) + local replicaset_mt = getmetatable(replicaset) + + for _, vshard_call_name in ipairs(vshard_call_names) do + local old_func = replicaset_mt.__index[vshard_call_name] + assert(old_func ~= nil, vshard_call_name) + + replicaset_mt.__index[vshard_call_name] = function(...) + local func_name = select(2, ...) + if not string.startswith(func_name, 'vshard.') or func_name == 'vshard.storage.call' then + table.insert(_G.vshard_calls, vshard_call_name) + end + return old_func(...) + end + end + end) + end, +} diff --git a/test/entrypoint/srv_read_calls_strategies/all_init.lua b/test/entrypoint/srv_read_calls_strategies/all_init.lua deleted file mode 100644 index 1827214d..00000000 --- a/test/entrypoint/srv_read_calls_strategies/all_init.lua +++ /dev/null @@ -1,29 +0,0 @@ -return function() - rawset(_G, 'vshard_calls', {}) - - rawset(_G, 'clear_vshard_calls', function() - table.clear(_G.vshard_calls) - end) - - rawset(_G, 'patch_vshard_calls', function(vshard_call_names) - local vshard = require('vshard') - - local replicasets = vshard.router.routeall() - - local _, replicaset = next(replicasets) - local replicaset_mt = getmetatable(replicaset) - - for _, vshard_call_name in ipairs(vshard_call_names) do - local old_func = replicaset_mt.__index[vshard_call_name] - assert(old_func ~= nil, vshard_call_name) - - replicaset_mt.__index[vshard_call_name] = function(...) - local func_name = select(2, ...) - if not string.startswith(func_name, 'vshard.') or func_name == 'vshard.storage.call' then - table.insert(_G.vshard_calls, vshard_call_name) - end - return old_func(...) - end - end - end) -end diff --git a/test/entrypoint/srv_read_calls_strategies/cartridge_init.lua b/test/entrypoint/srv_read_calls_strategies/cartridge_init.lua index 96a94860..ca21b2c6 100755 --- a/test/entrypoint/srv_read_calls_strategies/cartridge_init.lua +++ b/test/entrypoint/srv_read_calls_strategies/cartridge_init.lua @@ -3,6 +3,7 @@ require('strict').on() _G.is_initialized = function() return false end +local fio = require('fio') local log = require('log') local errors = require('errors') local cartridge = require('cartridge') @@ -10,13 +11,15 @@ local cartridge = require('cartridge') if package.setsearchroot ~= nil then package.setsearchroot() else + local root = fio.dirname(fio.dirname(fio.dirname(fio.dirname(debug.sourcedir())))) + package.path = package.path .. root .. "/?.lua;" package.path = package.path .. debug.sourcedir() .. "/?.lua;" end package.preload['customers-storage'] = function() return { role_name = 'customers-storage', - init = require('storage_init'), + init = require('storage').init, } end @@ -36,6 +39,6 @@ if not ok then os.exit(1) end -require('all_init')() +require('all').init() _G.is_initialized = cartridge.is_healthy diff --git a/test/entrypoint/srv_read_calls_strategies/storage.lua b/test/entrypoint/srv_read_calls_strategies/storage.lua new file mode 100644 index 00000000..0948aea3 --- /dev/null +++ b/test/entrypoint/srv_read_calls_strategies/storage.lua @@ -0,0 +1,22 @@ +local helper = require('test.helper') + +return { + init = helper.wrap_schema_init(function() + local engine = os.getenv('ENGINE') or 'memtx' + local customers_space = box.schema.space.create('customers', { + format = { + {name = 'id', type = 'unsigned'}, + {name = 'bucket_id', type = 'unsigned'}, + {name = 'name', type = 'string'}, + {name = 'age', type = 'number'}, + }, + if_not_exists = true, + engine = engine, + }) + customers_space:create_index('id', { + parts = { {field = 'id'} }, + if_not_exists = true, + }) + end), + wait_until_ready = helper.wait_schema_init, +} diff --git a/test/entrypoint/srv_read_calls_strategies/storage_init.lua b/test/entrypoint/srv_read_calls_strategies/storage_init.lua deleted file mode 100644 index 0973bb7d..00000000 --- a/test/entrypoint/srv_read_calls_strategies/storage_init.lua +++ /dev/null @@ -1,21 +0,0 @@ -return function() - if box.info.ro == true then - return - end - - local engine = os.getenv('ENGINE') or 'memtx' - local customers_space = box.schema.space.create('customers', { - format = { - {name = 'id', type = 'unsigned'}, - {name = 'bucket_id', type = 'unsigned'}, - {name = 'name', type = 'string'}, - {name = 'age', type = 'number'}, - }, - if_not_exists = true, - engine = engine, - }) - customers_space:create_index('id', { - parts = { {field = 'id'} }, - if_not_exists = true, - }) -end diff --git a/test/entrypoint/srv_say_hi/all.lua b/test/entrypoint/srv_say_hi/all.lua new file mode 100644 index 00000000..1037fc33 --- /dev/null +++ b/test/entrypoint/srv_say_hi/all.lua @@ -0,0 +1,72 @@ +local fiber = require('fiber') +local helper = require('test.helper') + +-- Adds execution rights to a function for a vshard storage user. +local function add_storage_execute(func_name) + + + if box.schema.user.exists('storage') then + box.schema.func.create(func_name, {setuid = true, if_not_exists = true}) + box.schema.user.grant('storage', 'execute', 'function', func_name, {if_not_exists = true}) + end +end + +return { + init = function() + rawset(_G, 'say_hi_politely', function (to_name) + to_name = to_name or "handsome" + local my_alias = box.info.id + return string.format("HI, %s! I am %s", to_name, my_alias) + end) + + rawset(_G, 'say_hi_sleepily', function (time_to_sleep) + if time_to_sleep ~= nil then + fiber.sleep(time_to_sleep) + end + + return "HI" + end) + + rawset(_G, 'vshard_calls', {}) + + rawset(_G, 'clear_vshard_calls', function() + table.clear(_G.vshard_calls) + end) + + rawset(_G, 'patch_vshard_calls', function(vshard_call_names) + local vshard = require('vshard') + + local replicasets = vshard.router.routeall() + + local _, replicaset = next(replicasets) + local replicaset_mt = getmetatable(replicaset) + + for _, vshard_call_name in ipairs(vshard_call_names) do + local old_func = replicaset_mt.__index[vshard_call_name] + assert(old_func ~= nil, vshard_call_name) + + replicaset_mt.__index[vshard_call_name] = function(...) + local func_name = select(2, ...) + if not string.startswith(func_name, 'vshard.') or func_name == 'vshard.storage.call' then + table.insert(_G.vshard_calls, vshard_call_name) + end + return old_func(...) + end + end + end) + + if type(box.cfg) ~= 'table' then + -- Cartridge, unit tests. + return + else + helper.wrap_schema_init(function() + add_storage_execute('clear_vshard_calls') + add_storage_execute('say_hi_sleepily') + add_storage_execute('say_hi_politely') + add_storage_execute('patch_vshard_calls') + add_storage_execute('non_existent_func') + end)() + end + end, + wait_until_ready = helper.wait_schema_init, +} diff --git a/test/entrypoint/srv_say_hi/all_init.lua b/test/entrypoint/srv_say_hi/all_init.lua deleted file mode 100644 index 01c0edcb..00000000 --- a/test/entrypoint/srv_say_hi/all_init.lua +++ /dev/null @@ -1,63 +0,0 @@ -local fiber = require('fiber') - --- Adds execution rights to a function for a vshard storage user. -local function add_storage_execute(func_name) - if type(box.cfg) ~= 'table' then - -- Cartridge, unit tests. - return - end - if box.cfg.read_only == false and box.schema.user.exists('storage') then - box.schema.func.create(func_name, {setuid = true}) - box.schema.user.grant('storage', 'execute', 'function', func_name) - end -end - -return function() - rawset(_G, 'say_hi_politely', function (to_name) - to_name = to_name or "handsome" - local my_alias = box.info.id - return string.format("HI, %s! I am %s", to_name, my_alias) - end) - add_storage_execute('say_hi_politely') - - rawset(_G, 'say_hi_sleepily', function (time_to_sleep) - if time_to_sleep ~= nil then - fiber.sleep(time_to_sleep) - end - - return "HI" - end) - add_storage_execute('say_hi_sleepily') - - rawset(_G, 'vshard_calls', {}) - - rawset(_G, 'clear_vshard_calls', function() - table.clear(_G.vshard_calls) - end) - add_storage_execute('clear_vshard_calls') - - rawset(_G, 'patch_vshard_calls', function(vshard_call_names) - local vshard = require('vshard') - - local replicasets = vshard.router.routeall() - - local _, replicaset = next(replicasets) - local replicaset_mt = getmetatable(replicaset) - - for _, vshard_call_name in ipairs(vshard_call_names) do - local old_func = replicaset_mt.__index[vshard_call_name] - assert(old_func ~= nil, vshard_call_name) - - replicaset_mt.__index[vshard_call_name] = function(...) - local func_name = select(2, ...) - if not string.startswith(func_name, 'vshard.') or func_name == 'vshard.storage.call' then - table.insert(_G.vshard_calls, vshard_call_name) - end - return old_func(...) - end - end - end) - add_storage_execute('patch_vshard_calls') - - add_storage_execute('non_existent_func') -end diff --git a/test/entrypoint/srv_say_hi/cartridge_init.lua b/test/entrypoint/srv_say_hi/cartridge_init.lua index 1890e017..43388468 100755 --- a/test/entrypoint/srv_say_hi/cartridge_init.lua +++ b/test/entrypoint/srv_say_hi/cartridge_init.lua @@ -3,6 +3,7 @@ require('strict').on() _G.is_initialized = function() return false end +local fio = require('fio') local log = require('log') local errors = require('errors') local cartridge = require('cartridge') @@ -10,6 +11,8 @@ local cartridge = require('cartridge') if package.setsearchroot ~= nil then package.setsearchroot() else + local root = fio.dirname(fio.dirname(fio.dirname(fio.dirname(debug.sourcedir())))) + package.path = package.path .. root .. "/?.lua;" package.path = package.path .. debug.sourcedir() .. "/?.lua;" end @@ -30,6 +33,6 @@ if not ok then os.exit(1) end -require('all_init')() +require('all').init() _G.is_initialized = cartridge.is_healthy diff --git a/test/entrypoint/srv_schema/cartridge_init.lua b/test/entrypoint/srv_schema/cartridge_init.lua index 7998e50d..5588781f 100755 --- a/test/entrypoint/srv_schema/cartridge_init.lua +++ b/test/entrypoint/srv_schema/cartridge_init.lua @@ -3,6 +3,7 @@ require('strict').on() _G.is_initialized = function() return false end +local fio = require('fio') local log = require('log') local errors = require('errors') local cartridge = require('cartridge') @@ -10,13 +11,15 @@ local cartridge = require('cartridge') if package.setsearchroot ~= nil then package.setsearchroot() else + local root = fio.dirname(fio.dirname(fio.dirname(fio.dirname(debug.sourcedir())))) + package.path = package.path .. root .. "/?.lua;" package.path = package.path .. debug.sourcedir() .. "/?.lua;" end package.preload['customers-storage'] = function() return { role_name = 'customers-storage', - init = require('storage_init') + init = require('storage').init, } end diff --git a/test/entrypoint/srv_schema/storage.lua b/test/entrypoint/srv_schema/storage.lua new file mode 100644 index 00000000..e5496273 --- /dev/null +++ b/test/entrypoint/srv_schema/storage.lua @@ -0,0 +1,86 @@ +local schema = require('crud.schema') +local helper = require('test.helper') + +return { + init = function() + local engine = os.getenv('ENGINE') or 'memtx' + + rawset(_G, 'reload_schema', function() + for name, space in pairs(box.space) do + -- Can be indexed by space id and space name, + -- so we need to be careful with duplicates. + if type(name) == 'string' and schema.system_spaces[name] == nil then + space:drop() + end + end + + local customers_space = box.schema.space.create('customers', { + format = { + {name = 'id', type = 'unsigned'}, + {name = 'bucket_id', type = 'unsigned'}, + {name = 'name', type = 'string'}, + {name = 'age', type = 'number'}, + }, + if_not_exists = true, + engine = engine, + }) + customers_space:create_index('id', { + parts = { {field = 'id'} }, + if_not_exists = true, + }) + customers_space:create_index('bucket_id', { + parts = { {field = 'bucket_id'} }, + unique = false, + if_not_exists = true, + }) + + local shops_space = box.schema.space.create('shops', { + format = { + {name = 'registry_id', type = 'unsigned'}, + {name = 'bucket_id', type = 'unsigned'}, + {name = 'name', type = 'string'}, + {name = 'address', type = 'string'}, + {name = 'owner', type = 'string', is_nullable = true}, + }, + if_not_exists = true, + engine = engine, + }) + shops_space:create_index('registry', { + parts = { {field = 'registry_id'} }, + if_not_exists = true, + }) + shops_space:create_index('bucket_id', { + parts = { {field = 'bucket_id'} }, + unique = false, + if_not_exists = true, + }) + shops_space:create_index('address', { + parts = { {field = 'address'} }, + unique = true, + if_not_exists = true, + }) + end) + + rawset(_G, 'alter_schema', function() + box.space['customers']:create_index('age', { + parts = { {field = 'age'} }, + unique = false, + if_not_exists = true, + }) + + box.space['shops']:format({ + {name = 'registry_id', type = 'unsigned'}, + {name = 'bucket_id', type = 'unsigned'}, + {name = 'name', type = 'string'}, + {name = 'address', type = 'string'}, + {name = 'owner', type = 'string', is_nullable = true}, + {name = 'salary', type = 'unsigned', is_nullable = true}, + }) + end) + + helper.wrap_schema_init( + rawget(_G, 'reload_schema') + )() + end, + wait_until_ready = helper.wait_schema_init, +} diff --git a/test/entrypoint/srv_schema/storage_init.lua b/test/entrypoint/srv_schema/storage_init.lua deleted file mode 100644 index 4351fa87..00000000 --- a/test/entrypoint/srv_schema/storage_init.lua +++ /dev/null @@ -1,84 +0,0 @@ -local schema = require('crud.schema') - -return function() - if box.info.ro == true then - return - end - - local engine = os.getenv('ENGINE') or 'memtx' - - rawset(_G, 'reload_schema', function() - for name, space in pairs(box.space) do - -- Can be indexed by space id and space name, - -- so we need to be careful with duplicates. - if type(name) == 'string' and schema.system_spaces[name] == nil then - space:drop() - end - end - - local customers_space = box.schema.space.create('customers', { - format = { - {name = 'id', type = 'unsigned'}, - {name = 'bucket_id', type = 'unsigned'}, - {name = 'name', type = 'string'}, - {name = 'age', type = 'number'}, - }, - if_not_exists = true, - engine = engine, - }) - customers_space:create_index('id', { - parts = { {field = 'id'} }, - if_not_exists = true, - }) - customers_space:create_index('bucket_id', { - parts = { {field = 'bucket_id'} }, - unique = false, - if_not_exists = true, - }) - - local shops_space = box.schema.space.create('shops', { - format = { - {name = 'registry_id', type = 'unsigned'}, - {name = 'bucket_id', type = 'unsigned'}, - {name = 'name', type = 'string'}, - {name = 'address', type = 'string'}, - {name = 'owner', type = 'string', is_nullable = true}, - }, - if_not_exists = true, - engine = engine, - }) - shops_space:create_index('registry', { - parts = { {field = 'registry_id'} }, - if_not_exists = true, - }) - shops_space:create_index('bucket_id', { - parts = { {field = 'bucket_id'} }, - unique = false, - if_not_exists = true, - }) - shops_space:create_index('address', { - parts = { {field = 'address'} }, - unique = true, - if_not_exists = true, - }) - end) - - rawset(_G, 'alter_schema', function() - box.space['customers']:create_index('age', { - parts = { {field = 'age'} }, - unique = false, - if_not_exists = true, - }) - - box.space['shops']:format({ - {name = 'registry_id', type = 'unsigned'}, - {name = 'bucket_id', type = 'unsigned'}, - {name = 'name', type = 'string'}, - {name = 'address', type = 'string'}, - {name = 'owner', type = 'string', is_nullable = true}, - {name = 'salary', type = 'unsigned', is_nullable = true}, - }) - end) - - rawget(_G, 'reload_schema')() -end diff --git a/test/entrypoint/srv_select/cartridge_init.lua b/test/entrypoint/srv_select/cartridge_init.lua index 03a2c438..02c9fa5c 100755 --- a/test/entrypoint/srv_select/cartridge_init.lua +++ b/test/entrypoint/srv_select/cartridge_init.lua @@ -3,6 +3,7 @@ require('strict').on() _G.is_initialized = function() return false end +local fio = require('fio') local log = require('log') local errors = require('errors') local cartridge = require('cartridge') @@ -10,13 +11,15 @@ local cartridge = require('cartridge') if package.setsearchroot ~= nil then package.setsearchroot() else + local root = fio.dirname(fio.dirname(fio.dirname(fio.dirname(debug.sourcedir())))) + package.path = package.path .. root .. "/?.lua;" package.path = package.path .. debug.sourcedir() .. "/?.lua;" end package.preload['customers-storage'] = function() return { role_name = 'customers-storage', - init = require('storage_init') + init = require('storage').init, } end diff --git a/test/entrypoint/srv_select/storage.lua b/test/entrypoint/srv_select/storage.lua new file mode 100644 index 00000000..5b157d05 --- /dev/null +++ b/test/entrypoint/srv_select/storage.lua @@ -0,0 +1,195 @@ +local crud_utils = require('crud.common.utils') +local helper = require('test.helper') + +return { + init = helper.wrap_schema_init(function() + local engine = os.getenv('ENGINE') or 'memtx' + box.schema.space.create('no_index_space', { + format = { + {name = 'id', type = 'unsigned'}, + {name = 'bucket_id', type = 'unsigned'}, + {name = 'name', type = 'string'}, + }, + if_not_exists = true, + engine = engine, + }) + + local customers_space = box.schema.space.create('customers', { + format = { + {name = 'id', type = 'unsigned'}, + {name = 'bucket_id', type = 'unsigned'}, + {name = 'name', type = 'string'}, + {name = 'last_name', type = 'string'}, + {name = 'age', type = 'number'}, + {name = 'city', type = 'string'}, + }, + if_not_exists = true, + engine = engine, + }) + -- primary index + customers_space:create_index('id_index', { + parts = { {field = 'id'} }, + if_not_exists = true, + }) + customers_space:create_index('bucket_id', { + parts = { {field = 'bucket_id'} }, + unique = false, + if_not_exists = true, + }) + customers_space:create_index('age_index', { + parts = { {field = 'age'} }, + unique = false, + if_not_exists = true, + }) + -- indexes with same names as fields + customers_space:create_index('age', { + parts = { {field = 'age'} }, + unique = false, + if_not_exists = true, + }) + customers_space:create_index('id', { + parts = { {field = 'id'} }, + if_not_exists = true, + }) + customers_space:create_index('full_name', { + parts = { + {field = 'name', collation = 'unicode_ci'}, + {field = 'last_name', collation = 'unicode_ci'} , + }, + unique = false, + if_not_exists = true, + }) + + if crud_utils.tarantool_supports_uuids() then + local goods_space = box.schema.space.create('goods', { + format = { + {name = 'uuid', type = 'uuid'}, + {name = 'bucket_id', type = 'unsigned'}, + {name = 'name', type = 'string'}, + {name = 'category_id', type = 'uuid'}, + }, + if_not_exists = true, + engine = engine, + }) + --primary index + goods_space:create_index('uuid', { + parts = { {field = 'uuid'} }, + if_not_exists = true, + }) + goods_space:create_index('bucket_id', { + parts = { {field = 'bucket_id'} }, + unique = false, + if_not_exists = true, + }) + end + + local coord_space = box.schema.space.create('coord', { + format = { + {name = 'x', type = 'unsigned'}, + {name = 'y', type = 'unsigned'}, + {name = 'bucket_id', type = 'unsigned'}, + }, + if_not_exists = true, + engine = engine, + }) + -- primary index + coord_space:create_index('primary', { + parts = { + {field = 'x'}, + {field = 'y'}, + }, + if_not_exists = true, + }) + coord_space:create_index('bucket_id', { + parts = { {field = 'bucket_id'} }, + unique = false, + if_not_exists = true, + }) + + local book_translation = box.schema.space.create('book_translation', { + format = { + { name = 'id', type = 'unsigned' }, + { name = 'bucket_id', type = 'unsigned' }, + { name = 'language', type = 'string' }, + { name = 'edition', type = 'integer' }, + { name = 'translator', type = 'string' }, + { name = 'comments', type = 'string', is_nullable = true }, + }, + if_not_exists = true, + }) + + book_translation:create_index('id', { + parts = { 'id', 'language', 'edition' }, + if_not_exists = true, + }) + + book_translation:create_index('bucket_id', { + parts = { 'bucket_id' }, + unique = false, + if_not_exists = true, + }) + + local developers_space = box.schema.space.create('developers', { + format = { + {name = 'id', type = 'unsigned'}, + {name = 'bucket_id', type = 'unsigned'}, + {name = 'name', type = 'string'}, + {name = 'last_name', type = 'string'}, + {name = 'age', type = 'number'}, + {name = 'additional', type = 'any'}, + }, + if_not_exists = true, + engine = engine, + }) + + -- primary index + developers_space:create_index('id_index', { + parts = { 'id' }, + if_not_exists = true, + }) + + developers_space:create_index('bucket_id', { + parts = { 'bucket_id' }, + unique = false, + if_not_exists = true, + }) + + if crud_utils.tarantool_supports_jsonpath_indexes() then + local cars_space = box.schema.space.create('cars', { + format = { + {name = 'id', type = 'map'}, + {name = 'bucket_id', type = 'unsigned'}, + {name = 'age', type = 'number'}, + {name = 'manufacturer', type = 'string'}, + {name = 'data', type = 'map'} + }, + if_not_exists = true, + engine = engine, + }) + + -- primary index + cars_space:create_index('id_ind', { + parts = { + {1, 'unsigned', path = 'car_id.signed'}, + }, + if_not_exists = true, + }) + + cars_space:create_index('bucket_id', { + parts = { 'bucket_id' }, + unique = false, + if_not_exists = true, + }) + + cars_space:create_index('data_index', { + parts = { + {5, 'str', path = 'car.color'}, + {5, 'str', path = 'car.model'}, + }, + unique = false, + if_not_exists = true, + }) + end + end), + wait_until_ready = helper.wait_schema_init, +} diff --git a/test/entrypoint/srv_select/storage_init.lua b/test/entrypoint/srv_select/storage_init.lua deleted file mode 100644 index 5bc49aa4..00000000 --- a/test/entrypoint/srv_select/storage_init.lua +++ /dev/null @@ -1,195 +0,0 @@ -local crud_utils = require('crud.common.utils') - -return function() - if box.info.ro == true then - return - end - - local engine = os.getenv('ENGINE') or 'memtx' - box.schema.space.create('no_index_space', { - format = { - {name = 'id', type = 'unsigned'}, - {name = 'bucket_id', type = 'unsigned'}, - {name = 'name', type = 'string'}, - }, - if_not_exists = true, - engine = engine, - }) - - local customers_space = box.schema.space.create('customers', { - format = { - {name = 'id', type = 'unsigned'}, - {name = 'bucket_id', type = 'unsigned'}, - {name = 'name', type = 'string'}, - {name = 'last_name', type = 'string'}, - {name = 'age', type = 'number'}, - {name = 'city', type = 'string'}, - }, - if_not_exists = true, - engine = engine, - }) - -- primary index - customers_space:create_index('id_index', { - parts = { {field = 'id'} }, - if_not_exists = true, - }) - customers_space:create_index('bucket_id', { - parts = { {field = 'bucket_id'} }, - unique = false, - if_not_exists = true, - }) - customers_space:create_index('age_index', { - parts = { {field = 'age'} }, - unique = false, - if_not_exists = true, - }) - -- indexes with same names as fields - customers_space:create_index('age', { - parts = { {field = 'age'} }, - unique = false, - if_not_exists = true, - }) - customers_space:create_index('id', { - parts = { {field = 'id'} }, - if_not_exists = true, - }) - customers_space:create_index('full_name', { - parts = { - {field = 'name', collation = 'unicode_ci'}, - {field = 'last_name', collation = 'unicode_ci'} , - }, - unique = false, - if_not_exists = true, - }) - - if crud_utils.tarantool_supports_uuids() then - local goods_space = box.schema.space.create('goods', { - format = { - {name = 'uuid', type = 'uuid'}, - {name = 'bucket_id', type = 'unsigned'}, - {name = 'name', type = 'string'}, - {name = 'category_id', type = 'uuid'}, - }, - if_not_exists = true, - engine = engine, - }) - --primary index - goods_space:create_index('uuid', { - parts = { {field = 'uuid'} }, - if_not_exists = true, - }) - goods_space:create_index('bucket_id', { - parts = { {field = 'bucket_id'} }, - unique = false, - if_not_exists = true, - }) - end - - local coord_space = box.schema.space.create('coord', { - format = { - {name = 'x', type = 'unsigned'}, - {name = 'y', type = 'unsigned'}, - {name = 'bucket_id', type = 'unsigned'}, - }, - if_not_exists = true, - engine = engine, - }) - -- primary index - coord_space:create_index('primary', { - parts = { - {field = 'x'}, - {field = 'y'}, - }, - if_not_exists = true, - }) - coord_space:create_index('bucket_id', { - parts = { {field = 'bucket_id'} }, - unique = false, - if_not_exists = true, - }) - - local book_translation = box.schema.space.create('book_translation', { - format = { - { name = 'id', type = 'unsigned' }, - { name = 'bucket_id', type = 'unsigned' }, - { name = 'language', type = 'string' }, - { name = 'edition', type = 'integer' }, - { name = 'translator', type = 'string' }, - { name = 'comments', type = 'string', is_nullable = true }, - }, - if_not_exists = true, - }) - - book_translation:create_index('id', { - parts = { 'id', 'language', 'edition' }, - if_not_exists = true, - }) - - book_translation:create_index('bucket_id', { - parts = { 'bucket_id' }, - unique = false, - if_not_exists = true, - }) - - local developers_space = box.schema.space.create('developers', { - format = { - {name = 'id', type = 'unsigned'}, - {name = 'bucket_id', type = 'unsigned'}, - {name = 'name', type = 'string'}, - {name = 'last_name', type = 'string'}, - {name = 'age', type = 'number'}, - {name = 'additional', type = 'any'}, - }, - if_not_exists = true, - engine = engine, - }) - - -- primary index - developers_space:create_index('id_index', { - parts = { 'id' }, - if_not_exists = true, - }) - - developers_space:create_index('bucket_id', { - parts = { 'bucket_id' }, - unique = false, - if_not_exists = true, - }) - - if crud_utils.tarantool_supports_jsonpath_indexes() then - local cars_space = box.schema.space.create('cars', { - format = { - {name = 'id', type = 'map'}, - {name = 'bucket_id', type = 'unsigned'}, - {name = 'age', type = 'number'}, - {name = 'manufacturer', type = 'string'}, - {name = 'data', type = 'map'} - }, - if_not_exists = true, - engine = engine, - }) - - -- primary index - cars_space:create_index('id_ind', { - parts = { - {1, 'unsigned', path = 'car_id.signed'}, - }, - if_not_exists = true, - }) - - cars_space:create_index('bucket_id', { - parts = { 'bucket_id' }, - unique = false, - if_not_exists = true, - }) - - cars_space:create_index('data_index', { - parts = { - {5, 'str', path = 'car.color'}, - {5, 'str', path = 'car.model'}, - }, - unique = false, - if_not_exists = true, - }) - end -end diff --git a/test/entrypoint/srv_simple_operations/cartridge_init.lua b/test/entrypoint/srv_simple_operations/cartridge_init.lua index c4579622..c9118edc 100755 --- a/test/entrypoint/srv_simple_operations/cartridge_init.lua +++ b/test/entrypoint/srv_simple_operations/cartridge_init.lua @@ -3,6 +3,7 @@ require('strict').on() _G.is_initialized = function() return false end +local fio = require('fio') local log = require('log') local errors = require('errors') local cartridge = require('cartridge') @@ -10,13 +11,15 @@ local cartridge = require('cartridge') if package.setsearchroot ~= nil then package.setsearchroot() else + local root = fio.dirname(fio.dirname(fio.dirname(fio.dirname(debug.sourcedir())))) + package.path = package.path .. root .. "/?.lua;" package.path = package.path .. debug.sourcedir() .. "/?.lua;" end package.preload['customers-storage'] = function() return { role_name = 'customers-storage', - init = require('storage_init') + init = require('storage').init, } end diff --git a/test/entrypoint/srv_simple_operations/storage.lua b/test/entrypoint/srv_simple_operations/storage.lua new file mode 100644 index 00000000..a487a589 --- /dev/null +++ b/test/entrypoint/srv_simple_operations/storage.lua @@ -0,0 +1,135 @@ +local helper = require('test.helper') + +return { + init = helper.wrap_schema_init(function() + local engine = os.getenv('ENGINE') or 'memtx' + local customers_space = box.schema.space.create('customers', { + format = { + {name = 'id', type = 'unsigned'}, + {name = 'bucket_id', type = 'unsigned'}, + {name = 'name', type = 'string'}, + {name = 'age', type = 'number'}, + }, + if_not_exists = true, + engine = engine, + }) + customers_space:create_index('id', { + parts = { {field = 'id'} }, + if_not_exists = true, + }) + customers_space:create_index('bucket_id', { + parts = { {field = 'bucket_id'} }, + unique = false, + if_not_exists = true, + }) + + local developers_space = box.schema.space.create('developers', { + format = { + {name = 'id', type = 'unsigned'}, + {name = 'bucket_id', type = 'unsigned'}, + }, + if_not_exists = true, + engine = engine, + }) + developers_space:create_index('id', { + parts = { {field = 'id'} }, + if_not_exists = true, + }) + developers_space:create_index('bucket_id', { + parts = { {field = 'bucket_id'} }, + unique = false, + if_not_exists = true, + }) + + rawset(_G, 'add_extra_field', function(space_name, field_name) + local space = box.space[space_name] + local new_format = space:format() + table.insert(new_format, {name = field_name, type = 'any', is_nullable = true}) + space:format(new_format) + end) + + rawset(_G, 'create_space_for_gh_326_cases', function() + local countries_space = box.schema.space.create('countries', { + format = { + {name = 'id', type = 'unsigned'}, + {name = 'bucket_id', type = 'unsigned'}, + {name = 'name', type = 'string'}, + {name = 'population', type = 'unsigned'}, + }, + if_not_exists = true, + engine = os.getenv('ENGINE') or 'memtx', + }) + countries_space:create_index('id', { + parts = { {field = 'id'} }, + if_not_exists = true, + }) + countries_space:create_index('bucket_id', { + parts = { {field = 'bucket_id'} }, + unique = false, + if_not_exists = true, + }) + end) + + rawset(_G, 'drop_space_for_gh_326_cases', function() + box.space['countries']:drop() + end) + + -- Space with huge amount of nullable fields + -- an object that inserted in such space should get + -- explicit nulls in absence fields otherwise + -- Tarantool serializers could consider such object as map (not array). + local tags_space = box.schema.space.create('tags', { + format = { + {name = 'id', type = 'unsigned'}, + {name = 'bucket_id', type = 'unsigned'}, + {name = 'is_red', type = 'boolean', is_nullable = true}, + {name = 'is_green', type = 'boolean', is_nullable = true}, + {name = 'is_blue', type = 'boolean', is_nullable = true}, + {name = 'is_yellow', type = 'boolean', is_nullable = true}, + {name = 'is_sweet', type = 'boolean', is_nullable = true}, + {name = 'is_dirty', type = 'boolean', is_nullable = true}, + {name = 'is_long', type = 'boolean', is_nullable = true}, + {name = 'is_short', type = 'boolean', is_nullable = true}, + {name = 'is_useful', type = 'boolean', is_nullable = true}, + {name = 'is_correct', type = 'boolean', is_nullable = true}, + }, + if_not_exists = true, + engine = engine, + }) + + tags_space:create_index('id', { + parts = { {field = 'id'} }, + if_not_exists = true, + }) + tags_space:create_index('bucket_id', { + parts = { {field = 'bucket_id'} }, + unique = false, + if_not_exists = true, + }) + + local sequence_space = box.schema.space.create('notebook', { + format = { + {name = 'local_id', type = 'unsigned', is_nullable = false}, + {name = 'bucket_id', type = 'unsigned', is_nullable = false}, + {name = 'record', type = 'string', is_nullable = false}, + }, + if_not_exists = true, + engine = engine, + }) + + box.schema.sequence.create('local_id', {if_not_exists = true}) + + sequence_space:create_index('local_id', { + parts = { {field = 'local_id'} }, + unique = true, + if_not_exists = true, + sequence = 'local_id', + }) + sequence_space:create_index('bucket_id', { + parts = { {field = 'bucket_id'} }, + unique = false, + if_not_exists = true, + }) + end), + wait_until_ready = helper.wait_schema_init, +} diff --git a/test/entrypoint/srv_simple_operations/storage_init.lua b/test/entrypoint/srv_simple_operations/storage_init.lua deleted file mode 100644 index af90840b..00000000 --- a/test/entrypoint/srv_simple_operations/storage_init.lua +++ /dev/null @@ -1,134 +0,0 @@ -return function() - if box.info.ro == true then - return - end - - local engine = os.getenv('ENGINE') or 'memtx' - local customers_space = box.schema.space.create('customers', { - format = { - {name = 'id', type = 'unsigned'}, - {name = 'bucket_id', type = 'unsigned'}, - {name = 'name', type = 'string'}, - {name = 'age', type = 'number'}, - }, - if_not_exists = true, - engine = engine, - }) - customers_space:create_index('id', { - parts = { {field = 'id'} }, - if_not_exists = true, - }) - customers_space:create_index('bucket_id', { - parts = { {field = 'bucket_id'} }, - unique = false, - if_not_exists = true, - }) - - local developers_space = box.schema.space.create('developers', { - format = { - {name = 'id', type = 'unsigned'}, - {name = 'bucket_id', type = 'unsigned'}, - }, - if_not_exists = true, - engine = engine, - }) - developers_space:create_index('id', { - parts = { {field = 'id'} }, - if_not_exists = true, - }) - developers_space:create_index('bucket_id', { - parts = { {field = 'bucket_id'} }, - unique = false, - if_not_exists = true, - }) - - rawset(_G, 'add_extra_field', function(space_name, field_name) - local space = box.space[space_name] - local new_format = space:format() - table.insert(new_format, {name = field_name, type = 'any', is_nullable = true}) - space:format(new_format) - end) - - rawset(_G, 'create_space_for_gh_326_cases', function() - local countries_space = box.schema.space.create('countries', { - format = { - {name = 'id', type = 'unsigned'}, - {name = 'bucket_id', type = 'unsigned'}, - {name = 'name', type = 'string'}, - {name = 'population', type = 'unsigned'}, - }, - if_not_exists = true, - engine = os.getenv('ENGINE') or 'memtx', - }) - countries_space:create_index('id', { - parts = { {field = 'id'} }, - if_not_exists = true, - }) - countries_space:create_index('bucket_id', { - parts = { {field = 'bucket_id'} }, - unique = false, - if_not_exists = true, - }) - end) - - rawset(_G, 'drop_space_for_gh_326_cases', function() - box.space['countries']:drop() - end) - - -- Space with huge amount of nullable fields - -- an object that inserted in such space should get - -- explicit nulls in absence fields otherwise - -- Tarantool serializers could consider such object as map (not array). - local tags_space = box.schema.space.create('tags', { - format = { - {name = 'id', type = 'unsigned'}, - {name = 'bucket_id', type = 'unsigned'}, - {name = 'is_red', type = 'boolean', is_nullable = true}, - {name = 'is_green', type = 'boolean', is_nullable = true}, - {name = 'is_blue', type = 'boolean', is_nullable = true}, - {name = 'is_yellow', type = 'boolean', is_nullable = true}, - {name = 'is_sweet', type = 'boolean', is_nullable = true}, - {name = 'is_dirty', type = 'boolean', is_nullable = true}, - {name = 'is_long', type = 'boolean', is_nullable = true}, - {name = 'is_short', type = 'boolean', is_nullable = true}, - {name = 'is_useful', type = 'boolean', is_nullable = true}, - {name = 'is_correct', type = 'boolean', is_nullable = true}, - }, - if_not_exists = true, - engine = engine, - }) - - tags_space:create_index('id', { - parts = { {field = 'id'} }, - if_not_exists = true, - }) - tags_space:create_index('bucket_id', { - parts = { {field = 'bucket_id'} }, - unique = false, - if_not_exists = true, - }) - - local sequence_space = box.schema.space.create('notebook', { - format = { - {name = 'local_id', type = 'unsigned', is_nullable = false}, - {name = 'bucket_id', type = 'unsigned', is_nullable = false}, - {name = 'record', type = 'string', is_nullable = false}, - }, - if_not_exists = true, - engine = engine, - }) - - box.schema.sequence.create('local_id', {if_not_exists = true}) - - sequence_space:create_index('local_id', { - parts = { {field = 'local_id'} }, - unique = true, - if_not_exists = true, - sequence = 'local_id', - }) - sequence_space:create_index('bucket_id', { - parts = { {field = 'bucket_id'} }, - unique = false, - if_not_exists = true, - }) -end diff --git a/test/entrypoint/srv_stats/cartridge_init.lua b/test/entrypoint/srv_stats/cartridge_init.lua index 3cdd3ccf..5db3b4df 100755 --- a/test/entrypoint/srv_stats/cartridge_init.lua +++ b/test/entrypoint/srv_stats/cartridge_init.lua @@ -3,6 +3,7 @@ require('strict').on() _G.is_initialized = function() return false end +local fio = require('fio') local log = require('log') local errors = require('errors') local cartridge = require('cartridge') @@ -12,13 +13,15 @@ local crud_utils = require('crud.common.utils') if package.setsearchroot ~= nil then package.setsearchroot() else + local root = fio.dirname(fio.dirname(fio.dirname(fio.dirname(debug.sourcedir())))) + package.path = package.path .. root .. "/?.lua;" package.path = package.path .. debug.sourcedir() .. "/?.lua;" end package.preload['customers-storage'] = function() return { role_name = 'customers-storage', - init = require('storage_init'), + init = require('storage').init, } end diff --git a/test/entrypoint/srv_stats/storage.lua b/test/entrypoint/srv_stats/storage.lua new file mode 100644 index 00000000..62a41cde --- /dev/null +++ b/test/entrypoint/srv_stats/storage.lua @@ -0,0 +1,36 @@ +local helper = require('test.helper') + +return { + init = helper.wrap_schema_init(function() + local engine = os.getenv('ENGINE') or 'memtx' + local customers_space = box.schema.space.create('customers', { + format = { + {name = 'id', type = 'unsigned'}, + {name = 'bucket_id', type = 'unsigned'}, + {name = 'name', type = 'string'}, + {name = 'last_name', type = 'string'}, + {name = 'age', type = 'number'}, + {name = 'city', type = 'string'}, + }, + if_not_exists = true, + engine = engine, + id = 542, + }) + -- primary index + customers_space:create_index('id_index', { + parts = { {field = 'id'} }, + if_not_exists = true, + }) + customers_space:create_index('bucket_id', { + parts = { {field = 'bucket_id'} }, + unique = false, + if_not_exists = true, + }) + customers_space:create_index('age_index', { + parts = { {field = 'age'} }, + unique = false, + if_not_exists = true, + }) + end), + wait_until_ready = helper.wait_schema_init, +} diff --git a/test/entrypoint/srv_stats/storage_init.lua b/test/entrypoint/srv_stats/storage_init.lua deleted file mode 100644 index d64d5fc1..00000000 --- a/test/entrypoint/srv_stats/storage_init.lua +++ /dev/null @@ -1,35 +0,0 @@ -return function() - if box.info.ro == true then - return - end - - local engine = os.getenv('ENGINE') or 'memtx' - local customers_space = box.schema.space.create('customers', { - format = { - {name = 'id', type = 'unsigned'}, - {name = 'bucket_id', type = 'unsigned'}, - {name = 'name', type = 'string'}, - {name = 'last_name', type = 'string'}, - {name = 'age', type = 'number'}, - {name = 'city', type = 'string'}, - }, - if_not_exists = true, - engine = engine, - id = 542, - }) - -- primary index - customers_space:create_index('id_index', { - parts = { {field = 'id'} }, - if_not_exists = true, - }) - customers_space:create_index('bucket_id', { - parts = { {field = 'bucket_id'} }, - unique = false, - if_not_exists = true, - }) - customers_space:create_index('age_index', { - parts = { {field = 'age'} }, - unique = false, - if_not_exists = true, - }) -end diff --git a/test/entrypoint/srv_update_schema/cartridge_init.lua b/test/entrypoint/srv_update_schema/cartridge_init.lua index ba9b4274..c1082d07 100755 --- a/test/entrypoint/srv_update_schema/cartridge_init.lua +++ b/test/entrypoint/srv_update_schema/cartridge_init.lua @@ -3,6 +3,7 @@ require('strict').on() _G.is_initialized = function() return false end +local fio = require('fio') local log = require('log') local errors = require('errors') local cartridge = require('cartridge') @@ -10,13 +11,15 @@ local cartridge = require('cartridge') if package.setsearchroot ~= nil then package.setsearchroot() else + local root = fio.dirname(fio.dirname(fio.dirname(fio.dirname(debug.sourcedir())))) + package.path = package.path .. root .. "/?.lua;" package.path = package.path .. debug.sourcedir() .. "/?.lua;" end package.preload['customers-storage'] = function() return { role_name = 'customers-storage', - init = require('storage_init'), + init = require('storage').init, } end diff --git a/test/entrypoint/srv_update_schema/storage.lua b/test/entrypoint/srv_update_schema/storage.lua new file mode 100644 index 00000000..1135e748 --- /dev/null +++ b/test/entrypoint/srv_update_schema/storage.lua @@ -0,0 +1,72 @@ +return { + init = function() + local engine = os.getenv('ENGINE') or 'memtx' + rawset(_G, 'create_space', function() + local customers_space = box.schema.space.create('customers', { + format = { + {name = 'id', type = 'unsigned'}, + {name = 'bucket_id', type = 'unsigned'}, + {name = 'value', type = 'string'}, + {name = 'number', type = 'integer', is_nullable = true}, + }, + if_not_exists = true, + engine = engine, + }) + + -- primary index + customers_space:create_index('id_index', { + parts = { {field = 'id'} }, + if_not_exists = true, + }) + end) + + rawset(_G, 'create_bucket_id_index', function() + box.space.customers:create_index('bucket_id', { + parts = { {field = 'bucket_id'} }, + if_not_exists = true, + unique = false, + }) + end) + + rawset(_G, 'set_value_type_to_unsigned', function() + local new_format = {} + + for _, field_format in ipairs(box.space.customers:format()) do + if field_format.name == 'value' then + field_format.type = 'unsigned' + end + table.insert(new_format, field_format) + end + + box.space.customers:format(new_format) + end) + + rawset(_G, 'add_extra_field', function() + local new_format = box.space.customers:format() + table.insert(new_format, {name = 'extra', type = 'string', is_nullable = true}) + box.space.customers:format(new_format) + end) + + rawset(_G, 'add_value_index', function() + box.space.customers:create_index('value_index', { + parts = { {field = 'value'} }, + if_not_exists = true, + unique = false, + }) + end) + + rawset(_G, 'create_number_value_index', function() + box.space.customers:create_index('number_value_index', { + parts = { {field = 'number'}, {field = 'value'} }, + if_not_exists = true, + unique = false, + }) + end) + + rawset(_G, 'alter_number_value_index', function() + box.space.customers.index.number_value_index:alter({ + parts = { {field = 'value'}, {field = 'number'} }, + }) + end) + end, +} \ No newline at end of file diff --git a/test/entrypoint/srv_update_schema/storage_init.lua b/test/entrypoint/srv_update_schema/storage_init.lua deleted file mode 100644 index 0c81fa88..00000000 --- a/test/entrypoint/srv_update_schema/storage_init.lua +++ /dev/null @@ -1,74 +0,0 @@ -return function() - if box.info.ro == true then - return - end - - local engine = os.getenv('ENGINE') or 'memtx' - rawset(_G, 'create_space', function() - local customers_space = box.schema.space.create('customers', { - format = { - {name = 'id', type = 'unsigned'}, - {name = 'bucket_id', type = 'unsigned'}, - {name = 'value', type = 'string'}, - {name = 'number', type = 'integer', is_nullable = true}, - }, - if_not_exists = true, - engine = engine, - }) - - -- primary index - customers_space:create_index('id_index', { - parts = { {field = 'id'} }, - if_not_exists = true, - }) - end) - - rawset(_G, 'create_bucket_id_index', function() - box.space.customers:create_index('bucket_id', { - parts = { {field = 'bucket_id'} }, - if_not_exists = true, - unique = false, - }) - end) - - rawset(_G, 'set_value_type_to_unsigned', function() - local new_format = {} - - for _, field_format in ipairs(box.space.customers:format()) do - if field_format.name == 'value' then - field_format.type = 'unsigned' - end - table.insert(new_format, field_format) - end - - box.space.customers:format(new_format) - end) - - rawset(_G, 'add_extra_field', function() - local new_format = box.space.customers:format() - table.insert(new_format, {name = 'extra', type = 'string', is_nullable = true}) - box.space.customers:format(new_format) - end) - - rawset(_G, 'add_value_index', function() - box.space.customers:create_index('value_index', { - parts = { {field = 'value'} }, - if_not_exists = true, - unique = false, - }) - end) - - rawset(_G, 'create_number_value_index', function() - box.space.customers:create_index('number_value_index', { - parts = { {field = 'number'}, {field = 'value'} }, - if_not_exists = true, - unique = false, - }) - end) - - rawset(_G, 'alter_number_value_index', function() - box.space.customers.index.number_value_index:alter({ - parts = { {field = 'value'}, {field = 'number'} }, - }) - end) -end diff --git a/test/helper.lua b/test/helper.lua index 4022b113..ad63f3a2 100644 --- a/test/helper.lua +++ b/test/helper.lua @@ -9,6 +9,7 @@ local luatest_utils = require('luatest.utils') local checks = require('checks') local digest = require('digest') +local fiber = require('fiber') local fio = require('fio') local crud = require('crud') @@ -87,15 +88,15 @@ local function entrypoint_vshard(name, entrypoint, err) end function helpers.entrypoint_vshard_storage(name) - return entrypoint_vshard(name, 'storage_init', true) + return entrypoint_vshard(name, 'storage', true) end function helpers.entrypoint_vshard_router(name) - return entrypoint_vshard(name, 'router_init', true) + return entrypoint_vshard(name, 'router', true) end function helpers.entrypoint_vshard_all(name) - return entrypoint_vshard(name, 'all_init', true) + return entrypoint_vshard(name, 'all', true) end function helpers.table_keys(t) @@ -704,9 +705,9 @@ function helpers.start_default_cluster(g, srv_name) local vshard_cfg = { sharding = helpers.get_test_vshard_sharding(), bucket_count = 3000, - storage_init = entrypoint_vshard(srv_name, 'storage_init', false), - router_init = entrypoint_vshard(srv_name, 'router_init', false), - all_init = entrypoint_vshard(srv_name, 'all_init', false), + storage_entrypoint = entrypoint_vshard(srv_name, 'storage', false), + router_entrypoint = entrypoint_vshard(srv_name, 'router', false), + all_entrypoint = entrypoint_vshard(srv_name, 'all', false), crud_init = true, async_storage_start = helpers.async_storage_start(), } @@ -954,4 +955,60 @@ function helpers.async_storage_start() return instance_start_in_ro_mode() and async_storage_start_supported() end +helpers.SCHEMA_READY_FLAG = '_is_schema_ready' + +function helpers.set_func_flag(flag) + box.schema.func.create(flag, { + language = 'LUA', + body = 'function() return true end', + if_not_exists = true, + }) +end + +function helpers.wait_func_flag(flag) + while true do + local status, ready = pcall(box.schema.func.call, flag) + + if status and ready then + return true + end + + fiber.sleep(0.05) + end +end + +function helpers.wrap_schema_init(func) + local function wrapped_func() + if box.info.ro then + return + end + + func() + + helpers.set_func_flag(helpers.SCHEMA_READY_FLAG) + end + + if helpers.async_storage_start() then + return function() + box.watch('box.status', wrapped_func) + end + else + return wrapped_func + end +end + +function helpers.wait_schema_init() + helpers.wait_func_flag(helpers.SCHEMA_READY_FLAG) +end + +function helpers.wait_rw() + while true do + if box.info.ro == false then + return + end + + fiber.sleep(0.05) + end +end + return helpers diff --git a/test/integration/read_calls_strategies_test.lua b/test/integration/read_calls_strategies_test.lua index 1373271b..19bb4f4d 100644 --- a/test/integration/read_calls_strategies_test.lua +++ b/test/integration/read_calls_strategies_test.lua @@ -32,13 +32,13 @@ pgroup.before_all(function(g) g.space_format = g.cluster:server('s1-master').net_box.space.customers:format() g.clear_vshard_calls = function() - g.cluster.main_server.net_box:call('clear_vshard_calls') + g.router:call('clear_vshard_calls') end g.get_vshard_call_strategies = function() -- Retries are possible, especially in CI, so we don't assert -- the quantity of calls, only strategies used. - local vshard_calls = g.cluster.main_server.net_box:eval('return _G.vshard_calls') + local vshard_calls = g.router:eval('return _G.vshard_calls') local vshard_call_strategies_map = {} for _, v in ipairs(vshard_calls) do @@ -54,7 +54,7 @@ pgroup.before_all(function(g) -- patch vshard.router.call* functions local vshard_call_names = {'callro', 'callbro', 'callre', 'callbre', 'callrw'} - g.cluster.main_server.net_box:call('patch_vshard_calls', {vshard_call_names}) + g.router:call('patch_vshard_calls', {vshard_call_names}) end) pgroup.after_all(function(g) @@ -67,7 +67,7 @@ end) pgroup.test_get = function(g) g.clear_vshard_calls() - local _, err = g.cluster.main_server.net_box:call('crud.get', {'customers', 1, { + local _, err = g.router:call('crud.get', {'customers', 1, { mode = g.params.mode, balance = g.params.balance, prefer_replica = g.params.prefer_replica @@ -79,7 +79,7 @@ end pgroup.test_select = function(g) g.clear_vshard_calls() - local _, err = g.cluster.main_server.net_box:call('crud.select', {'customers', nil, { + local _, err = g.router:call('crud.select', {'customers', nil, { mode = g.params.mode, balance = g.params.balance, prefer_replica = g.params.prefer_replica, @@ -99,7 +99,7 @@ pgroup.test_pairs = function(g) prefer_replica = g.params.prefer_replica } - local _, err = g.cluster.main_server.net_box:eval([[ + local _, err = g.router:eval([[ local crud = require('crud') local opts = ... @@ -112,7 +112,7 @@ end pgroup.test_count = function(g) g.clear_vshard_calls() - local _, err = g.cluster.main_server.net_box:call('crud.count', {'customers', nil, { + local _, err = g.router:call('crud.count', {'customers', nil, { mode = g.params.mode, balance = g.params.balance, prefer_replica = g.params.prefer_replica, diff --git a/test/integration/stats_test.lua b/test/integration/stats_test.lua index bf7576da..b9d23167 100644 --- a/test/integration/stats_test.lua +++ b/test/integration/stats_test.lua @@ -115,24 +115,28 @@ group_metrics.after_each(disable_stats) local function create_new_space(g) helpers.call_on_storages(g.cluster, function(server) - server.net_box:eval([[ - local space_name = ... - if not box.cfg.read_only then - local sp = box.schema.space.create(space_name, { format = { - {name = 'id', type = 'unsigned'}, - {name = 'bucket_id', type = 'unsigned'}, - }}) + server:exec(function(space_name) + if not box.info.ro then + local sp = box.schema.space.create(space_name, { + format = { + {name = 'id', type = 'unsigned'}, + {name = 'bucket_id', type = 'unsigned'}, + }, + if_not_exists = true, + }) sp:create_index('pk', { parts = { {field = 'id'} }, + if_not_exists = true, }) sp:create_index('bucket_id', { parts = { {field = 'bucket_id'} }, unique = false, + if_not_exists = true, }) end - ]], { new_space_name }) + end, {new_space_name}) end) end diff --git a/test/performance/perf_test.lua b/test/performance/perf_test.lua index 436a6446..6b37b781 100644 --- a/test/performance/perf_test.lua +++ b/test/performance/perf_test.lua @@ -50,7 +50,7 @@ local vshard_cfg_template = { }, }, bucket_count = 3000, - storage_init = helpers.entrypoint_vshard_storage('srv_ddl'), + storage_entrypoint = helpers.entrypoint_vshard_storage('srv_ddl'), crud_init = true, } diff --git a/test/unit/call_test.lua b/test/unit/call_test.lua index 3332381f..4a9a7cc4 100644 --- a/test/unit/call_test.lua +++ b/test/unit/call_test.lua @@ -26,7 +26,7 @@ local vshard_cfg_template = { }, }, bucket_count = 3000, - all_init = helpers.entrypoint_vshard_all('srv_say_hi'), + all_entrypoint = helpers.entrypoint_vshard_all('srv_say_hi'), crud_init = true, } diff --git a/test/unit/not_initialized_test.lua b/test/unit/not_initialized_test.lua index e204bd25..e05c8e7f 100644 --- a/test/unit/not_initialized_test.lua +++ b/test/unit/not_initialized_test.lua @@ -18,7 +18,7 @@ local vshard_cfg_template = { }, }, bucket_count = 20, - storage_init = helpers.entrypoint_vshard_storage('srv_not_initialized'), + storage_entrypoint = helpers.entrypoint_vshard_storage('srv_not_initialized'), } local cartridge_cfg_template = { diff --git a/test/unit/select_dropped_indexes_test.lua b/test/unit/select_dropped_indexes_test.lua index 2347efa0..cb0d7a1c 100644 --- a/test/unit/select_dropped_indexes_test.lua +++ b/test/unit/select_dropped_indexes_test.lua @@ -10,6 +10,7 @@ local helpers = require('test.helper') g.before_all = function() helpers.box_cfg() + helpers.wait_rw() local customers = box.schema.space.create('customers', { format = { diff --git a/test/unit/select_executor_test.lua b/test/unit/select_executor_test.lua index 2623b744..1b206ec9 100644 --- a/test/unit/select_executor_test.lua +++ b/test/unit/select_executor_test.lua @@ -26,6 +26,7 @@ end g.before_all = function() helpers.box_cfg() + helpers.wait_rw() local customers_space = box.schema.space.create('customers', { format = { diff --git a/test/unit/select_filters_test.lua b/test/unit/select_filters_test.lua index a8272c8e..50dded8e 100644 --- a/test/unit/select_filters_test.lua +++ b/test/unit/select_filters_test.lua @@ -15,6 +15,7 @@ local helpers = require('test.helper') g.before_all = function() helpers.box_cfg() + helpers.wait_rw() local customers_space = box.schema.space.create('customers', { format = { diff --git a/test/unit/select_filters_uuid_test.lua b/test/unit/select_filters_uuid_test.lua index ee6b1f2e..4f57b32a 100644 --- a/test/unit/select_filters_uuid_test.lua +++ b/test/unit/select_filters_uuid_test.lua @@ -17,6 +17,7 @@ local helpers = require('test.helper') g.before_all = function() if crud_utils.tarantool_supports_uuids() then helpers.box_cfg() + helpers.wait_rw() local customers_space = box.schema.space.create('customers', { format = { diff --git a/test/unit/select_plan_bad_indexes_test.lua b/test/unit/select_plan_bad_indexes_test.lua index a63e1c3f..db25c2f6 100644 --- a/test/unit/select_plan_bad_indexes_test.lua +++ b/test/unit/select_plan_bad_indexes_test.lua @@ -12,6 +12,7 @@ local NOT_FOUND_INDEX_ERR_MSG = 'An index that matches specified conditions was g.before_all = function() helpers.box_cfg() + helpers.wait_rw() local customers_space = box.schema.space.create('customers', { format = { diff --git a/test/unit/select_plan_test.lua b/test/unit/select_plan_test.lua index af9b3426..a4dcd6c6 100644 --- a/test/unit/select_plan_test.lua +++ b/test/unit/select_plan_test.lua @@ -10,6 +10,7 @@ local helpers = require('test.helper') g.before_all = function() helpers.box_cfg() + helpers.wait_rw() local customers_space = box.schema.space.create('customers', { format = { diff --git a/test/unit/serialization_test.lua b/test/unit/serialization_test.lua index 5decefe4..9a19ee94 100644 --- a/test/unit/serialization_test.lua +++ b/test/unit/serialization_test.lua @@ -7,6 +7,7 @@ local helpers = require('test.helper') g.before_all = function() helpers.box_cfg() + helpers.wait_rw() local customers_space = box.schema.space.create('customers', { format = { diff --git a/test/unit/sharding_metadata_test.lua b/test/unit/sharding_metadata_test.lua index be2ce2a3..58e4b856 100644 --- a/test/unit/sharding_metadata_test.lua +++ b/test/unit/sharding_metadata_test.lua @@ -24,25 +24,26 @@ g.before_each(function() {name = 'sharding_func_body', type = 'string', is_nullable = true}, } - if type(box.cfg) ~= 'table' then - helpers.box_cfg() - end + helpers.box_cfg() + helpers.wait_rw() -- Create a space _ddl_sharding_key with a tuple that -- contains a space name and it's sharding key. box.schema.space.create('_ddl_sharding_key', { format = sharding_key_format, + if_not_exists = true, }) - box.space._ddl_sharding_key:create_index('pk') + box.space._ddl_sharding_key:create_index('pk', {if_not_exists = true}) -- Create a space _ddl_sharding_func with a tuple that -- contains a space name and it's sharding func name/body. box.schema.space.create('_ddl_sharding_func', { format = sharding_func_format, + if_not_exists = true, }) - box.space._ddl_sharding_func:create_index('pk') + box.space._ddl_sharding_func:create_index('pk', {if_not_exists = true}) - box.schema.space.create('fetch_on_storage') + box.schema.space.create('fetch_on_storage', {if_not_exists = true}) end) -- Since Tarantool 3.0 triggers still live after a space drop. To properly diff --git a/test/vshard_helpers/vtest.lua b/test/vshard_helpers/vtest.lua index caa62b6d..31bab49e 100644 --- a/test/vshard_helpers/vtest.lua +++ b/test/vshard_helpers/vtest.lua @@ -221,16 +221,26 @@ local function start_router(g, cfg, opts) cfg.engine = nil local router = router_new(g, 'router', cfg) - if opts.router_init ~= nil then - router:exec(function(router_init) - require(router_init)() - end, {opts.router_init}) + if opts.router_entrypoint ~= nil then + router:exec(function(router_entrypoint) + local entrypoint = require(router_entrypoint) + entrypoint.init() + if entrypoint.wait_until_ready ~= nil then + entrypoint.wait_until_ready() + end + end, {opts.router_entrypoint}) end - if opts.all_init ~= nil then - router:exec(function(all_init) - require(all_init)() - end, {opts.all_init}) + + if opts.all_entrypoint ~= nil then + router:exec(function(all_entrypoint) + local entrypoint = require(all_entrypoint) + entrypoint.init() + if entrypoint.wait_until_ready ~= nil then + entrypoint.wait_until_ready() + end + end, {opts.all_entrypoint}) end + if opts.crud_init then router:exec(function() require('crud').init_router() @@ -400,15 +410,15 @@ local function cluster_new(g, cfg) local replicas = {} local master_map = {} - local storage_init = cfg.storage_init - local router_init = cfg.router_init - local all_init = cfg.all_init + local storage_entrypoint = cfg.storage_entrypoint + local router_entrypoint = cfg.router_entrypoint + local all_entrypoint = cfg.all_entrypoint local crud_init = cfg.crud_init local async_storage_start = cfg.async_storage_start - cfg.storage_init = nil - cfg.router_init = nil - cfg.all_init = nil + cfg.storage_entrypoint = nil + cfg.router_entrypoint = nil + cfg.all_entrypoint = nil cfg.crud_init = nil cfg.async_storage_start = nil @@ -537,15 +547,38 @@ local function cluster_new(g, cfg) end for _, replica in pairs(all_servers) do - if storage_init ~= nil then - replica:exec(function(storage_init) - require(storage_init)() - end, {storage_init}) + if storage_entrypoint ~= nil then + replica:exec(function(storage_entrypoint) + local entrypoint = require(storage_entrypoint) + entrypoint.init() + end, {storage_entrypoint}) end - if all_init ~= nil then - replica:exec(function(all_init) - require(all_init)() - end, {all_init}) + + if all_entrypoint ~= nil then + replica:exec(function(all_entrypoint) + local entrypoint = require(all_entrypoint) + entrypoint.init() + end, {all_entrypoint}) + end + end + + for _, replica in pairs(all_servers) do + if storage_entrypoint ~= nil then + replica:exec(function(storage_entrypoint) + local entrypoint = require(storage_entrypoint) + if entrypoint.wait_until_ready then + entrypoint.wait_until_ready() + end + end, {storage_entrypoint}) + end + + if all_entrypoint ~= nil then + replica:exec(function(all_entrypoint) + local entrypoint = require(all_entrypoint) + if entrypoint.wait_until_ready then + entrypoint.wait_until_ready() + end + end, {all_entrypoint}) end end @@ -567,8 +600,8 @@ local function cluster_new(g, cfg) end start_router(g, cfg, { - router_init = router_init, - all_init = all_init, + router_entrypoint = router_entrypoint, + all_entrypoint = all_entrypoint, crud_init = crud_init, })