Skip to content

Commit 30ec2ce

Browse files
committed
More tests
1 parent fea6d32 commit 30ec2ce

File tree

1 file changed

+87
-41
lines changed

1 file changed

+87
-41
lines changed

test/integration/count_test.lua

Lines changed: 87 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pgroup.after_all(function(g) helpers.stop_cluster(g.cluster) end)
2727

2828
pgroup.before_each(function(g)
2929
helpers.truncate_space_on_cluster(g.cluster, 'customers')
30+
helpers.truncate_space_on_cluster(g.cluster, 'coord')
3031
end)
3132

3233
pgroup.test_count_non_existent_space = function(g)
@@ -48,48 +49,12 @@ pgroup.test_not_valid_value_type = function(g)
4849
{'==', 'id', 'not_number'}
4950
}
5051

51-
local obj, err = g.cluster.main_server.net_box:eval([[
52-
local crud = require('crud')
53-
local conditions = ...
54-
55-
local result, err = crud.count('customers', conditions)
56-
return result, err
57-
]], {conditions})
58-
59-
t.assert_equals(obj, nil)
60-
t.assert_str_contains(err.err, "Supplied key type of part 0 does not match index part type: expected unsigned")
61-
end
62-
63-
pgroup.test_count_all = function(g)
64-
local customers = {}
65-
local expected_len = 100
66-
67-
-- let's insert a large number of tuples in a simple loop that gives
68-
-- really high probability that there is at least one tuple on each storage
69-
for i = 1, expected_len do
70-
table.insert(customers, {
71-
id = i, name = tostring(i), last_name = tostring(i),
72-
age = i, city = tostring(i),
73-
})
74-
end
75-
76-
helpers.insert_objects(g, 'customers', customers)
77-
78-
-- use box.count
79-
local result, err = g.cluster.main_server.net_box:call('crud.count',
80-
{'customers'}
81-
)
82-
83-
t.assert_equals(err, nil)
84-
t.assert_equals(result, expected_len)
85-
86-
-- use approximate algorithm
8752
local result, err = g.cluster.main_server.net_box:call('crud.count',
88-
{'customers', nil, {use_box_count = false}}
53+
{'customers', conditions}
8954
)
9055

91-
t.assert_equals(err, nil)
92-
t.assert_equals(result, expected_len)
56+
t.assert_equals(result, nil)
57+
t.assert_str_contains(err.err, "Supplied key type of part 0 does not match index part type: expected unsigned")
9358
end
9459

9560
pgroup.test_count_all = function(g)
@@ -175,14 +140,12 @@ pgroup.test_select_by_primary_index = function(g)
175140
local conditions = {{'==', 'id_index', 3}}
176141

177142
-- use box.count
178-
--[[
179143
local result, err = g.cluster.main_server.net_box:call('crud.count',
180144
{'customers', conditions}
181145
)
182146

183147
t.assert_equals(err, nil)
184148
t.assert_equals(result, expected_len)
185-
--]]
186149

187150
-- use approximate algorithm
188151
local result, err = g.cluster.main_server.net_box:call('crud.count',
@@ -467,3 +430,86 @@ pgroup.test_lt_condition_with_index = function(g)
467430
t.assert_equals(err, nil)
468431
t.assert_equals(result, expected_len)
469432
end
433+
434+
--[[
435+
pgroup.test_multiple_conditions = function(g)
436+
local bucket_id = 1
437+
local other_bucket_id, err = helpers.get_other_storage_bucket_id(g.cluster, bucket_id)
438+
t.assert(other_bucket_id ~= nil, err)
439+
440+
-- let's insert five tuples on different replicasets
441+
-- (two tuples on one replica and three on the other)
442+
-- to check that the total length will be calculated on the router
443+
helpers.insert_objects(g, 'customers', {
444+
{
445+
id = 1, name = "Elizabeth", last_name = "Jackson",
446+
age = 31, city = "New York",
447+
bucket_id = bucket_id,
448+
}, {
449+
id = 2, name = "Mary", last_name = "Brown",
450+
age = 33, city = "Los Angeles",
451+
bucket_id = other_bucket_id,
452+
}, {
453+
id = 3, name = "Elizabeth", last_name = "Smith",
454+
age = 33, city = "Los Angeles",
455+
bucket_id = bucket_id
456+
}, {
457+
id = 4, name = "William", last_name = "White",
458+
age = 81, city = "Chicago",
459+
bucket_id = bucket_id
460+
}, {
461+
id = 5, name = "Elizabeth", last_name = "May",
462+
age = 28, city = "New York",
463+
bucket_id = other_bucket_id
464+
},
465+
})
466+
467+
local conditions = {
468+
{'>', 'age', 25},
469+
{'==', 'name', 'Elizabeth'},
470+
{'==', 'city', 'New York'},
471+
}
472+
473+
local expected_len = 2
474+
475+
-- use box.count
476+
local result, err = g.cluster.main_server.net_box:call('crud.count',
477+
{'customers', conditions}
478+
)
479+
480+
t.assert_equals(err, nil)
481+
--t.assert_equals(result, expected_len)
482+
483+
-- use approximate algorithm
484+
local result, err = g.cluster.main_server.net_box:call('crud.count',
485+
{'customers', conditions, {use_box_count = false}}
486+
)
487+
488+
t.assert_equals(err, nil)
489+
t.assert_equals(result, expected_len)
490+
end
491+
--]]
492+
493+
pgroup.test_multipart_primary_index = function(g)
494+
local bucket_id = 1
495+
local other_bucket_id, err = helpers.get_other_storage_bucket_id(g.cluster, bucket_id)
496+
t.assert(other_bucket_id ~= nil, err)
497+
498+
helpers.insert_objects(g, 'coord', {
499+
{ x = 0, y = 0, bucket_id = bucket_id }, -- 1
500+
{ x = 0, y = 1, bucket_id = other_bucket_id }, -- 2
501+
{ x = 0, y = 2, bucket_id = bucket_id }, -- 3
502+
{ x = 1, y = 3, bucket_id = other_bucket_id }, -- 4
503+
{ x = 1, y = 4, bucket_id = bucket_id }, -- 5
504+
})
505+
506+
local conditions = {{'=', 'primary', 0}}
507+
local result, err = g.cluster.main_server.net_box:call('crud.count', {'coord', conditions})
508+
t.assert_equals(err, nil)
509+
t.assert_equals(result, 3)
510+
511+
local conditions = {{'=', 'primary', {0, 2}}}
512+
local result, err = g.cluster.main_server.net_box:call('crud.count', {'coord', conditions})
513+
t.assert_equals(err, nil)
514+
t.assert_equals(result, 1)
515+
end

0 commit comments

Comments
 (0)