spec/inputs/jdbc_spec.rb in logstash-input-jdbc-4.1.3 vs spec/inputs/jdbc_spec.rb in logstash-input-jdbc-4.2.0
- old
+ new
@@ -57,17 +57,19 @@
it "should load all drivers when passing an array" do
mixin_settings['jdbc_driver_library'] = '/foo/bar,/bar/foo'
expect(plugin).to receive(:load_drivers).with(['/foo/bar', '/bar/foo'])
plugin.register
+ plugin.run(queue) # load when first run
plugin.stop
end
it "should load all drivers when using a single value" do
mixin_settings['jdbc_driver_library'] = '/foo/bar'
expect(plugin).to receive(:load_drivers).with(['/foo/bar'])
plugin.register
+ plugin.run(queue) # load when first run
plugin.stop
end
it "should stop without raising exception" do
plugin.register
@@ -817,11 +819,14 @@
before do
mixin_settings['jdbc_driver_class'] = "org.not.ExistsDriver"
end
it "should fail" do
- expect { plugin.register }.to raise_error(LogStash::ConfigurationError)
+ expect do
+ plugin.register
+ plugin.run(queue) # load when first run
+ end.to raise_error(LogStash::ConfigurationError)
end
end
context "when timing out on connection" do
let(:settings) do
@@ -835,10 +840,11 @@
}
end
it "should raise PoolTimeout error" do
plugin.register
+ plugin.run(queue)
db = plugin.instance_variable_get(:@database)
expect(db.pool.instance_variable_get(:@timeout)).to eq(0)
expect(db.pool.instance_variable_get(:@max_size)).to eq(1)
q, q1 = Queue.new, Queue.new
@@ -850,11 +856,14 @@
end
it "should log error message" do
allow(Sequel).to receive(:connect).and_raise(Sequel::PoolTimeout)
expect(plugin.logger).to receive(:error).with("Failed to connect to database. 0 second timeout exceeded. Tried 1 times.")
- expect { plugin.register }.to raise_error(Sequel::PoolTimeout)
+ expect do
+ plugin.register
+ plugin.run(queue)
+ end.to raise_error(Sequel::PoolTimeout)
end
end
context "when using logging" do
@@ -928,11 +937,14 @@
mixin_settings['connection_retry_attempts'] = 2
mixin_settings['jdbc_pool_timeout'] = 0
allow(Sequel).to receive(:connect).and_raise(Sequel::PoolTimeout)
expect(plugin.logger).to receive(:error).with("Failed to connect to database. 0 second timeout exceeded. Trying again.")
expect(plugin.logger).to receive(:error).with("Failed to connect to database. 0 second timeout exceeded. Tried 2 times.")
- expect { plugin.register }.to raise_error(Sequel::PoolTimeout)
+ expect do
+ plugin.register
+ plugin.run(queue)
+ end.to raise_error(Sequel::PoolTimeout)
end
it "should not fail when passed a non-positive value" do
mixin_settings['connection_retry_attempts'] = -2
expect { plugin.register }.to_not raise_error
@@ -965,15 +977,18 @@
encoded_row = {
"column0" => "foo",
"column1" => "bar".force_encoding(Encoding::ISO_8859_1),
"column2" => 3
}
+ event = LogStash::Event.new(row)
expect(LogStash::Event).to receive(:new) do |row|
row.each do |k, v|
next unless v.is_a?(String)
expect(row[k].encoding).to eq(encoded_row[k].encoding)
end
+
+ event
end
plugin.run(events)
end
context "when all string columns should be encoded" do
@@ -997,15 +1012,18 @@
encoded_row = {
"column0" => "foo",
"column1" => "bar",
"column2" => 3
}
+ event = LogStash::Event.new(row)
expect(LogStash::Event).to receive(:new) do |row|
row.each do |k, v|
next unless v.is_a?(String)
expect(row[k].encoding).to eq(encoded_row[k].encoding)
end
+
+ event
end
plugin.run(events)
end
end
@@ -1032,14 +1050,17 @@
"column0" => "foo",
"column1" => "bar",
"column2" => 3,
"column3" => "berlin".force_encoding(Encoding::ASCII_8BIT)
}
+ event = LogStash::Event.new(row)
expect(LogStash::Event).to receive(:new) do |row|
row.each do |k, v|
next unless v.is_a?(String)
expect(row[k].encoding).to eq(encoded_row[k].encoding)
end
+
+ event
end
plugin.run(events)
end
end
end