Skip to content

Commit

Permalink
Merge pull request #9 from ping4/connection_pool_fixes
Browse files Browse the repository at this point in the history
Connection pool fixes
  • Loading branch information
outoftime committed Feb 25, 2013
2 parents 3e67b82 + 59fcb22 commit d404492
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/cequel/keyspace.rb
Expand Up @@ -54,10 +54,10 @@ def connection_pool
return @connection_pool if defined? @connection_pool
if @configuration[:pool]
options = {
:size => configuration[:pool],
:timeout => configuration[:pool_timeout]
:size => @configuration[:pool] || 10,
:timeout => @configuration[:pool_timeout] || 5
}
@connection_pool = ConnectionPool.new(:size => 10, :timeout => 5) do
@connection_pool = ConnectionPool.new(options) do
build_connection
end
else
Expand Down
23 changes: 22 additions & 1 deletion spec/examples/keyspace_spec.rb
Expand Up @@ -32,7 +32,6 @@
APPLY BATCH
CQL


cequel.batch(:auto_apply => 2) do
cequel[:posts].insert(:id => 1, :title => 'Hey')
cequel[:posts].update(:body => 'Body')
Expand All @@ -45,6 +44,28 @@
end
end

describe '::connection_pool' do
it 'should use connection pool if pool specified' do
#NOTE: called one time per pool entry
Cequel::Keyspace.any_instance.should_receive(:build_connection).once.and_return(connection)
Cequel::Keyspace.any_instance.should_receive(:connection).never
keyspace = Cequel::Keyspace.new(:pool => 1)

keyspace.with_connection { |conn| }
keyspace.with_connection { |conn| }
keyspace.with_connection { |conn| }
end

it 'should not use connection pool if no pool specified' do
Cequel::Keyspace.any_instance.should_receive(:connection).exactly(3).times.and_return(connection)
keyspace = Cequel::Keyspace.new({})

keyspace.with_connection { |conn| }
keyspace.with_connection { |conn| }
keyspace.with_connection { |conn| }
end
end

describe '::logger=' do
let(:io) { StringIO.new }
let(:logger) { Logger.new(io) }
Expand Down

0 comments on commit d404492

Please sign in to comment.