td-client 0.8.79 → 0.8.80

Sign up to get free protection for your applications and to get access to all the features.
@@ -113,9 +113,9 @@ describe 'BulkImport API' do
113
113
  stub_api_request(:post, '/v3/bulk_loads/guess').
114
114
  with(:body => original_config.to_json).
115
115
  to_return(:body => guessed_config.to_json)
116
- api.bulk_load_guess(
116
+ expect(api.bulk_load_guess(
117
117
  original_config
118
- ).should == guessed_config
118
+ )).to eq(guessed_config)
119
119
  end
120
120
 
121
121
  it 'raises an error' do
@@ -134,23 +134,23 @@ describe 'BulkImport API' do
134
134
  with(:body => original_config.to_json).
135
135
  to_return(:status => 500, :body => guessed_config.to_json)
136
136
  begin
137
- retry_api.bulk_load_guess(
137
+ expect(retry_api.bulk_load_guess(
138
138
  original_config
139
- ).should != nil
139
+ )).to != nil
140
140
  rescue TreasureData::APIError => e
141
- e.message.should =~ /^500: BulkLoad configuration guess failed/
141
+ expect(e.message).to match(/^500: BulkLoad configuration guess failed/)
142
142
  end
143
143
  end
144
144
 
145
145
  it 'perform retries on connection failure' do
146
146
  api = retry_api
147
- api.instance_eval { @api }.stub(:post).and_raise(SocketError.new('>>'))
147
+ allow(api.instance_eval { @api }).to receive(:post).and_raise(SocketError.new('>>'))
148
148
  begin
149
149
  retry_api.bulk_load_guess(
150
150
  original_config
151
151
  )
152
152
  rescue SocketError => e
153
- e.message.should == '>> (Retried 1 times in 1 seconds)'
153
+ expect(e.message).to eq('>> (Retried 1 times in 1 seconds)')
154
154
  end
155
155
  end
156
156
  end
@@ -160,9 +160,9 @@ describe 'BulkImport API' do
160
160
  stub_api_request(:post, '/v3/bulk_loads/guess').
161
161
  with(:body => original_config.to_json).
162
162
  to_return(:body => guessed_config.to_json)
163
- api.bulk_load_guess(
163
+ expect(api.bulk_load_guess(
164
164
  original_config
165
- ).should == guessed_config
165
+ )).to eq(guessed_config)
166
166
  end
167
167
 
168
168
  it 'raises an error' do
@@ -181,23 +181,23 @@ describe 'BulkImport API' do
181
181
  with(:body => original_config.to_json).
182
182
  to_return(:status => 500, :body => guessed_config.to_json)
183
183
  begin
184
- retry_api.bulk_load_guess(
184
+ expect(retry_api.bulk_load_guess(
185
185
  original_config
186
- ).should != nil
186
+ )).to != nil
187
187
  rescue TreasureData::APIError => e
188
- e.message.should =~ /^500: BulkLoad configuration guess failed/
188
+ expect(e.message).to match(/^500: BulkLoad configuration guess failed/)
189
189
  end
190
190
  end
191
191
 
192
192
  it 'perform retries on connection failure' do
193
193
  api = retry_api
194
- api.instance_eval { @api }.stub(:post).and_raise(SocketError.new('>>'))
194
+ allow(api.instance_eval { @api }).to receive(:post).and_raise(SocketError.new('>>'))
195
195
  begin
196
196
  retry_api.bulk_load_guess(
197
197
  original_config
198
198
  )
199
199
  rescue SocketError => e
200
- e.message.should == '>> (Retried 1 times in 1 seconds)'
200
+ expect(e.message).to eq('>> (Retried 1 times in 1 seconds)')
201
201
  end
202
202
  end
203
203
  end
@@ -207,9 +207,9 @@ describe 'BulkImport API' do
207
207
  stub_api_request(:post, '/v3/bulk_loads/preview').
208
208
  with(:body => guessed_config.to_json).
209
209
  to_return(:body => preview_result.to_json)
210
- api.bulk_load_preview(
210
+ expect(api.bulk_load_preview(
211
211
  guessed_config
212
- ).should == preview_result
212
+ )).to eq(preview_result)
213
213
  end
214
214
 
215
215
  it 'raises an error' do
@@ -232,11 +232,11 @@ describe 'BulkImport API' do
232
232
  stub_api_request(:post, '/v3/job/issue/bulkload/database').
233
233
  with(:body => expected_request.to_json).
234
234
  to_return(:body => {'job_id' => 12345}.to_json)
235
- api.bulk_load_issue(
235
+ expect(api.bulk_load_issue(
236
236
  'database',
237
237
  'table',
238
238
  guessed_config
239
- ).should == '12345'
239
+ )).to eq('12345')
240
240
  end
241
241
  end
242
242
 
@@ -245,14 +245,14 @@ describe 'BulkImport API' do
245
245
  stub_api_request(:get, '/v3/bulk_loads').
246
246
  to_return(:body => [bulk_load_session, bulk_load_session].to_json)
247
247
  result = api.bulk_load_list
248
- result.size.should == 2
249
- result.first.should == bulk_load_session
248
+ expect(result.size).to eq(2)
249
+ expect(result.first).to eq(bulk_load_session)
250
250
  end
251
251
 
252
252
  it 'returns empty' do
253
253
  stub_api_request(:get, '/v3/bulk_loads').
254
254
  to_return(:body => [].to_json)
255
- api.bulk_load_list.size.should == 0
255
+ expect(api.bulk_load_list.size).to eq(0)
256
256
  end
257
257
  end
258
258
 
@@ -268,7 +268,7 @@ describe 'BulkImport API' do
268
268
  stub_api_request(:post, '/v3/bulk_loads').
269
269
  with(:body => expected_request.to_json).
270
270
  to_return(:body => bulk_load_session.to_json)
271
- api.bulk_load_create(
271
+ expect(api.bulk_load_create(
272
272
  'nahi_test_1',
273
273
  'database',
274
274
  'table',
@@ -278,7 +278,7 @@ describe 'BulkImport API' do
278
278
  timezone: 'Asia/Tokyo',
279
279
  delay: 3600
280
280
  }
281
- ).should == bulk_load_session
281
+ )).to eq(bulk_load_session)
282
282
  end
283
283
 
284
284
  it 'accepts empty option' do
@@ -289,12 +289,12 @@ describe 'BulkImport API' do
289
289
  stub_api_request(:post, '/v3/bulk_loads').
290
290
  with(:body => expected_request.to_json).
291
291
  to_return(:body => bulk_load_session.to_json)
292
- api.bulk_load_create(
292
+ expect(api.bulk_load_create(
293
293
  'nahi_test_1',
294
294
  'database',
295
295
  'table',
296
296
  guessed_config
297
- ).should == bulk_load_session
297
+ )).to eq(bulk_load_session)
298
298
  end
299
299
 
300
300
  it 'accepts time_column option' do
@@ -306,7 +306,7 @@ describe 'BulkImport API' do
306
306
  stub_api_request(:post, '/v3/bulk_loads').
307
307
  with(:body => expected_request.to_json).
308
308
  to_return(:body => bulk_load_session.to_json)
309
- api.bulk_load_create(
309
+ expect(api.bulk_load_create(
310
310
  'nahi_test_1',
311
311
  'database',
312
312
  'table',
@@ -314,7 +314,7 @@ describe 'BulkImport API' do
314
314
  {
315
315
  time_column: 'c0'
316
316
  }
317
- ).should == bulk_load_session
317
+ )).to eq(bulk_load_session)
318
318
  end
319
319
  end
320
320
 
@@ -322,7 +322,7 @@ describe 'BulkImport API' do
322
322
  it 'returns bulk_load_session' do
323
323
  stub_api_request(:get, '/v3/bulk_loads/nahi_test_1').
324
324
  to_return(:body => bulk_load_session.to_json)
325
- api.bulk_load_show('nahi_test_1').should == bulk_load_session
325
+ expect(api.bulk_load_show('nahi_test_1')).to eq(bulk_load_session)
326
326
  end
327
327
  end
328
328
 
@@ -331,10 +331,10 @@ describe 'BulkImport API' do
331
331
  stub_api_request(:put, '/v3/bulk_loads/nahi_test_1').
332
332
  with(:body => bulk_load_session.to_json).
333
333
  to_return(:body => bulk_load_session.to_json)
334
- api.bulk_load_update(
334
+ expect(api.bulk_load_update(
335
335
  'nahi_test_1',
336
336
  bulk_load_session
337
- ).should == bulk_load_session
337
+ )).to eq(bulk_load_session)
338
338
  end
339
339
  end
340
340
 
@@ -342,7 +342,7 @@ describe 'BulkImport API' do
342
342
  it 'returns updated bulk_load_session' do
343
343
  stub_api_request(:delete, '/v3/bulk_loads/nahi_test_1').
344
344
  to_return(:body => bulk_load_session.to_json)
345
- api.bulk_load_delete('nahi_test_1').should == bulk_load_session
345
+ expect(api.bulk_load_delete('nahi_test_1')).to eq(bulk_load_session)
346
346
  end
347
347
  end
348
348
 
@@ -351,8 +351,8 @@ describe 'BulkImport API' do
351
351
  stub_api_request(:get, '/v3/bulk_loads/nahi_test_1/jobs').
352
352
  to_return(:body => [bulk_load_job, bulk_load_job].to_json)
353
353
  result = api.bulk_load_history('nahi_test_1')
354
- result.size.should == 2
355
- result.first.should == bulk_load_job
354
+ expect(result.size).to eq(2)
355
+ expect(result.first).to eq(bulk_load_job)
356
356
  end
357
357
  end
358
358
 
@@ -361,7 +361,7 @@ describe 'BulkImport API' do
361
361
  stub_api_request(:post, '/v3/bulk_loads/nahi_test_1/jobs').
362
362
  with(:body => '{}').
363
363
  to_return(:body => {'job_id' => 12345}.to_json)
364
- api.bulk_load_run('nahi_test_1').should == '12345'
364
+ expect(api.bulk_load_run('nahi_test_1')).to eq('12345')
365
365
  end
366
366
 
367
367
  it 'accepts scheduled_time' do
@@ -369,7 +369,7 @@ describe 'BulkImport API' do
369
369
  stub_api_request(:post, '/v3/bulk_loads/nahi_test_1/jobs').
370
370
  with(:body => {scheduled_time: now.to_s}.to_json).
371
371
  to_return(:body => {'job_id' => 12345}.to_json)
372
- api.bulk_load_run('nahi_test_1', now).should == '12345'
372
+ expect(api.bulk_load_run('nahi_test_1', now)).to eq('12345')
373
373
  end
374
374
  end
375
375
 
@@ -18,7 +18,7 @@ describe 'Database API' do
18
18
  stub_api_request(:post, "/v3/database/create/#{e(db_name)}").
19
19
  to_return(:body => {'database' => db_name}.to_json)
20
20
 
21
- api.create_database(db_name).should be true
21
+ expect(api.create_database(db_name)).to be true
22
22
  end
23
23
 
24
24
  it 'should return 400 error with invalid name' do
@@ -20,7 +20,7 @@ describe 'Export API' do
20
20
  stub_api_request(:post, "/v3/export/run/#{e(db_name)}/#{e(table_name)}").with(:body => params.merge('storage_type' => storage_type)).
21
21
  to_return(:body => {'database' => db_name, 'job_id' => '1', 'debug' => {}}.to_json)
22
22
 
23
- api.export(db_name, table_name, storage_type, params).should == '1'
23
+ expect(api.export(db_name, table_name, storage_type, params)).to eq('1')
24
24
  end
25
25
 
26
26
  it 'should return 400 error with invalid storage type' do
@@ -25,7 +25,7 @@ describe 'Import API' do
25
25
  with(:body => '12345').
26
26
  to_return(:body => '{"elapsed_time":"1.23"}')
27
27
  File.open(t.path) do |f|
28
- api.import('db', 'table', 'format', f, 5, 'unique_id').should == 1.23
28
+ expect(api.import('db', 'table', 'format', f, 5, 'unique_id')).to eq(1.23)
29
29
  end
30
30
  end
31
31
 
@@ -38,7 +38,7 @@ describe 'Import API' do
38
38
  with(:body => '12345').
39
39
  to_return(:body => '{"elapsed_time":"1.23"}')
40
40
  File.open(t.path) do |f|
41
- api.import('db', 'table', 'format', f, 5).should == 1.23
41
+ expect(api.import('db', 'table', 'format', f, 5)).to eq(1.23)
42
42
  end
43
43
  end
44
44
 
@@ -51,7 +51,7 @@ describe 'Import API' do
51
51
  with(:body => '12345').
52
52
  to_return(:body => '{"elapsed_time":"1.23"}')
53
53
  File.open(t.path) do |f|
54
- api_old.import('db', 'table', 'format', f, 5).should == 1.23
54
+ expect(api_old.import('db', 'table', 'format', f, 5)).to eq(1.23)
55
55
  end
56
56
  end
57
57
 
@@ -20,7 +20,7 @@ describe 'Job API' do
20
20
  it 'should returns 20 jobs by default' do
21
21
  stub_api_request(:get, "/v3/job/list", :query => {'from' => '0'}).to_return(:body => {'jobs' => raw_jobs}.to_json)
22
22
  jobs = api.list_jobs
23
- jobs.size.should == 20
23
+ expect(jobs.size).to eq(20)
24
24
  end
25
25
 
26
26
  (0...MAX_JOB).each {|i|
@@ -32,20 +32,20 @@ describe 'Job API' do
32
32
  jobs[i..i].map {|job_id, type, status, query, start_at, end_at, cpu_time,
33
33
  result_size, result_url, priority, retry_limit, org, db,
34
34
  duration|
35
- job_id.should == job['job_id']
36
- type.should == job['type']
37
- status.should == job['status']
38
- query.should == job['query']
39
- start_at.should == job['start_at']
40
- end_at.should == job['end_at']
41
- cpu_time.should == job['cpu_time']
42
- result_size.should == job['result_size']
43
- result_url.should == job['result_url']
44
- priority.should == job['priority']
45
- retry_limit.should == job['retry_limit']
46
- org.should == job['organization']
47
- db.should == job['database']
48
- duration.should == job['duration']
35
+ expect(job_id).to eq(job['job_id'])
36
+ expect(type).to eq(job['type'])
37
+ expect(status).to eq(job['status'])
38
+ expect(query).to eq(job['query'])
39
+ expect(start_at).to eq(job['start_at'])
40
+ expect(end_at).to eq(job['end_at'])
41
+ expect(cpu_time).to eq(job['cpu_time'])
42
+ expect(result_size).to eq(job['result_size'])
43
+ expect(result_url).to eq(job['result_url'])
44
+ expect(priority).to eq(job['priority'])
45
+ expect(retry_limit).to eq(job['retry_limit'])
46
+ expect(org).to eq(job['organization'])
47
+ expect(db).to eq(job['database'])
48
+ expect(duration).to eq(job['duration'])
49
49
  }
50
50
  end
51
51
  }
@@ -53,14 +53,14 @@ describe 'Job API' do
53
53
  it 'should returns 10 jobs with to parameter' do
54
54
  stub_api_request(:get, "/v3/job/list", :query => {'from' => '0', 'to' => '10'}).to_return(:body => {'jobs' => raw_jobs[0...10]}.to_json)
55
55
  jobs = api.list_jobs(0, 10)
56
- jobs.size.should == 10
56
+ expect(jobs.size).to eq(10)
57
57
  end
58
58
 
59
59
  it 'should returns 10 jobs with to status parameter' do
60
60
  error_jobs = raw_jobs.select { |j| j['status'] == 'error' }
61
61
  stub_api_request(:get, "/v3/job/list", :query => {'from' => '0', 'status' => 'error'}).to_return(:body => {'jobs' => error_jobs}.to_json)
62
62
  jobs = api.list_jobs(0, nil, 'error')
63
- jobs.size.should == error_jobs.size
63
+ expect(jobs.size).to eq(error_jobs.size)
64
64
  end
65
65
 
66
66
  #it 'should contain the result_size field' do
@@ -75,21 +75,21 @@ describe 'Job API' do
75
75
 
76
76
  type, query, status, url, debug, start_at, end_at, cpu_time,
77
77
  result_size, result_url, hive_result_schema, priority, retry_limit, org, db = api.show_job(i)
78
- type.should == job['type']
79
- query.should == job['query']
80
- status.should == job['status']
81
- url.should == job['url']
82
- debug.should == job['debug']
83
- start_at.should == job['start_at']
84
- end_at.should == job['end_at']
85
- cpu_time.should == job['cpu_time']
86
- result_size.should == job['result_size']
87
- result_url.should == job['result_url']
88
- hive_result_schema.should == job['hive_result_schema']
89
- result_url.should == job['result_url']
90
- priority.should == job['priority']
91
- org.should == job['organization']
92
- db.should == job['database']
78
+ expect(type).to eq(job['type'])
79
+ expect(query).to eq(job['query'])
80
+ expect(status).to eq(job['status'])
81
+ expect(url).to eq(job['url'])
82
+ expect(debug).to eq(job['debug'])
83
+ expect(start_at).to eq(job['start_at'])
84
+ expect(end_at).to eq(job['end_at'])
85
+ expect(cpu_time).to eq(job['cpu_time'])
86
+ expect(result_size).to eq(job['result_size'])
87
+ expect(result_url).to eq(job['result_url'])
88
+ expect(hive_result_schema).to eq(job['hive_result_schema'])
89
+ expect(result_url).to eq(job['result_url'])
90
+ expect(priority).to eq(job['priority'])
91
+ expect(org).to eq(job['organization'])
92
+ expect(db).to eq(job['database'])
93
93
  end
94
94
  }
95
95
 
@@ -129,7 +129,7 @@ describe 'Job API' do
129
129
  stub_api_request(:get, "/v3/job/status/#{e(job_id)}").to_return(:body => result_job.to_json)
130
130
 
131
131
  status = api.job_status(job_id)
132
- status.should == (i.odd? ? 'success' : 'error')
132
+ expect(status).to eq(i.odd? ? 'success' : 'error')
133
133
  end
134
134
  }
135
135
  end
@@ -144,7 +144,7 @@ describe 'Job API' do
144
144
  stub_api_request(:post, "/v3/job/issue/hive/#{e(db_name)}").with(:body => params).to_return(return_body)
145
145
 
146
146
  job_id = api.hive_query(query, db_name)
147
- job_id.should == '1'
147
+ expect(job_id).to eq('1')
148
148
  end
149
149
 
150
150
  it 'issue a query with result_url' do
@@ -152,7 +152,7 @@ describe 'Job API' do
152
152
  stub_api_request(:post, "/v3/job/issue/hive/#{e(db_name)}").with(:body => params).to_return(return_body)
153
153
 
154
154
  job_id = api.hive_query(query, db_name, 'td://@/test/table')
155
- job_id.should == '1'
155
+ expect(job_id).to eq('1')
156
156
  end
157
157
 
158
158
  it 'issue a query with priority' do
@@ -160,7 +160,7 @@ describe 'Job API' do
160
160
  stub_api_request(:post, "/v3/job/issue/hive/#{e(db_name)}").with(:body => params).to_return(return_body)
161
161
 
162
162
  job_id = api.hive_query(query, db_name, nil, 1)
163
- job_id.should == '1'
163
+ expect(job_id).to eq('1')
164
164
  end
165
165
  end
166
166
 
@@ -178,7 +178,40 @@ describe 'Job API' do
178
178
  stub_api_request(:get, '/v3/job/result/12345').
179
179
  with(:query => {'format' => 'msgpack'}).
180
180
  to_return(:body => packed)
181
- api.job_result(12345).should == ['hello', 'world']
181
+ expect(api.job_result(12345)).to eq(['hello', 'world'])
182
+ end
183
+
184
+ it 'can resume' do
185
+ sz = packed.bytesize / 3
186
+ stub_api_request(:get, '/v3/job/result/12345').
187
+ with(:query => {'format' => 'msgpack'}).
188
+ to_return(
189
+ :headers => {
190
+ 'Content-Length' => packed.bytesize,
191
+ 'Etag' => '"abcdefghijklmn"',
192
+ },
193
+ :body => packed[0, sz]
194
+ )
195
+ stub_api_request(:get, '/v3/job/result/12345').
196
+ with(
197
+ :headers => {
198
+ 'If-Range' => '"abcdefghijklmn"',
199
+ 'Range' => "bytes=#{sz}-",
200
+ },
201
+ :query => {'format' => 'msgpack'}
202
+ ).
203
+ to_return(
204
+ :headers => {
205
+ 'Content-Length' => packed.bytesize - sz,
206
+ 'Content-Range' => "bytes #{sz}-#{packed.bytesize-1}/#{packed.bytesize}",
207
+ 'Etag' => '"abcdefghijklmn"',
208
+ },
209
+ :body => packed[sz, packed.bytesize - sz]
210
+ )
211
+ expect(api).to receive(:sleep).once
212
+ expect($stderr).to receive(:print)
213
+ expect($stderr).to receive(:puts)
214
+ expect(api.job_result(12345)).to eq ['hello', 'world']
182
215
  end
183
216
  end
184
217
 
@@ -203,8 +236,8 @@ describe 'Job API' do
203
236
  total_size = 0
204
237
  api.job_result_format(12345, 'json', io) {|size| total_size += size }
205
238
 
206
- io.string.should == json
207
- total_size.should == json.size
239
+ expect(io.string).to eq(json)
240
+ expect(total_size).to eq(json.size)
208
241
  end
209
242
  end
210
243
 
@@ -216,7 +249,7 @@ describe 'Job API' do
216
249
  :headers => {'Content-Encoding' => 'gzip'},
217
250
  :body => packed
218
251
  )
219
- api.job_result_format(12345, 'json').should == ['hello', 'world'].to_json
252
+ expect(api.job_result_format(12345, 'json')).to eq(['hello', 'world'].to_json)
220
253
  end
221
254
 
222
255
  it 'writes formatted job result' do
@@ -228,7 +261,51 @@ describe 'Job API' do
228
261
  )
229
262
  s = StringIO.new
230
263
  api.job_result_format(12345, 'json', s)
231
- s.string.should == ['hello', 'world'].to_json
264
+ expect(s.string).to eq(['hello', 'world'].to_json)
265
+ end
266
+
267
+ context 'can resume' do
268
+ before do
269
+ sz = packed.bytesize / 3
270
+ stub_api_request(:get, '/v3/job/result/12345').
271
+ with(:query => {'format' => 'json'}).
272
+ to_return(
273
+ :headers => {
274
+ 'Content-Encoding' => 'gzip',
275
+ 'Content-Length' => packed.bytesize,
276
+ 'Etag' => '"abcdefghijklmn"',
277
+ },
278
+ :body => packed[0, sz]
279
+ )
280
+ stub_api_request(:get, '/v3/job/result/12345').
281
+ with(
282
+ :headers => {
283
+ 'If-Range' => '"abcdefghijklmn"',
284
+ 'Range' => "bytes=#{sz}-",
285
+ },
286
+ :query => {'format' => 'json'}
287
+ ).
288
+ to_return(
289
+ :headers => {
290
+ 'Content-Encoding' => 'gzip',
291
+ 'Content-Length' => packed.bytesize-sz,
292
+ 'Content-Range' => "bytes #{sz}-#{packed.bytesize-1}/#{packed.bytesize}",
293
+ 'Etag' => '"abcdefghijklmn"',
294
+ },
295
+ :body => packed[sz, packed.bytesize-sz]
296
+ )
297
+ expect(api).to receive(:sleep).once
298
+ expect($stderr).to receive(:print)
299
+ expect($stderr).to receive(:puts)
300
+ end
301
+ it 'can work with io' do
302
+ s = StringIO.new
303
+ api.job_result_format(12345, 'json', s)
304
+ expect(s.string).to eq ['hello', 'world'].to_json
305
+ end
306
+ it 'can work without block' do
307
+ expect(api.job_result_format(12345, 'json')).to eq ['hello', 'world'].to_json
308
+ end
232
309
  end
233
310
  end
234
311
  end
@@ -256,7 +333,45 @@ describe 'Job API' do
256
333
  api.job_result_each(12345) do |row|
257
334
  result << row
258
335
  end
259
- result.should == ['hello', 'world']
336
+ expect(result).to eq(['hello', 'world'])
337
+ end
338
+
339
+ it 'can resume' do
340
+ sz= packed.bytesize / 3
341
+ stub_api_request(:get, '/v3/job/result/12345').
342
+ with(:query => {'format' => 'msgpack'}).
343
+ to_return(
344
+ :headers => {
345
+ 'Content-Encoding' => 'gzip',
346
+ 'Content-Length' => packed.bytesize,
347
+ 'Etag' => '"abcdefghijklmn"',
348
+ },
349
+ :body => packed[0, sz]
350
+ )
351
+ stub_api_request(:get, '/v3/job/result/12345').
352
+ with(
353
+ :headers => {
354
+ 'If-Range' => '"abcdefghijklmn"',
355
+ 'Range' => "bytes=#{sz}-",
356
+ },
357
+ :query => {'format' => 'msgpack'}
358
+ ).
359
+ to_return(
360
+ :headers => {
361
+ 'Content-Length' => packed.bytesize-sz,
362
+ 'Content-Range' => "bytes #{sz}-#{packed.bytesize-1}/#{packed.bytesize}",
363
+ 'Etag' => '"abcdefghijklmn"',
364
+ },
365
+ :body => packed[sz, packed.bytesize-sz]
366
+ )
367
+ expect(api).to receive(:sleep).once
368
+ expect($stderr).to receive(:print)
369
+ expect($stderr).to receive(:puts)
370
+ result = []
371
+ api.job_result_each(12345) do |row|
372
+ result << row
373
+ end
374
+ expect(result).to eq ['hello', 'world']
260
375
  end
261
376
  end
262
377
 
@@ -285,7 +400,45 @@ describe 'Job API' do
285
400
  api.job_result_each_with_compr_size(12345) do |row, size|
286
401
  result << [row, size]
287
402
  end
288
- result.should == [['hello', 32], ['world', 32]]
403
+ expect(result).to eq([['hello', 32], ['world', 32]])
404
+ end
405
+
406
+ it 'can resume' do
407
+ sz = packed.bytesize / 3
408
+ stub_api_request(:get, '/v3/job/result/12345').
409
+ with(:query => {'format' => 'msgpack'}).
410
+ to_return(
411
+ :headers => {
412
+ 'Content-Encoding' => 'gzip',
413
+ 'Content-Length' => packed.bytesize,
414
+ 'Etag' => '"abcdefghijklmn"',
415
+ },
416
+ :body => packed[0, sz]
417
+ )
418
+ stub_api_request(:get, '/v3/job/result/12345').
419
+ with(
420
+ :headers => {
421
+ 'If-Range' => '"abcdefghijklmn"',
422
+ 'Range' => "bytes=#{sz}-",
423
+ },
424
+ :query => {'format' => 'msgpack'}
425
+ ).
426
+ to_return(
427
+ :headers => {
428
+ 'Content-Length' => packed.bytesize - sz,
429
+ 'Content-Range' => "bytes #{sz}-#{packed.bytesize-1}/#{packed.bytesize}",
430
+ 'Etag' => '"abcdefghijklmn"',
431
+ },
432
+ :body => packed[sz, packed.bytesize - sz]
433
+ )
434
+ expect(api).to receive(:sleep).once
435
+ expect($stderr).to receive(:print)
436
+ expect($stderr).to receive(:puts)
437
+ result = []
438
+ api.job_result_each_with_compr_size(12345) do |row, size|
439
+ result << [row, size]
440
+ end
441
+ expect(result).to eq [['hello', 32], ['world', 32]]
289
442
  end
290
443
  end
291
444
 
@@ -299,7 +452,7 @@ describe 'Job API' do
299
452
  to_return(:body => 'raw binary')
300
453
  api.job_result_raw(12345, 'json', io)
301
454
 
302
- io.string.should == 'raw binary'
455
+ expect(io.string).to eq('raw binary')
303
456
  end
304
457
  end
305
458
 
@@ -308,7 +461,7 @@ describe 'Job API' do
308
461
  stub_api_request(:get, '/v3/job/result/12345').
309
462
  with(:query => {'format' => 'json'}).
310
463
  to_return(:body => 'raw binary')
311
- api.job_result_raw(12345, 'json').should == 'raw binary'
464
+ expect(api.job_result_raw(12345, 'json')).to eq('raw binary')
312
465
  end
313
466
  end
314
467
 
@@ -326,37 +479,38 @@ describe 'Job API' do
326
479
  end
327
480
 
328
481
  it 'can resume' do
482
+ sz = packed.bytesize / 3
329
483
  stub_api_request(:get, '/v3/job/result/12345').
330
484
  with(:query => {'format' => 'msgpack.gz'}).
331
485
  to_return(
332
486
  :headers => {
333
- 'Content-Length' => 32,
487
+ 'Content-Length' => packed.bytesize,
334
488
  'Etag' => '"abcdefghijklmn"',
335
489
  },
336
- :body => packed[0, 20]
490
+ :body => packed[0, sz]
337
491
  )
338
492
  stub_api_request(:get, '/v3/job/result/12345').
339
493
  with(
340
494
  :headers => {
341
495
  'If-Range' => '"abcdefghijklmn"',
342
- 'Range' => 'bytes=20-',
496
+ 'Range' => "bytes=#{sz}-",
343
497
  },
344
498
  :query => {'format' => 'msgpack.gz'}
345
499
  ).
346
500
  to_return(
347
501
  :headers => {
348
- 'Content-Length' => 12,
349
- 'Content-Range' => 'bytes 20-31/32',
502
+ 'Content-Length' => packed.bytesize - sz,
503
+ 'Content-Range' => "bytes #{sz}-#{packed.bytesize-1}/#{packed.bytesize}",
350
504
  'Etag' => '"abcdefghijklmn"',
351
505
  },
352
- :body => packed[20, 12]
506
+ :body => packed[sz, packed.bytesize - sz]
353
507
  )
354
508
  expect(api).to receive(:sleep).once
355
509
  expect($stderr).to receive(:print)
356
510
  expect($stderr).to receive(:puts)
357
511
  sio = StringIO.new(''.force_encoding(Encoding::ASCII_8BIT))
358
512
  api.job_result_raw(12345, 'msgpack.gz', sio)
359
- sio.string.should == packed
513
+ expect(sio.string).to eq(packed)
360
514
  end
361
515
  end
362
516
 
@@ -364,7 +518,7 @@ describe 'Job API' do
364
518
  it 'kills a job' do
365
519
  stub_api_request(:post, '/v3/job/kill/12345').
366
520
  to_return(:body => {'former_status' => 'status'}.to_json)
367
- api.kill(12345).should == 'status'
521
+ expect(api.kill(12345)).to eq('status')
368
522
  end
369
523
  end
370
524
  end