vertica 0.9.6 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -2,14 +2,14 @@ GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
4
  git (1.2.5)
5
- jeweler (1.8.3)
5
+ jeweler (1.8.4)
6
6
  bundler (~> 1.0)
7
7
  git (>= 1.2.5)
8
8
  rake
9
9
  rdoc
10
- json (1.7.3)
11
- rake (0.9.2.2)
12
- rdoc (3.12)
10
+ json (1.7.7)
11
+ rake (10.0.4)
12
+ rdoc (3.12.2)
13
13
  json (~> 1.4)
14
14
 
15
15
  PLATFORMS
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.6
1
+ 0.10.0
@@ -23,10 +23,7 @@ class Vertica::Connection
23
23
  @options[:read_timeout] ||= 30
24
24
 
25
25
  @row_style = @options[:row_style] ? @options[:row_style] : :hash
26
- unless options[:skip_startup]
27
- startup_connection
28
- initialize_connection
29
- end
26
+ boot_connection unless options[:skip_startup]
30
27
  end
31
28
 
32
29
  def on_notice(&block)
@@ -76,24 +73,35 @@ class Vertica::Connection
76
73
  raise ArgumentError, "invalid message: (#{message.inspect})" unless message.respond_to?(:to_bytes)
77
74
  puts "=> #{message.inspect}" if @debug
78
75
  socket.write message.to_bytes
76
+ rescue SystemCallError => e
77
+ close_socket
78
+ raise Vertica::Error::ConnectionError.new(e.message)
79
79
  end
80
80
 
81
81
  def close
82
82
  write Vertica::Messages::Terminate.new
83
+ ensure
84
+ close_socket
85
+ end
86
+
87
+ def close_socket
83
88
  socket.close
84
89
  @socket = nil
85
- rescue Errno::ENOTCONN # the backend closed the socket already
90
+ rescue SystemCallError
86
91
  ensure
87
92
  reset_values
88
93
  end
89
94
 
90
95
  def reset_connection
91
96
  close
92
-
97
+ boot_connection
98
+ end
99
+
100
+ def boot_connection
93
101
  startup_connection
94
102
  initialize_connection
95
103
  end
96
-
104
+
97
105
  def cancel
98
106
  conn = self.class.new(options.merge(:skip_startup => true))
99
107
  conn.write Vertica::Messages::CancelRequest.new(backend_pid, backend_key)
@@ -123,8 +131,12 @@ class Vertica::Connection
123
131
  puts "<= #{message.inspect}" if @debug
124
132
  return message
125
133
  else
126
- raise Errno::ETIMEDOUT
134
+ close
135
+ raise Vertica::Error::TimedOutError.new("Connection timed out.")
127
136
  end
137
+ rescue SystemCallError => e
138
+ close_socket
139
+ raise Vertica::Error::ConnectionError.new(e.message)
128
140
  end
129
141
 
130
142
  def process_message(message)
@@ -172,6 +184,7 @@ class Vertica::Connection
172
184
  protected
173
185
 
174
186
  def run_with_job_lock(job)
187
+ boot_connection if closed?
175
188
  raise Vertica::Error::SynchronizeError.new(@current_job, job) if busy?
176
189
  @current_job = job
177
190
  job.run
data/lib/vertica/error.rb CHANGED
@@ -6,6 +6,7 @@ class Vertica::Error < StandardError
6
6
  class InterruptImpossible < Vertica::Error; end
7
7
  class MessageError < Vertica::Error; end
8
8
  class EmptyQueryError < Vertica::Error; end
9
+ class TimedOutError < ConnectionError; end
9
10
 
10
11
  class SynchronizeError < Vertica::Error
11
12
  attr_reader :running_job, :requested_job
@@ -74,8 +74,45 @@ class ConnectionTest < Test::Unit::TestCase
74
74
  end
75
75
 
76
76
  def test_connection_inspect_should_not_print_password
77
- @connection = Vertica::Connection.new(TEST_CONNECTION_HASH)
78
- inspected_string = @connection.inspect
77
+ connection = Vertica::Connection.new(TEST_CONNECTION_HASH)
78
+ inspected_string = connection.inspect
79
79
  assert_no_match /:password=>#{TEST_CONNECTION_HASH[:password]}/, inspected_string
80
80
  end
81
+
82
+ def test_connection_timed_out_error
83
+ connection = Vertica::Connection.new(TEST_CONNECTION_HASH)
84
+ connection.options[:read_timeout] = 0.01
85
+ assert_raises(Vertica::Error::TimedOutError) {connection.query("SELECT SLEEP(1)")}
86
+ assert connection.closed?
87
+ end
88
+
89
+ def test_automatically_reconnects
90
+ connection = Vertica::Connection.new(TEST_CONNECTION_HASH)
91
+ connection.close
92
+ assert_equal(1, connection.query("SELECT 1").the_value)
93
+ end
94
+
95
+ def test_socket_write_error
96
+ connection = Vertica::Connection.new(TEST_CONNECTION_HASH)
97
+ class << connection.socket
98
+ def write(foo)
99
+ raise Errno::ETIMEDOUT
100
+ end
101
+ end
102
+
103
+ assert_raises(Vertica::Error::ConnectionError) {connection.query('select 1')}
104
+ assert connection.closed?
105
+ end
106
+
107
+ def test_socket_read_error
108
+ connection = Vertica::Connection.new(TEST_CONNECTION_HASH)
109
+ class << connection.socket
110
+ def read(foo)
111
+ raise Errno::ETIMEDOUT
112
+ end
113
+ end
114
+
115
+ assert_raises(Vertica::Error::ConnectionError) {connection.query('select 1')}
116
+ assert connection.closed?
117
+ end
81
118
  end
@@ -110,7 +110,7 @@ class QueryTest < Test::Unit::TestCase
110
110
  end
111
111
 
112
112
  def test_read_timeout
113
- assert_raises(Errno::ETIMEDOUT) do
113
+ assert_raises(Vertica::Error::TimedOutError) do
114
114
  @connection.options[:read_timeout] = 0.0001
115
115
  @connection.query("SELECT * FROM test_ruby_vertica_table")
116
116
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vertica
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.6
4
+ version: 0.10.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-03-25 00:00:00.000000000 Z
14
+ date: 2013-04-11 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rake
18
- requirement: &70124964988460 !ruby/object:Gem::Requirement
18
+ requirement: !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ! '>='
@@ -23,10 +23,15 @@ dependencies:
23
23
  version: '0'
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *70124964988460
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ! '>='
30
+ - !ruby/object:Gem::Version
31
+ version: '0'
27
32
  - !ruby/object:Gem::Dependency
28
33
  name: jeweler
29
- requirement: &70124964987720 !ruby/object:Gem::Requirement
34
+ requirement: !ruby/object:Gem::Requirement
30
35
  none: false
31
36
  requirements:
32
37
  - - ! '>='
@@ -34,7 +39,12 @@ dependencies:
34
39
  version: '0'
35
40
  type: :runtime
36
41
  prerelease: false
37
- version_requirements: *70124964987720
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
38
48
  description: Query Vertica with ruby
39
49
  email: sprsquish@gmail.com
40
50
  executables: []
@@ -109,6 +119,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
119
  - - ! '>='
110
120
  - !ruby/object:Gem::Version
111
121
  version: '0'
122
+ segments:
123
+ - 0
124
+ hash: 714844317513278375
112
125
  required_rubygems_version: !ruby/object:Gem::Requirement
113
126
  none: false
114
127
  requirements:
@@ -117,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
130
  version: '0'
118
131
  requirements: []
119
132
  rubyforge_project:
120
- rubygems_version: 1.8.16
133
+ rubygems_version: 1.8.25
121
134
  signing_key:
122
135
  specification_version: 3
123
136
  summary: Pure ruby library for interacting with Vertica