td-client 1.0.0 → 1.0.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 140238f578d4cee66cc4ef09c155375719ad1c9e
4
- data.tar.gz: cc7df46122c3186fc80c99ca1911aff0bcf8c994
3
+ metadata.gz: 1319b82466ec1059629cb62dbe33cdacc0488d60
4
+ data.tar.gz: fd2b1bc6ee9211e3b225537d753bbef3a5fe6f19
5
5
  SHA512:
6
- metadata.gz: bdd1ba7cfb27afbc22a07845c06cf420afa1d9d40411137573ec2406ceeb923838a65be2e3ce7dbdc5120126a3386aa6234dca79426e9341d57e3a82ebe559d3
7
- data.tar.gz: 8045b7325a7492b35db7962ed36d3bb6895d3307990c1e43d7523e0832b9a33b7d2ac4d792a0b8284755342726c231ea994f83d0829a72a19a3b7a891789a738
6
+ metadata.gz: fa93f95456b45d53a8621f2e22a87537fc8955c59954ef52155b71b7938b67d1794e5cba4b89b9f398f7089fe49638d4e15e216b2e73c76a8505b3eab770db45
7
+ data.tar.gz: dd3ef388960816cadae765c39f705778987c2490895e36c74704a076135349b7dbacfbc8cfa123314abfa718fcef68d725a2e9009c437df00fc6d60d057fb113
@@ -272,6 +272,9 @@ module Job
272
272
  end
273
273
  end
274
274
 
275
+ class HTTPServerException < StandardError
276
+ end
277
+
275
278
  def job_result_download(job_id, format='msgpack', autodecode=true)
276
279
  client, header = new_client
277
280
  client.send_timeout = @send_timeout
@@ -305,12 +308,8 @@ module Job
305
308
  end
306
309
  when 206 # resuming
307
310
  else
308
- if res.status/100 == 5 && cumul_retry_delay < @max_cumul_retry_delay
309
- $stderr.puts "Error #{res.status}: #{get_error(res)}. Retrying after #{retry_delay} seconds..."
310
- sleep retry_delay
311
- cumul_retry_delay += retry_delay
312
- retry_delay *= 2
313
- redo
311
+ if res.status/100 == 5
312
+ raise HTTPServerException
314
313
  end
315
314
  raise_error("Get job result failed", res)
316
315
  end
@@ -331,7 +330,8 @@ module Job
331
330
 
332
331
  # completed?
333
332
  validate_content_length_with_range(response, current_total_chunk_size)
334
- rescue Errno::ECONNREFUSED, Errno::ECONNRESET, Timeout::Error, EOFError, OpenSSL::SSL::SSLError, SocketError => e
333
+ rescue Errno::ECONNREFUSED, Errno::ECONNRESET, Timeout::Error, EOFError,
334
+ OpenSSL::SSL::SSLError, SocketError, HTTPServerException => e
335
335
  if response # at least a chunk is downloaded
336
336
  if etag = response.header['ETag'][0]
337
337
  header['If-Range'] = etag
@@ -1,5 +1,5 @@
1
1
  module TreasureData
2
2
  class Client
3
- VERSION = '1.0.0'
3
+ VERSION = '1.0.1'
4
4
  end
5
5
  end
@@ -286,7 +286,7 @@ describe 'Job API' do
286
286
  expect(api.job_result(12345)).to eq ['hello', 'world']
287
287
  end
288
288
 
289
- it '200->500->206 can resume' do
289
+ it '200->206 can resume' do
290
290
  sz = packed.bytesize / 3
291
291
  stub_api_request(:get, '/v3/job/result/12345').
292
292
  with(:query => {'format' => 'msgpack'}).
@@ -297,23 +297,6 @@ describe 'Job API' do
297
297
  },
298
298
  :body => packed[0, sz]
299
299
  )
300
- stub_api_request(:get, '/v3/job/result/12345').
301
- with(
302
- :headers => {
303
- 'If-Range' => '"abcdefghijklmn"',
304
- 'Range' => "bytes=#{sz}-",
305
- },
306
- :query => {'format' => 'msgpack'}
307
- ).
308
- to_return(
309
- :status => 500,
310
- :headers => {
311
- 'Content-Length' => packed.bytesize - sz,
312
- 'Content-Range' => "bytes #{sz}-#{packed.bytesize-1}/#{packed.bytesize}",
313
- 'Etag' => '"abcdefghijklmn"',
314
- },
315
- :body => packed
316
- )
317
300
  stub_api_request(:get, '/v3/job/result/12345').
318
301
  with(
319
302
  :headers => {
@@ -783,6 +766,57 @@ describe 'Job API' do
783
766
  end
784
767
  end
785
768
 
769
+ context '500 -> 200' do
770
+ before do
771
+ sz = packed.bytesize / 3
772
+ count = 0
773
+ stub_api_request(:get, '/v3/job/result/12345').
774
+ with(:query => {'format' => format}).
775
+ to_return do
776
+ count += 1
777
+ if count == 1
778
+ {:status => 500}
779
+ else
780
+ {
781
+ :headers => {
782
+ 'Content-Encoding' => content_encoding,
783
+ 'Content-Length' => packed.bytesize,
784
+ 'Etag' => '"abcdefghijklmn"',
785
+ },
786
+ :body => packed,
787
+ }
788
+ end
789
+ end
790
+ expect(api).to receive(:sleep).once
791
+ allow($stderr).to receive(:print)
792
+ allow($stderr).to receive(:puts)
793
+ end
794
+ context 'Content-Encoding: gzip' do
795
+ let (:content_encoding){ 'gzip' }
796
+ let (:packed){ gziped }
797
+ context 'msgpack' do
798
+ let (:format){ 'msgpack' }
799
+ it { is_expected.to eq formatted }
800
+ end
801
+ context 'json' do
802
+ let (:format){ 'json' }
803
+ it { is_expected.to eq formatted }
804
+ end
805
+ end
806
+ context 'Content-Encoding: deflate' do
807
+ let (:content_encoding){ 'deflate' }
808
+ let (:packed){ deflated }
809
+ context 'msgpack' do
810
+ let (:format){ 'msgpack' }
811
+ it { is_expected.to eq formatted }
812
+ end
813
+ context 'json' do
814
+ let (:format){ 'json' }
815
+ it { is_expected.to eq formatted }
816
+ end
817
+ end
818
+ end
819
+
786
820
  context 'without autodecode' do
787
821
  before do
788
822
  sz = packed.bytesize / 3
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: td-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Treasure Data, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-20 00:00:00.000000000 Z
11
+ date: 2017-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -200,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
200
  version: '0'
201
201
  requirements: []
202
202
  rubyforge_project:
203
- rubygems_version: 2.6.8
203
+ rubygems_version: 2.6.11
204
204
  signing_key:
205
205
  specification_version: 4
206
206
  summary: Treasure Data API library for Ruby