spec/inputs/jdbc_spec.rb in logstash-input-jdbc-4.3.11 vs spec/inputs/jdbc_spec.rb in logstash-input-jdbc-4.3.12
- old
+ new
@@ -1265,6 +1265,56 @@
expect(event.get("custom_time")).to be_a(LogStash::Timestamp)
expect(event.get("custom_time").to_s).to eq("1999-12-31T23:59:59.000Z")
expect(event.get("ranking").to_f).to eq(95.67)
end
end
+
+ context "when debug logging and a count query raises a count related error" do
+ let(:settings) do
+ { "statement" => "SELECT * from types_table" }
+ end
+ let(:logger) { double("logger", :debug? => true) }
+ let(:statement_logger) { LogStash::PluginMixins::Jdbc::CheckedCountLogger.new(logger) }
+ let(:value_tracker) { double("value tracker", :set_value => nil, :write => nil) }
+ let(:msg) { 'Java::JavaSql::SQLSyntaxErrorException: Dynamic SQL Error; SQL error code = -104; Token unknown - line 1, column 105; LIMIT [SQLState:42000, ISC error code:335544634]' }
+ let(:error_args) do
+ {"exception" => msg}
+ end
+
+ before do
+ db << "INSERT INTO types_table (num, string, started_at, custom_time, ranking) VALUES (1, 'A test', '1999-12-31', '1999-12-31 23:59:59', 95.67)"
+ plugin.register
+ plugin.set_statement_logger(statement_logger)
+ plugin.set_value_tracker(value_tracker)
+ allow(value_tracker).to receive(:value).and_return("bar")
+ allow(statement_logger).to receive(:execute_count).once.and_raise(StandardError.new(msg))
+ end
+
+ after do
+ plugin.stop
+ end
+
+ context "if the count query raises an error" do
+ it "should log a debug line without a count key as its unknown whether a count works at this stage" do
+ expect(logger).to receive(:warn).once.with("Attempting a count query raised an error, the generated count statement is most likely incorrect but check networking, authentication or your statement syntax", error_args)
+ expect(logger).to receive(:warn).once.with("Ongoing count statement generation is being prevented")
+ expect(logger).to receive(:debug).once.with("Executing JDBC query", :statement => settings["statement"], :parameters => {:sql_last_value=>"bar"})
+ plugin.run(queue)
+ queue.pop
+ end
+
+ it "should create an event normally" do
+ allow(logger).to receive(:warn)
+ allow(logger).to receive(:debug)
+ plugin.run(queue)
+ event = queue.pop
+ expect(event.get("num")).to eq(1)
+ expect(event.get("string")).to eq("A test")
+ expect(event.get("started_at")).to be_a(LogStash::Timestamp)
+ expect(event.get("started_at").to_s).to eq("1999-12-31T00:00:00.000Z")
+ expect(event.get("custom_time")).to be_a(LogStash::Timestamp)
+ expect(event.get("custom_time").to_s).to eq("1999-12-31T23:59:59.000Z")
+ expect(event.get("ranking").to_f).to eq(95.67)
+ end
+ end
+ end
end