# ==== Purpose ====
#
# Test that the sync chain generated by
# include/rpl_change_topology.inc (sourced from include/rpl_init.inc)
# is correct.
#
# We test a number of different topologies.  Each topology is tested
# in extra/rpl_tests/rpl_test_framework.inc.  See
# extra/rpl_tests/rpl_test_framework.inc for details on how the sync
# chain is tested.
#
# ==== Related bugs ====
#
# BUG#49978: Replication tests don't clean up replication state at the end


# We only need to execute this test once. Also, we rely on 'DELETE
# FROM t1' to remove rows in slave tables that don't exist in master
# tables (see include/rpl_test_framework.inc for details).
--source include/have_binlog_format_statement.inc


--echo ==== Create t1 on all servers. ====
if ($mtr_supports_more_than_10_servers)
{
  --let $rpl_server_count= 15
  --let $rpl_topology= 1->2->3->4->5->6->7->8->9->10->11->12->13->14->15
}
if (!$mtr_supports_more_than_10_servers)
{
  --let $rpl_server_count= 9
  --let $rpl_topology= 1->2->3->4->5->6->7->8->9
}
--source include/rpl_init.inc
CREATE TABLE t1 (a INT);
--source include/rpl_end.inc

# Initialize $next_number before first call to
# extra/rpl_tests/rpl_test_framework.text
--let $next_number= 0


--echo ==== Test 3-server topologies ====

--let $rpl_server_count= 3

--let $rpl_topology= 1 -> 2
--let $masters= 1,3
--source extra/rpl_tests/rpl_test_framework.inc

--let $rpl_topology= 2 -> 3
--let $masters= 1,2
--source extra/rpl_tests/rpl_test_framework.inc

--let $rpl_topology= none
--let $masters= 1,2,3
--source extra/rpl_tests/rpl_test_framework.inc

--let $rpl_topology= 1->2, 2->1
--let $masters= 1,3
--source extra/rpl_tests/rpl_test_framework.inc

--let $rpl_topology= 1->2->1
--let $masters= 2,3
--source extra/rpl_tests/rpl_test_framework.inc

--let $rpl_topology= 2->1->2
--let $masters= 1,3
--source extra/rpl_tests/rpl_test_framework.inc

--let $rpl_topology= 1->2->3
--let $masters= 1
--source extra/rpl_tests/rpl_test_framework.inc

--let $rpl_topology= 2->3->2->1
--let $masters= 3
--source extra/rpl_tests/rpl_test_framework.inc

--let $rpl_topology= 1->2,2->3,3->1
--let $masters= 3
--source extra/rpl_tests/rpl_test_framework.inc

--let $rpl_topology= 1->3->2->1
--let $masters= 3
--source extra/rpl_tests/rpl_test_framework.inc


--echo ==== Test 6-server topologies ====

--let $rpl_server_count= 6

--let $rpl_topology= 1->2->3->4->1->5->6
--let $masters= 1
--source extra/rpl_tests/rpl_test_framework.inc

--let $rpl_topology= 3->4->5->6->3->1->2
--let $masters= 4
--source extra/rpl_tests/rpl_test_framework.inc

--let $rpl_topology= 6->5->4->3->2->1
--let $masters= 6
--source extra/rpl_tests/rpl_test_framework.inc

--let $rpl_topology= 1->2->3->1,4->5->6
--let $masters= 3,4
--source extra/rpl_tests/rpl_test_framework.inc


--echo ==== Test 9-server topology ====

--let $rpl_server_count= 9

--let $rpl_topology= 1->2, 2->3, 3->4, 4->5, 5->1, 1->6, 6->7, 6->8, 8->9
--let $masters= 2
--source extra/rpl_tests/rpl_test_framework.inc

if ($mtr_supports_more_than_10_servers) {
--echo ==== Test 15-server topologies ====

--let $rpl_server_count= 15

--let $rpl_topology= 1->2->3->4->5->6->7->8->9->10->11->12->13->14->15->1
--let $masters= 2
--source extra/rpl_tests/rpl_test_framework.inc

# This is a binary tree
--let $rpl_topology= 1->2->4->8,1->3->6->12,2->5->10,3->7->14,4->9,5->11,6->13,7->15
--let $masters= 1
--source extra/rpl_tests/rpl_test_framework.inc
}

--echo ==== Clean up ====

if ($mtr_supports_more_than_10_servers) {
  --let $rpl_topology= 1->2->3->4->5->6->7->8->9->10->11->12->13->14->15
}
if (!$mtr_supports_more_than_10_servers) {
  --let $rpl_topology= 1->2->3->4->5->6->7->8->9
}
--source include/rpl_init.inc
--connection server_1
DROP TABLE t1;
--source include/rpl_end.inc
