################################################################################
# rpl_semi_sync_master
#
# It is a global variable only and can be set dynamically.
# It has ENUM type and only accepts 'AFTER_COMMIT' and 'AFTER_SYNC' two values.
#
# This test verifies the variable can be set, selected and showed correctly.
################################################################################
source include/have_semisync_plugin.inc;

--echo #
--echo # Initialization
--echo #
# The following is to prevent a mis-match on windows that has the name of the
# lib ending with 'dll'
--replace_regex /\.dll/.so/
eval INSTALL PLUGIN rpl_semi_sync_master SONAME '$SEMISYNC_MASTER_PLUGIN';

--echo #
--echo # Verify it can set selected and showed correctly
--echo #
SELECT @@GLOBAL.rpl_semi_sync_master_wait_point;

SHOW GLOBAL VARIABLES LIKE 'rpl_semi_sync_master_wait_point';

--disable_warnings
SELECT * FROM performance_schema.global_variables WHERE
  VARIABLE_NAME = 'rpl_semi_sync_master_wait_point';
--enable_warnings

--echo #
--echo # Verify it is not a session variable
--echo #
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
SELECT @@SESSION.rpl_semi_sync_master_wait_point;

SHOW SESSION VARIABLES LIKE 'rpl_semi_sync_master_wait_point';

--disable_warnings
SELECT * FROM performance_schema.session_variables WHERE
  VARIABLE_NAME ='rpl_semi_sync_master_wait_point';
--enable_warnings

--echo #
--echo # Verify it can be set correctly
--echo #
SET GLOBAL rpl_semi_sync_master_wait_point = AFTER_COMMIT;
SELECT @@GLOBAL.rpl_semi_sync_master_wait_point;

SET GLOBAL rpl_semi_sync_master_wait_point = AFTER_SYNC;
SELECT @@GLOBAL.rpl_semi_sync_master_wait_point;

# 1 is same to AFTER_COMMIT
SET GLOBAL rpl_semi_sync_master_wait_point = 1;
SELECT @@GLOBAL.rpl_semi_sync_master_wait_point;

# 0 is same to AFTER_SYNC
SET GLOBAL rpl_semi_sync_master_wait_point = 0;
SELECT @@GLOBAL.rpl_semi_sync_master_wait_point;

--error ER_GLOBAL_VARIABLE
SET SESSION rpl_semi_sync_master_wait_point = AFTER_COMMIT;
SHOW SESSION VARIABLES LIKE 'rpl_semi_sync_master_wait_point';

--echo #
--echo # Verify it could not bet set with invalid values
--echo #
--error ER_WRONG_VALUE_FOR_VAR
SET GLOBAL rpl_semi_sync_master_wait_point = 2;

--error ER_WRONG_VALUE_FOR_VAR
SET GLOBAL rpl_semi_sync_master_wait_point = blabla;

--error ER_WRONG_VALUE_FOR_VAR
SET GLOBAL rpl_semi_sync_master_wait_point = "blabla";

--error ER_WRONG_VALUE_FOR_VAR
SET GLOBAL rpl_semi_sync_master_wait_point = "";

--error ER_WRONG_VALUE_FOR_VAR
SET GLOBAL rpl_semi_sync_master_wait_point = NULL;

--error ER_WRONG_TYPE_FOR_VAR
SET GLOBAL rpl_semi_sync_master_wait_point = 0.1;

--echo #
--echo # Cleanup
--echo #
UNINSTALL PLUGIN rpl_semi_sync_master;

