vertica 0.12.0 → 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -20
- data/lib/vertica.rb +15 -8
- data/lib/vertica/column.rb +32 -13
- data/lib/vertica/connection.rb +143 -119
- data/lib/vertica/{messages/backend_messages → protocol/backend}/authentication.rb +1 -1
- data/lib/vertica/{messages/backend_messages → protocol/backend}/backend_key_data.rb +1 -1
- data/lib/vertica/{messages/backend_messages → protocol/backend}/bind_complete.rb +1 -1
- data/lib/vertica/{messages/backend_messages → protocol/backend}/close_complete.rb +1 -1
- data/lib/vertica/{messages/backend_messages → protocol/backend}/command_complete.rb +1 -1
- data/lib/vertica/{messages/backend_messages → protocol/backend}/copy_in_response.rb +2 -2
- data/lib/vertica/{messages/backend_messages → protocol/backend}/data_row.rb +1 -1
- data/lib/vertica/{messages/backend_messages → protocol/backend}/empty_query_response.rb +1 -1
- data/lib/vertica/{messages/backend_messages → protocol/backend}/error_response.rb +1 -1
- data/lib/vertica/{messages/backend_messages → protocol/backend}/no_data.rb +1 -1
- data/lib/vertica/{messages/backend_messages → protocol/backend}/notice_response.rb +6 -6
- data/lib/vertica/{messages/backend_messages → protocol/backend}/parameter_description.rb +2 -2
- data/lib/vertica/{messages/backend_messages → protocol/backend}/parameter_status.rb +3 -3
- data/lib/vertica/{messages/backend_messages → protocol/backend}/parse_complete.rb +1 -1
- data/lib/vertica/{messages/backend_messages → protocol/backend}/portal_suspended.rb +1 -1
- data/lib/vertica/{messages/backend_messages → protocol/backend}/ready_for_query.rb +2 -2
- data/lib/vertica/{messages/backend_messages → protocol/backend}/row_description.rb +9 -9
- data/lib/vertica/{messages/backend_messages → protocol/backend}/unknown.rb +1 -1
- data/lib/vertica/{messages/frontend_messages → protocol/frontend}/bind.rb +2 -3
- data/lib/vertica/{messages/frontend_messages → protocol/frontend}/cancel_request.rb +3 -4
- data/lib/vertica/{messages/frontend_messages → protocol/frontend}/close.rb +3 -3
- data/lib/vertica/{messages/frontend_messages → protocol/frontend}/copy_data.rb +6 -6
- data/lib/vertica/{messages/frontend_messages → protocol/frontend}/copy_done.rb +1 -1
- data/lib/vertica/{messages/frontend_messages → protocol/frontend}/copy_fail.rb +5 -5
- data/lib/vertica/{messages/frontend_messages → protocol/frontend}/describe.rb +3 -3
- data/lib/vertica/{messages/frontend_messages → protocol/frontend}/execute.rb +3 -3
- data/lib/vertica/{messages/frontend_messages → protocol/frontend}/flush.rb +1 -1
- data/lib/vertica/{messages/frontend_messages → protocol/frontend}/parse.rb +3 -3
- data/lib/vertica/protocol/frontend/password.rb +32 -0
- data/lib/vertica/{messages/frontend_messages → protocol/frontend}/query.rb +3 -4
- data/lib/vertica/{messages/frontend_messages → protocol/frontend}/ssl_request.rb +2 -2
- data/lib/vertica/{messages/frontend_messages → protocol/frontend}/startup.rb +2 -3
- data/lib/vertica/{messages/frontend_messages → protocol/frontend}/sync.rb +1 -1
- data/lib/vertica/{messages/frontend_messages → protocol/frontend}/terminate.rb +1 -1
- data/lib/vertica/protocol/message.rb +86 -0
- data/lib/vertica/query.rb +63 -44
- data/lib/vertica/result.rb +25 -47
- data/lib/vertica/row.rb +44 -0
- data/lib/vertica/row_description.rb +102 -0
- data/lib/vertica/version.rb +1 -1
- data/test/connection.yml.example +8 -8
- data/test/functional/functional_connection_test.rb +178 -0
- data/test/functional/{query_test.rb → functional_query_test.rb} +64 -67
- data/test/functional/functional_value_conversion_test.rb +117 -0
- data/test/test_helper.rb +1 -1
- data/test/unit/backend_message_test.rb +57 -57
- data/test/unit/column_test.rb +23 -23
- data/test/unit/frontend_message_test.rb +5 -5
- data/test/unit/quoting_test.rb +16 -5
- data/test/unit/result_test.rb +61 -0
- data/test/unit/row_description_test.rb +56 -0
- data/test/unit/row_test.rb +31 -0
- data/vertica.gemspec +1 -0
- metadata +67 -45
- data/lib/vertica/messages/frontend_messages/password.rb +0 -34
- data/lib/vertica/messages/message.rb +0 -79
- data/test/functional/connection_test.rb +0 -128
- data/test/functional/value_conversion_test.rb +0 -88
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class RowDescriptionTest < Minitest::Test
|
4
|
+
def setup
|
5
|
+
@message = Vertica::Protocol::RowDescription.new("\x00\x02id\x00\x00\np8\x00\x01\x00\x00\x00\x06\x00\b\xFF\xFF\xFF\xFF\x00\x00name\x00\x00\np8\x00\x02\x00\x00\x00\t\xFF\xFF\x00\x00\x00h\x00\x00")
|
6
|
+
|
7
|
+
@column1 = Vertica::Column.new(@message.fields[0])
|
8
|
+
@column2 = Vertica::Column.new(@message.fields[1])
|
9
|
+
|
10
|
+
@row_description = Vertica::RowDescription.build([@column1, @column2])
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_build_from_row_description_message
|
14
|
+
assert_equal Vertica::RowDescription.build(@message), @row_description
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_build_from_self_returns_self
|
18
|
+
assert Vertica::RowDescription.build(@row_description).eql?(@row_description)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_build_from_nil_return_nil
|
22
|
+
assert_nil Vertica::RowDescription.build(nil)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_size
|
26
|
+
assert_equal 2, @row_description.length
|
27
|
+
assert_equal 2, @row_description.size
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_column_with_index
|
31
|
+
assert_equal [@column1, 0], @row_description.column_with_index(0)
|
32
|
+
assert_equal [@column2, 1], @row_description.column_with_index('name')
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_finding_columns_by_index
|
36
|
+
assert_equal @column1, @row_description[0]
|
37
|
+
assert_equal @column2, @row_description.column(1)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_finding_columns_by_name
|
41
|
+
assert_equal @column1, @row_description['id']
|
42
|
+
assert_equal @column2, @row_description.column('name')
|
43
|
+
|
44
|
+
assert_equal @column1, @row_description.column(:id)
|
45
|
+
assert_equal @column2, @row_description[:name]
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_to_a
|
49
|
+
assert_equal [@column1, @column2], @row_description.to_a
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_to_h
|
53
|
+
hash = { 'id' => @column1, 'name' => @column2}
|
54
|
+
assert_equal hash, @row_description.to_h
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class RowTest < Minitest::Test
|
4
|
+
def setup
|
5
|
+
@message = Vertica::Protocol::RowDescription.new("\x00\x02id\x00\x00\np8\x00\x01\x00\x00\x00\x06\x00\b\xFF\xFF\xFF\xFF\x00\x00name\x00\x00\np8\x00\x02\x00\x00\x00\t\xFF\xFF\x00\x00\x00h\x00\x00")
|
6
|
+
|
7
|
+
@column1 = Vertica::Column.new(@message.fields[0])
|
8
|
+
@column2 = Vertica::Column.new(@message.fields[1])
|
9
|
+
|
10
|
+
@row_description = Vertica::RowDescription.build([@column1, @column2])
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_fetch
|
14
|
+
row = Vertica::Row.new(@row_description, [123, 'test'])
|
15
|
+
assert_equal 123, row[0]
|
16
|
+
assert_equal 123, row.fetch('id')
|
17
|
+
assert_equal 'test', row.fetch(1)
|
18
|
+
assert_equal 'test', row[:name]
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_to_a
|
22
|
+
row = Vertica::Row.new(@row_description, [123, 'test'])
|
23
|
+
assert_equal [123, 'test'], row.to_a
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_to_h
|
27
|
+
row = Vertica::Row.new(@row_description, [123, 'test'])
|
28
|
+
hash = { 'id' => 123, 'name' => 'test' }
|
29
|
+
assert_equal hash, row.to_h
|
30
|
+
end
|
31
|
+
end
|
data/vertica.gemspec
CHANGED
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.
|
4
|
+
version: 1.0.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Smick
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-07-
|
13
|
+
date: 2016-07-05 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|
@@ -54,6 +54,20 @@ dependencies:
|
|
54
54
|
- - ~>
|
55
55
|
- !ruby/object:Gem::Version
|
56
56
|
version: '5'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: mocha
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
type: :development
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
57
71
|
description: Query Vertica with ruby
|
58
72
|
email:
|
59
73
|
- sprsquish@gmail.com
|
@@ -74,54 +88,59 @@ files:
|
|
74
88
|
- lib/vertica/column.rb
|
75
89
|
- lib/vertica/connection.rb
|
76
90
|
- lib/vertica/error.rb
|
77
|
-
- lib/vertica/
|
78
|
-
- lib/vertica/
|
79
|
-
- lib/vertica/
|
80
|
-
- lib/vertica/
|
81
|
-
- lib/vertica/
|
82
|
-
- lib/vertica/
|
83
|
-
- lib/vertica/
|
84
|
-
- lib/vertica/
|
85
|
-
- lib/vertica/
|
86
|
-
- lib/vertica/
|
87
|
-
- lib/vertica/
|
88
|
-
- lib/vertica/
|
89
|
-
- lib/vertica/
|
90
|
-
- lib/vertica/
|
91
|
-
- lib/vertica/
|
92
|
-
- lib/vertica/
|
93
|
-
- lib/vertica/
|
94
|
-
- lib/vertica/
|
95
|
-
- lib/vertica/
|
96
|
-
- lib/vertica/
|
97
|
-
- lib/vertica/
|
98
|
-
- lib/vertica/
|
99
|
-
- lib/vertica/
|
100
|
-
- lib/vertica/
|
101
|
-
- lib/vertica/
|
102
|
-
- lib/vertica/
|
103
|
-
- lib/vertica/
|
104
|
-
- lib/vertica/
|
105
|
-
- lib/vertica/
|
106
|
-
- lib/vertica/
|
107
|
-
- lib/vertica/
|
108
|
-
- lib/vertica/
|
109
|
-
- lib/vertica/
|
110
|
-
- lib/vertica/
|
111
|
-
- lib/vertica/
|
91
|
+
- lib/vertica/protocol/backend/authentication.rb
|
92
|
+
- lib/vertica/protocol/backend/backend_key_data.rb
|
93
|
+
- lib/vertica/protocol/backend/bind_complete.rb
|
94
|
+
- lib/vertica/protocol/backend/close_complete.rb
|
95
|
+
- lib/vertica/protocol/backend/command_complete.rb
|
96
|
+
- lib/vertica/protocol/backend/copy_in_response.rb
|
97
|
+
- lib/vertica/protocol/backend/data_row.rb
|
98
|
+
- lib/vertica/protocol/backend/empty_query_response.rb
|
99
|
+
- lib/vertica/protocol/backend/error_response.rb
|
100
|
+
- lib/vertica/protocol/backend/no_data.rb
|
101
|
+
- lib/vertica/protocol/backend/notice_response.rb
|
102
|
+
- lib/vertica/protocol/backend/parameter_description.rb
|
103
|
+
- lib/vertica/protocol/backend/parameter_status.rb
|
104
|
+
- lib/vertica/protocol/backend/parse_complete.rb
|
105
|
+
- lib/vertica/protocol/backend/portal_suspended.rb
|
106
|
+
- lib/vertica/protocol/backend/ready_for_query.rb
|
107
|
+
- lib/vertica/protocol/backend/row_description.rb
|
108
|
+
- lib/vertica/protocol/backend/unknown.rb
|
109
|
+
- lib/vertica/protocol/frontend/bind.rb
|
110
|
+
- lib/vertica/protocol/frontend/cancel_request.rb
|
111
|
+
- lib/vertica/protocol/frontend/close.rb
|
112
|
+
- lib/vertica/protocol/frontend/copy_data.rb
|
113
|
+
- lib/vertica/protocol/frontend/copy_done.rb
|
114
|
+
- lib/vertica/protocol/frontend/copy_fail.rb
|
115
|
+
- lib/vertica/protocol/frontend/describe.rb
|
116
|
+
- lib/vertica/protocol/frontend/execute.rb
|
117
|
+
- lib/vertica/protocol/frontend/flush.rb
|
118
|
+
- lib/vertica/protocol/frontend/parse.rb
|
119
|
+
- lib/vertica/protocol/frontend/password.rb
|
120
|
+
- lib/vertica/protocol/frontend/query.rb
|
121
|
+
- lib/vertica/protocol/frontend/ssl_request.rb
|
122
|
+
- lib/vertica/protocol/frontend/startup.rb
|
123
|
+
- lib/vertica/protocol/frontend/sync.rb
|
124
|
+
- lib/vertica/protocol/frontend/terminate.rb
|
125
|
+
- lib/vertica/protocol/message.rb
|
112
126
|
- lib/vertica/query.rb
|
113
127
|
- lib/vertica/result.rb
|
128
|
+
- lib/vertica/row.rb
|
129
|
+
- lib/vertica/row_description.rb
|
114
130
|
- lib/vertica/version.rb
|
115
131
|
- test/connection.yml.example
|
116
|
-
- test/functional/
|
117
|
-
- test/functional/
|
118
|
-
- test/functional/
|
132
|
+
- test/functional/functional_connection_test.rb
|
133
|
+
- test/functional/functional_query_test.rb
|
134
|
+
- test/functional/functional_value_conversion_test.rb
|
119
135
|
- test/resources/test_ruby_vertica_table.csv
|
120
136
|
- test/test_helper.rb
|
121
137
|
- test/unit/backend_message_test.rb
|
122
138
|
- test/unit/column_test.rb
|
123
139
|
- test/unit/frontend_message_test.rb
|
124
140
|
- test/unit/quoting_test.rb
|
141
|
+
- test/unit/result_test.rb
|
142
|
+
- test/unit/row_description_test.rb
|
143
|
+
- test/unit/row_test.rb
|
125
144
|
- vagrant/Vagrantfile
|
126
145
|
- vagrant/setup_vertica.sh
|
127
146
|
- vertica.gemspec
|
@@ -140,9 +159,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
140
159
|
version: '0'
|
141
160
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
161
|
requirements:
|
143
|
-
- - '
|
162
|
+
- - '>'
|
144
163
|
- !ruby/object:Gem::Version
|
145
|
-
version:
|
164
|
+
version: 1.3.1
|
146
165
|
requirements: []
|
147
166
|
rubyforge_project:
|
148
167
|
rubygems_version: 2.0.14.1
|
@@ -151,13 +170,16 @@ specification_version: 4
|
|
151
170
|
summary: Pure Ruby library for interacting with Vertica
|
152
171
|
test_files:
|
153
172
|
- test/connection.yml.example
|
154
|
-
- test/functional/
|
155
|
-
- test/functional/
|
156
|
-
- test/functional/
|
173
|
+
- test/functional/functional_connection_test.rb
|
174
|
+
- test/functional/functional_query_test.rb
|
175
|
+
- test/functional/functional_value_conversion_test.rb
|
157
176
|
- test/resources/test_ruby_vertica_table.csv
|
158
177
|
- test/test_helper.rb
|
159
178
|
- test/unit/backend_message_test.rb
|
160
179
|
- test/unit/column_test.rb
|
161
180
|
- test/unit/frontend_message_test.rb
|
162
181
|
- test/unit/quoting_test.rb
|
182
|
+
- test/unit/result_test.rb
|
183
|
+
- test/unit/row_description_test.rb
|
184
|
+
- test/unit/row_test.rb
|
163
185
|
has_rdoc:
|
@@ -1,34 +0,0 @@
|
|
1
|
-
|
2
|
-
module Vertica
|
3
|
-
module Messages
|
4
|
-
class Password < FrontendMessage
|
5
|
-
message_id 'p'
|
6
|
-
|
7
|
-
def initialize(password, auth_method = nil, options = {})
|
8
|
-
@password = password
|
9
|
-
@auth_method = auth_method || Vertica::Messages::Authentication::CLEARTEXT_PASSWORD
|
10
|
-
@options = options
|
11
|
-
end
|
12
|
-
|
13
|
-
def encoded_password
|
14
|
-
case @auth_method
|
15
|
-
when Vertica::Messages::Authentication::CLEARTEXT_PASSWORD
|
16
|
-
@password
|
17
|
-
when Vertica::Messages::Authentication::CRYPT_PASSWORD
|
18
|
-
@password.crypt(@options[:salt])
|
19
|
-
when Vertica::Messages::Authentication::MD5_PASSWORD
|
20
|
-
require 'digest/md5'
|
21
|
-
@password = Digest::MD5.hexdigest(@password + @options[:user])
|
22
|
-
@password = Digest::MD5.hexdigest(@password + @options[:salt])
|
23
|
-
@password = 'md5' + @password
|
24
|
-
else
|
25
|
-
raise ArgumentError.new("unsupported authentication method: #{@auth_method}")
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def to_bytes
|
30
|
-
message_string [encoded_password].pack('Z*')
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,79 +0,0 @@
|
|
1
|
-
module Vertica
|
2
|
-
module Messages
|
3
|
-
|
4
|
-
class Message
|
5
|
-
def self.message_id(message_id)
|
6
|
-
self.send(:define_method, :message_id) { message_id }
|
7
|
-
end
|
8
|
-
|
9
|
-
def message_string(msg)
|
10
|
-
msg = msg.join if msg.is_a?(Array)
|
11
|
-
message_size = [4 + msg.bytesize].pack('N')
|
12
|
-
message_id ? "#{message_id}#{message_size}#{msg}" : "#{message_size}#{msg}"
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
class BackendMessage < Message
|
17
|
-
MessageIdMap = {}
|
18
|
-
|
19
|
-
def self.factory(type, data)
|
20
|
-
#puts "factory reading message #{type} #{size} #{type.class}"
|
21
|
-
if klass = MessageIdMap[type] #explicitly use the char value, for 1.9 compat
|
22
|
-
klass.new data
|
23
|
-
else
|
24
|
-
Messages::Unknown.new type, data
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.message_id(message_id)
|
29
|
-
super
|
30
|
-
MessageIdMap[message_id] = self #explicitly use the char value, for 1.9 compat
|
31
|
-
end
|
32
|
-
|
33
|
-
def initialize(data)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
class FrontendMessage < Message
|
38
|
-
def to_bytes
|
39
|
-
message_string ''
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
require 'vertica/messages/backend_messages/authentication'
|
46
|
-
require 'vertica/messages/backend_messages/backend_key_data'
|
47
|
-
require 'vertica/messages/backend_messages/bind_complete'
|
48
|
-
require 'vertica/messages/backend_messages/close_complete'
|
49
|
-
require 'vertica/messages/backend_messages/command_complete'
|
50
|
-
require 'vertica/messages/backend_messages/data_row'
|
51
|
-
require 'vertica/messages/backend_messages/empty_query_response'
|
52
|
-
require 'vertica/messages/backend_messages/notice_response'
|
53
|
-
require 'vertica/messages/backend_messages/error_response'
|
54
|
-
require 'vertica/messages/backend_messages/no_data'
|
55
|
-
require 'vertica/messages/backend_messages/parameter_description'
|
56
|
-
require 'vertica/messages/backend_messages/parameter_status'
|
57
|
-
require 'vertica/messages/backend_messages/parse_complete'
|
58
|
-
require 'vertica/messages/backend_messages/portal_suspended'
|
59
|
-
require 'vertica/messages/backend_messages/ready_for_query'
|
60
|
-
require 'vertica/messages/backend_messages/row_description'
|
61
|
-
require 'vertica/messages/backend_messages/copy_in_response'
|
62
|
-
require 'vertica/messages/backend_messages/unknown'
|
63
|
-
|
64
|
-
require 'vertica/messages/frontend_messages/bind'
|
65
|
-
require 'vertica/messages/frontend_messages/cancel_request'
|
66
|
-
require 'vertica/messages/frontend_messages/close'
|
67
|
-
require 'vertica/messages/frontend_messages/describe'
|
68
|
-
require 'vertica/messages/frontend_messages/execute'
|
69
|
-
require 'vertica/messages/frontend_messages/flush'
|
70
|
-
require 'vertica/messages/frontend_messages/parse'
|
71
|
-
require 'vertica/messages/frontend_messages/password'
|
72
|
-
require 'vertica/messages/frontend_messages/query'
|
73
|
-
require 'vertica/messages/frontend_messages/ssl_request'
|
74
|
-
require 'vertica/messages/frontend_messages/startup'
|
75
|
-
require 'vertica/messages/frontend_messages/sync'
|
76
|
-
require 'vertica/messages/frontend_messages/terminate'
|
77
|
-
require 'vertica/messages/frontend_messages/copy_done'
|
78
|
-
require 'vertica/messages/frontend_messages/copy_fail'
|
79
|
-
require 'vertica/messages/frontend_messages/copy_data'
|
@@ -1,128 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class ConnectionTest < Minitest::Test
|
4
|
-
def test_opening_and_closing_connection
|
5
|
-
connection = Vertica::Connection.new(TEST_CONNECTION_HASH)
|
6
|
-
assert_valid_open_connection(connection)
|
7
|
-
|
8
|
-
connection.close
|
9
|
-
assert_valid_closed_connection(connection)
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_connection_with_ssl
|
13
|
-
connection = Vertica::Connection.new(TEST_CONNECTION_HASH.merge(:ssl => true))
|
14
|
-
assert_valid_open_connection(connection)
|
15
|
-
assert connection.ssl?
|
16
|
-
|
17
|
-
connection.close
|
18
|
-
assert_valid_closed_connection(connection)
|
19
|
-
assert !connection.ssl?
|
20
|
-
|
21
|
-
rescue Vertica::Error::SSLNotSupported
|
22
|
-
puts "\nThe test server doesn't support SSL, so SSL connections could not be tested."
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_reset_connection
|
26
|
-
connection = Vertica::Connection.new(TEST_CONNECTION_HASH)
|
27
|
-
original_backend_pid, original_backend_key = connection.backend_pid, connection.backend_key
|
28
|
-
|
29
|
-
connection.reset_connection
|
30
|
-
|
31
|
-
assert_valid_open_connection(connection)
|
32
|
-
assert original_backend_pid != connection.backend_pid
|
33
|
-
assert original_backend_key != connection.backend_key
|
34
|
-
assert_equal :no_transaction, connection.transaction_status
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_interruptable_connection
|
38
|
-
connection = Vertica::Connection.new(TEST_CONNECTION_HASH.merge(:interruptable => true))
|
39
|
-
assert connection.interruptable?, "The connection should be interruptable!"
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_new_with_error_response
|
43
|
-
assert_raises Vertica::Error::ConnectionError do
|
44
|
-
Vertica::Connection.new(TEST_CONNECTION_HASH.merge('database' => 'nonexistant_db'))
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_connection_inspect_should_not_print_password
|
49
|
-
connection = Vertica::Connection.new(TEST_CONNECTION_HASH)
|
50
|
-
inspected_string = connection.inspect
|
51
|
-
assert inspected_string !~ /:password=>#{TEST_CONNECTION_HASH[:password]}/
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_connection_timed_out_error
|
55
|
-
connection = Vertica::Connection.new(TEST_CONNECTION_HASH)
|
56
|
-
connection.options[:read_timeout] = 0.01
|
57
|
-
assert_raises(Vertica::Error::TimedOutError) {connection.query("SELECT SLEEP(1)")}
|
58
|
-
assert connection.closed?
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_automatically_reconnects
|
62
|
-
connection = Vertica::Connection.new(TEST_CONNECTION_HASH)
|
63
|
-
connection.close
|
64
|
-
assert_equal(1, connection.query("SELECT 1").the_value)
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_socket_write_error
|
68
|
-
connection = Vertica::Connection.new(TEST_CONNECTION_HASH)
|
69
|
-
class << connection.socket
|
70
|
-
def write_nonblock(foo)
|
71
|
-
raise Errno::ETIMEDOUT
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
assert_raises(Vertica::Error::ConnectionError) { connection.query('select 1') }
|
76
|
-
assert connection.closed?
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_socket_read_error
|
80
|
-
connection = Vertica::Connection.new(TEST_CONNECTION_HASH)
|
81
|
-
class << connection.socket
|
82
|
-
def read_nonblock(foo)
|
83
|
-
raise Errno::ETIMEDOUT
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
assert_raises(Vertica::Error::ConnectionError) {connection.query('select 1')}
|
88
|
-
assert connection.closed?
|
89
|
-
end
|
90
|
-
|
91
|
-
def test_concurrent_access
|
92
|
-
connection = Vertica::Connection.new(TEST_CONNECTION_HASH)
|
93
|
-
t = Thread.new { connection.query("SELECT sleep(1)") }
|
94
|
-
sleep(0.1)
|
95
|
-
|
96
|
-
assert connection.busy?, "The connection should be busy while executing a query"
|
97
|
-
assert_raises(Vertica::Error::SynchronizeError) { connection.query('SELECT 1') }
|
98
|
-
|
99
|
-
t.join
|
100
|
-
assert connection.ready_for_query?, "The connection should be available again."
|
101
|
-
connection.close
|
102
|
-
end
|
103
|
-
|
104
|
-
private
|
105
|
-
|
106
|
-
def assert_valid_open_connection(connection)
|
107
|
-
assert connection.opened?
|
108
|
-
assert !connection.closed?
|
109
|
-
|
110
|
-
# connection variables
|
111
|
-
assert connection.backend_pid
|
112
|
-
assert connection.backend_key
|
113
|
-
assert connection.transaction_status
|
114
|
-
|
115
|
-
# parameters
|
116
|
-
assert connection.parameters.kind_of?(Hash)
|
117
|
-
assert connection.parameters.include?('server_version')
|
118
|
-
end
|
119
|
-
|
120
|
-
def assert_valid_closed_connection(connection)
|
121
|
-
assert !connection.opened?
|
122
|
-
assert connection.closed?
|
123
|
-
assert_equal({}, connection.parameters)
|
124
|
-
assert_nil connection.backend_pid
|
125
|
-
assert_nil connection.backend_key
|
126
|
-
assert_nil connection.transaction_status
|
127
|
-
end
|
128
|
-
end
|