@@ -27,6 +27,7 @@ pgroup.after_all(function(g) helpers.stop_cluster(g.cluster) end)
27
27
28
28
pgroup .before_each (function (g )
29
29
helpers .truncate_space_on_cluster (g .cluster , ' customers' )
30
+ helpers .truncate_space_on_cluster (g .cluster , ' coord' )
30
31
end )
31
32
32
33
pgroup .test_count_non_existent_space = function (g )
@@ -48,48 +49,12 @@ pgroup.test_not_valid_value_type = function(g)
48
49
{' ==' , ' id' , ' not_number' }
49
50
}
50
51
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
87
52
local result , err = g .cluster .main_server .net_box :call (' crud.count' ,
88
- {' customers' , nil , { use_box_count = false } }
53
+ {' customers' , conditions }
89
54
)
90
55
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 " )
93
58
end
94
59
95
60
pgroup .test_count_all = function (g )
@@ -175,14 +140,12 @@ pgroup.test_select_by_primary_index = function(g)
175
140
local conditions = {{' ==' , ' id_index' , 3 }}
176
141
177
142
-- use box.count
178
- --[[
179
143
local result , err = g .cluster .main_server .net_box :call (' crud.count' ,
180
144
{' customers' , conditions }
181
145
)
182
146
183
147
t .assert_equals (err , nil )
184
148
t .assert_equals (result , expected_len )
185
- --]]
186
149
187
150
-- use approximate algorithm
188
151
local result , err = g .cluster .main_server .net_box :call (' crud.count' ,
@@ -467,3 +430,86 @@ pgroup.test_lt_condition_with_index = function(g)
467
430
t .assert_equals (err , nil )
468
431
t .assert_equals (result , expected_len )
469
432
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