etcdv3 0.9.0 → 0.10.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: 2c90b3d66d75efdf3c6c608cc1ccaf9673731070
4
- data.tar.gz: 7698e02e69968d2e6348dd01a7e6813d27d5d50e
3
+ metadata.gz: eea828b2c14cfeab2c0f9be8a84ea937131a5dc2
4
+ data.tar.gz: a2e02f9d0155f35185994c07cd7abc5a6d23d5df
5
5
  SHA512:
6
- metadata.gz: 634ec36c4eccf0b93dd69b51a25e6515c06a26a1677264fb02d035c793cf905feb739ad9bde6e40ae30617416aebe7b85706bb4a1060cbb3d26d8b68e42a702f
7
- data.tar.gz: 7043f69c71837cefc8168ff3d5c0225afc9109c4a1c5e9aab1bec7b5fcf56999c9866abac23c3a7b13e9de5422b1983ffae57448f85dafd65f5d369837d7d286
6
+ metadata.gz: bff96b426657924163a26df9ca1322b5600b33607453d4648affffe2e66bf7c7ef20e5fe2d0443435de71b74d9ceec637f968196315837426294d26dd1b84e78
7
+ data.tar.gz: 1a10f332e633b1010aba3a355b05ef82e2546e37413222de7553bcdb2461d0d2b368573af75a33e927349c4f461c81564d80adbe149ea7f6e5ac8b478158cc1e
data/.travis.yml CHANGED
@@ -5,11 +5,9 @@ rvm:
5
5
  - 2.3.8
6
6
 
7
7
  env:
8
- - ETCD_VERSION=v3.1.20
9
- - ETCD_VERSION=v3.2.25
10
- # v3.3.10 is not working for whatever reason (at least in travis, spec passes
11
- # locally for me)
12
- # - ETCD_VERSION=v3.3.10
8
+ - ETCD_VERSION_TO_TEST=v3.1.20
9
+ - ETCD_VERSION_TO_TEST=v3.2.25
10
+ - ETCD_VERSION_TO_TEST=v3.3.10
13
11
 
14
12
  install:
15
13
  - bundle install
data/README.md CHANGED
@@ -149,12 +149,15 @@ end
149
149
 
150
150
  ## Watch
151
151
  ```ruby
152
- # Watch for changes on a specified key and return
153
- events = conn.watch('foo')
152
+ # Watch for changes on a specified key for at most 10 seconds and return
153
+ events = conn.watch('foo', timeout: 10)
154
154
 
155
155
  # Watch for changes on a specified key range and return
156
156
  events = conn.watch('foo', range_end: 'fop')
157
157
 
158
+ # Watch for changes since a given revision
159
+ events = conn.watch('foo', start_revision: 42)
160
+
158
161
  # Watches for changes continuously until killed.
159
162
  event_count = 0
160
163
  conn.watch('boom') do |events|
data/Rakefile CHANGED
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- ETCD_VERSION = ENV["ETCD_VERSION"] || "v3.2.0"
4
- ETCD_URL = "https://github.com/coreos/etcd/releases/download/#{ETCD_VERSION}/etcd-#{ETCD_VERSION}-linux-amd64.tar.gz"
3
+ ETCD_VERSION = ENV["ETCD_VERSION_TO_TEST"] || "v3.2.0"
4
+ ETCD_URL = "https://github.com/coreos/etcd/releases/download/" \
5
+ "#{ETCD_VERSION}/etcd-#{ETCD_VERSION}-linux-amd64.tar.gz"
5
6
 
6
7
  require "tmpdir"
7
8
 
@@ -1,3 +1,3 @@
1
1
  class Etcdv3
2
- VERSION = '0.9.0'.freeze
2
+ VERSION = '0.10.1'.freeze
3
3
  end
data/lib/etcdv3/watch.rb CHANGED
@@ -1,16 +1,20 @@
1
1
  class Etcdv3
2
2
  class Watch
3
+ include GRPC::Core::TimeConsts
3
4
 
4
- def initialize(hostname, credentials, _timeout, metadata = {})
5
+ def initialize(hostname, credentials, timeout, metadata = {})
5
6
  @stub = Etcdserverpb::Watch::Stub.new(hostname, credentials)
7
+ @timeout = timeout
6
8
  @metadata = metadata
7
9
  end
8
10
 
9
- def watch(key, range_end, block)
10
- create_req = Etcdserverpb::WatchCreateRequest.new(key: key, range_end: range_end)
11
+ def watch(key, range_end, start_revision, block, timeout: nil)
12
+ create_req = Etcdserverpb::WatchCreateRequest.new(key: key)
13
+ create_req.range_end = range_end if range_end
14
+ create_req.start_revision = start_revision if start_revision
11
15
  watch_req = Etcdserverpb::WatchRequest.new(create_request: create_req)
12
16
  events = nil
13
- @stub.watch([watch_req], metadata: @metadata).each do |resp|
17
+ @stub.watch([watch_req], metadata: @metadata, deadline: deadline(timeout)).each do |resp|
14
18
  next if resp.events.empty?
15
19
  if block
16
20
  block.call(resp.events)
@@ -21,5 +25,9 @@ class Etcdv3
21
25
  end
22
26
  events
23
27
  end
28
+
29
+ def deadline(timeout)
30
+ from_relative_time(timeout || @timeout)
31
+ end
24
32
  end
25
33
  end
data/lib/etcdv3.rb CHANGED
@@ -219,8 +219,8 @@ class Etcdv3
219
219
  end
220
220
 
221
221
  # Watches for changes on a specified key range.
222
- def watch(key, range_end: '', &block)
223
- @conn.handle(:watch, 'watch', [key, range_end, block])
222
+ def watch(key, range_end: nil, start_revision: nil, timeout: nil, &block)
223
+ @conn.handle(:watch, 'watch', [key, range_end, start_revision, block, timeout: timeout])
224
224
  end
225
225
 
226
226
  def transaction(timeout: nil, &block)
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+ require 'securerandom'
3
+
4
+ # Locking is not implemented in etcd v3.1.X
5
+ unless $instance.version < Gem::Version.new("3.2.0")
6
+ describe Etcdv3::Watch do
7
+ let(:stub) { local_stub(Etcdv3::Watch, 1) }
8
+ let(:kv_stub) { local_stub(Etcdv3::KV, 1) }
9
+
10
+ context 'xxx' do
11
+ before(:each) do
12
+ kv_stub.put 'foo', 'bar'
13
+ end
14
+ it_should_behave_like "a method with a GRPC timeout", described_class, :watch, :watch, 'foo', "\0", 1, nil
15
+ end
16
+ end
17
+ end
data/spec/etcdv3_spec.rb CHANGED
@@ -181,6 +181,20 @@ describe Etcdv3 do
181
181
  end
182
182
  end
183
183
 
184
+ describe '#watch' do
185
+ let!(:foo) { conn.put('foo', 'bar') }
186
+ subject { conn.watch('foo', start_revision: 1) }
187
+ it { is_expected.to_not be_nil }
188
+ it "raises a GRPC::DeadlineExceeded exception when it takes too long" do
189
+ expect do
190
+ conn.watch('foo', timeout: 0)
191
+ end.to raise_exception(GRPC::DeadlineExceeded)
192
+ end
193
+ it "accepts a timeout" do
194
+ expect{ conn.watch('foo', start_revision: 1, timeout: 10) }.to_not raise_exception
195
+ end
196
+ end
197
+
184
198
  describe '#lease_keep_alive_once' do
185
199
  let!(:lease_id) { conn.lease_grant(2)['ID'] }
186
200
  subject { conn.lease_keep_alive_once(lease_id) }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: etcdv3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shaun Davis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-18 00:00:00.000000000 Z
11
+ date: 2019-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grpc
@@ -114,6 +114,7 @@ files:
114
114
  - spec/etcdv3/lease_spec.rb
115
115
  - spec/etcdv3/lock_spec.rb
116
116
  - spec/etcdv3/maintenance_spec.rb
117
+ - spec/etcdv3/watch_spec.rb
117
118
  - spec/etcdv3_spec.rb
118
119
  - spec/helpers/connections.rb
119
120
  - spec/helpers/shared_examples_for_timeout.rb
@@ -151,6 +152,7 @@ test_files:
151
152
  - spec/etcdv3/lease_spec.rb
152
153
  - spec/etcdv3/lock_spec.rb
153
154
  - spec/etcdv3/maintenance_spec.rb
155
+ - spec/etcdv3/watch_spec.rb
154
156
  - spec/etcdv3_spec.rb
155
157
  - spec/helpers/connections.rb
156
158
  - spec/helpers/shared_examples_for_timeout.rb