ruby_doozer 0.4.0 → 0.5.0

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: b15a0cb9ca75e17c5abe248f29b83f418570240b
4
- data.tar.gz: 70fa3e7ccf86e679789a9f7858d80e90c5fada89
3
+ metadata.gz: d5d47ee0a6102bf34e1c122195959b683d1675a5
4
+ data.tar.gz: 6ffff10b2c3fc0081eb883bca20a8ea0eb9a8203
5
5
  SHA512:
6
- metadata.gz: b71b533217dfc507366609a9a2dcf16fd0bd9451bc26b9fd07c22594e5e044e76a1b38a7ef105ddbeba08b08092fb0b95e7e2636f29b292342ed88c827055c5e
7
- data.tar.gz: 86ed713d400eb0980ceb7c6d0da3171e9b84432d06c51eedc3049499b033d9f987d2dc537982f4840b7bb51bb3c725f4a243a91f41f1ca2c311ff6349902d647
6
+ metadata.gz: ee567d9875f26659295fbffcc7a492702168c5063889f8c7492786f916241f295c5b9b667e3be0db26d5736eb8c4fb7b912401e237db891c20e43bec33d08b76
7
+ data.tar.gz: 5e4a09132f67ae2b43c5b839897eb4925b66168c606f2013687c19da464bde398e6d15e02a4a8f3319f0eee84cc1da1c6b108197930427a47534189cac0304be
@@ -35,8 +35,8 @@ module RubyDoozer
35
35
  doozer_pool.with_connection do |doozer|
36
36
  @current_revision = doozer.current_revision
37
37
  # Fetch all the configuration information from Doozer and set the internal copy
38
- doozer.walk(path, @current_revision).each do |node|
39
- set_cached_value(relative_path(node.path), node.value)
38
+ doozer.walk(path, @current_revision) do |path, value, revision|
39
+ set_cached_value(relative_path(path), value)
40
40
  end
41
41
  end
42
42
 
@@ -109,27 +109,39 @@ module RubyDoozer
109
109
  invoke(Request.new(:path => secret, :verb => Request::Verb::ACCESS))
110
110
  end
111
111
 
112
- # Returns every entry in the supplied path
112
+ # Iterate over every entry in the supplied path
113
113
  # path can also contain wildcard characters such as '*'
114
+ #
115
+ # Parameters:
116
+ # path
117
+ # The path including wildcard specifiers
118
+ # The path must begin with '/'
119
+ # The path can contain any of the following wildcard specifiers:
120
+ # ** Includes the directory and it's children
121
+ # * Only values with that path
122
+ # Example paths:
123
+ # /**
124
+ # /*
125
+ # /configs/**
126
+ # /ctl/node/*/addr
127
+ #
114
128
  # Example:
115
- # hosts = []
116
- # walk('/ctl/node/*/addr', current_revision).each do |node|
117
- # hosts << node.value unless hosts.include? node.value
129
+ # client.walk('/**') do |path, value, revision|
130
+ # puts "Found: #{path} => #{value}, Revision: #{revision}"
118
131
  # end
119
- def walk(path, rev = nil, offset = 0)
120
- paths = []
132
+ def walk(path, rev = nil, offset = 0, &block)
133
+ paths = block ? nil : []
121
134
  revision = rev || current_revision
122
135
  # Resume walk on network connection failure
123
136
  @socket.retry_on_connection_failure do
124
137
  while true
125
138
  send(Request.new(:path => path, :rev => revision , :offset => offset, :verb => Request::Verb::WALK))
126
139
  response = read
127
- if response.err_code
140
+ if response.err_code != 0
128
141
  break if response.err_code == Response::Err::RANGE
129
- else
130
- raise ResponseError.new("#{Response::Err.name_by_value(response.err_code)}: #{response.err_detail}") if response.err_code != 0
142
+ raise ResponseError.new("#{Response::Err.name_by_value(response.err_code)}: #{response.err_detail}")
131
143
  end
132
- paths << response
144
+ block ? block.call(response.path, response.value, response.rev) : paths << response
133
145
  offset += 1
134
146
  end
135
147
  end
@@ -140,8 +152,8 @@ module RubyDoozer
140
152
  # representing another Doozer server that can be connected to
141
153
  def doozer_hosts
142
154
  hosts = []
143
- walk('/ctl/node/*/addr', current_revision).each do |node|
144
- hosts << node.value unless hosts.include? node.value
155
+ walk('/ctl/node/*/addr') do |path, value, revision|
156
+ hosts << value unless hosts.include? value
145
157
  end
146
158
  end
147
159
 
@@ -193,11 +205,13 @@ module RubyDoozer
193
205
  # Send the protobuf Request to Doozer
194
206
  def send(request)
195
207
  # Translate path so that underscores are converted to minuses
196
- request.path.gsub!('_', '-')
208
+ # Don't change the original input value
209
+ request.path = request.path.gsub('_', '-')
197
210
  request.tag = 0
198
211
  data = request.serialize_to_string
199
212
  # An additional header is added to the request indicating the size of the request
200
213
  head = [data.length].pack("N")
214
+ logger.trace('Sending') {request.to_hash}
201
215
  @socket.write(head+data)
202
216
  end
203
217
 
@@ -208,7 +222,8 @@ module RubyDoozer
208
222
  length = head.unpack("N")[0]
209
223
  response = Response.new.parse_from_string(@socket.read(length))
210
224
  # Translate returned path so that minuses are converted to underscores
211
- response.path.gsub!('_', '-')
225
+ response.path.gsub!('-', '_')
226
+ logger.trace('Received') {response.to_hash}
212
227
  response
213
228
  end
214
229
 
@@ -156,8 +156,8 @@ module RubyDoozer
156
156
  def each_pair(&block)
157
157
  path = "#{@root_path}/**"
158
158
  doozer_pool.with_connection do |doozer|
159
- doozer.walk(path, doozer.current_revision).each do |node|
160
- block.call(relative_path(node.path), node.value)
159
+ doozer.walk(path) do |path, value, revision|
160
+ block.call(relative_path(path), value)
161
161
  end
162
162
  end
163
163
  end
@@ -1,3 +1,3 @@
1
1
  module RubyDoozer #:nodoc
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -34,6 +34,8 @@ class ClientTest < Test::Unit::TestCase
34
34
  end
35
35
 
36
36
  context "with client connection" do
37
+ PATHS = ['/test/foo', '/test/with_underscores', '/test/deeper_one/and_again_with_multiple']
38
+
37
39
  setup do
38
40
  @client = RubyDoozer::Client.new(:server => 'localhost:8046')
39
41
  end
@@ -41,7 +43,7 @@ class ClientTest < Test::Unit::TestCase
41
43
  def teardown
42
44
  if @client
43
45
  @client.close
44
- @client.delete('/test/foo')
46
+ PATHS.each {|path| @client.delete(path)}
45
47
  end
46
48
  end
47
49
 
@@ -49,19 +51,37 @@ class ClientTest < Test::Unit::TestCase
49
51
  assert @client.current_revision >= 0
50
52
  end
51
53
 
52
- ['/test/foo', '/test/with_underscores'].each do |path|
54
+ context "successfully set and get data" do
55
+ PATHS.each do |path|
56
+ should "in #{path}" do
57
+ new_revision = @client.set(path, 'value')
58
+ result = @client.get(path)
59
+ assert_equal 'value', result.value
60
+ assert_equal new_revision, result.rev
61
+ end
62
+
63
+ should "successfully set and get data using array operators in #{path}" do
64
+ @client[path] = 'value2'
65
+ result = @client[path]
66
+ assert_equal 'value2', result
67
+ end
68
+ end
69
+ end
53
70
 
54
- should "successfully set and get data in #{path}" do
55
- new_revision = @client.set(path, 'value')
56
- result = @client.get(path)
57
- assert_equal 'value', result.value
58
- assert_equal new_revision, result.rev
71
+ context "with a directory tree" do
72
+ setup do
73
+ PATHS.each {|path| @client[path] = path}
59
74
  end
60
75
 
61
- should "successfully set and get data using array operators in #{path}" do
62
- @client[path] = 'value2'
63
- result = @client[path]
64
- assert_equal 'value2', result
76
+ should "walk" do
77
+ # Fetch all the configuration information from Doozer and set the internal copy
78
+ count = 0
79
+ @client.walk('/test/**') do |path, value, revision|
80
+ assert_equal true, PATHS.include?(path)
81
+ assert_equal path, value
82
+ count += 1
83
+ end
84
+ assert_equal PATHS.size, count
65
85
  end
66
86
  end
67
87
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_doozer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reid Morrison