modern_times 0.2.11 → 0.3.0
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.
- data/README.rdoc +114 -80
- data/VERSION +1 -1
- data/examples/advanced_requestor/README +15 -0
- data/examples/advanced_requestor/base_request_worker.rb +13 -0
- data/examples/advanced_requestor/char_count_worker.rb +11 -0
- data/examples/advanced_requestor/exception_raiser_worker.rb +10 -0
- data/examples/advanced_requestor/length_worker.rb +9 -0
- data/examples/advanced_requestor/manager.rb +22 -0
- data/examples/advanced_requestor/modern_times.yml +32 -0
- data/examples/advanced_requestor/print_worker.rb +9 -0
- data/examples/advanced_requestor/publish.rb +46 -0
- data/examples/advanced_requestor/reverse_worker.rb +9 -0
- data/examples/advanced_requestor/triple_worker.rb +9 -0
- data/examples/requestor/request.rb +3 -3
- data/examples/requestor/reverse_echo_worker.rb +1 -2
- data/lib/modern_times.rb +1 -1
- data/lib/modern_times/base/supervisor.rb +2 -0
- data/lib/modern_times/base/worker.rb +5 -3
- data/lib/modern_times/jms.rb +2 -0
- data/lib/modern_times/jms/connection.rb +7 -0
- data/lib/modern_times/jms/publish_handle.rb +219 -0
- data/lib/modern_times/jms/publisher.rb +55 -29
- data/lib/modern_times/{jms_requestor/worker.rb → jms/request_worker.rb} +29 -51
- data/lib/modern_times/jms/supervisor.rb +30 -0
- data/lib/modern_times/jms/supervisor_mbean.rb +17 -1
- data/lib/modern_times/jms/worker.rb +43 -40
- data/lib/modern_times/manager.rb +6 -2
- data/lib/modern_times/marshal_strategy.rb +14 -17
- data/lib/modern_times/marshal_strategy/bson.rb +2 -0
- data/lib/modern_times/marshal_strategy/json.rb +3 -0
- data/lib/modern_times/marshal_strategy/ruby.rb +3 -0
- data/lib/modern_times/marshal_strategy/string.rb +3 -0
- data/lib/modern_times/marshal_strategy/yaml.rb +3 -0
- data/lib/modern_times/railsable.rb +7 -14
- data/lib/modern_times/time_track.rb +84 -0
- data/test/jms.yml +1 -0
- data/test/jms_failure_test.rb +128 -0
- data/test/jms_requestor_block_test.rb +275 -0
- data/test/jms_requestor_test.rb +71 -96
- data/test/jms_test.rb +59 -78
- data/test/marshal_strategy_test.rb +1 -3
- metadata +29 -14
- data/examples/exception_test/bar_worker.rb +0 -8
- data/examples/exception_test/base_worker.rb +0 -23
- data/examples/exception_test/manager.rb +0 -11
- data/lib/modern_times/jms_requestor.rb +0 -10
- data/lib/modern_times/jms_requestor/request_handle.rb +0 -42
- data/lib/modern_times/jms_requestor/requestor.rb +0 -56
- data/lib/modern_times/jms_requestor/supervisor.rb +0 -45
- data/lib/modern_times/jms_requestor/supervisor_mbean.rb +0 -21
@@ -5,8 +5,8 @@ module ModernTimes
|
|
5
5
|
module Railsable
|
6
6
|
def init_rails
|
7
7
|
# Allow user to use JMS w/o modifying jms.yml which could be checked in and hose other users
|
8
|
-
env = ENV['MODERN_TIMES_ENV'] || Rails.env
|
9
|
-
if @config = YAML.load(ERB.new(File.read(File.join(Rails.root, "config", "jms.yml"))).result(binding))[env]
|
8
|
+
@env = ENV['MODERN_TIMES_ENV'] || Rails.env
|
9
|
+
if @config = YAML.load(ERB.new(File.read(File.join(Rails.root, "config", "jms.yml"))).result(binding))[@env]
|
10
10
|
ModernTimes.logger.info "Messaging Enabled"
|
11
11
|
ModernTimes::JMS::Connection.init(@config)
|
12
12
|
@is_jms_enabled = true
|
@@ -46,9 +46,8 @@ module ModernTimes
|
|
46
46
|
else
|
47
47
|
Rails.logger.info "Messaging disabled"
|
48
48
|
@is_jms_enabled = false
|
49
|
-
ModernTimes::JMS::Publisher.setup_dummy_publishing(rails_workers)
|
49
|
+
ModernTimes::JMS::Publisher.setup_dummy_publishing(rails_workers.map {|klass| klass.new})
|
50
50
|
ModernTimes::JMS::Consumer.setup_dummy_receiving
|
51
|
-
ModernTimes::JMSRequestor::Requestor.setup_dummy_requesting(rails_workers)
|
52
51
|
end
|
53
52
|
end
|
54
53
|
|
@@ -57,21 +56,15 @@ module ModernTimes
|
|
57
56
|
raise 'init_rails has not been called, modify your config/environment.rb to include this call' if @is_jms_enabled.nil?
|
58
57
|
raise 'Messaging is not enabled, modify your config/jms.yml file' unless @is_jms_enabled
|
59
58
|
default_config = {
|
60
|
-
:persist_file => File.join(Rails.root, "log", "modern_times.
|
59
|
+
:persist_file => File.join(Rails.root, "log", "modern_times.yml"),
|
61
60
|
:worker_file => File.join(Rails.root, "config", "workers.yml"),
|
62
|
-
:jmx =>
|
61
|
+
:jmx => @env != 'test',
|
63
62
|
:stop_on_signal => true,
|
64
|
-
:dummy_host =>
|
63
|
+
:dummy_host => @env,
|
65
64
|
:allowed_workers => rails_workers,
|
66
65
|
}
|
67
66
|
|
68
|
-
|
69
|
-
manager.stop_on_signal
|
70
|
-
manager.allowed_workers = rails_workers
|
71
|
-
manager.persist_file = manager_config[:persist_file] || File.join(Rails.root, "log", "modern_times.persist")
|
72
|
-
manager.dummy_host = Rails.env
|
73
|
-
manager.worker_file = manager_config[:worker_file] || File.join(Rails.root, "config", "workers.yml")
|
74
|
-
return manager
|
67
|
+
return ModernTimes::Manager.new(default_config.merge(manager_config))
|
75
68
|
end
|
76
69
|
|
77
70
|
def rails_workers
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'benchmark'
|
2
|
+
|
3
|
+
module ModernTimes
|
4
|
+
class TimeTrack
|
5
|
+
attr_reader :total_count, :time_count, :max_time, :last_time
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@mutex = Mutex.new
|
9
|
+
@total_count = 0
|
10
|
+
@last_time = 0.0
|
11
|
+
reset
|
12
|
+
end
|
13
|
+
|
14
|
+
def reset
|
15
|
+
@mutex.synchronize do
|
16
|
+
@time_count = 0
|
17
|
+
@min_time = nil
|
18
|
+
@max_time = 0.0
|
19
|
+
@total_time = 0.0
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def perform
|
24
|
+
answer = nil
|
25
|
+
@last_time = Benchmark.realtime { answer = yield }
|
26
|
+
@mutex.synchronize do
|
27
|
+
@total_count += 1
|
28
|
+
@time_count += 1
|
29
|
+
@total_time += @last_time
|
30
|
+
@min_time = @last_time if !@min_time || @last_time < @min_time
|
31
|
+
@max_time = @last_time if @last_time > @max_time
|
32
|
+
end
|
33
|
+
answer
|
34
|
+
end
|
35
|
+
|
36
|
+
def total_time
|
37
|
+
@mutex.synchronize do
|
38
|
+
[@time_count, @total_time]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def min_time
|
43
|
+
@min_time || 0.0
|
44
|
+
end
|
45
|
+
|
46
|
+
def avg_time
|
47
|
+
@mutex.synchronize do
|
48
|
+
return 0.0 if @time_count == 0
|
49
|
+
@total_time / @time_count
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Return the total time and reset it. Kind of hackish but allows for tools like
|
54
|
+
# Hyperic to poll these values in an xml attribute setup.
|
55
|
+
def total_time_reset
|
56
|
+
@mutex.synchronize do
|
57
|
+
retval = [@time_count, @total_time]
|
58
|
+
@time_count = 0
|
59
|
+
@total_time = 0.0
|
60
|
+
return retval
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def min_time_reset
|
65
|
+
@mutex.synchronize do
|
66
|
+
val = @min_time || 0.0
|
67
|
+
@min_time = nil
|
68
|
+
return val
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def max_time_reset
|
73
|
+
@mutex.synchronize do
|
74
|
+
val = @max_time
|
75
|
+
@max_time = 0.0
|
76
|
+
return val
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def to_s
|
81
|
+
"sample=#{@time_count} min=#{('%.1f' % (1000*min_time))}ms max=#{('%.1f' % (1000*max_time))}ms avg=#{('%.1f' % (1000*avg_time))}ms"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/test/jms.yml
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
:factory: org.apache.activemq.ActiveMQConnectionFactory
|
2
2
|
:broker_url: tcp://localhost:61616
|
3
|
+
:log_times: false
|
3
4
|
:require_jars:
|
4
5
|
- <%= Dir.glob("#{ENV['ACTIVEMQ_HOME']}/activemq-all-*.jar")[0] %>
|
5
6
|
#- <%= Dir.glob("#{ENV['ACTIVEMQ_HOME']}/lib/optional/slf4j-log4j*.jar")[0] %>
|
@@ -0,0 +1,128 @@
|
|
1
|
+
require 'modern_times'
|
2
|
+
require 'shoulda'
|
3
|
+
require 'test/unit'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'erb'
|
6
|
+
|
7
|
+
# NOTE: This test requires a running ActiveMQ server
|
8
|
+
|
9
|
+
class ExceptionWorker
|
10
|
+
include ModernTimes::JMS::Worker
|
11
|
+
|
12
|
+
def perform(obj)
|
13
|
+
puts "ExceptinoWorker received #{obj} but raising exception"
|
14
|
+
raise 'foobar'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# This will read from the queue that ExceptionWorker fails to
|
19
|
+
class ExceptionFailureWorker
|
20
|
+
include ModernTimes::JMS::Worker
|
21
|
+
|
22
|
+
def self.my_obj
|
23
|
+
@@my_obj
|
24
|
+
end
|
25
|
+
|
26
|
+
def perform(obj)
|
27
|
+
puts "ExceptinoFailureWorker received #{obj}"
|
28
|
+
@@my_obj = obj
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class JMSFailureTest < Test::Unit::TestCase
|
33
|
+
|
34
|
+
context 'jms' do
|
35
|
+
setup do
|
36
|
+
config = YAML.load(ERB.new(File.read(File.join(File.dirname(__FILE__), 'jms.yml'))).result(binding))
|
37
|
+
ModernTimes::JMS::Connection.init(config)
|
38
|
+
end
|
39
|
+
|
40
|
+
teardown do
|
41
|
+
end
|
42
|
+
|
43
|
+
context "worker with exception" do
|
44
|
+
setup do
|
45
|
+
@manager = ModernTimes::Manager.new
|
46
|
+
|
47
|
+
@manager.add(ExceptionWorker, 1)
|
48
|
+
@manager.add(ExceptionFailureWorker, 1)
|
49
|
+
|
50
|
+
sleep 1
|
51
|
+
end
|
52
|
+
|
53
|
+
teardown do
|
54
|
+
if @manager
|
55
|
+
@manager.stop
|
56
|
+
@manager.join
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
should "write failure messages to a queue of <name>Failure" do
|
61
|
+
|
62
|
+
# Publish to Exception that will throw exception which will put on ExceptionFailure queue
|
63
|
+
publisher = ModernTimes::JMS::Publisher.new(:queue_name => 'Exception', :marshal => :string)
|
64
|
+
publisher.publish('zulu')
|
65
|
+
sleep 1
|
66
|
+
assert_equal 'zulu', ExceptionFailureWorker.my_obj
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# context "dummy publishing" do
|
71
|
+
# setup do
|
72
|
+
# workers = [
|
73
|
+
# CharCountWorker.new,
|
74
|
+
# CharCountWorker.new(:name => 'CharCount2'),
|
75
|
+
# LengthWorker.new,
|
76
|
+
# LengthWorker.new(:name => 'Length2'),
|
77
|
+
# ReverseWorker.new,
|
78
|
+
# TripleWorker.new,
|
79
|
+
# HolderWorker.new,
|
80
|
+
# ]
|
81
|
+
# ModernTimes::JMS::Publisher.setup_dummy_publishing(workers)
|
82
|
+
# end
|
83
|
+
#
|
84
|
+
# teardown do
|
85
|
+
# ModernTimes::JMS::Publisher.clear_dummy_publishing
|
86
|
+
# end
|
87
|
+
#
|
88
|
+
# should "handle replies" do
|
89
|
+
#
|
90
|
+
# publisher = ModernTimes::JMS::Publisher.new(:virtual_topic_name => 'test_string', :response => true, :marshal => :string)
|
91
|
+
# cc_val = {'f' => 1, 'o' => 4, 'b' => 1}
|
92
|
+
#
|
93
|
+
# hash = make_call(publisher, 'fooboo', 2)
|
94
|
+
# assert_response(hash['CharCount'], :message, cc_val)
|
95
|
+
# assert_response(hash['CharCount2'], :message, cc_val)
|
96
|
+
# assert_response(hash['Length'], :message, 6)
|
97
|
+
# assert_response(hash['Length2'], :message, 6)
|
98
|
+
# assert_response(hash['Reverse'], :message, 'ooboof')
|
99
|
+
# assert_response(hash['Triple'], :message, 'fooboofooboofooboo')
|
100
|
+
#
|
101
|
+
# # Timeouts don't occur when dummy publishing
|
102
|
+
# CharCountWorker.sleep_time = 3
|
103
|
+
# ReverseWorker.sleep_time = 3
|
104
|
+
# hash = make_call(publisher, 'fooboo', 2)
|
105
|
+
# assert_response(hash['CharCount'], :message, cc_val)
|
106
|
+
# assert_response(hash['CharCount2'], :message, cc_val)
|
107
|
+
# assert_response(hash['Length'], :message, 6)
|
108
|
+
# assert_response(hash['Length2'], :message, 6)
|
109
|
+
# assert_response(hash['Reverse'], :message, 'ooboof')
|
110
|
+
# assert_response(hash['Triple'], :message, 'fooboofooboofooboo')
|
111
|
+
# CharCountWorker.sleep_time = nil
|
112
|
+
# ReverseWorker.sleep_time = nil
|
113
|
+
#
|
114
|
+
# CharCountWorker.do_exception = true
|
115
|
+
# TripleWorker.do_exception = true
|
116
|
+
# hash = make_call(publisher, 'fooboo', 2)
|
117
|
+
# assert_exception(hash['CharCount'], :explicit_exception)
|
118
|
+
# assert_exception(hash['CharCount2'], :default_exception)
|
119
|
+
# assert_response(hash['Length'], :message, 6)
|
120
|
+
# assert_response(hash['Length2'], :message, 6)
|
121
|
+
# assert_response(hash['Reverse'], :message, 'ooboof')
|
122
|
+
# assert_exception(hash['Triple'], :default_exception)
|
123
|
+
# CharCountWorker.do_exception = false
|
124
|
+
# TripleWorker.do_exception = false
|
125
|
+
# end
|
126
|
+
# end
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,275 @@
|
|
1
|
+
require 'modern_times'
|
2
|
+
require 'shoulda'
|
3
|
+
require 'test/unit'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'erb'
|
6
|
+
|
7
|
+
# NOTE: This test requires a running ActiveMQ server
|
8
|
+
|
9
|
+
class BaseRequestWorker
|
10
|
+
include ModernTimes::JMS::RequestWorker
|
11
|
+
|
12
|
+
def self.sleep_time=(val)
|
13
|
+
@sleep_time = val
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.sleep_time
|
17
|
+
@sleep_time
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.do_exception=(val)
|
21
|
+
@create_exception = val
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.do_exception
|
25
|
+
@create_exception
|
26
|
+
end
|
27
|
+
|
28
|
+
def request(obj)
|
29
|
+
raise Exception,'my exception' if self.class.do_exception
|
30
|
+
sleep self.class.sleep_time if self.class.sleep_time
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class CharCountWorker < BaseRequestWorker
|
35
|
+
virtual_topic 'test_string'
|
36
|
+
response :marshal => :bson, :time_to_live => 10000
|
37
|
+
|
38
|
+
def request(obj)
|
39
|
+
super
|
40
|
+
hash = Hash.new(0)
|
41
|
+
obj.each_char {|c| hash[c] += 1}
|
42
|
+
hash
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class LengthWorker < BaseRequestWorker
|
47
|
+
virtual_topic 'test_string'
|
48
|
+
response :marshal => :ruby, :time_to_live => 10000
|
49
|
+
|
50
|
+
def request(obj)
|
51
|
+
super
|
52
|
+
obj.length
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class ReverseWorker < BaseRequestWorker
|
57
|
+
virtual_topic 'test_string'
|
58
|
+
response :marshal => :string, :time_to_live => 10000
|
59
|
+
|
60
|
+
def request(obj)
|
61
|
+
super
|
62
|
+
obj.reverse
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
class TripleWorker < BaseRequestWorker
|
67
|
+
virtual_topic 'test_string'
|
68
|
+
response :marshal => :string, :time_to_live => 10000
|
69
|
+
|
70
|
+
def request(obj)
|
71
|
+
super
|
72
|
+
obj*3
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
class HolderWorker
|
77
|
+
include ModernTimes::JMS::Worker
|
78
|
+
virtual_topic 'test_string'
|
79
|
+
|
80
|
+
def self.my_obj
|
81
|
+
@@my_obj
|
82
|
+
end
|
83
|
+
|
84
|
+
def perform(obj)
|
85
|
+
@@my_obj = obj
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
class JMSRequestorBlockTest < Test::Unit::TestCase
|
90
|
+
|
91
|
+
def assert_response(hash, expected_key, expected_val)
|
92
|
+
assert_equal 1, hash.keys.size
|
93
|
+
actual_val = hash[expected_key]
|
94
|
+
assert_equal expected_val, actual_val
|
95
|
+
end
|
96
|
+
|
97
|
+
def assert_exception(hash, expected_key)
|
98
|
+
assert_equal 1, hash.keys.size
|
99
|
+
e = hash[expected_key]
|
100
|
+
|
101
|
+
assert e.kind_of?(ModernTimes::RemoteException)
|
102
|
+
end
|
103
|
+
|
104
|
+
def make_call(publisher, string, timeout)
|
105
|
+
handle = publisher.publish(string)
|
106
|
+
hash_results = {}
|
107
|
+
|
108
|
+
handle.read_response(timeout) do |response|
|
109
|
+
response.on_message 'CharCount' do |val|
|
110
|
+
hash = hash_results[response.name] ||= {}
|
111
|
+
hash[:message] = val
|
112
|
+
end
|
113
|
+
response.on_message 'CharCount2' do |val|
|
114
|
+
hash = hash_results[response.name] ||= {}
|
115
|
+
hash[:message] = val
|
116
|
+
end
|
117
|
+
response.on_message 'Length', 'Length2', 'Reverse', 'Triple' do |val|
|
118
|
+
hash = hash_results[response.name] ||= {}
|
119
|
+
hash[:message] = val
|
120
|
+
end
|
121
|
+
response.on_timeout 'Reverse' do
|
122
|
+
hash = hash_results[response.name] ||= {}
|
123
|
+
hash[:explicit_timeout] = true
|
124
|
+
end
|
125
|
+
response.on_timeout do
|
126
|
+
hash = hash_results[response.name] ||= {}
|
127
|
+
hash[:default_timeout] = true
|
128
|
+
end
|
129
|
+
response.on_remote_exception 'CharCount' do |e|
|
130
|
+
hash = hash_results[response.name] ||= {}
|
131
|
+
hash[:explicit_exception] = e
|
132
|
+
end
|
133
|
+
response.on_remote_exception do |e|
|
134
|
+
hash = hash_results[response.name] ||= {}
|
135
|
+
hash[:default_exception] = e
|
136
|
+
end
|
137
|
+
end
|
138
|
+
puts "results=#{hash_results.inspect}"
|
139
|
+
# 6 request workers
|
140
|
+
assert_equal 6, hash_results.keys.size
|
141
|
+
assert_equal string, HolderWorker.my_obj
|
142
|
+
return hash_results
|
143
|
+
end
|
144
|
+
|
145
|
+
context 'jms request with block' do
|
146
|
+
setup do
|
147
|
+
config = YAML.load(ERB.new(File.read(File.join(File.dirname(__FILE__), 'jms.yml'))).result(binding))
|
148
|
+
ModernTimes::JMS::Connection.init(config)
|
149
|
+
end
|
150
|
+
|
151
|
+
teardown do
|
152
|
+
end
|
153
|
+
|
154
|
+
context "real publishing" do
|
155
|
+
setup do
|
156
|
+
@manager = ModernTimes::Manager.new
|
157
|
+
|
158
|
+
@manager.add(CharCountWorker, 1)
|
159
|
+
@manager.add(CharCountWorker, 1, :name => 'CharCount2')
|
160
|
+
@manager.add(LengthWorker, 1)
|
161
|
+
@manager.add(LengthWorker, 1, :name => 'Length2')
|
162
|
+
@manager.add(ReverseWorker, 1)
|
163
|
+
@manager.add(TripleWorker, 1)
|
164
|
+
@manager.add(HolderWorker, 1)
|
165
|
+
|
166
|
+
sleep 1
|
167
|
+
end
|
168
|
+
|
169
|
+
teardown do
|
170
|
+
if @manager
|
171
|
+
@manager.stop
|
172
|
+
@manager.join
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
should "handle replies" do
|
177
|
+
|
178
|
+
publisher = ModernTimes::JMS::Publisher.new(:virtual_topic_name => 'test_string', :response => true, :marshal => :string)
|
179
|
+
cc_val = {'f' => 1, 'o' => 4, 'b' => 1}
|
180
|
+
|
181
|
+
hash = make_call(publisher, 'fooboo', 2)
|
182
|
+
assert_response(hash['CharCount'], :message, cc_val)
|
183
|
+
assert_response(hash['CharCount2'], :message, cc_val)
|
184
|
+
assert_response(hash['Length'], :message, 6)
|
185
|
+
assert_response(hash['Length2'], :message, 6)
|
186
|
+
assert_response(hash['Reverse'], :message, 'ooboof')
|
187
|
+
assert_response(hash['Triple'], :message, 'fooboofooboofooboo')
|
188
|
+
|
189
|
+
CharCountWorker.sleep_time = 3
|
190
|
+
ReverseWorker.sleep_time = 3
|
191
|
+
hash = make_call(publisher, 'fooboo', 2)
|
192
|
+
assert_response(hash['CharCount'], :default_timeout, true)
|
193
|
+
assert_response(hash['CharCount2'], :default_timeout, true)
|
194
|
+
assert_response(hash['Length'], :message, 6)
|
195
|
+
assert_response(hash['Length2'], :message, 6)
|
196
|
+
assert_response(hash['Reverse'], :explicit_timeout, true)
|
197
|
+
assert_response(hash['Triple'], :message, 'fooboofooboofooboo')
|
198
|
+
CharCountWorker.sleep_time = nil
|
199
|
+
ReverseWorker.sleep_time = nil
|
200
|
+
|
201
|
+
CharCountWorker.do_exception = true
|
202
|
+
TripleWorker.do_exception = true
|
203
|
+
hash = make_call(publisher, 'fooboo', 2)
|
204
|
+
assert_exception(hash['CharCount'], :explicit_exception)
|
205
|
+
assert_exception(hash['CharCount2'], :default_exception)
|
206
|
+
assert_response(hash['Length'], :message, 6)
|
207
|
+
assert_response(hash['Length2'], :message, 6)
|
208
|
+
assert_response(hash['Reverse'], :message, 'ooboof')
|
209
|
+
assert_exception(hash['Triple'], :default_exception)
|
210
|
+
CharCountWorker.do_exception = false
|
211
|
+
TripleWorker.do_exception = false
|
212
|
+
|
213
|
+
sleep 2
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
context "dummy publishing" do
|
218
|
+
setup do
|
219
|
+
workers = [
|
220
|
+
CharCountWorker.new,
|
221
|
+
CharCountWorker.new(:name => 'CharCount2'),
|
222
|
+
LengthWorker.new,
|
223
|
+
LengthWorker.new(:name => 'Length2'),
|
224
|
+
ReverseWorker.new,
|
225
|
+
TripleWorker.new,
|
226
|
+
HolderWorker.new,
|
227
|
+
]
|
228
|
+
ModernTimes::JMS::Publisher.setup_dummy_publishing(workers)
|
229
|
+
end
|
230
|
+
|
231
|
+
teardown do
|
232
|
+
ModernTimes::JMS::Publisher.clear_dummy_publishing
|
233
|
+
end
|
234
|
+
|
235
|
+
should "handle replies" do
|
236
|
+
|
237
|
+
publisher = ModernTimes::JMS::Publisher.new(:virtual_topic_name => 'test_string', :response => true, :marshal => :string)
|
238
|
+
cc_val = {'f' => 1, 'o' => 4, 'b' => 1}
|
239
|
+
|
240
|
+
hash = make_call(publisher, 'fooboo', 2)
|
241
|
+
assert_response(hash['CharCount'], :message, cc_val)
|
242
|
+
assert_response(hash['CharCount2'], :message, cc_val)
|
243
|
+
assert_response(hash['Length'], :message, 6)
|
244
|
+
assert_response(hash['Length2'], :message, 6)
|
245
|
+
assert_response(hash['Reverse'], :message, 'ooboof')
|
246
|
+
assert_response(hash['Triple'], :message, 'fooboofooboofooboo')
|
247
|
+
|
248
|
+
# Timeouts don't occur when dummy publishing
|
249
|
+
CharCountWorker.sleep_time = 3
|
250
|
+
ReverseWorker.sleep_time = 3
|
251
|
+
hash = make_call(publisher, 'fooboo', 2)
|
252
|
+
assert_response(hash['CharCount'], :message, cc_val)
|
253
|
+
assert_response(hash['CharCount2'], :message, cc_val)
|
254
|
+
assert_response(hash['Length'], :message, 6)
|
255
|
+
assert_response(hash['Length2'], :message, 6)
|
256
|
+
assert_response(hash['Reverse'], :message, 'ooboof')
|
257
|
+
assert_response(hash['Triple'], :message, 'fooboofooboofooboo')
|
258
|
+
CharCountWorker.sleep_time = nil
|
259
|
+
ReverseWorker.sleep_time = nil
|
260
|
+
|
261
|
+
CharCountWorker.do_exception = true
|
262
|
+
TripleWorker.do_exception = true
|
263
|
+
hash = make_call(publisher, 'fooboo', 2)
|
264
|
+
assert_exception(hash['CharCount'], :explicit_exception)
|
265
|
+
assert_exception(hash['CharCount2'], :default_exception)
|
266
|
+
assert_response(hash['Length'], :message, 6)
|
267
|
+
assert_response(hash['Length2'], :message, 6)
|
268
|
+
assert_response(hash['Reverse'], :message, 'ooboof')
|
269
|
+
assert_exception(hash['Triple'], :default_exception)
|
270
|
+
CharCountWorker.do_exception = false
|
271
|
+
TripleWorker.do_exception = false
|
272
|
+
end
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|