qpid_messaging 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/LICENSE +234 -0
  2. data/README.rdoc +46 -0
  3. data/Rakefile +87 -0
  4. data/TODO +7 -0
  5. data/examples/client.rb +50 -0
  6. data/examples/drain.rb +111 -0
  7. data/examples/hello_world.rb +49 -0
  8. data/examples/map_receiver.rb +63 -0
  9. data/examples/map_sender.rb +52 -0
  10. data/examples/server.rb +51 -0
  11. data/examples/spout.rb +126 -0
  12. data/ext/cqpid/cqpid.cpp +9903 -0
  13. data/ext/cqpid/extconf.rb +73 -0
  14. data/features/closing_a_connection.feature +13 -0
  15. data/features/closing_a_session.feature +13 -0
  16. data/features/connecting_to_a_broker.feature +13 -0
  17. data/features/creating_a_receiver.feature +29 -0
  18. data/features/creating_a_sender.feature +25 -0
  19. data/features/creating_a_session.feature +12 -0
  20. data/features/getting_the_connections_authenticated_username.feature +8 -0
  21. data/features/receiving_a_message.feature +28 -0
  22. data/features/sending_a_message.feature +21 -0
  23. data/features/session_returns_its_connection.feature +12 -0
  24. data/features/sessions_have_names.feature +8 -0
  25. data/features/step_definitions/address_steps.rb +24 -0
  26. data/features/step_definitions/connection_steps.rb +93 -0
  27. data/features/step_definitions/receiver_steps.rb +61 -0
  28. data/features/step_definitions/sender_steps.rb +34 -0
  29. data/features/step_definitions/session_steps.rb +99 -0
  30. data/features/support/env.rb +22 -0
  31. data/lib/qpid_messaging.rb +30 -0
  32. data/lib/qpid_messaging/address.rb +187 -0
  33. data/lib/qpid_messaging/connection.rb +162 -0
  34. data/lib/qpid_messaging/duration.rb +95 -0
  35. data/lib/qpid_messaging/encoding.rb +61 -0
  36. data/lib/qpid_messaging/errors.rb +33 -0
  37. data/lib/qpid_messaging/message.rb +368 -0
  38. data/lib/qpid_messaging/receiver.rb +184 -0
  39. data/lib/qpid_messaging/sender.rb +152 -0
  40. data/lib/qpid_messaging/session.rb +269 -0
  41. data/lib/qpid_messaging/version.rb +33 -0
  42. data/spec/qpid/address_spec.rb +87 -0
  43. data/spec/qpid/connection_spec.rb +191 -0
  44. data/spec/qpid/duration_spec.rb +56 -0
  45. data/spec/qpid/encoding_spec.rb +63 -0
  46. data/spec/qpid/message_spec.rb +292 -0
  47. data/spec/qpid/receiver_spec.rb +170 -0
  48. data/spec/qpid/sender_spec.rb +135 -0
  49. data/spec/qpid/session_spec.rb +353 -0
  50. data/spec/spec_helper.rb +20 -0
  51. metadata +106 -0
@@ -0,0 +1,170 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ #
19
+
20
+ require 'spec_helper'
21
+
22
+ module Qpid
23
+
24
+ module Messaging
25
+
26
+ describe Receiver do
27
+
28
+ before(:each) do
29
+ @message_impl = double("Cqpid::Message")
30
+ @session = double("Qpid::Messaging::Session")
31
+ @receiver_impl = double("Cqpid::Receiver")
32
+
33
+ @receiver = Qpid::Messaging::Receiver.new @session, @receiver_impl
34
+ end
35
+
36
+ it "returns the underlying implementation" do
37
+ impl = @receiver.receiver_impl
38
+
39
+ impl.should == @receiver_impl
40
+ end
41
+
42
+ it "gets a message with the default duration" do
43
+ @receiver_impl.should_receive(:get).
44
+ with(Qpid::Messaging::Duration::FOREVER.duration_impl).
45
+ and_return(@message_impl)
46
+
47
+ message = @receiver.get
48
+
49
+ message.message_impl.should == @message_impl
50
+ end
51
+
52
+ it "gets a message with a specified duration" do
53
+ @receiver_impl.should_receive(:get).
54
+ with(Qpid::Messaging::Duration::SECOND.duration_impl).
55
+ and_return(@message_impl)
56
+
57
+ message = @receiver.get Qpid::Messaging::Duration::SECOND
58
+
59
+ message.message_impl.should == @message_impl
60
+ end
61
+
62
+ it "returns nil when get receives no message" do
63
+ @receiver_impl.should_receive(:get).
64
+ with(Qpid::Messaging::Duration::MINUTE.duration_impl).
65
+ and_return(nil)
66
+
67
+ message = @receiver.get Qpid::Messaging::Duration::MINUTE
68
+
69
+ message.should be_nil
70
+ end
71
+
72
+ it "fetches a message with the default duration" do
73
+ @receiver_impl.should_receive(:fetch).
74
+ with(Qpid::Messaging::Duration::FOREVER.duration_impl).
75
+ and_return(@message_impl)
76
+
77
+ message = @receiver.fetch
78
+
79
+ message.message_impl.should == @message_impl
80
+ end
81
+
82
+ it "fetches a message with a specified duration" do
83
+ @receiver_impl.should_receive(:fetch).
84
+ with(Qpid::Messaging::Duration::SECOND.duration_impl).
85
+ and_return(@message_impl)
86
+
87
+ message = @receiver.fetch Qpid::Messaging::Duration::SECOND
88
+
89
+ message.message_impl.should == @message_impl
90
+ end
91
+
92
+ it "returns nil when fetch recieves no message" do
93
+ @receiver_impl.should_receive(:fetch).
94
+ with(Qpid::Messaging::Duration::MINUTE.duration_impl).
95
+ and_return(nil)
96
+
97
+ message = @receiver.fetch Qpid::Messaging::Duration::MINUTE
98
+
99
+ message.should be_nil
100
+ end
101
+
102
+ it "assigns capacity" do
103
+ @receiver_impl.should_receive(:setCapacity).
104
+ with(10)
105
+
106
+ @receiver.capacity = 10
107
+ end
108
+
109
+ it "returns the capacity" do
110
+ @receiver_impl.should_receive(:getCapacity).
111
+ and_return(10)
112
+
113
+ capacity = @receiver.capacity
114
+
115
+ capacity.should == 10
116
+ end
117
+
118
+ it "reports the number of available messages" do
119
+ @receiver_impl.should_receive(:getAvailable).
120
+ and_return(20)
121
+
122
+ available = @receiver.available
123
+
124
+ available.should == 20
125
+ end
126
+
127
+ it "reports the number of unsettled messages" do
128
+ @receiver_impl.should_receive(:getUnsettled).
129
+ and_return(25)
130
+
131
+ unsettled = @receiver.unsettled
132
+
133
+ unsettled.should == 25
134
+ end
135
+
136
+ it "closes" do
137
+ @receiver_impl.should_receive(:close)
138
+
139
+ @receiver.close
140
+ end
141
+
142
+ it "reports its closed status" do
143
+ @receiver_impl.should_receive(:isClosed).
144
+ and_return(true)
145
+
146
+ closed = @receiver.closed?
147
+
148
+ closed.should == true
149
+ end
150
+
151
+ it "returns its name" do
152
+ @receiver_impl.should_receive(:getName).
153
+ and_return("farkle")
154
+
155
+ name = @receiver.name
156
+
157
+ name.should == "farkle"
158
+ end
159
+
160
+ it "returns its related session" do
161
+ session = @receiver.session
162
+
163
+ session.should == @session
164
+ end
165
+
166
+ end
167
+
168
+ end
169
+
170
+ end
@@ -0,0 +1,135 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ #
19
+
20
+ require 'spec_helper'
21
+
22
+ module Qpid
23
+
24
+ module Messaging
25
+
26
+ describe Sender do
27
+
28
+ before(:each) do
29
+ @message = double("Qpid::Messaging::Message")
30
+ @message_impl = double("Cqpid::Message")
31
+ @sender_impl = double("Cqpid::Sender")
32
+ @session = double("Qpid::Messaging::Session")
33
+
34
+ @sender = Qpid::Messaging::Sender.new @session, @sender_impl
35
+ end
36
+
37
+ it "returns its implementation" do
38
+ impl = @sender.sender_impl
39
+
40
+ impl.should == @sender_impl
41
+ end
42
+
43
+ it "sends a message" do
44
+ @message.should_receive(:message_impl).
45
+ and_return(@message_impl)
46
+ @sender_impl.should_receive(:send).
47
+ with(@message_impl, false)
48
+
49
+ @sender.send @message
50
+ end
51
+
52
+ it "sends a message with optional synch" do
53
+ @message.should_receive(:message_impl).
54
+ and_return(@message_impl)
55
+ @sender_impl.should_receive(:send).
56
+ with(@message_impl, true)
57
+
58
+ @sender.send @message, :sync => true
59
+ end
60
+
61
+ it "sends a message with an optional block" do
62
+ block_called = false
63
+
64
+ @message.should_receive(:message_impl).
65
+ and_return(@message_impl)
66
+ @sender_impl.should_receive(:send).
67
+ with(@message_impl, false)
68
+
69
+ @sender.send @message do |message|
70
+ block_called = true if message == @message
71
+ end
72
+
73
+ block_called.should be_true
74
+ end
75
+
76
+ it "closes" do
77
+ @sender_impl.should_receive(:close)
78
+
79
+ @sender.close
80
+ end
81
+
82
+ it "returns its name" do
83
+ @sender_impl.should_receive(:getName).
84
+ and_return("farkle")
85
+
86
+ name = @sender.name
87
+
88
+ name.should == "farkle"
89
+ end
90
+
91
+ it "sets its capacity" do
92
+ @sender_impl.should_receive(:setCapacity).
93
+ with(100)
94
+
95
+ @sender.capacity = 100
96
+ end
97
+
98
+ it "returns its capacity" do
99
+ @sender_impl.should_receive(:getCapacity).
100
+ and_return(25)
101
+
102
+ capacity = @sender.capacity
103
+
104
+ capacity.should == 25
105
+ end
106
+
107
+ it "returns the number of unsettled messages" do
108
+ @sender_impl.should_receive(:getUnsettled).
109
+ and_return(15)
110
+
111
+ unsettled = @sender.unsettled
112
+
113
+ unsettled.should == 15
114
+ end
115
+
116
+ it "returns the number of available message slots" do
117
+ @sender_impl.should_receive(:getAvailable).
118
+ and_return(50)
119
+
120
+ available = @sender.available
121
+
122
+ available.should == 50
123
+ end
124
+
125
+ it "returns a reference to its session" do
126
+ session = @sender.session
127
+
128
+ session.should == @session
129
+ end
130
+
131
+ end
132
+
133
+ end
134
+
135
+ end
@@ -0,0 +1,353 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ #
19
+
20
+ require 'spec_helper'
21
+
22
+ module Qpid
23
+
24
+ module Messaging
25
+
26
+ describe Session do
27
+
28
+ before(:each) do
29
+ @connection = double("Qpid::Messaging::Connection")
30
+ @session_impl = double("Cqpid::Session")
31
+ @session = Qpid::Messaging::Session.new @connection, @session_impl
32
+ @sender_impl = double("Cqpid::Sender")
33
+ @receiver_impl = double("Cqpid::Receiver")
34
+ end
35
+
36
+ it "returns its implementation" do
37
+ impl = @session.session_impl
38
+
39
+ impl.should == @session_impl
40
+ end
41
+
42
+ it "returns its connection" do
43
+ connection = @session.connection
44
+
45
+ connection.should == @connection
46
+ end
47
+
48
+ it "creates a Sender from an Address" do
49
+ address = Qpid::Messaging::Address.new "my-queu", "", :create => :always
50
+
51
+ @session_impl.should_receive(:createSender).
52
+ with(address.address_impl).
53
+ and_return(@sender_impl)
54
+ @sender_impl.should_receive(:getName).
55
+ and_return("my-queue")
56
+
57
+ sender = @session.create_sender address
58
+
59
+ sender.sender_impl.should == @sender_impl
60
+ end
61
+
62
+ it "creates a Sender from an address string" do
63
+ address = "my-queue;{create:true}"
64
+
65
+ @session_impl.should_receive(:createSender).
66
+ with(address).
67
+ and_return(@sender_impl)
68
+ @sender_impl.should_receive(:getName).
69
+ and_return("my-queue")
70
+
71
+ sender = @session.create_sender address
72
+
73
+ sender.sender_impl.should == @sender_impl
74
+ end
75
+
76
+ #######################################
77
+ # scenarios involing an existing Sender
78
+ #######################################
79
+ describe "when retrieving a Sender by name" do
80
+
81
+ before(:each) do
82
+ address = "my-queue;{create:always}"
83
+ @name = "my-queue"
84
+
85
+ @session_impl.should_receive(:createSender).
86
+ with(address).
87
+ and_return(@sender_impl)
88
+ @sender_impl.should_receive(:getName).
89
+ and_return(@name)
90
+
91
+ @sender = @session.create_sender address
92
+ end
93
+
94
+ it "works when the name is valid" do
95
+ sender = @session.sender @name
96
+
97
+ sender.should == @sender
98
+ end
99
+
100
+ it "raises an error when the name is invalid" do
101
+ expect {
102
+ @session.sender @name.reverse
103
+ }.to raise_error(Qpid::Messaging::KeyError)
104
+ end
105
+
106
+ end
107
+
108
+ it "creates a Receiver from an Address" do
109
+ address = Qpid::Messaging::Address.new "my-queue", ""
110
+
111
+ @session_impl.should_receive(:createReceiver).
112
+ with(address.address_impl).
113
+ and_return(@receiver_impl)
114
+ @receiver_impl.should_receive(:getName).
115
+ and_return("my-queue")
116
+
117
+ receiver = @session.create_receiver address
118
+
119
+ receiver.receiver_impl.should == @receiver_impl
120
+ end
121
+
122
+ it "creates a Receiver from an address string" do
123
+ address = "my-queue"
124
+
125
+ @session_impl.should_receive(:createReceiver).
126
+ with(address).
127
+ and_return(@receiver_impl)
128
+ @receiver_impl.should_receive(:getName).
129
+ and_return("my-queue")
130
+
131
+ receiver = @session.create_receiver address
132
+
133
+ receiver.receiver_impl.should == @receiver_impl
134
+ end
135
+
136
+ #########################################
137
+ # scenarios involving an existing Receiver
138
+ ##########################################
139
+ describe "when retrieving a Receiver by name" do
140
+
141
+ before(:each) do
142
+ address = "my-queue"
143
+ @name = "my-queue"
144
+
145
+ @session_impl.should_receive(:createReceiver).
146
+ with(address).
147
+ and_return(@receiver_impl)
148
+ @receiver_impl.should_receive(:getName).
149
+ and_return(@name)
150
+
151
+ @receiver = @session.create_receiver address
152
+ end
153
+
154
+ it "works with a valid name" do
155
+ receiver = @session.receiver @name
156
+
157
+ receiver.should == @receiver
158
+ end
159
+
160
+ it "raises an error when the name is invalid" do
161
+ expect {
162
+ @session.receiver @name.reverse
163
+ }.to raise_error(Qpid::Messaging::KeyError)
164
+ end
165
+
166
+ end
167
+
168
+ it "closes the session" do
169
+ @session_impl.should_receive(:close)
170
+
171
+ @session.close
172
+ end
173
+
174
+ it "commits a pending transaction" do
175
+ @session_impl.should_receive(:commit)
176
+
177
+ @session.commit
178
+ end
179
+
180
+ it "rolls back an uncommitted transaction" do
181
+ @session_impl.should_receive(:rollback)
182
+
183
+ @session.rollback
184
+ end
185
+
186
+ it "acknowledges all received messages" do
187
+ @session_impl.should_receive(:acknowledge).
188
+ with(false)
189
+
190
+ @session.acknowledge
191
+ end
192
+
193
+ it "acknowledges all messages synchronously" do
194
+ @session_impl.should_receive(:acknowledge).
195
+ with(true)
196
+
197
+ @session.acknowledge :sync => true
198
+ end
199
+
200
+ it "acknowledges all messages asynchronously" do
201
+ @session_impl.should_receive(:acknowledge).
202
+ with(false)
203
+
204
+ @session.acknowledge :sync => false
205
+ end
206
+
207
+ ######################################
208
+ # Scenarios involving a single message
209
+ ######################################
210
+ describe "with a single message" do
211
+
212
+ before(:each) do
213
+ @message = Qpid::Messaging::Message.new :content => "Testing"
214
+ end
215
+
216
+ it "can acknowledge asynchronously by default" do
217
+ @session_impl.should_receive(:acknowledge).
218
+ with(@message.message_impl, false)
219
+
220
+ @session.acknowledge :message => @message
221
+ end
222
+
223
+ it "can acknowledge synchronously" do
224
+ @session_impl.should_receive(:acknowledge).
225
+ with(@message.message_impl, true)
226
+
227
+ @session.acknowledge :message => @message, :sync => true
228
+ end
229
+
230
+ it "can acknowledge asynchronously" do
231
+ @session_impl.should_receive(:acknowledge).
232
+ with(@message.message_impl, false)
233
+
234
+ @session.acknowledge :message => @message, :sync => false
235
+ end
236
+
237
+ it "can reject it" do
238
+ @session_impl.should_receive(:reject).
239
+ with(@message.message_impl)
240
+
241
+ @session.reject @message
242
+ end
243
+
244
+ it "can release it" do
245
+ @session_impl.should_receive(:release).
246
+ with(@message.message_impl)
247
+
248
+ @session.release @message
249
+ end
250
+
251
+ end
252
+
253
+ it "does not block by default when synchronizating with the broker" do
254
+ @session_impl.should_receive(:sync).
255
+ with(false)
256
+
257
+ @session.sync
258
+ end
259
+
260
+ it "can block while synchronizing with the broker" do
261
+ @session_impl.should_receive(:sync).
262
+ with(true)
263
+
264
+ @session.sync :block => true
265
+ end
266
+
267
+ it "can not block while synchronizing with the broker" do
268
+ @session_impl.should_receive(:sync).
269
+ with(false)
270
+
271
+ @session.sync :block => false
272
+ end
273
+
274
+ it "returns the number of messages that are receivable" do
275
+ @session_impl.should_receive(:getReceivable).
276
+ and_return(15)
277
+
278
+ receivable = @session.receivable
279
+
280
+ receivable.should == 15
281
+ end
282
+
283
+ it "returns the number of unsettled messages" do
284
+ @session_impl.should_receive(:getUnsettledAcks).
285
+ and_return(25)
286
+
287
+ unsettled = @session.unsettled_acks
288
+
289
+ unsettled.should == 25
290
+ end
291
+
292
+ it "waits forever by default for the next Receiver with messages" do
293
+ @session_impl.should_receive(:nextReceiver).
294
+ with(Qpid::Messaging::Duration::FOREVER.duration_impl).
295
+ and_return(@receiver_impl)
296
+
297
+ receiver = @session.next_receiver
298
+
299
+ receiver.receiver_impl.should == @receiver_impl
300
+ end
301
+
302
+ it "uses the specified time when waiting for the next Receiver with messages" do
303
+ @session_impl.should_receive(:nextReceiver).
304
+ with(Qpid::Messaging::Duration::SECOND.duration_impl).
305
+ and_return(@receiver_impl)
306
+
307
+ receiver = @session.next_receiver Qpid::Messaging::Duration::SECOND
308
+
309
+ receiver.receiver_impl.should == @receiver_impl
310
+ end
311
+
312
+ it "returns nil when no Receiver has messages within the timeout period" do
313
+ @session_impl.should_receive(:nextReceiver).
314
+ with(Qpid::Messaging::Duration::MINUTE.duration_impl).
315
+ and_return(nil)
316
+
317
+ receiver = @session.next_receiver Qpid::Messaging::Duration::MINUTE
318
+
319
+ receiver.should be_nil
320
+ end
321
+
322
+ it "returns true when there are errors on the session" do
323
+ @session_impl.should_receive(:hasError).
324
+ and_return(true)
325
+
326
+ errors = @session.errors?
327
+
328
+ errors.should be_true
329
+ end
330
+
331
+ it "returns false when there are no errors on the session" do
332
+ @session_impl.should_receive(:hasError).
333
+ and_return(false)
334
+
335
+ errors = @session.errors?
336
+
337
+ errors.should be_false
338
+ end
339
+
340
+ it "causes exceptions to be raised when there are errors" do
341
+ @session_impl.should_receive(:checkError).
342
+ and_raise(RuntimeError)
343
+
344
+ expect {
345
+ @session.errors
346
+ }.to raise_error(RuntimeError)
347
+ end
348
+
349
+ end
350
+
351
+ end
352
+
353
+ end