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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c6de2a573aa133bee0d1d9401b019c1740152625
4
- data.tar.gz: f956e6bbf6bdb2692b2da104aaccb67a0fcb01e8
3
+ metadata.gz: 50ef468b6baf6f10daa58ed8d4913317caed79f4
4
+ data.tar.gz: 0eff38ddec5f5a4a5b07adae1bff244537f487c7
5
5
  SHA512:
6
- metadata.gz: 08efdcb4b4da96bfeeb0f52886c8290645233ff58dde635ff8a82a14ce0b13e57879612ca413ea4a5333b7e174519fafe0720d4204a58a357d23fa22b8750d70
7
- data.tar.gz: 2fcdfcf3f3ad2f627b6a2577864f61c7d0f2d9c0801d5d5bd2286f95da8a3c3f976f9028b5bf6ea01bedf9f3cc18c1e5bfaac780a14ef08157dca2191a509708
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.status == 200 && !response.body.to_s.empty?
163
- return response.body
164
- end
165
+ if response
166
+ if response.status == 200 && !response.body.to_s.empty?
167
+ return response.body
168
+ end
165
169
 
166
- if response.status != 503 # retry only if 503 Service Unavailable
167
- # deterministic error
168
- @exception = PrestoHttpError.new(response.status, "Presto API error at #{uri} returned #{response.status}: #{response.body}")
169
- raise @exception
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
@@ -15,6 +15,6 @@
15
15
  #
16
16
  module Presto
17
17
  module Client
18
- VERSION = "0.4.6"
18
+ VERSION = "0.4.7"
19
19
  end
20
20
  end
@@ -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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: presto-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sadayuki Furuhashi