###############################################################################
# Bug #20436436  NEW->OLD ASSERT FAILURE `GTID_MODE > 0' IN 5.6.24 AT LOG_EVENT.CC:13555
#
# The problem is caused when slave sql thread is applying an
# anonymous_gtid log events on mysql 5.6, since the
# anonymous_gtid log event can be generated on mysql 5.7 after
# wl#7592 when gtid_mode is OFF or OFF_PERMISSVE. So the
# NEW->OLD replication is broken.
#
# On mysql 5.6, the slave sql thread should report an error and abort
# when applying the anonymous_gtid log event if gtid_mode is ON.
#
# Steps to Reproduce:
#  1) Stop slave threads and clear slave datadir.
#  2) Copy the binlog with Anonymous_GTID log events and
#     relay log index to slave datadir.
#  3) Process the binlog with Anonymous_GTID log events
#     and wait for SQL thread error.
###############################################################################

--source include/have_gtid.inc
# We did not run the test with MTS, since the slave sql error
# 'ER_CANT_SET_GTID_NEXT_TO_GTID_WHEN_GTID_MODE_IS_OFF' is
# overwritten by 'ER_MTS_INCONSISTENT_DATA' in MTS.
--source include/not_mts_slave_parallel_workers.inc
--source include/have_binlog_format_statement.inc
--source include/master-slave.inc

--source include/rpl_connection_slave.inc
--let $MYSQLD_SLAVE_DATADIR= `select @@datadir`

--echo #
--echo # Stop slave threads and clear slave datadir.
--echo #
--source include/stop_slave.inc
RESET SLAVE;
--remove_file $MYSQLD_SLAVE_DATADIR/slave-relay-bin.000001
--remove_file $MYSQLD_SLAVE_DATADIR/slave-relay-bin.index

--echo #
--echo # Copy the binlog with Anonymous_GTID log events and
--echo # relay log index to slave datadir.
--echo #
# On Win* platforms path separator is backslash.
if (`SELECT CONVERT(@@VERSION_COMPILE_OS USING latin1) IN ('Win32', 'Win64', 'Windows')`)
{
  --copy_file std_data/slave-relay-bin_win.index $MYSQLD_SLAVE_DATADIR/slave-relay-bin.index
}
if (`SELECT CONVERT(@@VERSION_COMPILE_OS USING latin1) NOT IN ('Win32', 'Win64', 'Windows')`)
{
  --copy_file std_data/slave-relay-bin_linux.index $MYSQLD_SLAVE_DATADIR/slave-relay-bin.index
}
--copy_file std_data/binlog_transaction_with_anonymous_GTID.000001 $MYSQLD_SLAVE_DATADIR/slave-relay-bin.000001

--echo #
--echo # Process the binlog with Anonymous_GTID log events.
--echo #
START SLAVE;
--echo #
--echo # Wait for SQL thread error.
--echo #
call mtr.add_suppression("Slave.* @@SESSION.GTID_NEXT cannot be set to ANONYMOUS when @@GLOBAL.GTID_MODE = ON.");
--let $slave_sql_errno= convert_error(ER_CANT_SET_GTID_NEXT_TO_ANONYMOUS_WHEN_GTID_MODE_IS_ON)
--source include/wait_for_slave_sql_error.inc

# Reset slave.
--source include/stop_slave.inc
RESET MASTER;
RESET SLAVE;
--source include/start_slave.inc

# Cleanup
--source include/rpl_connection_master.inc
--source include/rpl_end.inc
