Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

using now a single connection and no pool anymore

  • Loading branch information...
commit 34eaca50bbf8ca7bb38a8fcceafb8cd06369580c 1 parent 93ecb0a
@railsbros-dirk railsbros-dirk authored
View
6 Rakefile
@@ -19,7 +19,7 @@ DESCRIPTION
gem.add_dependency "bertrpc"
gem.add_dependency "json"
- gem.add_development_dependency "rspec"
+ gem.add_development_dependency "rspec", "~> 2.6.0"
gem.add_development_dependency "simple_publisher"
gem.add_development_dependency "beanstalk-client"
gem.add_development_dependency "em-jack"
@@ -29,6 +29,8 @@ rescue LoadError
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
end
+Jeweler::RubygemsDotOrgTasks.new
+
require 'spec/rake/spectask'
Spec::Rake::SpecTask.new(:spec) do |spec|
spec.libs << 'lib' << 'spec'
@@ -41,8 +43,6 @@ Spec::Rake::SpecTask.new(:rcov) do |spec|
spec.rcov = true
end
-task :spec => :check_dependencies
-
task :default => :spec
require 'rake/rdoctask'
View
14 lib/hoth/transport/beanstalkd.rb
@@ -10,12 +10,18 @@ module Transport
class Beanstalkd < Base
def call_remote_with(*args)
- connection = Beanstalk::Pool.new(["#{endpoint.host}:#{endpoint.port}"])
+ connection = Beanstalk::Connection.new("#{endpoint.host}:#{endpoint.port}")
connection.use(tube_name)
- encoded_args = encoder.encode(args)
- Rails.logger.debug "encoded_args: #{encoded_args}"
- connection.put encoded_args
+ begin
+ encoded_args = encoder.encode(args)
+ Hoth::Logger.debug "encoded_args: #{encoded_args}"
+ connection.put encoded_args
+ rescue => e
+ Hoth::Logger.warn "An error occured while sending a payload to beanstalkd: #{e.message}"
+ ensure
+ connection.close
+ end
end
def tube_name
View
61 spec/unit/transport/beanstalkd_spec.rb
@@ -0,0 +1,61 @@
+require File.expand_path(File.join(File.dirname(__FILE__), '../../', 'spec_helper'))
+
+module Hoth
+ module Transport
+
+ describe "Beanstalkd" do
+ before(:each) do
+ endpoint = mock("EndpointMock")
+ endpoint.stub(:host).and_return("localhost")
+ endpoint.stub(:port).and_return("11300")
+
+ service_module = mock("ServiceModule")
+ service_module.should_receive(:name).and_return(:test_service_module)
+
+ @service = mock("ServiceMock")
+ @service.should_receive(:name).and_return(:test_service)
+ @service.should_receive(:endpoint).any_number_of_times.and_return(endpoint)
+ @service.should_receive(:module).any_number_of_times.and_return(service_module)
+
+ @beanstalk_connection = mock("Beanstalk::Connection")
+ end
+
+ it "should send the payload over a simple Beanstalk::Connection and close the connection afterwards" do
+ Beanstalk::Connection.should_receive(:new).with("localhost:11300").and_return(@beanstalk_connection)
+ @beanstalk_connection.should_receive(:use).with(anything)
+ @beanstalk_connection.should_receive(:put).with(["some_data_to_send"])
+ @beanstalk_connection.should_receive(:close)
+
+ transport = Beanstalkd.new(@service)
+ transport.call_remote_with("some_data_to_send")
+ end
+
+ it "should ensure to close the connection after sending the payload to beanstalkd" do
+ Beanstalk::Connection.should_receive(:new).with("localhost:11300").and_return(@beanstalk_connection)
+ @beanstalk_connection.should_receive(:use).with(anything)
+ @beanstalk_connection.should_receive(:put).never
+ @beanstalk_connection.should_receive(:close)
+
+ transport = Beanstalkd.new(@service)
+ transport.encoder.should_receive(:encode).with(anything).and_raise("some error")
+ transport.call_remote_with("some_data_to_send")
+ end
+
+ it "should use the beanstalk tube specified by the transport" do
+ Beanstalk::Connection.should_receive(:new).with("localhost:11300").and_return(@beanstalk_connection)
+ transport = Beanstalkd.new(@service)
+ @beanstalk_connection.should_receive(:use).with(transport.tube_name)
+ @beanstalk_connection.should_receive(:put).with(["some_data_to_send"])
+ @beanstalk_connection.should_receive(:close)
+
+ transport.call_remote_with("some_data_to_send")
+ end
+
+ it "should define the tube_name according to the module and service name" do
+ transport = Beanstalkd.new(@service)
+ transport.tube_name.should == "test-service-module/test-service"
+ end
+ end
+
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.