Permalink
Browse files

Merge pull request #4 from EagleChen/master

add a rabbimq complex lifecycle test
  • Loading branch information...
2 parents 8277ec2 + 7c92480 commit 925399c8376fbfe4d0770600a0ab4fed38e0cb54 @figof figof committed Mar 27, 2013
@@ -211,10 +211,42 @@ def job_completed?(job)
return true if job["status"] == "completed" || job["status"] == "failed"
end
+ def create_items_and_verify_rabbit(service_manifest, app, items)
+ cred = app.services[0].manifest[:entity][:credentials]
+ url = "http://#{cred[:username]}:#{cred[:password]}@#{cred[:host]}:#{cred[:admin_port]}/api"
+ resource = RestClient::Resource.new url
+ items.each do |type, objects|
+ objects.each do |object|
+ name, durable = object
+ #post is not supported for this path
+ resource["#{type}/#{cred[:vhost]}/#{name}"].put({:durable => durable}.to_json, :content_type => "application/json")
+ end
+ end
-
+ get_and_verify_rabbit(service_manifest, app, items, nil)
end
-end
+ def clear_and_verify_rabbit(service_manifest, app, items)
+ cred = app.services[0].manifest[:entity][:credentials]
+ url = "http://#{cred[:username]}:#{cred[:password]}@#{cred[:host]}:#{cred[:admin_port]}/api"
+ resource = RestClient::Resource.new url
+ items.each do |type, objects|
+ objects.each { |object| resource["#{type}/#{cred[:vhost]}/#{object[0]}"].delete }
+ end
+
+ get_and_verify_rabbit(service_manifest, app, nil, items)
+ end
+ def get_and_verify_rabbit(service_manifest, app, included_items, excluded_items)
+ cred = app.services[0].manifest[:entity][:credentials]
+ url = "http://#{cred[:username]}:#{cred[:password]}@#{cred[:host]}:#{cred[:admin_port]}/api"
+ resource = RestClient::Resource.new(url)
+ queues = JSON.parse(resource["queues"].get).map { |queue| [queue["name"], queue["durable"]] }
+ exchanges = JSON.parse(resource["exchanges"].get).map { |exchange| [exchange["name"], exchange["durable"]] }
+ server_items = queues + exchanges
+ included_items.values.flatten(1).each { |item| server_items.include?(item).should == true } if included_items
+ excluded_items.values.flatten(1).each { |item| server_items.include?(item).should == false } if excluded_items
+ end
+ end
+end
@@ -457,6 +457,41 @@
result["result"]["snapshot_id"].should == nil
end
+ it "Take rabbit snapshot with complex configuration and rollback to a certain snapshot", :rabbit => true do
+ quota = snapshot_quota('rabbit')
+ pending('This test requires quota > 0') unless quota > 0
+ app = create_push_app('app_sinatra_service2', nil, nil, [RABBITMQ_MANIFEST])
+
+ content = app.get_response(:get, '/env')
+ service_id = parse_service_id(content, 'rabbit')
+ items = { "queues" => [["test_queue", false], ["test_durable_queue", true]],
+ "exchanges" => [["test_exchange", false], ["test_durable_exchange", true]] }
+ create_items_and_verify_rabbit(RABBITMQ_MANIFEST, app, items)
+
+ result = create_snapshot(service_id)
+ snapshot_id = result["result"]["snapshot_id"]
+
+ snapshot = get_snapshot(service_id, snapshot_id)
+ snapshot["snapshot_id"].should == snapshot_id
+ snapshot["size"].should > 0
+ snapshot["date"].should_not == nil
+
+ snapshots = get_snapshots(service_id)
+ snapshot = snapshots["snapshots"].find {|s| s["snapshot_id"] == snapshot_id}
+ snapshot.should_not == nil
+ snapshot["size"].should > 0
+ snapshot["date"].should_not == nil
+
+ clear_and_verify_rabbit(RABBITMQ_MANIFEST, app, items)
+ rollback_snapshot(service_id, snapshot_id)
+ included_items, excluded_items = {}, {}
+ items.each do |k, v|
+ included_items[k] = [v[1]]
+ excluded_items[k] = [v[0]]
+ end
+ get_and_verify_rabbit(RABBITMQ_MANIFEST, app, included_items, excluded_items)
+ end
+
it "Import and export serialized data for rabbit service", :rabbit => true do
quota = snapshot_quota('rabbit')
pending('This test requires quota > 2') unless quota > 2 # FIXME

0 comments on commit 925399c

Please sign in to comment.