diff --git a/lib/logstash/outputs/jdbc.rb b/lib/logstash/outputs/jdbc.rb index fb34230..c70651f 100644 --- a/lib/logstash/outputs/jdbc.rb +++ b/lib/logstash/outputs/jdbc.rb @@ -260,7 +260,7 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base else value = i end - + case value when Time # See LogStash::Timestamp, below, for the why behind strftime. @@ -275,7 +275,11 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base # strftime appears to be the most reliable across drivers. statement.setString(idx + 1, value.time.strftime(STRFTIME_FMT)) when Fixnum, Integer - statement.setInt(idx + 1, value) + if value > 2147483647 or value < -2147483648 + statement.setLong(idx + 1, value) + else + statement.setInt(idx + 1, value) + end when Float statement.setFloat(idx + 1, value) when String @@ -303,7 +307,7 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base log_method = (retrying ? 'warn' : 'error') loop do - @logger.send(log_method, log_text, :exception => current_exception, :backtrace => current_exception.backtrace) + @logger.send(log_method, log_text, :exception => current_exception) if current_exception.respond_to? 'getNextException' current_exception = current_exception.getNextException() diff --git a/spec/jdbc_spec_helper.rb b/spec/jdbc_spec_helper.rb index 2cfd548..89bf44f 100644 --- a/spec/jdbc_spec_helper.rb +++ b/spec/jdbc_spec_helper.rb @@ -33,11 +33,11 @@ RSpec.shared_context 'when outputting messages' do end let(:jdbc_create_table) do - "CREATE table #{jdbc_test_table} (created_at datetime not null, message varchar(512) not null, message_sprintf varchar(512) not null, static_int int not null, static_bit bit not null)" + "CREATE table #{jdbc_test_table} (created_at datetime not null, message varchar(512) not null, message_sprintf varchar(512) not null, static_int int not null, static_bit bit not null, static_bigint bigint not null)" end let(:jdbc_statement) do - ["insert into #{jdbc_test_table} (created_at, message, message_sprintf, static_int, static_bit) values(?, ?, ?, ?, ?)", '@timestamp', 'message', 'sprintf-%{message}', 1, true] + ["insert into #{jdbc_test_table} (created_at, message, message_sprintf, static_int, static_bit, static_bigint) values(?, ?, ?, ?, ?, ?)", '@timestamp', 'message', 'sprintf-%{message}', 1, true, 4000881632477184] end let(:systemd_database_service) do @@ -124,25 +124,24 @@ RSpec.shared_context 'when outputting messages' do # Check that everything is fine right now expect { p.multi_receive([event]) }.not_to raise_error - # Start a thread to stop and restart the service. + cmd = 'sudo /etc/init.d/%s* %s' + + `which systemctl` + if $?.success? + start_stop_cmd = 'sudo systemctl %s %s' + end + + cmd = cmd % { action: 'stop', service: systemd_database_service } + `#{cmd}` + + # Start a thread to restart the service after the fact. t = Thread.new(systemd_database_service) { |systemd_database_service| - start_stop_cmd = 'sudo /etc/init.d/%s* %s' - - `which systemctl` - if $?.success? - start_stop_cmd = 'sudo systemctl %s %s' - end - - cmd = start_stop_cmd % { action: 'stop', service: systemd_database_service } - `#{cmd}` - sleep 10 + sleep 20 cmd = start_stop_cmd % { action: 'start', service: systemd_database_service } `#{cmd}` } - - # Wait a few seconds to the service to stop - sleep 5 + t.run expect(logger).to receive(:warn).at_least(:once).with(/JDBC - Exception. Retrying/, Hash) expect { p.multi_receive([event]) }.to_not raise_error diff --git a/spec/outputs/jdbc_derby_spec.rb b/spec/outputs/jdbc_derby_spec.rb index b06980b..ad9ed33 100644 --- a/spec/outputs/jdbc_derby_spec.rb +++ b/spec/outputs/jdbc_derby_spec.rb @@ -10,7 +10,7 @@ describe 'logstash-output-jdbc: derby', if: ENV['JDBC_DERBY_JAR'] do end let(:jdbc_create_table) do - "CREATE table #{jdbc_test_table} (created_at timestamp not null, message varchar(512) not null, message_sprintf varchar(512) not null, static_int int not null, static_bit boolean not null)" + "CREATE table #{jdbc_test_table} (created_at timestamp not null, message varchar(512) not null, message_sprintf varchar(512) not null, static_int int not null, static_bit boolean not null, static_bigint bigint not null)" end let(:jdbc_settings) do