| 1 |
########### ../t/crud_rpl.test ######### |
| 2 |
## # |
| 3 |
## This test aims to run crud message on replication setup. # |
| 4 |
## Test runs following message on master and checks data on slave # |
| 5 |
## - create_collection message # |
| 6 |
## - Insert message # |
| 7 |
## - create_collection_index # |
| 8 |
## - update message # |
| 9 |
## - delete message # |
| 10 |
####################################################################### |
| 11 |
|
| 12 |
|
| 13 |
--source include/master-slave.inc |
| 14 |
--source include/count_sessions.inc |
| 15 |
--source include/xplugin_create_user.inc |
| 16 |
|
| 17 |
|
| 18 |
# Use master connection |
| 19 |
--connection master |
| 20 |
|
| 21 |
--source include/xplugin_preamble.inc |
| 22 |
--source ../include/have_performance_schema_events_waits_history.inc |
| 23 |
call mtr.add_suppression("Error parsing message of type 12: args"); |
| 24 |
call mtr.add_suppression("Error handling message: args"); |
| 25 |
|
| 26 |
## Test starts here |
| 27 |
--write_file $MYSQL_TMP_DIR/mysqlx-in.tmp |
| 28 |
-->sql |
| 29 |
#-- "Creating database for testcase" |
| 30 |
DROP DATABASE IF EXISTS xplugintest; |
| 31 |
CREATE DATABASE xplugintest; |
| 32 |
USE xplugintest; |
| 33 |
CREATE TABLE table1 ( _id INT PRIMARY KEY, doc JSON ) ; |
| 34 |
-->endsql |
| 35 |
|
| 36 |
#-- "Create table table2 in xplugintest " |
| 37 |
|
| 38 |
-->stmtadmin create_collection {"schema":"xplugintest","name":"table2"} |
| 39 |
-->recvresult |
| 40 |
|
| 41 |
-->echo Insert multiple rows into a Document column |
| 42 |
Mysqlx.Crud.Insert { |
| 43 |
collection { |
| 44 |
name: "table2" |
| 45 |
schema: "xplugintest" |
| 46 |
} |
| 47 |
data_model: DOCUMENT |
| 48 |
row { |
| 49 |
field { |
| 50 |
type: LITERAL |
| 51 |
literal { |
| 52 |
type: V_STRING |
| 53 |
v_string { |
| 54 |
value: "\n{\n \"_id\": \"1\",\n \"name\": \"Omar Bras\", \"id\": \"1\"\n}" |
| 55 |
} |
| 56 |
} |
| 57 |
} |
| 58 |
} |
| 59 |
row { |
| 60 |
field { |
| 61 |
type: LITERAL |
| 62 |
literal { |
| 63 |
type: V_STRING |
| 64 |
v_string { |
| 65 |
value: "\n{\n \"_id\": \"2\",\n \"name\": \"Omar Mex\", \"id\": \"2\"\n}" |
| 66 |
} |
| 67 |
} |
| 68 |
} |
| 69 |
} |
| 70 |
} |
| 71 |
-->recvresult |
| 72 |
-->sql |
| 73 |
SELECT * FROM xplugintest.table2; |
| 74 |
-->endsql |
| 75 |
|
| 76 |
|
| 77 |
#-- "Index with unique(true), index column NOT NULL (true)" |
| 78 |
-->stmtadmin create_collection_index {"schema":"xplugintest", "collection":"table2", "name":"name_index", "unique":true, "fields":{"field":"$.name", "type":"TEXT(50)","required":true}} |
| 79 |
-->recvresult |
| 80 |
-->sql |
| 81 |
SHOW CREATE TABLE xplugintest.table2; |
| 82 |
SELECT * FROM xplugintest.table2; |
| 83 |
-->endsql |
| 84 |
|
| 85 |
|
| 86 |
-->echo Update decimal value with a corner value plus 1 |
| 87 |
Mysqlx.Crud.Update { |
| 88 |
collection { |
| 89 |
name: "table2" |
| 90 |
schema: "xplugintest" |
| 91 |
} |
| 92 |
data_model: DOCUMENT |
| 93 |
criteria { |
| 94 |
type: OPERATOR |
| 95 |
operator { |
| 96 |
name: "==" |
| 97 |
param { |
| 98 |
type: IDENT identifier { name: "_id" } |
| 99 |
} |
| 100 |
param { |
| 101 |
type: LITERAL |
| 102 |
literal { |
| 103 |
type: V_SINT |
| 104 |
v_signed_int: 2 |
| 105 |
} |
| 106 |
} |
| 107 |
} |
| 108 |
} |
| 109 |
operation { |
| 110 |
source { |
| 111 |
document_path { |
| 112 |
type: MEMBER |
| 113 |
value: "name" |
| 114 |
} |
| 115 |
} |
| 116 |
operation: ITEM_SET |
| 117 |
value { |
| 118 |
type: LITERAL |
| 119 |
literal { |
| 120 |
type: V_STRING |
| 121 |
v_string { |
| 122 |
value: "\"Omar Argentina\"" |
| 123 |
} |
| 124 |
} |
| 125 |
} |
| 126 |
} |
| 127 |
} |
| 128 |
-->recvresult |
| 129 |
|
| 130 |
|
| 131 |
-->sql |
| 132 |
SHOW CREATE TABLE xplugintest.table2; |
| 133 |
SELECT JSON_EXTRACT(doc,'$.name') FROM xplugintest.table2; |
| 134 |
SELECT * FROM xplugintest.table2; |
| 135 |
-->endsql |
| 136 |
|
| 137 |
-->echo Delete with == operator |
| 138 |
Mysqlx.Crud.Delete { |
| 139 |
collection { |
| 140 |
name: "table2" |
| 141 |
schema: "xplugintest" |
| 142 |
} |
| 143 |
data_model: DOCUMENT |
| 144 |
criteria { |
| 145 |
type: OPERATOR |
| 146 |
operator { |
| 147 |
name: "==" |
| 148 |
param { |
| 149 |
type: IDENT identifier { name: "_id" } |
| 150 |
} |
| 151 |
param { |
| 152 |
type: LITERAL |
| 153 |
literal { |
| 154 |
type: V_SINT |
| 155 |
v_signed_int: 2 |
| 156 |
} |
| 157 |
} |
| 158 |
} |
| 159 |
} |
| 160 |
} |
| 161 |
-->recvresult |
| 162 |
|
| 163 |
-->sql |
| 164 |
SELECT JSON_EXTRACT(doc,'$.name') FROM xplugintest.table2; |
| 165 |
SELECT * FROM xplugintest.table2; |
| 166 |
-->endsql |
| 167 |
|
| 168 |
|
| 169 |
Mysqlx.Crud.Insert { |
| 170 |
collection { |
| 171 |
name: "table2" |
| 172 |
schema: "xplugintest" |
| 173 |
} |
| 174 |
data_model: DOCUMENT |
| 175 |
row { |
| 176 |
field { |
| 177 |
type: LITERAL |
| 178 |
literal { |
| 179 |
type: V_STRING |
| 180 |
v_string { |
| 181 |
value: "\n{\n \"_id\": \"3\",\n \"name\": \"Omar Peru\", \"id\": \"3\"\n}" |
| 182 |
} |
| 183 |
} |
| 184 |
} |
| 185 |
} |
| 186 |
} |
| 187 |
-->recvresult |
| 188 |
|
| 189 |
# Insert fail due to non unique _id doc member |
| 190 |
Mysqlx.Crud.Insert { |
| 191 |
collection { |
| 192 |
name: "table2" |
| 193 |
schema: "xplugintest" |
| 194 |
} |
| 195 |
data_model: DOCUMENT |
| 196 |
row { |
| 197 |
field { |
| 198 |
type: LITERAL |
| 199 |
literal { |
| 200 |
type: V_STRING |
| 201 |
v_string { |
| 202 |
value: "\n{\n \"_id\": \"1\",\n \"name\": \"Omar Colombia\", \"id\": \"3\"\n}" |
| 203 |
} |
| 204 |
} |
| 205 |
} |
| 206 |
} |
| 207 |
} |
| 208 |
# Error |
| 209 |
-->expecterror 5116 |
| 210 |
-->recvresult |
| 211 |
|
| 212 |
-->sql |
| 213 |
SELECT * FROM xplugintest.table2; |
| 214 |
-->endsql |
| 215 |
|
| 216 |
# Insert into table1 |
| 217 |
-->sql |
| 218 |
INSERT INTO xplugintest.table1 VALUES (1,'{"a":["x", "y"]}'), (2,'{"b":["x", "y"]}'); |
| 219 |
-->endsql |
| 220 |
-->expecterror 1062 |
| 221 |
-->sql |
| 222 |
INSERT INTO xplugintest.table1 VALUES (3,'{"c":["x", "y"]}'), (2,'{"d":["x", "y"]}'); |
| 223 |
SELECT * FROM xplugintest.table1 ; |
| 224 |
UPDATE xplugintest.table1 SET doc= '{"m":["x", "y"]}' WHERE _id=1; |
| 225 |
SELECT * FROM xplugintest.table1 ; |
| 226 |
-->endsql |
| 227 |
|
| 228 |
EOF |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
--exec $MYSQLXTEST -u x_root --password='' --file=$MYSQL_TMP_DIR/mysqlx-in.tmp 2>&1 |
| 233 |
--remove_file $MYSQL_TMP_DIR/mysqlx-in.tmp |
| 234 |
|
| 235 |
--source include/sync_slave_sql_with_master.inc |
| 236 |
#-- connection slave |
| 237 |
--echo # Connection:slave - Row with value 2 is expected on slave. |
| 238 |
USE xplugintest; |
| 239 |
SHOW CREATE TABLE xplugintest.table2; |
| 240 |
SELECT * FROM xplugintest.table2; |
| 241 |
SELECT * FROM xplugintest.table1; |
| 242 |
--let $diff_tables= master:xplugintest.table1, slave:xplugintest.table1 |
| 243 |
--let $diff_tables= master:xplugintest.table2, slave:xplugintest.table2 |
| 244 |
--source include/diff_tables.inc |
| 245 |
|
| 246 |
## Cleanup |
| 247 |
-- connection master |
| 248 |
DROP DATABASE IF EXISTS xplugintest; |
| 249 |
|
| 250 |
--source ../include/xplugin_cleanup.inc |
| 251 |
--source include/wait_until_count_sessions.inc |
| 252 |
--source include/sync_slave_sql_with_master.inc |
| 253 |
--source include/rpl_end.inc |
| 254 |
|