spec/inputs/jdbc_spec.rb in logstash-input-jdbc-4.1.1 vs spec/inputs/jdbc_spec.rb in logstash-input-jdbc-4.1.2
- old
+ new
@@ -461,10 +461,54 @@
plugin.run(queue)
expect(plugin.instance_variable_get("@sql_last_value")).to eq(50)
end
end
+ context "when iteratively running plugin#run with timestamp tracking column with column value" do
+ let(:mixin_settings) do
+ { "jdbc_user" => ENV['USER'], "jdbc_driver_class" => "org.apache.derby.jdbc.EmbeddedDriver",
+ "jdbc_connection_string" => "jdbc:derby:memory:testdb;create=true"
+ }
+ end
+
+ let(:settings) do
+ { "statement" => "SELECT num, created_at, custom_time FROM test_table WHERE custom_time > :sql_last_value",
+ "use_column_value" => true,
+ "tracking_column" => "custom_time",
+ "tracking_column_type" => "timestamp",
+ "last_run_metadata_path" => Stud::Temporary.pathname }
+ end
+
+ let(:nums) { [10, 20, 30, 40, 50] }
+ let(:times) {["2015-05-06 13:14:15","2015-05-07 13:14:15","2015-05-08 13:14:15","2015-05-09 13:14:15","2015-05-10 13:14:15"]}
+
+ before do
+ plugin.register
+ end
+
+ after do
+ plugin.stop
+ end
+
+ it "should successfully update sql_last_value" do
+ test_table = db[:test_table]
+
+ plugin.run(queue)
+ expect(plugin.instance_variable_get("@sql_last_value")).to eq(Time.parse("1970-01-01 00:00:00.000000000 +0000"))
+ test_table.insert(:num => nums[0], :created_at => Time.now.utc, :custom_time => times[0])
+ test_table.insert(:num => nums[1], :created_at => Time.now.utc, :custom_time => times[1])
+ plugin.run(queue)
+ expect(plugin.instance_variable_get("@sql_last_value").class).to eq(Time.parse(times[0]).class)
+ expect(plugin.instance_variable_get("@sql_last_value")).to eq(Time.parse(times[1]))
+ test_table.insert(:num => nums[2], :created_at => Time.now.utc, :custom_time => times[2])
+ test_table.insert(:num => nums[3], :created_at => Time.now.utc, :custom_time => times[3])
+ test_table.insert(:num => nums[4], :created_at => Time.now.utc, :custom_time => times[4])
+ plugin.run(queue)
+ expect(plugin.instance_variable_get("@sql_last_value")).to eq(Time.parse(times[4]))
+ end
+ end
+
context "when iteratively running plugin#run with tracking_column and stored metadata" do
let(:mixin_settings) do
{ "jdbc_user" => ENV['USER'], "jdbc_driver_class" => "org.apache.derby.jdbc.EmbeddedDriver",
"jdbc_connection_string" => "jdbc:derby:memory:testdb;create=true"
}
@@ -819,12 +863,11 @@
end
let(:num_rows) { 5 }
before do
- plugin.instance_variable_set("@logger", logger)
- allow(logger).to receive(:debug?)
+ allow(plugin.logger).to receive(:debug?)
num_rows.times do
db[:test_table].insert(:num => 1)
end
plugin.register
@@ -832,13 +875,11 @@
after do
plugin.stop
end
- let(:logger) { double("logger") }
-
- it "should report the staments to logging" do
- expect(logger).to receive(:debug).with(kind_of(String)).once
+ it "should report the statements to logging" do
+ expect(plugin.logger).to receive(:debug).once
plugin.run(queue)
end
end
describe "config option lowercase_column_names behaviour" do