File: gr_unique_key_table_requirements.test

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (119 lines) | stat: -rw-r--r-- 3,626 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
################################################################################
# The intent of this test is to verify if the validations that were
# created within the Group Replication plugin in the runtime process
# are fully functional.
#
# It will test the invalid scenarios for table creation.
#
#   Table with only unique key.
#   Table with NULL key.
#   Table with Unique NULL key.
#   Table with a normal key. (Not unique)
#
# It will cycle all cases in which the runtime validation is verified.
#
# Afterwards the plugin will be stopped and one of the cases will be tested in
# order to assess that the verification is no longer accomplished.
#
# Test:
# 0. The test requires two servers: M1 and M2.
# 1. Setup group of two members. Bring both the members ONLINE.
# 2. On M1:
#  - Create table t1 with only unique key.
#  - Create table t2 with possible NULL value for the key.
#  - Create table t3 with unique NULL key.
#  - Sync it to the group.
# 3. Testing all the three tables that will fail with following DML operations:
#  - Test the INSERT instruction. It must fail.
#  - Test the UPDATE instruction. It must fail.
#  - Test the DELETE instruction. It must fail.
#  - Sync data to the group.
# 4. Stop GR on M1. Stop GR on M2.
# 5. Testing all the three tables again with following DML operations on M1:
#  - Test the INSERT instruction. It must succeed.
#  - Test the UPDATE instruction. It must succeed.
#  - Test the DELETE instruction. It must succeed.
# 6. Clean up.
################################################################################
--source include/have_group_replication_plugin.inc
--source include/group_replication.inc

SET SESSION sql_log_bin=0;
call mtr.add_suppression("Table.*does not have any PRIMARY KEY. This is not compatible with Group Replication.");
SET SESSION sql_log_bin=1;

--connection server1
#Lets create several tables. They will all breach 1 or more rules

#Wrong table with only unique Key
CREATE TABLE t1 (c1 INT UNIQUE KEY) ENGINE=InnoDB;

#Wrong table with possible NULL value for the key.
CREATE TABLE t2 (c1 INT, KEY `c1` (`c1`)) ENGINE=InnoDB;

#Wrong table with unique key with null value.
CREATE TABLE t3 (c1 INT UNIQUE NULL) ENGINE=InnoDB;

--source include/rpl_sync.inc

#
# The tests begin here.
#
--echo #
--echo # Testing all tables that will fail.
--echo #

--let $wrong_tables_count=3
while ($wrong_tables_count)
{
  #Test the INSERT instruction
  --error ER_BEFORE_DML_VALIDATION_ERROR
  --eval INSERT INTO t$wrong_tables_count VALUES(1)

  #Test the UPDATE instruction
  --error ER_BEFORE_DML_VALIDATION_ERROR
  --eval UPDATE t$wrong_tables_count SET c1 = 2

  #Test the DELETE instruction
  --error ER_BEFORE_DML_VALIDATION_ERROR
  --eval DELETE FROM t$wrong_tables_count

  --dec $wrong_tables_count
}

#This will sync data among all group members
--source include/rpl_sync.inc

--echo # Now, lets repeat all the tests with group replication stopped.
--source include/stop_group_replication.inc
--connection server2
--source include/stop_group_replication.inc

--connection server1

--let $wrong_tables_count=3
while ($wrong_tables_count)
{
  #Test the INSERT instruction
  --eval INSERT INTO t$wrong_tables_count VALUES(1)

  #Test the UPDATE instruction
  --eval UPDATE t$wrong_tables_count SET c1 = 2

  #Test the DELETE instruction
  --eval DELETE FROM t$wrong_tables_count

  #clean up this table
  --eval DROP TABLE t$wrong_tables_count

  --dec $wrong_tables_count
}

--connection server2
--let $table_count= 3
while ($table_count)
{
  --eval DROP TABLE t$table_count
  --dec $table_count
}
--source include/group_replication_end.inc