lib/stella/client.rb in solutious-stella-0.7.0.002 vs lib/stella/client.rb in solutious-stella-0.7.0.003
- old
+ new
@@ -14,10 +14,11 @@
@base_uri, @client_id = base_uri, client_id
@cookie_file = Tempfile.new('stella-cookie')
@stats = Stella::Stats.new("Client #{@client_id}")
end
+
def execute(usecase)
http_client = generate_http_client
container = Container.new(usecase)
counter = 0
usecase.requests.each do |req|
@@ -28,20 +29,19 @@
raise NoHostDefined, uri_obj if uri.host.nil? || uri.host.empty?
meth = req.http_method.to_s.downcase
Stella.ld "#{meth}: " << "#{uri_obj.to_s} " << req.params.inspect
- changed and notify_observers(:send_request, @client_id, usecase, meth, uri, req, params, counter)
begin
+ update(:send_request, usecase, meth, uri, req, params, counter)
container.response = http_client.send(meth, uri, params) # booya!
- changed and notify_observers(:receive_response, @client_id, usecase, meth, uri, req, params, container)
+ update(:receive_response, usecase, meth, uri, req, params, container)
rescue => ex
- changed and notify_observers(:request_error, @client_id, usecase, meth, uri, req, params, ex)
+ update(:request_error, usecase, meth, uri, req, params, ex)
next
end
-
ret = execute_response_handler container, req
Drydock::Screen.flush
if ret.kind_of?(ResponseModifier)
@@ -60,10 +60,15 @@
def enable_benchmark_mode; @bm = true; end
def disable_benchmark_mode; @bm = false; end
def benchmark?; @bm == true; end
private
+ def update(kind, *args)
+ changed
+ notify_observers(kind, @client_id, *args)
+ end
+
def run_sleeper(wait)
if wait.is_a?(Range)
ms = rand(wait.last * 1000).to_f
ms = wait.first if ms < wait.first
else
@@ -137,22 +142,22 @@
# Find the appropriate response handler by executing the
# HTTP response status against the configured handlers.
# If several match, the first one is used.
def execute_response_handler(container, req)
- handlers = req.response.select do |regex,handler|
+ handler = nil
+ req.response.each_pair do |regex,h|
regex = /#{regex}/ unless regex.is_a? Regexp
Stella.ld "HANDLER REGEX: #{regex} (#{container.status})"
- container.status.to_s =~ regex
+ handler = h and break if container.status.to_s =~ regex
end
ret = nil
- unless handlers.empty?
+ unless handler.nil?
begin
- changed
- ret = container.instance_eval &handlers.values.first
- notify_observers(:execute_response_handler, @client_id, req, container)
+ ret = container.instance_eval &handler
+ update(:execute_response_handler, req, container)
rescue => ex
- notify_observers(:error_execute_response_handler, @client_id, ex, req, container)
+ update(:error_execute_response_handler, ex, req, container)
Stella.ld ex.message, ex.backtrace
end
end
ret
end
\ No newline at end of file