Class: RSpec::Hive::Connector

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/hive/connector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Connector

Returns a new instance of Connector.



10
11
12
13
# File 'lib/rspec/hive/connector.rb', line 10

def initialize(configuration)
  @config = configuration
  # transport: :sasl, sasl_params: {username: 'hive', password: ''},
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



8
9
10
# File 'lib/rspec/hive/connector.rb', line 8

def config
  @config
end

#resultObject (readonly)

Returns the value of attribute result.



8
9
10
# File 'lib/rspec/hive/connector.rb', line 8

def result
  @result
end

Instance Method Details

#start_connection(db_name = DbName.random_name) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rspec/hive/connector.rb', line 15

def start_connection(db_name = DbName.random_name)
  connection = open_connection
  connection.switch_database(db_name)
  @config.hive_options.each do |key, value|
    connection.execute("SET #{key}=#{value};")
  end

  connection

rescue Thrift::ApplicationException => e
  config.logger.fatal('An exception was thrown during start connection')
  config.logger.fatal(e)
  stop_connection(connection)
  connection
end

#stop_connection(connection) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/rspec/hive/connector.rb', line 31

def stop_connection(connection)
  connection.close_session if connection.session
  connection.close
rescue IOError => e
  config.logger.fatal('An exception was thrown during close connection')
  config.logger.fatal(e)
end

#tlcli_connectObject



39
40
41
42
43
44
45
# File 'lib/rspec/hive/connector.rb', line 39

def tlcli_connect
  RBHive.tcli_connect(@config.host,
                      @config.port,
                      connection_options) do |connection|
    yield ConnectionDelegator.new(connection, @config)
  end
end