~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
#
2
# Test behavior of various per-account limits (aka quotas)
3
#
4
5
# Requires privileges to be enabled
6
7
# Prepare play-ground 
8
--disable_warnings
9
drop table if exists t1;
10
--enable_warnings
11
create table t1 (i int);
12
# Just be sure that nothing will bother us
13
delete from mysql.user where user like 'mysqltest\_%';
14
delete from mysql.db where user like 'mysqltest\_%';
15
delete from mysql.tables_priv where user like 'mysqltest\_%';
16
delete from mysql.columns_priv where user like 'mysqltest\_%';
17
flush privileges;
18
19
# Limits doesn't work with prepared statements (yet)
20
--disable_ps_protocol
21
22
# Test of MAX_QUERIES_PER_HOUR limit
23
grant usage on *.* to mysqltest_1@localhost with max_queries_per_hour 2;
24
# This ensures that counters are reset and makes test scheduling independent
25
flush user_resources;
26
connect (mqph, localhost, mysqltest_1,,);
27
connection mqph;
28
select * from t1;
29
select * from t1;
30
--error 1226
31
select * from t1;
32
connect (mqph2, localhost, mysqltest_1,,);
33
connection mqph2;
34
--error 1226
35
select * from t1;
36
# cleanup
37
connection default;
38
drop user mysqltest_1@localhost;
39
disconnect mqph;
40
disconnect mqph2;
41
42
# Test of MAX_UPDATES_PER_HOUR limit
43
grant usage on *.* to mysqltest_1@localhost with max_updates_per_hour 2;
44
flush user_resources;
45
connect (muph, localhost, mysqltest_1,,);
46
connection muph;
47
select * from t1;
48
select * from t1;
49
select * from t1;
50
delete from t1;
51
delete from t1;
52
--error 1226
53
delete from t1;
54
select * from t1;
55
connect (muph2, localhost, mysqltest_1,,);
56
connection muph2;
57
--error 1226
58
delete from t1;
59
select * from t1;
60
# Cleanup
61
connection default;
62
drop user mysqltest_1@localhost;
63
disconnect muph;
64
disconnect muph2;
65
66
# Test of MAX_CONNECTIONS_PER_HOUR limit
67
grant usage on *.* to mysqltest_1@localhost with max_connections_per_hour 2;
68
flush user_resources;
69
connect (mcph1, localhost, mysqltest_1,,);
70
connection mcph1;
71
select * from t1;
72
connect (mcph2, localhost, mysqltest_1,,);
73
connection mcph2;
74
select * from t1;
75
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
76
--error 1226
77
connect (mcph3, localhost, mysqltest_1,,);
78
# Old connection is still ok
79
select * from t1;
80
# Let us try to close old connections and try again. This will also test that
81
# counters are not thrown away if there are no connections for this user.
82
disconnect mcph1;
83
disconnect mcph2;
84
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
85
--error 1226
86
connect (mcph3, localhost, mysqltest_1,,);
87
# Cleanup
88
connection default;
89
drop user mysqltest_1@localhost;
90
91
# Test of MAX_USER_CONNECTIONS limit
92
# We need this to reset internal mqh_used variable
93
flush privileges;
94
grant usage on *.* to mysqltest_1@localhost with max_user_connections 2;
95
flush user_resources;
96
connect (muc1, localhost, mysqltest_1,,);
97
connection muc1;
98
select * from t1;
99
connect (muc2, localhost, mysqltest_1,,);
100
connection muc2;
101
select * from t1;
102
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
103
--error 1226
104
connect (muc3, localhost, mysqltest_1,,);
105
# Closing of one of connections should help
106
disconnect muc1;
107
connect (muc3, localhost, mysqltest_1,,);
108
select * from t1;
109
# Changing of limit should also help (and immediately) 
110
connection default;
111
grant usage on *.* to mysqltest_1@localhost with max_user_connections 3;
112
flush user_resources;
113
connect (muc4, localhost, mysqltest_1,,);
114
connection muc4;
115
select * from t1;
116
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
117
--error 1226
118
connect (muc5, localhost, mysqltest_1,,);
119
# Clean up
120
connection default;
121
disconnect muc2;
122
disconnect muc3;
123
disconnect muc4;
124
drop user mysqltest_1@localhost;
125
126
# Now let us test interaction between global and per-account
127
# max_user_connections limits
128
select @@session.max_user_connections, @@global.max_user_connections;
129
# Local max_user_connections variable can't be set directly
130
# since this limit is per-account
131
--error 1229
132
set session max_user_connections= 2; 
133
# But it is ok to set global max_user_connections
134
set global max_user_connections= 2; 
135
select @@session.max_user_connections, @@global.max_user_connections;
136
# Let us check that global limit works
137
grant usage on *.* to mysqltest_1@localhost;
138
flush user_resources;
139
connect (muca1, localhost, mysqltest_1,,);
140
connection muca1;
141
select @@session.max_user_connections, @@global.max_user_connections;
142
connect (muca2, localhost, mysqltest_1,,);
143
connection muca2;
144
select * from t1;
145
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
146
--error 1203
147
connect (muca3, localhost, mysqltest_1,,);
148
# Now we are testing that per-account limit prevails over gloabl limit
149
connection default;
150
grant usage on *.* to mysqltest_1@localhost with max_user_connections 3;
151
flush user_resources;
152
connect (muca3, localhost, mysqltest_1,,);
153
connection muca3;
154
select @@session.max_user_connections, @@global.max_user_connections;
155
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
156
--error 1226
157
connect (muca4, localhost, mysqltest_1,,);
158
# Cleanup
159
connection default;
160
disconnect muca1;
161
disconnect muca2;
162
disconnect muca3;
163
set global max_user_connections= 0; 
164
drop user mysqltest_1@localhost;
165
--enable_ps_protocol
166
167
# Final cleanup
168
drop table t1;