Skip to content

Commit

Permalink
test: call router for router operations
Browse files Browse the repository at this point in the history
Before this patch, most tests used an assumption that main server is
a router. Yet these are two different concepts.

`main_server` entity was introduced in Cartridge test helpers Cluster
as some server you may refer to for maintenance work, like clusterwide
configuration update. Any cluster server is fine to do such operation:
router or not. Since most cluster configurations start with router
definition, it is often a first server in a list and is chosen to be
main_server as well. But no one guarantees that main_server provides
router API (both for vshard and crud).
  • Loading branch information
DifferentialOrange committed Jan 23, 2024
1 parent 28d5eab commit 0860a83
Show file tree
Hide file tree
Showing 31 changed files with 810 additions and 822 deletions.
23 changes: 9 additions & 14 deletions test/helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function helpers.insert_objects(g, space_name, objects)
local inserted_objects = {}

for _, obj in ipairs(objects) do
local result, err = g.cluster.main_server.net_box:call('crud.insert_object', {space_name, obj})
local result, err = g.router:call('crud.insert_object', {space_name, obj})

t.assert_equals(err, nil)

Expand Down Expand Up @@ -354,7 +354,7 @@ function helpers.assert_ge(actual, expected, message)
end

function helpers.get_other_storage_bucket_id(cluster, bucket_id)
return cluster.main_server.net_box:eval([[
return cluster:server('router'):eval([[
local vshard = require('vshard')
local bucket_id = ...
Expand Down Expand Up @@ -392,7 +392,7 @@ end
helpers.tarantool_version_at_least = crud_utils.tarantool_version_at_least

function helpers.update_sharding_key_cache(cluster, space_name)
return cluster.main_server.net_box:eval([[
return cluster:server('router'):eval([[
local sharding_key = require('crud.common.sharding_key')
local space_name = ...
Expand All @@ -401,7 +401,7 @@ function helpers.update_sharding_key_cache(cluster, space_name)
end

function helpers.get_sharding_key_cache(cluster)
return cluster.main_server.net_box:eval([[
return cluster:server('router'):eval([[
local vshard = require('vshard')
local sharding_metadata_cache = require('crud.common.sharding.router_metadata_cache')
Expand All @@ -416,7 +416,7 @@ end
-- object through net.box that's why we get a sign of record
-- existence of cache but not the cache itself
function helpers.update_sharding_func_cache(cluster, space_name)
return cluster.main_server.net_box:eval([[
return cluster:server('router'):eval([[
local sharding_func = require('crud.common.sharding_func')
local space_name = ...
Expand All @@ -433,7 +433,7 @@ end
-- object through net.box that's why we get size of cache
-- but not the cache itself
function helpers.get_sharding_func_cache_size(cluster)
return cluster.main_server.net_box:eval([[
return cluster:server('router'):eval([[
local vshard = require('vshard')
local sharding_metadata_cache = require('crud.common.sharding.router_metadata_cache')
Expand Down Expand Up @@ -734,6 +734,9 @@ function helpers.start_cluster(g, cartridge_cfg, vshard_cfg)
vtest.cluster_new(g, g.cfg)
g.cfg.engine = nil
end

g.router = g.cluster:server('router')
assert(g.router ~= nil, 'router found')
end

function helpers.stop_cluster(cluster, backend)
Expand All @@ -744,14 +747,6 @@ function helpers.stop_cluster(cluster, backend)
end
end

function helpers.get_router(cluster, backend)
if backend == helpers.backend.CARTRIDGE then
return cluster:server('router')
elseif backend == helpers.backend.VSHARD then
return cluster.main_server
end
end

function helpers.parse_module_version(str)
-- https://github.com/tarantool/luatest/blob/f37b353b77be50a1f1ce87c1ff2edf0c1b96d5d1/luatest/utils.lua#L166-L173
local splitstr = str:split('.')
Expand Down
64 changes: 32 additions & 32 deletions test/integration/borders_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ end)

pgroup.test_non_existent_space = function(g)
-- min
local result, err = g.cluster.main_server.net_box:call('crud.min', {
local result, err = g.router:call('crud.min', {
'non_existent_space',
nil,
{mode = 'write'},
Expand All @@ -36,7 +36,7 @@ pgroup.test_non_existent_space = function(g)
t.assert_str_contains(err.err, "Space \"non_existent_space\" doesn't exist")

-- max
local result, err = g.cluster.main_server.net_box:call('crud.max', {
local result, err = g.router:call('crud.max', {
'non_existent_space',
nil,
{mode = 'write'},
Expand All @@ -48,7 +48,7 @@ end

pgroup.test_non_existent_index = function(g)
-- min
local result, err = g.cluster.main_server.net_box:call('crud.min', {
local result, err = g.router:call('crud.min', {
'customers',
'non_existent_index',
{mode = 'write'},
Expand All @@ -57,7 +57,7 @@ pgroup.test_non_existent_index = function(g)
t.assert_equals(result, nil)
t.assert_str_contains(err.err, "Index \"non_existent_index\" of space \"customers\" doesn't exist")

local result, err = g.cluster.main_server.net_box:call('crud.min', {
local result, err = g.router:call('crud.min', {
'customers',
13,
{mode = 'write'},
Expand All @@ -67,7 +67,7 @@ pgroup.test_non_existent_index = function(g)
t.assert_str_contains(err.err, "Index \"13\" of space \"customers\" doesn't exist")

-- max
local result, err = g.cluster.main_server.net_box:call('crud.max', {
local result, err = g.router:call('crud.max', {
'customers',
'non_existent_index',
{mode = 'write'},
Expand All @@ -76,7 +76,7 @@ pgroup.test_non_existent_index = function(g)
t.assert_equals(result, nil)
t.assert_str_contains(err.err, "Index \"non_existent_index\" of space \"customers\" doesn't exist")

local result, err = g.cluster.main_server.net_box:call('crud.max', {
local result, err = g.router:call('crud.max', {
'customers',
13,
{mode = 'write'},
Expand All @@ -88,7 +88,7 @@ end

pgroup.test_empty_space = function(g)
-- min
local result, err = g.cluster.main_server.net_box:call('crud.min', {
local result, err = g.router:call('crud.min', {
'customers',
nil,
{mode = 'write'},
Expand All @@ -98,7 +98,7 @@ pgroup.test_empty_space = function(g)
t.assert_equals(#result.rows, 0)

-- min by age index with fields
local result, err = g.cluster.main_server.net_box:call('crud.min', {
local result, err = g.router:call('crud.min', {
'customers',
'age_index',
{fields = {'name'}, mode = 'write'},
Expand All @@ -108,7 +108,7 @@ pgroup.test_empty_space = function(g)
t.assert_equals(#result.rows, 0)

-- max
local result, err = g.cluster.main_server.net_box:call('crud.max', {
local result, err = g.router:call('crud.max', {
'customers',
nil,
{mode = 'write'},
Expand All @@ -118,7 +118,7 @@ pgroup.test_empty_space = function(g)
t.assert_equals(#result.rows, 0)

-- max by age index with fields
local result, err = g.cluster.main_server.net_box:call('crud.max', {
local result, err = g.router:call('crud.max', {
'customers',
'age_index',
{fields = {'name'}, mode = 'write'},
Expand Down Expand Up @@ -148,71 +148,71 @@ pgroup.test_min = function(g)
table.sort(customers, function(obj1, obj2) return obj1.id < obj2.id end)

-- by primary
local result, err = g.cluster.main_server.net_box:call('crud.min', {
local result, err = g.router:call('crud.min', {
'customers', nil, {mode = 'write'},
})
t.assert_equals(err, nil)
local objects = crud.unflatten_rows(result.rows, result.metadata)
t.assert_equals(objects, helpers.get_objects_by_idxs(customers, {1}))

-- by primary, index ID is specified
local result, err = g.cluster.main_server.net_box:call('crud.min', {
local result, err = g.router:call('crud.min', {
'customers', 0, {mode = 'write'},
})
t.assert_equals(err, nil)
local objects = crud.unflatten_rows(result.rows, result.metadata)
t.assert_equals(objects, helpers.get_objects_by_idxs(customers, {1}))

-- by primary with fields
local result, err = g.cluster.main_server.net_box:call('crud.min', {
local result, err = g.router:call('crud.min', {
'customers', nil, {fields = {'name', 'last_name'}, mode = 'write'},
})
t.assert_equals(err, nil)
local objects = crud.unflatten_rows(result.rows, result.metadata)
t.assert_equals(objects, {{name = "Elizabeth", last_name = "Jackson"}})

-- by age index
local result, err = g.cluster.main_server.net_box:call('crud.min', {
local result, err = g.router:call('crud.min', {
'customers', 'age_index', {mode = 'write'},
})
t.assert_equals(err, nil)
local objects = crud.unflatten_rows(result.rows, result.metadata)
t.assert_equals(objects, helpers.get_objects_by_idxs(customers, {4}))

-- by age index, index ID is specified
local result, err = g.cluster.main_server.net_box:call('crud.min', {
local result, err = g.router:call('crud.min', {
'customers', 2, {mode = 'write'},
})
t.assert_equals(err, nil)
local objects = crud.unflatten_rows(result.rows, result.metadata)
t.assert_equals(objects, helpers.get_objects_by_idxs(customers, {4}))

-- by age index with fields
local result, err = g.cluster.main_server.net_box:call('crud.min', {
local result, err = g.router:call('crud.min', {
'customers', 'age_index', {fields = {'name', 'last_name'}, mode = 'write'},
})
t.assert_equals(err, nil)
local objects = crud.unflatten_rows(result.rows, result.metadata)
t.assert_equals(objects, {{name = "William", last_name = "White"}})

-- by composite index full_name
local result, err = g.cluster.main_server.net_box:call('crud.min', {
local result, err = g.router:call('crud.min', {
'customers', 'full_name', {mode = 'write'},
})
t.assert_equals(err, nil)
local objects = crud.unflatten_rows(result.rows, result.metadata)
t.assert_equals(objects, helpers.get_objects_by_idxs(customers, {3}))

-- by composite index full_name, index ID is specified
local result, err = g.cluster.main_server.net_box:call('crud.min', {
local result, err = g.router:call('crud.min', {
'customers', 5, {mode = 'write'},
})
t.assert_equals(err, nil)
local objects = crud.unflatten_rows(result.rows, result.metadata)
t.assert_equals(objects, helpers.get_objects_by_idxs(customers, {3}))

-- by composite index full_name with fields
local result, err = g.cluster.main_server.net_box:call('crud.min', {
local result, err = g.router:call('crud.min', {
'customers', 'full_name', {fields = {'name', 'last_name'}, mode = 'write'},
})
t.assert_equals(err, nil)
Expand Down Expand Up @@ -240,71 +240,71 @@ pgroup.test_max = function(g)
table.sort(customers, function(obj1, obj2) return obj1.id < obj2.id end)

-- by primary
local result, err = g.cluster.main_server.net_box:call('crud.max', {
local result, err = g.router:call('crud.max', {
'customers', nil, {mode = 'write'},
})
t.assert_equals(err, nil)
local objects = crud.unflatten_rows(result.rows, result.metadata)
t.assert_equals(objects, helpers.get_objects_by_idxs(customers, {4}))

-- by primary, index ID is specified
local result, err = g.cluster.main_server.net_box:call('crud.max', {
local result, err = g.router:call('crud.max', {
'customers', 0, {mode = 'write'},
})
t.assert_equals(err, nil)
local objects = crud.unflatten_rows(result.rows, result.metadata)
t.assert_equals(objects, helpers.get_objects_by_idxs(customers, {4}))

-- by primary with fields
local result, err = g.cluster.main_server.net_box:call('crud.max', {
local result, err = g.router:call('crud.max', {
'customers', nil, {fields = {'name', 'last_name'}, mode = 'write'}
})
t.assert_equals(err, nil)
local objects = crud.unflatten_rows(result.rows, result.metadata)
t.assert_equals(objects, {{name = "William", last_name = "White"}})

-- by age index
local result, err = g.cluster.main_server.net_box:call('crud.max', {
local result, err = g.router:call('crud.max', {
'customers', 'age_index', {mode = 'write'},
})
t.assert_equals(err, nil)
local objects = crud.unflatten_rows(result.rows, result.metadata)
t.assert_equals(objects, helpers.get_objects_by_idxs(customers, {2}))

-- by age index, index ID is specified
local result, err = g.cluster.main_server.net_box:call('crud.max', {
local result, err = g.router:call('crud.max', {
'customers', 2, {mode = 'write'},
})
t.assert_equals(err, nil)
local objects = crud.unflatten_rows(result.rows, result.metadata)
t.assert_equals(objects, helpers.get_objects_by_idxs(customers, {2}))

-- by age index with fields
local result, err = g.cluster.main_server.net_box:call('crud.max', {
local result, err = g.router:call('crud.max', {
'customers', 'age_index', {fields = {'name', 'last_name'}, mode = 'write'},
})
t.assert_equals(err, nil)
local objects = crud.unflatten_rows(result.rows, result.metadata)
t.assert_equals(objects, {{name = "Mary", last_name = "Brown"}})

-- by composite index full_name
local result, err = g.cluster.main_server.net_box:call('crud.max', {
local result, err = g.router:call('crud.max', {
'customers', 'full_name', {mode = 'write'},
})
t.assert_equals(err, nil)
local objects = crud.unflatten_rows(result.rows, result.metadata)
t.assert_equals(objects, helpers.get_objects_by_idxs(customers, {4}))

-- by composite index full_name, index ID is specified
local result, err = g.cluster.main_server.net_box:call('crud.max', {
local result, err = g.router:call('crud.max', {
'customers', 5, {mode = 'write'},
})
t.assert_equals(err, nil)
local objects = crud.unflatten_rows(result.rows, result.metadata)
t.assert_equals(objects, helpers.get_objects_by_idxs(customers, {4}))

-- by composite index full_name with fields
local result, err = g.cluster.main_server.net_box:call('crud.max', {
local result, err = g.router:call('crud.max', {
'customers', 'full_name', {fields = {'name', 'last_name'}, mode = 'write'},
})
t.assert_equals(err, nil)
Expand Down Expand Up @@ -334,15 +334,15 @@ pgroup.test_equal_secondary_keys = function(g)
table.sort(customers, function(obj1, obj2) return obj1.id < obj2.id end)

-- min
local result, err = g.cluster.main_server.net_box:call('crud.min', {
local result, err = g.router:call('crud.min', {
'customers', 'age_index', {mode = 'write'},
})
t.assert_equals(err, nil)
local objects = crud.unflatten_rows(result.rows, result.metadata)
t.assert_equals(objects, helpers.get_objects_by_idxs(customers, {1}))

-- max
local result, err = g.cluster.main_server.net_box:call('crud.max', {
local result, err = g.router:call('crud.max', {
'customers', 'age_index', {mode = 'write'},
})
t.assert_equals(err, nil)
Expand All @@ -369,7 +369,7 @@ pgroup.test_opts_not_damaged = function(g)

-- min
local min_opts = {timeout = 1, fields = {'name', 'age'}, mode = 'write'}
local new_min_opts, err = g.cluster.main_server:eval([[
local new_min_opts, err = g.router:eval([[
local crud = require('crud')
local min_opts = ...
Expand All @@ -384,7 +384,7 @@ pgroup.test_opts_not_damaged = function(g)

-- max
local max_opts = {timeout = 1, fields = {'name', 'age'}, mode = 'write'}
local new_max_opts, err = g.cluster.main_server:eval([[
local new_max_opts, err = g.router:eval([[
local crud = require('crud')
local max_opts = ...
Expand Down
Loading

0 comments on commit 0860a83

Please sign in to comment.