File: gr_invoked_features.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 (194 lines) | stat: -rw-r--r-- 5,459 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
################################################################################
# Purpose: Testing the behavior of execution of Invoked Features for
#          Group Replication.
#
# Test:
# 0. The test requires two servers: M1 and M2.
# 1. With both members ONLINE. Create tables and add some data.
# 2. Create invoked features in M1 and M2.
#  - On M1, create view for table.
#  - On M1, create trigger.
#  - On M2, create event.
#  - On M1, create function.
#  - On M2, create procedure for event.
#  - Sync everything.
# 3. Do some actions to check the effect of the invoked features on the
#    transactional tables.
# 4. Check original objects.
# 5. Sync the two members and check replicated objects in the group.
# 6. Clean up.
################################################################################

--source include/set_privilege_checks_user_as_system_user.inc
--source include/have_group_replication_plugin.inc
--source include/group_replication.inc

#
# Prepare objects (tables etc)
#
# Create tables
--eval CREATE TABLE t11 (a INT NOT NULL PRIMARY KEY, b INT, c VARCHAR(64)) ENGINE=innodb
INSERT INTO t11 VALUES (1,1,'1');
--disable_warnings
INSERT INTO t11 VALUES (2,2,UUID());
--enable_warnings
--eval CREATE TABLE t12 (a INT PRIMARY KEY, b INT, c VARCHAR(64)) ENGINE=innodb
INSERT INTO t12 VALUES (1,1,'1');
--disable_warnings
INSERT INTO t12 VALUES (2,2,UUID());
--enable_warnings

# Create invoked features on member1 and member2 and see its behavior
--echo
# Create view for tables t11
CREATE VIEW v11 AS SELECT * FROM t11;

# Creating some invoked features on group members and check its behavior on the group.
--connection server1
DELIMITER |;

CREATE TRIGGER t11_tr1 BEFORE INSERT ON t11 FOR EACH ROW
BEGIN
  INSERT INTO t12 VALUES (NEW.a, NEW.b, NEW.c);
  INSERT INTO t13 VALUES (NEW.a, NEW.b, NEW.c);
END|

DELIMITER ;|

--connection server2

DELIMITER |;
CREATE EVENT e1 ON SCHEDULE EVERY 1 SECOND DISABLE DO
BEGIN
  ALTER EVENT e1 DISABLE;
  CALL p11(10, '');
END|

DELIMITER ;|

# Create functions and procedures used for events
--connection server1

DELIMITER |;

CREATE FUNCTION f1 (x INT) RETURNS VARCHAR(64)
BEGIN
  IF x > 5 THEN
    RETURN UUID();
  END IF;
  RETURN '';
END|

DELIMITER ;|

--connection server2

DELIMITER |;

CREATE PROCEDURE p11 (IN x INT, IN y VARCHAR(64))
BEGIN
  INSERT IGNORE INTO t11 VALUES (x,x,y);
END|

DELIMITER ;|

# Syncing the second member with the first one
--source include/rpl_sync.inc
--connection server1

#
# Start test case
#
# Do some actions to check the effect of the invoked features on the
# transactional tables.

--echo
--disable_warnings
CREATE TABLE t13(a INT NOT NULL PRIMARY KEY, b INT, c VARCHAR(64)) engine=InnoDB;
INSERT INTO t11 VALUES (3,3,'');
UPDATE t11 SET c='2' WHERE a = 1;
--source include/rpl_sync.inc

--connection server2
INSERT INTO t11 VALUES(4,4,f1(4));
--connection server1
INSERT INTO t11 VALUES(7,7,f1(7));

--connection server1
CALL p11(5, UUID());
--connection server2
CALL p11(10, UUID());

--enable_warnings
--connection server1
# Scheduler is on
SET @old_event_scheduler= @@global.event_scheduler;
SET GLOBAL EVENT_SCHEDULER = on;
# Wait while events will executed
ALTER EVENT e1 ENABLE;
--let $wait_condition= SELECT COUNT(*) = 1 FROM t11 WHERE t11.a = 10
--source include/wait_condition_or_abort.inc
#
# Wait for the event to have been disabled.
#
# There may be a race here, since it looks like the
# event thread might not have the chance to disable
# the event before it is shutdown. Note that the
# act of disabling the event is done inside the
# event itself!
#
--let $wait_condition= SELECT status="DISABLED" FROM information_schema.events WHERE event_schema='test' AND event_name="e1"
--source include/wait_condition_or_abort.inc
SET GLOBAL EVENT_SCHEDULER = @old_event_scheduler;

--source include/rpl_sync.inc
# Check original objects
--echo
--sorted_result
SHOW TABLES LIKE 't%';
--sorted_result
SELECT table_name FROM information_schema.views WHERE table_schema='test';
--sorted_result
SELECT trigger_name, event_manipulation, event_object_table FROM information_schema.triggers WHERE trigger_schema='test';
--sorted_result
SELECT routine_type, routine_name FROM information_schema.routines WHERE routine_schema='test';
--sorted_result
SELECT event_name, status FROM information_schema.events WHERE event_schema='test';

# Syncing the two members involved in the group
--source include/rpl_sync.inc

--let $diff_tables= server1:t11, server2:t11
--source include/diff_tables.inc

--let $diff_tables= server1:t12, server2:t12
--source include/diff_tables.inc

--let $diff_tables= server1:t13, server2:t13
--source include/diff_tables.inc

# Check replicated objects in the group
--echo
--sorted_result
SHOW TABLES LIKE 't%';
--sorted_result
SELECT table_name FROM information_schema.views WHERE table_schema='test';
--sorted_result
SELECT trigger_name, event_manipulation, event_object_table FROM information_schema.triggers WHERE trigger_schema='test';
--sorted_result
SELECT routine_type, routine_name FROM information_schema.routines WHERE routine_schema='test';
--sorted_result
SELECT event_name, status FROM information_schema.events WHERE event_schema='test';

#
# Clean up
#
# Remove tables,views,procedures,functions
--connection server1
DROP VIEW IF EXISTS v11;
DROP TABLE IF EXISTS t11,t12,t13;
DROP PROCEDURE IF EXISTS p11;
DROP FUNCTION IF EXISTS f1;
DROP EVENT IF EXISTS e1;

--source include/group_replication_end.inc