gz_activemessaging 0.13.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +15 -0
  2. data/.travis.yml +40 -0
  3. data/Appraisals +19 -0
  4. data/Gemfile +15 -0
  5. data/Gemfile.lock +87 -0
  6. data/README.md +27 -0
  7. data/Rakefile +49 -0
  8. data/VERSION +1 -0
  9. data/activemessaging.gemspec +137 -0
  10. data/gemfiles/activesupport23.gemfile +10 -0
  11. data/gemfiles/activesupport23.gemfile.lock +51 -0
  12. data/gemfiles/activesupport30.gemfile +11 -0
  13. data/gemfiles/activesupport30.gemfile.lock +53 -0
  14. data/gemfiles/activesupport31.gemfile +11 -0
  15. data/gemfiles/activesupport31.gemfile.lock +55 -0
  16. data/gemfiles/activesupport32.gemfile +10 -0
  17. data/gemfiles/activesupport32.gemfile.lock +55 -0
  18. data/generators/a13g_test_harness/a13g_test_harness_generator.rb +19 -0
  19. data/generators/a13g_test_harness/templates/active_messaging_test.rhtml +13 -0
  20. data/generators/a13g_test_harness/templates/active_messaging_test_controller.rb +29 -0
  21. data/generators/a13g_test_harness/templates/index.rhtml +17 -0
  22. data/generators/filter/USAGE +0 -0
  23. data/generators/filter/filter_generator.rb +19 -0
  24. data/generators/filter/templates/filter.rb +12 -0
  25. data/generators/filter/templates/filter_test.rb +28 -0
  26. data/generators/processor/USAGE +8 -0
  27. data/generators/processor/processor_generator.rb +31 -0
  28. data/generators/processor/templates/application_processor.rb +18 -0
  29. data/generators/processor/templates/broker.yml +140 -0
  30. data/generators/processor/templates/jruby_poller +117 -0
  31. data/generators/processor/templates/messaging.rb +12 -0
  32. data/generators/processor/templates/poller +25 -0
  33. data/generators/processor/templates/poller.rb +26 -0
  34. data/generators/processor/templates/processor.rb +8 -0
  35. data/generators/processor/templates/processor_test.rb +20 -0
  36. data/generators/tracer/USAGE +8 -0
  37. data/generators/tracer/templates/controller.rb +14 -0
  38. data/generators/tracer/templates/helper.rb +2 -0
  39. data/generators/tracer/templates/index.rhtml +4 -0
  40. data/generators/tracer/templates/layout.rhtml +16 -0
  41. data/generators/tracer/templates/trace_processor.rb +100 -0
  42. data/generators/tracer/tracer_generator.rb +25 -0
  43. data/init.rb +1 -0
  44. data/lib/activemessaging.rb +133 -0
  45. data/lib/activemessaging/adapter.rb +20 -0
  46. data/lib/activemessaging/adapters/amqp.rb +215 -0
  47. data/lib/activemessaging/adapters/asqs.rb +487 -0
  48. data/lib/activemessaging/adapters/base.rb +71 -0
  49. data/lib/activemessaging/adapters/beanstalk.rb +88 -0
  50. data/lib/activemessaging/adapters/jms.rb +243 -0
  51. data/lib/activemessaging/adapters/reliable_msg.rb +186 -0
  52. data/lib/activemessaging/adapters/stomp.rb +212 -0
  53. data/lib/activemessaging/adapters/synch.rb +95 -0
  54. data/lib/activemessaging/adapters/test.rb +137 -0
  55. data/lib/activemessaging/adapters/wmq.rb +193 -0
  56. data/lib/activemessaging/base_message.rb +28 -0
  57. data/lib/activemessaging/filter.rb +29 -0
  58. data/lib/activemessaging/gateway.rb +429 -0
  59. data/lib/activemessaging/message_sender.rb +30 -0
  60. data/lib/activemessaging/named_base.rb +54 -0
  61. data/lib/activemessaging/processor.rb +44 -0
  62. data/lib/activemessaging/railtie.rb +26 -0
  63. data/lib/activemessaging/test_helper.rb +189 -0
  64. data/lib/activemessaging/threaded_poller.rb +234 -0
  65. data/lib/activemessaging/trace_filter.rb +34 -0
  66. data/lib/generators/active_messaging/install/USAGE +21 -0
  67. data/lib/generators/active_messaging/install/install_generator.rb +39 -0
  68. data/lib/generators/active_messaging/install/templates/application_processor.rb +18 -0
  69. data/lib/generators/active_messaging/install/templates/broker.yml +139 -0
  70. data/lib/generators/active_messaging/install/templates/poller +24 -0
  71. data/lib/generators/active_messaging/install/templates/poller.rb +22 -0
  72. data/lib/generators/active_messaging/install/templates/threaded_poller +46 -0
  73. data/lib/generators/active_messaging/processor/USAGE +2 -0
  74. data/lib/generators/active_messaging/processor/processor_generator.rb +39 -0
  75. data/lib/generators/active_messaging/processor/templates/messaging.rb +12 -0
  76. data/lib/generators/active_messaging/processor/templates/processor.rb +8 -0
  77. data/lib/generators/active_messaging/processor/templates/processor_spec.rb +24 -0
  78. data/lib/generators/active_messaging/processor/templates/processor_test.rb +20 -0
  79. data/lib/tasks/start_consumers.rake +8 -0
  80. data/poller.rb +14 -0
  81. data/test/all_tests.rb +10 -0
  82. data/test/app/config/broker.yml +4 -0
  83. data/test/asqs_test.rb +125 -0
  84. data/test/config_test.rb +42 -0
  85. data/test/filter_test.rb +131 -0
  86. data/test/gateway_test.rb +220 -0
  87. data/test/jms_test.rb +64 -0
  88. data/test/reliable_msg_test.rb +83 -0
  89. data/test/stomp_test.rb +168 -0
  90. data/test/test_helper.rb +36 -0
  91. data/test/tracer_test.rb +57 -0
  92. 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
@@ -0,0 +1,8 @@
1
+ namespace "activemessaging" do
2
+
3
+ desc 'Run all consumers'
4
+ task :start_consumers do
5
+ load File.dirname(__FILE__) + '/../poller.rb'
6
+ end
7
+
8
+ 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
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+
3
+ require 'test/unit'
4
+
5
+ # tests
6
+ require 'config_test'
7
+ require 'filter_test'
8
+ require 'tracer_test'
9
+ require 'jms_test'
10
+ require 'asqs_test'
@@ -0,0 +1,4 @@
1
+ # Yaml config file for testing ActiveMessaging
2
+ test:
3
+ adapter: test
4
+ reliable: false
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
@@ -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
@@ -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