cpi-event-connector 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,5 +1,4 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in cpi-event-connector.gemspec
4
- gem 'bunny', :git => "https://github.com/ruby-amqp/bunny.git"
5
4
  gemspec
data/Gemfile.lock CHANGED
@@ -1,15 +1,9 @@
1
- GIT
2
- remote: https://github.com/ruby-amqp/bunny.git
3
- revision: af6d5e35c7fcd5667807b595c8eb22f08780c0aa
4
- specs:
5
- bunny (0.8.0.pre1)
6
-
7
1
  PATH
8
2
  remote: .
9
3
  specs:
10
- cpi-event-connector (0.0.12)
4
+ cpi-event-connector (0.0.13)
11
5
  activesupport (~> 3)
12
- bunny
6
+ bunny (~> 0.8.0)
13
7
  uuidtools (~> 2.1.2)
14
8
 
15
9
  GEM
@@ -19,6 +13,7 @@ GEM
19
13
  i18n (~> 0.6)
20
14
  multi_json (~> 1.0)
21
15
  backports (2.5.1)
16
+ bunny (0.8.0)
22
17
  diff-lcs (1.1.3)
23
18
  i18n (0.6.0)
24
19
  justinf-unification_assertion (0.0.2)
@@ -38,7 +33,6 @@ PLATFORMS
38
33
 
39
34
  DEPENDENCIES
40
35
  backports
41
- bunny!
42
36
  cpi-event-connector!
43
37
  justinf-unification_assertion
44
38
  rspec
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
21
21
  s.add_development_dependency "backports"
22
22
  s.add_development_dependency "justinf-unification_assertion"
23
23
 
24
- s.add_runtime_dependency "bunny"
24
+ s.add_runtime_dependency "bunny", "~> 0.8.0"
25
25
  s.add_runtime_dependency "activesupport", "~> 3"
26
26
  s.add_runtime_dependency "uuidtools", "~> 2.1.2"
27
27
  end
@@ -3,9 +3,10 @@ require 'bunny'
3
3
 
4
4
  module Cpi
5
5
  class Connector
6
- def initialize params={}
6
+ def initialize params={}, logger
7
7
  @queue = params.delete(:queue)
8
8
  @params = params
9
+ @logger = logger
9
10
  end
10
11
 
11
12
  def transmit(message, options = nil)
@@ -21,19 +22,27 @@ module Cpi
21
22
  end
22
23
  end
23
24
 
25
+ def connectivity_test
26
+ @started = false
27
+ start
28
+ "Event Connector can connect to AMQP server at #{@params[:host]}:#{@params[:port]}"
29
+ rescue StandardError => e
30
+ e.message
31
+ end
32
+
24
33
  private
25
34
 
26
35
  def start
27
36
  return if @started
28
37
 
29
- Event.logger.debug "Connecting to Rabbit with params #{@params.inspect}"
38
+ @logger.debug "Connecting to Rabbit with params #{@params.inspect}"
30
39
  @bunny = Bunny.new @params
31
40
  @bunny.start
32
41
  @bunny.tx_select
33
42
  @exchange = @bunny.exchange('')
34
43
 
35
44
  @started = true
36
- Event.logger.debug "Connection established"
45
+ @logger.debug "Connection established"
37
46
  end
38
47
 
39
48
  def with_retries(*args, &block)
@@ -49,15 +58,15 @@ module Cpi
49
58
  begin
50
59
  yield
51
60
  rescue *exceptions => e
52
- Event.logger.debug "Exception caught in #with_retries:\n#{e.message}"
61
+ @logger.debug "Exception caught in #with_retries:\n#{e.message}"
53
62
  if retried < options[:retries]
54
63
  retried += 1
55
- Event.logger.debug "Trying again. Have tried #{retried} times so far."
64
+ @logger.debug "Trying again. Have tried #{retried} times so far."
56
65
  sleep options[:sleep]
57
66
  options[:before_retry].call
58
67
  retry
59
68
  else
60
- Event.logger.debug "Gave up on retries, throwing: #{e.message}"
69
+ @logger.debug "Gave up on retries, throwing: #{e.message}"
61
70
  raise e
62
71
  end
63
72
  end
@@ -1,6 +1,8 @@
1
1
  require 'active_support/core_ext/string'
2
2
 
3
3
  module Cpi
4
+ THREAD_LOCAL_VARIABLE = :cpi_connector
5
+
4
6
  class Event
5
7
  class << self
6
8
  attr_accessor :connection_params
@@ -31,10 +33,19 @@ module Cpi
31
33
  @logger.debug "Transmission complete"
32
34
  end
33
35
 
36
+ def self.connectivity_test
37
+ if !@enabled
38
+ return 'Event Connector is not enabled.'
39
+ end
40
+
41
+ self.connector.connectivity_test
42
+ end
43
+
34
44
  private
35
45
 
36
46
  def self.connector
37
- Thread.current[:cpi_connector] ||= Cpi::Connector.new(self.connection_params)
47
+ Thread.current[THREAD_LOCAL_VARIABLE] ||= Cpi::Connector.new(self.connection_params, @logger)
38
48
  end
49
+
39
50
  end
40
51
  end
@@ -1,3 +1,3 @@
1
1
  module Cpi
2
- VERSION = "0.0.13"
2
+ VERSION = "0.0.14"
3
3
  end
@@ -7,6 +7,7 @@ describe Cpi::Connector do
7
7
  let(:bunny) { double(Bunny) }
8
8
  let(:params) { {:host => "", :port => "", :username => "", :password => "", :queue => "cpi"} }
9
9
  let(:queue) { double("a queue")}
10
+ let(:logger) { Logger.new("/dev/null") }
10
11
  let(:exchange) { double("an exchange")}
11
12
 
12
13
 
@@ -19,7 +20,7 @@ describe Cpi::Connector do
19
20
  end
20
21
 
21
22
  describe "#transmit" do
22
- let(:connector) { Cpi::Connector.new params }
23
+ let(:connector) { Cpi::Connector.new params, logger }
23
24
  let(:event) { "event" }
24
25
 
25
26
  before do
data/spec/event_spec.rb CHANGED
@@ -6,6 +6,14 @@ require 'unification_assertion'
6
6
  describe Cpi::Event do
7
7
  let(:config) { { :enabled => true, :key => "value" } }
8
8
  let(:logger) { stub("Logger", debug: nil, info: nil) }
9
+ let(:real_config) { {
10
+ host: "localhost",
11
+ port: "5672",
12
+ username: "guest",
13
+ password: "guest",
14
+ queue: "connector-test",
15
+ enabled: "true"
16
+ } }
9
17
 
10
18
  describe ".configure" do
11
19
  let(:connector) { double(Cpi::Connector) }
@@ -24,14 +32,7 @@ describe Cpi::Event do
24
32
  end
25
33
 
26
34
  describe ".transmit" do
27
- let(:real_config) { {
28
- host: "localhost",
29
- port: "5672",
30
- username: "guest",
31
- password: "guest",
32
- queue: "connector-test",
33
- enabled: "true"
34
- } }
35
+
35
36
  let(:content) { "<test />" }
36
37
 
37
38
  it "generates and sends an event" do
@@ -90,4 +91,22 @@ describe Cpi::Event do
90
91
  expect {Cpi::Event.transmit("message", nil, "content")}.to raise_error(ArgumentError)
91
92
  end
92
93
  end
94
+
95
+ describe ".connectivity_test" do
96
+ it "tells you when the connector is not enabled" do
97
+ Cpi::Event.configure({enabled: false}, logger)
98
+ Cpi::Event.connectivity_test.should == 'Event Connector is not enabled.'
99
+ end
100
+
101
+ it "tells you when the connection params are correct" do
102
+ Cpi::Event.configure(real_config, logger)
103
+ Cpi::Event.connectivity_test.should == 'Event Connector can connect to AMQP server at localhost:5672'
104
+ end
105
+
106
+ it "returns false when the connection params are incorrect" do
107
+ real_config[:host] = "doesntwork"
108
+ Cpi::Event.configure(real_config, logger)
109
+ Cpi::Event.connectivity_test.should == "getaddrinfo: Name or service not known"
110
+ end
111
+ end
93
112
  end
@@ -13,9 +13,10 @@ port: 5672
13
13
  username: guest
14
14
  password: guest
15
15
  queue: connector-test"}
16
+ let(:logger) { Logger.new("/dev/null") }
16
17
 
17
18
  it "sends a message to an amqp server" do
18
- connector = Cpi::Connector.new(YAML::load(yaml_config).symbolize_keys!)
19
+ connector = Cpi::Connector.new(YAML::load(yaml_config).symbolize_keys!, logger)
19
20
  connector.transmit("message")
20
21
 
21
22
  b = Bunny.new
@@ -26,7 +27,7 @@ queue: connector-test"}
26
27
  end
27
28
 
28
29
  it "sends a message when a queue is specified" do
29
- connector = Cpi::Connector.new(YAML::load(yaml_config).symbolize_keys!)
30
+ connector = Cpi::Connector.new(YAML::load(yaml_config).symbolize_keys!, logger)
30
31
  connector.transmit("message", :queue => "my queue")
31
32
 
32
33
  b = Bunny.new
data/spec/spec_helper.rb CHANGED
@@ -2,4 +2,9 @@ require 'rspec'
2
2
 
3
3
  RSpec.configure do |config|
4
4
  config.color_enabled = true
5
+
6
+ config.before(:each) do
7
+ # make sure we get a new connector for every test
8
+ Thread.current[Cpi::THREAD_LOCAL_VARIABLE] = nil
9
+ end
5
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cpi-event-connector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.14
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-22 00:00:00.000000000 Z
12
+ date: 2012-08-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &23871620 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *23871620
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: backports
27
- requirement: &23871200 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *23871200
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: justinf-unification_assertion
38
- requirement: &23870780 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,21 +53,31 @@ dependencies:
43
53
  version: '0'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *23870780
47
- - !ruby/object:Gem::Dependency
48
- name: bunny
49
- requirement: &23870360 !ruby/object:Gem::Requirement
56
+ version_requirements: !ruby/object:Gem::Requirement
50
57
  none: false
51
58
  requirements:
52
59
  - - ! '>='
53
60
  - !ruby/object:Gem::Version
54
61
  version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: bunny
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 0.8.0
55
70
  type: :runtime
56
71
  prerelease: false
57
- version_requirements: *23870360
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 0.8.0
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: activesupport
60
- requirement: &23869860 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ~>
@@ -65,10 +85,15 @@ dependencies:
65
85
  version: '3'
66
86
  type: :runtime
67
87
  prerelease: false
68
- version_requirements: *23869860
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '3'
69
94
  - !ruby/object:Gem::Dependency
70
95
  name: uuidtools
71
- requirement: &23869360 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
72
97
  none: false
73
98
  requirements:
74
99
  - - ~>
@@ -76,7 +101,12 @@ dependencies:
76
101
  version: 2.1.2
77
102
  type: :runtime
78
103
  prerelease: false
79
- version_requirements: *23869360
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 2.1.2
80
110
  description: see summary
81
111
  email:
82
112
  - engineering@nulogy.com
@@ -99,7 +129,6 @@ files:
99
129
  - spec/generator_spec.rb
100
130
  - spec/integration_spec.rb
101
131
  - spec/spec_helper.rb
102
- - spec_helper.rb
103
132
  homepage: ''
104
133
  licenses: []
105
134
  post_install_message:
@@ -120,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
149
  version: '0'
121
150
  requirements: []
122
151
  rubyforge_project:
123
- rubygems_version: 1.8.10
152
+ rubygems_version: 1.8.24
124
153
  signing_key:
125
154
  specification_version: 3
126
155
  summary: Sends events to CPI
data/spec_helper.rb DELETED
@@ -1,7 +0,0 @@
1
- Dir[File.dirname(__FILE__) + "/spec/support/**/*.rb"].each {|f| require f}
2
-
3
- require 'rspec'
4
-
5
- RSpec.configure do |config|
6
- config.color_enabled = true
7
- end