polardbxengine/mysql-test/suite/x/t/crud_rpl.test

338 lines
6.8 KiB
Plaintext

########### ../t/crud_rpl.test #########
## #
## This test aims to run crud message on replication setup. #
## Test runs following message on master and checks data on slave #
## - create_collection message #
## - Insert message #
## - create_collection_index #
## - update message #
## - delete message #
#######################################################################
--source include/master-slave.inc
--source include/count_sessions.inc
--source include/xplugin_create_user.inc
# Use master connection
--connection master
--source include/xplugin_preamble.inc
--source ../include/have_performance_schema_events_waits_history.inc
call mtr.add_suppression("Error parsing message of type 12: args");
call mtr.add_suppression("Error handling message: args");
## Test starts here
--write_file $MYSQL_TMP_DIR/mysqlx-in.tmp
-->sql
#-- "Creating database for testcase"
DROP DATABASE IF EXISTS xplugintest;
CREATE DATABASE xplugintest;
USE xplugintest;
CREATE TABLE table1 ( _id INT PRIMARY KEY, doc JSON ) ;
-->endsql
#-- "Create table table2 in xplugintest "
Mysqlx.Sql.StmtExecute {
stmt: "create_collection"
args {
type: SCALAR
scalar {
type: V_STRING
v_string {
value: "xplugintest"
}
}
}
args {
type: SCALAR
scalar {
type: V_STRING
v_string {
value: "table2"
}
}
}
namespace: "xplugin"
}
-->recvresult
-->echo Insert multiple rows into a Document column
Mysqlx.Crud.Insert {
collection {
name: "table2"
schema: "xplugintest"
}
data_model: DOCUMENT
row {
field {
type: LITERAL
literal {
type: V_STRING
v_string {
value: "\n{\n \"_id\": \"1\",\n \"name\": \"Omar Bras\", \"id\": \"1\"\n}"
}
}
}
}
row {
field {
type: LITERAL
literal {
type: V_STRING
v_string {
value: "\n{\n \"_id\": \"2\",\n \"name\": \"Omar Mex\", \"id\": \"2\"\n}"
}
}
}
}
}
-->recvresult
-->sql
SELECT * FROM xplugintest.table2;
-->endsql
#-- "Index with unique(true), index column NOT NULL (true)"
Mysqlx.Sql.StmtExecute {
stmt: "create_collection_index"
args {
type: SCALAR
scalar {
type: V_STRING
v_string {
value: "xplugintest"
}
}
}
args {
type: SCALAR
scalar {
type: V_STRING
v_string {
value: "table2"
}
}
}
args {
type: SCALAR
scalar {
type: V_STRING
v_string {
value: "name_index"
}
}
}
args {
type: SCALAR
scalar {
type: V_BOOL
v_bool: true
}
}
args {
type: SCALAR
scalar {
type: V_STRING
v_string {
value: "$.name"
}
}
}
args {
type: SCALAR
scalar {
type: V_STRING
v_string {
value: "TEXT(50)"
}
}
}
args {
type: SCALAR
scalar {
type: V_BOOL
v_bool: true
}
}
namespace: "xplugin"
}
-->recvresult
-->sql
SHOW CREATE TABLE xplugintest.table2;
SELECT * FROM xplugintest.table2;
-->endsql
-->echo Update decimal value with a corner value plus 1
Mysqlx.Crud.Update {
collection {
name: "table2"
schema: "xplugintest"
}
data_model: DOCUMENT
criteria {
type: OPERATOR
operator {
name: "=="
param {
type: IDENT identifier { name: "_id" }
}
param {
type: LITERAL
literal {
type: V_SINT
v_signed_int: 2
}
}
}
}
operation {
source {
document_path {
type: MEMBER
value: "name"
}
}
operation: ITEM_SET
value {
type: LITERAL
literal {
type: V_STRING
v_string {
value: "\"Omar Argentina\""
}
}
}
}
}
-->recvresult
-->sql
SHOW CREATE TABLE xplugintest.table2;
SELECT JSON_EXTRACT(doc,'$.name') FROM xplugintest.table2;
SELECT * FROM xplugintest.table2;
-->endsql
-->echo Delete with == operator
Mysqlx.Crud.Delete {
collection {
name: "table2"
schema: "xplugintest"
}
data_model: DOCUMENT
criteria {
type: OPERATOR
operator {
name: "=="
param {
type: IDENT identifier { name: "_id" }
}
param {
type: LITERAL
literal {
type: V_SINT
v_signed_int: 2
}
}
}
}
}
-->recvresult
-->sql
SELECT JSON_EXTRACT(doc,'$.name') FROM xplugintest.table2;
SELECT * FROM xplugintest.table2;
-->endsql
Mysqlx.Crud.Insert {
collection {
name: "table2"
schema: "xplugintest"
}
data_model: DOCUMENT
row {
field {
type: LITERAL
literal {
type: V_STRING
v_string {
value: "\n{\n \"_id\": \"3\",\n \"name\": \"Omar Peru\", \"id\": \"3\"\n}"
}
}
}
}
}
-->recvresult
# Insert fail due to non unique _id doc member
Mysqlx.Crud.Insert {
collection {
name: "table2"
schema: "xplugintest"
}
data_model: DOCUMENT
row {
field {
type: LITERAL
literal {
type: V_STRING
v_string {
value: "\n{\n \"_id\": \"1\",\n \"name\": \"Omar Colombia\", \"id\": \"3\"\n}"
}
}
}
}
}
# Error
-->expecterror 5116
-->recvresult
-->sql
SELECT * FROM xplugintest.table2;
-->endsql
# Insert into table1
-->sql
INSERT INTO xplugintest.table1 VALUES (1,'{"a":["x", "y"]}'), (2,'{"b":["x", "y"]}');
-->endsql
-->expecterror 1062
-->sql
INSERT INTO xplugintest.table1 VALUES (3,'{"c":["x", "y"]}'), (2,'{"d":["x", "y"]}');
SELECT * FROM xplugintest.table1 ;
UPDATE xplugintest.table1 SET doc= '{"m":["x", "y"]}' WHERE _id=1;
SELECT * FROM xplugintest.table1 ;
-->endsql
EOF
--exec $MYSQLXTEST -u x_root --password='' --file=$MYSQL_TMP_DIR/mysqlx-in.tmp 2>&1
--remove_file $MYSQL_TMP_DIR/mysqlx-in.tmp
--source include/sync_slave_sql_with_master.inc
#-- connection slave
--echo # Connection:slave - Row with value 2 is expected on slave.
USE xplugintest;
SHOW CREATE TABLE xplugintest.table2;
SELECT * FROM xplugintest.table2;
SELECT * FROM xplugintest.table1;
--let $diff_tables= master:xplugintest.table1, slave:xplugintest.table1
--let $diff_tables= master:xplugintest.table2, slave:xplugintest.table2
--source include/diff_tables.inc
## Cleanup
-- connection master
DROP DATABASE IF EXISTS xplugintest;
--source include/xplugin_drop_user.inc
--source include/wait_until_count_sessions.inc
--source include/sync_slave_sql_with_master.inc
--source include/rpl_end.inc