presto-client-legacy 0.4.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,183 @@
1
+ require 'spec_helper'
2
+
3
+ describe PrestoLegacy::Client::StatementClient do
4
+ let :options do
5
+ {
6
+ server: "localhost",
7
+ user: "frsyuki",
8
+ catalog: "native",
9
+ schema: "default",
10
+ time_zone: "US/Pacific",
11
+ language: "ja_JP",
12
+ properties: {"hello" => "world", "name"=>"value"},
13
+ debug: true,
14
+ }
15
+ end
16
+
17
+ let :query do
18
+ "select * from sys.node"
19
+ end
20
+
21
+ let :response_json do
22
+ {
23
+ id: "queryid",
24
+ stats: {}
25
+ }
26
+ end
27
+
28
+ it "sets headers" do
29
+ stub_request(:post, "localhost/v1/statement").
30
+ with(body: query,
31
+ headers: {
32
+ "User-Agent" => "presto-ruby/#{VERSION}",
33
+ "X-Presto-Catalog" => options[:catalog],
34
+ "X-Presto-Schema" => options[:schema],
35
+ "X-Presto-User" => options[:user],
36
+ "X-Presto-Language" => options[:language],
37
+ "X-Presto-Time-Zone" => options[:time_zone],
38
+ "X-Presto-Session" => options[:properties].map {|k,v| "#{k}=#{v}"}.join("\r\nX-Presto-Session: ")
39
+ }).to_return(body: response_json.to_json)
40
+
41
+ faraday = Faraday.new(url: "http://localhost")
42
+ StatementClient.new(faraday, query, options)
43
+ end
44
+
45
+ let :response_json2 do
46
+ {
47
+ id: "queryid",
48
+ nextUri: 'http://localhost/v1/next_uri',
49
+ stats: {}
50
+ }
51
+ end
52
+
53
+ it "sets headers" do
54
+ retry_p = false
55
+ stub_request(:post, "localhost/v1/statement").
56
+ with(body: query,
57
+ headers: {
58
+ "User-Agent" => "presto-ruby/#{VERSION}",
59
+ "X-Presto-Catalog" => options[:catalog],
60
+ "X-Presto-Schema" => options[:schema],
61
+ "X-Presto-User" => options[:user],
62
+ "X-Presto-Language" => options[:language],
63
+ "X-Presto-Time-Zone" => options[:time_zone],
64
+ "X-Presto-Session" => options[:properties].map {|k,v| "#{k}=#{v}"}.join("\r\nX-Presto-Session: ")
65
+ }).to_return(body: response_json2.to_json)
66
+
67
+ stub_request(:get, "localhost/v1/next_uri").
68
+ with(headers: {
69
+ "User-Agent" => "presto-ruby/#{VERSION}",
70
+ "X-Presto-Catalog" => options[:catalog],
71
+ "X-Presto-Schema" => options[:schema],
72
+ "X-Presto-User" => options[:user],
73
+ "X-Presto-Language" => options[:language],
74
+ "X-Presto-Time-Zone" => options[:time_zone],
75
+ "X-Presto-Session" => options[:properties].map {|k,v| "#{k}=#{v}"}.join("\r\nX-Presto-Session: ")
76
+ }).to_return(body: lambda{|req|if retry_p; response_json.to_json; else; retry_p=true; raise Timeout::Error.new("execution expired"); end })
77
+
78
+ faraday = Faraday.new(url: "http://localhost")
79
+ sc = StatementClient.new(faraday, query, options.merge(http_open_timeout: 1))
80
+ sc.has_next?.should be_true
81
+ sc.advance.should be_true
82
+ retry_p.should be_true
83
+ end
84
+
85
+ it "decodes DeleteHandle" do
86
+ dh = Models::DeleteHandle.decode({
87
+ "handle" => {
88
+ "connectorId" => "c1",
89
+ "connectorHandle" => {},
90
+ }
91
+ })
92
+ dh.handle.should be_a_kind_of Models::TableHandle
93
+ dh.handle.connector_id.should == "c1"
94
+ dh.handle.connector_handle.should == {}
95
+ end
96
+
97
+ it "validates models" do
98
+ lambda do
99
+ Models::DeleteHandle.decode({
100
+ "handle" => "invalid"
101
+ })
102
+ end.should raise_error(TypeError, /String to Hash/)
103
+ end
104
+
105
+ describe "ssl" do
106
+ it "is disabled by default" do
107
+ f = Query.__send__(:faraday_client, {
108
+ server: "localhost",
109
+ })
110
+ f.url_prefix.to_s.should == "http://localhost/"
111
+ end
112
+
113
+ it "is enabled with ssl: true" do
114
+ f = Query.__send__(:faraday_client, {
115
+ server: "localhost",
116
+ ssl: true,
117
+ })
118
+ f.url_prefix.to_s.should == "https://localhost/"
119
+ f.ssl.verify?.should == true
120
+ end
121
+
122
+ it "is enabled with ssl: {verify: false}" do
123
+ f = Query.__send__(:faraday_client, {
124
+ server: "localhost",
125
+ ssl: {verify: false}
126
+ })
127
+ f.url_prefix.to_s.should == "https://localhost/"
128
+ f.ssl.verify?.should == false
129
+ end
130
+
131
+ it "rejects invalid ssl: verify: object" do
132
+ lambda do
133
+ f = Query.__send__(:faraday_client, {
134
+ server: "localhost",
135
+ ssl: {verify: "??"}
136
+ })
137
+ end.should raise_error(ArgumentError, /String/)
138
+ end
139
+
140
+ it "is enabled with ssl: Hash" do
141
+ require 'openssl'
142
+
143
+ ssl = {
144
+ ca_file: "/path/to/dummy.pem",
145
+ ca_path: "/path/to/pemdir",
146
+ cert_store: OpenSSL::X509::Store.new,
147
+ client_cert: OpenSSL::X509::Certificate.new,
148
+ client_key: OpenSSL::PKey::DSA.new,
149
+ }
150
+
151
+ f = Query.__send__(:faraday_client, {
152
+ server: "localhost",
153
+ ssl: ssl,
154
+ })
155
+
156
+ f.url_prefix.to_s.should == "https://localhost/"
157
+ f.ssl.verify?.should == true
158
+ f.ssl.ca_file.should == ssl[:ca_file]
159
+ f.ssl.ca_path.should == ssl[:ca_path]
160
+ f.ssl.cert_store.should == ssl[:cert_store]
161
+ f.ssl.client_cert.should == ssl[:client_cert]
162
+ f.ssl.client_key.should == ssl[:client_key]
163
+ end
164
+
165
+ it "rejects an invalid string" do
166
+ lambda do
167
+ Query.__send__(:faraday_client, {
168
+ server: "localhost",
169
+ ssl: '??',
170
+ })
171
+ end.should raise_error(ArgumentError, /String/)
172
+ end
173
+
174
+ it "rejects an integer" do
175
+ lambda do
176
+ Query.__send__(:faraday_client, {
177
+ server: "localhost",
178
+ ssl: 3,
179
+ })
180
+ end.should raise_error(ArgumentError, /:ssl/)
181
+ end
182
+ end
183
+ end
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: presto-client-legacy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.17
5
+ platform: ruby
6
+ authors:
7
+ - Sadayuki Furuhash
8
+ - Kai Sasaki
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-08-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: 0.8.8
21
+ - - "<"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.10.0
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ version: 0.8.8
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.10.0
34
+ - !ruby/object:Gem::Dependency
35
+ name: multi_json
36
+ requirement: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ type: :runtime
42
+ prerelease: false
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ - !ruby/object:Gem::Dependency
49
+ name: rake
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.2
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.2
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.13.0
69
+ type: :development
70
+ prerelease: false
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 2.13.0
76
+ - !ruby/object:Gem::Dependency
77
+ name: webmock
78
+ requirement: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.16.1
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.16.1
90
+ - !ruby/object:Gem::Dependency
91
+ name: simplecov
92
+ requirement: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.10.0
97
+ type: :development
98
+ prerelease: false
99
+ version_requirements: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.10.0
104
+ description: Presto client library for legacy presto version
105
+ email:
106
+ - sf@treasure-data.com
107
+ - lewuathe@me.com
108
+ executables: []
109
+ extensions: []
110
+ extra_rdoc_files: []
111
+ files:
112
+ - ".gitignore"
113
+ - ".travis.yml"
114
+ - ChangeLog
115
+ - Gemfile
116
+ - README.md
117
+ - Rakefile
118
+ - lib/presto-client-legacy.rb
119
+ - lib/presto/client.rb
120
+ - lib/presto/client/client.rb
121
+ - lib/presto/client/errors.rb
122
+ - lib/presto/client/models.rb
123
+ - lib/presto/client/query.rb
124
+ - lib/presto/client/statement_client.rb
125
+ - lib/presto/client/version.rb
126
+ - modelgen/modelgen.rb
127
+ - modelgen/models.rb
128
+ - modelgen/presto_models.rb
129
+ - presto-client-legacy.gemspec
130
+ - spec/client_spec.rb
131
+ - spec/spec_helper.rb
132
+ - spec/statement_client_spec.rb
133
+ homepage: https://github.com/Lewuathe/presto-client-ruby
134
+ licenses:
135
+ - Apache-2.0
136
+ metadata: {}
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: 1.9.1
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubyforge_project:
153
+ rubygems_version: 2.5.1
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: Presto client library for legacy presto version (before 0.151)
157
+ test_files:
158
+ - spec/client_spec.rb
159
+ - spec/spec_helper.rb
160
+ - spec/statement_client_spec.rb