File: select.test.lua

package info (click to toggle)
tarantool 2.6.0-1.4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 85,412 kB
  • sloc: ansic: 513,775; cpp: 69,493; sh: 25,650; python: 19,190; perl: 14,973; makefile: 4,178; yacc: 1,329; sql: 1,074; pascal: 620; ruby: 190; awk: 18; lisp: 7
file content (150 lines) | stat: -rw-r--r-- 5,263 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
msgpack = require('msgpack')
env = require('test_run')
test_run = env.new()

s = box.schema.space.create('select', { temporary = true })
index1 = s:create_index('primary', { type = 'tree' })
index2 = s:create_index('second', { type = 'tree', unique = true,  parts = {2, 'unsigned', 1, 'unsigned'}})
for i = 1, 20 do s:insert({ i, 1, 2, 3 }) end

test_run:cmd("setopt delimiter ';'")
local function test_op(op, idx, ...)
    local t1 = idx[op .. '_ffi'](idx, ...)
    local t2 = idx[op .. '_luac'](idx, ...)
    if msgpack.encode(t1) ~= msgpack.encode(t2) then
        return 'different result from '..op..'_ffi and '..op..'_luac', t1, t2
    end
    return t1
end
test = setmetatable({}, {
    __index = function(_, op) return function(...) return test_op(op, ...) end end
});
test_run:cmd("setopt delimiter ''");


--------------------------------------------------------------------------------
-- get tests
--------------------------------------------------------------------------------

s.index[0].get == s.index[0].get_ffi or s.index[0].get == s.index[0].get_luac

test.get(s.index[0])
test.get(s.index[0], {})
test.get(s.index[0], nil)
test.get(s.index[0], 1)
test.get(s.index[0], {1})
test.get(s.index[0], {1, 2})
test.get(s.index[0], 0)
test.get(s.index[0], {0})
test.get(s.index[0], "0")
test.get(s.index[0], {"0"})

test.get(s.index[1], 1)
test.get(s.index[1], {1})
test.get(s.index[1], {1, 2})

--------------------------------------------------------------------------------
-- select tests
--------------------------------------------------------------------------------

s.index[0].select == s.index[0].select_ffi or s.index[0].select == s.index[0].select_luac

test.select(s.index[0])
test.select(s.index[0], {})
test.select(s.index[0], nil)
test.select(s.index[0], {}, {iterator = 'ALL'})

test.select(s.index[0], nil, {iterator = box.index.ALL })
test.select(s.index[0], {}, {iterator = box.index.ALL, limit = 10})
test.select(s.index[0], nil, {iterator = box.index.ALL, limit = 0})
test.select(s.index[0], {}, {iterator = 'ALL', limit = 1, offset = 15})
test.select(s.index[0], nil, {iterator = 'ALL', limit = 20, offset = 15})

test.select(s.index[0], nil, {iterator = box.index.EQ})
test.select(s.index[0], {}, {iterator = 'EQ'})
test.select(s.index[0], nil, {iterator = 'REQ'})
test.select(s.index[0], {}, {iterator = box.index.REQ})

test.select(s.index[0], nil, {iterator = 'EQ', limit = 2, offset = 1})
test.select(s.index[0], {}, {iterator = box.index.REQ, limit = 2, offset = 1})

test.select(s.index[0], 1)
test.select(s.index[0], {1})
test.select(s.index[0], {1, 2})
test.select(s.index[0], 0)
test.select(s.index[0], {0})
test.select(s.index[0], "0")
test.select(s.index[0], {"0"})

test.select(s.index[1], 1)
test.select(s.index[1], {1})
test.select(s.index[1], {1}, {limit = 2})
test.select(s.index[1], 1, {iterator = 'EQ'})
test.select(s.index[1], {1}, {iterator = box.index.EQ, offset = 16, limit = 2})
test.select(s.index[1], {1}, {iterator = box.index.REQ, offset = 16, limit = 2 })
test.select(s.index[1], {1, 2}, {iterator = 'EQ'})
test.select(s.index[1], {1, 2}, {iterator = box.index.REQ})
test.select(s.index[1], {1, 2})

test.select(s.index[0], nil, { iterator = 'ALL', offset = 0, limit = 4294967295 })
test.select(s.index[0], {}, { iterator = 'ALL', offset = 0, limit = 4294967295 })

test.select(s.index[0], 1)
test.select(s.index[0], 1, { iterator = box.index.EQ })
test.select(s.index[0], 1, { iterator = 'EQ' })
test.select(s.index[0], 1, { iterator = 'GE' })
test.select(s.index[0], 1, { iterator = 'GE', limit = 2 })
test.select(s.index[0], 1, { iterator = 'LE', limit = 2 })
test.select(s.index[0], 1, { iterator = 'GE', offset = 10, limit = 2 })

s:select(2)

--------------------------------------------------------------------------------
-- min/max tests
--------------------------------------------------------------------------------

test.min(s.index[1])
test.max(s.index[1])

--------------------------------------------------------------------------------
-- count tests
--------------------------------------------------------------------------------

test.count(s.index[1])
test.count(s.index[0], nil)
test.count(s.index[0], {})
test.count(s.index[0], 10, { iterator = 'GT'})

--------------------------------------------------------------------------------
-- random tests
--------------------------------------------------------------------------------

test.random(s.index[0], 48)

s:drop()

collectgarbage('collect')

-- gh-3224 resurrect tuple bigrefs

collectgarbage('stop')
s = box.schema.space.create('select', { temporary = true })
index = s:create_index('primary', { type = 'tree' })
_ = s:insert{0}
_ = s:insert{1}
_ = s:insert{2}
_ = s:insert{3}
lots_of_links = setmetatable({}, {__mode = 'v'})
i = 0
while (i < 33000) do table.insert(lots_of_links, s:get{0}) i = i + 1 end
while (i < 66000) do table.insert(lots_of_links, s:get{1}) i = i + 1 end
while (i < 100000) do table.insert(lots_of_links, s:get{2}) i = i + 1 end
ref_count = 0
for k, v in pairs(lots_of_links) do ref_count = ref_count + 1 end
ref_count
-- check that tuples are deleted after gc is activated
collectgarbage('collect')
-- GC should be restarted after it was stopped.
collectgarbage('restart')
lots_of_links
s:drop()