iudex-http-test 1.1.0-java

Sign up to get free protection for your applications and to get access to all the features.
data/.gemtest ADDED
File without changes
data/History.rdoc ADDED
@@ -0,0 +1,2 @@
1
+ === 1.1.0 (2011-11-13)
2
+ * Initial release with Iudex 1.1.x.
data/Manifest.txt ADDED
@@ -0,0 +1,16 @@
1
+ History.rdoc
2
+ Manifest.txt
3
+ README.rdoc
4
+ Rakefile
5
+ bin/iudex-http-test-fg
6
+ lib/iudex-http-test/base.rb
7
+ lib/iudex-http-test.rb
8
+ lib/iudex-http-test/broken_server.rb
9
+ lib/iudex-http-test/helper.rb
10
+ lib/iudex-http-test/server.rb
11
+ lib/iudex-http-test/test_app.rb
12
+ public/atom.xml
13
+ test/setup.rb
14
+ test/test_broken_server.rb
15
+ test/test_server.rb
16
+ test/test_test_app.rb
data/README.rdoc ADDED
@@ -0,0 +1,25 @@
1
+ = iudex-http-test
2
+
3
+ * http://github.com/dekellum/iudex
4
+
5
+ == Description
6
+
7
+ Iudex is a general purpose web crawler and feed processor in
8
+ ruby/java. The iudex-http-test gem contains a HTTP test server for
9
+ testing HTTP client implementations.
10
+
11
+ == License
12
+
13
+ Copyright (c) 2011 David Kellum
14
+
15
+ Licensed under the Apache License, Version 2.0 (the "License"); you
16
+ may not use this file except in compliance with the License. You
17
+ may obtain a copy of the License at:
18
+
19
+ http://www.apache.org/licenses/LICENSE-2.0
20
+
21
+ Unless required by applicable law or agreed to in writing, software
22
+ distributed under the License is distributed on an "AS IS" BASIS,
23
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
24
+ implied. See the License for the specific language governing
25
+ permissions and limitations under the License.
data/Rakefile ADDED
@@ -0,0 +1,36 @@
1
+ # -*- ruby -*-
2
+
3
+ $LOAD_PATH << './lib'
4
+ require 'iudex-http-test/base'
5
+
6
+ require 'rubygems'
7
+ gem 'rjack-tarpit', '~> 1.4'
8
+ require 'rjack-tarpit'
9
+
10
+ t = RJack::TarPit.new( 'iudex-http-test',
11
+ Iudex::HTTP::Test::VERSION,
12
+ :java_platform )
13
+
14
+ t.specify do |h|
15
+ h.developer( "David Kellum", "dek-oss@gravitext.com" )
16
+ h.extra_deps += [ [ 'fishwife', '~> 1.1.0' ],
17
+ [ 'sinatra', '~> 1.3.1' ],
18
+ [ 'markaby', '~> 0.7.1' ],
19
+ [ 'minitest', '~> 2.3' ] ]
20
+
21
+ h.testlib = :minitest
22
+ h.extra_dev_deps += [ [ 'rack-test', '~> 0.6.0' ] ]
23
+ end
24
+
25
+ task :check_history_version do
26
+ t.test_line_match( 'History.rdoc', /^==/, / #{t.version} / )
27
+ end
28
+ task :check_history_date do
29
+ t.test_line_match( 'History.rdoc', /^==/, /\([0-9\-]+\)$/ )
30
+ end
31
+
32
+ task :gem => [ :check_history_version ]
33
+ task :tag => [ :check_history_version, :check_history_date ]
34
+ task :push => [ :check_history_date ]
35
+
36
+ t.define_tasks
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env jruby
2
+ #.hashdot.vm.options += -Xmx256m
3
+ # -*- ruby -*-
4
+
5
+ #--
6
+ # Copyright (c) 2011 David Kellum
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License"); you
9
+ # may not use this file except in compliance with the License. You
10
+ # may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17
+ # implied. See the License for the specific language governing
18
+ # permissions and limitations under the License.
19
+ #++
20
+
21
+ $LOAD_PATH.unshift File.join( File.dirname(__FILE__), "..", "lib" )
22
+
23
+ module IudexBinScript
24
+
25
+ require 'rubygems'
26
+ require 'rjack-logback'
27
+ require 'optparse'
28
+
29
+ include RJack
30
+ Logback.config_console( :thread => true )
31
+
32
+ require 'iudex-http-test/server'
33
+
34
+ include Iudex
35
+
36
+ OptionParser.new do |opts|
37
+ opts.on( "-v", "--version", "Display version" ) do
38
+ puts "iudex-http-test-fg: #{ Iudex::HTTP::Test::VERSION }"
39
+ exit 1
40
+ end
41
+ opts.on( "-d", "--debug", "Enable verbose DEBUG logging" ) do
42
+ Logback.root.level = Logback::DEBUG
43
+ end
44
+ end.parse!
45
+
46
+ server = HTTP::Test::Server.new
47
+ server.start
48
+ server.join
49
+
50
+ end
@@ -0,0 +1,19 @@
1
+ #--
2
+ # Copyright (c) 2011 David Kellum
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you
5
+ # may not use this file except in compliance with the License. You
6
+ # may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13
+ # implied. See the License for the specific language governing
14
+ # permissions and limitations under the License.
15
+ #++
16
+
17
+ require 'iudex-http-test/base'
18
+ require 'iudex-http-test/test_app'
19
+ require 'iudex-http-test/server'
@@ -0,0 +1,23 @@
1
+ #--
2
+ # Copyright (c) 2011 David Kellum
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you
5
+ # may not use this file except in compliance with the License. You
6
+ # may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13
+ # implied. See the License for the specific language governing
14
+ # permissions and limitations under the License.
15
+ #++
16
+
17
+ module Iudex
18
+ module HTTP
19
+ module Test
20
+ VERSION = '1.1.0'
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,50 @@
1
+ #--
2
+ # Copyright (c) 2011 David Kellum
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you
5
+ # may not use this file except in compliance with the License. You
6
+ # may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13
+ # implied. See the License for the specific language governing
14
+ # permissions and limitations under the License.
15
+ #++
16
+
17
+ require 'iudex-http-test/base'
18
+
19
+ require 'socket'
20
+
21
+ module Iudex::HTTP::Test
22
+
23
+ class BrokenServer
24
+ attr_accessor :port
25
+
26
+ def initialize
27
+ @port = 19293
28
+ @server = nil
29
+ end
30
+
31
+ def start
32
+ @server = TCPServer.new( @port )
33
+ end
34
+
35
+ def accept
36
+ sock = @server.accept
37
+ yield sock if block_given?
38
+ end
39
+
40
+ def stop
41
+ if @server
42
+ @server.close
43
+ @server = nil
44
+ true
45
+ end
46
+ end
47
+
48
+ end
49
+
50
+ end
@@ -0,0 +1,78 @@
1
+ #--
2
+ # Copyright (c) 2011 David Kellum
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you
5
+ # may not use this file except in compliance with the License. You
6
+ # may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13
+ # implied. See the License for the specific language governing
14
+ # permissions and limitations under the License.
15
+ #++
16
+
17
+ require 'iudex-http-test/server'
18
+
19
+ require 'minitest/unit'
20
+ require 'net/http'
21
+ require 'ostruct'
22
+
23
+ module Iudex::HTTP::Test
24
+
25
+ class CustomUnit < MiniTest::Unit
26
+
27
+ def _run_suites(suites, type)
28
+ super(suites, type)
29
+ ensure
30
+ Helper.stop
31
+ end
32
+
33
+ def self.register
34
+ MiniTest::Unit.runner = CustomUnit.new
35
+ end
36
+ end
37
+
38
+ module Helper
39
+
40
+ def server
41
+ Helper.server
42
+ end
43
+
44
+ def self.server
45
+ @server ||=
46
+ begin
47
+ if running_standalone?
48
+ OpenStruct.new( :port => Server::DEFAULT_PORT )
49
+ else
50
+ server = Server.new
51
+ server.start
52
+ server
53
+ end
54
+ end
55
+ end
56
+
57
+ def self.running_standalone?
58
+ res = Net::HTTP.start( 'localhost', Server::DEFAULT_PORT ) do |http|
59
+ http.open_timeout = 0.5
60
+ http.read_timeout = 1.0
61
+ http.get( '/index' )
62
+ end
63
+ ( res.code.to_i == 200 )
64
+ rescue Timeout::Error, Errno::ECONNREFUSED
65
+ false
66
+ end
67
+
68
+ def self.stop
69
+ if @server
70
+ $stderr.puts
71
+ @server.stop
72
+ @server.join
73
+ @server = nil
74
+ end
75
+ end
76
+ end
77
+
78
+ end
@@ -0,0 +1,40 @@
1
+ #--
2
+ # Copyright (c) 2011 David Kellum
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you
5
+ # may not use this file except in compliance with the License. You
6
+ # may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13
+ # implied. See the License for the specific language governing
14
+ # permissions and limitations under the License.
15
+ #++
16
+
17
+ require 'iudex-http-test/base'
18
+ require 'iudex-http-test/test_app'
19
+
20
+ require 'fishwife'
21
+
22
+ module Iudex::HTTP::Test
23
+
24
+ class Server < Fishwife::HttpServer
25
+
26
+ DEFAULT_PORT = 19292
27
+
28
+ def initialize( opts = {} )
29
+ opts = { :port => DEFAULT_PORT,
30
+ :max_threads => 20 }.merge( opts )
31
+ super( opts )
32
+ end
33
+
34
+ def start( app = TestApp )
35
+ super
36
+ end
37
+
38
+ end
39
+
40
+ end
@@ -0,0 +1,194 @@
1
+ #--
2
+ # Copyright (c) 2011 David Kellum
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you
5
+ # may not use this file except in compliance with the License. You
6
+ # may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13
+ # implied. See the License for the specific language governing
14
+ # permissions and limitations under the License.
15
+ #++
16
+
17
+ require 'rack'
18
+
19
+ #FIXME: Otherwise rack can fail on threaded autoload (to be fixed in jruby)
20
+ require 'rack/mime'
21
+ require 'rack/head'
22
+ require 'rack/protection/frame_options'
23
+
24
+ require 'sinatra/base'
25
+ require 'markaby'
26
+ require 'cgi'
27
+ require 'thread'
28
+ require 'rjack-slf4j'
29
+
30
+ require 'iudex-http-test/base'
31
+
32
+ module Iudex::HTTP::Test
33
+
34
+ # Sets up rack.logger to write to rack.errors stream
35
+ class SLogger
36
+ include RJack
37
+ def initialize( app, level = :info )
38
+ @app = app
39
+ @logger = SLF4J[ self.class ]
40
+ @level = level
41
+
42
+ def @logger.<<( msg )
43
+ send( @level, msg )
44
+ end
45
+ end
46
+
47
+ def call(env)
48
+ env['rack.logger'] = @logger
49
+ @app.call(env)
50
+ end
51
+ end
52
+
53
+ class ConcurrentCounter
54
+ def initialize
55
+ @lock = Mutex.new
56
+ @count = 0
57
+ end
58
+
59
+ def sync( &block )
60
+ @lock.synchronize( &block )
61
+ end
62
+
63
+ def enter
64
+ sync { @count += 1 }
65
+ end
66
+
67
+ def exit
68
+ sync { @count -= 1 }
69
+ end
70
+
71
+ def count
72
+ sync { @count }
73
+ end
74
+ end
75
+
76
+ class TestApp < Sinatra::Base
77
+
78
+ PUBLIC = File.expand_path( File.join( File.dirname( __FILE__ ),
79
+ '..', '..', 'public' ) )
80
+
81
+ set :environment, :production
82
+ set :show_exceptions, false
83
+ set :raise_errors, true
84
+ set :dump_errors, false
85
+ use SLogger
86
+
87
+ @@counter = ConcurrentCounter.new
88
+
89
+ before do
90
+ # Handle (con)currency param, halting if exceeded
91
+ @con = params[:con].to_i # 0 if nil
92
+ if @con > 0 && @@counter.enter > @con
93
+ halt( 418, "Concurrency #{@con} exceeded" )
94
+ end
95
+
96
+ # Sleep now if requested
97
+ s = params[:sleep].to_f # 0.0 if nil
98
+ sleep s if s > 0.0
99
+ end
100
+
101
+ after do
102
+ @@counter.exit if @con > 0
103
+ end
104
+
105
+ get '/' do
106
+ redirect to( '/index' )
107
+ end
108
+
109
+ get '/301' do
110
+ redirect( to( '/index' ), 301 ) #"redirect body"
111
+ end
112
+
113
+ get '/redirect' do
114
+ loc = params[ :loc ]
115
+ redirect loc if loc
116
+ halt 400, "loc query parameter required"
117
+ end
118
+
119
+ get '/redirects/multi/:depth' do
120
+ depth = params[:depth].to_i
121
+ status = ( params[:code] || 302 ).to_i
122
+ if depth > 1
123
+ redirect( to( "/redirects/multi/#{depth - 1}#{common params}" ),
124
+ status )
125
+ else
126
+ "You finally made it"
127
+ end
128
+ end
129
+
130
+ get '/index' do
131
+ markaby do
132
+ html do
133
+ head { title "Test Index Page" }
134
+ body do
135
+ h1 "Iudex HTTP Test Service"
136
+ a( :href => url( '/foobar' ) ) { "foobar" }
137
+ end
138
+ end
139
+ end
140
+ end
141
+
142
+ get '/atom.xml' do
143
+ send_file( "#{PUBLIC}/atom.xml",
144
+ :type => 'application/atom+xml' )
145
+ end
146
+
147
+ get '/env' do
148
+ request.inspect
149
+ end
150
+
151
+ get '/error' do
152
+ raise "Raising this ERROR for you"
153
+ end
154
+
155
+ get '/304' do
156
+ halt 304
157
+ end
158
+
159
+ get '/concount' do
160
+ content_type 'text/plain'
161
+ @@counter.count.to_s
162
+ end
163
+
164
+ get '/echo/header/:name' do
165
+ content_type 'text/plain'
166
+ env[ 'HTTP_' + params[ :name ].gsub( /-/, '_' ).upcase ].to_s
167
+ end
168
+
169
+ class GiantGenerator
170
+ FILLER = <<-END
171
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
172
+ eiusmod tempor incididunt ut labore et dolore magna aliqua.
173
+ END
174
+
175
+ def each
176
+ loop { yield FILLER }
177
+ end
178
+ end
179
+
180
+ get '/giant' do
181
+ [ 200, { 'Content-Type' => 'text/plain' }, GiantGenerator.new ]
182
+ end
183
+
184
+ def common( params )
185
+ ps = [ :sleep, :con ].
186
+ map { |k| ( v = params[k] ) && [ k, v ] }.
187
+ compact.
188
+ map { |k,v| [ k, CGI.escape( v.to_s ) ].join( '=' ) }
189
+ '?' + ps.join( '&' ) unless ps.empty?
190
+ end
191
+
192
+ end
193
+
194
+ end