@@ -7,10 +7,10 @@ package.path = fio.abspath(debug.getinfo(1).source:match("@?(.*/)")
7
7
:gsub (' /./' , ' /' ):gsub (' /+$' , ' ' )) .. ' /../../?.lua' .. ' ;' ..
8
8
package.path
9
9
10
- local json = require (' json' )
11
10
local yaml = require (' yaml' )
12
11
local graphql = require (' graphql' )
13
12
local utils = require (' graphql.utils' )
13
+ local testdata = require (' test.local.space_compound_index_testdata' )
14
14
15
15
-- utils
16
16
-- -----
@@ -20,164 +20,21 @@ local function strip_error(err)
20
20
return tostring (err ):gsub (' ^.-:.-: (.*)$' , ' %1' )
21
21
end
22
22
23
- -- schemas and meta-information
24
- -- ----------------------------
25
-
26
- local schemas = json .decode ([[ {
27
- "user": {
28
- "type": "record",
29
- "name": "user",
30
- "fields": [
31
- { "name": "user_str", "type": "string" },
32
- { "name": "user_num", "type": "long" },
33
- { "name": "first_name", "type": "string" },
34
- { "name": "last_name", "type": "string" }
35
- ]
36
- },
37
- "order": {
38
- "type": "record",
39
- "name": "order",
40
- "fields": [
41
- { "name": "order_str", "type": "string" },
42
- { "name": "order_num", "type": "long" },
43
- { "name": "user_str", "type": "string" },
44
- { "name": "user_num", "type": "long" },
45
- { "name": "description", "type": "string" }
46
- ]
47
- }
48
- }]] )
49
-
50
- local collections = json .decode ([[ {
51
- "user_collection": {
52
- "schema_name": "user",
53
- "connections": [
54
- {
55
- "type": "1:N",
56
- "name": "order_connection",
57
- "destination_collection": "order_collection",
58
- "parts": [
59
- { "source_field": "user_str", "destination_field": "user_str" },
60
- { "source_field": "user_num", "destination_field": "user_num" }
61
- ],
62
- "index_name": "user_str_num_index"
63
- },
64
- {
65
- "type": "1:N",
66
- "name": "order_str_connection",
67
- "destination_collection": "order_collection",
68
- "parts": [
69
- { "source_field": "user_str", "destination_field": "user_str" }
70
- ],
71
- "index_name": "user_str_num_index"
72
- }
73
- ]
74
- },
75
- "order_collection": {
76
- "schema_name": "order",
77
- "connections": [
78
- {
79
- "type": "1:1",
80
- "name": "user_connection",
81
- "destination_collection": "user_collection",
82
- "parts": [
83
- { "source_field": "user_str", "destination_field": "user_str" },
84
- { "source_field": "user_num", "destination_field": "user_num" }
85
- ],
86
- "index_name": "user_str_num_index"
87
- }
88
- ]
89
- }
90
- }]] )
91
-
92
- local service_fields = {
93
- user = {},
94
- order = {},
95
- }
96
-
97
- local indexes = {
98
- user_collection = {
99
- user_str_num_index = {
100
- service_fields = {},
101
- fields = {' user_str' , ' user_num' },
102
- index_type = ' tree' ,
103
- unique = true ,
104
- primary = true ,
105
- },
106
- },
107
- order_collection = {
108
- order_str_num_index = {
109
- service_fields = {},
110
- fields = {' order_str' , ' order_num' },
111
- index_type = ' tree' ,
112
- unique = true ,
113
- primary = true ,
114
- },
115
- user_str_num_index = {
116
- service_fields = {},
117
- fields = {' user_str' , ' user_num' },
118
- index_type = ' tree' ,
119
- unique = false ,
120
- primary = false ,
121
- },
122
- },
123
- }
124
-
125
- -- fill spaces
126
- -- -----------
127
-
128
- -- user_collection fields
129
- local U_USER_STR_FN = 1
130
- local U_USER_NUM_FN = 2
131
-
132
- -- order_collection fields
133
- local O_ORDER_STR_FN = 1
134
- local O_ORDER_NUM_FN = 2
135
- local O_USER_STR_FN = 3
136
- local O_USER_NUM_FN = 4
137
-
138
- box .cfg {background = false }
139
- box .once (' test_space_init_spaces' , function ()
140
- -- users
141
- box .schema .create_space (' user_collection' )
142
- box .space .user_collection :create_index (' user_str_num_index' ,
143
- {type = ' tree' , unique = true , parts = {
144
- U_USER_STR_FN , ' string' , U_USER_NUM_FN , ' unsigned' ,
145
- }}
146
- )
147
-
148
- -- orders
149
- box .schema .create_space (' order_collection' )
150
- box .space .order_collection :create_index (' order_str_num_index' ,
151
- {type = ' tree' , unique = true , parts = {
152
- O_ORDER_STR_FN , ' string' , O_ORDER_NUM_FN , ' unsigned' ,
153
- }}
154
- )
155
- box .space .order_collection :create_index (' user_str_num_index' ,
156
- {type = ' tree' , unique = false , parts = {
157
- O_USER_STR_FN , ' string' , O_USER_NUM_FN , ' unsigned' ,
158
- }}
159
- )
160
- end )
23
+ -- init box, upload test data and acquire metadata
24
+ -- -----------------------------------------------
161
25
162
- for i = 1 , 20 do
163
- for j = 1 , 5 do
164
- local s =
165
- j % 5 == 1 and ' a' or
166
- j % 5 == 2 and ' b' or
167
- j % 5 == 3 and ' c' or
168
- j % 5 == 4 and ' d' or
169
- j % 5 == 0 and ' e' or
170
- nil
171
- assert (s ~= nil , ' s must not be nil' )
172
- box .space .user_collection :replace (
173
- {' user_str_' .. s , i , ' first name ' .. s , ' last name ' .. s })
174
- for k = 1 , 10 do
175
- box .space .order_collection :replace (
176
- {' order_str_' .. s .. ' _' .. tostring (k ), i * 100 + k ,
177
- ' user_str_' .. s , i , ' description ' .. s })
178
- end
179
- end
180
- end
26
+ -- init box and data schema
27
+ testdata .init_spaces ()
28
+
29
+ -- upload test data
30
+ testdata .fill_test_data ()
31
+
32
+ -- acquire metadata
33
+ local metadata = testdata .get_test_metadata ()
34
+ local schemas = metadata .schemas
35
+ local collections = metadata .collections
36
+ local service_fields = metadata .service_fields
37
+ local indexes = metadata .indexes
181
38
182
39
-- build accessor and graphql schemas
183
40
-- ----------------------------------
@@ -381,8 +238,6 @@ print(('RESULT: ok: %s; err: %s'):format(tostring(ok), strip_error(err)))
381
238
-- clean up
382
239
-- --------
383
240
384
- box .space ._schema :delete (' oncetest_space_init_spaces' )
385
- box .space .user_collection :drop ()
386
- box .space .order_collection :drop ()
241
+ testdata .drop ()
387
242
388
243
os.exit ()
0 commit comments