1########### ../t/connection_unixsocket_rpl.test              #########
2## WL#9306                                                           #
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--source include/not_windows.inc
13--source include/have_innodb.inc
14--source include/master-slave.inc
15--source include/count_sessions.inc
16--source ../include/have_performance_schema_threads.inc
17
18
19# Use master connection
20--connection master
21
22--source ../include/xplugin_preamble.inc
23call mtr.add_suppression("Error parsing message of type 12: args");
24call mtr.add_suppression("Error handling message: args");
25
26CREATE USER user_localhost@localhost IDENTIFIED WITH 'mysql_native_password' BY '';
27GRANT ALL ON *.* TO user_localhost@localhost;
28
29## Test starts here
30--write_file $MYSQL_TMP_DIR/mysqlx-in.tmp
31## Checking connection type
32-->stmtsql SELECT CONNECTION_TYPE from performance_schema.threads where processlist_command='Query';
33-->recvresult
34-->sql
35-- "Creating database for testcase"
36DROP DATABASE IF EXISTS xplugintest;
37CREATE DATABASE xplugintest;
38USE xplugintest;
39CREATE TABLE table1 ( _id INT PRIMARY KEY, doc JSON ) ;
40-->endsql
41
42-- "Create table table2 in xplugintest "
43
44Mysqlx.Sql.StmtExecute {
45  stmt: "create_collection"
46  args {
47    type: SCALAR
48    scalar {
49      type: V_STRING
50      v_string {
51        value: "xplugintest"
52      }
53    }
54  }
55  args {
56    type: SCALAR
57    scalar {
58      type: V_STRING
59      v_string {
60        value: "table2"
61      }
62    }
63  }
64  namespace: "xplugin"
65}
66-->recvresult
67
68-->echo Insert multiple rows into a Document column
69Mysqlx.Crud.Insert {
70  collection {
71    name: "table2"
72    schema: "xplugintest"
73  }
74  data_model: DOCUMENT
75  row {
76    field {
77      type: LITERAL
78      literal {
79        type: V_STRING
80        v_string {
81          value: "\n{\n         \"_id\": \"1\",\n         \"name\": \"Omar Bras\", \"id\": \"1\"\n}"
82        }
83      }
84    }
85  }
86  row {
87    field {
88      type: LITERAL
89      literal {
90        type: V_STRING
91        v_string {
92          value: "\n{\n         \"_id\": \"2\",\n         \"name\": \"Omar Mex\", \"id\": \"2\"\n}"
93        }
94      }
95    }
96  }
97}
98-->recvresult
99-->sql
100SELECT * FROM xplugintest.table2;
101-->endsql
102
103
104-- "Index with  unique(true), index column NOT NULL (true)"
105Mysqlx.Sql.StmtExecute {
106  stmt: "create_collection_index"
107  args {
108    type: SCALAR
109    scalar {
110      type: V_STRING
111      v_string {
112        value: "xplugintest"
113      }
114    }
115  }
116  args {
117    type: SCALAR
118    scalar {
119      type: V_STRING
120      v_string {
121        value: "table2"
122      }
123    }
124  }
125  args {
126    type: SCALAR
127    scalar {
128      type: V_STRING
129      v_string {
130        value: "name_index"
131      }
132    }
133  }
134  args {
135    type: SCALAR
136    scalar {
137      type: V_BOOL
138      v_bool: true
139    }
140  }
141  args {
142    type: SCALAR
143    scalar {
144      type: V_STRING
145      v_string {
146        value: "$.name"
147      }
148    }
149  }
150  args {
151    type: SCALAR
152    scalar {
153      type: V_STRING
154      v_string {
155        value: "TEXT(50)"
156      }
157    }
158  }
159  args {
160    type: SCALAR
161    scalar {
162      type: V_BOOL
163      v_bool: true
164    }
165  }
166  namespace: "xplugin"
167}
168-->recvresult
169-->sql
170SHOW CREATE TABLE xplugintest.table2;
171SELECT * FROM xplugintest.table2;
172-->endsql
173
174
175-->echo Update decimal value with a corner value plus 1
176Mysqlx.Crud.Update {
177  collection {
178    name: "table2"
179    schema: "xplugintest"
180  }
181  data_model: DOCUMENT
182  criteria {
183    type: OPERATOR
184    operator {
185      name: "=="
186      param {
187        type: IDENT identifier { name: "_id" }
188      }
189      param {
190        type: LITERAL
191        literal {
192               type: V_SINT
193               v_signed_int: 2
194        }
195      }
196    }
197  }
198  operation {
199    source {
200      document_path {
201        type: MEMBER
202        value: "name"
203      }
204    }
205    operation: ITEM_SET
206    value {
207      type: LITERAL
208      literal {
209          type: V_STRING
210          v_string {
211            value: "\"Omar Argentina\""
212          }
213      }
214    }
215  }
216}
217-->recvresult
218
219
220-->sql
221SHOW CREATE TABLE xplugintest.table2;
222SELECT JSON_EXTRACT(doc,'$.name') FROM xplugintest.table2;
223SELECT * FROM xplugintest.table2;
224-->endsql
225
226-->echo Delete with == operator
227Mysqlx.Crud.Delete {
228  collection {
229    name: "table2"
230    schema: "xplugintest"
231  }
232  data_model: DOCUMENT
233  criteria {
234    type: OPERATOR
235    operator {
236      name: "=="
237      param {
238        type: IDENT identifier { name: "_id" }
239      }
240      param {
241        type: LITERAL
242        literal {
243                type: V_SINT
244                v_signed_int: 2
245              }
246         }
247      }
248   }
249}
250-->recvresult
251
252-->sql
253SELECT JSON_EXTRACT(doc,'$.name') FROM xplugintest.table2;
254SELECT * FROM xplugintest.table2;
255-->endsql
256
257
258Mysqlx.Crud.Insert {
259  collection {
260    name: "table2"
261    schema: "xplugintest"
262  }
263  data_model: DOCUMENT
264  row {
265    field {
266      type: LITERAL
267      literal {
268        type: V_STRING
269        v_string {
270          value: "\n{\n         \"_id\": \"3\",\n         \"name\": \"Omar Peru\", \"id\": \"3\"\n}"
271        }
272      }
273    }
274  }
275}
276-->recvresult
277
278# Insert fail due to non unique _id doc member
279Mysqlx.Crud.Insert {
280  collection {
281    name: "table2"
282    schema: "xplugintest"
283  }
284  data_model: DOCUMENT
285  row {
286    field {
287      type: LITERAL
288      literal {
289        type: V_STRING
290        v_string {
291          value: "\n{\n         \"_id\": \"1\",\n         \"name\": \"Omar Colombia\", \"id\": \"3\"\n}"
292        }
293      }
294    }
295  }
296}
297# Error
298-->expecterror 5116
299-->recvresult
300
301-->sql
302SELECT * FROM xplugintest.table2;
303-->endsql
304
305# Insert into table1
306-->sql
307INSERT INTO xplugintest.table1 VALUES (1,'{"a":["x", "y"]}'), (2,'{"b":["x", "y"]}');
308-->endsql
309-->expecterror 1062
310-->sql
311INSERT INTO xplugintest.table1 VALUES (3,'{"c":["x", "y"]}'), (2,'{"d":["x", "y"]}');
312SELECT * FROM xplugintest.table1 ;
313UPDATE xplugintest.table1 SET doc= '{"m":["x", "y"]}' WHERE _id=1;
314SELECT * FROM xplugintest.table1 ;
315-->endsql
316
317EOF
318
319--exec $MYSQLXTEST --socket=$MASTER_X_MYSOCK -u user_localhost -h localhost  --password='' --file=$MYSQL_TMP_DIR/mysqlx-in.tmp 2>&1
320--remove_file $MYSQL_TMP_DIR/mysqlx-in.tmp
321
322--source include/sync_slave_sql_with_master.inc
323-- connection slave
324--echo # Connection:slave - Row with value 2 is expected on slave.
325USE xplugintest;
326SHOW CREATE TABLE xplugintest.table2;
327SELECT * FROM xplugintest.table2;
328SELECT * FROM xplugintest.table1;
329--let $diff_tables= master:xplugintest.table1, slave:xplugintest.table1
330--source include/diff_tables.inc
331--let $diff_tables= master:xplugintest.table2, slave:xplugintest.table2
332--source include/diff_tables.inc
333
334#cleanup
335-- connection master
336DROP DATABASE IF EXISTS xplugintest;
337DROP USER IF EXISTS user_localhost@localhost;
338## Postamble
339
340UNINSTALL PLUGIN mysqlx;
341
342--source include/wait_until_count_sessions.inc
343--source include/sync_slave_sql_with_master.inc
344--source include/rpl_end.inc
345
346