magellan-rails 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/magellan/rails/version.rb +1 -1
- data/lib/magellan/worker/executor.rb +10 -1
- data/spec/magellan/worker/executor_spec.rb +67 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c421c287c6fa5f5c8f5b6ef25b7b3f99bfae56e
|
4
|
+
data.tar.gz: 0c895a7553fa8799cd237631a549ebd8c44206b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36dfd7b680d8689dc06111cb67a366946fc4b0a9385a17f34d0af9dd0d5672de56bbc877c21fa1f2b4f9459585378d062bc2b23d39313b1860d00542fb380053
|
7
|
+
data.tar.gz: 1e9474777f528152bb2913dbb43eb750c65ebb7c827d3ebc058b81fc0c7bdbb4b39d8166dd5ad76d0e991b1848cc84c3da4796f9039e948c9182e9474b295cc8
|
@@ -23,7 +23,16 @@ class Magellan::Worker::Executor
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def execute(reply_to, correlation_id, delivery_tag, request_message)
|
26
|
-
|
26
|
+
version = request_message["v"] || 1
|
27
|
+
case version
|
28
|
+
when 1
|
29
|
+
request_method = request_message["headers"]["Method"]
|
30
|
+
when 2
|
31
|
+
request_method = request_message["env"]["METHOD"]
|
32
|
+
else
|
33
|
+
raise "Unsupported request format version: #{version}. Please update magellan-rails."
|
34
|
+
end
|
35
|
+
case request_method
|
27
36
|
when /\Apublish\z/i
|
28
37
|
subscriber_executor.execute(request_message)
|
29
38
|
else
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe Magellan::Worker::Executor do
|
6
|
+
|
7
|
+
describe "#execute" do
|
8
|
+
let(:exchange) do double(:exchange) end
|
9
|
+
let(:reply_to) do double(:reply_to) end
|
10
|
+
let(:correlation_id) do double(:correlation_id) end
|
11
|
+
let(:delivery_tag) do double(:delivery_tag) end
|
12
|
+
let(:rails_executor) do double(:rails_executor) end
|
13
|
+
let(:subscriber_executor) do double(:subscriber_executor) end
|
14
|
+
let(:executor) do
|
15
|
+
Magellan::Worker::Executor.new(exchange).tap do |e|
|
16
|
+
e.instance_variable_set :@rails_executor, rails_executor
|
17
|
+
e.instance_variable_set :@subscriber_executor, subscriber_executor
|
18
|
+
end
|
19
|
+
end
|
20
|
+
before do
|
21
|
+
allow_any_instance_of(Magellan::Worker::Executor).to receive(:require)
|
22
|
+
end
|
23
|
+
|
24
|
+
context "v1" do
|
25
|
+
let(:request_obj) do { "headers" => { "Method" => @method, "Path-Info" => "topic" }, "body" => "payload" } end
|
26
|
+
context "GET" do
|
27
|
+
before do
|
28
|
+
@method = "GET"
|
29
|
+
expect(rails_executor).to receive(:execute).with(reply_to, correlation_id, delivery_tag, request_obj).and_return(:result)
|
30
|
+
end
|
31
|
+
it do
|
32
|
+
expect(executor.execute(reply_to, correlation_id, delivery_tag, request_obj)).to eql(:result)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
context "PUBLISH" do
|
36
|
+
before do
|
37
|
+
@method = "PUBLISH"
|
38
|
+
expect(subscriber_executor).to receive(:execute).with(request_obj).and_return(:result)
|
39
|
+
end
|
40
|
+
it do
|
41
|
+
expect(executor.execute(reply_to, correlation_id, delivery_tag, request_obj)).to eql(:result)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
context "v2" do
|
46
|
+
let(:request_obj) do { "v" => 2, "env" => { "METHOD" => @method, "PATH_INFO" => "topic" }, "headers" => {}, "body" => "payload" } end
|
47
|
+
context "GET" do
|
48
|
+
before do
|
49
|
+
@method = "GET"
|
50
|
+
expect(rails_executor).to receive(:execute).with(reply_to, correlation_id, delivery_tag, request_obj).and_return(:result)
|
51
|
+
end
|
52
|
+
it do
|
53
|
+
expect(executor.execute(reply_to, correlation_id, delivery_tag, request_obj)).to eql(:result)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
context "PUBLISH" do
|
57
|
+
before do
|
58
|
+
@method = "PUBLISH"
|
59
|
+
expect(subscriber_executor).to receive(:execute).with(request_obj).and_return(:result)
|
60
|
+
end
|
61
|
+
it do
|
62
|
+
expect(executor.execute(reply_to, correlation_id, delivery_tag, request_obj)).to eql(:result)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: magellan-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuuki Noguchi
|
@@ -147,6 +147,7 @@ files:
|
|
147
147
|
- spec/magellan/subscriber/mapper_spec.rb
|
148
148
|
- spec/magellan/subscriber/request_spec.rb
|
149
149
|
- spec/magellan/worker/core_spec.rb
|
150
|
+
- spec/magellan/worker/executor_spec.rb
|
150
151
|
- spec/spec_helper.rb
|
151
152
|
homepage: ''
|
152
153
|
licenses:
|
@@ -178,4 +179,5 @@ test_files:
|
|
178
179
|
- spec/magellan/subscriber/mapper_spec.rb
|
179
180
|
- spec/magellan/subscriber/request_spec.rb
|
180
181
|
- spec/magellan/worker/core_spec.rb
|
182
|
+
- spec/magellan/worker/executor_spec.rb
|
181
183
|
- spec/spec_helper.rb
|