Adds more specific error exception checks to tests
This commit is contained in:
		
							parent
							
								
									d362e791e5
								
							
						
					
					
						commit
						baaeba3c07
					
				@ -173,7 +173,7 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
 | 
				
			|||||||
  def load_jar_files!
 | 
					  def load_jar_files!
 | 
				
			||||||
    # Load jar from driver path
 | 
					    # Load jar from driver path
 | 
				
			||||||
    unless @driver_jar_path.nil?
 | 
					    unless @driver_jar_path.nil?
 | 
				
			||||||
      raise Exception, 'JDBC - Could not find jar file at given path. Check config.' unless File.exist? @driver_jar_path
 | 
					      raise LogStash::ConfigurationError, 'JDBC - Could not find jar file at given path. Check config.' unless File.exist? @driver_jar_path
 | 
				
			||||||
      require @driver_jar_path
 | 
					      require @driver_jar_path
 | 
				
			||||||
      return
 | 
					      return
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
@ -189,7 +189,7 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
 | 
				
			|||||||
    @logger.debug('JDBC - jarpath', path: jarpath)
 | 
					    @logger.debug('JDBC - jarpath', path: jarpath)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    jars = Dir[jarpath]
 | 
					    jars = Dir[jarpath]
 | 
				
			||||||
    raise Exception, 'JDBC - No jars found. Have you read the README?' if jars.empty?
 | 
					    raise LogStash::ConfigurationError, 'JDBC - No jars found. Have you read the README?' if jars.empty?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    jars.each do |jar|
 | 
					    jars.each do |jar|
 | 
				
			||||||
      @logger.debug('JDBC - Loaded jar', jar: jar)
 | 
					      @logger.debug('JDBC - Loaded jar', jar: jar)
 | 
				
			||||||
 | 
				
			|||||||
@ -15,7 +15,7 @@ RSpec.shared_context 'when initializing' do
 | 
				
			|||||||
  it 'shouldn\'t register with a missing jar file' do
 | 
					  it 'shouldn\'t register with a missing jar file' do
 | 
				
			||||||
    jdbc_settings['driver_jar_path'] = nil
 | 
					    jdbc_settings['driver_jar_path'] = nil
 | 
				
			||||||
    plugin = LogStash::Plugin.lookup('output', 'jdbc').new(jdbc_settings)
 | 
					    plugin = LogStash::Plugin.lookup('output', 'jdbc').new(jdbc_settings)
 | 
				
			||||||
    expect { plugin.register }.to raise_error
 | 
					    expect { plugin.register }.to raise_error(LogStash::ConfigurationError)
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -64,8 +64,6 @@ RSpec.shared_context 'when outputting messages' do
 | 
				
			|||||||
  it 'should save a event' do
 | 
					  it 'should save a event' do
 | 
				
			||||||
    expect { plugin.multi_receive([event]) }.to_not raise_error
 | 
					    expect { plugin.multi_receive([event]) }.to_not raise_error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    sleep 5
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    # Verify the number of items in the output table
 | 
					    # Verify the number of items in the output table
 | 
				
			||||||
    c = plugin.instance_variable_get(:@pool).getConnection
 | 
					    c = plugin.instance_variable_get(:@pool).getConnection
 | 
				
			||||||
    stmt = c.prepareStatement("select count(*) as total from #{jdbc_test_table} where message = ?")
 | 
					    stmt = c.prepareStatement("select count(*) as total from #{jdbc_test_table} where message = ?")
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user