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"
44 let $events_done=`SELECT count(*) FROM t1
id`;
46 eval SELECT $events_done > 0 as ONE;
49 sync_slave_with_master;
51 --echo "Checking
event data on the slave"
53 eval SELECT count(*) - $events_done as ZERO FROM t1
id;
56 --echo "Checking
event is inactive on slave"
57 SELECT db, name, status, originator FROM mysql.
event WHERE db = '
test' AND name = 'justonce';
59 # Create an event on the slave and check to see what the originator is.
60 --echo
"Dropping event test.slave_once on the slave"
62 DROP EVENT IF EXISTS
test.slave_once;
65 # Create an event on slave and check its state. An event shouldn't be executed
66 # so set start time in 1 hour.
67 CREATE EVENT
test.slave_once ON SCHEDULE EVERY 5 MINUTE STARTS CURRENT_TIMESTAMP +
INTERVAL 1 HOUR DO
68 INSERT IGNORE INTO t1(
id, c) VALUES (3, 'from slave_once');
70 --echo "Checking
event status on the slave for originator value = slave's server_id"
71 SELECT db, name, status, originator FROM mysql.
event WHERE db = '
test' AND name = 'slave_once';
73 --echo "Dropping
event test.slave_once on the slave"
75 DROP EVENT IF EXISTS
test.slave_once;
80 # BUG#20384 - disable events on slave
81 --echo
"Dropping event test.justonce on the master"
83 DROP EVENT IF EXISTS
test.justonce;
86 # Create an event on master and check its state on slave. An event shouldn't be executed
87 # so set start time in 1 hour. Check that changes of event statement replicated to slave
89 --echo
"Creating event test.er on the master"
90 CREATE EVENT
test.er ON SCHEDULE EVERY 3 SECOND STARTS CURRENT_TIMESTAMP +
INTERVAL 1 HOUR DO
91 INSERT IGNORE INTO t1(
id, c) VALUES (4, 'from er');
93 --echo "Checking
event status on the master"
94 SELECT db, name, status, originator, body FROM mysql.
event WHERE db = '
test' AND name = 'er';
96 sync_slave_with_master;
98 --echo "Checking
event status on the slave"
99 SELECT db, name, status, originator, body FROM mysql.
event WHERE db = '
test' AND name = 'er';
102 --echo "Altering
event test.er on the master"
103 ALTER EVENT
test.er ON SCHEDULE EVERY 5 SECOND STARTS CURRENT_TIMESTAMP +
INTERVAL 1 HOUR DO
104 INSERT IGNORE INTO t1(
id, c) VALUES (5, 'from alter er');
106 --echo "Checking
event status on the master"
107 SELECT db, name, status, originator, body FROM mysql.
event WHERE db = '
test' AND name = 'er';
109 sync_slave_with_master;
111 --echo "Checking
event status on the slave"
112 SELECT db, name, status, originator, body FROM mysql.
event WHERE db = '
test' AND name = 'er';
115 --echo "Dropping
event test.er on the master"
118 --echo "Checking
event status on the master"
119 SELECT db, name, status, originator FROM mysql.
event WHERE db = '
test';
123 sync_slave_with_master;
125 --echo "Checking
event status on the slave"
126 SELECT db, name, status, originator FROM mysql.
event WHERE db = 'test';
128 # test the DISABLE ON SLAVE for setting event SLAVESIDE_DISABLED as status
131 # Create an event on slave and check its status. An event shouldn't be executed
132 # so set start time in 1 hour.
134 --echo
"Creating event test.slave_terminate on the slave"
135 CREATE EVENT test.slave_terminate ON SCHEDULE EVERY 3 SECOND STARTS CURRENT_TIMESTAMP +
INTERVAL 1 HOUR DO
136 INSERT IGNORE INTO t1(
id, c) VALUES (6, 'from slave_terminate');
138 --echo "Checking
event status on the slave"
139 SELECT db, name, status, originator FROM mysql.
event WHERE db = 'test' AND name = 'slave_terminate';
141 --echo "Dropping
event test.slave_terminate on the slave"
142 DROP EVENT test.slave_terminate;
144 --echo "Creating
event test.slave_terminate with DISABLE ON SLAVE on the slave"
145 CREATE EVENT test.slave_terminate ON SCHEDULE EVERY 3 SECOND DISABLE ON SLAVE DO
146 INSERT IGNORE INTO t1(c) VALUES (7, 'from slave_terminate');
148 --echo "Checking
event status on the slave"
149 SELECT db, name, status, originator FROM mysql.
event WHERE db = 'test' AND name = 'slave_terminate';
151 --echo "Dropping
event test.slave_terminate on the slave"
152 DROP EVENT test.slave_terminate;
157 sync_slave_with_master;