Skip to content

Commit

Permalink
Use in-built stats instead on helper in tests
Browse files Browse the repository at this point in the history
Use in-built `crud.stats()` info instead on `storage_stat` helper
in tests to track map reduce calls.

Part of #224
  • Loading branch information
DifferentialOrange committed Dec 6, 2021
1 parent d948af8 commit 0971c76
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 191 deletions.
6 changes: 6 additions & 0 deletions test/helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,10 @@ function helpers.update_cache(cluster, space_name)
]], {space_name})
end

function helpers.get_map_reduces_stat(router_net_box)
return router_net_box:eval([[
return require('crud').stats().select.details.map_reduces
]])
end

return helpers
110 changes: 0 additions & 110 deletions test/helpers/storage_stat.lua

This file was deleted.

38 changes: 12 additions & 26 deletions test/integration/ddl_sharding_key_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ local crud = require('crud')
local t = require('luatest')

local helpers = require('test.helper')
local storage_stat = require('test.helpers.storage_stat')

local ok = pcall(require, 'ddl')
if not ok then
Expand Down Expand Up @@ -34,13 +33,6 @@ pgroup.before_all(function(g)
]])
t.assert_equals(type(result), 'table')
t.assert_equals(err, nil)

helpers.call_on_storages(g.cluster, function(server)
server.net_box:eval([[
local storage_stat = require('test.helpers.storage_stat')
storage_stat.init_on_storage()
]])
end)
end)

pgroup.after_all(function(g) helpers.stop_cluster(g.cluster) end)
Expand Down Expand Up @@ -349,45 +341,39 @@ for name, case in pairs(cases) do
pgroup[('test_%s_wont_lead_to_map_reduce'):format(name)] = function(g)
case.prepare_data(g, case.space_name)

local stat_a = storage_stat.collect(g.cluster)
local router = g.cluster:server('router').net_box
local map_reduces_before = helpers.get_map_reduces_stat(router)

local result, err = g.cluster.main_server.net_box:call('crud.select', {
local result, err = router:call('crud.select', {
case.space_name, case.conditions
})
t.assert_equals(err, nil)
t.assert_not_equals(result, nil)
t.assert_equals(#result.rows, 1)

local stat_b = storage_stat.collect(g.cluster)

-- Check a number of select() requests made by CRUD on cluster's storages
-- after calling select() on a router. Make sure only a single storage has
-- a single select() request. Otherwise we lead to map-reduce.
local stats = storage_stat.diff(stat_b, stat_a)
t.assert_equals(storage_stat.total(stats), 1, 'Select request was not a map reduce')
local map_reduces_after = helpers.get_map_reduces_stat(router)
local diff = map_reduces_after - map_reduces_before
t.assert_equals(diff, 0, 'Select request was not a map reduce')
end
end

pgroup.test_select_for_part_of_sharding_key_will_lead_to_map_reduce = function(g)
local space_name = 'customers_name_age_key_different_indexes'
prepare_data_name_age_sharding_key(g, space_name)

local stat_a = storage_stat.collect(g.cluster)
local router = g.cluster:server('router').net_box
local map_reduces_before = helpers.get_map_reduces_stat(router)

local result, err = g.cluster.main_server.net_box:call('crud.select', {
local result, err = router:call('crud.select', {
space_name, {{'==', 'age', 58}},
})
t.assert_equals(err, nil)
t.assert_not_equals(result, nil)
t.assert_equals(#result.rows, 1)

local stat_b = storage_stat.collect(g.cluster)

-- Check a number of select() requests made by CRUD on cluster's storages
-- after calling select() on a router. Make sure it was a map-reduce
-- since we do not have sharding key values in conditions.
local stats = storage_stat.diff(stat_b, stat_a)
t.assert_equals(storage_stat.total(stats), 2, 'Select request was a map reduce')
local map_reduces_after = helpers.get_map_reduces_stat(router)
local diff = map_reduces_after - map_reduces_before
t.assert_equals(diff, 1, 'Select request was a map reduce')
end

pgroup.test_select_secondary_idx = function(g)
Expand Down
37 changes: 9 additions & 28 deletions test/integration/pairs_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ local t = require('luatest')
local crud_utils = require('crud.common.utils')

local helpers = require('test.helper')
local storage_stat = require('test.helpers.storage_stat')

local pgroup = t.group('pairs', {
{engine = 'memtx'},
Expand All @@ -26,13 +25,6 @@ pgroup.before_all(function(g)
g.cluster:start()

g.space_format = g.cluster.servers[2].net_box.space.customers:format()

helpers.call_on_storages(g.cluster, function(server)
server.net_box:eval([[
local storage_stat = require('test.helpers.storage_stat')
storage_stat.init_on_storage()
]])
end)
end)

pgroup.after_all(function(g) helpers.stop_cluster(g.cluster) end)
Expand Down Expand Up @@ -842,10 +834,11 @@ pgroup.test_pairs_no_map_reduce = function(g)

table.sort(customers, function(obj1, obj2) return obj1.id < obj2.id end)

local stat_a = storage_stat.collect(g.cluster)
local router = g.cluster:server('router').net_box
local map_reduces_before = helpers.get_map_reduces_stat(router)

-- Case: no conditions, just bucket id.
local rows = g.cluster.main_server.net_box:eval([[
local rows = router:eval([[
local crud = require('crud')
return crud.pairs(...):totable()
Expand All @@ -858,15 +851,9 @@ pgroup.test_pairs_no_map_reduce = function(g)
{3, 2804, 'David', 'Smith', 33, 'Los Angeles'},
})

local stat_b = storage_stat.collect(g.cluster)
t.assert_equals(storage_stat.diff(stat_b, stat_a), {
['s-1'] = {
select_requests = 1,
},
['s-2'] = {
select_requests = 0,
},
})
local map_reduces_after_1 = helpers.get_map_reduces_stat(router)
local diff_1 = map_reduces_after_1 - map_reduces_before
t.assert_equals(diff_1, 0, 'Select request was not a map reduce')

-- Case: EQ on secondary index, which is not in the sharding
-- index (primary index in the case).
Expand All @@ -883,13 +870,7 @@ pgroup.test_pairs_no_map_reduce = function(g)
{4, 1161, 'William', 'White', 81, 'Chicago'},
})

local stat_c = storage_stat.collect(g.cluster)
t.assert_equals(storage_stat.diff(stat_c, stat_b), {
['s-1'] = {
select_requests = 0,
},
['s-2'] = {
select_requests = 1,
},
})
local map_reduces_after_2 = helpers.get_map_reduces_stat(router)
local diff_2 = map_reduces_after_2 - map_reduces_after_1
t.assert_equals(diff_2, 0, 'Select request was not a map reduce')
end
35 changes: 8 additions & 27 deletions test/integration/select_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ local crud = require('crud')
local crud_utils = require('crud.common.utils')

local helpers = require('test.helper')
local storage_stat = require('test.helpers.storage_stat')

local pgroup = t.group('select', {
{engine = 'memtx'},
Expand All @@ -27,13 +26,6 @@ pgroup.before_all(function(g)
g.cluster:start()

g.space_format = g.cluster.servers[2].net_box.space.customers:format()

helpers.call_on_storages(g.cluster, function(server)
server.net_box:eval([[
local storage_stat = require('test.helpers.storage_stat')
storage_stat.init_on_storage()
]])
end)
end)

pgroup.after_all(function(g) helpers.stop_cluster(g.cluster) end)
Expand Down Expand Up @@ -1615,7 +1607,8 @@ pgroup.test_select_no_map_reduce = function(g)

table.sort(customers, function(obj1, obj2) return obj1.id < obj2.id end)

local stat_a = storage_stat.collect(g.cluster)
local router = g.cluster:server('router').net_box
local map_reduces_before = helpers.get_map_reduces_stat(router)

-- Case: no conditions, just bucket id.
local result, err = g.cluster.main_server.net_box:call('crud.select', {
Expand All @@ -1628,15 +1621,9 @@ pgroup.test_select_no_map_reduce = function(g)
{3, 2804, 'David', 'Smith', 33, 'Los Angeles'},
})

local stat_b = storage_stat.collect(g.cluster)
t.assert_equals(storage_stat.diff(stat_b, stat_a), {
['s-1'] = {
select_requests = 1,
},
['s-2'] = {
select_requests = 0,
},
})
local map_reduces_after_1 = helpers.get_map_reduces_stat(router)
local diff_1 = map_reduces_after_1 - map_reduces_before
t.assert_equals(diff_1, 0, 'Select request was not a map reduce')

-- Case: EQ on secondary index, which is not in the sharding
-- index (primary index in the case).
Expand All @@ -1650,13 +1637,7 @@ pgroup.test_select_no_map_reduce = function(g)
{4, 1161, 'William', 'White', 81, 'Chicago'},
})

local stat_c = storage_stat.collect(g.cluster)
t.assert_equals(storage_stat.diff(stat_c, stat_b), {
['s-1'] = {
select_requests = 0,
},
['s-2'] = {
select_requests = 1,
},
})
local map_reduces_after_2 = helpers.get_map_reduces_stat(router)
local diff_2 = map_reduces_after_2 - map_reduces_after_1
t.assert_equals(diff_2, 0, 'Select request was not a map reduce')
end

0 comments on commit 0971c76

Please sign in to comment.