|
2 | 2 | require "logstash/devutils/rspec/spec_helper" |
3 | 3 | require "logstash/inputs/jdbc" |
4 | 4 | require "jdbc/derby" |
| 5 | +require "jdbc/mysql" |
| 6 | +Jdbc::MySQL.load_driver |
5 | 7 | require "sequel" |
6 | 8 | require "sequel/adapters/jdbc" |
7 | 9 | require "timecop" |
|
26 | 28 | end |
27 | 29 |
|
28 | 30 | before :each do |
29 | | - Jdbc::Derby.load_driver |
30 | | - db.create_table :test_table do |
31 | | - DateTime :created_at |
32 | | - Integer :num |
33 | | - String :string |
34 | | - DateTime :custom_time |
35 | | - end |
36 | | - db << "CREATE TABLE types_table (num INTEGER, string VARCHAR(255), started_at DATE, custom_time TIMESTAMP, ranking DECIMAL(16,6))" |
| 31 | + if !RSpec.current_example.metadata[:no_connection] |
| 32 | + # before body |
| 33 | + Jdbc::Derby.load_driver |
| 34 | + db.create_table :test_table do |
| 35 | + DateTime :created_at |
| 36 | + Integer :num |
| 37 | + String :string |
| 38 | + DateTime :custom_time |
| 39 | + end |
| 40 | + db << "CREATE TABLE types_table (num INTEGER, string VARCHAR(255), started_at DATE, custom_time TIMESTAMP, ranking DECIMAL(16,6))" |
| 41 | + end |
37 | 42 | end |
38 | 43 |
|
39 | 44 | after :each do |
40 | | - db.drop_table(:test_table) |
41 | | - db.drop_table(:types_table) |
| 45 | + if !RSpec.current_example.metadata[:no_connection] |
| 46 | + db.drop_table(:test_table) |
| 47 | + db.drop_table(:types_table) |
| 48 | + end |
42 | 49 | end |
43 | 50 |
|
44 | 51 | context "when registering and tearing down" do |
|
87 | 94 | end |
88 | 95 | end |
89 | 96 |
|
| 97 | + context "when connecting to a non-existent server", :no_connection => true do |
| 98 | + let(:mixin_settings) do |
| 99 | + super.merge( |
| 100 | + "jdbc_driver_class" => "com.mysql.jdbc.Driver", |
| 101 | + "jdbc_connection_string" => "jdbc:mysql://localhost:99999/somedb" |
| 102 | + ) |
| 103 | + end |
| 104 | + let(:settings) { super.merge("statement" => "SELECT 1 as col1 FROM test_table", "jdbc_user" => "foo", "jdbc_password" => "bar") } |
| 105 | + |
| 106 | + it "should not register correctly" do |
| 107 | + plugin.register |
| 108 | + q = Queue.new |
| 109 | + expect do |
| 110 | + plugin.run(q) |
| 111 | + end.to raise_error(::Sequel::DatabaseConnectionError) |
| 112 | + end |
| 113 | + end |
| 114 | + |
90 | 115 | context "when both jdbc_password and jdbc_password_filepath arguments are passed" do |
91 | 116 | let(:statement) { "SELECT * from test_table" } |
92 | 117 | let(:jdbc_password) { "secret" } |
|
0 commit comments