ap4r 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,35 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/ap4r/service_handler.rb")
2
+
3
+ namespace :test do
4
+
5
+ # task :asyncs do
6
+ # setup - run - teardown comes here.
7
+ # Names should be considered further.
8
+ # end
9
+
10
+ namespace :asyncs do
11
+
12
+ desc "Start Rails and AP4R servers to test:asyncs:exec"
13
+ task :arrange do |t|
14
+ ap4r_handler = Ap4r::ServiceHandler.new
15
+ ap4r_handler.start_rails_service
16
+ ap4r_handler.start_ap4r_service
17
+ end
18
+
19
+ desc "Start Rails and AP4R servers to test:asyncs:exec"
20
+ task :cleanup do |t|
21
+ ap4r_handler = Ap4r::ServiceHandler.new
22
+ ap4r_handler.stop_ap4r_service
23
+ ap4r_handler.stop_rails_service
24
+ end
25
+
26
+ Rake::TestTask.new(:run => "db:test:prepare") do |t|
27
+ t.libs << "test"
28
+ t.pattern = 'test/async/**/*_test.rb'
29
+ t.verbose = true
30
+ end
31
+ Rake::Task['test:asyncs:run'].comment = "Run the unit tests in test/async"
32
+
33
+ end
34
+
35
+ end
@@ -0,0 +1,130 @@
1
+ require File.join(File.dirname(__FILE__), "../spec_helper")
2
+
3
+ require "reliable-msg"
4
+ require "ap4r/dispatcher"
5
+
6
+ class Ap4r::Dispatchers::Base
7
+ attr_accessor :response
8
+ end
9
+
10
+ describe Ap4r::Dispatchers::Base, " message modification with no configuration" do
11
+ before(:each) do
12
+ @headers = {:target_url => "http://www.sample.org:8888/aaa/bbb" }
13
+ @body = "body"
14
+ @message = ReliableMsg::Message.new(1, @headers.clone, @body.clone)
15
+ @conf = {}
16
+ @dispatcher = Ap4r::Dispatchers::Base.new(@message, @conf)
17
+ @dispatcher.modify_message
18
+ end
19
+
20
+ it "should not change headers" do
21
+ @message.headers == @headers.should
22
+ end
23
+
24
+ it "should not change body" do
25
+ @message.object.should == @body
26
+ end
27
+
28
+ end
29
+
30
+ describe Ap4r::Dispatchers::Base, " message modification with url rewrite" do
31
+ before(:each) do
32
+ @headers = {:target_url => "http://www.sample.org:8888/aaa/bbb" }
33
+ @body = "body"
34
+ @message = ReliableMsg::Message.new(1, @headers.clone, @body.clone)
35
+ @conf = {"modify_rules" => {"url" => "proc{|url| url.port = url.port + 11}" }}
36
+ @dispatcher = Ap4r::Dispatchers::Base.new(@message, @conf)
37
+ @dispatcher.modify_message
38
+ end
39
+
40
+ it "should not change headers except :target_url" do
41
+ @message.headers[:target_url] = @headers[:target_url]
42
+ @message.headers.should == @headers
43
+ end
44
+
45
+ it "should change :target_url as ruled" do
46
+ @message.headers[:target_url].should == "http://www.sample.org:8899/aaa/bbb"
47
+ end
48
+
49
+ it "should not change body" do
50
+ @message.object.should == @body
51
+ end
52
+
53
+ end
54
+
55
+ describe Ap4r::Dispatchers::Http, " validation of response status as HTTP OK" do
56
+ before(:each) do
57
+ @dispatcher = Ap4r::Dispatchers::Http.new(@message = nil, @conf = nil)
58
+ end
59
+
60
+ it "should accept 200 status" do
61
+ @dispatcher.response = Net::HTTPOK.new(nil, 200, nil)
62
+ proc{ @dispatcher.validate_response_status(Net::HTTPOK) }.should_not raise_error
63
+ end
64
+
65
+ it "should repel 201 status" do
66
+ @dispatcher.response = Net::HTTPCreated.new(nil, 201, nil)
67
+ proc{ @dispatcher.validate_response_status(Net::HTTPOK) }.should raise_error
68
+ end
69
+
70
+ it "should repel 301 status" do
71
+ @dispatcher.response = Net::HTTPMovedPermanently.new(nil, 301, nil)
72
+ proc{ @dispatcher.validate_response_status(Net::HTTPOK) }.should raise_error
73
+ end
74
+
75
+ end
76
+
77
+ describe Ap4r::Dispatchers::Http, " validation of response status as 2xx" do
78
+ before(:each) do
79
+ @dispatcher = Ap4r::Dispatchers::Http.new(@message = nil, @conf = nil)
80
+ end
81
+
82
+ it "should accept 200 status" do
83
+ @dispatcher.response = Net::HTTPOK.new(nil, 200, nil)
84
+ proc{ @dispatcher.validate_response_status(Net::HTTPSuccess) }.should_not raise_error
85
+ end
86
+
87
+ it "should accept 201 status" do
88
+ @dispatcher.response = Net::HTTPCreated.new(nil, 201, nil)
89
+ proc{ @dispatcher.validate_response_status(Net::HTTPSuccess) }.should_not raise_error
90
+ end
91
+
92
+ it "should repel 301 status" do
93
+ @dispatcher.response = Net::HTTPMovedPermanently.new(nil, 301, nil)
94
+ proc{ @dispatcher.validate_response_status(Net::HTTPSuccess) }.should raise_error
95
+ end
96
+
97
+ end
98
+
99
+ describe Ap4r::Dispatchers::Http, " validation of response body" do
100
+ before(:each) do
101
+ @message = nil
102
+ @conf = nil
103
+ @dispatcher = Ap4r::Dispatchers::Http.new(@message, @conf)
104
+ @response = mock("response")
105
+ @dispatcher.response = @response
106
+ end
107
+
108
+ it 'should accept just text "true"' do
109
+ @response.should_receive(:body).once.and_return("true")
110
+ proc{ @dispatcher.validate_response_body(/true/) }.should_not raise_error
111
+ end
112
+
113
+ it 'should accept text including "true"' do
114
+ @response.should_receive(:body).and_return{
115
+ "first line is not important\nsome words true and more\nand also third line is useless." }
116
+ proc{ @dispatcher.validate_response_body(/true/) }.should_not raise_error
117
+ end
118
+
119
+ it 'should repel empty text' do
120
+ @response.should_receive(:body).and_return("")
121
+ proc{ @dispatcher.validate_response_body(/true/) }.should raise_error
122
+ end
123
+
124
+ it 'should repel long text without "true"' do
125
+ @response.should_receive(:body).and_return{
126
+ "first line is not important\nsome words, more and more\nand also third line is useless." }
127
+ proc{ @dispatcher.validate_response_body(/true/) }.should raise_error
128
+ end
129
+
130
+ end
@@ -0,0 +1,7 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
2
+
3
+ # TODO: stub logic to take files with no specs in coverage report 2007/05/22 by shino
4
+ %w(carrier message_store_ext multi_queue
5
+ queue_manager_ext store_and_forward).each{|f|
6
+ require "ap4r/#{f}"
7
+ }
metadata CHANGED
@@ -1,19 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.2
2
+ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: ap4r
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.3.2
7
- date: 2007-06-06 00:00:00 +09:00
6
+ version: 0.3.3
7
+ date: 2007-09-19 00:00:00 +09:00
8
8
  summary: Asynchronous Processing for Ruby.
9
9
  require_paths:
10
10
  - lib
11
11
  email: shinohara.shunichi@future.co.jp, kato.kiwamu@future.co.jp
12
- homepage: http://rubyforge.org/projects/ap4r/
12
+ homepage: http://ap4r.rubyforge.org/wiki/wiki.pl?HomePage
13
13
  rubyforge_project: ap4r
14
14
  description: Asynchronous Processing for Ruby.
15
- autorequire: ap4r.rb
16
- default_executable: ap4r_setup
15
+ autorequire:
16
+ default_executable:
17
17
  bindir: bin
18
18
  has_rdoc: true
19
19
  required_ruby_version: !ruby/object:Gem::Version::Requirement
@@ -30,43 +30,29 @@ authors:
30
30
  - Shunichi Shinohara
31
31
  - Kiwamu Kato
32
32
  files:
33
- - bin
34
- - CHANGELOG
35
- - config
36
- - doc
37
- - lib
33
+ - History.txt
38
34
  - MIT-LICENSE
39
- - rails_plugin
35
+ - Manifest.txt
36
+ - README.txt
40
37
  - Rakefile
41
- - README
42
- - script
43
- - spec
44
38
  - bin/ap4r_setup
45
39
  - config/ap4r_settings.rb
46
40
  - config/log4r.yaml
47
41
  - config/queues.cfg
48
42
  - config/queues_disk.cfg
49
43
  - config/queues_mysql.cfg
50
- - rails_plugin/ap4r
51
- - rails_plugin/ap4r/lib
52
- - rails_plugin/ap4r/lib/async_controller.rb
53
- - script/irm
54
- - script/loop.cmd
55
- - script/loop.rb
56
- - script/mongrel_ap4r
57
- - script/start
58
- - script/stop
59
- - lib/ap4r
44
+ - config/queues_pgsql.cfg
45
+ - lib/ap4r.rb
60
46
  - lib/ap4r/carrier.rb
61
47
  - lib/ap4r/dispatcher.rb
62
48
  - lib/ap4r/message_store_ext.rb
63
49
  - lib/ap4r/mongrel.rb
64
50
  - lib/ap4r/mongrel_ap4r.rb
65
51
  - lib/ap4r/multi_queue.rb
52
+ - lib/ap4r/postgresql.sql
66
53
  - lib/ap4r/queue_manager_ext.rb
67
54
  - lib/ap4r/queue_manager_ext_debug.rb
68
55
  - lib/ap4r/retention_history.rb
69
- - lib/ap4r/script
70
56
  - lib/ap4r/script/base.rb
71
57
  - lib/ap4r/script/queue_manager_control.rb
72
58
  - lib/ap4r/script/setup.rb
@@ -74,23 +60,33 @@ files:
74
60
  - lib/ap4r/start_with_log4r.rb
75
61
  - lib/ap4r/store_and_forward.rb
76
62
  - lib/ap4r/stored_message.rb
77
- - lib/ap4r/util
78
63
  - lib/ap4r/util/irm.rb
79
64
  - lib/ap4r/util/queue_client.rb
80
65
  - lib/ap4r/version.rb
81
- - lib/ap4r.rb
82
- test_files: []
83
-
66
+ - lib/ap4r/xxx_create_table_for_saf.rb
67
+ - lib/ap4r/xxx_create_table_for_saf_to_postgresql.rb
68
+ - rails_plugin/ap4r/init.rb
69
+ - rails_plugin/ap4r/lib/ap4r/queue_put_stub.rb
70
+ - rails_plugin/ap4r/lib/ap4r/service_handler.rb
71
+ - rails_plugin/ap4r/lib/ap4r_client.rb
72
+ - rails_plugin/ap4r/lib/async_helper.rb
73
+ - rails_plugin/ap4r/lib/message_builder.rb
74
+ - rails_plugin/ap4r/tasks/ap4r.rake
75
+ - script/irm
76
+ - script/mongrel_ap4r
77
+ - script/start
78
+ - script/stop
79
+ - spec/local/dispatcher_base_spec.rb
80
+ - spec/spec_helper.rb
81
+ test_files:
82
+ - spec/local/dispatcher_base_spec.rb
84
83
  rdoc_options:
85
84
  - --main
86
- - README
87
- - --title
88
- - Asynchronous Processing for Ruby
89
- - --line-numbers
85
+ - README.txt
90
86
  extra_rdoc_files:
91
- - README
92
- - CHANGELOG
93
- - rails_plugin
87
+ - History.txt
88
+ - Manifest.txt
89
+ - README.txt
94
90
  executables:
95
91
  - ap4r_setup
96
92
  extensions: []
@@ -108,7 +104,7 @@ dependencies:
108
104
  version: 1.1.0
109
105
  version:
110
106
  - !ruby/object:Gem::Dependency
111
- name: rake
107
+ name: activesupport
112
108
  version_requirement:
113
109
  version_requirements: !ruby/object:Gem::Version::Requirement
114
110
  requirements:
@@ -117,7 +113,7 @@ dependencies:
117
113
  version: 0.0.0
118
114
  version:
119
115
  - !ruby/object:Gem::Dependency
120
- name: activesupport
116
+ name: mongrel
121
117
  version_requirement:
122
118
  version_requirements: !ruby/object:Gem::Version::Requirement
123
119
  requirements:
@@ -126,7 +122,7 @@ dependencies:
126
122
  version: 0.0.0
127
123
  version:
128
124
  - !ruby/object:Gem::Dependency
129
- name: mongrel
125
+ name: rake
130
126
  version_requirement:
131
127
  version_requirements: !ruby/object:Gem::Version::Requirement
132
128
  requirements:
data/README DELETED
@@ -1,55 +0,0 @@
1
- == What is AP4R?
2
-
3
- AP4R, Asynchronous Processing for Ruby, is the implementation of reliable asynchronous message processing. It provides message queuing, and message dispatching.
4
- Using asynchronous processing, we can cut down turn-around-time of web applications by queuing, or can utilize more machine power by load-balancing.
5
- Also AP4R nicely ties with your Ruby on Rails applications. See Hello World sample application from rubyforge.
6
-
7
- For more information, please step in AP4R homepage!
8
-
9
- http://ap4r.rubyforge.org/wiki/wiki.pl
10
-
11
- == Features
12
-
13
- 1. Business logics can be implemented as simple Web applications, or ruby code, whether it's called asynchronously or synchronously.
14
- 1. Asynchronous messaging is reliable by RDBMS persistence (now MySQL only) or file persistence, under the favor of reliable-msg.
15
- 1. Load balancing over multiple AP4R processes on single/multiple servers is supported.
16
- 1. Asynchronous logics are called via various protocols, such as XML-RPC, SOAP, HTTP PUT, and more.
17
- 1. Using store and forward function, at-least-omce QoS level is provided.
18
-
19
- == Typical process flow
20
-
21
- 1. A client(e.g. a web browser) makes a request to a web server (Apache, Lighttpd, etc...).
22
- 1. A rails application (a synchronous logic) is executed on mongrel via mod_proxy or something.
23
- 1. At the last of the synchronous logic, message(s) are put to AP4R (AP4R provides a helper).
24
- 1. Once the synchronous logic is done, the clients receives a response immediately.
25
- 1. AP4R queues the message, and requests it to the web server asynchronously.
26
- 1. An asynchronous logic, implemented as usual rails action, is executed.
27
-
28
-
29
- == Installation
30
-
31
- Use RubyGems command.
32
-
33
- $ sudo gem install ap4r --include-dependencies
34
-
35
- == References
36
-
37
- * Ruby Homepage
38
- * http://www.ruby-lang.org/
39
- * Ruby on Rails tutorial
40
- * http://www.onlamp.com/pub/a/onlamp/2005/01/20/rails.html
41
- * MySQL tutorial
42
- * http://dev.mysql.com/doc/refman/5.0/en/index.html
43
- * reliable-msg
44
- * http://trac.labnotes.org/cgi-bin/trac.cgi/wiki/Ruby/ReliableMessaging
45
-
46
- == Licence
47
-
48
- This licence is licensed under the MIT license.
49
- Copyright(c) 2007 Future Architect Inc.
50
-
51
- == Authors
52
-
53
- * Kiwamu Kato
54
- * Shunichi Shinohara
55
-
data/script/loop.cmd DELETED
@@ -1,3 +0,0 @@
1
- @ECHO OFF
2
-
3
- ruby %~dp0loop.rb manager start -c queues%1.cfg
data/script/loop.rb DELETED
@@ -1,8 +0,0 @@
1
- load_path = "-Ilib/"
2
-
3
- loop{
4
- puts; puts '=== queue manager starting ==='
5
- system "ruby #{load_path} script/queues.rb #{ARGV.join(' ')}"
6
- puts; puts '=== queue manager stopped ==='
7
- }
8
-