td-client 0.8.77 → 0.8.78

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: 979926070464720f6bd1b6a59807be434867d11e
4
- data.tar.gz: 4d091e61892417bdf7204db853959364bf22f73d
3
+ metadata.gz: b7b08bc82aed5007cc2f9b0500847ca78520cc78
4
+ data.tar.gz: 1fa61539241cce5a9152f23629f46c5c95a7ec01
5
5
  SHA512:
6
- metadata.gz: 0fc6cd57b053cfd3b88bcfe53e03014c65699a6fd95bd270dd3e35b67bdef565a212e643458283263deed4037775946b9f675859b959a22863c23d68460f775f
7
- data.tar.gz: c23339a69564b86d9676f825706a49cafde1fb404e485a3e6a7d3eb64ed7051cd4efeddd63ce7288ece545d4ddb0b3a30e769ea9114b84d9e55dbac8eb3dcb38
6
+ metadata.gz: cd680197fab594cf321145804b06b99d9070cecb97115625b7a489d94b4baae685f47744a866172f20baf6d50b7e9c9eca0287b20ab0d4692cfeec38aa5e9448
7
+ data.tar.gz: 64fc10d47a765efc4bab85fb24fa12b0cbc459336467f21765007057807117c6177f936f642c84da608d15fa09ddb9dacf5e08a3b50fcb96f900860f78c9c02e
@@ -121,7 +121,12 @@ class API
121
121
  record[k] = v.to_s
122
122
  end
123
123
  }
124
- record.to_msgpack(out)
124
+ if out
125
+ out << record.to_msgpack
126
+ out
127
+ else
128
+ record.to_msgpack
129
+ end
125
130
  end
126
131
 
127
132
  # @param [String] target
@@ -1,7 +1,7 @@
1
+ require 'timeout'
1
2
 
2
3
  module TreasureData
3
4
 
4
-
5
5
  class Model
6
6
  # @param [TreasureData::Client] client
7
7
  def initialize(client)
@@ -403,8 +403,25 @@ class Job < Model
403
403
  attr_reader :priority, :retry_limit, :org_name, :db_name
404
404
  attr_reader :duration
405
405
 
406
- def wait(timeout=nil)
407
- # TODO
406
+ def wait(timeout=nil, wait_interval=2)
407
+ # this should use monotonic clock but td-client-ruby supports Ruby 1.8.7 now.
408
+ # therefore add workaround to initializing clock on each delta
409
+ if timeout
410
+ orig_timeout = timeout
411
+ t1 = Time.now.to_f
412
+ end
413
+ until finished?
414
+ if timeout
415
+ t = Time.now.to_f
416
+ d = t - t1
417
+ t1 = t
418
+ timeout -= d if d > 0
419
+ raise ::TimeoutError, "timeout=#{orig_timeout} wait_interval=#{wait_interval}" if timeout <= 0
420
+ end
421
+ sleep wait_interval
422
+ yield self if block_given?
423
+ update_progress!
424
+ end
408
425
  end
409
426
 
410
427
  def kill!
@@ -1,5 +1,5 @@
1
1
  module TreasureData
2
2
  class Client
3
- VERSION = '0.8.77'
3
+ VERSION = '0.8.78'
4
4
  end
5
5
  end
@@ -4,11 +4,34 @@ require 'logger'
4
4
  require 'webrick'
5
5
  require 'webrick/https'
6
6
 
7
+ # Workaround for https://github.com/jruby/jruby-openssl/issues/78
8
+ # With recent JRuby + jruby-openssl, X509CRL#extentions_to_text causes
9
+ # StringIndexOOBException when we try to dump SSL Server Certificate.
10
+ # when one of extensions has "" as value.
11
+ # This hack is from httpclient https://github.com/nahi/httpclient/blob/master/lib/httpclient/util.rb#L27-L46
12
+ if defined? JRUBY_VERSION
13
+ require 'openssl'
14
+ require 'java'
15
+ module OpenSSL
16
+ module X509
17
+ class Certificate
18
+ java_import 'java.security.cert.Certificate'
19
+ java_import 'java.security.cert.CertificateFactory'
20
+ java_import 'java.io.ByteArrayInputStream'
21
+ def to_text
22
+ cf = CertificateFactory.getInstance('X.509')
23
+ cf.generateCertificate(ByteArrayInputStream.new(self.to_der.to_java_bytes)).toString
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+
7
30
  describe 'API SSL connection' do
8
31
  DIR = File.dirname(File.expand_path(__FILE__))
9
32
 
10
33
  after :each do
11
- @server.shutdown
34
+ @server.shutdown if @server
12
35
  end
13
36
 
14
37
  it 'should fail to connect SSLv3 only server' do
@@ -62,4 +62,72 @@ describe 'Job Model' do
62
62
  end
63
63
  end
64
64
  end
65
+
66
+ describe '#wait' do
67
+ let(:client) { Client.authenticate('user', 'password') }
68
+ let(:job_id) { 12345678 }
69
+ let(:job) { Job.new(client, job_id, nil, nil) }
70
+
71
+ def change_job_status(status)
72
+ allow(client).to receive(:job_status).with(job_id).and_return(status)
73
+ end
74
+
75
+ before do
76
+ change_job_status(Job::STATUS_QUEUED)
77
+ end
78
+
79
+ context 'without timeout' do
80
+ it 'waits the job to be finished' do
81
+ begin
82
+ thread = Thread.start { job.wait }
83
+ expect(thread).to be_alive
84
+ change_job_status(Job::STATUS_SUCCESS)
85
+ thread.join(1)
86
+ expect(thread).to be_stop
87
+ ensure
88
+ thread.kill # just in case
89
+ end
90
+ end
91
+
92
+ it 'calls a given block in every wait_interval second' do
93
+ expect { |b|
94
+ begin
95
+ thread = Thread.start {
96
+ job.wait(nil, 0.1, &b)
97
+ }
98
+ sleep 0.3
99
+ change_job_status(Job::STATUS_SUCCESS)
100
+ thread.join(0.5)
101
+ expect(thread).to be_stop
102
+ ensure
103
+ thread.kill # just in case
104
+ end
105
+ }.to yield_control.at_least(2).at_most(3).times
106
+ end
107
+ end
108
+
109
+ context 'with timeout' do
110
+ context 'the job running time is too long' do
111
+ it 'raise ::TimeoutError' do
112
+ expect {
113
+ job.wait(0.1)
114
+ }.to raise_error(::TimeoutError)
115
+ end
116
+ end
117
+
118
+ it 'calls a given block in every wait_interval second, and timeout' do
119
+ expect { |b|
120
+ begin
121
+ thread = Thread.start {
122
+ job.wait(0.3, 0.1, &b)
123
+ }
124
+ expect{ thread.value }.to raise_error(::TimeoutError)
125
+ expect(thread).to be_stop
126
+ ensure
127
+ thread.kill # just in case
128
+ end
129
+ }.to yield_control.at_least(2).times
130
+ end
131
+ end
132
+ end
65
133
  end
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: 0.8.77
4
+ version: 0.8.78
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: 2015-12-17 00:00:00.000000000 Z
11
+ date: 2016-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -31,7 +31,7 @@ dependencies:
31
31
  version: 0.5.3
32
32
  - - "<"
33
33
  - !ruby/object:Gem::Version
34
- version: 0.6.0
34
+ version: 0.8.0
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
@@ -53,7 +53,7 @@ dependencies:
53
53
  version: 0.5.3
54
54
  - - "<"
55
55
  - !ruby/object:Gem::Version
56
- version: 0.6.0
56
+ version: 0.8.0
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: json
59
59
  requirement: !ruby/object:Gem::Requirement
@@ -72,22 +72,16 @@ dependencies:
72
72
  name: httpclient
73
73
  requirement: !ruby/object:Gem::Requirement
74
74
  requirements:
75
- - - ">="
76
- - !ruby/object:Gem::Version
77
- version: 2.5.2
78
- - - "<"
75
+ - - "~>"
79
76
  - !ruby/object:Gem::Version
80
- version: 2.6.0
77
+ version: '2.7'
81
78
  type: :runtime
82
79
  prerelease: false
83
80
  version_requirements: !ruby/object:Gem::Requirement
84
81
  requirements:
85
- - - ">="
86
- - !ruby/object:Gem::Version
87
- version: 2.5.2
88
- - - "<"
82
+ - - "~>"
89
83
  - !ruby/object:Gem::Version
90
- version: 2.6.0
84
+ version: '2.7'
91
85
  - !ruby/object:Gem::Dependency
92
86
  name: rspec
93
87
  requirement: !ruby/object:Gem::Requirement