Debian Codegraph @

mysql-test/suite/x/t/admin_modify_collection_options.test

raw
1 ## Test modify_collection_options command
2
3 ## Preamble
4 --source include/xplugin_preamble.inc
5 --source include/xplugin_create_user.inc
6 ## Tests start here
7
8 create schema xtest;
9
10 --let $xtest_file= $MYSQL_TMP_DIR/admin_modify_collection_options.xpl
11 --write_file $xtest_file
12 -->import validation_schema.macro
13 -->import assert_status_variable.macro
14 -->quiet
15
16 -->macro Create_basic_collection %NAME%
17 stmtadmin create_collection {"schema": "xtest", "name": "%NAME%", "options": {
18 "validation": {
19 "schema": {"description": "base"}
20 }
21 }};
22 -->recvresult
23 -->endmacro
24
25 -->echo
26 -->echo
27 -->echo ## I. Try to modify non existing collection.
28 -->echo
29 -->echo ## II. Check modify_collection_options with invalid validation field.
30 -->echo #
31 -->echo # 1. Empty validation field given.
32 -->echo # 2. No validation field given.
33 -->echo # 3. Validation contains only unknown fields.
34 -->echo # 4. Validation contains valid fields along with unknown fields.
35 -->echo # 5. Options contain invalid field.
36 -->echo
37 -->echo ## III. Check modify_collection_options command with the validation
38 -->echo # level field set.
39 -->echo #
40 -->echo # 1. Test with invalid validation level value.
41 -->echo # 2. Test turning on the validation.
42 -->echo # 3. Test turning off the validation.
43 -->echo # 4. Check case insensitive values for validation level setting.
44 -->echo
45 -->echo ## IV. Check modify_collection_options command with the validation
46 -->echo # schema field set.
47 -->echo #
48 -->echo # 1. Test containing invalid schema field.
49 -->echo # 2. Test with empty schema field.
50 -->echo # 3. Replace default validation schema with one provided by a user.
51 -->echo # 4. Set validation schema encoded as protobuf string.
52 -->echo # 5. Set validation schema encoded as Mysqlx.Datatypes.Object.
53 -->echo # 6. Check special characters handling inside a validation schema.
54 -->echo
55 -->echo ## V. Check modify_collection_options command with both validation
56 -->echo # schema and validation level fields set.
57 -->echo #
58 -->echo # 1. Set validation schema encoded as protobuf string and validation
59 -->echo # level set to off.
60 -->echo # 2. Set validation schema encoded as Mysqlx.Datatypes.Object and
61 -->echo # validation level set to strict.
62 -->echo # 3. Check modify_collection_options with custom schema and invalid
63 -->echo # level field value.
64 -->echo
65 -->echo ## VI. Check modify_collection_options command when modification fails.
66 -->echo #
67 -->echo # 1. Insert some invalid data when validation is disabled, after that
68 -->echo # modification must fail. Fix the offending row and modification
69 -->echo # should pass this time.
70 -->echo # 2. Modification fails on existing data, update offending row so that
71 -->echo # it will be in line with the new schema and try again, this time
72 -->echo # modify_collumn_options must pass.
73 -->echo # 3. Insert invalid data when validation is disabled, modify collection
74 -->echo # using new schema which would treat existing data as valid and
75 -->echo # enabling the validation.
76 -->echo
77 -->echo ## VII. Check Mysqlx_stmt_modify_collection_options variable.
78
79
80 -->echo
81 -->echo #
82 -->echo # I
83 -->stmtsql DROP TABLE IF EXISTS xtest.tab;
84 -->recvresult
85 -->callmacro Modify_schema tab {"type":"object"}
86 -->recverror ER_NO_SUCH_TABLE
87
88
89 -->echo
90 -->echo #
91 -->echo # II.1
92 stmtadmin modify_collection_options {"schema": "xtest", "name": "coll", "options": {
93 "validation": {}
94 }};
95 -->recverror ER_X_CMD_ARGUMENT_OBJECT_EMPTY
96
97
98 -->echo
99 -->echo #
100 -->echo # II.2
101 -->stmtadmin modify_collection_options {"schema": "xtest", "name": "coll", "options": ""}
102 -->recverror ER_X_CMD_ARGUMENT_TYPE
103
104
105 -->echo
106 -->echo #
107 -->echo # II.3
108 stmtadmin modify_collection_options {"schema": "xtest", "name": "coll", "options": {
109 "validation": {
110 "foo": "bar", "baz": ""
111 }
112 }};
113 -->recverror ER_X_CMD_INVALID_ARGUMENT
114
115
116 -->echo
117 -->echo #
118 -->echo # II.4
119 stmtadmin modify_collection_options {"schema": "xtest", "name": "coll", "options": {
120 "validation": {
121 "foo": "bar", "level": "off"
122 }
123 }};
124 -->recverror ER_X_CMD_INVALID_ARGUMENT
125
126 -->echo
127 -->echo #
128 -->echo # II.5
129 stmtadmin modify_collection_options {"schema": "xtest", "name": "coll", "options": {
130 "foo": { "x": "y" } }};
131 -->recverror ER_X_CMD_INVALID_ARGUMENT
132
133
134 -->echo
135 -->echo #
136 -->echo # III.1
137 -->callmacro Modify_level coll foo
138 -->recverror ER_X_CMD_ARGUMENT_VALUE
139
140
141 -->echo
142 -->echo #
143 -->echo # III.2
144 -->callmacro Create_coll_with_validation test_coll {"description": "base"} off
145 -->callmacro Assert_is_enforced test_coll NO
146 -->callmacro Modify_level test_coll strict
147 -->recvresult
148 -->callmacro Assert_is_enforced test_coll YES
149 -->callmacro Drop_collection test_coll
150
151
152 -->echo
153 -->echo #
154 -->echo # III.3
155 -->callmacro Create_coll_with_validation test_coll {"description": "base"} strict
156 -->callmacro Assert_is_enforced test_coll YES
157 -->callmacro Modify_level test_coll off
158 -->recvresult
159 -->callmacro Assert_is_enforced test_coll NO
160 -->callmacro Drop_collection test_coll
161
162
163 -->echo
164 -->echo #
165 -->echo # III.4
166 -->callmacro Create_coll_with_validation test_coll {"description": "base"} STRICT
167 -->callmacro Assert_is_enforced test_coll YES
168 -->callmacro Modify_level test_coll OfF
169 -->recvresult
170 -->callmacro Assert_is_enforced test_coll NO
171 -->callmacro Drop_collection test_coll
172
173
174 -->echo
175 -->echo #
176 -->echo # IV.1
177 -->callmacro Create_basic_collection test_coll
178 -->callmacro Modify_schema test_coll "surpise surprise"
179 -->recverror ER_X_INVALID_VALIDATION_SCHEMA
180 -->callmacro Insert_value_to_collection test_coll '{"_id": "one"}'
181 -->recvresult
182 -->callmacro Modify_schema test_coll {"type":"object"}
183 -->recvresult
184 -->callmacro Insert_value_to_collection test_coll '{"_id": "two"}'
185 -->recvresult
186 -->callmacro Drop_collection test_coll
187
188
189 -->echo
190 -->echo #
191 -->echo # IV.2
192 -->callmacro Create_basic_collection test_coll
193 stmtadmin modify_collection_options {"schema": "xtest", "name": "test_coll", "options": {
194 "validation": {
195 "schema": ""
196 }
197 }};
198 -->recvresult
199 -->callmacro Insert_value_to_collection test_coll '{"_id": "one"}'
200 -->recverror ER_INVALID_JSON_TEXT
201 -->callmacro Drop_collection test_coll
202
203
204 -->echo
205 -->echo #
206 -->echo # IV.3
207 -->stmtadmin create_collection {"schema": "xtest", "name": "test_coll"}
208 -->recvresult
209 -->callmacro Show_validation_schema
210 -->callmacro Modify_schema test_coll {"id": "some id", "description": "modified"}
211 -->recvresult
212 -->callmacro Show_validation_schema
213 -->callmacro Drop_collection test_coll
214
215
216 -->echo
217 -->echo #
218 -->echo # IV.4
219 -->callmacro Create_basic_collection test_coll
220 -->callmacro Show_validation_schema
221 -->callmacro Modify_schema test_coll "{\"description\": \"modified\"}"
222 -->recvresult
223 -->callmacro Show_validation_schema
224 -->callmacro Drop_collection test_coll
225
226
227 -->echo
228 -->echo #
229 -->echo # IV.5
230 -->callmacro Create_basic_collection test_coll
231 -->callmacro Modify_schema test_coll {"description": "modified"}
232 -->recvresult
233 -->callmacro Show_validation_schema
234 -->callmacro Drop_collection test_coll
235
236
237 -->echo
238 -->echo #
239 -->echo # IV.6
240 -->callmacro Create_basic_collection test_coll
241 -->callmacro Modify_schema test_coll {"description": "fo\"o`b@\\"}
242 -->recvresult
243 -->callmacro Show_validation_schema
244 -->callmacro Drop_collection test_coll
245
246
247 -->echo
248 -->echo #
249 -->echo # V.1
250 -->callmacro Create_coll_with_validation test_coll {"description": "base"} strict
251 -->callmacro Assert_is_enforced test_coll YES
252 stmtadmin modify_collection_options {"schema": "xtest", "name": "test_coll",
253 "options": {
254 "validation": {
255 "schema": "{\"description\": \"test\"}", "level": "off"
256 }
257 }
258 };
259 -->recvresult
260 -->callmacro Assert_is_enforced test_coll NO
261 -->callmacro Show_validation_schema
262 -->callmacro Drop_collection test_coll
263
264
265 -->echo
266 -->echo #
267 -->echo # V.2
268 -->callmacro Create_coll_with_validation test_coll {"description": "base"} off
269 -->callmacro Assert_is_enforced test_coll NO
270 stmtadmin modify_collection_options {"schema": "xtest", "name": "test_coll",
271 "options": {
272 "validation": {
273 "schema": {"description": "test"},
274 "level": "strict"
275 }
276 }
277 };
278 -->recvresult
279 -->callmacro Assert_is_enforced test_coll YES
280 -->callmacro Show_validation_schema
281 -->callmacro Drop_collection test_coll
282
283
284 -->echo
285 -->echo #
286 -->echo # V.3
287 stmtadmin modify_collection_options {"schema": "xtest", "name": "test_coll",
288 "options": {
289 "validation": {
290 "schema": {"description": "test"},
291 "level": "bad"
292 }
293 }
294 };
295 -->recverror ER_X_CMD_ARGUMENT_VALUE
296
297
298 -->echo
299 -->echo #
300 -->echo # VI.1
301 varlet %STR% {"type": "object",
302 "properties": {
303 "latitude": {"type": "number", "minimum": -90, "maximum": 90}},
304 "required": ["latitude", "longitude"]};
305 -->callmacro Create_coll_with_validation test_coll %STR% off
306 # Invalid value can be inserted since validation is turned off.
307 callmacro Insert_value_to_collection test_coll
308 '{"_id": "one", "latitude":3312}';
309 -->recvresult
310 # Valid data, insert ok.
311 callmacro Insert_value_to_collection test_coll
312 '{"_id": "two", "latitude":45, "longitude":54}';
313 -->recvresult
314 -->callmacro Assert_not_empty test_coll
315 # Fail because existing data does not fit the validation schema.
316 -->callmacro Modify_level test_coll strict
317 -->recverror ER_X_DOCUMENT_DOESNT_MATCH_EXPECTED_SCHEMA
318 -->callmacro Assert_is_enforced test_coll NO
319 -->stmtsql DELETE FROM xtest.test_coll WHERE `_id` = "one";
320 -->recvresult
321 # No more invalid data, modification passes.
322 -->callmacro Modify_level test_coll strict
323 -->recvresult
324 -->callmacro Assert_is_enforced test_coll YES
325 # Valid data, insert ok.
326 callmacro Insert_value_to_collection
327 test_coll
328 '{"_id": "three", "latitude": 10, "longitude": 11}';
329 -->recvresult
330 # Now insert with invalid data will fail immediately.
331 callmacro Insert_value_to_collection test_coll
332 '{"_id": "four", "latitude": 521}';
333 -->recverror ER_X_DOCUMENT_DOESNT_MATCH_EXPECTED_SCHEMA
334 # Update to valid value, ok.
335 callmacro Update_item test_coll
336 latitude
337 {type: V_SINT v_signed_int: 10}
338 {type: V_SINT v_signed_int: 23};
339 -->recvresult
340 # Update tries to change data against the schema and fails.
341 callmacro Update_item test_coll
342 latitude
343 {type: V_SINT v_signed_int: 23}
344 {type: V_DOUBLE v_double: 1000};
345 -->recverror ER_X_DOCUMENT_DOESNT_MATCH_EXPECTED_SCHEMA
346 -->callmacro Drop_collection test_coll
347
348
349 -->echo
350 -->echo #
351 -->echo # VI.2
352 varlet %STR% {"type": "object",
353 "properties": {
354 "latitude": {"type": "number", "minimum": -90, "maximum": 90}},
355 "required": ["latitude", "longitude"]};
356 -->callmacro Create_coll_with_validation test_coll %STR% strict
357 # Insert according to existing schema
358 callmacro Insert_value_to_collection test_coll
359 '{"_id": "one", "latitude":80, "longitude":70}';
360 -->recvresult
361 callmacro Insert_value_to_collection test_coll
362 '{"_id": "two", "latitude":45, "longitude":54}';
363 -->recvresult
364 -->callmacro Assert_not_empty test_coll
365
366 varlet %STR% "type": "object", "properties": {
367 "latitude": {"type": "number", "maximum": 50}},
368 "required": ["latitude"];
369
370 # Modify collection adding new validation schema which is not valid because of
371 # a data which was inserted already
372 -->callmacro Modify_schema test_coll {%STR%}
373 -->recverror ER_X_DOCUMENT_DOESNT_MATCH_EXPECTED_SCHEMA
374 # Change the offending row so that new validation schema should be ok.
375 callmacro Update_item test_coll
376 latitude
377 {type: V_SINT v_signed_int: 80}
378 {type: V_DOUBLE v_double: 41.1};
379 -->recvresult
380 # Modify shema options for updated data should pass.
381 -->callmacro Modify_schema test_coll {%STR%}
382 -->recvresult
383 -->stmtsql SHOW CREATE TABLE xtest.test_coll
384 -->recvresult
385 # Insert valid data according to the new validation schema.
386 callmacro Insert_value_to_collection test_coll
387 '{"_id": "three", "latitude":30}';
388 -->recvresult
389 # Insert invalid data according to the new validation schema.
390 callmacro Insert_value_to_collection test_coll
391 '{"_id": "four", "latitude":60}';
392 -->recverror ER_X_DOCUMENT_DOESNT_MATCH_EXPECTED_SCHEMA
393 # Update to a valid value according to the new validation schema.
394 callmacro Update_item test_coll
395 latitude
396 {type: V_SINT v_signed_int: 30}
397 {type: V_SINT v_signed_int: 31};
398 -->recvresult
399 # Update to an invalid value according to the new validation schema.
400 callmacro Update_item test_coll
401 latitude
402 {type: V_SINT v_signed_int: 31}
403 {type: V_SINT v_signed_int: 131};
404 -->recverror ER_X_DOCUMENT_DOESNT_MATCH_EXPECTED_SCHEMA
405 -->callmacro Drop_collection test_coll
406
407
408 -->echo
409 -->echo #
410 -->echo # VI.3
411 varlet %STR% {"type": "object",
412 "properties": {
413 "latitude": {"type": "number", "minimum": -90, "maximum": 90}},
414 "required": ["latitude", "longitude"]};
415 -->callmacro Create_coll_with_validation test_coll %STR% off
416 -->callmacro Assert_is_enforced test_coll NO
417 # Invalid value can be inserted since validation is turned off.
418 callmacro Insert_value_to_collection test_coll
419 '{"_id": "one", "latitude":100}';
420 -->recvresult
421 # Valid data, insert ok.
422 callmacro Insert_value_to_collection test_coll
423 '{"_id": "two", "latitude":45, "longitude":54}';
424 -->recvresult
425 -->callmacro Assert_not_empty test_coll
426 # New validation is allowed as it does not conflict with the existing data.
427 varlet %STR% "type": "object", "properties": {
428 "latitude": {"type": "number", "maximum": 150}},
429 "required": ["latitude"];
430 stmtadmin modify_collection_options {"schema": "xtest", "name": "test_coll",
431 "options": {
432 "validation": {
433 "schema": {%STR%},
434 "level": "strict"
435 }
436 }
437 };
438 -->recvresult
439 -->callmacro Assert_is_enforced test_coll YES
440 # Valid based on the new schema.
441 callmacro Insert_value_to_collection test_coll
442 '{"_id": "three", "latitude":122}';
443 -->recvresult
444 # Invalid based on the new schema.
445 callmacro Insert_value_to_collection test_coll
446 '{"_id": "four", "latitude":154}';
447 -->recverror ER_X_DOCUMENT_DOESNT_MATCH_EXPECTED_SCHEMA
448 -->callmacro Drop_collection test_coll
449
450
451 -->echo
452 -->echo #
453 -->echo # VII
454 -->newsession temp
455 -->quiet
456 -->stmtadmin create_collection {"schema": "xtest", "name": "test_coll"}
457 -->recvresult
458 # Initial value.
459 -->callmacro Assert_status_variable Mysqlx_stmt_modify_collection_options 0
460 stmtadmin modify_collection_options
461 {"schema": "xtest", "name": "test_coll", "options": { "validation": { "level": "off"}}};
462 -->recvresult
463 # After successful modify_collection_options operation.
464 -->callmacro Assert_status_variable Mysqlx_stmt_modify_collection_options 1
465 stmtadmin modify_collection_options
466 {"schema": "xtest", "name": "test_coll", "options": { "validation": { "level": "foo"}}};
467 -->recverror ER_X_CMD_ARGUMENT_VALUE
468 # After unsuccessful modify_collection_options operation.
469 -->callmacro Assert_status_variable Mysqlx_stmt_modify_collection_options 2
470 stmtadmin modify_collection_options
471 {"schema": "xtest", "name": "test_coll", "options": { "validation": { "level": "off"}}};
472 -->recvresult
473 # After next successful modify_collection_options operation.
474 -->callmacro Assert_status_variable Mysqlx_stmt_modify_collection_options 3
475 -->callmacro Drop_collection test_coll
476 -->closesession
477
478 EOF
479
480 --exec $MYSQLXTEST -ux_root --password='' --file=$xtest_file 2>&1
481
482 ## Cleanup
483 --source ../include/xplugin_cleanup.inc