torquebox-messaging 1.0.0.CR1-java
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/acl-spi-3.0.0.CR2.jar +0 -0
- data/lib/activation-1.1.jar +0 -0
- data/lib/authorization-spi-3.0.0.CR2.jar +0 -0
- data/lib/dtdparser-1.21.jar +0 -0
- data/lib/gem_hook.rb +22 -0
- data/lib/hornetq-core-2.1.2.Final.jar +0 -0
- data/lib/hornetq-jms-client-2.1.2.Final.jar +0 -0
- data/lib/hornetq-logging-2.1.2.Final.jar +0 -0
- data/lib/identity-spi-3.0.0.CR2.jar +0 -0
- data/lib/jaxb-api-2.1.9.jar +0 -0
- data/lib/jboss-common-core-2.2.17.GA.jar +0 -0
- data/lib/jboss-jms-api_1.1_spec-1.0.0.Final.jar +0 -0
- data/lib/jboss-logging-3.0.0.Beta4.jar +0 -0
- data/lib/jboss-reflect-2.2.0.GA.jar +0 -0
- data/lib/jbosssx-bare-3.0.0.CR2.jar +0 -0
- data/lib/jbossxacml-2.0.5.CR1.jar +0 -0
- data/lib/jbossxb-2.0.3.GA.jar +0 -0
- data/lib/jnp-client-5.0.5.Final.jar +0 -0
- data/lib/jruby-complete-1.6.1.jar +0 -0
- data/lib/netty-3.2.1.Final.jar +0 -0
- data/lib/org.torquebox.messaging-client.rb +20 -0
- data/lib/picketbox-acl-impl-3.0.0.CR2.jar +0 -0
- data/lib/picketbox-bare-3.0.0.CR2.jar +0 -0
- data/lib/picketbox-identity-impl-3.0.0.CR2.jar +0 -0
- data/lib/picketbox-spi-bare-3.0.0.CR2.jar +0 -0
- data/lib/torquebox/messaging/backgroundable.rb +134 -0
- data/lib/torquebox/messaging/client.rb +74 -0
- data/lib/torquebox/messaging/destination.rb +173 -0
- data/lib/torquebox/messaging/ext/javax_jms_queue_browser.rb +27 -0
- data/lib/torquebox/messaging/ext/javax_jms_session.rb +142 -0
- data/lib/torquebox/messaging/task.rb +46 -0
- data/lib/torquebox/messaging.rb +6 -0
- data/lib/torquebox-base-core.jar +0 -0
- data/lib/torquebox-base-metadata.jar +0 -0
- data/lib/torquebox-base-spi.jar +0 -0
- data/lib/torquebox-mc-support.jar +0 -0
- data/lib/torquebox-messaging-core.jar +0 -0
- data/lib/torquebox-messaging.jar +0 -0
- data/lib/torquebox-messaging.rb +43 -0
- data/lib/xercesImpl-2.9.1.jar +0 -0
- data/lib/xml-apis-1.3.04.jar +0 -0
- data/licenses/lgpl-2.1.txt +504 -0
- data/spec/backgroundable_spec.rb +141 -0
- data/spec/client_spec.rb +119 -0
- data/spec/destination_spec.rb +296 -0
- data/spec/dispatcher-queues.yml +4 -0
- data/spec/dispatcher_not_running.rb +54 -0
- data/spec/ext/java_jmx_session_spec.rb +71 -0
- data/spec/queues.yml +6 -0
- data/spec/task_spec.rb +66 -0
- metadata +163 -0
@@ -0,0 +1,141 @@
|
|
1
|
+
require 'torquebox/messaging/backgroundable'
|
2
|
+
|
3
|
+
class MyTestModel
|
4
|
+
include TorqueBox::Messaging::Backgroundable
|
5
|
+
|
6
|
+
def an_async_action(arg1, arg2)
|
7
|
+
a_sync_action
|
8
|
+
end
|
9
|
+
always_background :an_async_action
|
10
|
+
|
11
|
+
def a_sync_action; end
|
12
|
+
def foo; end
|
13
|
+
def bar; end
|
14
|
+
def optioned; end
|
15
|
+
def redefine_me; end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe TorqueBox::Messaging::Backgroundable do
|
19
|
+
before(:all) do
|
20
|
+
@util = TorqueBox::Messaging::Backgroundable::Util
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "always_background" do
|
24
|
+
it "should be able to handle mutliple methods" do
|
25
|
+
MyTestModel.always_background :foo, :bar
|
26
|
+
@util.instance_methods_include?(MyTestModel, '__async_foo').should be_true
|
27
|
+
@util.instance_methods_include?(MyTestModel, '__async_bar').should be_true
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should handle methods that are defined after the always_background call" do
|
31
|
+
MyTestModel.always_background :baz
|
32
|
+
@util.instance_methods_include?(MyTestModel, '__async_baz').should_not be_true
|
33
|
+
MyTestModel.class_eval('def baz;end')
|
34
|
+
@util.instance_methods_include?(MyTestModel, '__async_baz').should be_true
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should handle methods that are redefined after the always_background call" do
|
38
|
+
MyTestModel.always_background :redefine_me
|
39
|
+
MyTestModel.class_eval('def redefine_me; :xyz; end')
|
40
|
+
MyTestModel.new.__sync_redefine_me.should == :xyz
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should work for private methods, maintaining visibility" do
|
44
|
+
MyTestModel.class_eval('private; def no_peeking;end')
|
45
|
+
MyTestModel.always_background :no_peeking
|
46
|
+
@util.private_instance_methods_include?(MyTestModel, 'no_peeking').should be_true
|
47
|
+
@util.private_instance_methods_include?(MyTestModel, '__async_no_peeking').should be_true
|
48
|
+
@util.private_instance_methods_include?(MyTestModel, '__sync_no_peeking').should be_true
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should work for protected methods, maintaining visibility" do
|
52
|
+
MyTestModel.class_eval('protected; def some_peeking;end')
|
53
|
+
MyTestModel.always_background :some_peeking
|
54
|
+
@util.protected_instance_methods_include?(MyTestModel, 'some_peeking').should be_true
|
55
|
+
@util.protected_instance_methods_include?(MyTestModel, '__async_some_peeking').should be_true
|
56
|
+
@util.protected_instance_methods_include?(MyTestModel, '__sync_some_peeking').should be_true
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "a method handled asynchronously" do
|
61
|
+
before(:each) do
|
62
|
+
@queue = mock('queue')
|
63
|
+
@queue.stub(:publish)
|
64
|
+
TorqueBox::Messaging::Queue.stub(:new).and_return(@queue)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should put a message on the queue" do
|
68
|
+
@queue.should_receive(:publish)
|
69
|
+
MyTestModel.new.an_async_action(nil, nil)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should include the receiver, sync method, and args" do
|
73
|
+
object = MyTestModel.new
|
74
|
+
@queue.should_receive(:publish).with({:receiver => object, :method => '__sync_an_async_action', :args => [:a, :b]}, { })
|
75
|
+
object.an_async_action(:a, :b)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should not call the action immediately" do
|
79
|
+
object = MyTestModel.new
|
80
|
+
object.should_not_receive(:a_sync_action)
|
81
|
+
object.an_async_action(nil, nil)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should pass through the options" do
|
85
|
+
MyTestModel.always_background :optioned, :priority => :low
|
86
|
+
@queue.should_receive(:publish).with(anything, :priority => :low)
|
87
|
+
MyTestModel.new.optioned
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
describe 'background' do
|
93
|
+
before(:each) do
|
94
|
+
@queue = mock('queue')
|
95
|
+
@queue.stub(:publish)
|
96
|
+
TorqueBox::Messaging::Queue.stub(:new).and_return(@queue)
|
97
|
+
@object = MyTestModel.new
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should queue any method called on it" do
|
101
|
+
@queue.should_receive(:publish).with({:receiver => anything,
|
102
|
+
:method => :foo,
|
103
|
+
:args => anything}, { })
|
104
|
+
@object.background.foo
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should queue the receiver" do
|
108
|
+
@queue.should_receive(:publish).with({:receiver => @object,
|
109
|
+
:method => anything,
|
110
|
+
:args => anything}, { })
|
111
|
+
@object.background.foo
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should queue the args" do
|
115
|
+
@queue.should_receive(:publish).with({:receiver => anything,
|
116
|
+
:method => anything,
|
117
|
+
:args => [1,2]}, {})
|
118
|
+
@object.background.foo(1,2)
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should raise when given a block" do
|
122
|
+
lambda {
|
123
|
+
@object.background.foo { }
|
124
|
+
}.should raise_error(ArgumentError)
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should handle missing methods" do
|
128
|
+
@object.should_receive(:method_missing)
|
129
|
+
@object.background.no_method
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should pass through any options" do
|
133
|
+
@queue.should_receive(:publish).with({:receiver => anything,
|
134
|
+
:method => anything,
|
135
|
+
:args => anything},
|
136
|
+
{:ttl => 1})
|
137
|
+
@object.background(:ttl => 1).foo
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
require 'torquebox-messaging-container'
|
4
|
+
require 'torquebox-naming-container'
|
5
|
+
require 'torquebox-container-foundation'
|
6
|
+
|
7
|
+
require 'torquebox/messaging/client'
|
8
|
+
|
9
|
+
describe TorqueBox::Messaging::Client do
|
10
|
+
|
11
|
+
describe "sending and receiving" do
|
12
|
+
before(:each) do
|
13
|
+
@container = TorqueBox::Container::Foundation.new
|
14
|
+
@container.enable( TorqueBox::Naming::NamingService ) {|config| config.export=false}
|
15
|
+
@container.enable( TorqueBox::Messaging::MessageBroker )
|
16
|
+
@container.start
|
17
|
+
|
18
|
+
@queues_yml = @container.deploy( File.join( File.dirname(__FILE__), 'queues.yml' ) )
|
19
|
+
@container.process_deployments(true)
|
20
|
+
end
|
21
|
+
|
22
|
+
after(:each) do
|
23
|
+
@container.undeploy( @queues_yml )
|
24
|
+
@container.stop
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should be able to send to a queue from two threads/two sessions" do
|
28
|
+
|
29
|
+
received_message = nil
|
30
|
+
|
31
|
+
consumer_thread = Thread.new {
|
32
|
+
TorqueBox::Messaging::Client.connect() do |session|
|
33
|
+
received_message = session.receive( '/queues/foo' )
|
34
|
+
session.commit
|
35
|
+
end
|
36
|
+
}
|
37
|
+
|
38
|
+
producer_thread = Thread.new {
|
39
|
+
TorqueBox::Messaging::Client.connect() do |session|
|
40
|
+
session.publish( '/queues/foo', "howdy" )
|
41
|
+
session.commit
|
42
|
+
end
|
43
|
+
}
|
44
|
+
|
45
|
+
consumer_thread.join
|
46
|
+
|
47
|
+
received_message.should_not be_nil
|
48
|
+
received_message.should eql( "howdy" )
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
it "should be able to send to a queue from one thread/one session" do
|
53
|
+
|
54
|
+
received_message = nil
|
55
|
+
|
56
|
+
TorqueBox::Messaging::Client.connect() do |session|
|
57
|
+
session.publish( '/queues/foo', "howdy" )
|
58
|
+
session.commit
|
59
|
+
received_message = session.receive( '/queues/foo' )
|
60
|
+
session.commit
|
61
|
+
end
|
62
|
+
|
63
|
+
received_message.should_not be_nil
|
64
|
+
received_message.should eql( "howdy" )
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should be able to send and receive a non-String message" do
|
68
|
+
message = {:string => "a string", :symbol => :a_symbol, :hash => {}, :array => []}
|
69
|
+
received_message = nil
|
70
|
+
|
71
|
+
TorqueBox::Messaging::Client.connect() do |session|
|
72
|
+
session.publish( '/queues/foo', message )
|
73
|
+
session.commit
|
74
|
+
received_message = session.receive( '/queues/foo' )
|
75
|
+
session.commit
|
76
|
+
end
|
77
|
+
|
78
|
+
received_message.should_not be_nil
|
79
|
+
received_message.should eql( message )
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should identify a non-String message with a text property" do
|
83
|
+
received_message = nil
|
84
|
+
TorqueBox::Messaging::Client.connect() do |session|
|
85
|
+
session.publish( '/queues/foo', [] )
|
86
|
+
session.commit
|
87
|
+
received_message = session.receive( '/queues/foo', :decode => false )
|
88
|
+
session.commit
|
89
|
+
end
|
90
|
+
received_message.decode.should eql( [] )
|
91
|
+
received_message.get_string_property( 'torquebox_encoding' ).should eql( 'base64' )
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should not identify a String message with a text property" do
|
95
|
+
received_message = nil
|
96
|
+
TorqueBox::Messaging::Client.connect() do |session|
|
97
|
+
session.publish( '/queues/foo', "foo" )
|
98
|
+
session.commit
|
99
|
+
received_message = session.receive( '/queues/foo', :decode => false )
|
100
|
+
session.commit
|
101
|
+
end
|
102
|
+
received_message.text.should eql( "foo" )
|
103
|
+
received_message.decode.should eql( "foo" )
|
104
|
+
received_message.get_string_property( 'torquebox_encoding' ).should be_nil
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should timeout if asked" do
|
108
|
+
received_message = nil
|
109
|
+
TorqueBox::Messaging::Client.connect() do |session|
|
110
|
+
received_message = session.receive( '/queues/foo', :timeout => 1 )
|
111
|
+
end
|
112
|
+
received_message.should be_nil
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
|
@@ -0,0 +1,296 @@
|
|
1
|
+
|
2
|
+
require 'torquebox-container-foundation'
|
3
|
+
require 'torquebox-naming-container'
|
4
|
+
require 'torquebox-messaging-container'
|
5
|
+
require 'torquebox/messaging/destination'
|
6
|
+
|
7
|
+
describe TorqueBox::Messaging::Destination do
|
8
|
+
|
9
|
+
it "should return its name for to_s" do
|
10
|
+
queue = TorqueBox::Messaging::Queue.new("/queues/foo")
|
11
|
+
queue.name.should == "/queues/foo"
|
12
|
+
queue.to_s.should == queue.name
|
13
|
+
topic = TorqueBox::Messaging::Topic.new("/topics/bar")
|
14
|
+
topic.name.should == "/topics/bar"
|
15
|
+
topic.to_s.should == topic.name
|
16
|
+
end
|
17
|
+
|
18
|
+
%w{ create start }.each do |method|
|
19
|
+
|
20
|
+
it "should create a queue on #{method}" do
|
21
|
+
server = mock("server")
|
22
|
+
server.should_receive(:createQueue)
|
23
|
+
server.should_receive(:destroyQueue).with("my_queue")
|
24
|
+
TorqueBox::Kernel.stub!(:lookup).with("JMSServerManager").and_yield(server)
|
25
|
+
|
26
|
+
queue = TorqueBox::Messaging::Queue.new("my_queue")
|
27
|
+
queue.name.should eql("my_queue")
|
28
|
+
queue.send method
|
29
|
+
queue.destroy
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should create a topic on #{method}" do
|
33
|
+
server = mock("server")
|
34
|
+
server.should_receive(:createTopic)
|
35
|
+
server.should_receive(:destroyTopic).with("my_topic")
|
36
|
+
TorqueBox::Kernel.stub!(:lookup).with("JMSServerManager").and_yield(server)
|
37
|
+
|
38
|
+
topic = TorqueBox::Messaging::Topic.new("my_topic")
|
39
|
+
topic.name.should eql("my_topic")
|
40
|
+
topic.send method
|
41
|
+
topic.destroy
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "publish" do
|
47
|
+
before(:each) do
|
48
|
+
@session = mock('session')
|
49
|
+
@session.stub(:transacted?).and_return(false)
|
50
|
+
TorqueBox::Messaging::Client.stub(:connect).and_yield(@session)
|
51
|
+
@queue = TorqueBox::Messaging::Queue.new('foo')
|
52
|
+
end
|
53
|
+
|
54
|
+
context "normalizing options" do
|
55
|
+
context "priority" do
|
56
|
+
{
|
57
|
+
:low => 1,
|
58
|
+
:normal => 4,
|
59
|
+
:high => 7,
|
60
|
+
:critical => 9
|
61
|
+
}.each do |symbol, level|
|
62
|
+
it "should normalize :#{symbol} to #{level}" do
|
63
|
+
@session.should_receive(:publish).with(anything, anything, { :priority => level })
|
64
|
+
@queue.publish('message', { :priority => symbol })
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should pass through valid integer priorities" do
|
69
|
+
@session.should_receive(:publish).with(anything, anything, { :priority => 5 })
|
70
|
+
@queue.publish('message', { :priority => 5 })
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should pass through valid integer-as-string priorities" do
|
74
|
+
@session.should_receive(:publish).with(anything, anything, { :priority => 5 })
|
75
|
+
@queue.publish('message', { :priority => "5" })
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should raise on an invalid integer" do
|
79
|
+
lambda {
|
80
|
+
@queue.publish('message', { :priority => -1 })
|
81
|
+
}.should raise_error(ArgumentError)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should handle persistence = true" do
|
86
|
+
@session.should_receive(:publish).with(anything, anything, { :delivery_mode => javax.jms::DeliveryMode.PERSISTENT })
|
87
|
+
@queue.publish('message', { :persistent => true })
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should handle persistence = false" do
|
91
|
+
@session.should_receive(:publish).with(anything, anything, { :delivery_mode => javax.jms::DeliveryMode.NON_PERSISTENT })
|
92
|
+
@queue.publish('message', { :persistent => false })
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
describe "message selectors" do
|
99
|
+
before(:each) do
|
100
|
+
@container = TorqueBox::Container::Foundation.new
|
101
|
+
@container.enable( TorqueBox::Naming::NamingService ) {|config| config.export=false}
|
102
|
+
@container.enable( TorqueBox::Messaging::MessageBroker )
|
103
|
+
@container.start
|
104
|
+
@queue = TorqueBox::Messaging::Queue.new "/queues/selector_test"
|
105
|
+
@queue.start
|
106
|
+
end
|
107
|
+
|
108
|
+
after(:each) do
|
109
|
+
@queue.destroy
|
110
|
+
@container.stop
|
111
|
+
end
|
112
|
+
|
113
|
+
{
|
114
|
+
true => 'prop = true',
|
115
|
+
true => 'prop <> false',
|
116
|
+
5 => 'prop = 5',
|
117
|
+
5 => 'prop > 4',
|
118
|
+
5.5 => 'prop = 5.5',
|
119
|
+
5.5 => 'prop < 6',
|
120
|
+
'string' => "prop = 'string'"
|
121
|
+
}.each do |value, selector|
|
122
|
+
it "should be able to select with property set to #{value} using selector '#{selector}'" do
|
123
|
+
@queue.publish value.to_s, :properties => { :prop => value }
|
124
|
+
message = @queue.receive(:timeout => 1000, :selector => selector)
|
125
|
+
message.should == value.to_s
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
describe "browse" do
|
132
|
+
before(:each) do
|
133
|
+
@container = TorqueBox::Container::Foundation.new
|
134
|
+
@container.enable( TorqueBox::Naming::NamingService ) {|config| config.export=false}
|
135
|
+
@container.enable( TorqueBox::Messaging::MessageBroker )
|
136
|
+
@container.start
|
137
|
+
end
|
138
|
+
|
139
|
+
after(:each) do
|
140
|
+
@container.stop
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should allow enumeration of the messages" do
|
144
|
+
queue = TorqueBox::Messaging::Queue.new "/queues/browseable"
|
145
|
+
queue.start
|
146
|
+
queue.publish "howdy"
|
147
|
+
queue.first.text.should == 'howdy'
|
148
|
+
queue.destroy
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should accept a selector" do
|
152
|
+
queue = TorqueBox::Messaging::Queue.new "/queues/browseable", {}, :selector => 'blurple > 5'
|
153
|
+
queue.start
|
154
|
+
queue.publish "howdy", :properties => {:blurple => 5}
|
155
|
+
queue.publish "ahoyhoy", :properties => {:blurple => 6}
|
156
|
+
queue.first.text.should == 'ahoyhoy'
|
157
|
+
queue.detect { |m| m.text == 'howdy' }.should be_nil
|
158
|
+
queue.destroy
|
159
|
+
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe "sending and receiving" do
|
164
|
+
before(:each) do
|
165
|
+
@container = TorqueBox::Container::Foundation.new
|
166
|
+
@container.enable( TorqueBox::Naming::NamingService ) {|config| config.export=false}
|
167
|
+
@container.enable( TorqueBox::Messaging::MessageBroker )
|
168
|
+
@container.start
|
169
|
+
end
|
170
|
+
|
171
|
+
after(:each) do
|
172
|
+
@container.stop
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should be able to publish to and receive from a queue" do
|
176
|
+
queue = TorqueBox::Messaging::Queue.new "/queues/foo"
|
177
|
+
queue.start
|
178
|
+
|
179
|
+
queue.publish "howdy"
|
180
|
+
message = queue.receive
|
181
|
+
|
182
|
+
queue.destroy
|
183
|
+
message.should eql( "howdy" )
|
184
|
+
end
|
185
|
+
|
186
|
+
it "should publish to multiple topic consumers" do
|
187
|
+
topic = TorqueBox::Messaging::Topic.new "/topics/foo"
|
188
|
+
topic.start
|
189
|
+
threads, count = [], 10
|
190
|
+
|
191
|
+
# Use a threadsafe "array"
|
192
|
+
msgs = java.util.Collections.synchronizedList( [] )
|
193
|
+
|
194
|
+
# Ensure all clients are blocking on the receipt of a message
|
195
|
+
count.times { threads << Thread.new { msgs << topic.receive } }
|
196
|
+
sleep(1)
|
197
|
+
topic.publish "howdy"
|
198
|
+
threads.each {|t| t.join}
|
199
|
+
|
200
|
+
topic.destroy
|
201
|
+
msgs.to_a.should eql( ["howdy"] * count )
|
202
|
+
end
|
203
|
+
|
204
|
+
context "synchronous messaging" do
|
205
|
+
it "should return value of block given to receive_and_publish" do
|
206
|
+
queue = TorqueBox::Messaging::Queue.new "/queues/publish_and_receive"
|
207
|
+
queue.start
|
208
|
+
|
209
|
+
response_thread = Thread.new {
|
210
|
+
queue.receive_and_publish( :timeout => 10000 ) { |msg| msg.upcase }
|
211
|
+
}
|
212
|
+
message = queue.publish_and_receive "ping", :timeout => 10000
|
213
|
+
response_thread.join
|
214
|
+
|
215
|
+
queue.destroy
|
216
|
+
message.should eql( "PING" )
|
217
|
+
end
|
218
|
+
|
219
|
+
it "should return request message if no block given" do
|
220
|
+
queue = TorqueBox::Messaging::Queue.new "/queues/publish_and_receive"
|
221
|
+
queue.start
|
222
|
+
|
223
|
+
response_thread = Thread.new {
|
224
|
+
queue.receive_and_publish( :timeout => 10000 )
|
225
|
+
}
|
226
|
+
message = queue.publish_and_receive "ping", :timeout => 10000
|
227
|
+
response_thread.join
|
228
|
+
|
229
|
+
queue.destroy
|
230
|
+
message.should eql( "ping" )
|
231
|
+
end
|
232
|
+
|
233
|
+
it "should not mess up with multiple consumers" do
|
234
|
+
queue = TorqueBox::Messaging::Queue.new "/queues/publish_and_receive"
|
235
|
+
queue.start
|
236
|
+
|
237
|
+
thread_count = 3
|
238
|
+
response_threads = (1..thread_count).map do
|
239
|
+
Thread.new {
|
240
|
+
queue.receive_and_publish( :timeout => 10000 ) { |msg| msg.upcase }
|
241
|
+
}
|
242
|
+
end
|
243
|
+
|
244
|
+
message = queue.publish_and_receive "ping", :timeout => 10000
|
245
|
+
# Send extra messages to trigger all remaining response threads
|
246
|
+
(thread_count - 1).times do
|
247
|
+
queue.publish_and_receive "ping", :timeout => 10000
|
248
|
+
end
|
249
|
+
response_threads.each { |thread| thread.join }
|
250
|
+
|
251
|
+
queue.destroy
|
252
|
+
message.should eql( "PING" )
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
context "destination not ready" do
|
257
|
+
it "should block on publish until queue is ready" do
|
258
|
+
queue = TorqueBox::Messaging::Queue.new "/queues/not_ready"
|
259
|
+
# Start the queue in a separate thread after a delay
|
260
|
+
setup_thread = Thread.new {
|
261
|
+
sleep( 0.2 )
|
262
|
+
queue.start
|
263
|
+
}
|
264
|
+
# The queue will not be ready when we call the publish method
|
265
|
+
queue.publish "something"
|
266
|
+
message = queue.receive
|
267
|
+
|
268
|
+
setup_thread.join
|
269
|
+
queue.destroy
|
270
|
+
message.should eql( "something" )
|
271
|
+
end
|
272
|
+
|
273
|
+
it "should block on receive until topic is ready" do
|
274
|
+
topic = TorqueBox::Messaging::Topic.new "/topics/not_ready"
|
275
|
+
# Start the topic in a separate thread after a delay
|
276
|
+
setup_thread = Thread.new {
|
277
|
+
topic.start
|
278
|
+
}
|
279
|
+
# The topic will not be ready when we call the receive method
|
280
|
+
message = topic.receive :timeout => 200
|
281
|
+
|
282
|
+
setup_thread.join
|
283
|
+
topic.destroy
|
284
|
+
message.should be_nil
|
285
|
+
end
|
286
|
+
|
287
|
+
it "should block until startup_timeout reached" do
|
288
|
+
queue = TorqueBox::Messaging::Queue.new "/queues/not_ready"
|
289
|
+
lambda {
|
290
|
+
queue.publish "something", :startup_timeout => 200
|
291
|
+
}.should raise_error(javax.naming.NameNotFoundException)
|
292
|
+
end
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
#require 'spec_helper'
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'torquebox-naming'
|
5
|
+
require 'torquebox-naming-container'
|
6
|
+
require 'torquebox-messaging-container'
|
7
|
+
require 'torquebox/messaging/message_processor'
|
8
|
+
require 'torquebox/messaging/destination'
|
9
|
+
|
10
|
+
QUEUE_QUESTIONS = TorqueBox::Messaging::Queue.new("/queues/questions")
|
11
|
+
QUEUE_ANSWERS = TorqueBox::Messaging::Queue.new("/queues/answers")
|
12
|
+
|
13
|
+
TESTING_ON_WINDOWS = ( java.lang::System.getProperty( "os.name" ) =~ /.*windows*/i )
|
14
|
+
|
15
|
+
class Upcaser < TorqueBox::Messaging::MessageProcessor
|
16
|
+
def on_message(body)
|
17
|
+
QUEUE_ANSWERS.publish( body.upcase )
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "dispatcher test" do
|
22
|
+
before(:each) do
|
23
|
+
@container = TorqueBox::Container::Foundation.new
|
24
|
+
@container.enable( TorqueBox::Naming::NamingService ) {|config| config.export=true}
|
25
|
+
@container.enable( TorqueBox::Messaging::MessageBroker )
|
26
|
+
@container.start
|
27
|
+
|
28
|
+
@queues_yml = @container.deploy( File.join( File.dirname(__FILE__), 'dispatcher-queues.yml' ) )
|
29
|
+
@container.process_deployments(true)
|
30
|
+
puts "Deployed queues"
|
31
|
+
end
|
32
|
+
|
33
|
+
after(:each) do
|
34
|
+
puts "UNDEPLOY queues"
|
35
|
+
@container.undeploy( @queues_yml )
|
36
|
+
puts "UNDEPLOYED queues"
|
37
|
+
puts "STOP container"
|
38
|
+
@container.stop
|
39
|
+
puts "STOPPED container"
|
40
|
+
end
|
41
|
+
|
42
|
+
unless TESTING_ON_WINDOWS
|
43
|
+
it "should associate a processor with a queue" do
|
44
|
+
dispatcher = TorqueBox::Messaging::Dispatcher.new( :skip_naming=>true ) do
|
45
|
+
map Upcaser, QUEUE_QUESTIONS
|
46
|
+
end
|
47
|
+
dispatcher.start
|
48
|
+
QUEUE_QUESTIONS.publish "lkjsdf"
|
49
|
+
QUEUE_ANSWERS.receive(:timeout => 2000).should == "LKJSDF"
|
50
|
+
dispatcher.stop
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'torquebox/messaging/ext/javax_jms_session'
|
2
|
+
|
3
|
+
describe javax.jms::Session do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@session = javax.jms::Session.new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe ".populate_message_properties" do
|
10
|
+
it "should do nothing if no properties are submitted" do
|
11
|
+
jms_message = mock('JMSMessage')
|
12
|
+
jms_message.should_not_receive(:setStringProperty)
|
13
|
+
|
14
|
+
@session.populate_message_properties jms_message, nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should register properties with String keys" do
|
18
|
+
properties = {'abc' => 'def'}
|
19
|
+
|
20
|
+
jms_message = mock('JMSMessage')
|
21
|
+
jms_message.should_receive(:set_string_property).with('abc', 'def')
|
22
|
+
|
23
|
+
@session.populate_message_properties jms_message, properties
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should register properties with Symbol keys" do
|
27
|
+
properties = {:abc => :def}
|
28
|
+
|
29
|
+
jms_message = mock('JMSMessage')
|
30
|
+
jms_message.should_receive(:set_string_property).with('abc', 'def')
|
31
|
+
|
32
|
+
@session.populate_message_properties jms_message, properties
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should register true as a boolean" do
|
36
|
+
properties = {:abc => true}
|
37
|
+
|
38
|
+
jms_message = mock('JMSMessage')
|
39
|
+
jms_message.should_receive(:set_boolean_property).with('abc', true)
|
40
|
+
|
41
|
+
@session.populate_message_properties jms_message, properties
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should register false as a boolean" do
|
45
|
+
properties = {:abc => false}
|
46
|
+
|
47
|
+
jms_message = mock('JMSMessage')
|
48
|
+
jms_message.should_receive(:set_boolean_property).with('abc', false)
|
49
|
+
|
50
|
+
@session.populate_message_properties jms_message, properties
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should register 5 as an long" do
|
54
|
+
properties = {:abc => 5}
|
55
|
+
|
56
|
+
jms_message = mock('JMSMessage')
|
57
|
+
jms_message.should_receive(:set_long_property).with('abc', 5)
|
58
|
+
|
59
|
+
@session.populate_message_properties jms_message, properties
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should register 5.5 as a double" do
|
63
|
+
properties = {:abc => 5.5}
|
64
|
+
|
65
|
+
jms_message = mock('JMSMessage')
|
66
|
+
jms_message.should_receive(:set_double_property).with('abc', 5.5)
|
67
|
+
|
68
|
+
@session.populate_message_properties jms_message, properties
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|