gz_activemessaging 0.13.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.travis.yml +40 -0
- data/Appraisals +19 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +87 -0
- data/README.md +27 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/activemessaging.gemspec +137 -0
- data/gemfiles/activesupport23.gemfile +10 -0
- data/gemfiles/activesupport23.gemfile.lock +51 -0
- data/gemfiles/activesupport30.gemfile +11 -0
- data/gemfiles/activesupport30.gemfile.lock +53 -0
- data/gemfiles/activesupport31.gemfile +11 -0
- data/gemfiles/activesupport31.gemfile.lock +55 -0
- data/gemfiles/activesupport32.gemfile +10 -0
- data/gemfiles/activesupport32.gemfile.lock +55 -0
- data/generators/a13g_test_harness/a13g_test_harness_generator.rb +19 -0
- data/generators/a13g_test_harness/templates/active_messaging_test.rhtml +13 -0
- data/generators/a13g_test_harness/templates/active_messaging_test_controller.rb +29 -0
- data/generators/a13g_test_harness/templates/index.rhtml +17 -0
- data/generators/filter/USAGE +0 -0
- data/generators/filter/filter_generator.rb +19 -0
- data/generators/filter/templates/filter.rb +12 -0
- data/generators/filter/templates/filter_test.rb +28 -0
- data/generators/processor/USAGE +8 -0
- data/generators/processor/processor_generator.rb +31 -0
- data/generators/processor/templates/application_processor.rb +18 -0
- data/generators/processor/templates/broker.yml +140 -0
- data/generators/processor/templates/jruby_poller +117 -0
- data/generators/processor/templates/messaging.rb +12 -0
- data/generators/processor/templates/poller +25 -0
- data/generators/processor/templates/poller.rb +26 -0
- data/generators/processor/templates/processor.rb +8 -0
- data/generators/processor/templates/processor_test.rb +20 -0
- data/generators/tracer/USAGE +8 -0
- data/generators/tracer/templates/controller.rb +14 -0
- data/generators/tracer/templates/helper.rb +2 -0
- data/generators/tracer/templates/index.rhtml +4 -0
- data/generators/tracer/templates/layout.rhtml +16 -0
- data/generators/tracer/templates/trace_processor.rb +100 -0
- data/generators/tracer/tracer_generator.rb +25 -0
- data/init.rb +1 -0
- data/lib/activemessaging.rb +133 -0
- data/lib/activemessaging/adapter.rb +20 -0
- data/lib/activemessaging/adapters/amqp.rb +215 -0
- data/lib/activemessaging/adapters/asqs.rb +487 -0
- data/lib/activemessaging/adapters/base.rb +71 -0
- data/lib/activemessaging/adapters/beanstalk.rb +88 -0
- data/lib/activemessaging/adapters/jms.rb +243 -0
- data/lib/activemessaging/adapters/reliable_msg.rb +186 -0
- data/lib/activemessaging/adapters/stomp.rb +212 -0
- data/lib/activemessaging/adapters/synch.rb +95 -0
- data/lib/activemessaging/adapters/test.rb +137 -0
- data/lib/activemessaging/adapters/wmq.rb +193 -0
- data/lib/activemessaging/base_message.rb +28 -0
- data/lib/activemessaging/filter.rb +29 -0
- data/lib/activemessaging/gateway.rb +429 -0
- data/lib/activemessaging/message_sender.rb +30 -0
- data/lib/activemessaging/named_base.rb +54 -0
- data/lib/activemessaging/processor.rb +44 -0
- data/lib/activemessaging/railtie.rb +26 -0
- data/lib/activemessaging/test_helper.rb +189 -0
- data/lib/activemessaging/threaded_poller.rb +234 -0
- data/lib/activemessaging/trace_filter.rb +34 -0
- data/lib/generators/active_messaging/install/USAGE +21 -0
- data/lib/generators/active_messaging/install/install_generator.rb +39 -0
- data/lib/generators/active_messaging/install/templates/application_processor.rb +18 -0
- data/lib/generators/active_messaging/install/templates/broker.yml +139 -0
- data/lib/generators/active_messaging/install/templates/poller +24 -0
- data/lib/generators/active_messaging/install/templates/poller.rb +22 -0
- data/lib/generators/active_messaging/install/templates/threaded_poller +46 -0
- data/lib/generators/active_messaging/processor/USAGE +2 -0
- data/lib/generators/active_messaging/processor/processor_generator.rb +39 -0
- data/lib/generators/active_messaging/processor/templates/messaging.rb +12 -0
- data/lib/generators/active_messaging/processor/templates/processor.rb +8 -0
- data/lib/generators/active_messaging/processor/templates/processor_spec.rb +24 -0
- data/lib/generators/active_messaging/processor/templates/processor_test.rb +20 -0
- data/lib/tasks/start_consumers.rake +8 -0
- data/poller.rb +14 -0
- data/test/all_tests.rb +10 -0
- data/test/app/config/broker.yml +4 -0
- data/test/asqs_test.rb +125 -0
- data/test/config_test.rb +42 -0
- data/test/filter_test.rb +131 -0
- data/test/gateway_test.rb +220 -0
- data/test/jms_test.rb +64 -0
- data/test/reliable_msg_test.rb +83 -0
- data/test/stomp_test.rb +168 -0
- data/test/test_helper.rb +36 -0
- data/test/tracer_test.rb +57 -0
- metadata +202 -0
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
require 'activemessaging/test_helper'
|
3
|
+
require File.dirname(__FILE__) + '/../../app/processors/application_processor'
|
4
|
+
|
5
|
+
class <%= class_name %>ProcessorTest < Test::Unit::TestCase
|
6
|
+
include ActiveMessaging::TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
load File.dirname(__FILE__) + "/../../app/processors/<%= file_name %>_processor.rb"
|
10
|
+
@processor = <%= class_name %>Processor.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown
|
14
|
+
@processor = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_<%= file_name %>_processor
|
18
|
+
@processor.on_message('Your test message here!')
|
19
|
+
end
|
20
|
+
end
|
data/poller.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Make sure stdout and stderr write out without delay for using with daemon like scripts
|
3
|
+
STDOUT.sync = true; STDOUT.flush
|
4
|
+
STDERR.sync = true; STDERR.flush
|
5
|
+
|
6
|
+
# Load Rails
|
7
|
+
RAILS_ROOT=File.expand_path(File.join(File.dirname(__FILE__), '..','..','..'))
|
8
|
+
load File.join(RAILS_ROOT, 'config', 'environment.rb')
|
9
|
+
|
10
|
+
# Load ActiveMessaging processors
|
11
|
+
#ActiveMessaging::load_processors
|
12
|
+
|
13
|
+
# Start it up!
|
14
|
+
ActiveMessaging::start
|
data/test/all_tests.rb
ADDED
data/test/asqs_test.rb
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
require 'activemessaging/adapters/asqs'
|
3
|
+
|
4
|
+
class AsqsTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
class FakeHTTPResponse
|
7
|
+
attr_accessor :headers, :body
|
8
|
+
|
9
|
+
def to_hash
|
10
|
+
@headers
|
11
|
+
end
|
12
|
+
|
13
|
+
def kind_of? kind
|
14
|
+
true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
::ActiveMessaging::Adapters::AmazonSqs::Connection.class_eval do
|
19
|
+
attr_accessor :test_response, :test_headers
|
20
|
+
|
21
|
+
DEFAULT_RESPONSE = <<EOM
|
22
|
+
<ListQueuesResponse xmlns='http://queue.amazonaws.com/doc/2007-05-01/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:type='ListQueuesResponse'>
|
23
|
+
<Queues>
|
24
|
+
<QueueUrl>http://queue.amazonaws.com/thisisatestid1/test1</QueueUrl>
|
25
|
+
<QueueUrl>http://queue.amazonaws.com/thisisatestid12/test2</QueueUrl>
|
26
|
+
</Queues>
|
27
|
+
<ResponseStatus><StatusCode>Success</StatusCode><RequestId>cb919c0a-9bce-4afe-9b48-9bdf2412bb67</RequestId></ResponseStatus>
|
28
|
+
</ListQueuesResponse>
|
29
|
+
EOM
|
30
|
+
|
31
|
+
def http_request h, p, r
|
32
|
+
raise test_response if test_response.is_a?(Exception)
|
33
|
+
|
34
|
+
resp = FakeHTTPResponse.new
|
35
|
+
resp.body = @test_response || DEFAULT_RESPONSE
|
36
|
+
resp.headers = @test_headers || {}
|
37
|
+
return resp
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
def setup
|
43
|
+
@connection = ActiveMessaging::Adapters::AmazonSqs::Connection.new(:reliable=>false, :access_key_id=>'access_key_id', :secret_access_key=>'secret_access_key', :reconnectDelay=>1)
|
44
|
+
@d = "asqs"
|
45
|
+
@message = "mary had a little lamb"
|
46
|
+
end
|
47
|
+
|
48
|
+
def teardown
|
49
|
+
@connection.disconnect unless @connection.nil?
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_message_size
|
53
|
+
assert_equal @connection.max_message_size, 8
|
54
|
+
|
55
|
+
@connection = ActiveMessaging::Adapters::AmazonSqs::Connection.new(:reliable=>false, :access_key_id=>'access_key_id', :secret_access_key=>'secret_access_key', :max_message_size => 10)
|
56
|
+
|
57
|
+
assert_nothing_raised do
|
58
|
+
@connection.send @d, @message
|
59
|
+
end
|
60
|
+
|
61
|
+
large_message = "m" * 1024 * 9
|
62
|
+
assert_nothing_raised do
|
63
|
+
@connection.send @d, large_message
|
64
|
+
end
|
65
|
+
large_message = nil
|
66
|
+
|
67
|
+
large_message = "m" * 1024 * 11
|
68
|
+
assert_raise(RuntimeError) do
|
69
|
+
@connection.send @d, large_message
|
70
|
+
end
|
71
|
+
large_message = nil
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_allow_underscore_and_dash
|
76
|
+
assert_nothing_raised do
|
77
|
+
@connection.subscribe 'name-name_dash'
|
78
|
+
end
|
79
|
+
assert_raise(RuntimeError) do
|
80
|
+
@connection.subscribe '!@#$%^&'
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
def test_send_and_receive
|
86
|
+
@connection.subscribe @d, :visibility_timeout=>100
|
87
|
+
@connection.send @d, @message
|
88
|
+
|
89
|
+
@connection.test_headers = {:destination=>@d}
|
90
|
+
@connection.test_response = <<EOM
|
91
|
+
<ReceiveMessageResponse>
|
92
|
+
<Message>
|
93
|
+
<MessageId>11YEJMCHE2DM483NGN40|3H4AA8J7EJKM0DQZR7E1|PT6DRTB278S4MNY77NJ0</MessageId>
|
94
|
+
<ReceiptHandle>some handle value</ReceiptHandle>
|
95
|
+
<Body>#{@message}</Body>
|
96
|
+
<MD5OfBody>not really the md5</MD5OfBody>
|
97
|
+
</Message>
|
98
|
+
<ResponseStatus>
|
99
|
+
<StatusCode>Success</StatusCode>
|
100
|
+
<RequestId>b5bf2332-e983-4d3e-941a-f64c0d21f00f</RequestId>
|
101
|
+
</ResponseStatus>
|
102
|
+
</ReceiveMessageResponse>
|
103
|
+
EOM
|
104
|
+
|
105
|
+
message = @connection.receive
|
106
|
+
assert_equal @message, message.body
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_receive_timeout
|
110
|
+
@connection.subscribe @d
|
111
|
+
@connection.send @d, @message
|
112
|
+
|
113
|
+
@connection.test_headers = {:destination=>@d}
|
114
|
+
@connection.test_response = TimeoutError.new('test timeout error')
|
115
|
+
@connection.reliable = true
|
116
|
+
begin
|
117
|
+
Timeout.timeout 2 do
|
118
|
+
@connection.receive
|
119
|
+
end
|
120
|
+
rescue Timeout::Error=>toe
|
121
|
+
assert_not_equal toe.message, 'test timeout error'
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
data/test/config_test.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class TestProcessor < ActiveMessaging::Processor
|
4
|
+
end
|
5
|
+
|
6
|
+
class ConfigTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def setup
|
9
|
+
ActiveMessaging::Gateway.define do |s|
|
10
|
+
s.destination :hello_world, '/queue/helloWorld'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def teardown
|
15
|
+
ActiveMessaging::Gateway.reset
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_can_subscribe_to_named_queue
|
19
|
+
TestProcessor.subscribes_to :hello_world
|
20
|
+
sub = ActiveMessaging::Gateway.subscriptions.values.last
|
21
|
+
assert_equal :hello_world, sub.destination.name
|
22
|
+
assert_equal TestProcessor, sub.processor_class
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_can_publish_to_named_queue
|
26
|
+
TestProcessor.publishes_to :hello_world
|
27
|
+
#no exception - publish just checks to see if the queue exists
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_should_raise_error_if_subscribe_to_queue_that_does_not_exist
|
31
|
+
assert_raises(RuntimeError) do
|
32
|
+
TestProcessor.subscribes_to :queue_that_does_not_exist
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_should_raise_error_if_publishes_to_queue_that_does_not_exist
|
37
|
+
assert_raises(RuntimeError) do
|
38
|
+
TestProcessor.publishes_to :queue_that_does_not_exist
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
data/test/filter_test.rb
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
require 'activemessaging/filter'
|
3
|
+
|
4
|
+
module ActiveMessaging #:nodoc:
|
5
|
+
def self.reload_activemessaging
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class FilterTest < Test::Unit::TestCase
|
10
|
+
|
11
|
+
class MockFilter < ActiveMessaging::Filter
|
12
|
+
|
13
|
+
@@called = {}
|
14
|
+
cattr_reader :called
|
15
|
+
|
16
|
+
attr_reader :options
|
17
|
+
|
18
|
+
def initialize(options)
|
19
|
+
@options = options
|
20
|
+
end
|
21
|
+
|
22
|
+
def process(message, details={})
|
23
|
+
@@called[options[:name]] = {:message=>message, :details=>details}
|
24
|
+
end
|
25
|
+
|
26
|
+
class << self
|
27
|
+
include Test::Unit::Assertions
|
28
|
+
|
29
|
+
def reset
|
30
|
+
@@called = {}
|
31
|
+
end
|
32
|
+
|
33
|
+
def assert_was_called(name=nil)
|
34
|
+
assert @@called.has_key?(name)
|
35
|
+
end
|
36
|
+
|
37
|
+
def assert_was_not_called(name=nil)
|
38
|
+
assert !@@called.has_key?(name)
|
39
|
+
end
|
40
|
+
|
41
|
+
def assert_routing(name, routing)
|
42
|
+
assert_equal routing, @@called[name][:details]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class TestProcessor < ActiveMessaging::Processor
|
48
|
+
include ActiveMessaging::MessageSender
|
49
|
+
#subscribes_to :testqueue
|
50
|
+
|
51
|
+
@@was_called = false
|
52
|
+
class<<self
|
53
|
+
include Test::Unit::Assertions
|
54
|
+
|
55
|
+
def assert_was_called
|
56
|
+
assert @@was_called
|
57
|
+
@@was_called = false
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def on_message(message)
|
62
|
+
@@was_called = true
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
include ActiveMessaging::TestHelper
|
67
|
+
|
68
|
+
def setup
|
69
|
+
ActiveMessaging::Gateway.define do |d|
|
70
|
+
d.destination :testqueue, '/queue/test.queue'
|
71
|
+
d.filter 'filter_test/mock_filter', :direction=>:bidirectional, :name=>:bidirectional
|
72
|
+
d.filter 'filter_test/mock_filter', :direction=>:incoming, :name=>:incoming
|
73
|
+
d.filter 'filter_test/mock_filter', :direction=>:outgoing, :name=>:outgoing
|
74
|
+
|
75
|
+
d.filter 'filter_test/mock_filter', :direction=>:incoming, :name=>:exclude_only, :only=>:foo
|
76
|
+
d.filter 'filter_test/mock_filter', :direction=>:incoming, :name=>:include_only, :only=>:testqueue
|
77
|
+
d.filter 'filter_test/mock_filter', :direction=>:incoming, :name=>:exclude_except, :except=>:testqueue
|
78
|
+
d.filter 'filter_test/mock_filter', :direction=>:incoming, :name=>:include_except, :except=>:foo
|
79
|
+
end
|
80
|
+
|
81
|
+
TestProcessor.subscribes_to :testqueue
|
82
|
+
MockFilter.reset
|
83
|
+
end
|
84
|
+
|
85
|
+
def teardown
|
86
|
+
ActiveMessaging::Gateway.reset
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_filters_use_include
|
90
|
+
ActiveMessaging::Gateway.dispatch ActiveMessaging::TestMessage.new('body', {}, '/queue/test.queue')
|
91
|
+
MockFilter.assert_was_called(:include_only)
|
92
|
+
MockFilter.assert_was_not_called(:exclude_only)
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_filters_use_exclude
|
96
|
+
ActiveMessaging::Gateway.dispatch ActiveMessaging::TestMessage.new('body', {}, '/queue/test.queue')
|
97
|
+
MockFilter.assert_was_called(:include_except)
|
98
|
+
MockFilter.assert_was_not_called(:exclude_except)
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_filters_and_processor_gets_called_on_receive
|
102
|
+
ActiveMessaging::Gateway.dispatch ActiveMessaging::TestMessage.new('body', {}, '/queue/test.queue')
|
103
|
+
MockFilter.assert_was_called(:bidirectional)
|
104
|
+
MockFilter.assert_was_called(:incoming)
|
105
|
+
MockFilter.assert_was_not_called(:outgoing)
|
106
|
+
TestProcessor.assert_was_called
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_filters_gets_called_on_publish
|
110
|
+
ActiveMessaging::Gateway.publish :testqueue, "blah blah"
|
111
|
+
MockFilter.assert_was_called(:bidirectional)
|
112
|
+
MockFilter.assert_was_not_called(:incoming)
|
113
|
+
MockFilter.assert_was_called(:outgoing)
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_sets_routing_details_on_send
|
117
|
+
sender = TestProcessor.new
|
118
|
+
sender.publish :testqueue, "Hi there!"
|
119
|
+
|
120
|
+
MockFilter.assert_was_called(:outgoing)
|
121
|
+
MockFilter.assert_routing(:outgoing, {:destination=>ActiveMessaging::Gateway.find_queue(:testqueue), :publisher=>FilterTest::TestProcessor, :direction=>:outgoing})
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_sets_routing_details_on_receive
|
125
|
+
ActiveMessaging::Gateway.dispatch ActiveMessaging::TestMessage.new('body', {}, '/queue/test.queue')
|
126
|
+
|
127
|
+
MockFilter.assert_was_called(:incoming)
|
128
|
+
MockFilter.assert_routing(:incoming, {:destination=>ActiveMessaging::Gateway.find_queue(:testqueue), :receiver=>FilterTest::TestProcessor, :direction=>:incoming})
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
@@ -0,0 +1,220 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class InitializeFilter
|
4
|
+
|
5
|
+
attr_accessor :options
|
6
|
+
|
7
|
+
def initialize(options)
|
8
|
+
@options = options
|
9
|
+
end
|
10
|
+
|
11
|
+
def process(message, details={})
|
12
|
+
puts "ObjectFilter process called!"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class GatewayTest < Test::Unit::TestCase
|
17
|
+
class ClassFilter
|
18
|
+
def initialize
|
19
|
+
raise "Don't try and construct one of these please"
|
20
|
+
end
|
21
|
+
|
22
|
+
class << self
|
23
|
+
def process(message, details={})
|
24
|
+
puts "ClassFilter process called!"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class ObjectFilter
|
30
|
+
def process(message, details={})
|
31
|
+
puts "ObjectFilter process called!"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class MessageManglingFilter
|
36
|
+
class << self
|
37
|
+
def process(message, details={})
|
38
|
+
message.body.upcase!
|
39
|
+
message.id.upcase!
|
40
|
+
message.headers['the-mangler'] = 'run'
|
41
|
+
message.destination.gsub! '/', '#'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class TestProcessor < ActiveMessaging::Processor
|
47
|
+
include ActiveMessaging::MessageSender
|
48
|
+
#subscribes_to :testqueue
|
49
|
+
def on_message(message)
|
50
|
+
@test_message = true
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class TestRetryProcessor < ActiveMessaging::Processor
|
55
|
+
include ActiveMessaging::MessageSender
|
56
|
+
#subscribes_to :testqueue
|
57
|
+
def on_message(message)
|
58
|
+
#puts "TestRetryProcessor - about to raise exception"
|
59
|
+
raise ActiveMessaging::AbortMessageException.new("Cause a retry!")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
class TestAdapter
|
64
|
+
end
|
65
|
+
|
66
|
+
def setup
|
67
|
+
end
|
68
|
+
|
69
|
+
def teardown
|
70
|
+
ActiveMessaging::Gateway.reset
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
def test_create_filter
|
75
|
+
filter_obj = ActiveMessaging::Gateway.create_filter('gateway_test/object_filter', {:direction=>:incoming, :name=>'test1'})
|
76
|
+
assert filter_obj
|
77
|
+
assert filter_obj.is_a?(GatewayTest::ObjectFilter)
|
78
|
+
|
79
|
+
filter_obj = ActiveMessaging::Gateway.create_filter('initialize_filter', {:direction=>:incoming, :name=>'test2'})
|
80
|
+
assert filter_obj
|
81
|
+
assert filter_obj.is_a?(InitializeFilter)
|
82
|
+
assert_equal filter_obj.options, {:direction=>:incoming, :name=>'test2'}
|
83
|
+
|
84
|
+
filter_obj = ActiveMessaging::Gateway.create_filter(:initialize_filter, {:direction=>:incoming, :name=>'test2'})
|
85
|
+
assert filter_obj
|
86
|
+
assert filter_obj.is_a?(InitializeFilter)
|
87
|
+
assert_equal filter_obj.options, {:direction=>:incoming, :name=>'test2'}
|
88
|
+
|
89
|
+
filter_obj = ActiveMessaging::Gateway.create_filter(:'gateway_test/class_filter', {:direction=>:incoming, :name=>'test2'})
|
90
|
+
assert filter_obj
|
91
|
+
assert filter_obj.is_a?(Class)
|
92
|
+
assert_equal filter_obj.name, "GatewayTest::ClassFilter"
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_register_adapter
|
96
|
+
ActiveMessaging::Gateway.register_adapter :test_register_adapter, TestAdapter
|
97
|
+
assert_equal TestAdapter, ActiveMessaging::Gateway.adapters[:test_register_adapter]
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_destination
|
101
|
+
ActiveMessaging::Gateway.destination :hello_world, '/queue/helloWorld'
|
102
|
+
dest = ActiveMessaging::Gateway.named_destinations[:hello_world]
|
103
|
+
assert_equal :hello_world, dest.name
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_destination_duplicates
|
107
|
+
ActiveMessaging::Gateway.destination :hello_world, '/queue/helloWorld'
|
108
|
+
dest = ActiveMessaging::Gateway.named_destinations[:hello_world]
|
109
|
+
assert_equal :hello_world, dest.name
|
110
|
+
|
111
|
+
# make sure a dupe name causes an error
|
112
|
+
assert_raises RuntimeError do
|
113
|
+
ActiveMessaging::Gateway.destination :hello_world, '/queue/helloWorld2'
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_connection
|
118
|
+
conn = ActiveMessaging::Gateway.connection
|
119
|
+
assert_equal conn.class, ActiveMessaging::Adapters::Test::Connection
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_subscribe_and_unsubscribe
|
123
|
+
ActiveMessaging::Gateway.destination :hello_world, '/queue/helloWorld'
|
124
|
+
ActiveMessaging::Gateway.subscribe_to :hello_world, TestProcessor, headers={}
|
125
|
+
sub = ActiveMessaging::Gateway.subscriptions.values.last
|
126
|
+
assert_equal :hello_world, sub.destination.name
|
127
|
+
assert_equal TestProcessor, sub.processor_class
|
128
|
+
|
129
|
+
ActiveMessaging::Gateway.subscribe
|
130
|
+
assert_not_nil ActiveMessaging::Gateway.connection.find_subscription(sub.destination.value)
|
131
|
+
|
132
|
+
ActiveMessaging::Gateway.unsubscribe
|
133
|
+
assert_nil ActiveMessaging::Gateway.connection.find_subscription(sub.destination.value)
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_disconnect
|
137
|
+
assert_equal 0, ActiveMessaging::Gateway.connections.keys.size
|
138
|
+
|
139
|
+
conn = ActiveMessaging::Gateway.connection
|
140
|
+
assert_equal 1, ActiveMessaging::Gateway.connections.keys.size
|
141
|
+
assert_equal true, conn.connected
|
142
|
+
|
143
|
+
ActiveMessaging::Gateway.disconnect
|
144
|
+
|
145
|
+
assert_equal 0, ActiveMessaging::Gateway.connections.keys.size
|
146
|
+
assert_equal false, conn.connected
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_publish
|
150
|
+
ActiveMessaging::Gateway.destination :hello_world, '/queue/helloWorld'
|
151
|
+
ActiveMessaging::Gateway.publish :hello_world, "test_publish body", self.class, headers={}, timeout=10
|
152
|
+
assert_not_nil ActiveMessaging::Gateway.connection.find_message('/queue/helloWorld', "test_publish body")
|
153
|
+
|
154
|
+
assert_raise(RuntimeError) do
|
155
|
+
ActiveMessaging::Gateway.publish :hello_world, nil, self.class, headers={}, timeout=10
|
156
|
+
end
|
157
|
+
assert_raise(RuntimeError) do
|
158
|
+
ActiveMessaging::Gateway.publish :hello_world, '', self.class, headers={}, timeout=10
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_acknowledge_message
|
163
|
+
ActiveMessaging::Gateway.destination :hello_world, '/queue/helloWorld'
|
164
|
+
ActiveMessaging::Gateway.subscribe_to :hello_world, TestProcessor, headers={}
|
165
|
+
sub = ActiveMessaging::Gateway.subscriptions.values.last
|
166
|
+
dest = ActiveMessaging::Adapters::Test::Destination.new '/queue/helloWorld'
|
167
|
+
msg = ActiveMessaging::Adapters::Test::Message.new("message_body", nil, {}, dest.name)
|
168
|
+
ActiveMessaging::Gateway.acknowledge_message sub, msg
|
169
|
+
assert_equal msg, ActiveMessaging::Gateway.connection.received_messages.first
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_abort_message
|
173
|
+
ActiveMessaging::Gateway.destination :hello_world, '/queue/helloWorld'
|
174
|
+
ActiveMessaging::Gateway.subscribe_to :hello_world, TestRetryProcessor, headers={}
|
175
|
+
sub = ActiveMessaging::Gateway.subscriptions.values.last
|
176
|
+
dest = ActiveMessaging::Adapters::Test::Destination.new '/queue/helloWorld'
|
177
|
+
msg = ActiveMessaging::Adapters::Test::Message.new("message_body", nil, {}, dest.name)
|
178
|
+
ActiveMessaging::Gateway.dispatch(msg)
|
179
|
+
assert_equal msg, ActiveMessaging::Gateway.connection.unreceived_messages.first
|
180
|
+
end
|
181
|
+
|
182
|
+
def test_aborted_messages_retry_original_message
|
183
|
+
ActiveMessaging::Gateway.destination :hello_world, '/queue/helloWorld'
|
184
|
+
ActiveMessaging::Gateway.filter 'gateway_test/message_mangling_filter'
|
185
|
+
ActiveMessaging::Gateway.subscribe_to :hello_world, TestRetryProcessor, headers={}
|
186
|
+
|
187
|
+
message_body = "message_body"
|
188
|
+
message_id = "55-a-msg"
|
189
|
+
message_headers = { 'x-my-header' => 'value' }
|
190
|
+
message_destination = '/queue/helloWorld'
|
191
|
+
msg = ActiveMessaging::Adapters::Test::Message.new(message_body.dup, message_id.dup, message_headers.dup, message_destination.dup)
|
192
|
+
ActiveMessaging::Gateway.dispatch(msg)
|
193
|
+
assert_equal message_body, ActiveMessaging::Gateway.connection.unreceived_messages.first.body
|
194
|
+
assert_equal message_id, ActiveMessaging::Gateway.connection.unreceived_messages.first.id
|
195
|
+
assert_equal message_headers, ActiveMessaging::Gateway.connection.unreceived_messages.first.headers
|
196
|
+
assert_equal message_destination, ActiveMessaging::Gateway.connection.unreceived_messages.first.destination
|
197
|
+
end
|
198
|
+
|
199
|
+
def test_receive
|
200
|
+
ActiveMessaging::Gateway.destination :hello_world, '/queue/helloWorld'
|
201
|
+
ActiveMessaging::Gateway.publish :hello_world, "test_publish body", self.class, headers={}, timeout=10
|
202
|
+
msg = ActiveMessaging::Gateway.receive :hello_world, self.class, headers={}, timeout=10
|
203
|
+
assert_not_nil ActiveMessaging::Gateway.connection.find_message('/queue/helloWorld', "test_publish body")
|
204
|
+
end
|
205
|
+
|
206
|
+
# def test_reload
|
207
|
+
# ActiveMessaging.reload_activemessaging
|
208
|
+
# size = ActiveMessaging::Gateway.named_destinations.size
|
209
|
+
# ActiveMessaging.reload_activemessaging
|
210
|
+
# assert_equal size, ActiveMessaging::Gateway.named_destinations.size
|
211
|
+
# end
|
212
|
+
|
213
|
+
## figure out how to test these better - start in a thread perhaps?
|
214
|
+
# def test_start
|
215
|
+
# end
|
216
|
+
#
|
217
|
+
# def test_stop
|
218
|
+
# end
|
219
|
+
|
220
|
+
end
|