stella 0.7.0.004 → 0.7.0.005
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/stella +16 -20
- data/examples/essentials/logo.png +0 -0
- data/examples/{basic → essentials}/plan.rb +7 -3
- data/examples/{basic → essentials}/search_terms.csv +0 -0
- data/examples/example_webapp.rb +7 -4
- data/examples/example_webapp.ru +3 -0
- data/lib/stella.rb +18 -26
- data/lib/stella/cli.rb +4 -1
- data/lib/stella/client.rb +49 -26
- data/lib/stella/data.rb +35 -9
- data/lib/stella/data/http.rb +1 -1
- data/lib/stella/data/http/request.rb +3 -14
- data/lib/stella/engine.rb +10 -4
- data/lib/stella/engine/functional.rb +2 -4
- data/lib/stella/engine/load.rb +24 -21
- data/lib/stella/mixins.rb +1 -1
- data/lib/stella/stats.rb +17 -4
- data/lib/stella/testplan/usecase.rb +2 -2
- data/lib/stella/utils.rb +16 -1
- data/lib/stella/version.rb +1 -1
- data/stella.gemspec +17 -4
- data/vendor/httpclient-2.1.5.2/httpclient.rb +1025 -0
- data/vendor/httpclient-2.1.5.2/httpclient/auth.rb +522 -0
- data/vendor/httpclient-2.1.5.2/httpclient/cacert.p7s +1579 -0
- data/vendor/httpclient-2.1.5.2/httpclient/cacert_sha1.p7s +1579 -0
- data/vendor/httpclient-2.1.5.2/httpclient/connection.rb +84 -0
- data/vendor/httpclient-2.1.5.2/httpclient/cookie.rb +562 -0
- data/vendor/httpclient-2.1.5.2/httpclient/http.rb +867 -0
- data/vendor/httpclient-2.1.5.2/httpclient/session.rb +864 -0
- data/vendor/httpclient-2.1.5.2/httpclient/ssl_config.rb +417 -0
- data/vendor/httpclient-2.1.5.2/httpclient/stats.rb +90 -0
- data/vendor/httpclient-2.1.5.2/httpclient/timeout.rb +136 -0
- data/vendor/httpclient-2.1.5.2/httpclient/util.rb +86 -0
- metadata +18 -5
- data/lib/stella/dsl.rb +0 -5
@@ -0,0 +1,136 @@
|
|
1
|
+
# HTTPClient - HTTP client library.
|
2
|
+
# Copyright (C) 2000-2009 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
|
3
|
+
#
|
4
|
+
# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
|
5
|
+
# redistribute it and/or modify it under the same terms of Ruby's license;
|
6
|
+
# either the dual license version in 2003, or any later version.
|
7
|
+
|
8
|
+
|
9
|
+
require 'timeout'
|
10
|
+
require 'thread'
|
11
|
+
|
12
|
+
|
13
|
+
class HTTPClient
|
14
|
+
|
15
|
+
|
16
|
+
# Replaces timeout.rb to avoid Thread creation and scheduling overhead.
|
17
|
+
#
|
18
|
+
# You should check another timeout replace in WEBrick.
|
19
|
+
# See lib/webrick/utils.rb in ruby/1.9.
|
20
|
+
#
|
21
|
+
# About this implementation:
|
22
|
+
# * Do not create Thread for each timeout() call. Just create 1 Thread for
|
23
|
+
# timeout scheduler.
|
24
|
+
# * Do not wakeup the scheduler thread so often. Let scheduler thread sleep
|
25
|
+
# until the nearest period.
|
26
|
+
class TimeoutScheduler
|
27
|
+
|
28
|
+
# Represents timeout period.
|
29
|
+
class Period
|
30
|
+
attr_reader :thread, :time
|
31
|
+
|
32
|
+
# Creates new Period.
|
33
|
+
def initialize(thread, time, ex)
|
34
|
+
@thread, @time, @ex = thread, time, ex
|
35
|
+
@lock = Mutex.new
|
36
|
+
end
|
37
|
+
|
38
|
+
# Raises if thread exists and alive.
|
39
|
+
def raise(message)
|
40
|
+
@lock.synchronize do
|
41
|
+
if @thread and @thread.alive?
|
42
|
+
@thread.raise(@ex, message)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Cancel this Period. Mutex is needed to avoid too-late exception.
|
48
|
+
def cancel
|
49
|
+
@lock.synchronize do
|
50
|
+
@thread = nil
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# Creates new TimeoutScheduler.
|
56
|
+
def initialize
|
57
|
+
@pool = {}
|
58
|
+
@next = nil
|
59
|
+
@thread = start_timer_thread
|
60
|
+
end
|
61
|
+
|
62
|
+
# Registers new timeout period.
|
63
|
+
def register(thread, sec, ex)
|
64
|
+
period = Period.new(thread, Time.now + sec, ex || ::Timeout::Error)
|
65
|
+
@pool[period] = true
|
66
|
+
if @next.nil? or period.time < @next
|
67
|
+
begin
|
68
|
+
@thread.wakeup
|
69
|
+
rescue ThreadError
|
70
|
+
# Thread may be dead by fork.
|
71
|
+
@thread = start_timer_thread
|
72
|
+
end
|
73
|
+
end
|
74
|
+
period
|
75
|
+
end
|
76
|
+
|
77
|
+
# Cancels the given period.
|
78
|
+
def cancel(period)
|
79
|
+
@pool.delete(period)
|
80
|
+
period.cancel
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def start_timer_thread
|
86
|
+
thread = Thread.new {
|
87
|
+
while true
|
88
|
+
if @pool.empty?
|
89
|
+
@next = nil
|
90
|
+
sleep
|
91
|
+
else
|
92
|
+
min, = @pool.min { |a, b| a[0].time <=> b[0].time }
|
93
|
+
@next = min.time
|
94
|
+
sec = @next - Time.now
|
95
|
+
if sec > 0
|
96
|
+
sleep(sec)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
now = Time.now
|
100
|
+
@pool.keys.each do |period|
|
101
|
+
if period.time < now
|
102
|
+
period.raise('execution expired')
|
103
|
+
cancel(period)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
}
|
108
|
+
Thread.pass while thread.status != 'sleep'
|
109
|
+
thread
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
class << self
|
114
|
+
# CAUTION: caller must aware of race condition.
|
115
|
+
def timeout_scheduler
|
116
|
+
@timeout_scheduler ||= TimeoutScheduler.new
|
117
|
+
end
|
118
|
+
end
|
119
|
+
timeout_scheduler # initialize at first time.
|
120
|
+
|
121
|
+
module Timeout
|
122
|
+
def timeout(sec, ex = nil, &block)
|
123
|
+
return yield if sec == nil or sec.zero?
|
124
|
+
scheduler = nil
|
125
|
+
begin
|
126
|
+
scheduler = HTTPClient.timeout_scheduler
|
127
|
+
period = scheduler.register(Thread.current, sec, ex)
|
128
|
+
yield(sec)
|
129
|
+
ensure
|
130
|
+
scheduler.cancel(period) if scheduler and period
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
|
136
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# HTTPClient - HTTP client library.
|
2
|
+
# Copyright (C) 2000-2009 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
|
3
|
+
#
|
4
|
+
# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
|
5
|
+
# redistribute it and/or modify it under the same terms of Ruby's license;
|
6
|
+
# either the dual license version in 2003, or any later version.
|
7
|
+
|
8
|
+
|
9
|
+
require 'uri'
|
10
|
+
|
11
|
+
|
12
|
+
class HTTPClient
|
13
|
+
|
14
|
+
|
15
|
+
# A module for common function.
|
16
|
+
module Util
|
17
|
+
# Keyword argument helper.
|
18
|
+
# args:: given arguments.
|
19
|
+
# *field:: a list of arguments to be extracted.
|
20
|
+
#
|
21
|
+
# You can extract 3 arguments (a, b, c) with:
|
22
|
+
#
|
23
|
+
# include Util
|
24
|
+
# def my_method(*args)
|
25
|
+
# a, b, c = keyword_argument(args, :a, :b, :c)
|
26
|
+
# ...
|
27
|
+
# end
|
28
|
+
# my_method(1, 2, 3)
|
29
|
+
# my_method(:b => 2, :a = 1)
|
30
|
+
#
|
31
|
+
# instead of;
|
32
|
+
#
|
33
|
+
# def my_method(a, b, c)
|
34
|
+
# ...
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
def keyword_argument(args, *field)
|
38
|
+
if args.size == 1 and args[0].is_a?(Hash)
|
39
|
+
args[0].values_at(*field)
|
40
|
+
else
|
41
|
+
args
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Gets an URI instance.
|
46
|
+
def urify(uri)
|
47
|
+
if uri.nil?
|
48
|
+
nil
|
49
|
+
elsif uri.is_a?(URI)
|
50
|
+
uri
|
51
|
+
else
|
52
|
+
URI.parse(uri.to_s)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Returns true if the given 2 URIs have a part_of relationship.
|
57
|
+
# * the same scheme
|
58
|
+
# * the same host String (no host resolution or IP-addr conversion)
|
59
|
+
# * the same port number
|
60
|
+
# * target URI's path starts with base URI's path.
|
61
|
+
def uri_part_of(uri, part)
|
62
|
+
((uri.scheme == part.scheme) and
|
63
|
+
(uri.host == part.host) and
|
64
|
+
(uri.port == part.port) and
|
65
|
+
uri.path.upcase.index(part.path.upcase) == 0)
|
66
|
+
end
|
67
|
+
module_function :uri_part_of
|
68
|
+
|
69
|
+
# Returns parent directory URI of the given URI.
|
70
|
+
def uri_dirname(uri)
|
71
|
+
uri = uri.clone
|
72
|
+
uri.path = uri.path.sub(/\/[^\/]*\z/, '/')
|
73
|
+
uri
|
74
|
+
end
|
75
|
+
module_function :uri_dirname
|
76
|
+
|
77
|
+
# Finds a value of a Hash.
|
78
|
+
def hash_find_value(hash, &block)
|
79
|
+
v = hash.find(&block)
|
80
|
+
v ? v[1] : nil
|
81
|
+
end
|
82
|
+
module_function :hash_find_value
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stella
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.0.
|
4
|
+
version: 0.7.0.005
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Delano Mandelbaum
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-09-
|
12
|
+
date: 2009-09-18 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -78,9 +78,11 @@ files:
|
|
78
78
|
- README.rdoc
|
79
79
|
- Rakefile
|
80
80
|
- bin/stella
|
81
|
-
- examples/
|
82
|
-
- examples/
|
81
|
+
- examples/essentials/logo.png
|
82
|
+
- examples/essentials/plan.rb
|
83
|
+
- examples/essentials/search_terms.csv
|
83
84
|
- examples/example_webapp.rb
|
85
|
+
- examples/example_webapp.ru
|
84
86
|
- examples/exceptions/plan.rb
|
85
87
|
- lib/stella.rb
|
86
88
|
- lib/stella/cli.rb
|
@@ -91,7 +93,6 @@ files:
|
|
91
93
|
- lib/stella/data/http/body.rb
|
92
94
|
- lib/stella/data/http/request.rb
|
93
95
|
- lib/stella/data/http/response.rb
|
94
|
-
- lib/stella/dsl.rb
|
95
96
|
- lib/stella/engine.rb
|
96
97
|
- lib/stella/engine/functional.rb
|
97
98
|
- lib/stella/engine/load.rb
|
@@ -108,6 +109,18 @@ files:
|
|
108
109
|
- lib/threadify.rb
|
109
110
|
- stella.gemspec
|
110
111
|
- support/useragents.txt
|
112
|
+
- vendor/httpclient-2.1.5.2/httpclient.rb
|
113
|
+
- vendor/httpclient-2.1.5.2/httpclient/auth.rb
|
114
|
+
- vendor/httpclient-2.1.5.2/httpclient/cacert.p7s
|
115
|
+
- vendor/httpclient-2.1.5.2/httpclient/cacert_sha1.p7s
|
116
|
+
- vendor/httpclient-2.1.5.2/httpclient/connection.rb
|
117
|
+
- vendor/httpclient-2.1.5.2/httpclient/cookie.rb
|
118
|
+
- vendor/httpclient-2.1.5.2/httpclient/http.rb
|
119
|
+
- vendor/httpclient-2.1.5.2/httpclient/session.rb
|
120
|
+
- vendor/httpclient-2.1.5.2/httpclient/ssl_config.rb
|
121
|
+
- vendor/httpclient-2.1.5.2/httpclient/stats.rb
|
122
|
+
- vendor/httpclient-2.1.5.2/httpclient/timeout.rb
|
123
|
+
- vendor/httpclient-2.1.5.2/httpclient/util.rb
|
111
124
|
has_rdoc: true
|
112
125
|
homepage: http://solutious.com/projects/stella/
|
113
126
|
licenses: []
|