presto-client 0.4.6 → 0.4.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/presto/client/statement_client.rb +12 -7
- data/lib/presto/client/version.rb +1 -1
- data/spec/statement_client_spec.rb +34 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50ef468b6baf6f10daa58ed8d4913317caed79f4
|
4
|
+
data.tar.gz: 0eff38ddec5f5a4a5b07adae1bff244537f487c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1b162c629fef338f79cce11b704557266491b434bedef53e3b2d3960e2f79ebfc352e5b1b93d52d520fbe2508985e5dd54fbf2c731292ac11780bb9fb63efc6
|
7
|
+
data.tar.gz: d6dbd80fed2869cab60fc26d232bbdeee8c678b7441e75387d3706bf39aad87f1aef332f40ba519825d0096e3b71732562d27545dac68ddbf765859cbc0408ff
|
@@ -154,19 +154,24 @@ module Presto::Client
|
|
154
154
|
begin
|
155
155
|
begin
|
156
156
|
response = @faraday.get(uri)
|
157
|
+
rescue Faraday::Error::TimeoutError, Faraday::Error::ConnectionFailed
|
158
|
+
# temporally error to retry
|
159
|
+
response = nil
|
157
160
|
rescue => e
|
158
161
|
@exception = e
|
159
162
|
raise @exception
|
160
163
|
end
|
161
164
|
|
162
|
-
if response
|
163
|
-
|
164
|
-
|
165
|
+
if response
|
166
|
+
if response.status == 200 && !response.body.to_s.empty?
|
167
|
+
return response.body
|
168
|
+
end
|
165
169
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
+
if response.status != 503 # retry only if 503 Service Unavailable
|
171
|
+
# deterministic error
|
172
|
+
@exception = PrestoHttpError.new(response.status, "Presto API error at #{uri} returned #{response.status}: #{response.body}")
|
173
|
+
raise @exception
|
174
|
+
end
|
170
175
|
end
|
171
176
|
|
172
177
|
attempts += 1
|
@@ -41,5 +41,39 @@ describe Presto::Client::StatementClient do
|
|
41
41
|
faraday = Faraday.new(url: "http://localhost")
|
42
42
|
StatementClient.new(faraday, query, options)
|
43
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
|
+
}).to_return(body: lambda{|req|if retry_p; response_json.to_json; else; retry_p=true; raise Timeout::Error.new("execution expired"); end })
|
71
|
+
|
72
|
+
faraday = Faraday.new(url: "http://localhost")
|
73
|
+
sc = StatementClient.new(faraday, query, options.merge(http_open_timeout: 1))
|
74
|
+
sc.has_next?.should be_true
|
75
|
+
sc.advance.should be_true
|
76
|
+
retry_p.should be_true
|
77
|
+
end
|
44
78
|
end
|
45
79
|
|