nebulous_stomp 2.0.2 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.hgignore +2 -0
- data/.hgtags +1 -0
- data/README.md +225 -28
- data/feature/connection_example.yaml +24 -0
- data/feature/feature_test_spec.rb +247 -0
- data/feature/gimme.rb +91 -0
- data/lib/nebulous_stomp/listener.rb +107 -0
- data/lib/nebulous_stomp/message.rb +132 -265
- data/lib/nebulous_stomp/msg/body.rb +169 -0
- data/lib/nebulous_stomp/msg/header.rb +98 -0
- data/lib/nebulous_stomp/param.rb +16 -35
- data/lib/nebulous_stomp/redis_handler.rb +19 -29
- data/lib/nebulous_stomp/redis_handler_null.rb +12 -11
- data/lib/nebulous_stomp/redis_helper.rb +110 -0
- data/lib/nebulous_stomp/request.rb +212 -0
- data/lib/nebulous_stomp/stomp_handler.rb +30 -96
- data/lib/nebulous_stomp/stomp_handler_null.rb +8 -22
- data/lib/nebulous_stomp/target.rb +52 -0
- data/lib/nebulous_stomp/version.rb +1 -1
- data/lib/nebulous_stomp.rb +63 -50
- data/md/LICENSE.txt +20 -2
- data/md/nebulous_protocol.md +25 -18
- data/spec/listener_spec.rb +104 -0
- data/spec/message_spec.rb +227 -116
- data/spec/nebulous_spec.rb +44 -9
- data/spec/param_spec.rb +16 -33
- data/spec/redis_handler_null_spec.rb +0 -2
- data/spec/redis_handler_spec.rb +0 -2
- data/spec/redis_helper_spec.rb +107 -0
- data/spec/request_spec.rb +249 -0
- data/spec/stomp_handler_null_spec.rb +33 -34
- data/spec/stomp_handler_spec.rb +1 -74
- data/spec/target_spec.rb +97 -0
- metadata +20 -11
- data/lib/nebulous_stomp/nebrequest.rb +0 -259
- data/lib/nebulous_stomp/nebrequest_null.rb +0 -37
- data/spec/nebrequest_null_spec.rb +0 -219
- data/spec/nebrequest_spec.rb +0 -239
- data/spec/through_test_spec.rb +0 -80
data/spec/target_spec.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'nebulous_stomp/target'
|
2
|
+
|
3
|
+
include NebulousStomp
|
4
|
+
|
5
|
+
|
6
|
+
describe Target do
|
7
|
+
|
8
|
+
let(:hash) do
|
9
|
+
{ sendQueue: 'sendy',
|
10
|
+
receiveQueue: 'receivy',
|
11
|
+
messageTimeout: 42,
|
12
|
+
name: 'test' }
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
def hash_minus(key)
|
17
|
+
hash.delete_if{|k,_| k == key }
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
describe "#new" do
|
22
|
+
|
23
|
+
it "accepts a hash" do
|
24
|
+
expect{ Target.new }.to raise_error ArgumentError
|
25
|
+
expect{ Target.new 14 }.to raise_error ArgumentError
|
26
|
+
|
27
|
+
expect{ Target.new(name:'fred', sendQueue:'foo', receiveQueue:'bar') }.not_to raise_error
|
28
|
+
end
|
29
|
+
|
30
|
+
it "raises ArgumentError if the hash does not have :sendQueue" do
|
31
|
+
expect{ Target.new(hash_minus :sendQueue) }.to raise_error ArgumentError
|
32
|
+
end
|
33
|
+
|
34
|
+
it "raises ArgumentError if the hash does not have :receiveQueue" do
|
35
|
+
expect{ Target.new(hash_minus :receiveQueue) }.to raise_error ArgumentError
|
36
|
+
end
|
37
|
+
|
38
|
+
it "raises ArgumentError if the has does not have a :name" do
|
39
|
+
expect{ Target.new(hash_minus :name) }.to raise_error ArgumentError
|
40
|
+
end
|
41
|
+
|
42
|
+
it "accepts an optional :messageTimeout" do
|
43
|
+
expect{ Target.new hash }.not_to raise_error
|
44
|
+
expect{ Target.new(hash_minus :messageTimeout) }.not_to raise_error
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
it "rejects unknown values in the hash" do
|
49
|
+
h = hash.merge(:notavalidthing => 14)
|
50
|
+
expect { Target.new h }.to raise_error ArgumentError
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
describe "#send_queue" do
|
57
|
+
|
58
|
+
it "returns the send queue" do
|
59
|
+
expect( Target.new(hash).send_queue ).to eq hash[:sendQueue]
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
describe "#receive_queue" do
|
66
|
+
|
67
|
+
it "returns the receive queue" do
|
68
|
+
expect( Target.new(hash).receive_queue ).to eq hash[:receiveQueue]
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
describe "#message_timeout" do
|
75
|
+
|
76
|
+
it "returns the timeout" do
|
77
|
+
expect( Target.new(hash).message_timeout ).to eq hash[:messageTimeout]
|
78
|
+
end
|
79
|
+
|
80
|
+
it "defaults the message timeout to nil" do
|
81
|
+
expect( Target.new(hash_minus :messageTimeout).message_timeout ).to be_nil
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
describe "#name" do
|
88
|
+
|
89
|
+
it "returns the name" do
|
90
|
+
expect( Target.new(hash).name ).to eq hash[:name]
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
end
|
97
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nebulous_stomp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Jones
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -174,32 +174,40 @@ files:
|
|
174
174
|
- Guardfile
|
175
175
|
- README.md
|
176
176
|
- Rakefile
|
177
|
+
- feature/connection_example.yaml
|
178
|
+
- feature/feature_test_spec.rb
|
179
|
+
- feature/gimme.rb
|
177
180
|
- lib/nebulous_stomp.rb
|
181
|
+
- lib/nebulous_stomp/listener.rb
|
178
182
|
- lib/nebulous_stomp/message.rb
|
179
|
-
- lib/nebulous_stomp/
|
180
|
-
- lib/nebulous_stomp/
|
183
|
+
- lib/nebulous_stomp/msg/body.rb
|
184
|
+
- lib/nebulous_stomp/msg/header.rb
|
181
185
|
- lib/nebulous_stomp/param.rb
|
182
186
|
- lib/nebulous_stomp/redis_handler.rb
|
183
187
|
- lib/nebulous_stomp/redis_handler_null.rb
|
188
|
+
- lib/nebulous_stomp/redis_helper.rb
|
189
|
+
- lib/nebulous_stomp/request.rb
|
184
190
|
- lib/nebulous_stomp/stomp_handler.rb
|
185
191
|
- lib/nebulous_stomp/stomp_handler_null.rb
|
192
|
+
- lib/nebulous_stomp/target.rb
|
186
193
|
- lib/nebulous_stomp/version.rb
|
187
194
|
- md/LICENSE.txt
|
188
195
|
- md/nebulous_protocol.md
|
189
196
|
- nebulous.gemspec
|
190
197
|
- spec/doc_no_pending.rb
|
191
198
|
- spec/helpers.rb
|
199
|
+
- spec/listener_spec.rb
|
192
200
|
- spec/message_spec.rb
|
193
|
-
- spec/nebrequest_null_spec.rb
|
194
|
-
- spec/nebrequest_spec.rb
|
195
201
|
- spec/nebulous_spec.rb
|
196
202
|
- spec/param_spec.rb
|
197
203
|
- spec/redis_handler_null_spec.rb
|
198
204
|
- spec/redis_handler_spec.rb
|
205
|
+
- spec/redis_helper_spec.rb
|
206
|
+
- spec/request_spec.rb
|
199
207
|
- spec/spec_helper.rb
|
200
208
|
- spec/stomp_handler_null_spec.rb
|
201
209
|
- spec/stomp_handler_spec.rb
|
202
|
-
- spec/
|
210
|
+
- spec/target_spec.rb
|
203
211
|
- tags
|
204
212
|
homepage: https://bitbucket.org/andy-twosticks/nebulous_stomp
|
205
213
|
licenses:
|
@@ -225,22 +233,23 @@ requirements:
|
|
225
233
|
- STOMP Messaging server
|
226
234
|
- Redis server (optional)
|
227
235
|
rubyforge_project:
|
228
|
-
rubygems_version: 2.5.
|
236
|
+
rubygems_version: 2.5.2
|
229
237
|
signing_key:
|
230
238
|
specification_version: 4
|
231
239
|
summary: Handles request-and-response messaging via STOMP
|
232
240
|
test_files:
|
233
241
|
- spec/doc_no_pending.rb
|
234
242
|
- spec/helpers.rb
|
243
|
+
- spec/listener_spec.rb
|
235
244
|
- spec/message_spec.rb
|
236
|
-
- spec/nebrequest_null_spec.rb
|
237
|
-
- spec/nebrequest_spec.rb
|
238
245
|
- spec/nebulous_spec.rb
|
239
246
|
- spec/param_spec.rb
|
240
247
|
- spec/redis_handler_null_spec.rb
|
241
248
|
- spec/redis_handler_spec.rb
|
249
|
+
- spec/redis_helper_spec.rb
|
250
|
+
- spec/request_spec.rb
|
242
251
|
- spec/spec_helper.rb
|
243
252
|
- spec/stomp_handler_null_spec.rb
|
244
253
|
- spec/stomp_handler_spec.rb
|
245
|
-
- spec/
|
254
|
+
- spec/target_spec.rb
|
246
255
|
has_rdoc:
|
@@ -1,259 +0,0 @@
|
|
1
|
-
require_relative 'stomp_handler'
|
2
|
-
require_relative 'redis_handler'
|
3
|
-
require_relative 'message'
|
4
|
-
|
5
|
-
|
6
|
-
module NebulousStomp
|
7
|
-
|
8
|
-
|
9
|
-
##
|
10
|
-
# Class to handle a request which returns a Message
|
11
|
-
#
|
12
|
-
# Note that this has changed since 0.1.0. The principal difference is we
|
13
|
-
# return a Nebulous::Message; the NebResponse class no longer exists.
|
14
|
-
#
|
15
|
-
class NebRequest
|
16
|
-
|
17
|
-
|
18
|
-
# The target name as set up by call to Nebulous::add_target
|
19
|
-
attr_reader :target
|
20
|
-
|
21
|
-
# Message timeout in seconds
|
22
|
-
attr_reader :mTimeout
|
23
|
-
|
24
|
-
# Cache timeout (fade and forget) in seconds
|
25
|
-
attr_reader :cTimeout
|
26
|
-
|
27
|
-
# The message
|
28
|
-
attr_reader :message
|
29
|
-
|
30
|
-
# The STOMP queue to send the request to
|
31
|
-
attr_reader :requestQ
|
32
|
-
|
33
|
-
# The STOMP queue to listen for responses on
|
34
|
-
attr_reader :responseQ
|
35
|
-
|
36
|
-
|
37
|
-
##
|
38
|
-
# :call-seq:
|
39
|
-
# NebRequest.new(target, verb)
|
40
|
-
# NebRequest.new(target, verb, params)
|
41
|
-
# NebRequest.new(target, verb, params, desc)
|
42
|
-
#
|
43
|
-
# Create a new request. Raises Nebulous::NebulousError if anything goes
|
44
|
-
# wrong.
|
45
|
-
#
|
46
|
-
# Parameters:
|
47
|
-
# target [Symbol] the target name to send the request to
|
48
|
-
# verb [String] the 'verb' part of the message
|
49
|
-
# params [String] the 'parameters' part of the message
|
50
|
-
# desc [String] the 'description' part of the message
|
51
|
-
# stompHandler ONLY FOR TESTING
|
52
|
-
# redisHandler ONLY FOR TESTING
|
53
|
-
#
|
54
|
-
def initialize( target,
|
55
|
-
verb,
|
56
|
-
params=nil,
|
57
|
-
desc=nil,
|
58
|
-
stompHandler=nil,
|
59
|
-
redisHandler=nil )
|
60
|
-
|
61
|
-
NebulousStomp.logger.debug(__FILE__) {"New NebRequest for verb #{verb}"}
|
62
|
-
|
63
|
-
@target = target.to_s
|
64
|
-
@stomp_handler = stompHandler
|
65
|
-
@redis_handler = redisHandler
|
66
|
-
@requestQ = nil
|
67
|
-
@responseQ = nil
|
68
|
-
@message = nil
|
69
|
-
@mTimeout = 0
|
70
|
-
@cTimeout = 0
|
71
|
-
|
72
|
-
xverb = verb.to_s
|
73
|
-
xparams = params.nil? ? nil : params.to_s
|
74
|
-
xdesc = desc.nil? ? nil : desc.to_s
|
75
|
-
|
76
|
-
@redis_handler ||= RedisHandler.new( Param.get(:redisConnectHash) )
|
77
|
-
@stomp_handler ||= StompHandler.new( Param.get(:stompConnectHash) )
|
78
|
-
|
79
|
-
neb_setup if nebulous_on?
|
80
|
-
@message = Message.from_parts(@responseQ, nil, xverb, xparams, xdesc)
|
81
|
-
neb_connect if nebulous_on?
|
82
|
-
end
|
83
|
-
|
84
|
-
|
85
|
-
##
|
86
|
-
# :call-seq:
|
87
|
-
# request.send_no_cache -> (Message)
|
88
|
-
# request.send_no_cache(mTimeout) -> (Message)
|
89
|
-
#
|
90
|
-
# Send a request and return the response, without using the cache.
|
91
|
-
#
|
92
|
-
# Parameters:
|
93
|
-
# mTimeout [Fixnum] Message timout in seconds - defaults to @mTimeout
|
94
|
-
#
|
95
|
-
# Raises NebulousTimeout or NebulousError as necessary.
|
96
|
-
#
|
97
|
-
# Note that this routine completely ignores Redis. It doesn't just not
|
98
|
-
# check the cache; it also doesn't update it.
|
99
|
-
#
|
100
|
-
def send_no_cache(mTimeout=@mTimeout)
|
101
|
-
return nil unless nebulous_on?
|
102
|
-
|
103
|
-
# If we've lost the connection then reconnect but *keep replyID*
|
104
|
-
@stomp_handler.stomp_connect unless @stomp_handler.connected?
|
105
|
-
@message.reply_id = @stomp_handler.calc_reply_id if @message.reply_id.nil?
|
106
|
-
|
107
|
-
neb_qna(mTimeout)
|
108
|
-
|
109
|
-
ensure
|
110
|
-
@stomp_handler.stomp_disconnect if @stomp_handler
|
111
|
-
end
|
112
|
-
|
113
|
-
|
114
|
-
##
|
115
|
-
# ::call-seq::
|
116
|
-
# request.send -> (Message)
|
117
|
-
# request.send(mTimeout) -> (Message)
|
118
|
-
# request.send(mTimeout,cTimeout) -> (Message)
|
119
|
-
#
|
120
|
-
# As send_nocache, but without not using the cache :)
|
121
|
-
#
|
122
|
-
# Parameters:
|
123
|
-
# mTimeout [Fixnum] Message timout in seconds - defaults to @mTimeout
|
124
|
-
# cTimeout [Fixnum] Cache timout in seconds - defaults to @cTimeout
|
125
|
-
#
|
126
|
-
# Raises NebulousTimeout, NebulousError as necessary.
|
127
|
-
#
|
128
|
-
# We use Redis for the cache. This is possibly like using a sledgehammer
|
129
|
-
# to crack a nut, but it certainly makes things very simple.
|
130
|
-
#
|
131
|
-
def send(mTimeout=@mTimeout, cTimeout=@cTimeout)
|
132
|
-
return nil unless nebulous_on?
|
133
|
-
return send_no_cache(mTimeout) unless redis_on?
|
134
|
-
|
135
|
-
@redis_handler.connect unless @redis_handler.connected?
|
136
|
-
|
137
|
-
found = @redis_handler.get(@message.protocol_json)
|
138
|
-
return Message.from_cache(found) unless found.nil?
|
139
|
-
|
140
|
-
# No answer in Redis -- ask Nebulous
|
141
|
-
nebMess = send_no_cache(mTimeout)
|
142
|
-
@redis_handler.set(@message.protocol_json, nebMess.to_cache, ex: cTimeout)
|
143
|
-
|
144
|
-
nebMess
|
145
|
-
|
146
|
-
ensure
|
147
|
-
@redis_handler.quit if @redis_handler
|
148
|
-
end
|
149
|
-
|
150
|
-
|
151
|
-
##
|
152
|
-
# :call-seq:
|
153
|
-
# request.clear_cache -> self
|
154
|
-
#
|
155
|
-
# Clear the cache of responses to this request - just this request.
|
156
|
-
#
|
157
|
-
def clear_cache
|
158
|
-
return self unless redis_on?
|
159
|
-
@redis_handler.connect unless @redis_handler.connected?
|
160
|
-
@redis_handler.del(@message.protocol_json)
|
161
|
-
|
162
|
-
self
|
163
|
-
|
164
|
-
ensure
|
165
|
-
@redis_handler.quit if @redis_handler
|
166
|
-
end
|
167
|
-
|
168
|
-
|
169
|
-
##
|
170
|
-
# :call-seq:
|
171
|
-
# request.redis_on? -> (boolean)
|
172
|
-
#
|
173
|
-
# Return true if Redis is turned on in the *config*
|
174
|
-
#
|
175
|
-
# (If you want to know if we are conected to Redis, try
|
176
|
-
# `@redis_handler.connected?`)
|
177
|
-
#
|
178
|
-
def redis_on?
|
179
|
-
@redis_handler && @redis_handler.redis_on?
|
180
|
-
end
|
181
|
-
|
182
|
-
|
183
|
-
##
|
184
|
-
# :call-seq:
|
185
|
-
# request.nebulous_on? -> (boolean)
|
186
|
-
#
|
187
|
-
# Return true if Nebulous is turned on in the *config*
|
188
|
-
#
|
189
|
-
def nebulous_on?
|
190
|
-
@stomp_handler && @stomp_handler.nebulous_on?
|
191
|
-
end
|
192
|
-
|
193
|
-
|
194
|
-
#
|
195
|
-
# Some of our attributes are actually on Message
|
196
|
-
#
|
197
|
-
|
198
|
-
def verb; @message ? @message.verb : nil; end
|
199
|
-
def params; @message ? @message.params : nil; end
|
200
|
-
def desc; @message ? @message.desc : nil; end
|
201
|
-
def replyID; @message ? @message.reply_id : nil; end
|
202
|
-
|
203
|
-
|
204
|
-
private
|
205
|
-
|
206
|
-
|
207
|
-
##
|
208
|
-
# Connect to STOMP etc and do initial setup
|
209
|
-
#
|
210
|
-
def neb_setup
|
211
|
-
targetHash = Param.get_target(@target)
|
212
|
-
raise NebulousError, "Unknown target #{target}" if targetHash.nil?
|
213
|
-
|
214
|
-
@cTimeout = Param.get(:cacheTimeout)
|
215
|
-
@mTimeout = targetHash[:messageTimeout] || Param.get(:messageTimeout)
|
216
|
-
@requestQ = targetHash[:sendQueue]
|
217
|
-
@responseQ = targetHash[:receiveQueue]
|
218
|
-
|
219
|
-
self
|
220
|
-
end
|
221
|
-
|
222
|
-
|
223
|
-
# Called automatically by initialize, if Nebulous is 'on' in the config.
|
224
|
-
#
|
225
|
-
def neb_connect
|
226
|
-
@stomp_handler.stomp_connect
|
227
|
-
@message.reply_id = @stomp_handler.calc_reply_id
|
228
|
-
self
|
229
|
-
end
|
230
|
-
|
231
|
-
|
232
|
-
##
|
233
|
-
# Send a message via STOMP and wait for a response
|
234
|
-
#
|
235
|
-
# Note: this used to return a Stomp::Message, but now it returns a
|
236
|
-
# Nebulous::Message.
|
237
|
-
#
|
238
|
-
def neb_qna(mTimeout)
|
239
|
-
@stomp_handler.send_message(@requestQ, @message)
|
240
|
-
|
241
|
-
response = nil
|
242
|
-
@stomp_handler.listen_with_timeout(@responseQ, mTimeout) do |msg|
|
243
|
-
if replyID && msg.in_reply_to != replyID
|
244
|
-
false
|
245
|
-
else
|
246
|
-
response = msg
|
247
|
-
true
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
|
-
response
|
252
|
-
end
|
253
|
-
|
254
|
-
|
255
|
-
end # of NebRequest
|
256
|
-
|
257
|
-
|
258
|
-
end
|
259
|
-
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'nebulous_stomp'
|
2
|
-
|
3
|
-
require_relative 'nebrequest'
|
4
|
-
require_relative 'stomp_handler_null'
|
5
|
-
require_relative 'redis_handler_null'
|
6
|
-
|
7
|
-
|
8
|
-
module NebulousStomp
|
9
|
-
|
10
|
-
|
11
|
-
##
|
12
|
-
# Class to fake a NebRequest
|
13
|
-
#
|
14
|
-
class NebRequestNull < NebRequest
|
15
|
-
|
16
|
-
def initialize( target, verb, params=nil, desc=nil )
|
17
|
-
sh = StompHandlerNull.new( Param.get(:stompConnectHash) )
|
18
|
-
rh = RedisHandlerNull.new( Param.get(:redisConnectHash) )
|
19
|
-
super(target, verb, params, desc, sh, rh)
|
20
|
-
end
|
21
|
-
|
22
|
-
|
23
|
-
def insert_fake_stomp(message)
|
24
|
-
@stomp_handler.insert_fake(message)
|
25
|
-
end
|
26
|
-
|
27
|
-
|
28
|
-
def insert_fake_redis(key, value)
|
29
|
-
@redis_handler.insert_fake(key, value)
|
30
|
-
end
|
31
|
-
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
|
36
|
-
end
|
37
|
-
|
@@ -1,219 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
include NebulousStomp
|
4
|
-
|
5
|
-
require 'nebulous_stomp/nebrequest_null'
|
6
|
-
require 'nebulous_stomp/message'
|
7
|
-
|
8
|
-
|
9
|
-
describe NebRequestNull do
|
10
|
-
|
11
|
-
def new_request(target, verb, params=nil, desc=nil)
|
12
|
-
NebRequestNull.new(target, verb, params, desc)
|
13
|
-
end
|
14
|
-
|
15
|
-
def disable(thing)
|
16
|
-
NebulousStomp.init( :stompConnectHash => thing == :stomp ? {} : stomp_hash,
|
17
|
-
:redisConnectHash => thing == :redis ? {} : redis_hash,
|
18
|
-
:messageTimeout => 5,
|
19
|
-
:cacheTimeout => 20 )
|
20
|
-
|
21
|
-
NebulousStomp.add_target( :accord,
|
22
|
-
:sendQueue => "/queue/laplace.dev",
|
23
|
-
:receiveQueue => "/queue/laplace.out",
|
24
|
-
:messageTimeout => 1 )
|
25
|
-
end
|
26
|
-
|
27
|
-
let(:stomp_hash) do
|
28
|
-
{ hosts: [{ login: 'guest',
|
29
|
-
passcode: 'guest',
|
30
|
-
host: '10.0.0.150',
|
31
|
-
port: 61613,
|
32
|
-
ssl: false }],
|
33
|
-
reliable: false }
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
let(:redis_hash) { {host: '127.0.0.1', port: 6379, db: 0} }
|
38
|
-
|
39
|
-
|
40
|
-
before do
|
41
|
-
disable(:nothing)
|
42
|
-
end
|
43
|
-
|
44
|
-
|
45
|
-
describe "#initialize" do
|
46
|
-
|
47
|
-
it "raises an exception for a bad target" do
|
48
|
-
expect{ new_request('badtarget', 'foo') }.
|
49
|
-
to raise_exception(NebulousError)
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
it "takes the timeout on the target over the default" do
|
54
|
-
expect( new_request('accord', 'foo').mTimeout ).to eq(1)
|
55
|
-
end
|
56
|
-
|
57
|
-
it "falls back to the default if the timeout on the target is not set" do
|
58
|
-
NebulousStomp.add_target( :dracula,
|
59
|
-
:sendQueue => "/queue/laplace.dev",
|
60
|
-
:receiveQueue => "/queue/laplace.out" )
|
61
|
-
|
62
|
-
expect( new_request('dracula', 'foo').mTimeout ).to eq(5)
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'doesn''t freak out if Nebulous is not "on"' do
|
66
|
-
disable(:stomp)
|
67
|
-
expect{ NebRequestNull.new('accord', 'foo', nil, nil) }.
|
68
|
-
not_to raise_exception
|
69
|
-
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|
73
|
-
##
|
74
|
-
|
75
|
-
|
76
|
-
describe "#clear_cache" do
|
77
|
-
|
78
|
-
it 'returns self' do
|
79
|
-
r = new_request('accord', 'foo')
|
80
|
-
expect( r.clear_cache ).to eq r
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'doesn''t freak out if Redis is not connected' do
|
84
|
-
disable(:redis)
|
85
|
-
r = NebRequestNull.new( 'accord', 'foo', nil, nil)
|
86
|
-
|
87
|
-
expect{ r.clear_cache }.not_to raise_exception
|
88
|
-
expect( r.clear_cache ).to eq r
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|
92
|
-
##
|
93
|
-
|
94
|
-
|
95
|
-
describe "#send_no_cache" do
|
96
|
-
|
97
|
-
it "returns something from STOMP" do
|
98
|
-
req = new_request('accord', 'foo')
|
99
|
-
req.insert_fake_stomp( Message.from_parts(nil, req.replyID, 'foo', 'bar', 'baz') )
|
100
|
-
response = req.send_no_cache
|
101
|
-
|
102
|
-
expect( response ).to be_a NebulousStomp::Message
|
103
|
-
expect( response.verb ).to eq('foo')
|
104
|
-
end
|
105
|
-
|
106
|
-
it 'returns a nebulous timeout if there is no response' do
|
107
|
-
request = new_request('accord', 'foo')
|
108
|
-
expect{ request.send_no_cache }.
|
109
|
-
to raise_exception NebulousStomp::NebulousTimeout
|
110
|
-
|
111
|
-
end
|
112
|
-
|
113
|
-
it 'returns nil if Nebulous is disabled in the config' do
|
114
|
-
disable(:stomp)
|
115
|
-
r = new_request('accord', 'foo')
|
116
|
-
|
117
|
-
expect( r.send_no_cache ).to eq nil
|
118
|
-
end
|
119
|
-
|
120
|
-
end
|
121
|
-
##
|
122
|
-
|
123
|
-
|
124
|
-
describe "#send" do
|
125
|
-
|
126
|
-
it "returns a Message object from STOMP the first time" do
|
127
|
-
req = new_request('accord', 'foo')
|
128
|
-
req.insert_fake_stomp( Message.from_parts(nil, req.replyID, 'foo', 'bar', 'baz') )
|
129
|
-
|
130
|
-
response = req.send
|
131
|
-
expect( response ).to be_a NebulousStomp::Message
|
132
|
-
expect( response.verb ).to eq('foo')
|
133
|
-
end
|
134
|
-
|
135
|
-
it "returns the answer from the cache if there is one" do
|
136
|
-
req = new_request('accord', 'foo')
|
137
|
-
req.insert_fake_stomp( Message.from_parts(nil, req.replyID, 'foo', 'bar', 'baz') )
|
138
|
-
req.insert_fake_redis('xxx', {'verb' => 'frog'}.to_json)
|
139
|
-
response = req.send
|
140
|
-
|
141
|
-
expect( response ).to be_a NebulousStomp::Message
|
142
|
-
expect( response.verb ).to eq('frog')
|
143
|
-
end
|
144
|
-
|
145
|
-
it "allows you to specify a message timeout" do
|
146
|
-
req = new_request('accord', 'foo')
|
147
|
-
req.insert_fake_stomp( Message.from_parts(nil, req.replyID, 'foo', 'bar', 'baz') )
|
148
|
-
|
149
|
-
expect{ req.send(3) }.not_to raise_exception
|
150
|
-
end
|
151
|
-
|
152
|
-
it "allows you to specify a message timeout & cache timeout" do
|
153
|
-
req = new_request('accord', 'foo')
|
154
|
-
req.insert_fake_stomp( Message.from_parts(nil, req.replyID, 'foo', 'bar', 'baz') )
|
155
|
-
|
156
|
-
expect{ req.send(3, 120) }.not_to raise_exception
|
157
|
-
end
|
158
|
-
|
159
|
-
it 'returns a nebulous timeout if there is no response' do
|
160
|
-
req = new_request('accord', 'foo')
|
161
|
-
expect{ req.send }.to raise_exception NebulousStomp::NebulousTimeout
|
162
|
-
end
|
163
|
-
|
164
|
-
it 'still works if Redis is turned off in the config' do
|
165
|
-
disable(:redis)
|
166
|
-
r = new_request('accord', 'tom')
|
167
|
-
r.insert_fake_stomp( Message.from_parts(nil, r.replyID, 'foo', 'bar', 'baz') )
|
168
|
-
|
169
|
-
response = r.send
|
170
|
-
expect( response ).to be_a NebulousStomp::Message
|
171
|
-
expect( response.verb ).to eq('foo')
|
172
|
-
end
|
173
|
-
|
174
|
-
it 'returns nil if Nebulous is disabled in the config' do
|
175
|
-
disable(:stomp)
|
176
|
-
r = new_request('accord', 'foo')
|
177
|
-
|
178
|
-
expect( r.send ).to eq nil
|
179
|
-
end
|
180
|
-
|
181
|
-
end
|
182
|
-
##
|
183
|
-
|
184
|
-
|
185
|
-
describe '#redis_on?' do
|
186
|
-
|
187
|
-
it 'is true if there is a redis connection hash' do
|
188
|
-
request = new_request('accord', 'foo')
|
189
|
-
expect( request.redis_on? ).to be_truthy
|
190
|
-
end
|
191
|
-
|
192
|
-
it 'is false if there is no redis connection hash' do
|
193
|
-
disable(:redis)
|
194
|
-
r = new_request('accord', 'foo')
|
195
|
-
expect( r.redis_on? ).to be_falsy
|
196
|
-
end
|
197
|
-
|
198
|
-
end
|
199
|
-
##
|
200
|
-
|
201
|
-
|
202
|
-
describe '#nebulous_on?' do
|
203
|
-
|
204
|
-
it 'is true if there is a nebulous connection hash' do
|
205
|
-
r = new_request('accord', 'foo')
|
206
|
-
expect( r.nebulous_on? ).to be_truthy
|
207
|
-
end
|
208
|
-
|
209
|
-
it 'is false if there is no nebulous connection hash' do
|
210
|
-
disable(:stomp)
|
211
|
-
r = new_request('accord', 'foo')
|
212
|
-
expect( r.nebulous_on? ).to be_falsy
|
213
|
-
end
|
214
|
-
|
215
|
-
end
|
216
|
-
##
|
217
|
-
|
218
|
-
end # of NebRequestNull
|
219
|
-
|