Class: Stella::Client
- Inherits:
-
Object
- Object
- Stella::Client
- Includes:
- Gibbler::Complex, Observable
- Defined in:
- lib/stella/client.rb
Defined Under Namespace
Classes: Container, Quit, Repeat, ResponseError, ResponseModifier
Instance Attribute Summary collapse
-
#base_uri ⇒ Object
Returns the value of attribute base_uri.
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#proxy ⇒ Object
Returns the value of attribute proxy.
-
#stats ⇒ Object
readonly
Returns the value of attribute stats.
Instance Method Summary collapse
- #benchmark? ⇒ Boolean
- #disable_benchmark_mode ⇒ Object
- #enable_benchmark_mode ⇒ Object
- #execute(usecase) ⇒ Object
-
#initialize(base_uri = nil, client_id = 1) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(base_uri = nil, client_id = 1) ⇒ Client
Returns a new instance of Client.
14 15 16 17 18 19 |
# File 'lib/stella/client.rb', line 14 def initialize(base_uri=nil, client_id=1) @base_uri, @client_id = base_uri, client_id @cookie_file = Tempfile.new('stella-cookie') @stats = Stella::Stats.new("Client #{@client_id}") @proxy = OpenStruct.new end |
Instance Attribute Details
#base_uri ⇒ Object
Returns the value of attribute base_uri.
11 12 13 |
# File 'lib/stella/client.rb', line 11 def base_uri @base_uri end |
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
10 11 12 |
# File 'lib/stella/client.rb', line 10 def client_id @client_id end |
#proxy ⇒ Object
Returns the value of attribute proxy.
12 13 14 |
# File 'lib/stella/client.rb', line 12 def proxy @proxy end |
#stats ⇒ Object (readonly)
Returns the value of attribute stats.
13 14 15 |
# File 'lib/stella/client.rb', line 13 def stats @stats end |
Instance Method Details
#benchmark? ⇒ Boolean
72 |
# File 'lib/stella/client.rb', line 72 def benchmark?; @bm == true; end |
#disable_benchmark_mode ⇒ Object
71 |
# File 'lib/stella/client.rb', line 71 def disable_benchmark_mode; @bm = false; end |
#enable_benchmark_mode ⇒ Object
70 |
# File 'lib/stella/client.rb', line 70 def enable_benchmark_mode; @bm = true; end |
#execute(usecase) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/stella/client.rb', line 21 def execute(usecase) http_client = create_http_client container = Container.new(usecase) counter = 0 usecase.requests.each do |req| counter += 1 update(:prepare_request, usecase, req, counter) uri_obj = URI.parse(req.uri) params = prepare_params(usecase, req.params) headers = prepare_headers(usecase, req.headers) uri = build_request_uri uri_obj, params, container raise NoHostDefined, uri_obj if uri.host.nil? || uri.host.empty? unique_id = [req, params, headers, counter].gibbler req_id = req.gibbler meth = req.http_method.to_s.downcase Stella.ld "#{req.http_method}: " << "#{uri_obj.to_s} " << params.inspect begin send_request http_client, usecase, meth, uri, req, params, headers, container rescue => ex update(:request_error, usecase, uri, req, params, ex) next end #probe_header_size(container.response) #probe_body_size(container.response) ret = execute_response_handler container, req Stella.lflush # TODO: consider throw/catch case ret.class.to_s when "Stella::Client::Repeat" Stella.ld "REPETITION: #{counter} of #{ret.times+1}" redo if counter <= ret.times when "Stella::Client::Quit" Stella.ld "QUIT USECASE: #{ret.}" break end counter = 0 # reset run_sleeper(req.wait) if req.wait && !benchmark? end end |