forked from gojek/wrest
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
446 lines (402 loc) · 15.2 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
# Copyright 2009 Sidu Ponnappa
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and limitations under the License.
# Note that some optional libraries/gems that the build (not Wrest itself) uses may not be available on all implementations of Ruby.
puts "Building on Ruby #{RUBY_VERSION}, #{RUBY_RELEASE_DATE}, #{RUBY_PLATFORM}"
require 'rubygems'
require 'bundler'
Bundler::GemHelper.install_tasks
Bundler.setup
require 'rspec/core/rake_task'
# require 'hanna/rdoctask'
require 'rake/contrib/sshpublisher'
# begin
# require 'metric_fu'
# MetricFu::Configuration.run do |config|
# config.rcov[:test_files] = ['spec/**/*_spec.rb']
# config.rcov[:rcov_opts] << "-Ispec" # Needed to find spec_helper
# end
# rescue LoadError
# puts 'metric_fu is not available. Install it with: gem install jscruggs-metric_fu -s http://gems.github.com'
# end
desc 'Default: run spec tests.'
task :default => 'rspec:unit'
desc 'Cruise task'
task :cruise => 'rspec:unit'
namespace :rspec do
desc "Run all unit specs"
task :unit do
ENV["wrest_functional_spec"] = nil
Rake::Task["rspec:spec_runner"].invoke
end
desc "Run all live functional specs - requires sample_rails_app running at 3000 in test environment"
task :functional do
ENV["wrest_functional_spec"] = "true"
Rake::Task["rspec:spec_runner"].invoke
end
RSpec::Core::RakeTask.new(:spec_runner) do |task|
task.pattern = 'spec/wrest/**/*_spec.rb'
end
end
# desc 'Generate documentation for Wrest'
# Rake::RDocTask.new(:rdoc) do |rdoc|
# rdoc.rdoc_dir = 'rdoc'
# rdoc.title = 'Wrest Documentation'
# rdoc.options << '--line-numbers' << '--inline-source'
# rdoc.rdoc_files.include('README.rdoc')
# rdoc.rdoc_files.include('lib/**/*.rb')
# end
namespace :rubyforge do
desc "Release gem and RDoc documentation to RubyForge"
task :release => ["rubyforge:release:gem", "rubyforge:release:docs"]
namespace :release do
desc "Publish RDoc to RubyForge."
task :docs => [:rdoc] do
config = YAML.load(
File.read(File.expand_path('~/.rubyforge/user-config.yml'))
)
host = "#{config['username']}@rubyforge.org"
remote_dir = "/var/www/gforge-projects/wrest/"
local_dir = 'rdoc'
Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
end
end
end
namespace (:benchmark) do
desc "Create classes to be used in Wrest::Resource vs. ActiveResource"
task :setup_test_classes do
require 'active_resource'
require 'lib/wrest'
class Ooga < Wrest::Resource::Base
end
class Booga < ActiveResource::Base
self.site=''
end
end
desc "Benchmark when objects are created each time before getting data; i.e there are few queries per instantiation"
task :create_and_get => :setup_test_classes do |t|
n = 10000
puts "Running #{n} times per report"
Benchmark.bmbm(10) do |rpt|
rpt.report("Wrest::Resource") do
n.times {
ooga = Ooga.new(:id => 5, :profession => 'Natural Magician', :enhanced_by => 'Kai Wren')
ooga.profession
ooga.profession?
ooga.enhanced_by
ooga.enhanced_by?
}
end
rpt.report("ActiveResource") do
n.times {
booga = Booga.new(:id => 5, :profession => 'Natural Magician', :enhanced_by => 'Kai Wren')
booga.profession
booga.profession?
booga.enhanced_by
booga.enhanced_by?
}
end
end
end
desc "Benchmark when objects are created beforehand; i.e there are many queries per instantiation"
task :create_once_and_get => :setup_test_classes do |t|
n = 10000
puts "Running #{n} times per report"
Benchmark.bmbm(10) do |rpt|
rpt.report("Wrest::Resource") do
ooga = Ooga.new(:id => 5, :profession => 'Natural Magician', :enhanced_by => 'Kai Wren')
n.times {
ooga.profession
ooga.profession?
ooga.enhanced_by
ooga.enhanced_by?
}
end
rpt.report("ActiveResource") do
booga = Booga.new(:id => 5, :profession => 'Natural Magician', :enhanced_by => 'Kai Wren')
n.times {
booga.profession
booga.profession?
booga.enhanced_by
booga.enhanced_by?
}
end
end
end
desc "Benchmark objects respond_to? performance without invocation"
task :responds_to_before => :setup_test_classes do |t|
n = 10000
puts "Running #{n} times per report"
Benchmark.bmbm(10) do |rpt|
rpt.report("Wrest::Resource") do
ooga = Ooga.new(:id => 5, :profession => 'Natural Magician', :enhanced_by => 'Kai Wren')
n.times {
ooga.respond_to?(:profession)
ooga.respond_to?(:profession?)
ooga.respond_to?(:profession=)
}
end
rpt.report("ActiveResource") do
booga = Booga.new(:id => 5, :profession => 'Natural Magician', :enhanced_by => 'Kai Wren')
n.times {
booga.respond_to?(:profession)
booga.respond_to?(:profession?)
booga.respond_to?(:profession=)
}
end
end
end
desc "Benchmark objects respond_to? performance after invocation"
task :responds_to_after => :setup_test_classes do |t|
n = 10000
puts "Running #{n} times per report"
Benchmark.bmbm(10) do |rpt|
rpt.report("Wrest::Resource") do
ooga = Ooga.new(:id => 5, :profession => 'Natural Magician', :enhanced_by => 'Kai Wren')
ooga.profession
ooga.profession?
ooga.profession = ''
n.times {
ooga.respond_to?(:profession)
ooga.respond_to?(:profession?)
ooga.respond_to?(:profession=)
}
end
rpt.report("ActiveResource") do
booga = Booga.new(:id => 5, :profession => 'Natural Magician', :enhanced_by => 'Kai Wren')
booga.profession
booga.profession?
booga.profession = ''
n.times {
booga.respond_to?(:profession)
booga.respond_to?(:profession?)
booga.respond_to?(:profession=)
}
end
end
end
desc "Benchmark keepalive connections (needs functional/sample_rails_app running with class-caching on and keep-alive enabled)"
task :keep_alive => :setup_test_classes do
n = 20
Wrest.logger = Logger.new(File.open("log/benchmark.log", 'a'))
Benchmark.bmbm(10) do |rpt|
rpt.report("Fresh connections (Connection: Close)") do
n.times {
'http://localhost:3000/headers'.to_uri.get
'http://localhost:3000/lead_bottles.xml?owner=Kai&type=bottle'.to_uri.get
}
end
rpt.report("Keep-alive connection (Connection: Keep-Alive)") do
Wrest::Native::Session.new('http://localhost:3000'.to_uri) do |session|
n.times {
session.get '/headers'
session.get '/lead_bottles.xml'
}
end
end
end
end
desc "Benchmark xml deserialisation"
task :deserialise_xml => :setup_test_classes do |t|
n = 100
puts "Deserialising using #{ActiveSupport::XmlMini.backend}"
Benchmark.bmbm(10) do |rpt|
rpt.report("Hash.from_xml") do
n.times {
Hash.from_xml(serialised_data)
}
end
end
end
def serialised_data
<<-EOXML
<?xml version="1.0" encoding="UTF-8"?>
<business-units type="array">
<business-unit>
<company>OogaInc</company>
<created-at type="datetime">2008-08-27T16:21:33Z</created-at>
<department>FooMeh</department>
<id type="integer">1</id>
<client-number>0001</client-number>
<updated-at type="datetime">2008-08-27T16:21:33Z</updated-at>
<accounts type="array">
<account>
<account-number>1</account-number>
<created-at type="datetime">2008-08-27T16:21:33Z</created-at>
<id type="integer">1</id>
<client-id type="integer">1</client-id>
<updated-at type="datetime">2008-08-27T16:21:33Z</updated-at>
<client-number>0001</client-number>
</account>
</accounts>
</business-unit>
<business-unit>
<company>OogaInc</company>
<created-at type="datetime">2008-08-27T18:35:22Z</created-at>
<department>BoogaBooga</department>
<id type="integer">32479</id>
<client-number>0002</client-number>
<updated-at type="datetime">2008-08-27T18:35:37Z</updated-at>
<accounts type="array">
<account>
<account-number>0</account-number>
<created-at type="datetime">2008-08-27T18:36:07Z</created-at>
<id type="integer">32479</id>
<client-id type="integer">32479</client-id>
<updated-at type="datetime">2008-08-27T18:36:12Z</updated-at>
<client-number>0002</client-number>
</account>
</accounts>
</business-unit>
<business-unit>
<company>OogaInc</company>
<created-at type="datetime">2008-08-27T16:21:33Z</created-at>
<department>Engineering</department>
<id type="integer">2</id>
<client-number>000101</client-number>
<updated-at type="datetime">2008-08-27T16:21:33Z</updated-at>
<accounts type="array">
<account>
<account-number>101</account-number>
<created-at type="datetime">2008-08-27T16:21:33Z</created-at>
<id type="integer">2</id>
<client-id type="integer">2</client-id>
<updated-at type="datetime">2008-08-27T16:21:33Z</updated-at>
<client-number>000101</client-number>
</account>
</accounts>
</business-unit>
<business-unit>
<company>OogaInc</company>
<created-at type="datetime">2008-08-27T16:21:34Z</created-at>
<department></department>
<id type="integer">3</id>
<client-number>0001000</client-number>
<updated-at type="datetime">2008-08-27T16:21:34Z</updated-at>
<accounts type="array">
<account>
<account-number>31974</account-number>
<created-at type="datetime">2008-08-27T16:21:34Z</created-at>
<id type="integer">3</id>
<client-id type="integer">3</client-id>
<updated-at type="datetime">2008-08-27T16:21:34Z</updated-at>
<client-number>0001000</client-number>
</account>
</accounts>
</business-unit>
<business-unit>
<company>OogaInc</company>
<created-at type="datetime">2008-08-27T16:21:34Z</created-at>
<department></department>
<id type="integer">4</id>
<client-number>0001001</client-number>
<updated-at type="datetime">2008-08-27T16:21:34Z</updated-at>
<accounts type="array">
<account>
<account-number>656064</account-number>
<created-at type="datetime">2008-08-27T16:21:34Z</created-at>
<id type="integer">4</id>
<client-id type="integer">4</client-id>
<updated-at type="datetime">2008-08-27T16:21:34Z</updated-at>
<client-number>0001001</client-number>
</account>
</accounts>
</business-unit>
<business-unit>
<company>OogaInc</company>
<created-at type="datetime">2008-08-27T16:21:34Z</created-at>
<department></department>
<id type="integer">5</id>
<client-number>0001002</client-number>
<updated-at type="datetime">2008-08-27T16:21:34Z</updated-at>
<accounts type="array">
<account>
<account-number>619842</account-number>
<created-at type="datetime">2008-08-27T16:21:34Z</created-at>
<id type="integer">5</id>
<client-id type="integer">5</client-id>
<updated-at type="datetime">2008-08-27T16:21:34Z</updated-at>
<client-number>0001002</client-number>
</account>
</accounts>
</business-unit>
<business-unit>
<company>OogaInc</company>
<created-at type="datetime">2008-08-27T16:21:34Z</created-at>
<department></department>
<id type="integer">6</id>
<client-number>0001003</client-number>
<updated-at type="datetime">2008-08-27T16:21:34Z</updated-at>
<accounts type="array">
<account>
<account-number>694370</account-number>
<created-at type="datetime">2008-08-27T16:21:34Z</created-at>
<id type="integer">6</id>
<client-id type="integer">6</client-id>
<updated-at type="datetime">2008-08-27T16:21:34Z</updated-at>
<client-number>0001003</client-number>
</account>
</accounts>
</business-unit>
<business-unit>
<company>OogaInc</company>
<created-at type="datetime">2008-08-27T16:21:34Z</created-at>
<department></department>
<id type="integer">7</id>
<client-number>0001004</client-number>
<updated-at type="datetime">2008-08-27T16:21:34Z</updated-at>
<accounts type="array">
<account>
<account-number>29284</account-number>
<created-at type="datetime">2008-08-27T16:21:34Z</created-at>
<id type="integer">7</id>
<client-id type="integer">7</client-id>
<updated-at type="datetime">2008-08-27T16:21:34Z</updated-at>
<client-number>0001004</client-number>
</account>
</accounts>
</business-unit>
<business-unit>
<company>OogaInc</company>
<created-at type="datetime">2008-08-27T16:21:34Z</created-at>
<department></department>
<id type="integer">8</id>
<client-number>0001005</client-number>
<updated-at type="datetime">2008-08-27T16:21:34Z</updated-at>
<accounts type="array">
<account>
<account-number>21285</account-number>
<created-at type="datetime">2008-08-27T16:21:34Z</created-at>
<id type="integer">8</id>
<client-id type="integer">8</client-id>
<updated-at type="datetime">2008-08-27T16:21:34Z</updated-at>
<client-number>0001005</client-number>
</account>
</accounts>
</business-unit>
<business-unit>
<company>OogaInc</company>
<created-at type="datetime">2008-08-27T16:21:34Z</created-at>
<department></department>
<id type="integer">9</id>
<client-number>0001006</client-number>
<updated-at type="datetime">2008-08-27T16:21:34Z</updated-at>
<accounts type="array">
<account>
<account-number>638772</account-number>
<created-at type="datetime">2008-08-27T16:21:34Z</created-at>
<id type="integer">9</id>
<client-id type="integer">9</client-id>
<updated-at type="datetime">2008-08-27T16:21:34Z</updated-at>
<client-number>0001006</client-number>
</account>
</accounts>
</business-unit>
</business-units>
EOXML
end
end