torquebox-messaging 1.1.1-java → 2.0.0.beta1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/lib/gem_hook.rb +26 -3
  2. data/lib/torquebox-messaging.jar +0 -0
  3. data/lib/torquebox-messaging.rb +2 -32
  4. data/lib/torquebox/messaging.rb +16 -0
  5. data/lib/torquebox/messaging/backgroundable.rb +32 -15
  6. data/lib/torquebox/messaging/backgroundable_processor.rb +32 -0
  7. data/lib/torquebox/messaging/connection.rb +127 -0
  8. data/lib/torquebox/messaging/connection_factory.rb +70 -0
  9. data/lib/torquebox/messaging/const_missing.rb +28 -0
  10. data/lib/torquebox/messaging/core.rb +27 -0
  11. data/lib/torquebox/messaging/destination.rb +68 -111
  12. data/lib/torquebox/messaging/ext/javax_jms_queue_browser.rb +1 -3
  13. data/lib/torquebox/messaging/future_responder.rb +10 -7
  14. data/lib/torquebox/messaging/json_message.rb +50 -0
  15. data/lib/torquebox/messaging/marshal_base64_message.rb +44 -0
  16. data/lib/torquebox/messaging/marshal_message.rb +43 -0
  17. data/lib/torquebox/messaging/message.rb +123 -0
  18. data/lib/torquebox/messaging/message_processor.rb +47 -0
  19. data/lib/torquebox/messaging/processor_wrapper.rb +38 -0
  20. data/lib/torquebox/messaging/queue.rb +61 -0
  21. data/lib/torquebox/messaging/session.rb +168 -0
  22. data/lib/torquebox/messaging/task.rb +7 -6
  23. data/lib/torquebox/messaging/text_message.rb +36 -0
  24. data/lib/torquebox/messaging/topic.rb +54 -0
  25. data/lib/torquebox/messaging/xa_connection.rb +58 -0
  26. data/lib/torquebox/messaging/xa_connection_factory.rb +59 -0
  27. data/lib/torquebox/messaging/xa_session.rb +30 -0
  28. data/licenses/lgpl-2.1.txt +7 -9
  29. data/spec/backgroundable_spec.rb +17 -24
  30. data/spec/destination_spec.rb +31 -318
  31. data/spec/future_responder_spec.rb +1 -1
  32. data/spec/json_message_spec.rb +50 -0
  33. data/spec/message_processor_spec.rb +54 -0
  34. data/spec/message_spec.rb +114 -0
  35. data/spec/task_spec.rb +11 -5
  36. metadata +38 -77
  37. data/lib/acl-spi-3.0.0.CR2.jar +0 -0
  38. data/lib/activation-1.1.jar +0 -0
  39. data/lib/authorization-spi-3.0.0.CR2.jar +0 -0
  40. data/lib/dtdparser-1.21.jar +0 -0
  41. data/lib/hornetq-core-2.1.2.Final.jar +0 -0
  42. data/lib/hornetq-jms-client-2.1.2.Final.jar +0 -0
  43. data/lib/hornetq-logging-2.1.2.Final.jar +0 -0
  44. data/lib/identity-spi-3.0.0.CR2.jar +0 -0
  45. data/lib/jaxb-api-2.1.9.jar +0 -0
  46. data/lib/jboss-common-core-2.2.17.GA.jar +0 -0
  47. data/lib/jboss-jms-api_1.1_spec-1.0.0.Final.jar +0 -0
  48. data/lib/jboss-logging-3.0.0.Beta4.jar +0 -0
  49. data/lib/jboss-reflect-2.2.0.GA.jar +0 -0
  50. data/lib/jbosssx-bare-3.0.0.CR2.jar +0 -0
  51. data/lib/jbossxacml-2.0.5.CR1.jar +0 -0
  52. data/lib/jbossxb-2.0.3.GA.jar +0 -0
  53. data/lib/jnp-client-5.0.5.Final.jar +0 -0
  54. data/lib/jruby-complete-1.6.3.jar +0 -0
  55. data/lib/netty-3.2.1.Final.jar +0 -0
  56. data/lib/picketbox-acl-impl-3.0.0.CR2.jar +0 -0
  57. data/lib/picketbox-bare-3.0.0.CR2.jar +0 -0
  58. data/lib/picketbox-identity-impl-3.0.0.CR2.jar +0 -0
  59. data/lib/picketbox-spi-bare-3.0.0.CR2.jar +0 -0
  60. data/lib/torquebox-base-core.jar +0 -0
  61. data/lib/torquebox-base-metadata.jar +0 -0
  62. data/lib/torquebox-base-spi.jar +0 -0
  63. data/lib/torquebox-mc-support.jar +0 -0
  64. data/lib/torquebox-messaging-core.jar +0 -0
  65. data/lib/torquebox/messaging/client.rb +0 -75
  66. data/lib/torquebox/messaging/ext/javax_jms_session.rb +0 -153
  67. data/lib/xercesImpl-2.9.1.jar +0 -0
  68. data/lib/xml-apis-1.3.04.jar +0 -0
  69. data/spec/client_spec.rb +0 -116
  70. data/spec/dispatcher-queues.yml +0 -4
  71. data/spec/dispatcher_not_running.rb +0 -54
  72. data/spec/ext/java_jmx_session_spec.rb +0 -71
  73. data/spec/queues.yml +0 -6
@@ -0,0 +1,36 @@
1
+ # Copyright 2008-2011 Red Hat, Inc, and individual contributors.
2
+ #
3
+ # This is free software; you can redistribute it and/or modify it
4
+ # under the terms of the GNU Lesser General Public License as
5
+ # published by the Free Software Foundation; either version 2.1 of
6
+ # the License, or (at your option) any later version.
7
+ #
8
+ # This software is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this software; if not, write to the Free
15
+ # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
16
+ # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
17
+
18
+ module TorqueBox
19
+ module Messaging
20
+ class TextMessage < Message
21
+ ENCODING = :text
22
+ JMS_TYPE = :text
23
+
24
+ def encode(message)
25
+ @jms_message.text = message || ''
26
+ end
27
+
28
+ def decode
29
+ @jms_message.text
30
+ end
31
+
32
+ end
33
+
34
+ Message.register_encoding( TextMessage )
35
+ end
36
+ end
@@ -0,0 +1,54 @@
1
+ # Copyright 2008-2011 Red Hat, Inc, and individual contributors.
2
+ #
3
+ # This is free software; you can redistribute it and/or modify it
4
+ # under the terms of the GNU Lesser General Public License as
5
+ # published by the Free Software Foundation; either version 2.1 of
6
+ # the License, or (at your option) any later version.
7
+ #
8
+ # This software is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this software; if not, write to the Free
15
+ # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
16
+ # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
17
+
18
+ require 'torquebox/messaging/destination'
19
+ require 'torquebox/service_registry'
20
+
21
+ module TorqueBox
22
+ module Messaging
23
+ class Topic < Destination
24
+
25
+ DEFAULT_SUBSCRIBER_NAME = 'subscriber-1'
26
+
27
+ def self.start( name, options={} )
28
+ jndi = options.fetch( :jndi, [].to_java(:string) )
29
+ TorqueBox::ServiceRegistry.lookup("jboss.messaging.default.jms.manager") do |server|
30
+ server.createTopic( false, name, jndi )
31
+ end
32
+ new( name )
33
+ end
34
+
35
+ def stop
36
+ TorqueBox::ServiceRegistry.lookup("jboss.messaging.default.jms.manager") do |server|
37
+ server.destroyTopic( name )
38
+ end
39
+ end
40
+
41
+ def unsubscribe(subscriber_name = DEFAULT_SUBSCRIBER_NAME, options = { })
42
+ wait_for_destination(options[:startup_timeout]) do
43
+ with_session do |session|
44
+ session.unsubscribe( subscriber_name )
45
+ end
46
+ end
47
+ end
48
+
49
+ def to_s
50
+ "[Topic: #{super}]"
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,58 @@
1
+ # Copyright 2008-2011 Red Hat, Inc, and individual contributors.
2
+ #
3
+ # This is free software; you can redistribute it and/or modify it
4
+ # under the terms of the GNU Lesser General Public License as
5
+ # published by the Free Software Foundation; either version 2.1 of
6
+ # the License, or (at your option) any later version.
7
+ #
8
+ # This software is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this software; if not, write to the Free
15
+ # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
16
+ # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
17
+
18
+ module TorqueBox
19
+ module Messaging
20
+ class XaConnection
21
+
22
+ def initialize(jms_connection)
23
+ @jms_connection = jms_connection
24
+ end
25
+
26
+ def start
27
+ @jms_connection.start
28
+ end
29
+
30
+ def close
31
+ @jms_connection.close
32
+ end
33
+
34
+ def client_id
35
+ @jms_connection.client_id
36
+ end
37
+
38
+ def client_id=(client_id)
39
+ @jms_connection.client_id = client_id
40
+ end
41
+
42
+ def with_session(&block)
43
+ session = self.create_session()
44
+ begin
45
+ result = block.call( session )
46
+ ensure
47
+ session.close
48
+ end
49
+ return result
50
+ end
51
+
52
+ def create_session()
53
+ XaSession.new( @jms_connection.create_xa_session() )
54
+ end
55
+
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,59 @@
1
+ # Copyright 2008-2011 Red Hat, Inc, and individual contributors.
2
+ #
3
+ # This is free software; you can redistribute it and/or modify it
4
+ # under the terms of the GNU Lesser General Public License as
5
+ # published by the Free Software Foundation; either version 2.1 of
6
+ # the License, or (at your option) any later version.
7
+ #
8
+ # This software is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this software; if not, write to the Free
15
+ # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
16
+ # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
17
+
18
+ require 'java'
19
+ require 'torquebox/messaging/connection'
20
+
21
+ module TorqueBox
22
+ module Messaging
23
+ class XaConnectionFactory
24
+
25
+ attr_reader :internal_connection_factory
26
+
27
+ def self.new(internal_connection_factory = nil)
28
+ return internal_connection_factory if internal_connection_factory.is_a?( XaConnectionFactory )
29
+ super
30
+ end
31
+
32
+ def initialize(internal_connection_factory = nil)
33
+ @internal_connection_factory = internal_connection_factory
34
+ end
35
+
36
+ def with_new_connection(client_id = nil, &block)
37
+ connection = create_connection
38
+ connection.client_id = client_id
39
+ connection.start
40
+ begin
41
+ result = block.call( connection )
42
+ ensure
43
+ connection.close
44
+ end
45
+ return result
46
+ end
47
+
48
+ def create_connection()
49
+ XaConnection.new( @internal_connection_factory.create_xa_connection )
50
+ end
51
+
52
+
53
+ def to_s
54
+ "[XaConnectionFactory: internal_connection_factory=#{internal_connection_factory}]"
55
+ end
56
+
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,30 @@
1
+ # Copyright 2008-2011 Red Hat, Inc, and individual contributors.
2
+ #
3
+ # This is free software; you can redistribute it and/or modify it
4
+ # under the terms of the GNU Lesser General Public License as
5
+ # published by the Free Software Foundation; either version 2.1 of
6
+ # the License, or (at your option) any later version.
7
+ #
8
+ # This software is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this software; if not, write to the Free
15
+ # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
16
+ # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
17
+
18
+ module TorqueBox
19
+ module Messaging
20
+
21
+ class XaSession < Session
22
+
23
+ def xa_resource
24
+ @jms_session.xa_resource
25
+ end
26
+
27
+ end
28
+
29
+ end
30
+ end
@@ -1,5 +1,5 @@
1
- GNU LESSER GENERAL PUBLIC LICENSE
2
- Version 2.1, February 1999
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 2.1, February 1999
3
3
 
4
4
  Copyright (C) 1991, 1999 Free Software Foundation, Inc.
5
5
  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
@@ -10,7 +10,7 @@
10
10
  as the successor of the GNU Library Public License, version 2, hence
11
11
  the version number 2.1.]
12
12
 
13
- Preamble
13
+ Preamble
14
14
 
15
15
  The licenses for most software are designed to take away your
16
16
  freedom to share and change it. By contrast, the GNU General Public
@@ -112,7 +112,7 @@ modification follow. Pay close attention to the difference between a
112
112
  former contains code derived from the library, whereas the latter must
113
113
  be combined with the library in order to run.
114
114
 
115
- GNU LESSER GENERAL PUBLIC LICENSE
115
+ GNU LESSER GENERAL PUBLIC LICENSE
116
116
  TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
117
117
 
118
118
  0. This License Agreement applies to any software library or other
@@ -146,7 +146,7 @@ such a program is covered only if its contents constitute a work based
146
146
  on the Library (independent of the use of the Library in a tool for
147
147
  writing it). Whether that is true depends on what the Library does
148
148
  and what the program that uses the Library does.
149
-
149
+
150
150
  1. You may copy and distribute verbatim copies of the Library's
151
151
  complete source code as you receive it, in any medium, provided that
152
152
  you conspicuously and appropriately publish on each copy an
@@ -432,7 +432,7 @@ decision will be guided by the two goals of preserving the free status
432
432
  of all derivatives of our free software and of promoting the sharing
433
433
  and reuse of software generally.
434
434
 
435
- NO WARRANTY
435
+ NO WARRANTY
436
436
 
437
437
  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
438
438
  WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
@@ -455,7 +455,7 @@ FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
455
455
  SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
456
456
  DAMAGES.
457
457
 
458
- END OF TERMS AND CONDITIONS
458
+ END OF TERMS AND CONDITIONS
459
459
 
460
460
  How to Apply These Terms to Your New Libraries
461
461
 
@@ -500,5 +500,3 @@ necessary. Here is a sample; alter the names:
500
500
  Ty Coon, President of Vice
501
501
 
502
502
  That's all there is to it!
503
-
504
-
@@ -80,10 +80,11 @@ describe TorqueBox::Messaging::Backgroundable do
80
80
  @queue.should_receive(:publish).with({
81
81
  :receiver => object,
82
82
  :future_id => '1234',
83
- :future_queue => "/queues/torquebox//backgroundable",
83
+ :future_queue => "/queues/torquebox//tasks/torquebox_backgroundable",
84
84
  :method => '__sync_an_async_action',
85
85
  :args => [:a, :b]
86
- }, { })
86
+ },
87
+ anything)
87
88
  object.an_async_action(:a, :b)
88
89
  end
89
90
 
@@ -95,7 +96,7 @@ describe TorqueBox::Messaging::Backgroundable do
95
96
 
96
97
  it "should pass through the options" do
97
98
  MyTestModel.always_background :optioned, :priority => :low
98
- @queue.should_receive(:publish).with(anything, :priority => :low)
99
+ @queue.should_receive(:publish).with(anything, hash_including(:priority => :low))
99
100
  MyTestModel.new.optioned
100
101
  end
101
102
 
@@ -110,29 +111,18 @@ describe TorqueBox::Messaging::Backgroundable do
110
111
  end
111
112
 
112
113
  it "should queue any method called on it" do
113
- @queue.should_receive(:publish).with({:receiver => anything,
114
- :method => :foo,
115
- :args => anything,
116
- :future_id => anything,
117
- :future_queue => anything}, { })
114
+ @queue.should_receive(:publish).with(hash_including(:method => :foo),
115
+ anything)
118
116
  @object.background.foo
119
117
  end
120
118
 
121
119
  it "should queue the receiver" do
122
- @queue.should_receive(:publish).with({:receiver => @object,
123
- :method => anything,
124
- :args => anything,
125
- :future_id => anything,
126
- :future_queue => anything}, { })
120
+ @queue.should_receive(:publish).with(hash_including(:receiver => @object), anything)
127
121
  @object.background.foo
128
122
  end
129
123
 
130
124
  it "should queue the args" do
131
- @queue.should_receive(:publish).with({:receiver => anything,
132
- :method => anything,
133
- :future_id => anything,
134
- :future_queue => anything,
135
- :args => [1,2]}, {})
125
+ @queue.should_receive(:publish).with(hash_including(:args => [1,2]), anything)
136
126
  @object.background.foo(1,2)
137
127
  end
138
128
 
@@ -148,14 +138,17 @@ describe TorqueBox::Messaging::Backgroundable do
148
138
  end
149
139
 
150
140
  it "should pass through any options" do
151
- @queue.should_receive(:publish).with({:receiver => anything,
152
- :method => anything,
153
- :args => anything,
154
- :future_id => anything,
155
- :future_queue => anything},
156
- {:ttl => 1})
141
+ @queue.should_receive(:publish).with(anything,
142
+ hash_including(:ttl => 1))
157
143
  @object.background(:ttl => 1).foo
158
144
  end
145
+
146
+ it "should always use the :marshal encoding" do
147
+ @queue.should_receive(:publish).with(anything,
148
+ hash_including(:encoding => :marshal))
149
+ @object.background.foo
150
+ end
151
+
159
152
  end
160
153
 
161
154
  end
@@ -1,54 +1,57 @@
1
1
 
2
- require 'torquebox-container-foundation'
3
- require 'torquebox-naming-container'
4
- require 'torquebox-messaging-container'
5
- require 'torquebox/messaging/destination'
2
+ require 'torquebox/messaging/queue'
3
+ require 'torquebox/messaging/topic'
4
+ require 'torquebox/service_registry'
5
+
6
+ java_import org.mockito.ArgumentCaptor
7
+ java_import org.mockito.Matchers
8
+ java_import org.mockito.Mockito
9
+ java_import org.hornetq.jms.server.impl.JMSServerManagerImpl
6
10
 
7
11
  describe TorqueBox::Messaging::Destination do
8
12
 
9
13
  it "should return its name for to_s" do
10
14
  queue = TorqueBox::Messaging::Queue.new("/queues/foo")
11
15
  queue.name.should == "/queues/foo"
12
- queue.to_s.should == queue.name
13
16
  topic = TorqueBox::Messaging::Topic.new("/topics/bar")
14
17
  topic.name.should == "/topics/bar"
15
- topic.to_s.should == topic.name
16
18
  end
17
19
 
18
- %w{ create start }.each do |method|
20
+ it "should start and stop a queue" do
21
+ server = Mockito.mock(JMSServerManagerImpl.java_class)
22
+ TorqueBox::ServiceRegistry.stub!(:lookup).with("jboss.messaging.default.jms.manager").and_yield(server)
19
23
 
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)
24
+ queue = TorqueBox::Messaging::Queue.start( "my_queue" )
25
+ queue.name.should == "my_queue"
26
+ queue.stop
25
27
 
26
- queue = TorqueBox::Messaging::Queue.new("my_queue")
27
- queue.name.should eql("my_queue")
28
- queue.send method
29
- queue.destroy
30
- end
28
+ Mockito.verify(server).createQueue(Matchers.anyBoolean,
29
+ Matchers.eq("my_queue"),
30
+ Matchers.anyString,
31
+ Matchers.anyBoolean)
32
+ Mockito.verify(server).destroyQueue("my_queue")
33
+ end
31
34
 
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)
35
+ it "should start and stop a topic" do
36
+ server = Mockito.mock(JMSServerManagerImpl.java_class)
37
+ TorqueBox::ServiceRegistry.stub!(:lookup).with("jboss.messaging.default.jms.manager").and_yield(server)
37
38
 
38
- topic = TorqueBox::Messaging::Topic.new("my_topic")
39
- topic.name.should eql("my_topic")
40
- topic.send method
41
- topic.destroy
42
- end
39
+ topic = TorqueBox::Messaging::Topic.start( "my_topic" )
40
+ topic.name.should == "my_topic"
41
+ topic.stop
42
+
43
+ Mockito.verify(server).createTopic(Matchers.anyBoolean,
44
+ Matchers.eq("my_topic"))
43
45
 
46
+ Mockito.verify(server).destroyTopic("my_topic")
44
47
  end
45
48
 
46
49
  describe "publish" do
47
50
  before(:each) do
48
51
  @session = mock('session')
49
52
  @session.stub(:transacted?).and_return(false)
50
- TorqueBox::Messaging::Client.stub(:connect).and_yield(@session)
51
53
  @queue = TorqueBox::Messaging::Queue.new('foo')
54
+ @queue.stub(:with_session).and_yield(@session)
52
55
  end
53
56
 
54
57
  context "normalizing options" do
@@ -94,294 +97,4 @@ describe TorqueBox::Messaging::Destination do
94
97
  end
95
98
  end
96
99
 
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.decode.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.decode.should == 'ahoyhoy'
157
- queue.detect { |m| m.decode == 'howdy' }.should be_nil
158
- queue.detect { |m| m.decode == 'ahoyhoy' }.should_not be_nil
159
- queue.destroy
160
-
161
- end
162
- end
163
-
164
- describe "sending and receiving" do
165
- before(:each) do
166
- @container = TorqueBox::Container::Foundation.new
167
- @container.enable( TorqueBox::Naming::NamingService ) {|config| config.export=false}
168
- @container.enable( TorqueBox::Messaging::MessageBroker )
169
- @container.start
170
- end
171
-
172
- after(:each) do
173
- @container.stop
174
- end
175
-
176
- it "should be able to publish to and receive from a queue" do
177
- queue = TorqueBox::Messaging::Queue.new "/queues/foo"
178
- queue.start
179
-
180
- queue.publish "howdy"
181
- message = queue.receive
182
-
183
- queue.destroy
184
- message.should eql( "howdy" )
185
- end
186
-
187
- it "should receive a binary file correctly" do
188
- queue = TorqueBox::Messaging::Queue.new "/queues/foo"
189
- queue.start
190
-
191
- data = File.open("#{File.dirname(__FILE__)}/../src/test/resources/sample.pdf", "r") { |file| file.read }
192
- queue.publish data
193
- message = queue.receive
194
-
195
- queue.destroy
196
- message.should eql( data )
197
- end
198
-
199
- it "should publish to multiple topic consumers" do
200
- topic = TorqueBox::Messaging::Topic.new "/topics/foo"
201
- topic.start
202
- threads, count = [], 10
203
-
204
- # Use a threadsafe "array"
205
- msgs = java.util.Collections.synchronizedList( [] )
206
-
207
- # Ensure all clients are blocking on the receipt of a message
208
- count.times { threads << Thread.new { msgs << topic.receive } }
209
- sleep(1)
210
- topic.publish "howdy"
211
- threads.each {|t| t.join}
212
-
213
- topic.destroy
214
- msgs.to_a.should eql( ["howdy"] * count )
215
- end
216
-
217
- context "durable topics" do
218
- describe 'receive' do
219
- it "should be durable" do
220
- topic = TorqueBox::Messaging::Topic.new "/topics/foo", :client_id => 'blarg'
221
- topic.start
222
-
223
- topic.receive :durable => true, :timeout => 1
224
- topic.publish 'biscuit'
225
- response = topic.receive :durable => true, :timeout => 10_000
226
- response.should == 'biscuit'
227
-
228
- topic.destroy
229
- end
230
-
231
- it "should raise if client_id is not set" do
232
- topic = TorqueBox::Messaging::Topic.new "/topics/foo"
233
- topic.start
234
-
235
- lambda { topic.receive :durable => true, :timeout => 1 }.should raise_error(ArgumentError)
236
-
237
- topic.destroy
238
- end
239
- end
240
-
241
- describe 'unsubscribe' do
242
- it "should work" do
243
- topic = TorqueBox::Messaging::Topic.new "/topics/foo", :client_id => 'blarg'
244
- topic.start
245
-
246
- topic.receive :durable => true, :timeout => 1
247
- topic.publish 'biscuit'
248
- response = topic.receive :durable => true, :timeout => 10_000
249
- response.should == 'biscuit'
250
-
251
- topic.unsubscribe
252
-
253
- topic.publish 'ham'
254
- response = topic.receive :durable => true, :timeout => 10
255
- response.should be_nil
256
-
257
- topic.publish 'gravy'
258
- response = topic.receive :durable => true, :timeout => 10_000
259
- response.should == 'gravy'
260
-
261
- topic.destroy
262
-
263
- end
264
- end
265
- end
266
-
267
- context "synchronous messaging" do
268
- it "should return value of block given to receive_and_publish" do
269
- queue = TorqueBox::Messaging::Queue.new "/queues/publish_and_receive"
270
- queue.start
271
-
272
- response_thread = Thread.new {
273
- queue.receive_and_publish( :timeout => 120_000 ) { |msg| msg.upcase }
274
- }
275
- message = queue.publish_and_receive "ping", :timeout => 120_000
276
- response_thread.join
277
-
278
- queue.destroy
279
- message.should eql( "PING" )
280
- end
281
-
282
- it "should return request message if no block given" do
283
- queue = TorqueBox::Messaging::Queue.new "/queues/publish_and_receive"
284
- queue.start
285
-
286
- response_thread = Thread.new {
287
- queue.receive_and_publish( :timeout => 120_000 )
288
- }
289
- message = queue.publish_and_receive "ping", :timeout => 120_000
290
- response_thread.join
291
-
292
- queue.destroy
293
- message.should eql( "ping" )
294
- end
295
-
296
- it "should not mess up with multiple consumers" do
297
- queue = TorqueBox::Messaging::Queue.new "/queues/publish_and_receive"
298
- queue.start
299
-
300
- thread_count = 3
301
- response_threads = (1..thread_count).map do
302
- Thread.new {
303
- queue.receive_and_publish( :timeout => 120_000 ) { |msg| msg.upcase }
304
- }
305
- end
306
-
307
- message = queue.publish_and_receive "ping", :timeout => 120_000
308
- # Send extra messages to trigger all remaining response threads
309
- (thread_count - 1).times do
310
- queue.publish_and_receive "ping", :timeout => 120_000
311
- end
312
- response_threads.each { |thread| thread.join }
313
-
314
- queue.destroy
315
- message.should eql( "PING" )
316
- end
317
-
318
- it "should allow a selector to be passed" do
319
- queue = TorqueBox::Messaging::Queue.new "/queues/publish_and_receive"
320
- queue.start
321
-
322
- response_thread = Thread.new {
323
- queue.receive_and_publish( :timeout => 120_000,
324
- :selector => "age > 60 or tan = true" )
325
- }
326
-
327
- # Publish a non-synchronous message that should not match selector
328
- queue.publish( "young and tan", :properties => { :age => 25, :tan => true } )
329
- # Publish a synchronous message that should not match selector
330
- queue.publish_and_receive( "young",
331
- :timeout => 25,
332
- :properties => { :age => 25 } )
333
- # Publish a synchronous message that should match selector
334
- message = queue.publish_and_receive( "wrinkled",
335
- :timeout => 120_000,
336
- :properties => { :age => 65, :tan => true } )
337
- message.should eql( "wrinkled" )
338
- response_thread.join
339
-
340
- # Drain any remaining messages off the queue
341
- 2.times { queue.receive(:timeout => 10) }
342
-
343
- queue.destroy
344
- end
345
- end
346
-
347
- context "destination not ready" do
348
- it "should block on publish until queue is ready" do
349
- queue = TorqueBox::Messaging::Queue.new "/queues/not_ready"
350
- # Start the queue in a separate thread after a delay
351
- setup_thread = Thread.new {
352
- sleep( 0.2 )
353
- queue.start
354
- }
355
- # The queue will not be ready when we call the publish method
356
- queue.publish "something"
357
- message = queue.receive
358
-
359
- setup_thread.join
360
- queue.destroy
361
- message.should eql( "something" )
362
- end
363
-
364
- it "should block on receive until topic is ready" do
365
- topic = TorqueBox::Messaging::Topic.new "/topics/not_ready"
366
- # Start the topic in a separate thread after a delay
367
- setup_thread = Thread.new {
368
- topic.start
369
- }
370
- # The topic will not be ready when we call the receive method
371
- message = topic.receive :timeout => 200
372
-
373
- setup_thread.join
374
- topic.destroy
375
- message.should be_nil
376
- end
377
-
378
- it "should block until startup_timeout reached" do
379
- queue = TorqueBox::Messaging::Queue.new "/queues/not_ready"
380
- lambda {
381
- queue.publish "something", :startup_timeout => 200
382
- }.should raise_error(javax.naming.NameNotFoundException)
383
- end
384
- end
385
- end
386
-
387
100
  end