Debian Codegraph @

mysql-test/suite/group_replication/t/gr_foreign_key_unique_conflict.test

raw
1 ################################################################################
2 # Test case to verify that concurrent transactions with intersecting
3 # write set, on foreign key referencing not null unique key, do conflict.
4 #
5 # Test:
6 # 0. The test requires two servers: M1 and M2.
7 # 1. Create a table on server1.
8 # 2. Checking the negative case in which there is a conflict.
9 # 3. Checking the positive case in which there is no conflict.
10 # 4. Check the data sanity.
11 # 5. Clean up.
12 ################################################################################
13
14 --source include/have_debug_sync.inc
15 --source include/have_group_replication_plugin.inc
16 --source include/group_replication.inc
17
18 --echo
19 --echo ############################################################
20 --echo # 1. Create a table on server1.
21 --let $rpl_connection_name= server1
22 --source include/rpl_connection.inc
23
24 CREATE TABLE t1 (c1 INT UNIQUE KEY NOT NULL);
25 CREATE TABLE t2 (c2 INT UNIQUE KEY NOT NULL, FOREIGN KEY (c2) REFERENCES t1(c1));
26 INSERT INTO t1 VALUES(1);
27 --source include/rpl_sync.inc
28
29 --echo
30 --echo ############################################################
31 --echo # 2. Checking the negative case in which there is a conflict.
32 --let $local_server_connection1=server1
33 --let $local_server_connection2=server_1
34 --let $remote_server_connection=server2
35 --let $local_transaction= INSERT INTO t2 VALUES (1)
36 --let $remote_transaction=UPDATE t1 SET c1=2 WHERE c1=1
37 --let $conflict_test=1
38 --source include/gr_parallel_local_and_remote_transactions.inc
39
40 --echo
41 --echo ############################################################
42 --echo # 3. Checking the positive case in which there is no conflict.
43 INSERT INTO t1 VALUES (5);
44
45 --let $local_server_connection1=server1
46 --let $local_server_connection2=server_1
47 --let $remote_server_connection=server2
48 --let $local_transaction= INSERT INTO t2 VALUES (5)
49 --let $remote_transaction=UPDATE t1 SET c1=6 WHERE c1=2
50 --let $conflict_test=0
51 --source include/gr_parallel_local_and_remote_transactions.inc
52
53 --echo
54 --echo ############################################################
55 --echo # 4. Check the data sanity.
56 --let $rpl_connection_name= server1
57 --source include/rpl_connection.inc
58
59 --let $assert_text= Table t2 will contain row after the above execution
60 --let $assert_cond= "[SELECT COUNT(*) AS count FROM t2 WHERE t2.c2 = 5, count, 1]" = "1"
61 --source include/assert.inc
62
63 --let $assert_text= Table t1 will contain row after the above execution
64 --let $assert_cond= "[SELECT COUNT(*) AS count FROM t1 WHERE t1.c1 = 5, count, 1]" = "1"
65 --source include/assert.inc
66
67 --let $assert_text= Table t1 will contain row after the above execution
68 --let $assert_cond= "[SELECT COUNT(*) AS count FROM t1 WHERE t1.c1 = 6, count, 1]" = "1"
69 --source include/assert.inc
70
71 --let $assert_text= Table t2 will contain 1 rows after the above execution
72 --let $assert_cond= "[SELECT COUNT(*) FROM t2]" = "1"
73 --source include/assert.inc
74
75 --let $assert_text= Table t1 will contain 2 rows after the above execution
76 --let $assert_cond= "[SELECT COUNT(*) FROM t1]" = "2"
77 --source include/assert.inc
78
79 --echo
80 --echo ############################################################
81 --echo # 5. Clean up.
82 DROP TABLE t2;
83 DROP TABLE t1;
84
85 --source include/group_replication_end.inc