stapfen 2.2.0-java
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 +7 -0
- data/.gitignore +19 -0
- data/CHANGES.md +16 -0
- data/Gemfile +16 -0
- data/LICENSE.txt +22 -0
- data/README.md +106 -0
- data/Rakefile +10 -0
- data/examples/simple.rb +44 -0
- data/lib/stapfen.rb +25 -0
- data/lib/stapfen/client.rb +8 -0
- data/lib/stapfen/client/jms.rb +118 -0
- data/lib/stapfen/client/kafka.rb +76 -0
- data/lib/stapfen/client/stomp.rb +35 -0
- data/lib/stapfen/destination.rb +59 -0
- data/lib/stapfen/logger.rb +48 -0
- data/lib/stapfen/message.rb +58 -0
- data/lib/stapfen/version.rb +3 -0
- data/lib/stapfen/worker.rb +265 -0
- data/spec/client/jms_spec.rb +199 -0
- data/spec/client/kafka_spec.rb +54 -0
- data/spec/client/stomp_spec.rb +5 -0
- data/spec/client_spec.rb +5 -0
- data/spec/destination_spec.rb +71 -0
- data/spec/logger_spec.rb +41 -0
- data/spec/message_spec.rb +96 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/worker_spec.rb +275 -0
- data/stapfen.gemspec +24 -0
- metadata +93 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '../lib'))
|
2
|
+
|
3
|
+
require 'stapfen'
|
4
|
+
require 'rspec/its'
|
5
|
+
|
6
|
+
is_java = (RUBY_PLATFORM == 'java')
|
7
|
+
|
8
|
+
unless is_java
|
9
|
+
require 'debugger'
|
10
|
+
require 'debugger/pry'
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
RSpec.configure do |c|
|
15
|
+
c.color = true
|
16
|
+
c.order = "random"
|
17
|
+
|
18
|
+
unless is_java
|
19
|
+
c.filter_run_excluding :java => true
|
20
|
+
end
|
21
|
+
end
|
data/spec/worker_spec.rb
ADDED
@@ -0,0 +1,275 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'stapfen/client/stomp'
|
3
|
+
|
4
|
+
describe Stapfen::Worker do
|
5
|
+
subject(:worker) { described_class.new }
|
6
|
+
|
7
|
+
context 'class methods' do
|
8
|
+
subject(:worker) { described_class }
|
9
|
+
|
10
|
+
it { should respond_to :run! }
|
11
|
+
it { should respond_to :configure }
|
12
|
+
it { should respond_to :consume }
|
13
|
+
it { should respond_to :log }
|
14
|
+
it { should respond_to :shutdown }
|
15
|
+
|
16
|
+
describe '#use_stomp!' do
|
17
|
+
subject(:result) { worker.use_stomp! }
|
18
|
+
|
19
|
+
it 'should update the instance variable' do
|
20
|
+
expect(result).to be true
|
21
|
+
expect(worker).to be_stomp
|
22
|
+
expect(worker).not_to be_jms
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#use_jms!', :java => true do
|
27
|
+
subject(:result) { worker.use_jms! }
|
28
|
+
|
29
|
+
after :each do
|
30
|
+
# Reset to the default since we've modified the class
|
31
|
+
worker.use_stomp!
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should update the instance variable' do
|
35
|
+
expect(result).to be true
|
36
|
+
expect(worker).to be_jms
|
37
|
+
expect(worker).not_to be_stomp
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#log' do
|
42
|
+
it "should store the block it's passed" do
|
43
|
+
logger = double('Mock Logger')
|
44
|
+
|
45
|
+
worker.log do
|
46
|
+
logger
|
47
|
+
end
|
48
|
+
|
49
|
+
expect(worker.logger).to be_instance_of Proc
|
50
|
+
end
|
51
|
+
|
52
|
+
after :each do
|
53
|
+
worker.logger = nil
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '#configure' do
|
58
|
+
let(:config) { {:valid => true} }
|
59
|
+
it 'should error when not passed a block' do
|
60
|
+
expect {
|
61
|
+
worker.configure
|
62
|
+
}.to raise_error(Stapfen::ConfigurationError)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should save the return value from the block' do
|
66
|
+
worker.configure do
|
67
|
+
config
|
68
|
+
end
|
69
|
+
expect(worker.configuration.call).to eql(config)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#exit_cleanly', :java => true do
|
74
|
+
subject(:result) { worker.exit_cleanly }
|
75
|
+
|
76
|
+
before do
|
77
|
+
allow(Java::JavaLang::System).to receive(:exit).with(0)
|
78
|
+
end
|
79
|
+
|
80
|
+
after do
|
81
|
+
worker.class_variable_set(:@@workers, [])
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'with no worker classes' do
|
85
|
+
it { should be false }
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'with a single worker class' do
|
89
|
+
let(:w) { double('Fake worker instance') }
|
90
|
+
|
91
|
+
before :each do
|
92
|
+
worker.class_variable_set(:@@workers, [w])
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should execute the worker's #exit_cleanly method" do
|
96
|
+
w.should_receive(:exit_cleanly)
|
97
|
+
expect(result).to be true
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should return false if the worker's #exit_cleanly method" do
|
101
|
+
w.should_receive(:exit_cleanly).and_raise(StandardError)
|
102
|
+
expect(result).to be false
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context 'with multiple worker classes' do
|
107
|
+
let(:w1) { double('Fake Worker 1') }
|
108
|
+
let(:w2) { double('Fake Worker 2') }
|
109
|
+
|
110
|
+
before do
|
111
|
+
worker.class_variable_set(:@@workers, [w1, w2])
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should invoke both #exit_cleanly methods' do
|
115
|
+
expect(w1).to receive(:exit_cleanly)
|
116
|
+
expect(w2).to receive(:exit_cleanly)
|
117
|
+
expect(worker.exit_cleanly).to be true
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe 'consume' do
|
123
|
+
context 'if no block is passed' do
|
124
|
+
it 'should raise an error if no block is passed' do
|
125
|
+
expect {
|
126
|
+
worker.consume 'jms.queue.lol'
|
127
|
+
}.to raise_error(Stapfen::ConsumeError)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
context 'with just a queue name' do
|
132
|
+
let(:name) { 'jms.queue.lol' }
|
133
|
+
|
134
|
+
before do
|
135
|
+
worker.instance_variable_set(:@consumers, [])
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'should add an entry for the queue name' do
|
139
|
+
worker.consume(name) do |msg|
|
140
|
+
nil
|
141
|
+
end
|
142
|
+
|
143
|
+
worker.consumers.should_not be_empty
|
144
|
+
entry = worker.consumers.first
|
145
|
+
entry.first.should eq(name)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
context 'unreceive behavior' do
|
150
|
+
let(:client) do
|
151
|
+
c = double('Mock Stapfen::Client')
|
152
|
+
c.stub(:connect)
|
153
|
+
c.stub(:can_unreceive? => true)
|
154
|
+
c.stub(:runloop)
|
155
|
+
c.stub(:unreceive)
|
156
|
+
c
|
157
|
+
end
|
158
|
+
|
159
|
+
let(:name) { '/queue/some_queue' }
|
160
|
+
let(:message) do
|
161
|
+
m = Stomp::Message.new(nil)
|
162
|
+
m.stub(:body => 'rspec msg')
|
163
|
+
m
|
164
|
+
end
|
165
|
+
|
166
|
+
before :each do
|
167
|
+
Stapfen::Client::Stomp.stub(:new).and_return(client)
|
168
|
+
|
169
|
+
# Clear any old consumers out
|
170
|
+
worker.consumers = []
|
171
|
+
|
172
|
+
# Get a subscription? Call the message handler block.
|
173
|
+
client.stub(:subscribe) do |name, headers, &block|
|
174
|
+
block.call(message)
|
175
|
+
end
|
176
|
+
|
177
|
+
config = {:valid => true}
|
178
|
+
|
179
|
+
worker.configure do
|
180
|
+
config
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
after do
|
185
|
+
worker.class_variable_set(:@@workers, [])
|
186
|
+
end
|
187
|
+
|
188
|
+
context 'with just a queue name' do
|
189
|
+
context 'on a failed message' do
|
190
|
+
it 'should not unreceive' do
|
191
|
+
client.should_receive(:unreceive).never
|
192
|
+
|
193
|
+
worker.consume(name) {|msg| false }
|
194
|
+
worker.new.run
|
195
|
+
end
|
196
|
+
end
|
197
|
+
context 'on a successful message' do
|
198
|
+
it 'should not unreceive' do
|
199
|
+
client.should_receive(:unreceive).never
|
200
|
+
|
201
|
+
worker.consume(name) {|msg| true }
|
202
|
+
worker.new.run
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
context 'with a queue name and headers for a dead_letter_queue and max_redeliveries' do
|
208
|
+
let(:unrec_headers) do
|
209
|
+
{ :dead_letter_queue => '/queue/foo',
|
210
|
+
:max_redeliveries => 3 }
|
211
|
+
end
|
212
|
+
|
213
|
+
let(:raw_headers) { unrec_headers.merge(:other_header => 'foo!') }
|
214
|
+
context 'on a failed message' do
|
215
|
+
it 'should unreceive' do
|
216
|
+
client.should_receive(:unreceive).once
|
217
|
+
|
218
|
+
worker.consume(name, raw_headers) {|msg| false }
|
219
|
+
worker.new.run
|
220
|
+
end
|
221
|
+
it 'should pass :unreceive_headers through to the unreceive call' do
|
222
|
+
client.should_receive(:unreceive).with(message, unrec_headers).once
|
223
|
+
|
224
|
+
worker.consume(name, raw_headers) {|msg| false }
|
225
|
+
worker.new.run
|
226
|
+
end
|
227
|
+
it 'should not remove the unreceive headers from the consumer' do
|
228
|
+
worker.consume(name, raw_headers) {|msg| false}
|
229
|
+
worker.new.run
|
230
|
+
|
231
|
+
expect(worker.consumers.last[1][:dead_letter_queue]).to eql unrec_headers[:dead_letter_queue]
|
232
|
+
expect(worker.consumers.last[1][:max_redeliveries]).to eql unrec_headers[:max_redeliveries]
|
233
|
+
end
|
234
|
+
end
|
235
|
+
context 'on a successfully handled message' do
|
236
|
+
it 'should not unreceive' do
|
237
|
+
client.should_receive(:unreceive).never
|
238
|
+
|
239
|
+
worker.consume(name, raw_headers) {|msg| true }
|
240
|
+
worker.new.run
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
context 'instance methods' do
|
249
|
+
describe '#exit_cleanly' do
|
250
|
+
let(:client) { double('RSpec Stomp Client') }
|
251
|
+
|
252
|
+
before :each do
|
253
|
+
worker.stub(:client).and_return(client)
|
254
|
+
end
|
255
|
+
|
256
|
+
it 'should close the client' do
|
257
|
+
client.stub(:closed?).and_return(false)
|
258
|
+
client.should_receive(:close)
|
259
|
+
worker.exit_cleanly
|
260
|
+
end
|
261
|
+
|
262
|
+
context 'with out having connected a client yet' do
|
263
|
+
before :each do
|
264
|
+
worker.stub(:client).and_return(nil)
|
265
|
+
end
|
266
|
+
|
267
|
+
it 'should not raise any errors' do
|
268
|
+
expect {
|
269
|
+
worker.exit_cleanly
|
270
|
+
}.not_to raise_error
|
271
|
+
end
|
272
|
+
end
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
data/stapfen.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'stapfen/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "stapfen"
|
8
|
+
s.version = Stapfen::VERSION
|
9
|
+
s.authors = ["R. Tyler Croy"]
|
10
|
+
s.email = ["rtyler.croy@lookout.com"]
|
11
|
+
s.description = "A simple gem for writing good basic STOMP workers"
|
12
|
+
s.summary = "A simple gem for writing good basic STOMP workers"
|
13
|
+
s.homepage = ""
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split($/)
|
16
|
+
s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
if RUBY_PLATFORM == "java"
|
21
|
+
s.add_dependency 'hermann', "~> 0.20.0"
|
22
|
+
s.platform = 'java'
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: stapfen
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.2.0
|
5
|
+
platform: java
|
6
|
+
authors:
|
7
|
+
- R. Tyler Croy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ~>
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: 0.20.0
|
19
|
+
name: hermann
|
20
|
+
prerelease: false
|
21
|
+
type: :runtime
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.20.0
|
27
|
+
description: A simple gem for writing good basic STOMP workers
|
28
|
+
email:
|
29
|
+
- rtyler.croy@lookout.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- .gitignore
|
35
|
+
- CHANGES.md
|
36
|
+
- Gemfile
|
37
|
+
- LICENSE.txt
|
38
|
+
- README.md
|
39
|
+
- Rakefile
|
40
|
+
- examples/simple.rb
|
41
|
+
- lib/stapfen.rb
|
42
|
+
- lib/stapfen/client.rb
|
43
|
+
- lib/stapfen/client/jms.rb
|
44
|
+
- lib/stapfen/client/kafka.rb
|
45
|
+
- lib/stapfen/client/stomp.rb
|
46
|
+
- lib/stapfen/destination.rb
|
47
|
+
- lib/stapfen/logger.rb
|
48
|
+
- lib/stapfen/message.rb
|
49
|
+
- lib/stapfen/version.rb
|
50
|
+
- lib/stapfen/worker.rb
|
51
|
+
- spec/client/jms_spec.rb
|
52
|
+
- spec/client/kafka_spec.rb
|
53
|
+
- spec/client/stomp_spec.rb
|
54
|
+
- spec/client_spec.rb
|
55
|
+
- spec/destination_spec.rb
|
56
|
+
- spec/logger_spec.rb
|
57
|
+
- spec/message_spec.rb
|
58
|
+
- spec/spec_helper.rb
|
59
|
+
- spec/worker_spec.rb
|
60
|
+
- stapfen.gemspec
|
61
|
+
homepage: ''
|
62
|
+
licenses: []
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.2.2
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: A simple gem for writing good basic STOMP workers
|
84
|
+
test_files:
|
85
|
+
- spec/client/jms_spec.rb
|
86
|
+
- spec/client/kafka_spec.rb
|
87
|
+
- spec/client/stomp_spec.rb
|
88
|
+
- spec/client_spec.rb
|
89
|
+
- spec/destination_spec.rb
|
90
|
+
- spec/logger_spec.rb
|
91
|
+
- spec/message_spec.rb
|
92
|
+
- spec/spec_helper.rb
|
93
|
+
- spec/worker_spec.rb
|