-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The approach is similar to crud bootstrap waiting. Cartridge tests approach remains the same. Part of #412 Part of #415
- Loading branch information
1 parent
ed42abb
commit c2c3c1c
Showing
57 changed files
with
1,388 additions
and
1,199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
} |
Oops, something went wrong.