1
##################################################################
2
# Author: Giuseppe, Chuck Bell #
3
# Date: 17-January-2007 #
4
# Purpose: To test that event effects are replicated #
5
# in both row based and statement based format #
6
##################################################################
9
DROP EVENT IF EXISTS test.justonce;
10
drop table if exists t1,t2;
13
# first, we need a table to record something from an event
15
eval CREATE TABLE `t1` (
16
`id` INT(10) UNSIGNED NOT NULL,
17
`c` VARCHAR(50) NOT NULL,
18
`ts` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
20
) ENGINE=$engine_type DEFAULT CHARSET=utf8;
22
INSERT INTO t1 (id, c) VALUES (1, 'manually');
24
# We create the event so that it inserts exactly 1 row in the table
25
# A recuring event is used so that we can be sure the event will
26
# fire regardless of timing delays on the server. Otherwise, it is
27
# possible for the event to timeout before it has inserted a row.
28
--echo "Creating event test.justonce on the master"
29
CREATE EVENT test.justonce ON SCHEDULE EVERY 2 SECOND DO
30
INSERT IGNORE INTO t1 (id, c) VALUES (2, 'from justonce');
32
# Show the event is alive and present on master
33
--echo "Checking event is active on master"
34
SELECT db, name, status, originator FROM mysql.event WHERE db = 'test' AND name = 'justonce';
36
# Wait until event has fired. We know this because t1 will contain
37
# the row from the event.
39
SELECT COUNT(*) = 1 FROM t1 WHERE c = 'from justonce';
40
--source include/wait_condition.inc
42
# check that table t1 contains something
43
--echo "Checking event data on the master"
45
--replace_column 3 TIMESTAMP
46
SELECT * FROM t1 ORDER BY id;
49
sync_slave_with_master;
51
--echo "Checking event data on the slave"
53
--replace_column 3 TIMESTAMP
54
SELECT * FROM t1 ORDER BY id;
57
--echo "Checking event is inactive on slave"
58
SELECT db, name, status, originator FROM mysql.event WHERE db = 'test' AND name = 'justonce';
60
# Create an event on the slave and check to see what the originator is.
61
--echo "Dropping event test.slave_once on the slave"
63
DROP EVENT IF EXISTS test.slave_once;
66
CREATE EVENT test.slave_once ON SCHEDULE EVERY 5 MINUTE DO
67
INSERT IGNORE INTO t1(id, c) VALUES (3, 'from slave_once');
69
--echo "Checking event status on the slave for originator value = slave's server_id"
70
SELECT db, name, status, originator FROM mysql.event WHERE db = 'test' AND name = 'slave_once';
72
--echo "Dropping event test.slave_once on the slave"
74
DROP EVENT IF EXISTS test.slave_once;
79
# BUG#20384 - disable events on slave
80
--echo "Dropping event test.justonce on the master"
82
DROP EVENT IF EXISTS test.justonce;
85
--echo "Creating event test.er on the master"
86
CREATE EVENT test.er ON SCHEDULE EVERY 3 SECOND DO
87
INSERT IGNORE INTO t1(id, c) VALUES (4, 'from er');
89
--echo "Checking event status on the master"
90
SELECT db, name, status, originator, body FROM mysql.event WHERE db = 'test' AND name = 'er';
92
sync_slave_with_master;
94
--echo "Checking event status on the slave"
95
SELECT db, name, status, originator, body FROM mysql.event WHERE db = 'test' AND name = 'er';
98
--echo "Altering event test.er on the master"
99
ALTER EVENT test.er ON SCHEDULE EVERY 5 SECOND DO
100
INSERT IGNORE INTO t1(id, c) VALUES (5, 'from alter er');
102
--echo "Checking event status on the master"
103
SELECT db, name, status, originator, body FROM mysql.event WHERE db = 'test' AND name = 'er';
105
sync_slave_with_master;
107
--echo "Checking event status on the slave"
108
SELECT db, name, status, originator, body FROM mysql.event WHERE db = 'test' AND name = 'er';
111
--echo "Dropping event test.er on the master"
114
--echo "Checking event status on the master"
115
SELECT db, name, status, originator FROM mysql.event WHERE db = 'test';
119
sync_slave_with_master;
121
--echo "Checking event status on the slave"
122
SELECT db, name, status, originator FROM mysql.event WHERE db = 'test';
124
# test the DISABLE ON SLAVE for setting event SLAVESIDE_DISABLED as status
127
--echo "Creating event test.slave_terminate on the slave"
128
CREATE EVENT test.slave_terminate ON SCHEDULE EVERY 3 SECOND DO
129
INSERT IGNORE INTO t1(id, c) VALUES (6, 'from slave_terminate');
131
--echo "Checking event status on the slave"
132
SELECT db, name, status, originator FROM mysql.event WHERE db = 'test' AND name = 'slave_terminate';
134
--echo "Dropping event test.slave_terminate on the slave"
135
DROP EVENT test.slave_terminate;
137
--echo "Creating event test.slave_terminate with DISABLE ON SLAVE on the slave"
138
CREATE EVENT test.slave_terminate ON SCHEDULE EVERY 3 SECOND DISABLE ON SLAVE DO
139
INSERT IGNORE INTO t1(c) VALUES (7, 'from slave_terminate');
141
--echo "Checking event status on the slave"
142
SELECT db, name, status, originator FROM mysql.event WHERE db = 'test' AND name = 'slave_terminate';
144
--echo "Dropping event test.slave_terminate on the slave"
145
DROP EVENT test.slave_terminate;
150
sync_slave_with_master;