--source include/have_profiling.inc
--source include/not_embedded.inc
--source include/have_validate_password_plugin.inc

# Warning is generated when default file (NULL) is used
CALL mtr.add_suppression("Dictionary file not specified");

--echo #
--echo # Tests for deprecation warnings introduced by wl#6443
--echo #

--echo # System variables

select @@global.max_tmp_tables;
select @@local.max_tmp_tables;
set @default_max_tmp_tables= @@global.max_tmp_tables;
select @@global.date_format;
select @@global.time_format;
select @@global.datetime_format;
set @@global.max_tmp_tables= 64;
set @@global.max_tmp_tables= @@global.max_tmp_tables;
set @@global.max_tmp_tables= @default_max_tmp_tables;
select @@global.profiling;
select @@local.profiling;
select @@global.profiling_history_size;
select @@local.profiling_history_size;
select @@global.have_profiling;
set @@local.profiling= @@global.profiling;
set @@local.profiling_history_size= @@global.profiling_history_size;
set @wl6443_have_profiling= @@global.have_profiling;

--echo # SHOW PROFILE and SHOW PROFILES

SHOW PROFILE;
SHOW PROFILE ALL;
SHOW PROFILE IPC;
SHOW PROFILES;

--echo # --plugin-xyz

--replace_regex /\.dll/.so/
eval INSTALL PLUGIN validate_password SONAME '$VALIDATE_PASSWORD';

--echo # restarting the server

# Write file to make mysql-test-run.pl wait for the server to stop
--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect

# Request shutdown
-- send_shutdown

# Call script that will poll the server waiting for it to disapear
-- source include/wait_until_disconnected.inc

--echo # Restart server.

--exec echo "restart:--plugin-validate-password-length=8" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect

# Turn on reconnect
--enable_reconnect

# Call script that will poll the server waiting for it to be back online again
--source include/wait_until_connected_again.inc

# Turn off reconnect again
--disable_reconnect

UNINSTALL PLUGIN validate_password;

--echo # Search for deprecation warnings in error log.
--echo # YMMDD HH:MM:SS [Warning] The syntax 'plugin-validate-password-length' is deprecated and will be removed in a future release. Please use validate-password-length instead.
--let $log_file= $MYSQLTEST_VARDIR/log/mysqld.1.err
--let LOGF= $log_file

perl;
  use strict;
  my $logf= $ENV{'LOGF'} or die "LOGF not set";
  open(FILE, "$logf") or die("Unable to open $logf: $!\n");
  my $count_warnings= grep(/\[Warning\] The syntax 'plugin-validate-password-length' is deprecated and will be removed in a future release\. Please use validate-password-length instead\./gi,<FILE>);
  my $count_warnings= $count_warnings;
  print "Deprecation warning count : $count_warnings\n";
  close(FILE);
EOF

-- source include/mysql_upgrade_preparation.inc

--echo # Host table deprecation
select count(*) from information_schema.tables where table_name like 'host' and table_schema like 'mysql' and table_type like 'BASE TABLE';

create table mysql.host(c1 int) engine MyISAM;
insert into mysql.host values(1);

--exec $MYSQL_UPGRADE --skip-verbose 2>&1
# It should have created a file in the MySQL Servers datadir
let $MYSQLD_DATADIR= `select @@datadir`;
file_exists $MYSQLD_DATADIR/mysql_upgrade_info;

drop table mysql.host;
create view mysql.host as select HOST from mysql.db;
create user 'wl6443_u1'@'10.10.10.1' identified by 'sql';
select count(*) from mysql.host;

--exec $MYSQL_UPGRADE --skip-verbose --force 2>&1
# It should have created a file in the MySQL Servers datadir
file_exists $MYSQLD_DATADIR/mysql_upgrade_info;

# Clean Up
drop view mysql.host;
drop user 'wl6443_u1'@'10.10.10.1';

--exec $MYSQL_UPGRADE --skip-verbose --force 2>&1
# It should have created a file in the MySQL Servers datadir
file_exists $MYSQLD_DATADIR/mysql_upgrade_info;
