flydata 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 83cb9df24d4fe0b983b20bfd30d1798aa4cbecdd
4
- data.tar.gz: a00a24a84acf688553503bf97b156acdd57fc8ab
3
+ metadata.gz: 281fa8038b28cccba7e12b76d72a5bab7af9d10b
4
+ data.tar.gz: 78895abe8bc0f92c7835ec9b0f7093e727a8b71f
5
5
  SHA512:
6
- metadata.gz: 335e28547f000af29cf5df8d7a28632fe8fa5356298016f80819622c2a8299ae8469aa46a4e2ec8aa6179c472d151ea90583da1a7ab5f9367aec7668200c9ebc
7
- data.tar.gz: 78049be459795e1eccb4b486c55e74989b8f2fae7cce9e5a8ce79236a12ad54d990550b30e71f9027e3ff299598d9f586a63fff8911ae159c6c0935f95e2bfeb
6
+ metadata.gz: d87649be6f3f5480fd1529e71a879c8b556f8a9d01aba06117d4a305883ae2734ca94e26d586d281af4aeda8bc2ac14e34e9064c1093bcae4a634559ddceebaf
7
+ data.tar.gz: bdba9b5af4a27d8129d2b8a7ff454de83daa2f6c09219a6a2d8bca09766fc86f473cd773a8575b2a52f65d3a23f6b27cbec057cb59ad3b454f5037c106be7ce4
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.4.2
data/flydata.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: flydata 0.4.1 ruby lib
5
+ # stub: flydata 0.4.2 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "flydata"
9
- s.version = "0.4.1"
9
+ s.version = "0.4.2"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Koichi Fujikawa", "Masashi Miyazaki", "Matthew Luu", "Mak Inada", "Sriram NS"]
14
- s.date = "2015-06-19"
14
+ s.date = "2015-06-23"
15
15
  s.description = "FlyData Agent"
16
16
  s.email = "sysadmin@flydata.com"
17
17
  s.executables = ["fdmysqldump", "flydata", "serverinfo"]
@@ -3,7 +3,7 @@ require 'flydata/fluent-plugins/mysql/ddl_query_handler'
3
3
 
4
4
  module Mysql
5
5
  class TruncateTableQueryHandler < DdlQueryHandler
6
- PATTERN = /^TRUNCATE TABLE/i
6
+ PATTERN = /^TRUNCATE/i
7
7
 
8
8
  def initialize(context)
9
9
  super
@@ -51,12 +51,12 @@ EOT
51
51
  end
52
52
  let(:alter_query_handler) do
53
53
  r = double('alter_query_handler')
54
- allow(r).to receive(:pattern).and_return(/^ALTER TABLE/i)
54
+ allow(r).to receive(:pattern).and_return(Mysql::AlterTableQueryHandler::PATTERN)
55
55
  r
56
56
  end
57
57
  let(:truncate_query_handler) do
58
58
  r = double('truncate_query_handler')
59
- allow(r).to receive(:pattern).and_return(/^TRUNCATE TABLE/i)
59
+ allow(r).to receive(:pattern).and_return(Mysql::TruncateTableQueryHandler::PATTERN)
60
60
  r
61
61
  end
62
62
  let(:context) { double('context') }
@@ -201,36 +201,48 @@ EOS
201
201
  context "truncate table queries" do
202
202
  let(:correct_query_handler) { truncate_query_handler }
203
203
 
204
- context "simple truncate query" do
205
- let(:query) { <<EOS.gsub(/\n$/, '') }
206
- TRUNCATE table users;
204
+ shared_examples "truncate table tests" do
205
+ context "simple truncate query" do
206
+ let(:query) { <<EOS.gsub(/\n$/, '') }
207
+ TRUNCATE#{opt_table} users;
207
208
  EOS
208
- let(:normalized_query) { <<EOS.gsub(/\n$/, '') }
209
- TRUNCATE table users;
209
+ let(:normalized_query) { <<EOS.gsub(/\n$/, '') }
210
+ TRUNCATE#{opt_table} users;
210
211
  EOS
211
212
 
212
- it_behaves_like "a dispatcher that calls query handler with correct query"
213
- end
214
- context "truncate query with dbname and table name and a comment in the beginning" do
215
- let(:query) { <<EOS.gsub(/\n$/, '') }
213
+ it_behaves_like "a dispatcher that calls query handler with correct query"
214
+ end
215
+ context "truncate query with dbname and table name and a comment in the beginning" do
216
+ let(:query) { <<EOS.gsub(/\n$/, '') }
216
217
  # I am going to truncate this table
217
- truncate table flydata_sync.users;
218
+ truncate#{opt_table} flydata_sync.users;
218
219
  EOS
219
- let(:normalized_query) { <<EOS.gsub(/\n$/, '') }
220
- truncate table flydata_sync.users;
220
+ let(:normalized_query) { <<EOS.gsub(/\n$/, '') }
221
+ truncate#{opt_table} flydata_sync.users;
221
222
  EOS
222
223
 
223
- it_behaves_like "a dispatcher that calls query handler with correct query"
224
- end
225
- context "truncate query with quoted dbname and table name with comments on the same line" do
226
- let(:query) { <<EOS.gsub(/\n$/, '') }
227
- truncate table `flydata_sync`.`users`; /* 無国籍 */ -- 'SJIS is トラブルメーカー'
224
+ it_behaves_like "a dispatcher that calls query handler with correct query"
225
+ end
226
+ context "truncate query with quoted dbname and table name with comments on the same line" do
227
+ let(:query) { <<EOS.gsub(/\n$/, '') }
228
+ truncate#{opt_table} `flydata_sync`.`users`; /* 無国籍 */ -- 'SJIS is トラブルメーカー'
228
229
  EOS
229
- let(:normalized_query) { <<EOS.gsub(/\n$/, '') }
230
- truncate table `flydata_sync`.`users`;
230
+ let(:normalized_query) { <<EOS.gsub(/\n$/, '') }
231
+ truncate#{opt_table} `flydata_sync`.`users`;
231
232
  EOS
232
233
 
233
- it_behaves_like "a dispatcher that calls query handler with correct query"
234
+ it_behaves_like "a dispatcher that calls query handler with correct query"
235
+ end
236
+ end
237
+
238
+ context "with table key word" do
239
+ let(:opt_table) { " table" }
240
+ include_examples "truncate table tests"
241
+ end
242
+
243
+ context "without table key word" do
244
+ let(:opt_table) { "" }
245
+ include_examples "truncate table tests"
234
246
  end
235
247
  end
236
248
  end
@@ -27,24 +27,34 @@ EOS
27
27
  expect(subject.table_info(record)).to eq({db_name: "testdb2", table_name: "testtable2"})
28
28
  end
29
29
  end
30
- context "truncate table query with no db name" do
31
- let(:normalized_query) { "TRUNCATE TABLE apps ;" }
32
- it do
33
- expect(subject.table_info(record)).to eq({db_name: "testdb", table_name: "apps"})
30
+ shared_examples "truncate table queries" do
31
+ context "truncate table query with no db name" do
32
+ let(:normalized_query) { "TRUNCATE#{opt_table} apps ;" }
33
+ it do
34
+ expect(subject.table_info(record)).to eq({db_name: "testdb", table_name: "apps"})
35
+ end
34
36
  end
35
- end
36
- context "truncate table query with db name" do
37
- let(:normalized_query) { "truncate table `testdb1`.`apps1`;" }
38
- it do
39
- expect(subject.table_info(record)).to eq({db_name: "testdb1", table_name: "apps1"})
37
+ context "truncate table query with db name" do
38
+ let(:normalized_query) { "truncate#{opt_table} `testdb1`.`apps1`;" }
39
+ it do
40
+ expect(subject.table_info(record)).to eq({db_name: "testdb1", table_name: "apps1"})
41
+ end
40
42
  end
41
- end
42
- context "truncate table query with quoted db name" do
43
- let(:normalized_query) { "truncate table testdb2.apps2;" }
44
- it do
45
- expect(subject.table_info(record)).to eq({db_name: "testdb2", table_name: "apps2"})
43
+ context "truncate table query with quoted db name" do
44
+ let(:normalized_query) { "truncate#{opt_table} testdb2.apps2;" }
45
+ it do
46
+ expect(subject.table_info(record)).to eq({db_name: "testdb2", table_name: "apps2"})
47
+ end
46
48
  end
47
49
  end
50
+ context "truncate table query with table key word" do
51
+ let(:opt_table) { " TABLE" }
52
+ include_examples "truncate table queries"
53
+ end
54
+ context "truncate table query without table key word" do
55
+ let(:opt_table) { "" }
56
+ include_examples "truncate table queries"
57
+ end
48
58
  context "query does not match DDL_TABLE_QUERY" do #This should not happen, ideally
49
59
  let(:normalized_query) { "CREATE TRIGGER mytrigger BEFORE INSERT ON TABLE_1 FOR EACH ROW SET NEW.MY_DATETIME_COLUMN = NOW();" }
50
60
  it do
@@ -7,36 +7,71 @@ module Mysql
7
7
  include_context "query handler context"
8
8
 
9
9
  describe '#process' do
10
- let(:truncate_query) { "TRUNCATE TABLE foo" }
11
- let(:expected_record) do
12
- {
13
- table_name: table,
14
- query: truncate_query,
15
- type: :truncate_table,
16
- respect_order: true,
17
- src_pos: "#{current_binlog_file}\t#{next_position - event_length}",
18
- table_rev: table_rev,
19
- seq: seq,
20
- v: flydata_record_version
21
- }
22
- end
10
+ let(:truncate_query) { "TRUNCATE table foo" }
11
+
23
12
  before do
24
13
  allow(record).to receive(:[]).with("query").and_return(truncate_query)
25
14
  allow(record).to receive(:[]).with("normalized_query").and_return(truncate_query)
26
15
  end
27
- context "for a non append only table" do
28
- it "should call Fluent's emit with appropriate params" do
29
- expect(Fluent::Engine).to receive(:emit).with(tag, timestamp, expected_record)
30
- expect(subject.process(record))
16
+
17
+ shared_examples "process truncate queries correctly" do
18
+ let(:expected_record) do
19
+ {
20
+ table_name: table,
21
+ query: truncate_query,
22
+ type: :truncate_table,
23
+ respect_order: true,
24
+ src_pos: "#{current_binlog_file}\t#{next_position - event_length}",
25
+ table_rev: table_rev,
26
+ seq: seq,
27
+ v: flydata_record_version
28
+ }
31
29
  end
32
- end
33
- context "for an append only table" do
34
- before do
35
- allow(context).to receive(:omit_events).and_return({ table => [:delete, :truncate_table] })
30
+
31
+ context "for a non append only table" do
32
+ it "should call Fluent's emit with appropriate params" do
33
+ expect(Fluent::Engine).to receive(:emit).with(tag, timestamp, expected_record)
34
+ expect(subject.process(record))
35
+ end
36
+ end
37
+ context "for an append only table" do
38
+ before do
39
+ allow(context).to receive(:omit_events).and_return({ table => [:delete, :truncate_table] })
40
+ end
41
+ it "should not call Fluent's emit" do
42
+ expect(Fluent::Engine).to receive(:emit).never
43
+ expect(subject.process(record))
44
+ end
36
45
  end
46
+ end
47
+
48
+ shared_examples "skip processing queries" do
37
49
  it "should not call Fluent's emit" do
38
50
  expect(Fluent::Engine).to receive(:emit).never
39
- expect(subject.process(record))
51
+ subject.process(record)
52
+ end
53
+ end
54
+
55
+ context "truncate queries with table keyword" do
56
+ let(:truncate_query) { "TRUNCATE table foo" }
57
+ include_examples "process truncate queries correctly"
58
+ end
59
+ context "truncate queries without table keyword" do
60
+ let(:truncate_query) { "TRUNCATE foo" }
61
+ include_examples "process truncate queries correctly"
62
+ end
63
+ context "truncate queries with db name" do
64
+ let(:table) { "var" }
65
+ let(:database) { "testdb" }
66
+
67
+ context 'when db exists' do
68
+ let(:truncate_query) { "TRUNCATE #{database}.#{table}" }
69
+ include_examples "process truncate queries correctly"
70
+ end
71
+
72
+ context 'when db doesn not exists' do
73
+ let(:truncate_query) { "TRUNCATE dummydb.#{table}" }
74
+ include_examples "skip processing queries"
40
75
  end
41
76
  end
42
77
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flydata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koichi Fujikawa
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2015-06-19 00:00:00.000000000 Z
15
+ date: 2015-06-23 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rest-client