Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'CHEF-1808' into nofields-work

  • Loading branch information...
commit 64c4a0b8c38b2693c1ccd550354556d86da8cae7 2 parents 00329ec + 9b39bf3
Seth Falcon seth authored
17 chef/lib/chef/index_queue/amqp_client.rb
@@ -31,11 +31,9 @@ def reset!
31 31 @amqp_client && amqp_client.connected? && amqp_client.stop
32 32 @amqp_client = nil
33 33 @exchange = nil
34   - @queue = nil
35 34 end
36 35
37 36 def stop
38   - @queue && @queue.subscription && @queue.unsubscribe
39 37 @amqp_client && @amqp_client.stop
40 38 end
41 39
@@ -61,25 +59,16 @@ def exchange
61 59 @exchange ||= amqp_client.exchange("chef-indexer", :durable => true, :type => :fanout)
62 60 end
63 61
64   - def queue
65   - unless @queue
66   - @queue = amqp_client.queue("chef-index-consumer-" + consumer_id, :durable => durable_queue?)
67   - @queue.bind(exchange)
68   - end
69   - @queue
70   - end
71   -
72 62 def disconnected!
73 63 @amqp_client = nil
74 64 reset!
75 65 end
76 66
77 67 def queue_for_object(obj_id)
78   - vnode_tag = obj_id_to_int(obj_id) % VNODES
79   - queue = amqp_client.queue("vnode-#{vnode_tag}")
80 68 retries = 0
  69 + vnode_tag = obj_id_to_int(obj_id) % VNODES
81 70 begin
82   - yield queue
  71 + yield amqp_client.queue("vnode-#{vnode_tag}")
83 72 rescue Bunny::ServerDownError, Bunny::ConnectionError, Errno::ECONNRESET
84 73 disconnected!
85 74 if (retries += 1) < 2
@@ -122,4 +111,4 @@ def amqp_opts
122 111
123 112 end
124 113 end
125   -end
  114 +end
57 chef/spec/unit/index_queue_spec.rb
@@ -226,60 +226,55 @@ def @amqp_client.connected?; false; end # stubbing predicate methods not working
226 226 end
227 227
228 228 describe "publishing" do
  229 +
229 230 before do
230   - @queue = FauxQueue.new
  231 + @queue_1 = FauxQueue.new
  232 + @queue_2 = FauxQueue.new
  233 +
231 234 @amqp_client.stub!(:qos)
232   - @amqp_client.stub!(:queue).and_return(@queue)
  235 + #@amqp_client.stub!(:queue).and_return(@queue)
233 236 @data = {"some_data" => "in_a_hash"}
234 237 end
235 238
236 239 it "resets the client upon a Bunny::ServerDownError when publishing" do
  240 + Bunny.stub!(:new).and_return(@amqp_client)
  241 + @amqp_client.should_receive(:queue).with("vnode-68").twice.and_return(@queue_1, @queue_2)
  242 +
  243 + @queue_1.should_receive(:publish).with(@data).and_raise(Bunny::ServerDownError)
  244 + @queue_2.should_receive(:publish).with(@data).and_raise(Bunny::ServerDownError)
  245 +
237 246 @publisher.should_receive(:disconnected!).at_least(3).times
238   - lambda {@publisher.queue_for_object("00000000-1111-2222-3333-444444444444") {|q| raise Bunny::ServerDownError}}.should raise_error(Bunny::ServerDownError)
  247 + lambda {@publisher.queue_for_object("00000000-1111-2222-3333-444444444444") {|q| q.publish(@data)}}.should raise_error(Bunny::ServerDownError)
239 248 end
240 249
241 250 it "resets the client upon a Bunny::ConnectionError when publishing" do
  251 + Bunny.stub!(:new).and_return(@amqp_client)
  252 + @amqp_client.should_receive(:queue).with("vnode-68").twice.and_return(@queue_1, @queue_2)
  253 +
  254 + @queue_1.should_receive(:publish).with(@data).and_raise(Bunny::ConnectionError)
  255 + @queue_2.should_receive(:publish).with(@data).and_raise(Bunny::ConnectionError)
  256 +
242 257 @publisher.should_receive(:disconnected!).at_least(3).times
243   - lambda {@publisher.queue_for_object("00000000-1111-2222-3333-444444444444") {|q| raise Bunny::ConnectionError}}.should raise_error(Bunny::ConnectionError)
  258 + lambda {@publisher.queue_for_object("00000000-1111-2222-3333-444444444444") {|q| q.publish(@data)}}.should raise_error(Bunny::ConnectionError)
244 259 end
245 260
246 261 it "resets the client upon a Errno::ECONNRESET when publishing" do
  262 + Bunny.stub!(:new).and_return(@amqp_client)
  263 + @amqp_client.should_receive(:queue).with("vnode-68").twice.and_return(@queue_1, @queue_2)
  264 +
  265 + @queue_1.should_receive(:publish).with(@data).and_raise(Errno::ECONNRESET)
  266 + @queue_2.should_receive(:publish).with(@data).and_raise(Errno::ECONNRESET)
  267 +
247 268 @publisher.should_receive(:disconnected!).at_least(3).times
248   - lambda {@publisher.queue_for_object("00000000-1111-2222-3333-444444444444") {|q| raise Errno::ECONNRESET}}.should raise_error(Errno::ECONNRESET)
  269 + lambda {@publisher.queue_for_object("00000000-1111-2222-3333-444444444444") {|q| q.publish(@data)}}.should raise_error(Errno::ECONNRESET)
249 270 end
250 271
251 272 end
252 273
253   - it "creates a queue bound to its exchange with a temporary UUID" do
254   - @amqp_client.stub!(:qos)
255   -
256   - a_queue_name = /chef\-index-consumer\-[0-9a-f]{8}\-[0-9a-f]{4}\-[0-9a-f]{4}\-[0-9a-f]{4}\-[0-9a-f]{12}/
257   -
258   - @queue = mock("Bunny::Queue")
259   - @amqp_client.should_receive(:queue).with(a_queue_name, :durable => false).and_return(@queue)
260   - @queue.should_receive(:bind).with(@exchange)
261   - @publisher.queue.should == @queue
262   - end
263   -
264   - it "creates a durable queue bound to the exchange when a UUID is configured" do
265   - expected_queue_id = "aaaaaaaa-bbbb-cccc-dddd-eeee-ffffffffffffffff"
266   - expected_queue_name = "chef-index-consumer-#{expected_queue_id}"
267   - Chef::Config[:amqp_consumer_id] = expected_queue_id
268   - @amqp_client.stub!(:qos)
269   -
270   - @queue = mock("Bunny::Queue")
271   - @amqp_client.should_receive(:queue).with(expected_queue_name, :durable => true).and_return(@queue)
272   - @queue.should_receive(:bind).with(@exchange)
273   - @publisher.queue.should == @queue
274   - end
275   -
276 274 it "stops bunny and clears subscriptions" do
277 275 bunny_client = mock("Bunny::Client")
278   - queue = mock("Bunny::Queue", :subscription => true)
279 276 @publisher.instance_variable_set(:@amqp_client, bunny_client)
280   - @publisher.instance_variable_set(:@queue, queue)
281 277 bunny_client.should_receive(:stop)
282   - queue.should_receive(:unsubscribe)
283 278 @publisher.stop
284 279 end
285 280

0 comments on commit 64c4a0b

Please sign in to comment.
Something went wrong with that request. Please try again.