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.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.hgignore +2 -0
  3. data/.hgtags +1 -0
  4. data/README.md +225 -28
  5. data/feature/connection_example.yaml +24 -0
  6. data/feature/feature_test_spec.rb +247 -0
  7. data/feature/gimme.rb +91 -0
  8. data/lib/nebulous_stomp/listener.rb +107 -0
  9. data/lib/nebulous_stomp/message.rb +132 -265
  10. data/lib/nebulous_stomp/msg/body.rb +169 -0
  11. data/lib/nebulous_stomp/msg/header.rb +98 -0
  12. data/lib/nebulous_stomp/param.rb +16 -35
  13. data/lib/nebulous_stomp/redis_handler.rb +19 -29
  14. data/lib/nebulous_stomp/redis_handler_null.rb +12 -11
  15. data/lib/nebulous_stomp/redis_helper.rb +110 -0
  16. data/lib/nebulous_stomp/request.rb +212 -0
  17. data/lib/nebulous_stomp/stomp_handler.rb +30 -96
  18. data/lib/nebulous_stomp/stomp_handler_null.rb +8 -22
  19. data/lib/nebulous_stomp/target.rb +52 -0
  20. data/lib/nebulous_stomp/version.rb +1 -1
  21. data/lib/nebulous_stomp.rb +63 -50
  22. data/md/LICENSE.txt +20 -2
  23. data/md/nebulous_protocol.md +25 -18
  24. data/spec/listener_spec.rb +104 -0
  25. data/spec/message_spec.rb +227 -116
  26. data/spec/nebulous_spec.rb +44 -9
  27. data/spec/param_spec.rb +16 -33
  28. data/spec/redis_handler_null_spec.rb +0 -2
  29. data/spec/redis_handler_spec.rb +0 -2
  30. data/spec/redis_helper_spec.rb +107 -0
  31. data/spec/request_spec.rb +249 -0
  32. data/spec/stomp_handler_null_spec.rb +33 -34
  33. data/spec/stomp_handler_spec.rb +1 -74
  34. data/spec/target_spec.rb +97 -0
  35. metadata +20 -11
  36. data/lib/nebulous_stomp/nebrequest.rb +0 -259
  37. data/lib/nebulous_stomp/nebrequest_null.rb +0 -37
  38. data/spec/nebrequest_null_spec.rb +0 -219
  39. data/spec/nebrequest_spec.rb +0 -239
  40. data/spec/through_test_spec.rb +0 -80
@@ -1,239 +0,0 @@
1
- require 'spec_helper'
2
-
3
- include NebulousStomp
4
-
5
- require 'nebulous_stomp/nebrequest'
6
- require 'nebulous_stomp/message'
7
- require 'nebulous_stomp/stomp_handler_null'
8
- require 'nebulous_stomp/redis_handler_null'
9
-
10
-
11
- describe NebRequest do
12
-
13
- let(:stomp_hash) do
14
- { hosts: [{ login: 'guest',
15
- passcode: 'guest',
16
- host: '10.0.0.150',
17
- port: 61613,
18
- ssl: false }],
19
- reliable: false }
20
-
21
- end
22
-
23
- let(:redis_hash) { {host: '127.0.0.1', port: 6379, db: 0} }
24
-
25
- let(:stomp_h) { StompHandlerNull.new(stomp_hash) }
26
- let(:redis_h) { RedisHandlerNull.new(redis_hash) }
27
-
28
- def new_request(target, verb, params=nil, desc=nil)
29
- NebRequest.new(target, verb, params, desc, stomp_h, redis_h)
30
- end
31
-
32
- before do
33
- NebulousStomp.init( :stompConnectHash => @stomph,
34
- :redisConnectHash => @redish,
35
- :messageTimeout => 5,
36
- :cacheTimeout => 20 )
37
-
38
- NebulousStomp.add_target( :accord,
39
- :sendQueue => "/queue/laplace.dev",
40
- :receiveQueue => "/queue/laplace.out",
41
- :messageTimeout => 1 )
42
-
43
- end
44
-
45
-
46
- describe "#initialize" do
47
-
48
- it "raises an exception for a bad target" do
49
- expect{ new_request('badtarget', 'foo') }.
50
- to raise_exception(NebulousError)
51
-
52
- end
53
-
54
- it "takes the timeout on the target over the default" do
55
- expect( new_request('accord', 'foo').mTimeout ).to eq(1)
56
- end
57
-
58
- it "falls back to the default if the timeout on the target is not set" do
59
- NebulousStomp.add_target( :dracula,
60
- :sendQueue => "/queue/laplace.dev",
61
- :receiveQueue => "/queue/laplace.out" )
62
-
63
- expect( new_request('dracula', 'foo').mTimeout ).to eq(5)
64
- end
65
-
66
- it 'doesn\'t freak out if Nebulous is not "on"' do
67
- sh = StompHandlerNull.new({})
68
-
69
- expect{ NebRequest.new('accord','foo',nil,nil,sh,redis_h) }.
70
- not_to raise_exception
71
-
72
- end
73
-
74
- end
75
- ##
76
-
77
-
78
- describe "#clear_cache" do
79
-
80
- it "removes the redis cache for a single request" do
81
- redis_h.insert_fake('foo', 'bar')
82
- expect( redis_h ).to receive(:del).with( {"verb"=>"foo"}.to_json )
83
-
84
- new_request('accord', 'foo').clear_cache
85
- end
86
-
87
- it 'returns self' do
88
- r = new_request('accord', 'foo')
89
- expect( r.clear_cache ).to eq r
90
- end
91
-
92
- it 'doesn\'t freak out if Redis is not connected' do
93
- rh = RedisHandlerNull.new({})
94
- r = NebRequest.new( 'accord', 'foo', nil, nil, stomp_h, rh)
95
-
96
- expect{ r.clear_cache }.not_to raise_exception
97
- expect( r.clear_cache ).to eq r
98
- end
99
-
100
- end
101
- ##
102
-
103
-
104
- describe "#send_no_cache" do
105
-
106
- it "returns something from STOMP" do
107
- request = new_request('accord', 'foo')
108
- stomp_h.insert_fake( Message.from_parts(nil, request.replyID, 'foo', 'bar', 'baz') )
109
- response = request.send_no_cache
110
-
111
- expect( response ).to be_a NebulousStomp::Message
112
- expect( response.verb ).to eq('foo')
113
- end
114
-
115
- it 'returns a nebulous timeout if there is no response' do
116
- request = new_request('accord', 'foo')
117
- expect{ request.send_no_cache }.
118
- to raise_exception NebulousStomp::NebulousTimeout
119
-
120
- end
121
-
122
- it 'returns nil if Nebulous is disabled in the config' do
123
- sh = StompHandlerNull.new({})
124
- r = NebRequest.new('accord', 'foo', nil, nil, sh, redis_h)
125
-
126
- expect( r.send_no_cache ).to eq nil
127
- end
128
-
129
- end
130
- ##
131
-
132
-
133
- describe "#send" do
134
-
135
- it "returns a Message object from STOMP the first time" do
136
- request = new_request('accord', 'foo')
137
- stomp_h.insert_fake( Message.from_parts(nil, request.replyID, 'foo', 'bar', 'baz') )
138
-
139
- response = request.send
140
- expect( response ).to be_a NebulousStomp::Message
141
- expect( response.verb ).to eq('foo')
142
- end
143
-
144
- it "returns the answer from the cache the second time" do
145
- stomp_h.insert_fake( Message.from_parts(nil, nil, 'foo', 'bar', 'baz') )
146
- redis_h.insert_fake('xxx', {'verb' => 'frog'}.to_json)
147
-
148
- # First time
149
- request = new_request('accord', 'foo')
150
- response = request.send
151
-
152
- # Second time
153
- request = new_request('accord', 'foo')
154
- response = request.send
155
-
156
- expect( response ).to be_a NebulousStomp::Message
157
- expect( response.verb ).to eq('frog')
158
- end
159
-
160
- it "allows you to specify a message timeout" do
161
- request = new_request('accord', 'foo')
162
- stomp_h.insert_fake( Message.from_parts(nil, request.replyID, 'foo', 'bar', 'baz') )
163
-
164
- expect{ request.send(3) }.not_to raise_exception
165
- end
166
-
167
- it "allows you to specify a message timeout & cache timeout" do
168
- request = new_request('accord', 'foo')
169
- stomp_h.insert_fake( Message.from_parts(nil, request.replyID, 'foo', 'bar', 'baz') )
170
-
171
- expect{ request.send(3, 120) }.not_to raise_exception
172
- end
173
-
174
- it 'returns a nebulous timeout if there is no response' do
175
- request = new_request('accord', 'foo')
176
- expect{ request.send }.to raise_exception NebulousStomp::NebulousTimeout
177
- end
178
-
179
- it 'still works if Redis is turned off in the config' do
180
- rh = RedisHandlerNull.new({})
181
- r = NebRequest.new('accord', 'tom', nil, nil, stomp_h, rh)
182
- stomp_h.insert_fake( Message.from_parts(nil, r.replyID, 'foo', 'bar', 'baz') )
183
-
184
- response = r.send
185
- expect( response ).to be_a NebulousStomp::Message
186
- expect( response.verb ).to eq('foo')
187
- end
188
-
189
- it 'returns nil if Nebulous is disabled in the config' do
190
- sh = StompHandlerNull.new({})
191
- r = NebRequest.new('accord', 'foo', nil, nil, sh, redis_h)
192
-
193
- expect( r.send ).to eq nil
194
- end
195
-
196
- end
197
- ##
198
-
199
-
200
- describe '#redis_on?' do
201
-
202
- it 'is true if there is a redis connection hash' do
203
- request = new_request('accord', 'foo')
204
- expect( request.redis_on? ).to be_truthy
205
- end
206
-
207
- it 'is false if there is no redis connection hash' do
208
- rh = RedisHandlerNull.new({})
209
- r = NebRequest.new('accord', 'foo', nil, nil, stomp_h, rh)
210
-
211
- expect( r.redis_on? ).to be_falsy
212
- end
213
-
214
- end
215
- ##
216
-
217
-
218
- describe '#nebulous_on?' do
219
-
220
- it 'is true if there is a nebulous connection hash' do
221
- sh = StompHandlerNull.new({foo: 'bar'})
222
- r = NebRequest.new('accord', 'foo', nil, nil, sh, redis_h)
223
-
224
- expect( r.nebulous_on? ).to be_truthy
225
- end
226
-
227
- it 'is false if there is no nebulous connection hash' do
228
- sh = StompHandlerNull.new({})
229
- r = NebRequest.new('accord', 'foo', nil, nil, sh, redis_h)
230
-
231
- expect( r.nebulous_on? ).to be_falsy
232
- end
233
-
234
- end
235
- ##
236
-
237
-
238
- end # of NebRequest
239
-
@@ -1,80 +0,0 @@
1
- require 'nebulous_stomp'
2
-
3
-
4
- ##
5
- # This is a through test against the JH development stomp server.
6
- # It's really only here to double check that the Stomp gem hasn't moved the
7
- # goalposts (again).
8
- #
9
- # In order for it to work, the JH RabbitMQ server has to be where we left it. And you need a
10
- # responder listening to /queue/nebulout.test for the 'ping' verb. So this test won't work for you
11
- # out of the box, unless you are me.
12
- #
13
- describe 'through test' do
14
-
15
- def connect_hash
16
- host = { login: 'guest',
17
- passcode: 'guest',
18
- host: '10.0.0.150',
19
- port: 61613,
20
- ssl: false }
21
-
22
- {hosts: [host], reliable: false}
23
- end
24
-
25
- def target_hash
26
- { sendQueue: "/queue/nebulous.test",
27
- receiveQueue: "/queue/nebulous.test.response" }
28
-
29
- end
30
-
31
- def init_stomp
32
- NebulousStomp.init(stompConnectHash: connect_hash, messageTimeout: 5)
33
- NebulousStomp.add_target(:target, target_hash)
34
- end
35
-
36
- ##
37
- # a little method to receive a message and send one back, for testinng
38
- # sending one.
39
- #
40
- def qna
41
- Thread.new do
42
-
43
- begin
44
- sh = NebulousStomp::StompHandler.new(connect_hash)
45
- sh.listen_with_timeout( target_hash[:sendQueue], 10 ) do |m|
46
- sh.send_message( *m.respond_success )
47
- end
48
- ensure
49
- sh.stomp_disconnect if sh
50
- end
51
-
52
- end
53
-
54
- rescue
55
- nil
56
- end
57
-
58
-
59
- let(:request) { NebulousStomp::NebRequest.new(:target, "ping") }
60
-
61
- before do
62
- init_stomp
63
- end
64
-
65
-
66
- it "sends a request" do
67
- expect{ request.send_no_cache }.to raise_exception NebulousStomp::NebulousTimeout
68
- end
69
-
70
-
71
- it "receives a response" do
72
- r = NebulousStomp::NebRequest.new(:target, "ping")
73
- qna; response = r.send_no_cache
74
-
75
- expect( response ).to be_a_kind_of NebulousStomp::Message
76
- expect( response.verb ).to eq 'success'
77
- end
78
-
79
- end
80
-