cpi-event-connector 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cpi_event_connector/connector.rb +15 -12
- data/lib/cpi_event_connector/event.rb +0 -1
- data/lib/cpi_event_connector/version.rb +1 -1
- data/spec/connector_spec.rb +35 -34
- data/spec/event_spec.rb +0 -2
- data/spec/integration_spec.rb +1 -4
- metadata +5 -5
@@ -7,27 +7,30 @@ module Cpi
|
|
7
7
|
@params = params
|
8
8
|
end
|
9
9
|
|
10
|
-
def start
|
11
|
-
@bunny = Bunny.new @params
|
12
|
-
@bunny.start
|
13
|
-
@bunny.tx_select
|
14
|
-
@exchange = @bunny.exchange('')
|
15
|
-
|
16
|
-
@queue = @bunny.queue(@queue_name, :durable => true)
|
17
|
-
end
|
18
|
-
|
19
10
|
def transmit(message)
|
20
11
|
begin
|
12
|
+
start
|
21
13
|
@exchange.publish(message, :key => @queue_name)
|
22
14
|
@bunny.tx_commit
|
23
15
|
rescue Bunny::ServerDownError, Bunny::ForcedConnectionCloseError, Bunny::ConnectionError
|
16
|
+
@started = false
|
24
17
|
start
|
25
18
|
retry
|
26
19
|
end
|
27
20
|
end
|
28
21
|
|
29
|
-
|
30
|
-
|
22
|
+
private
|
23
|
+
|
24
|
+
def start
|
25
|
+
return if @started
|
26
|
+
|
27
|
+
@bunny = Bunny.new @params
|
28
|
+
@bunny.start
|
29
|
+
@bunny.tx_select
|
30
|
+
@exchange = @bunny.exchange('')
|
31
|
+
|
32
|
+
@queue = @bunny.queue(@queue_name, :durable => true)
|
33
|
+
@started = true
|
31
34
|
end
|
32
35
|
end
|
33
|
-
end
|
36
|
+
end
|
data/spec/connector_spec.rb
CHANGED
@@ -18,63 +18,64 @@ describe Cpi::Connector do
|
|
18
18
|
bunny.stub(:exchange).and_return(exchange)
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
bunny.should_receive(:start)
|
21
|
+
describe "#transmit" do
|
22
|
+
let(:connector) { Cpi::Connector.new params }
|
23
|
+
let(:event) { "event" }
|
25
24
|
|
26
|
-
|
27
|
-
|
25
|
+
before do
|
26
|
+
exchange.stub(:publish)
|
27
|
+
bunny.stub(:tx_commit)
|
28
28
|
end
|
29
29
|
|
30
|
-
|
31
|
-
|
30
|
+
context "before connection established" do
|
31
|
+
it "connects to an amqp server" do
|
32
|
+
Bunny.should_receive(:new).with(params).and_return(bunny)
|
33
|
+
bunny.should_receive(:start)
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
-
end
|
35
|
+
connector.transmit(event)
|
36
|
+
end
|
36
37
|
|
37
|
-
|
38
|
-
|
38
|
+
it "connects to the specified queue" do
|
39
|
+
bunny.should_receive(:queue).with("cpi", :durable => true).and_return(queue)
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
end
|
41
|
+
connector.transmit(event)
|
42
|
+
end
|
43
43
|
|
44
|
-
|
45
|
-
|
44
|
+
it "creates a transaction before sending an event" do
|
45
|
+
bunny.should_receive(:tx_select)
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
end
|
50
|
-
end
|
47
|
+
connector.transmit(event)
|
48
|
+
end
|
51
49
|
|
52
|
-
|
53
|
-
|
54
|
-
@connector = Cpi::Connector.new params
|
55
|
-
@connector.start
|
50
|
+
it "gets an exchange" do
|
51
|
+
bunny.should_receive(:exchange).with('').and_return(exchange)
|
56
52
|
|
57
|
-
|
58
|
-
|
53
|
+
connector.transmit(event)
|
54
|
+
end
|
59
55
|
end
|
60
56
|
|
61
|
-
|
62
|
-
|
57
|
+
context "connection already established" do
|
58
|
+
before do
|
59
|
+
connector.transmit(event)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "does not do anything" do
|
63
|
+
Bunny.should_not_receive(:new)
|
63
64
|
|
64
|
-
|
65
|
+
connector.transmit(event)
|
66
|
+
end
|
65
67
|
end
|
66
68
|
|
67
69
|
it "sends a message to an amqp server" do
|
68
|
-
event = "an event"
|
69
70
|
exchange.should_receive(:publish).with(event, :key => "cpi")
|
70
71
|
|
71
|
-
|
72
|
+
connector.transmit(event)
|
72
73
|
end
|
73
74
|
|
74
75
|
it "commits the transaction after a message has been published" do
|
75
76
|
bunny.should_receive(:tx_commit)
|
76
77
|
|
77
|
-
|
78
|
+
connector.transmit("event")
|
78
79
|
end
|
79
80
|
end
|
80
81
|
end
|
data/spec/event_spec.rb
CHANGED
@@ -24,7 +24,6 @@ enabled: true
|
|
24
24
|
expected_config = YAML::load(yaml_config).symbolize_keys!
|
25
25
|
expected_config.delete(:enabled)
|
26
26
|
Cpi::Connector.should_receive(:new).with(expected_config).and_return(connector)
|
27
|
-
connector.should_receive(:start)
|
28
27
|
|
29
28
|
Cpi::Event.configure(YAML::load(yaml_config).symbolize_keys!)
|
30
29
|
end
|
@@ -33,7 +32,6 @@ enabled: true
|
|
33
32
|
yaml_config = "---
|
34
33
|
enabled: false"
|
35
34
|
Cpi::Connector.should_not_receive(:new)
|
36
|
-
connector.should_not_receive(:start)
|
37
35
|
|
38
36
|
Cpi::Event.configure(YAML::load(yaml_config))
|
39
37
|
end
|
data/spec/integration_spec.rb
CHANGED
@@ -16,15 +16,12 @@ queue: connector-test"}
|
|
16
16
|
|
17
17
|
it "sends a message to an amqp server" do
|
18
18
|
connector = Cpi::Connector.new(YAML::load(yaml_config).symbolize_keys!)
|
19
|
-
connector.start
|
20
19
|
connector.transmit("message")
|
21
|
-
connector.stop
|
22
20
|
|
23
21
|
b = Bunny.new
|
24
22
|
b.start
|
25
23
|
q = b.queue("connector-test", :durable => true)
|
26
24
|
message = q.pop
|
27
25
|
message[:payload].should == "message"
|
28
|
-
b.stop
|
29
26
|
end
|
30
|
-
end
|
27
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cpi-event-connector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 6
|
10
|
+
version: 0.0.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Nulogy
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-03-
|
18
|
+
date: 2012-03-28 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rspec
|
@@ -146,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
146
|
requirements: []
|
147
147
|
|
148
148
|
rubyforge_project:
|
149
|
-
rubygems_version: 1.8.
|
149
|
+
rubygems_version: 1.8.10
|
150
150
|
signing_key:
|
151
151
|
specification_version: 3
|
152
152
|
summary: Sends events to CPI
|