Class: PerformanceTester::Outcome::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/performance_tester/outcome.rb

Overview

Models an executed http request

Defined Under Namespace

Classes: NullResponse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request, hosts) ⇒ Request

Returns a new instance of Request.



39
40
41
42
43
44
# File 'lib/performance_tester/outcome.rb', line 39

def initialize(request, hosts)
  @url = URI.parse(request.url)
  @request_time = request.time
  @response = parse_response(request.response_parts)
  @host_aliases = hosts.invert
end

Instance Attribute Details

#host_aliasesObject (readonly)

Returns the value of attribute host_aliases.



37
38
39
# File 'lib/performance_tester/outcome.rb', line 37

def host_aliases
  @host_aliases
end

#request_timeObject (readonly)

Returns the value of attribute request_time.



37
38
39
# File 'lib/performance_tester/outcome.rb', line 37

def request_time
  @request_time
end

#responseObject (readonly)

Returns the value of attribute response.



37
38
39
# File 'lib/performance_tester/outcome.rb', line 37

def response
  @response
end

#urlObject (readonly)

Returns the value of attribute url.



37
38
39
# File 'lib/performance_tester/outcome.rb', line 37

def url
  @url
end

Instance Method Details

#content_typeObject



74
75
76
# File 'lib/performance_tester/outcome.rb', line 74

def content_type
  response.content_type
end

#hostObject



50
51
52
# File 'lib/performance_tester/outcome.rb', line 50

def host
  url.host
end

#host_aliasObject



46
47
48
# File 'lib/performance_tester/outcome.rb', line 46

def host_alias
  host_aliases.fetch(host) { host }
end

#null_responseObject



86
87
88
# File 'lib/performance_tester/outcome.rb', line 86

def null_response
  NullResponse.new(request_time, 0, '')
end

#parse_response(response_parts) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/performance_tester/outcome.rb', line 78

def parse_response(response_parts)
  if response_parts && !response_parts.empty?
    response_parts.last
  else
    null_response
  end
end

#pathObject



54
55
56
# File 'lib/performance_tester/outcome.rb', line 54

def path
  url.request_uri
end

#response_timeObject



66
67
68
# File 'lib/performance_tester/outcome.rb', line 66

def response_time
  response.time
end

#statusObject



70
71
72
# File 'lib/performance_tester/outcome.rb', line 70

def status
  response.status
end

#time_elapsedObject



58
59
60
# File 'lib/performance_tester/outcome.rb', line 58

def time_elapsed
  response_time - request_time
end

#to_sObject



62
63
64
# File 'lib/performance_tester/outcome.rb', line 62

def to_s
  [host_alias, path, status, content_type, time_elapsed].inspect
end