hoth 0.3.2.beta4 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,21 +1,25 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hoth (0.3.0)
4
+ hoth (0.3.2.beta6)
5
5
  activesupport
6
6
  bertrpc
7
+ hoth
7
8
  json
8
9
 
9
10
  GEM
10
11
  remote: http://rubygems.org/
11
12
  specs:
12
- activesupport (3.0.3)
13
+ activesupport (3.0.6)
14
+ beanstalk-client (1.1.0)
13
15
  bert (1.1.2)
14
16
  bertrpc (1.3.0)
15
- bert (>= 1.1.0, < 2.0.0)
17
+ bert (< 2.0.0, >= 1.1.0)
16
18
  diff-lcs (1.1.2)
19
+ em-jack (0.1.3)
20
+ eventmachine
17
21
  eventmachine (0.12.10)
18
- json (1.4.6)
22
+ json (1.5.1)
19
23
  memcache-client (1.8.5)
20
24
  rspec (2.4.0)
21
25
  rspec-core (~> 2.4.0)
@@ -37,9 +41,8 @@ PLATFORMS
37
41
  ruby
38
42
 
39
43
  DEPENDENCIES
40
- activesupport
41
- bertrpc
44
+ beanstalk-client
45
+ em-jack
42
46
  hoth!
43
- json
44
47
  rspec
45
48
  simple_publisher
@@ -9,18 +9,17 @@ module Hoth
9
9
 
10
10
  class BeanstalkdProvider
11
11
 
12
- def initialize
13
- @services_to_listen_for = Hoth::Modules.service_modules.values.inject([]) do |services, service_module|
14
- services << service_module.registered_services.select do |service|
15
- service.endpoint.transport == :beanstalkd
16
- end
17
- services.flatten
18
- end
12
+ attr_reader :module_name, :services_to_listen_for
13
+
14
+ def initialize(module_name = nil)
15
+ raise ArgumentError.new("You have to specify the module name for the beanstalkd provider") unless module_name
16
+ @module_name = module_name
17
+ identify_services_to_listen_for
19
18
  end
20
19
 
21
20
  def listen
22
21
  EM.run {
23
- @services_to_listen_for.each do |service|
22
+ self.services_to_listen_for.each do |service|
24
23
  conn_for_service = EMJack::Connection.new(:host => service.endpoint.host, :port => service.endpoint.port)
25
24
  conn_for_service.watch(service.transport.tube_name)
26
25
  conn_for_service.each_job do |job|
@@ -30,10 +29,10 @@ module Hoth
30
29
 
31
30
  begin
32
31
  decoded_params = responsible_service.transport.encoder.decode(job.body)
33
- Rails.logger.debug "decoded_params: #{decoded_params}"
32
+ Hoth::Logger.debug "decoded_params: #{decoded_params}"
34
33
  Hoth::Services.send(service.name, *decoded_params)
35
34
  rescue => e
36
- Rails.logger.warn "An error occured while invoking the service: #{e.message}"
35
+ Hoth::Logger.warn "An error occured while invoking the service: #{e.message}"
37
36
  ensure
38
37
  conn_for_service.delete(job)
39
38
  end
@@ -41,6 +40,14 @@ module Hoth
41
40
  end
42
41
  }
43
42
  end
43
+
44
+ private
45
+
46
+ def identify_services_to_listen_for
47
+ @services_to_listen_for = Hoth::Modules.service_modules[self.module_name.to_sym].registered_services.select do |service|
48
+ service.endpoint.transport == :beanstalkd
49
+ end
50
+ end
44
51
 
45
52
  end
46
53
 
@@ -9,11 +9,9 @@ module Hoth
9
9
  end
10
10
 
11
11
  def call(env)
12
- Hoth::Logger.debug "env: #{env.inspect}"
13
12
  if env["PATH_INFO"] =~ /^\/execute/
14
13
  begin
15
14
  req = Rack::Request.new(env)
16
- Hoth::Logger.debug "req: #{req.inspect}"
17
15
 
18
16
  service_name = req.params["name"]
19
17
  service_params = req.params["params"]
@@ -51,4 +49,4 @@ module Hoth
51
49
 
52
50
  end
53
51
  end
54
- end
52
+ end
@@ -10,12 +10,18 @@ module Hoth
10
10
  class Beanstalkd < Base
11
11
 
12
12
  def call_remote_with(*args)
13
- connection = Beanstalk::Pool.new(["#{endpoint.host}:#{endpoint.port}"])
13
+ connection = Beanstalk::Connection.new("#{endpoint.host}:#{endpoint.port}")
14
14
  connection.use(tube_name)
15
15
 
16
- encoded_args = encoder.encode(args)
17
- Rails.logger.debug "encoded_args: #{encoded_args}"
18
- connection.put encoded_args
16
+ begin
17
+ encoded_args = encoder.encode(args)
18
+ Hoth::Logger.debug "encoded_args: #{encoded_args}"
19
+ connection.put encoded_args
20
+ rescue => e
21
+ Hoth::Logger.warn "An error occured while sending a payload to beanstalkd: #{e.message}"
22
+ ensure
23
+ connection.close
24
+ end
19
25
  end
20
26
 
21
27
  def tube_name
@@ -0,0 +1,39 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '../../', 'spec_helper'))
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), '../../../', 'lib', 'hoth', 'providers', 'beanstalkd_provider'))
4
+
5
+ require 'rack/mock'
6
+
7
+ module Hoth
8
+ module Providers
9
+ describe BeanstalkdProvider do
10
+
11
+ it "should know its module name" do
12
+ # cannot be tested since i do not know how to mock constructor call
13
+ # http://stackoverflow.com/questions/5270819/how-to-test-a-method-call-in-a-constructor-with-rspec
14
+ # Hoth::Providers::BeanstalkdProvider.any_instance.stub!(:identify_services_to_listen_for)
15
+ # beanstalkd_provider = Hoth::Providers::BeanstalkdProvider.new("foo_module")
16
+ # beanstalkd_provider.module_name.should == "foo_module"
17
+ end
18
+
19
+ it "should throw an error if no module name is passed" do
20
+ lambda { Hoth::Providers::BeanstalkdProvider.new }.should raise_error(ArgumentError)
21
+ end
22
+
23
+ it "should only listen for services defined for the passed module name" do
24
+ mail_module = Hoth::ServiceModule.new(:name => "mail_module")
25
+ mail_module.should_not_receive(:registered_services)
26
+ foo_module = Hoth::ServiceModule.new(:name => "foo_module")
27
+ service = mock("RegisteredService")
28
+ service.stub_chain(:endpoint, :transport).and_return :beanstalkd
29
+ foo_module.should_receive(:registered_services).and_return([service])
30
+ Hoth::Modules.should_receive(:service_modules).and_return({
31
+ :mail_module => mail_module,
32
+ :foo_module => foo_module
33
+ })
34
+ beanstalkd_provider = Hoth::Providers::BeanstalkdProvider.new("foo_module")
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,61 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '../../', 'spec_helper'))
2
+
3
+ module Hoth
4
+ module Transport
5
+
6
+ describe "Beanstalkd" do
7
+ before(:each) do
8
+ endpoint = mock("EndpointMock")
9
+ endpoint.stub(:host).and_return("localhost")
10
+ endpoint.stub(:port).and_return("11300")
11
+
12
+ service_module = mock("ServiceModule")
13
+ service_module.should_receive(:name).and_return(:test_service_module)
14
+
15
+ @service = mock("ServiceMock")
16
+ @service.should_receive(:name).and_return(:test_service)
17
+ @service.should_receive(:endpoint).any_number_of_times.and_return(endpoint)
18
+ @service.should_receive(:module).any_number_of_times.and_return(service_module)
19
+
20
+ @beanstalk_connection = mock("Beanstalk::Connection")
21
+ end
22
+
23
+ it "should send the payload over a simple Beanstalk::Connection and close the connection afterwards" do
24
+ Beanstalk::Connection.should_receive(:new).with("localhost:11300").and_return(@beanstalk_connection)
25
+ @beanstalk_connection.should_receive(:use).with(anything)
26
+ @beanstalk_connection.should_receive(:put).with(["some_data_to_send"])
27
+ @beanstalk_connection.should_receive(:close)
28
+
29
+ transport = Beanstalkd.new(@service)
30
+ transport.call_remote_with("some_data_to_send")
31
+ end
32
+
33
+ it "should ensure to close the connection after sending the payload to beanstalkd" do
34
+ Beanstalk::Connection.should_receive(:new).with("localhost:11300").and_return(@beanstalk_connection)
35
+ @beanstalk_connection.should_receive(:use).with(anything)
36
+ @beanstalk_connection.should_receive(:put).never
37
+ @beanstalk_connection.should_receive(:close)
38
+
39
+ transport = Beanstalkd.new(@service)
40
+ transport.encoder.should_receive(:encode).with(anything).and_raise("some error")
41
+ transport.call_remote_with("some_data_to_send")
42
+ end
43
+
44
+ it "should use the beanstalk tube specified by the transport" do
45
+ Beanstalk::Connection.should_receive(:new).with("localhost:11300").and_return(@beanstalk_connection)
46
+ transport = Beanstalkd.new(@service)
47
+ @beanstalk_connection.should_receive(:use).with(transport.tube_name)
48
+ @beanstalk_connection.should_receive(:put).with(["some_data_to_send"])
49
+ @beanstalk_connection.should_receive(:close)
50
+
51
+ transport.call_remote_with("some_data_to_send")
52
+ end
53
+
54
+ it "should define the tube_name according to the module and service name" do
55
+ transport = Beanstalkd.new(@service)
56
+ transport.tube_name.should == "test-service-module/test-service"
57
+ end
58
+ end
59
+
60
+ end
61
+ end
metadata CHANGED
@@ -1,15 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hoth
3
3
  version: !ruby/object:Gem::Version
4
- hash: 62196363
5
- prerelease: 6
4
+ hash: 21
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 2
10
- - beta
11
- - 4
12
- version: 0.3.2.beta4
9
+ - 3
10
+ version: 0.3.3
13
11
  platform: ruby
14
12
  authors:
15
13
  - Dirk Breuer
@@ -17,12 +15,10 @@ autorequire:
17
15
  bindir: bin
18
16
  cert_chain: []
19
17
 
20
- date: 2011-01-12 00:00:00 +01:00
21
- default_executable:
18
+ date: 2011-05-27 00:00:00 Z
22
19
  dependencies:
23
20
  - !ruby/object:Gem::Dependency
24
- name: activesupport
25
- prerelease: false
21
+ type: :runtime
26
22
  requirement: &id001 !ruby/object:Gem::Requirement
27
23
  none: false
28
24
  requirements:
@@ -32,25 +28,27 @@ dependencies:
32
28
  segments:
33
29
  - 0
34
30
  version: "0"
35
- type: :runtime
31
+ prerelease: false
36
32
  version_requirements: *id001
33
+ name: hoth
37
34
  - !ruby/object:Gem::Dependency
38
- name: bertrpc
39
- prerelease: false
35
+ type: :development
40
36
  requirement: &id002 !ruby/object:Gem::Requirement
41
37
  none: false
42
38
  requirements:
43
- - - ">="
39
+ - - ~>
44
40
  - !ruby/object:Gem::Version
45
- hash: 3
41
+ hash: 23
46
42
  segments:
43
+ - 2
44
+ - 6
47
45
  - 0
48
- version: "0"
49
- type: :runtime
46
+ version: 2.6.0
47
+ prerelease: false
50
48
  version_requirements: *id002
49
+ name: rspec
51
50
  - !ruby/object:Gem::Dependency
52
- name: json
53
- prerelease: false
51
+ type: :development
54
52
  requirement: &id003 !ruby/object:Gem::Requirement
55
53
  none: false
56
54
  requirements:
@@ -60,11 +58,11 @@ dependencies:
60
58
  segments:
61
59
  - 0
62
60
  version: "0"
63
- type: :runtime
61
+ prerelease: false
64
62
  version_requirements: *id003
63
+ name: simple_publisher
65
64
  - !ruby/object:Gem::Dependency
66
- name: rspec
67
- prerelease: false
65
+ type: :development
68
66
  requirement: &id004 !ruby/object:Gem::Requirement
69
67
  none: false
70
68
  requirements:
@@ -74,11 +72,11 @@ dependencies:
74
72
  segments:
75
73
  - 0
76
74
  version: "0"
77
- type: :development
75
+ prerelease: false
78
76
  version_requirements: *id004
77
+ name: beanstalk-client
79
78
  - !ruby/object:Gem::Dependency
80
- name: simple_publisher
81
- prerelease: false
79
+ type: :development
82
80
  requirement: &id005 !ruby/object:Gem::Requirement
83
81
  none: false
84
82
  requirements:
@@ -88,11 +86,11 @@ dependencies:
88
86
  segments:
89
87
  - 0
90
88
  version: "0"
91
- type: :development
89
+ prerelease: false
92
90
  version_requirements: *id005
91
+ name: em-jack
93
92
  - !ruby/object:Gem::Dependency
94
- name: beanstalk-client
95
- prerelease: false
93
+ type: :runtime
96
94
  requirement: &id006 !ruby/object:Gem::Requirement
97
95
  none: false
98
96
  requirements:
@@ -102,11 +100,11 @@ dependencies:
102
100
  segments:
103
101
  - 0
104
102
  version: "0"
105
- type: :development
103
+ prerelease: false
106
104
  version_requirements: *id006
105
+ name: activesupport
107
106
  - !ruby/object:Gem::Dependency
108
- name: em-jack
109
- prerelease: false
107
+ type: :runtime
110
108
  requirement: &id007 !ruby/object:Gem::Requirement
111
109
  none: false
112
110
  requirements:
@@ -116,8 +114,81 @@ dependencies:
116
114
  segments:
117
115
  - 0
118
116
  version: "0"
119
- type: :development
117
+ prerelease: false
120
118
  version_requirements: *id007
119
+ name: bertrpc
120
+ - !ruby/object:Gem::Dependency
121
+ type: :runtime
122
+ requirement: &id008 !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ hash: 3
128
+ segments:
129
+ - 0
130
+ version: "0"
131
+ prerelease: false
132
+ version_requirements: *id008
133
+ name: json
134
+ - !ruby/object:Gem::Dependency
135
+ type: :development
136
+ requirement: &id009 !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ~>
140
+ - !ruby/object:Gem::Version
141
+ hash: 23
142
+ segments:
143
+ - 2
144
+ - 6
145
+ - 0
146
+ version: 2.6.0
147
+ prerelease: false
148
+ version_requirements: *id009
149
+ name: rspec
150
+ - !ruby/object:Gem::Dependency
151
+ type: :development
152
+ requirement: &id010 !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ hash: 3
158
+ segments:
159
+ - 0
160
+ version: "0"
161
+ prerelease: false
162
+ version_requirements: *id010
163
+ name: simple_publisher
164
+ - !ruby/object:Gem::Dependency
165
+ type: :development
166
+ requirement: &id011 !ruby/object:Gem::Requirement
167
+ none: false
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ hash: 3
172
+ segments:
173
+ - 0
174
+ version: "0"
175
+ prerelease: false
176
+ version_requirements: *id011
177
+ name: beanstalk-client
178
+ - !ruby/object:Gem::Dependency
179
+ type: :development
180
+ requirement: &id012 !ruby/object:Gem::Requirement
181
+ none: false
182
+ requirements:
183
+ - - ">="
184
+ - !ruby/object:Gem::Version
185
+ hash: 3
186
+ segments:
187
+ - 0
188
+ version: "0"
189
+ prerelease: false
190
+ version_requirements: *id012
191
+ name: em-jack
121
192
  description: |
122
193
  Creating a SOA requires a centralized location to define all services within the
123
194
  SOA. Furthermore you want to know where to deploy those services.
@@ -163,23 +234,24 @@ files:
163
234
  - spec/unit/endpoint_spec.rb
164
235
  - spec/unit/extension/core/exception_spec.rb
165
236
  - spec/unit/hoth_spec.rb
237
+ - spec/unit/providers/beanstalkd_provider_spec.rb
166
238
  - spec/unit/providers/rack_provider_spec.rb
167
239
  - spec/unit/service_definition_spec.rb
168
240
  - spec/unit/service_module_spec.rb
169
241
  - spec/unit/service_spec.rb
170
242
  - spec/unit/transport/base_spec.rb
243
+ - spec/unit/transport/beanstalkd_spec.rb
171
244
  - spec/unit/transport/http_spec.rb
172
245
  - spec/unit/transport/workling_spec.rb
173
246
  - spec/unit/transport_spec.rb
174
247
  - LICENSE
175
248
  - TODO
176
- has_rdoc: true
177
249
  homepage: http://github.com/galaxycats/hoth
178
250
  licenses: []
179
251
 
180
252
  post_install_message:
181
- rdoc_options:
182
- - --charset=UTF-8
253
+ rdoc_options: []
254
+
183
255
  require_paths:
184
256
  - lib
185
257
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -194,32 +266,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
194
266
  required_rubygems_version: !ruby/object:Gem::Requirement
195
267
  none: false
196
268
  requirements:
197
- - - ">"
269
+ - - ">="
198
270
  - !ruby/object:Gem::Version
199
- hash: 25
271
+ hash: 3
200
272
  segments:
201
- - 1
202
- - 3
203
- - 1
204
- version: 1.3.1
273
+ - 0
274
+ version: "0"
205
275
  requirements: []
206
276
 
207
277
  rubyforge_project:
208
- rubygems_version: 1.4.1
278
+ rubygems_version: 1.8.4
209
279
  signing_key:
210
280
  specification_version: 3
211
281
  summary: Registry and deployment description abstraction for SOA-Services
212
- test_files:
213
- - spec/spec_helper.rb
214
- - spec/unit/encoding/json_spec.rb
215
- - spec/unit/endpoint_spec.rb
216
- - spec/unit/extension/core/exception_spec.rb
217
- - spec/unit/hoth_spec.rb
218
- - spec/unit/providers/rack_provider_spec.rb
219
- - spec/unit/service_definition_spec.rb
220
- - spec/unit/service_module_spec.rb
221
- - spec/unit/service_spec.rb
222
- - spec/unit/transport/base_spec.rb
223
- - spec/unit/transport/http_spec.rb
224
- - spec/unit/transport/workling_spec.rb
225
- - spec/unit/transport_spec.rb
282
+ test_files: []
283
+