Permalink
Browse files

Removed unused connection methods

  • Loading branch information...
1 parent e23789c commit c2c047c98308751d30e0d59b490f77c307cf807b @durran durran committed Feb 11, 2014
Showing with 4 additions and 91 deletions.
  1. +1 −36 lib/mongo/pool/connection.rb
  2. +3 −55 spec/mongo/pool/connection_spec.rb
@@ -26,9 +26,7 @@ class Connection
# @return [Integer] The port number (nil for unix sockets).
# @!attribute timeout
# @return [Integer] The socket timeout value in seconds.
- # @!attribute last_use
- # @return [Time.now] The most recent lease time for the connection.
- attr_reader :host, :port, :timeout, :last_use
+ attr_reader :host, :port, :timeout
# Initializes a new connected and ready-to-use Connection instance.
#
@@ -48,45 +46,12 @@ def initialize(host, port, timeout = nil, opts = {})
@host = host
@port = port
@timeout = timeout || TIMEOUT
- @last_use = nil
@socket = nil
@ssl_opts = opts.reject { |k, v| !k.to_s.start_with?('ssl') }
connect if opts.fetch(:connect, true)
self
end
- # Leases the connection and sets the last use time to now.
- #
- # @example
- # connection = Connection.new('::1', 27015)
- # connection.lease
- #
- def lease
- @last_use = Time.now
- end
-
- # Expires the lease and sets last use to nil.
- #
- # @example
- # connection = Connection.new('::1', 27015)
- # connection.lease
- # connection.expire
- #
- def expire
- @last_use = nil
- end
-
- # Indicates whether or not the lease has expired.
- #
- # @example
- # connection = Connection.new('::1', 27015)
- # connection.expired?
- #
- # @return [true, false] Boolean value indicating if the lease has
- def expired?
- @last_use.nil?
- end
-
# Create a socket a connected socket instance.
#
# @example
@@ -37,10 +37,6 @@
expect(connection.timeout).to eq(Mongo::Pool::Connection::TIMEOUT)
end
- it 'sets the last use to nil' do
- expect(connection.last_use).to be nil
- end
-
it 'sets the socket to nil' do
socket = connection.instance_variable_get(:@socket)
expect(socket).to be nil
@@ -53,14 +49,12 @@
it 'sets the timeout value' do
expect(connection.timeout).to eq(timeout)
end
-
end
- context 'when port is nil' do
+ pending 'when port is nil' do
it 'creates unix socket' do
end
-
end
context 'when options are provided' do
@@ -79,7 +73,6 @@
socket = conn.instance_variable_get(:@socket)
expect(socket).to be nil
end
-
end
context 'when :connect => true' do
@@ -96,7 +89,6 @@
socket = conn.instance_variable_get(:@socket)
expect(socket).to_not be nil
end
-
end
context 'when :connect is not specified' do
@@ -113,7 +105,6 @@
socket = conn.instance_variable_get(:@socket)
expect(socket).to_not be nil
end
-
end
context 'when ssl options are specified' do
@@ -126,44 +117,8 @@
expect(ssl_opts).to_not be nil
expect(ssl_opts.keys).to include :ssl
end
-
end
-
- end
-
- end
-
- describe '#lease' do
-
- it 'sets the lease time to now' do
- connection.lease
- expect(connection.last_use).to_not be nil
- end
-
- end
-
- describe '#expire' do
-
- it 'sets the lease time to nil' do
- connection.lease
- connection.expire
- expect(connection.last_use).to be nil
end
-
- end
-
- describe '#expired?' do
-
- it 'returns true when lease time is not set' do
- connection.expire
- expect(connection.expired?).to be true
- end
-
- it 'returns false when the lease time has been set' do
- connection.lease
- expect(connection.expired?).to be false
- end
-
end
describe '#connect' do
@@ -175,7 +130,6 @@
expect(Mongo::Pool::Socket::Unix).to receive(:new)
described_class.new(host, nil)
end
-
end
context 'when ssl_opts are present' do
@@ -187,15 +141,13 @@
expect(Mongo::Pool::Socket::SSL).to receive(:new)
described_class.new(host, port, nil, opts)
end
-
end
it 'creates a tcp socket instance by default' do
allow(Mongo::Pool::Socket::TCP).to receive(:new)
expect(Mongo::Pool::Socket::TCP).to receive(:new)
described_class.new(host, port)
end
-
end
describe '#disconnect' do
@@ -211,7 +163,6 @@
expect(Mongo::Pool::Socket::TCP).to_not receive(:close)
connection.disconnect
end
-
end
context 'when the socket has been set' do
@@ -221,25 +172,22 @@
expect(socket).to receive(:close)
connection.disconnect
end
-
end
it 'sets the socket to nil' do
connection.disconnect
socket = connection.instance_variable_get(:@socket)
expect(socket).to be nil
end
-
end
- describe '#read' do
+ pending '#read' do
# TODO: definite Operation and OperationResult so that we can figure out
# what needs to happen here.
end
- describe '#write' do
+ pending '#write' do
# TODO: definite Operation and OperationResult so that we can figure out
# what needs to happen here.
end
-
end

0 comments on commit c2c047c

Please sign in to comment.