racknga 0.9.0 → 0.9.1

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,141 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright (C) 2010 Kouhei Sutou <kou@clear-code.com>
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+ #%# family=auto
19
+ #%# capabilities=autoconf
20
+
21
+ require 'rubygems'
22
+
23
+ mode = ARGV[0]
24
+
25
+ def passenger_status_path(gem_path)
26
+ File.join(gem_path, "bin", "passenger-status")
27
+ end
28
+
29
+ @label = ENV["label"]
30
+ @pid_file = ENV["pid_file"]
31
+ @ruby = ENV["ruby"] || Gem.ruby
32
+ @gem_path = ((ENV["GEM_HOME"] || '').split(/:/) + Gem.path).find do |path|
33
+ File.exist?(passenger_status_path(path))
34
+ end
35
+
36
+ def passenger_status
37
+ if @pid_file
38
+ unless File.readable?(@pid_file)
39
+ return [false, "PID file isn't readable: #{@pid_file}"]
40
+ end
41
+ pid = File.read(@pid_file).strip
42
+ else
43
+ pid = nil
44
+ end
45
+ result = `#{@ruby} #{passenger_status_path(@gem_path)} #{pid}`
46
+ [$?.success?, result]
47
+ end
48
+
49
+ def parse_result(result)
50
+ sections = {}
51
+ section = nil
52
+ result.each_line do |line|
53
+ case section
54
+ when "General information"
55
+ case line.chomp
56
+ when /\A(\S+)\s*=\s*(\d+)\z/
57
+ key = $1
58
+ value = $2.to_i
59
+ sections[section] << {:key => key, :label => key, :value => value}
60
+ when /\A(Waiting on global queue):\s*(\d+)\z/
61
+ label = $1
62
+ value = $2.to_i
63
+ sections[section] << {:key => "global_queue",
64
+ :label => label,
65
+ :value => value}
66
+ end
67
+ else
68
+ if /-+\s+(.+)\s+-+/ =~ line
69
+ section = $1
70
+ sections[section] = []
71
+ end
72
+ end
73
+ end
74
+ sections
75
+ end
76
+
77
+ def config
78
+ success, result = passenger_status
79
+ unless success
80
+ puts result
81
+ exit(false)
82
+ end
83
+
84
+ if @label
85
+ title = "Passenger: #{@label}: status"
86
+ else
87
+ title = "Passenger: status"
88
+ end
89
+ sections = parse_result(result)
90
+ puts(<<-EOC)
91
+ graph_title #{title}
92
+ graph_category passenger
93
+ graph_info Passenger status
94
+ graph_vlabel number of processes
95
+
96
+ EOC
97
+ have_stack_base = false
98
+ sections["General information"].each do |attributes|
99
+ key = attributes[:key]
100
+ next if key == "count"
101
+ puts("#{key}.label #{attributes[:label]}")
102
+ case key
103
+ when "max", "global_queue"
104
+ draw = "LINE2"
105
+ else
106
+ if have_stack_base
107
+ draw = "STACK"
108
+ else
109
+ draw = "AREA"
110
+ have_stack_base = true
111
+ end
112
+ end
113
+ puts("#{attributes[:key]}.draw #{draw}")
114
+ end
115
+ end
116
+
117
+ def report
118
+ success, result = passenger_status
119
+ exit(false) unless success
120
+
121
+ sections = parse_result(result)
122
+ sections["General information"].each do |attributes|
123
+ puts("#{attributes[:key]}.value #{attributes[:value]}")
124
+ end
125
+ end
126
+
127
+ case mode
128
+ when "auto", "autoconf", "detect"
129
+ success, result = passenger_status
130
+ if success
131
+ puts "yes"
132
+ exit(true)
133
+ else
134
+ puts "no (#{result})"
135
+ exit(false)
136
+ end
137
+ when "config"
138
+ config
139
+ else
140
+ report
141
+ end
@@ -0,0 +1,42 @@
1
+ # Copyright (C) 2010 Kouhei Sutou <kou@clear-code.com>
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
+
17
+ require 'rubygems'
18
+
19
+ require 'rack/test'
20
+ require 'webrat'
21
+ require 'json'
22
+
23
+ require 'racknga'
24
+ require 'racknga/middleware/cache'
25
+
26
+ Webrat.configure do |config|
27
+ config.mode = :rack
28
+ end
29
+
30
+ module RackngaTestUtils
31
+ include Rack::Test::Methods
32
+ include Webrat::Methods
33
+ include Webrat::Matchers
34
+
35
+ def fixtures_dir
36
+ Pathname(__FILE__).dirname + "fixtures"
37
+ end
38
+
39
+ def response
40
+ webrat_session.response
41
+ end
42
+ end
data/test/run-test.rb ADDED
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright (C) 2010 Kouhei Sutou <kou@clear-code.com>
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
+
19
+ $VERBOSE = true
20
+
21
+ $KCODE = "u" if RUBY_VERSION < "1.9"
22
+
23
+ require 'pathname'
24
+
25
+ base_dir = Pathname(__FILE__).dirname.parent.expand_path
26
+ test_unit_dir = base_dir + "test-unit"
27
+ test_unit_lib_dir = test_unit_dir + "lib"
28
+ rroonga_dir = base_dir.parent + "rroonga"
29
+ rroonga_ext_dir = rroonga_dir + "ext" + "groonga"
30
+ rroonga_lib_dir = rroonga_dir + "lib"
31
+ lib_dir = base_dir + "lib"
32
+ test_dir = base_dir + "test"
33
+
34
+ unless File.exist?(test_unit_dir)
35
+ test_unit_repository = "http://test-unit.rubyforge.org/svn/trunk/"
36
+ system("svn co #{test_unit_repository} #{test_unit_dir}") or exit(false)
37
+ end
38
+
39
+ $LOAD_PATH.unshift(test_unit_lib_dir.to_s)
40
+
41
+ require 'test/unit'
42
+
43
+ # ARGV.unshift("--priority-mode")
44
+
45
+ $LOAD_PATH.unshift(rroonga_ext_dir.to_s)
46
+ $LOAD_PATH.unshift(rroonga_lib_dir.to_s)
47
+ $LOAD_PATH.unshift(lib_dir.to_s)
48
+
49
+ $LOAD_PATH.unshift(test_dir.to_s)
50
+ require 'racknga-test-utils'
51
+
52
+ Dir.glob("#{test_dir}/**/test{_,-}*.rb") do |file|
53
+ require file.sub(/\.rb$/, '')
54
+ end
55
+
56
+ exit Test::Unit::AutoRunner.run(false)
@@ -0,0 +1,78 @@
1
+ # Copyright (C) 2010 Kouhei Sutou <kou@clear-code.com>
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
+
17
+ class MiddlewareJSONPTest < Test::Unit::TestCase
18
+ include RackngaTestUtils
19
+
20
+ def app
21
+ application = Proc.new do |environment|
22
+ @environment = environment
23
+ [200,
24
+ {"Content-Type" => "application/json"},
25
+ [@body]]
26
+ end
27
+ jsonp = Racknga::Middleware::JSONP.new(application)
28
+ Proc.new do |environment|
29
+ environment = @update_environment.call(environment) if @update_environment
30
+ jsonp.call(environment)
31
+ end
32
+ end
33
+
34
+ def setup
35
+ @cache_key_key = "racknga.cache.key"
36
+ @environment = nil
37
+ @body = "{}"
38
+ @update_environment = nil
39
+ end
40
+
41
+ def test_no_jsonp
42
+ get "/"
43
+ assert_equal(@body, webrat_session.response.body)
44
+ end
45
+
46
+ def test_jsonp
47
+ get "/?callback=jsonp_callback"
48
+ assert_equal("jsonp_callback(#{@body});",
49
+ webrat_session.response.body)
50
+ end
51
+
52
+ def test_no_jsonp_cache_key
53
+ get "/"
54
+ assert_nil(@environment[@cache_key_key])
55
+ end
56
+
57
+ def test_jsonp_cache_key
58
+ get "/?callback=jsonp_callback"
59
+ assert_equal("/",
60
+ @environment[@cache_key_key])
61
+ end
62
+
63
+ def test_jsonp_cache_key_with_parameters
64
+ get "/?query=ruby&callback=jsonp_callback&_=1279288762"
65
+ assert_equal("/?query=ruby",
66
+ @environment[@cache_key_key])
67
+ end
68
+
69
+ def test_jsonp_cache_key_exist
70
+ @update_environment = Proc.new do |environment|
71
+ environment[@cache_key_key] = "pc"
72
+ environment
73
+ end
74
+ get "/?callback=jsonp_callback"
75
+ assert_equal("pc:/",
76
+ @environment[@cache_key_key])
77
+ end
78
+ end
@@ -0,0 +1,160 @@
1
+ # Copyright (C) 2010 Kouhei Sutou <kou@clear-code.com>
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
+
17
+ module MiddlewareRangeTests
18
+ include RackngaTestUtils
19
+
20
+ def app
21
+ application = Proc.new do |environment|
22
+ @environment = environment
23
+ [200,
24
+ {
25
+ "Content-Type" => "video/ogv",
26
+ "Content-Length" => @body.bytesize.to_s,
27
+ "Last-Modified" => @ogv.mtime.httpdate,
28
+ "ETag" => @etag,
29
+ },
30
+ application_body]
31
+ end
32
+ Racknga::Middleware::Range.new(application)
33
+ end
34
+
35
+ def setup
36
+ @ogv = fixtures_dir + "rabbit-theme-change.ogv"
37
+ @ogv.open("rb") do |file|
38
+ @body = file.read.force_encoding("ASCII-8BIT")
39
+ end
40
+ stat = @ogv.stat
41
+ @etag = "%x-%x-%x" % [stat.ino, stat.size, stat.mtime.to_i * 1_000_000]
42
+ end
43
+
44
+ def test_both
45
+ get("/", {}, {"HTTP_RANGE" => "bytes=200-499"})
46
+
47
+ assert_response(206,
48
+ "300",
49
+ "bytes 200-499/#{@body.bytesize}",
50
+ @body[200, 300])
51
+ end
52
+
53
+ def test_first_byte_only
54
+ get("/", {}, {"HTTP_RANGE" => "bytes=200-"})
55
+
56
+ data_length = @body.bytesize
57
+ expected_bytes = data_length - 200
58
+ assert_response(206,
59
+ "#{expected_bytes}",
60
+ "bytes 200-#{data_length - 1}/#{data_length}",
61
+ @body[200, expected_bytes])
62
+ end
63
+
64
+ def test_last_byte_only
65
+ get("/", {}, {"HTTP_RANGE" => "bytes=-200"})
66
+
67
+ data_length = @body.bytesize
68
+ first_byte = data_length - 200
69
+ assert_response(206,
70
+ "200",
71
+ "bytes #{first_byte}-#{data_length - 1}/#{data_length}",
72
+ @body[data_length - 200, 200])
73
+ end
74
+
75
+ def test_no_position
76
+ get("/", {}, {"HTTP_RANGE" => "bytes=-"})
77
+
78
+ assert_response(416, "0", nil, "")
79
+ end
80
+
81
+ def test_if_range_date
82
+ get("/",
83
+ {},
84
+ {
85
+ "HTTP_RANGE" => "bytes=200-499",
86
+ "HTTP_IF_RANGE" => @ogv.mtime.httpdate,
87
+ })
88
+
89
+ data_length = @body.bytesize
90
+ assert_response(206, "300", "bytes 200-499/#{data_length}", @body[200, 300])
91
+ end
92
+
93
+ def test_if_range_date_expired
94
+ get("/",
95
+ {},
96
+ {
97
+ "HTTP_RANGE" => "bytes=200-499",
98
+ "HTTP_IF_RANGE" => Time.now.httpdate,
99
+ })
100
+
101
+ assert_response(200, "#{@body.bytesize}", nil, @body)
102
+ end
103
+
104
+ def test_if_range_etag
105
+ get("/",
106
+ {},
107
+ {
108
+ "HTTP_RANGE" => "bytes=200-499",
109
+ "HTTP_IF_RANGE" => @etag,
110
+ })
111
+
112
+ assert_response(206,
113
+ "300",
114
+ "bytes 200-499/#{@body.bytesize}",
115
+ @body[200, 300])
116
+ end
117
+
118
+ def test_if_range_etag_expired
119
+ get("/",
120
+ {},
121
+ {
122
+ "HTTP_RANGE" => "bytes=200-499",
123
+ "HTTP_IF_RANGE" => "not-match-etag",
124
+ })
125
+
126
+ assert_response(200, "#{@body.bytesize}", nil, @body)
127
+ end
128
+
129
+ private
130
+ def assert_response(status, content_length, content_range, body)
131
+ assert_equal({
132
+ :status => status,
133
+ :content_length => content_length,
134
+ :content_range => content_range,
135
+ :body => body,
136
+ },
137
+ {
138
+ :status => response.status,
139
+ :content_length => response.headers["Content-Length"],
140
+ :content_range => response.headers["Content-Range"],
141
+ :body => response.body,
142
+ })
143
+ end
144
+ end
145
+
146
+ class MiddlewareRangeDataTest < Test::Unit::TestCase
147
+ include MiddlewareRangeTests
148
+
149
+ def application_body
150
+ [@body]
151
+ end
152
+ end
153
+
154
+ class MiddlewareRangeFileTest < Test::Unit::TestCase
155
+ include MiddlewareRangeTests
156
+
157
+ def application_body
158
+ @ogv.open("rb")
159
+ end
160
+ end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: racknga
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 57
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 9
8
- - 0
9
- version: 0.9.0
9
+ - 1
10
+ version: 0.9.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - Kouhei Sutou
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-07-04 00:00:00 +09:00
18
+ date: 2010-11-11 00:00:00 +09:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: rroonga
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 3
27
30
  segments:
28
31
  - 0
29
32
  version: "0"
@@ -33,9 +36,11 @@ dependencies:
33
36
  name: rack
34
37
  prerelease: false
35
38
  requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
36
40
  requirements:
37
41
  - - ">="
38
42
  - !ruby/object:Gem::Version
43
+ hash: 3
39
44
  segments:
40
45
  - 0
41
46
  version: "0"
@@ -45,9 +50,11 @@ dependencies:
45
50
  name: rubyforge
46
51
  prerelease: false
47
52
  requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
48
54
  requirements:
49
55
  - - ">="
50
56
  - !ruby/object:Gem::Version
57
+ hash: 7
51
58
  segments:
52
59
  - 2
53
60
  - 0
@@ -59,14 +66,16 @@ dependencies:
59
66
  name: hoe
60
67
  prerelease: false
61
68
  requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
62
70
  requirements:
63
71
  - - ">="
64
72
  - !ruby/object:Gem::Version
73
+ hash: 19
65
74
  segments:
66
75
  - 2
67
76
  - 6
68
- - 1
69
- version: 2.6.1
77
+ - 2
78
+ version: 2.6.2
70
79
  type: :development
71
80
  version_requirements: *id004
72
81
  description: |
@@ -82,9 +91,9 @@ extensions: []
82
91
 
83
92
  extra_rdoc_files:
84
93
  - NEWS.rdoc
85
- - README.rdoc
86
- - README.ja.rdoc
87
94
  - NEWS.ja.rdoc
95
+ - README.ja.rdoc
96
+ - README.rdoc
88
97
  files:
89
98
  - AUTHORS
90
99
  - NEWS.ja.rdoc
@@ -97,17 +106,28 @@ files:
97
106
  - html/header.html.erb
98
107
  - lib/racknga/cache_database.rb
99
108
  - lib/racknga/exception_mail_notifier.rb
109
+ - lib/racknga/log_database.rb
100
110
  - lib/racknga/middleware/cache.rb
101
111
  - lib/racknga/middleware/deflater.rb
102
112
  - lib/racknga/middleware/exception_notifier.rb
113
+ - lib/racknga/middleware/jsonp.rb
114
+ - lib/racknga/middleware/log.rb
115
+ - lib/racknga/middleware/range.rb
103
116
  - lib/racknga/utils.rb
104
117
  - lib/racknga/version.rb
118
+ - lib/racknga/will_paginate.rb
105
119
  - lib/racknga.rb
106
- - license/LGPL
120
+ - munin/plugins/passenger_domain_
121
+ - munin/plugins/passenger_status
122
+ - test/fixtures/rabbit-theme-change.ogv
123
+ - test/racknga-test-utils.rb
124
+ - test/run-test.rb
125
+ - test/test-middleware-jsonp.rb
126
+ - test/test-middleware-range.rb
107
127
  has_rdoc: true
108
128
  homepage: http://groonga.rubyforge.org/
109
129
  licenses:
110
- - LGPL 2.1
130
+ - LGPL 2.1 or later
111
131
  post_install_message:
112
132
  rdoc_options:
113
133
  - --main
@@ -115,25 +135,29 @@ rdoc_options:
115
135
  require_paths:
116
136
  - lib
117
137
  required_ruby_version: !ruby/object:Gem::Requirement
138
+ none: false
118
139
  requirements:
119
140
  - - ">="
120
141
  - !ruby/object:Gem::Version
142
+ hash: 3
121
143
  segments:
122
144
  - 0
123
145
  version: "0"
124
146
  required_rubygems_version: !ruby/object:Gem::Requirement
147
+ none: false
125
148
  requirements:
126
149
  - - ">="
127
150
  - !ruby/object:Gem::Version
151
+ hash: 3
128
152
  segments:
129
153
  - 0
130
154
  version: "0"
131
155
  requirements: []
132
156
 
133
157
  rubyforge_project: groonga
134
- rubygems_version: 1.3.6
158
+ rubygems_version: 1.3.7
135
159
  signing_key:
136
160
  specification_version: 3
137
161
  summary: Rack middlewares that uses rroonga features.
138
- test_files: []
139
-
162
+ test_files:
163
+ - test/run-test.rb