2
# ###########################################################################
3
# First we check the log file itself: that it can be enabled and disabled,
4
# that the plugin only writes to it when enabled, and that it can be changed
5
# both when disabled (and then re-enabled) and changed when enabled (close
6
# old log file, open and write to new log file).
7
# ###########################################################################
9
# The query_log plugin is enabled by default, but query_log_file_enabled is
10
# disabled by default, so the plugin should not have opened/created the log
12
--exec if [ -f $DRIZZLETEST_VARDIR/query.log ]; then echo "Log file exists"; else echo "Log file does not exist"; fi
14
# Does the plugin crash Drizzle on startup? Hopefully not.
15
# Is it actually plugged in? It should be.
16
# Can we still exec queries without crashing Drizzle? Let's hope so.
18
select * from data_dictionary.plugins join data_dictionary.modules on plugins.plugin_name=modules.module_name where plugin_name='query_log';
21
# When the query_log plugin is added, it's enabled by default, but all its
22
# destinations (currently it has just one: file) are disabled. So this should
24
SELECT @@query_log_enabled, @@query_log_file_enabled;
26
# This query should not be logged because, although the plugin is enabled,
27
# the query log file is disabled.
30
# Enable the query log file. The first query logged is the SET. The sed
31
# command changes all numbers to zeros because most the value are variable:
32
# timestamps, execution times, etc.
33
SET GLOBAL query_log_file_enabled=TRUE;
34
SELECT @@query_log_enabled, @@query_log_file_enabled;
35
--exec $TOP_SRCDIR/plugin/query_log/tests/zero-query-log-values.sh $DRIZZLETEST_VARDIR/query.log
36
--cat_file $DRIZZLETEST_VARDIR/query.log
38
# Disable the query_log plugin globally, i.e. the master switch. Neither of
39
# these three queries should show in the log; so the log will be identical to
40
# before being disabled.
41
SET GLOBAL query_log_enabled=FALSE;
42
SELECT @@query_log_enabled, @@query_log_file_enabled;
44
--exec $TOP_SRCDIR/plugin/query_log/tests/zero-query-log-values.sh $DRIZZLETEST_VARDIR/query.log
45
--cat_file $DRIZZLETEST_VARDIR/query.log
47
# Disable and change the qury log file. The plugin should not actually open
48
# the new file until query_log_file_enabled is true again, so the second SELECT
49
# should should the new log file for @@query_log_file but the exec should
50
# show that the file doesn't exist yet.
51
SET GLOBAL query_log_file_enabled=FALSE;
52
SELECT @@query_log_enabled, @@query_log_file_enabled;
53
--replace_result $DRIZZLETEST_VARDIR DRIZZLETEST_VARDIR
54
eval SET GLOBAL query_log_file="$DRIZZLETEST_VARDIR/query-2.log";
55
--replace_result $DRIZZLETEST_VARDIR DRIZZLETEST_VARDIR
56
SELECT @@query_log_enabled, @@query_log_file_enabled, @@query_log_file;
57
--exec if [ -f $DRIZZLETEST_VARDIR/query-2.log ]; then echo "Log file exists"; else echo "Log file does not exist"; fi
59
# Now enable the log file again and it should contain just the second SET and
61
SET GLOBAL query_log_enabled=TRUE;
62
SET GLOBAL query_log_file_enabled=TRUE;
63
SELECT 'this is the second log file';
64
--exec if [ -f $DRIZZLETEST_VARDIR/query-2.log ]; then echo "Log file exists"; else echo "Log file does not exist"; fi
65
--exec $TOP_SRCDIR/plugin/query_log/tests/zero-query-log-values.sh $DRIZZLETEST_VARDIR/query-2.log
66
--cat_file $DRIZZLETEST_VARDIR/query-2.log
68
# Finally, change the log file while it's enabled.
69
--replace_result $DRIZZLETEST_VARDIR DRIZZLETEST_VARDIR
70
eval SET GLOBAL query_log_file="$DRIZZLETEST_VARDIR/query-3.log";
71
--replace_result $DRIZZLETEST_VARDIR DRIZZLETEST_VARDIR
72
SELECT @@query_log_enabled, @@query_log_file_enabled, @@query_log_file;
73
--exec if [ -f $DRIZZLETEST_VARDIR/query-2.log ]; then echo "Log file exists"; else echo "Log file does not exist"; fi
74
SELECT 'this is the third log file';
75
--exec $TOP_SRCDIR/plugin/query_log/tests/zero-query-log-values.sh $DRIZZLETEST_VARDIR/query-3.log
76
--system sed -e 's/".*"/"third-log-file"/' -i.bak $DRIZZLETEST_VARDIR/query-3.log
77
--cat_file $DRIZZLETEST_VARDIR/query-3.log
79
# And just to be sure, let's cat the previous logs to make sure they don't
80
# have any queries that they shouldn't have.
81
--exec $TOP_SRCDIR/plugin/query_log/tests/zero-query-log-values.sh $DRIZZLETEST_VARDIR/query.log
82
--cat_file $DRIZZLETEST_VARDIR/query.log
83
--exec $TOP_SRCDIR/plugin/query_log/tests/zero-query-log-values.sh $DRIZZLETEST_VARDIR/query-2.log
84
--cat_file $DRIZZLETEST_VARDIR/query-2.log
86
# Done. Cleanup for other tests.
87
--replace_result $DRIZZLETEST_VARDIR DRIZZLETEST_VARDIR
88
eval SET GLOBAL query_log_file="$DRIZZLETEST_VARDIR/query.log";
89
--remove_file $DRIZZLETEST_VARDIR/query-2.log
90
--remove_file $DRIZZLETEST_VARDIR/query-3.log
92
# ###########################################################################
93
# Now check that the logged values are correct.
94
# ###########################################################################
96
# Clear previous events from the log.
97
--exec echo "" > $DRIZZLETEST_VARDIR/query.log
99
# The first line of an event should be an ISO timestamp like
100
# YYYY-MM-DDTHH:MM:SS.uuuuuu. We just check that the start of the ts
101
# matches today's date.
102
let $today= `SELECT DATE(NOW())`;
103
--exec $TOP_SRCDIR/plugin/query_log/tests/check-query-log-attribute.pl $DRIZZLETEST_VARDIR/query.log ts matches "^$today"
105
# The 3rd line of an event should be microsecond times like 1.123456
106
--exec $TOP_SRCDIR/plugin/query_log/tests/check-query-log-attribute.pl $DRIZZLETEST_VARDIR/query.log execution_time,lock_time,session_time matches '\d\.\d{6}','\d\.\d{6}','\d\.\d{6}'
108
# The 2nd line (rows_examined, etc.) are ints, error on the 4th line is bool,
109
# and schema on the 5th line is a double-quoted string.
110
--exec $TOP_SRCDIR/plugin/query_log/tests/check-query-log-attribute.pl $DRIZZLETEST_VARDIR/query.log rows_examined,tmp_tables,warnings,error,schema equals 0,0,0,false,test
112
# Test that execution_time is accurate: if we sleep for 0.5s, execution time
113
# should be at least 0.50 and probably a few microseconds longer.
115
--exec $TOP_SRCDIR/plugin/query_log/tests/check-query-log-attribute.pl $DRIZZLETEST_VARDIR/query.log execution_time between 0.5 0.59
117
# ############################################################################
118
# Clean up. Tests must be idempotent and not leave behind a trace, so
119
# dtr --repeat-test 2 --suite query_log must pass.
120
# ############################################################################
121
SET GLOBAL query_log_enabled=TRUE;
122
SET GLOBAL query_log_file_enabled=FALSE;
124
--exec rm $DRIZZLETEST_VARDIR/query*.log
125
--exec rm $DRIZZLETEST_VARDIR/*.bak
127
# ###########################################################################
129
# ###########################################################################