|
@@ -4,6 +4,7 @@
|
|
|
class HelloWorld < Roda
|
|
|
plugin :default_headers, 'Content-Type'=>'text/html; charset=utf-8'
|
|
|
plugin :default_headers, 'Server'=>SERVER_STRING if SERVER_STRING
|
|
|
+ plugin :hooks
|
|
|
plugin :json
|
|
|
plugin :render, :escape=>:erubi, :layout_opts=>{ :cache_key=>'default_layout' }
|
|
|
plugin :static_routing
|
|
@@ -20,42 +21,27 @@ class HelloWorld < Roda
|
|
|
Random.rand(MAX_PK).succ
|
|
|
end
|
|
|
|
|
|
- # Return an array of `n' unique random numbers between 1 and MAX_PK
|
|
|
- def randn(n)
|
|
|
- (1..MAX_PK).to_a.shuffle!.take(n)
|
|
|
- end
|
|
|
-
|
|
|
- def set_date
|
|
|
+ after do
|
|
|
response['Date'] = Time.now.httpdate
|
|
|
end
|
|
|
|
|
|
# Test type 1: JSON serialization
|
|
|
static_get '/json' do
|
|
|
- set_date
|
|
|
-
|
|
|
{ :message=>'Hello, World!' }
|
|
|
end
|
|
|
|
|
|
# Test type 2: Single database query
|
|
|
static_get '/db' do
|
|
|
- set_date
|
|
|
-
|
|
|
World.with_pk(rand1).values
|
|
|
end
|
|
|
|
|
|
# Test type 3: Multiple database queries
|
|
|
static_get '/queries' do
|
|
|
- set_date
|
|
|
-
|
|
|
- # Benchmark requirements explicitly forbid a WHERE..IN here, so be good
|
|
|
- randn(bounded_queries)
|
|
|
- .map! { |id| World.with_pk(id).values }
|
|
|
+ Array.new(bounded_queries) { World.with_pk(rand1).values }
|
|
|
end
|
|
|
|
|
|
# Test type 4: Fortunes
|
|
|
static_get '/fortunes' do
|
|
|
- set_date
|
|
|
-
|
|
|
@fortunes = Fortune.all
|
|
|
@fortunes << Fortune.new(
|
|
|
:id=>0,
|
|
@@ -68,24 +54,15 @@ class HelloWorld < Roda
|
|
|
|
|
|
# Test type 5: Database updates
|
|
|
static_get '/updates' do
|
|
|
- set_date
|
|
|
-
|
|
|
- # Benchmark requirements explicitly forbid a WHERE..IN here, transactions
|
|
|
- # are optional, batch updates are allowed (but each transaction can only
|
|
|
- # read and write a single record?), so... be good
|
|
|
- randn(bounded_queries).map! do |id|
|
|
|
- DB.transaction do
|
|
|
- world = World.for_update.with_pk(id)
|
|
|
- world.update(:randomnumber=>rand1)
|
|
|
- world.values
|
|
|
- end
|
|
|
+ Array.new(bounded_queries) do
|
|
|
+ world = World.with_pk(rand1)
|
|
|
+ world.update(:randomnumber=>rand1)
|
|
|
+ world.values
|
|
|
end
|
|
|
end
|
|
|
|
|
|
# Test type 6: Plaintext
|
|
|
static_get '/plaintext' do
|
|
|
- set_date
|
|
|
-
|
|
|
response['Content-Type'] = 'text/plain'
|
|
|
|
|
|
'Hello, World!'
|