~percona-toolkit-dev/percona-toolkit/fix-log-parser-writer-bug-963225

« back to all changes in this revision

Viewing changes to t/lib/BinaryLogParser.t

  • Committer: Daniel Nichter
  • Date: 2011-06-24 17:22:06 UTC
  • Revision ID: daniel@percona.com-20110624172206-c7q4s4ad6r260zz6
Add lib/, t/lib/, and sandbox/.  All modules are updated and passing on MySQL 5.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
BEGIN {
 
4
   die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
 
5
      unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
 
6
   unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
 
7
};
 
8
 
 
9
use strict;
 
10
use warnings FATAL => 'all';
 
11
use English qw(-no_match_vars);
 
12
use Test::More tests => 7;
 
13
 
 
14
use MaatkitTest;
 
15
use BinaryLogParser;
 
16
 
 
17
my $p = new BinaryLogParser();
 
18
 
 
19
my $oktorun = 1;
 
20
my $sample  = "t/lib/samples/binlogs/";
 
21
 
 
22
test_log_parser(
 
23
   parser  => $p,
 
24
   file    => $sample."binlog001.txt",
 
25
   oktorun => sub { $oktorun = $_[0]; },
 
26
   result  => [
 
27
  {
 
28
    '@@session.character_set_client' => '8',
 
29
    '@@session.collation_connection' => '8',
 
30
    '@@session.collation_server' => '8',
 
31
    '@@session.foreign_key_checks' => '1',
 
32
    '@@session.sql_auto_is_null' => '1',
 
33
    '@@session.sql_mode' => '0',
 
34
    '@@session.time_zone' => '\'system\'',
 
35
    '@@session.unique_checks' => '1',
 
36
    Query_time => '20664',
 
37
    Thread_id => '104168',
 
38
    arg => 'BEGIN',
 
39
    bytes => 5,
 
40
    cmd => 'Query',
 
41
    end_log_pos => '498006652',
 
42
    error_code => '0',
 
43
    offset => '498006722',
 
44
    pos_in_log => 146,
 
45
    server_id => '21',
 
46
    timestamp => '1197046970',
 
47
    ts => '071207 12:02:50'
 
48
  },
 
49
  {
 
50
    Query_time => '20675',
 
51
    Thread_id => '104168',
 
52
    arg => 'update test3.tblo as o
 
53
         inner join test3.tbl2 as e on o.animal = e.animal and o.oid = e.oid
 
54
      set e.tblo = o.tblo,
 
55
          e.col3 = o.col3
 
56
      where e.tblo is null',
 
57
    bytes => 179,
 
58
    cmd => 'Query',
 
59
    db => 'test1',
 
60
    end_log_pos => '278',
 
61
    error_code => '0',
 
62
    offset => '498006789',
 
63
    pos_in_log => 605,
 
64
    server_id => '21',
 
65
    timestamp => '1197046927',
 
66
    ts => '071207 12:02:07'
 
67
  },
 
68
  {
 
69
    Query_time => '20704',
 
70
    Thread_id => '104168',
 
71
    arg => 'replace into test4.tbl9(tbl5, day, todo, comment)
 
72
 select distinct o.tbl5, date(o.col3), \'misc\', right(\'foo\', 50)
 
73
      from test3.tblo as o
 
74
         inner join test3.tbl2 as e on o.animal = e.animal and o.oid = e.oid
 
75
      where e.tblo is not null
 
76
         and o.col1 > 0
 
77
         and o.tbl2 is null
 
78
         and o.col3 >= date_sub(current_date, interval 30 day)',
 
79
    bytes => 363,
 
80
    cmd => 'Query',
 
81
    end_log_pos => '836',
 
82
    error_code => '0',
 
83
    offset => '498007067',
 
84
    pos_in_log => 953,
 
85
    server_id => '21',
 
86
    timestamp => '1197046928',
 
87
    ts => '071207 12:02:08'
 
88
  },
 
89
  {
 
90
    Query_time => '20664',
 
91
    Thread_id => '104168',
 
92
    arg => 'update test3.tblo as o inner join test3.tbl2 as e
 
93
 on o.animal = e.animal and o.oid = e.oid
 
94
      set o.tbl2 = e.tbl2,
 
95
          e.col9 = now()
 
96
      where o.tbl2 is null',
 
97
    bytes => 170,
 
98
    cmd => 'Query',
 
99
    end_log_pos => '1161',
 
100
    error_code => '0',
 
101
    offset => '498007625',
 
102
    pos_in_log => 1469,
 
103
    server_id => '21',
 
104
    timestamp => '1197046970',
 
105
    ts => '071207 12:02:50'
 
106
  },
 
107
  {
 
108
    Xid => '4584956',
 
109
    arg => 'COMMIT',
 
110
    bytes => 6,
 
111
    cmd => 'Query',
 
112
    end_log_pos => '498007840',
 
113
    offset => '498007950',
 
114
    pos_in_log => 1793,
 
115
    server_id => '21',
 
116
    ts => '071207 12:02:50'
 
117
  },
 
118
  {
 
119
    Query_time => '20661',
 
120
    Thread_id => '103374',
 
121
    arg => 'insert into test1.tbl6
 
122
      (day, tbl5, misccol9type, misccol9, metric11, metric12, secs)
 
123
      values
 
124
      (convert_tz(current_timestamp,\'EST5EDT\',\'PST8PDT\'), \'239\', \'foo\', \'bar\', 1, \'1\', \'16.3574378490448\')
 
125
      on duplicate key update metric11 = metric11 + 1,
 
126
         metric12 = metric12 + values(metric12), secs = secs + values(secs)',
 
127
    bytes => 341,
 
128
    cmd => 'Query',
 
129
    end_log_pos => '417',
 
130
    error_code => '0',
 
131
    offset => '498007977',
 
132
    pos_in_log => 1889,
 
133
    server_id => '21',
 
134
    timestamp => '1197046973',
 
135
    ts => '071207 12:02:53'
 
136
  },
 
137
  {
 
138
    Xid => '4584964',
 
139
    arg => 'COMMIT',
 
140
    bytes => 6,
 
141
    cmd => 'Query',
 
142
    end_log_pos => '498008284',
 
143
    offset => '498008394',
 
144
    pos_in_log => 2383,
 
145
    server_id => '21',
 
146
    ts => '071207 12:02:53'
 
147
  },
 
148
  {
 
149
    Query_time => '20661',
 
150
    Thread_id => '103374',
 
151
    arg => 'update test2.tbl8
 
152
      set last2metric1 = last1metric1, last2time = last1time,
 
153
         last1metric1 = last0metric1, last1time = last0time,
 
154
         last0metric1 = ondeckmetric1, last0time = now()
 
155
      where tbl8 in (10800712)',
 
156
    bytes => 228,
 
157
    cmd => 'Query',
 
158
    end_log_pos => '314',
 
159
    error_code => '0',
 
160
    offset => '498008421',
 
161
    pos_in_log => 2479,
 
162
    server_id => '21',
 
163
    timestamp => '1197046973',
 
164
    ts => '071207 12:02:53'
 
165
  },
 
166
  {
 
167
    Xid => '4584965',
 
168
    arg => 'COMMIT',
 
169
    bytes => 6,
 
170
    cmd => 'Query',
 
171
    end_log_pos => '498008625',
 
172
    offset => '498008735',
 
173
    pos_in_log => 2860,
 
174
    server_id => '21',
 
175
    ts => '071207 12:02:53'
 
176
  },
 
177
  {
 
178
    arg => 'ROLLBACK /* added by mysqlbinlog */
 
179
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/',
 
180
    bytes => 87,
 
181
    cmd => 'Query',
 
182
    pos_in_log => 3066,
 
183
    ts => undef
 
184
  }
 
185
]
 
186
);
 
187
 
 
188
is(
 
189
   $oktorun,
 
190
   0,
 
191
   'Sets oktorun'
 
192
);
 
193
 
 
194
test_log_parser(
 
195
   parser => $p,
 
196
   file   => $sample."binlog002.txt",
 
197
   result => [
 
198
  {
 
199
    arg => 'ROLLBACK',
 
200
    bytes => 8,
 
201
    cmd => 'Query',
 
202
    end_log_pos => '98',
 
203
    offset => '4',
 
204
    pos_in_log => 146,
 
205
    server_id => '12345',
 
206
    ts => '090722  7:21:41'
 
207
  },
 
208
  {
 
209
    '@@session.character_set_client' => '8',
 
210
    '@@session.collation_connection' => '8',
 
211
    '@@session.collation_server' => '8',
 
212
    '@@session.foreign_key_checks' => '1',
 
213
    '@@session.sql_auto_is_null' => '1',
 
214
    '@@session.sql_mode' => '0',
 
215
    '@@session.unique_checks' => '1',
 
216
    Query_time => '0',
 
217
    Thread_id => '3',
 
218
    arg => 'create database d',
 
219
    bytes => 17,
 
220
    cmd => 'Query',
 
221
    end_log_pos => '175',
 
222
    error_code => '0',
 
223
    offset => '98',
 
224
    pos_in_log => 381,
 
225
    server_id => '12345',
 
226
    timestamp => '1248268919',
 
227
    ts => '090722  7:21:59'
 
228
  },
 
229
  {
 
230
    Query_time => '0',
 
231
    Thread_id => '3',
 
232
    arg => 'create table foo (i int)',
 
233
    bytes => 24,
 
234
    cmd => 'Query',
 
235
    db => 'd',
 
236
    end_log_pos => '259',
 
237
    error_code => '0',
 
238
    offset => '175',
 
239
    pos_in_log => 795,
 
240
    server_id => '12345',
 
241
    timestamp => '1248268936',
 
242
    ts => '090722  7:22:16'
 
243
  },
 
244
  {
 
245
    Query_time => '0',
 
246
    Thread_id => '3',
 
247
    arg => 'insert foo values (1),(2)',
 
248
    bytes => 25,
 
249
    cmd => 'Query',
 
250
    end_log_pos => '344',
 
251
    error_code => '0',
 
252
    offset => '259',
 
253
    pos_in_log => 973,
 
254
    server_id => '12345',
 
255
    timestamp => '1248268944',
 
256
    ts => '090722  7:22:24'
 
257
  },
 
258
  {
 
259
    arg => 'ROLLBACK /* added by mysqlbinlog */
 
260
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/',
 
261
    bytes => 87,
 
262
    cmd => 'Query',
 
263
    pos_in_log => 1152,
 
264
    ts => undef
 
265
  }
 
266
   ]
 
267
);
 
268
 
 
269
# #############################################################################
 
270
# Issue 606: Unknown event type Rotate at ./mk-slave-prefetch
 
271
# #############################################################################
 
272
test_log_parser(
 
273
   parser => $p,
 
274
   file   => $sample."binlog006.txt",
 
275
   result => [],
 
276
);
 
277
 
 
278
# #############################################################################
 
279
# Done.
 
280
# #############################################################################
 
281
exit;