stella 0.7.3.002 → 0.7.4.001

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,143 @@
1
+
2
+
3
+ module Stella
4
+
5
+ class Logger
6
+ @@disable = false
7
+ def self.disable!() @@disable = true end
8
+ def self.disabled?() @@disable == true end
9
+
10
+ attr_accessor :lev
11
+ attr_reader :templates
12
+
13
+ def initialize(output=STDOUT)
14
+ @mutex, @buffer = Mutex.new, StringIO.new
15
+ @lev, @offset = 1, 0
16
+ @templates = {}
17
+ @autoflush = false
18
+ return if Logger.disabled?
19
+ self.output = output
20
+ end
21
+
22
+ def autoflush!() @autoflush = true end
23
+ def autoflush?() @autoflush == true end
24
+
25
+ def add_template(name, str)
26
+ @templates[name.to_sym] = str
27
+ end
28
+
29
+ def template(name)
30
+ @templates[name]
31
+ end
32
+
33
+ def template?(name)
34
+ @templates.has_key? name
35
+ end
36
+
37
+ def print(level, *msg)
38
+ return if level > @lev || Logger.disabled?
39
+ @buffer.print *msg
40
+ flush if autoflush?
41
+ true
42
+ end
43
+ def print!(level, msg)
44
+ return unless @lev == level
45
+ print level, msg
46
+ end
47
+
48
+ def puts(level, *msg)
49
+ return if level > @lev || Logger.disabled?
50
+ @buffer.puts *msg
51
+ flush if autoflush?
52
+ true
53
+ end
54
+
55
+ def info(*msg) puts 1, *msg end
56
+ def info1(*msg) puts 1, *msg end
57
+ def info2(*msg) puts 2, *msg end
58
+ def info3(*msg) puts 3, *msg end
59
+ def info4(*msg) puts 4, *msg end
60
+
61
+ def tinfo(templ, *args)
62
+ info template(templ) % args
63
+ end
64
+
65
+ def twarn(templ, *args)
66
+ warn template(templ) % args
67
+ end
68
+
69
+ class UnknownTemplate < Stella::Error
70
+ end
71
+
72
+ def method_missing(meth, *args)
73
+ raise UnknownTemplate.new(meth.to_s) unless template? meth
74
+ tinfo meth, *args
75
+ end
76
+
77
+ def output=(o)
78
+ @mutex.synchronize do
79
+ if o.kind_of? String
80
+ o = File.open(o, File::CREAT|File::TRUNC|File::RDWR, 0644)
81
+ end
82
+ @output = o
83
+ end
84
+ end
85
+
86
+ def flush
87
+ return if Logger.disabled?
88
+ @mutex.synchronize do
89
+ #return if @offset == @output.tell
90
+ @buffer.seek @offset
91
+ @output.print @buffer.read unless @buffer.eof?
92
+ @offset = @buffer.tell
93
+ @output.flush
94
+ end
95
+ true
96
+ end
97
+
98
+ def path
99
+ @output.path if @output.respond_to? :path
100
+ end
101
+
102
+ def clear
103
+ return if Logger.disabled?
104
+ flush
105
+ @mutex.synchronize do
106
+ @buffer.rewind
107
+ @offset = 0
108
+ end
109
+ end
110
+
111
+ def close
112
+ return if Logger.disabled?
113
+ flush
114
+ @buffer.close
115
+ @output.close
116
+ end
117
+
118
+ end
119
+
120
+ # Prints to a buffer.
121
+ # Must call flush to send to output.
122
+ class SyncLogger < Logger
123
+ def print(level, *msg)
124
+ return if level > @lev || Logger.disabled?
125
+ @mutex.synchronize {
126
+ @buffer.print *msg
127
+ flush if autoflush?
128
+ }
129
+ true
130
+ end
131
+
132
+ def puts(level, *msg)
133
+ #Stella.ld [level, @lev, msg]
134
+ return if level > @lev || Logger.disabled?
135
+ @mutex.synchronize {
136
+ @buffer.puts *msg
137
+ flush if autoflush?
138
+ }
139
+ true
140
+ end
141
+ end
142
+
143
+ end
@@ -1,11 +1,24 @@
1
- require 'stella/testplan/usecase'
2
- require 'stella/testplan/stats'
1
+ autoload :CSV, 'csv'
3
2
 
4
3
  module Stella
5
4
  class Testplan
6
5
  include Gibbler::Complex
7
6
  extend Attic
8
7
 
8
+ @file_cache = {}
9
+
10
+ class << self
11
+ attr_reader :file_cache
12
+ def readlines path
13
+ if @file_cache.has_key?(path)
14
+ Stella.ld "FILE CACHE HIT: #{path}"
15
+ return @file_cache[path]
16
+ end
17
+ Stella.ld "FILE CACHE LOAD: #{path}"
18
+ @file_cache[path] = File.readlines(path)
19
+ end
20
+ end
21
+
9
22
  attic :base_path
10
23
  attic :plan_path
11
24
 
@@ -108,7 +121,7 @@ class Testplan
108
121
  dig = long ? r.digest_cache : r.digest_cache.shorter
109
122
  str << " %-62s".bright % ["#{r.desc} (#{dig})"]
110
123
  str << " %s" % [r]
111
- if Stella.loglev > 2
124
+ if Stella.stdout.lev > 2
112
125
  [:wait].each { |i| str << " %s: %s" % [i, r.send(i)] }
113
126
  end
114
127
  end
@@ -121,23 +134,166 @@ class Testplan
121
134
  1.0 - @testplan_current_ratio
122
135
  end
123
136
 
137
+ end
138
+ end
139
+
140
+
141
+ module Stella
142
+ class Testplan
143
+
144
+ #
145
+ # Any valid Ruby syntax will do the trick:
146
+ #
147
+ # usecase(10, "Self-serve") {
148
+ # post("/listing/add", "Add a listing") {
149
+ # wait 1..4
150
+ # param :name => random(8)
151
+ # param :city => "Vancouver"
152
+ # response(302) {
153
+ # repeat 3
154
+ # }
155
+ # }
156
+ # }
157
+ #
158
+ class Usecase
159
+ include Gibbler::Complex
160
+ include Stella::Data::Helpers
161
+ extend Attic
162
+
163
+ class Auth < Struct.new(:kind, :user, :pass)
164
+ include Gibbler::Complex
165
+ end
166
+
167
+ attic :base_path # we don't want gibbler to see this
168
+ attic :plan_path
169
+
170
+ attr_accessor :desc
171
+ attr_writer :ratio
172
+ attr_reader :http_auth
173
+
174
+ attr_accessor :requests
175
+ attr_accessor :resources
176
+
177
+ class UnknownResource < Stella::Error
178
+ def message; "UnknownResource: #{@obj}"; end
179
+ end
180
+
181
+ def initialize(&blk)
182
+ @requests, @resources = [], {}
183
+ instance_eval &blk unless blk.nil?
184
+ end
185
+
186
+ def desc(*args)
187
+ @desc = args.first unless args.empty?
188
+ @desc
189
+ end
190
+
191
+ def resource(name, value=nil)
192
+ @resources[name] = value unless value.nil?
193
+ @resources[name]
194
+ end
195
+
196
+ def ratio
197
+ r = (@ratio || 0).to_f
198
+ r = r/100 if r > 1
199
+ r
200
+ end
201
+
202
+ def ratio_pretty
203
+ r = (@ratio || 0).to_f
204
+ r > 1.0 ? r.to_i : (r * 100).to_i
205
+ end
206
+
207
+ # Reads the contents of the file <tt>path</tt> (the current working
208
+ # directory is assumed to be the same directory containing the test plan).
209
+ def read(path)
210
+ path = File.join(base_path, path) if base_path
211
+ Stella.ld "READING FILE: #{path}"
212
+ Stella::Testplan.readlines path
213
+ end
214
+
215
+ def list(path)
216
+ read(path).collect { |line| line.strip }
217
+ end
218
+
219
+ def csv(path)
220
+ path = File.join(base_path, path) if base_path
221
+ Stella.ld "READING CSV: #{path}"
222
+ file = Stella::Testplan.readlines path
223
+ CSV.parse file.join
224
+ end
225
+
226
+ def quickcsv(path)
227
+ path = File.join(base_path, path) if base_path
228
+ Stella.ld "READING CSV(QUICK): #{path}"
229
+ ar = []
230
+ file = Stella::Testplan.readlines path
231
+ file.each do |l|
232
+ l.strip!
233
+ ar << l.split(',')
234
+ end
235
+ ar
236
+ end
237
+
238
+ def freeze
239
+ @requests.each { |r| r.freeze }
240
+ super
241
+ self
242
+ end
243
+
244
+ def auth(user, pass=nil, kind=:basic)
245
+ @http_auth ||= Auth.new
246
+ @http_auth.user, @http_auth.pass, @http_auth.kind = user, pass, kind
247
+ end
248
+
249
+ def add_request(meth, *args, &blk)
250
+ req = Stella::Data::HTTP::Request.new meth.to_s.upcase, args[0], &blk
251
+ req.desc = args[1] if args.size > 1 # Description is optional
252
+ Stella.ld req
253
+ @requests << req
254
+ req
255
+ end
256
+ def get(*args, &blk); add_request :get, *args, &blk; end
257
+ def put(*args, &blk); add_request :put, *args, &blk; end
258
+ def post(*args, &blk); add_request :post, *args, &blk; end
259
+ def head(*args, &blk); add_request :head, *args, &blk; end
260
+ def delete(*args, &blk); add_request :delete, *args, &blk; end
261
+
262
+ def xget(*args, &blk); Stella.ld "Skipping get" end
263
+ def xput(*args, &blk); Stella.ld "Skipping put" end
264
+ def xpost(*args, &blk); Stella.ld "Skipping post" end
265
+ def xhead(*args, &blk); Stella.ld "Skipping head" end
266
+ def xdelete(*args, &blk); Stella.ld "Skipping delete" end
267
+
268
+ end
269
+
124
270
  end
125
271
  end
126
272
 
127
- __END__
128
- # instance_exec for Ruby 1.8 written by Mauricio Fernandez
129
- # http://eigenclass.org/hiki/instance_exec
130
- if RUBY_VERSION =~ /1.8/
131
- module InstanceExecHelper; end
132
- include InstanceExecHelper
133
- def instance_exec(*args, &block) # !> method redefined; discarding old instance_exec
134
- mname = "__instance_exec_#{Thread.current.object_id.abs}_#{object_id.abs}"
135
- InstanceExecHelper.module_eval{ define_method(mname, &block) }
136
- begin
137
- ret = send(mname, *args)
138
- ensure
139
- InstanceExecHelper.module_eval{ undef_method(mname) } rescue nil
140
- end
141
- ret
273
+
274
+
275
+ module Stella
276
+ class Testplan
277
+
278
+ class Stats
279
+ include Gibbler::Complex
280
+ attr_reader :requests
281
+
282
+ def initialize
283
+ @requests = OpenStruct.new
284
+ reset
285
+ end
286
+
287
+ def total_requests
288
+ @requests.successful + @requests.failed
289
+ end
290
+
291
+ def reset
292
+ @requests.successful = 0
293
+ @requests.failed = 0
294
+ end
295
+
142
296
  end
297
+
298
+ end
143
299
  end
data/stella.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  @spec = Gem::Specification.new do |s|
2
2
  s.name = "stella"
3
3
  s.rubyforge_project = 'stella'
4
- s.version = "0.7.3.002"
4
+ s.version = "0.7.4.001"
5
5
  s.summary = "Blame Stella for breaking your web applications."
6
6
  s.description = s.summary
7
7
  s.author = "Delano Mandelbaum"
@@ -15,10 +15,10 @@
15
15
 
16
16
  s.executables = %w[stella]
17
17
 
18
- s.add_dependency 'benelux', '>= 0.5.1'
18
+ s.add_dependency 'benelux', '>= 0.5.2'
19
19
  s.add_dependency 'drydock', '>= 0.6.8'
20
20
  s.add_dependency 'gibbler', '>= 0.7.1'
21
- s.add_dependency 'sysinfo', '>= 0.7.0'
21
+ s.add_dependency 'sysinfo', '>= 0.7.1'
22
22
  s.add_dependency 'storable', '>= 0.5.8'
23
23
  s.add_dependency 'nokogiri'
24
24
 
@@ -42,33 +42,20 @@
42
42
  lib/stella/cli.rb
43
43
  lib/stella/client.rb
44
44
  lib/stella/client/container.rb
45
- lib/stella/client/modifiers.rb
46
- lib/stella/config.rb
45
+ lib/stella/common.rb
47
46
  lib/stella/data.rb
48
47
  lib/stella/data/http.rb
49
- lib/stella/data/http/body.rb
50
- lib/stella/data/http/request.rb
51
- lib/stella/data/http/response.rb
52
48
  lib/stella/engine.rb
53
49
  lib/stella/engine/functional.rb
54
50
  lib/stella/engine/load_create.rb
55
51
  lib/stella/engine/load_package.rb
56
52
  lib/stella/engine/load_queue.rb
57
53
  lib/stella/engine/loadbase.rb
58
- lib/stella/exceptions.rb
59
54
  lib/stella/guidelines.rb
60
- lib/stella/mixins.rb
61
- lib/stella/mixins/numeric.rb
62
- lib/stella/mixins/string.rb
63
- lib/stella/mixins/thread.rb
64
- lib/stella/mixins/time.rb
65
- lib/stella/stats.rb
55
+ lib/stella/logger.rb
66
56
  lib/stella/testplan.rb
67
- lib/stella/testplan/stats.rb
68
- lib/stella/testplan/usecase.rb
69
57
  lib/stella/utils.rb
70
58
  lib/stella/utils/httputil.rb
71
- lib/stella/version.rb
72
59
  lib/threadify.rb
73
60
  stella.gemspec
74
61
  support/sample_webapp/app.rb
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.3.002
4
+ version: 0.7.4.001
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-11-02 00:00:00 -05:00
12
+ date: 2009-11-11 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 0.5.1
23
+ version: 0.5.2
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: drydock
@@ -50,7 +50,7 @@ dependencies:
50
50
  requirements:
51
51
  - - ">="
52
52
  - !ruby/object:Gem::Version
53
- version: 0.7.0
53
+ version: 0.7.1
54
54
  version:
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: storable
@@ -100,33 +100,20 @@ files:
100
100
  - lib/stella/cli.rb
101
101
  - lib/stella/client.rb
102
102
  - lib/stella/client/container.rb
103
- - lib/stella/client/modifiers.rb
104
- - lib/stella/config.rb
103
+ - lib/stella/common.rb
105
104
  - lib/stella/data.rb
106
105
  - lib/stella/data/http.rb
107
- - lib/stella/data/http/body.rb
108
- - lib/stella/data/http/request.rb
109
- - lib/stella/data/http/response.rb
110
106
  - lib/stella/engine.rb
111
107
  - lib/stella/engine/functional.rb
112
108
  - lib/stella/engine/load_create.rb
113
109
  - lib/stella/engine/load_package.rb
114
110
  - lib/stella/engine/load_queue.rb
115
111
  - lib/stella/engine/loadbase.rb
116
- - lib/stella/exceptions.rb
117
112
  - lib/stella/guidelines.rb
118
- - lib/stella/mixins.rb
119
- - lib/stella/mixins/numeric.rb
120
- - lib/stella/mixins/string.rb
121
- - lib/stella/mixins/thread.rb
122
- - lib/stella/mixins/time.rb
123
- - lib/stella/stats.rb
113
+ - lib/stella/logger.rb
124
114
  - lib/stella/testplan.rb
125
- - lib/stella/testplan/stats.rb
126
- - lib/stella/testplan/usecase.rb
127
115
  - lib/stella/utils.rb
128
116
  - lib/stella/utils/httputil.rb
129
- - lib/stella/version.rb
130
117
  - lib/threadify.rb
131
118
  - stella.gemspec
132
119
  - support/sample_webapp/app.rb