Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

RUBY-494 rename all the things! standardizing class names across drivers

Mongo::Connection -> Mongo::MongoClient
Mongo::ReplSetConnection -> Mongo::MongoReplicaSetClient
Mongo::ShardedConnection -> Mongo::MongoShardedClient
  • Loading branch information...
commit d3563557f0e55d310d7678085a13f1d06845f63e 1 parent eedcf8e
@brandonblack brandonblack authored
Showing with 270 additions and 270 deletions.
  1. +9 −9 README.md
  2. +2 −2 bin/mongo_console
  3. +2 −2 examples/admin.rb
  4. +2 −2 examples/capped.rb
  5. +2 −2 examples/cursor.rb
  6. +2 −2 examples/gridfs.rb
  7. +2 −2 examples/index_test.rb
  8. +2 −2 examples/info.rb
  9. +2 −2 examples/queries.rb
  10. +1 −1  examples/replica_set.rb
  11. +2 −2 examples/simple.rb
  12. +2 −2 examples/strict.rb
  13. +2 −2 examples/types.rb
  14. +1 −1  examples/web/thin/load.rb
  15. +1 −1  examples/web/unicorn/load.rb
  16. +1 −1  examples/web/unicorn/unicorn.rb.template
  17. +3 −3 lib/mongo.rb
  18. +6 −6 lib/mongo/db.rb
  19. +2 −2 lib/mongo/gridfs/grid.rb
  20. +2 −2 lib/mongo/gridfs/grid_file_system.rb
  21. +6 −6 lib/mongo/legacy.rb
  22. +24 −24 lib/mongo/{client.rb → mongo_client.rb}
  23. +17 −17 lib/mongo/{repl_set_client.rb → mongo_replica_set_client.rb}
  24. +6 −6 lib/mongo/{sharded_client.rb → mongo_sharded_client.rb}
  25. +2 −2 lib/mongo/networking.rb
  26. +1 −1  lib/mongo/util/node.rb
  27. +7 −7 lib/mongo/util/uri_parser.rb
  28. +1 −1  tasks/benchmark/batch_size_benchmark
  29. +1 −1  tasks/benchmark/exp_series.rb
  30. +1 −1  tasks/benchmark/gridstore_benchmark
  31. +1 −1  tasks/benchmark/profile_array.rb
  32. +2 −2 tasks/benchmark/standard_benchmark
  33. +2 −2 tasks/testing.rake
  34. +1 −1  test/auxillary/1.4_feature_test.rb
  35. +1 −1  test/auxillary/authentication_test.rb
  36. +1 −1  test/auxillary/autoreconnect_test.rb
  37. +3 −3 test/auxillary/repl_set_auth_test.rb
  38. +5 −5 test/auxillary/slave_connection_test.rb
  39. +2 −2 test/functional/collection_test.rb
  40. +11 −11 test/functional/connection_test.rb
  41. +2 −2 test/functional/db_connection_test.rb
  42. +2 −2 test/functional/db_test.rb
  43. +11 −11 test/replica_set/basic_test.rb
  44. +22 −22 test/replica_set/client_test.rb
  45. +2 −2 test/replica_set/complex_connect_test.rb
  46. +2 −2 test/replica_set/count_test.rb
  47. +3 −3 test/replica_set/cursor_test.rb
  48. +1 −1  test/replica_set/insert_test.rb
  49. +1 −1  test/replica_set/query_test.rb
  50. +6 −6 test/replica_set/refresh_test.rb
  51. +2 −2 test/replica_set/replication_ack_test.rb
  52. +5 −5 test/sharded_cluster/basic_test.rb
  53. +2 −2 test/test_helper.rb
  54. +4 −4 test/tools/mongo_config.rb
  55. +2 −2 test/tools/mongo_config_test.rb
  56. +30 −30 test/unit/client_test.rb
  57. +11 −11 test/unit/collection_test.rb
  58. +1 −1  test/unit/connection_test.rb
  59. +2 −2 test/unit/cursor_test.rb
  60. +2 −2 test/unit/grid_test.rb
  61. +7 −7 test/unit/node_test.rb
  62. +1 −1  test/unit/pool_manager_test.rb
  63. +3 −3 test/unit/read_test.rb
  64. +3 −3 test/unit/write_concern_test.rb
View
18 README.md
@@ -47,7 +47,7 @@ Here's a quick code sample. Again, see the [MongoDB Ruby Tutorial](https://githu
require 'rubygems'
require 'mongo'
-@client = Mongo::Client.new('localhost', 27017)
+@client = Mongo::MongoClient.new('localhost', 27017)
@db = @client['sample-db']
@coll = @db['test']
@@ -154,7 +154,7 @@ timeout for waiting for old connections to be released to the pool.
To set up a pooled connection to a single MongoDB instance:
```ruby
- @client = Client.new("localhost", 27017, :pool_size => 5, :timeout => 5)
+ @client = MongoClient.new("localhost", 27017, :pool_size => 5, :timeout => 5)
```
Though the pooling architecture will undoubtedly evolve, it currently owes much credit
@@ -168,13 +168,13 @@ of v1.3.0, the Ruby driver detects forking and reconnects automatically.
## Environment variable `MONGODB_URI`
-`Mongo::Client.from_uri`, `Mongo::Client.new` and `Mongo::ReplSetClient.new` will use <code>ENV["MONGODB_URI"]</code> if no other args are provided.
+`Mongo::MongoClient.from_uri`, `Mongo::MongoClient.new` and `Mongo::MongoReplicaSetClient.new` will use <code>ENV["MONGODB_URI"]</code> if no other args are provided.
The URI must fit this specification:
mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]
-If the type of connection (direct or replica set) should be determined entirely from <code>ENV["MONGODB_URI"]</code>, you may want to use `Mongo::Client.from_uri` because it will return either `Mongo::Client` or a `Mongo::ReplSetClient` depending on how many hosts are specified. Trying to use `Mongo::Client.new` with multiple hosts in <code>ENV["MONGODB_URI"]</code> will raise an exception.
+If the type of connection (direct or replica set) should be determined entirely from <code>ENV["MONGODB_URI"]</code>, you may want to use `Mongo::MongoClient.from_uri` because it will return either `Mongo::MongoClient` or a `Mongo::MongoReplicaSetClient` depending on how many hosts are specified. Trying to use `Mongo::MongoClient.new` with multiple hosts in <code>ENV["MONGODB_URI"]</code> will raise an exception.
## String Encoding
@@ -204,10 +204,10 @@ generate _id values. If you want to control _id values or even their types,
using a PK factory lets you do so.
You can tell the Ruby Mongo driver how to create primary keys by passing in
-the :pk option to the Client#db method.
+the :pk option to the MongoClient#db method.
```ruby
-db = Mongo::Client.new('localhost', 27017).db('dbname', :pk => MyPKFactory.new)
+db = Mongo::MongoClient.new('localhost', 27017).db('dbname', :pk => MyPKFactory.new)
```
A primary key factory object must respond to :create_pk, which should
@@ -263,7 +263,7 @@ To turn on strict mode, either pass in :strict => true when obtaining a DB
object or call the `:strict=` method:
```ruby
-db = Client.new('localhost', 27017).db('dbname', :strict => true)
+db = MongoClient.new('localhost', 27017).db('dbname', :strict => true)
# I'm feeling lax
db.strict = false
# No, I'm not!
@@ -287,10 +287,10 @@ Notes:
## Socket timeouts
The Ruby driver support timeouts on socket read operations. To enable them, set the
-`:op_timeout` option when you create a `Mongo::Client` object.
+`:op_timeout` option when you create a `Mongo::MongoClient` object.
If implementing higher-level timeouts, using tools like `Rack::Timeout`, it's very important
-to call `Mongo::Client#close` to prevent the subsequent operation from receiving the previous
+to call `Mongo::MongoClient#close` to prevent the subsequent operation from receiving the previous
request.
# Testing
View
4 bin/mongo_console
@@ -10,11 +10,11 @@ require 'mongo'
include Mongo
host = org_argv[0] || ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
-port = org_argv[1] || ENV['MONGO_RUBY_DRIVER_PORT'] || Client::DEFAULT_PORT
+port = org_argv[1] || ENV['MONGO_RUBY_DRIVER_PORT'] || MongoClient::DEFAULT_PORT
dbnm = org_argv[2] || ENV['MONGO_RUBY_DRIVER_DB'] || 'ruby-mongo-console'
puts "Connecting to #{host}:#{port} (CLIENT) on with database #{dbnm} (DB)"
-CLIENT = Client.new(host, port)
+CLIENT = MongoClient.new(host, port)
DB = CLIENT.db(dbnm)
puts "Starting IRB session..."
View
4 examples/admin.rb
@@ -6,10 +6,10 @@
include Mongo
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
-port = ENV['MONGO_RUBY_DRIVER_PORT'] || Client::DEFAULT_PORT
+port = ENV['MONGO_RUBY_DRIVER_PORT'] || MongoClient::DEFAULT_PORT
puts "Connecting to #{host}:#{port}"
-client = Mongo::Client.new(host, port)
+client = Mongo::MongoClient.new(host, port)
db = client.db('ruby-mongo-examples')
coll = db.create_collection('test')
View
4 examples/capped.rb
@@ -4,10 +4,10 @@
include Mongo
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
-port = ENV['MONGO_RUBY_DRIVER_PORT'] || Client::DEFAULT_PORT
+port = ENV['MONGO_RUBY_DRIVER_PORT'] || MongoClient::DEFAULT_PORT
puts "Connecting to #{host}:#{port}"
-db = Client.new(host, port).db('ruby-mongo-examples')
+db = MongoClient.new(host, port).db('ruby-mongo-examples')
db.drop_collection('test')
# A capped collection has a max size and, optionally, a max number of records.
View
4 examples/cursor.rb
@@ -6,10 +6,10 @@
include Mongo
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
-port = ENV['MONGO_RUBY_DRIVER_PORT'] || Client::DEFAULT_PORT
+port = ENV['MONGO_RUBY_DRIVER_PORT'] || MongoClient::DEFAULT_PORT
puts "Connecting to #{host}:#{port}"
-db = Client.new(host, port).db('ruby-mongo-examples')
+db = MongoClient.new(host, port).db('ruby-mongo-examples')
coll = db.collection('test')
# Erase all records from collection, if any
View
4 examples/gridfs.rb
@@ -7,10 +7,10 @@ def assert
include Mongo
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
-port = ENV['MONGO_RUBY_DRIVER_PORT'] || Client::DEFAULT_PORT
+port = ENV['MONGO_RUBY_DRIVER_PORT'] || MongoClient::DEFAULT_PORT
puts "Connecting to #{host}:#{port}"
-db = Client.new(host, port).db('ruby-mongo-examples')
+db = MongoClient.new(host, port).db('ruby-mongo-examples')
data = "hello, world!"
View
4 examples/index_test.rb
@@ -5,10 +5,10 @@
include Mongo
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
-port = ENV['MONGO_RUBY_DRIVER_PORT'] || Client::DEFAULT_PORT
+port = ENV['MONGO_RUBY_DRIVER_PORT'] || MongoClient::DEFAULT_PORT
puts ">> Connecting to #{host}:#{port}"
-db = Client.new(host, port).db('ruby-mongo-index_test')
+db = MongoClient.new(host, port).db('ruby-mongo-index_test')
class Exception
def errmsg
View
4 examples/info.rb
@@ -5,10 +5,10 @@
include Mongo
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
-port = ENV['MONGO_RUBY_DRIVER_PORT'] || Client::DEFAULT_PORT
+port = ENV['MONGO_RUBY_DRIVER_PORT'] || MongoClient::DEFAULT_PORT
puts "Connecting to #{host}:#{port}"
-db = Client.new(host, port).db('ruby-mongo-examples')
+db = MongoClient.new(host, port).db('ruby-mongo-examples')
coll = db.collection('test')
# Erase all records from collection, if any
View
4 examples/queries.rb
@@ -6,10 +6,10 @@
include Mongo
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
-port = ENV['MONGO_RUBY_DRIVER_PORT'] || Client::DEFAULT_PORT
+port = ENV['MONGO_RUBY_DRIVER_PORT'] || MongoClient::DEFAULT_PORT
puts "Connecting to #{host}:#{port}"
-db = Client.new(host, port).db('ruby-mongo-examples')
+db = MongoClient.new(host, port).db('ruby-mongo-examples')
coll = db.collection('test')
# Remove all records, if any
View
2  examples/replica_set.rb
@@ -4,7 +4,7 @@
cons = []
10.times do
- cons << Mongo::ReplSetClient(['localhost:27017'], :read => :secondary)
+ cons << Mongo::MongoReplicaSetClient(['localhost:27017'], :read => :secondary)
end
ports = cons.map do |con|
View
4 examples/simple.rb
@@ -6,10 +6,10 @@
include Mongo
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
-port = ENV['MONGO_RUBY_DRIVER_PORT'] || Client::DEFAULT_PORT
+port = ENV['MONGO_RUBY_DRIVER_PORT'] || MongoClient::DEFAULT_PORT
puts "Connecting to #{host}:#{port}"
-db = Client.new(host, port).db('ruby-mongo-examples')
+db = MongoClient.new(host, port).db('ruby-mongo-examples')
coll = db.collection('test')
# Erase all records from collection, if any
View
4 examples/strict.rb
@@ -5,10 +5,10 @@
include Mongo
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
-port = ENV['MONGO_RUBY_DRIVER_PORT'] || Client::DEFAULT_PORT
+port = ENV['MONGO_RUBY_DRIVER_PORT'] || MongoClient::DEFAULT_PORT
puts "Connecting to #{host}:#{port}"
-db = Client.new(host, port).db('ruby-mongo-examples')
+db = MongoClient.new(host, port).db('ruby-mongo-examples')
db.drop_collection('does-not-exist')
db.create_collection('test')
View
4 examples/types.rb
@@ -6,10 +6,10 @@
include Mongo
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
-port = ENV['MONGO_RUBY_DRIVER_PORT'] || Client::DEFAULT_PORT
+port = ENV['MONGO_RUBY_DRIVER_PORT'] || MongoClient::DEFAULT_PORT
puts "Connecting to #{host}:#{port}"
-db = Client.new(host, port).db('ruby-mongo-examples')
+db = MongoClient.new(host, port).db('ruby-mongo-examples')
coll = db.collection('test')
# Remove all records, if any
View
2  examples/web/thin/load.rb
@@ -1,7 +1,7 @@
require File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'mongo')
require 'logger'
-$con = Mongo::ReplSetClient.new(['localhost:30000', 'localhost:30001'], :read => :secondary, :refresh_mode => :sync, :refresh_interval => 30)
+$con = Mongo::MongoReplicaSetClient.new(['localhost:30000', 'localhost:30001'], :read => :secondary, :refresh_mode => :sync, :refresh_interval => 30)
$db = $con['foo']
class Load < Sinatra::Base
View
2  examples/web/unicorn/load.rb
@@ -1,6 +1,6 @@
require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'mongo')
-$client = Mongo::Client.new('localhost', 27017)
+$client = Mongo::MongoClient.new('localhost', 27017)
$db = $client['foo']
class Load < Sinatra::Base
View
2  examples/web/unicorn/unicorn.rb.template
@@ -23,7 +23,7 @@ stdout_path "#{@dir}log/unicorn.stdout.log"
# NOTE: You need this when using forking web servers!
after_fork do |server, worker|
$client.close if $client
- $client = Mongo::Client.new('localhost', 27017)
+ $client = Mongo::MongoClient.new('localhost', 27017)
$db = $client['foo']
STDERR << "FORKED #{server} #{worker}"
end
View
6 lib/mongo.rb
@@ -66,9 +66,9 @@ module Constants
require 'mongo/networking'
-require 'mongo/client'
-require 'mongo/repl_set_client'
-require 'mongo/sharded_client'
+require 'mongo/mongo_client'
+require 'mongo/mongo_replica_set_client'
+require 'mongo/mongo_sharded_client'
require 'mongo/legacy'
require 'mongo/collection'
require 'mongo/cursor'
View
12 lib/mongo/db.rb
@@ -48,7 +48,7 @@ def strict?; @strict; end
# The name of the database and the local write concern options.
attr_reader :name, :write_concern
- # The Mongo::Client instance connecting to the MongoDB server.
+ # The Mongo::MongoClient instance connecting to the MongoDB server.
attr_reader :connection
# The length of time that Collection.ensure_index should cache index calls
@@ -60,8 +60,8 @@ def strict?; @strict; end
# Instances of DB are normally obtained by calling Mongo#db.
#
# @param [String] name the database name.
- # @param [Mongo::Client] client a connection object pointing to MongoDB. Note
- # that databases are usually instantiated via the Client class. See the examples below.
+ # @param [Mongo::MongoClient] client a connection object pointing to MongoDB. Note
+ # that databases are usually instantiated via the MongoClient class. See the examples below.
#
# @option opts [Boolean] :strict (False) If true, collections must exist to be accessed and must
# not exist to be created. See DB#collection and DB#create_collection.
@@ -73,7 +73,7 @@ def strict?; @strict; end
#
# @option opts [Hash] :w, :j, :wtimeout, :fsync Set the default write concern for this database.
# Propagated to Collection objects instantiated off of this DB. If no
- # options are provided, the default write concern set on this instance's Client object will be used. This
+ # options are provided, the default write concern set on this instance's MongoClient object will be used. This
# default can be overridden upon instantiation of any collection by explicitly setting write concern values
# on initialization
#
@@ -105,7 +105,7 @@ def initialize(name, client, opts={})
# @param [String] username
# @param [String] password
# @param [Boolean] save_auth
- # Save this authentication to the client object using Client#add_auth. This
+ # Save this authentication to the client object using MongoClient#add_auth. This
# will ensure that the authentication will be applied on database reconnect. Note
# that this value must be true when using connection pooling.
#
@@ -215,7 +215,7 @@ def remove_user(username)
end
# Deauthorizes use for this database for this client connection. Also removes
- # any saved authentication in the Client class associated with this
+ # any saved authentication in the MongoClient class associated with this
# database.
#
# @raise [MongoDBError] if logging out fails.
View
4 lib/mongo/gridfs/grid.rb
@@ -40,8 +40,8 @@ def initialize(db, fs_name=DEFAULT_FS_NAME)
# Create indexes only if we're connected to a primary node.
connection = @db.connection
- if (connection.class == Client && connection.read_primary?) ||
- (connection.class == ReplSetClient && connection.primary)
+ if (connection.class == MongoClient && connection.read_primary?) ||
+ (connection.class == MongoReplicaSetClient && connection.primary)
@chunks.create_index([['files_id', Mongo::ASCENDING], ['n', Mongo::ASCENDING]], :unique => true)
end
end
View
4 lib/mongo/gridfs/grid_file_system.rb
@@ -41,8 +41,8 @@ def initialize(db, fs_name=Grid::DEFAULT_FS_NAME)
# Create indexes only if we're connected to a primary node.
connection = @db.connection
- if (connection.class == Client && connection.read_primary?) ||
- (connection.class == ReplSetClient && connection.primary)
+ if (connection.class == MongoClient && connection.read_primary?) ||
+ (connection.class == MongoReplicaSetClient && connection.primary)
@files.create_index([['filename', 1], ['uploadDate', -1]])
@chunks.create_index([['files_id', Mongo::ASCENDING], ['n', Mongo::ASCENDING]], :unique => true)
end
View
12 lib/mongo/legacy.rb
@@ -42,8 +42,8 @@ def self.from_uri(uri = ENV['MONGODB_URI'], extra_opts={})
end
module Mongo
- # @deprecated Use Mongo::Client instead. Support will be removed after v2.0
- class Connection < Client
+ # @deprecated Use Mongo::MongoClient instead. Support will be removed after v2.0
+ class Connection < MongoClient
include Mongo::LegacyWriteConcern
def initialize(host=nil, port=nil, opts={})
@@ -52,8 +52,8 @@ def initialize(host=nil, port=nil, opts={})
end
end
- # @deprecated Use Mongo::ReplSetClient instead. Support will be removed after v2.0
- class ReplSetConnection < ReplSetClient
+ # @deprecated Use Mongo::MongoReplicaSetClient instead. Support will be removed after v2.0
+ class ReplSetConnection < MongoReplicaSetClient
include Mongo::LegacyWriteConcern
def initialize(*args)
@@ -66,8 +66,8 @@ def initialize(*args)
end
end
- # @deprecated Use Mongo::ShardedClient instead. Support will be removed after v2.0
- class ShardedConnection < ShardedClient
+ # @deprecated Use Mongo::MongoShardedClient instead. Support will be removed after v2.0
+ class ShardedConnection < MongoShardedClient
include Mongo::LegacyWriteConcern
def initialize(*args)
View
48 lib/mongo/client.rb → lib/mongo/mongo_client.rb
@@ -23,7 +23,7 @@
module Mongo
# Instantiates and manages self.connections to MongoDB.
- class Client
+ class MongoClient
include Mongo::Logging
include Mongo::Networking
include Mongo::WriteConcern
@@ -65,18 +65,18 @@ class Client
# You may specify whether connection to slave is permitted.
# In all cases, the default host is "localhost" and the default port is 27017.
#
- # If you're connecting to a replica set, you'll need to use ReplSetClient.new instead.
+ # If you're connecting to a replica set, you'll need to use MongoReplicaSetClient.new instead.
#
# Once connected to a replica set, you can find out which nodes are primary, secondary, and
- # arbiters with the corresponding accessors: Client#primary, Client#secondaries, and
- # Client#arbiters. This is useful if your application needs to connect manually to nodes other
+ # arbiters with the corresponding accessors: MongoClient#primary, MongoClient#secondaries, and
+ # MongoClient#arbiters. This is useful if your application needs to connect manually to nodes other
# than the primary.
#
# @param [String, Hash] host
# @param [Integer] port specify a port number here if only one host is being specified.
#
# @option opts [Hash] :w (1), :j (false), :wtimeout (false), :fsync (false) Set the default write concern
- # options propagated to DB objects instantiated off of this Client.
+ # options propagated to DB objects instantiated off of this MongoClient.
# This default can be overridden upon instantiation of any DB by explicitly setting an options hash
# on initialization. It can also be overridden at instantiation of a collection or at the time of a write operation.
# @option opts [Boolean] :slave_ok (false) Must be set to +true+ when connecting
@@ -95,16 +95,16 @@ class Client
# @option opts [Boolean] :ssl (false) If true, create the connection to the server using SSL.
#
# @example localhost, 27017 (or <code>ENV["MONGODB_URI"]</code> if available)
- # Mongo::Client.new
+ # Mongo::MongoClient.new
#
# @example localhost, 27017
- # Mongo::Client.new("localhost")
+ # Mongo::MongoClient.new("localhost")
#
# @example localhost, 3000, max 5 self.connections, with max 5 seconds of wait time.
- # Mongo::Client.new("localhost", 3000, :pool_size => 5, :timeout => 5)
+ # Mongo::MongoClient.new("localhost", 3000, :pool_size => 5, :timeout => 5)
#
# @example localhost, 3000, where this node may be a slave
- # Mongo::Client.new("localhost", 3000, :slave_ok => true)
+ # Mongo::MongoClient.new("localhost", 3000, :slave_ok => true)
#
# @see http://api.mongodb.org/ruby/current/file.REPLICA_SETS.html Replica sets in Ruby
#
@@ -118,14 +118,14 @@ def initialize(host=nil, port=nil, opts={})
if host.nil? and ENV.has_key?('MONGODB_URI')
parser = URIParser.new ENV['MONGODB_URI']
if parser.replicaset?
- raise MongoArgumentError, "Mongo::Client.new called with no arguments, but ENV['MONGODB_URI'] implies a replica set."
+ raise MongoArgumentError, "Mongo::MongoClient.new called with no arguments, but ENV['MONGODB_URI'] implies a replica set."
end
opts.merge!(parser.connection_options)
@host_to_try = [parser.host, parser.port]
elsif host.is_a?(String) && (port || DEFAULT_PORT).respond_to?(:to_i)
@host_to_try = [host, (port || DEFAULT_PORT).to_i]
elsif host || port
- raise MongoArgumentError, "Mongo::Client.new host or port argument error, host:#{host.inspect}, port:#{port.inspect}"
+ raise MongoArgumentError, "Mongo::MongoClient.new host or port argument error, host:#{host.inspect}, port:#{port.inspect}"
else
@host_to_try = [DEFAULT_HOST, DEFAULT_PORT]
end
@@ -160,7 +160,7 @@ def initialize(host=nil, port=nil, opts={})
# is_master command on the replica set.
#
# @param nodes [Array] An array of arrays, each of which specifies a host and port.
- # @param opts [Hash] Any of the available options that can be passed to Client.new.
+ # @param opts [Hash] Any of the available options that can be passed to MongoClient.new.
#
# @option opts [String] :rs_name (nil) The name of the replica set to connect to. An exception will be
# raised if unable to connect to a replica set with this name.
@@ -168,32 +168,32 @@ def initialize(host=nil, port=nil, opts={})
# to send reads to.
#
# @example
- # Mongo::Client.multi([["db1.example.com", 27017], ["db2.example.com", 27017]])
+ # Mongo::MongoClient.multi([["db1.example.com", 27017], ["db2.example.com", 27017]])
#
# @example This connection will read from a random secondary node.
- # Mongo::Client.multi([["db1.example.com", 27017], ["db2.example.com", 27017], ["db3.example.com", 27017]],
+ # Mongo::MongoClient.multi([["db1.example.com", 27017], ["db2.example.com", 27017], ["db3.example.com", 27017]],
# :read_secondary => true)
#
- # @return [Mongo::Client]
+ # @return [Mongo::MongoClient]
#
# @deprecated
def self.multi(nodes, opts={})
- warn "Client.multi is now deprecated and will be removed in v2.0. Please use ReplSetClient.new instead."
+ warn "MongoClient.multi is now deprecated and will be removed in v2.0. Please use MongoReplicaSetClient.new instead."
- ReplSetClient.new(*(nodes+[opts]))
+ MongoReplicaSetClient.new(*(nodes+[opts]))
end
# Initialize a connection to MongoDB using the MongoDB URI spec.
#
- # Since Client.new cannot be used with any <code>ENV["MONGODB_URI"]</code> that has multiple hosts (implying a replicaset),
+ # Since MongoClient.new cannot be used with any <code>ENV["MONGODB_URI"]</code> that has multiple hosts (implying a replicaset),
# you may use this when the type of your connection varies by environment and should be determined solely from <code>ENV["MONGODB_URI"]</code>.
#
# @param uri [String]
# A string of the format mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/database]
#
- # @param opts Any of the options available for Client.new
+ # @param opts Any of the options available for MongoClient.new
#
- # @return [Mongo::Client, Mongo::ReplSetClient]
+ # @return [Mongo::MongoClient, Mongo::MongoReplicaSetClient]
def self.from_uri(uri = ENV['MONGODB_URI'], extra_opts={})
parser = URIParser.new uri
parser.connection(extra_opts)
@@ -260,7 +260,7 @@ def apply_saved_authentication(opts={})
# by DB#authenticate.
#
# Note: this method will not actually issue an authentication command. To do that,
- # either run Client#apply_saved_authentication or DB#authenticate.
+ # either run MongoClient#apply_saved_authentication or DB#authenticate.
#
# @param [String] db_name
# @param [String] username
@@ -523,21 +523,21 @@ def max_bson_size
end
# Checkout a socket for reading (i.e., a secondary node).
- # Note: this is overridden in ReplSetClient.
+ # Note: this is overridden in MongoReplicaSetClient.
def checkout_reader(mode=:primary, tag_sets={}, acceptable_latency=15)
connect unless connected?
@primary_pool.checkout
end
# Checkout a socket for writing (i.e., a primary node).
- # Note: this is overridden in ReplSetClient.
+ # Note: this is overridden in MongoReplicaSetClient.
def checkout_writer
connect unless connected?
@primary_pool.checkout
end
# Check a socket back into its pool.
- # Note: this is overridden in ReplSetClient.
+ # Note: this is overridden in MongoReplicaSetClient.
def checkin(socket)
if @primary_pool && socket && socket.pool
socket.pool.checkin(socket)
View
34 lib/mongo/repl_set_client.rb → lib/mongo/mongo_replica_set_client.rb
@@ -19,7 +19,7 @@
module Mongo
# Instantiates and manages connections to a MongoDB replica set.
- class ReplSetClient < Client
+ class MongoReplicaSetClient < MongoClient
REPL_SET_OPTS = [
:read,
@@ -46,15 +46,15 @@ class ReplSetClient < Client
# If no args are provided, it will check <code>ENV["MONGODB_URI"]</code>.
#
# Once connected to a replica set, you can find out which nodes are primary, secondary, and
- # arbiters with the corresponding accessors: Client#primary, Client#secondaries, and
- # Client#arbiters. This is useful if your application needs to connect manually to nodes other
+ # arbiters with the corresponding accessors: MongoClient#primary, MongoClient#secondaries, and
+ # MongoClient#arbiters. This is useful if your application needs to connect manually to nodes other
# than the primary.
#
# @overload initialize(seeds=ENV["MONGODB_URI"], opts={})
# @param [Array<String>, Array<Array(String, Integer)>] seeds
#
# @option opts [Hash] :w (1), :j (false), :wtimeout (false), :fsync (false) Set the default write concern
- # propagated to DB objects instantiated off of this Client. This
+ # propagated to DB objects instantiated off of this MongoClient. This
# default can be overridden upon instantiation of any DB by explicitly setting write concern values
# on initialization.
# @option opts [:primary, :primary_preferred, :secondary, :secondary_preferred, :nearest] :read_preference (:primary)
@@ -94,13 +94,13 @@ class ReplSetClient < Client
# The purpose of seed nodes is to permit the driver to find at least one replica set member even if a member is down.
#
# @example Connect to a replica set and provide two seed nodes.
- # Mongo::ReplSetClient.new(['localhost:30000', 'localhost:30001'])
+ # Mongo::MongoReplicaSetClient.new(['localhost:30000', 'localhost:30001'])
#
# @example Connect to a replica set providing two seed nodes and ensuring a connection to the replica set named 'prod':
- # Mongo::ReplSetClient.new(['localhost:30000', 'localhost:30001'], :name => 'prod')
+ # Mongo::MongoReplicaSetClient.new(['localhost:30000', 'localhost:30001'], :name => 'prod')
#
# @example Connect to a replica set providing two seed nodes and allowing reads from a secondary node:
- # Mongo::ReplSetClient.new(['localhost:30000', 'localhost:30001'], :read => :secondary)
+ # Mongo::MongoReplicaSetClient.new(['localhost:30000', 'localhost:30001'], :read => :secondary)
#
# @see http://api.mongodb.org/ruby/current/file.REPLICA_SETS.html Replica sets in Ruby
#
@@ -115,19 +115,19 @@ def initialize(*args)
if nodes.empty? and ENV.has_key?('MONGODB_URI')
parser = URIParser.new ENV['MONGODB_URI']
if parser.direct?
- raise MongoArgumentError, "Mongo::ReplSetClient.new called with no arguments, but ENV['MONGODB_URI'] implies a direct connection."
+ raise MongoArgumentError, "Mongo::MongoReplicaSetClient.new called with no arguments, but ENV['MONGODB_URI'] implies a direct connection."
end
opts = parser.connection_options.merge! opts
nodes = [parser.nodes]
end
unless nodes.length > 0
- raise MongoArgumentError, "A ReplSetClient requires at least one seed node."
+ raise MongoArgumentError, "A MongoReplicaSetClient requires at least one seed node."
end
# This is temporary until support for the old format is dropped
if nodes.first.last.is_a?(Integer)
- warn "Initiating a ReplSetClient with seeds passed as individual [host, port] array arguments is deprecated."
+ warn "Initiating a MongoReplicaSetClient with seeds passed as individual [host, port] array arguments is deprecated."
warn "Please specify hosts as an array of 'host:port' strings; the old format will be removed in v2.0"
@seeds = nodes
else
@@ -168,7 +168,7 @@ def valid_opts
end
def inspect
- "<Mongo::ReplSetClient:0x#{self.object_id.to_s(16)} @seeds=#{@seeds.inspect} " +
+ "<Mongo::MongoReplicaSetClient:0x#{self.object_id.to_s(16)} @seeds=#{@seeds.inspect} " +
"@connected=#{@connected}>"
end
@@ -199,7 +199,7 @@ def connect
# Determine whether a replica set refresh is
# required. If so, run a hard refresh. You can
# force a hard refresh by running
- # ReplSetClient#hard_refresh!
+ # MongoReplicaSetClient#hard_refresh!
#
# @return [Boolean] +true+ unless a hard refresh
# is run and the refresh lock can't be acquired.
@@ -248,7 +248,7 @@ def connected?
# @deprecated
def connecting?
- warn "ReplSetClient#connecting? is deprecated and will be removed in v2.0."
+ warn "MongoReplicaSetClient#connecting? is deprecated and will be removed in v2.0."
false
end
@@ -267,8 +267,8 @@ def port
end
def nodes
- warn "ReplSetClient#nodes is DEPRECATED and will be removed in v2.0. " +
- "Please use ReplSetClient#seeds instead."
+ warn "MongoReplicaSetClient#nodes is DEPRECATED and will be removed in v2.0. " +
+ "Please use MongoReplicaSetClient#seeds instead."
@seeds
end
@@ -306,8 +306,8 @@ def close(opts={})
# @deprecated
def reset_connection
close
- warn "ReplSetClient#reset_connection is now deprecated and will be removed in v2.0. " +
- "Use ReplSetClient#close instead."
+ warn "MongoReplicaSetClient#reset_connection is now deprecated and will be removed in v2.0. " +
+ "Use MongoReplicaSetClient#close instead."
end
# Returns +true+ if it's okay to read from a secondary node.
View
12 lib/mongo/sharded_client.rb → lib/mongo/mongo_sharded_client.rb
@@ -19,7 +19,7 @@
module Mongo
# Instantiates and manages connections to a MongoDB sharded cluster for high availability.
- class ShardedClient < ReplSetClient
+ class MongoShardedClient < MongoReplicaSetClient
SHARDED_CLUSTER_OPTS = [:refresh_mode, :refresh_interval]
@@ -35,7 +35,7 @@ class ShardedClient < ReplSetClient
# @option opts [String] :name (nil) The name of the sharded cluster to connect to. You
# can use this option to verify that you're connecting to the right sharded cluster.
# @option opts [Hash] ::w (1), :j (false), :wtimeout (false), :fsync (false) Set the default write concern
- # propagated to DB objects instantiated off of this Client. This
+ # propagated to DB objects instantiated off of this MongoClient. This
# default can be overridden upon instantiation of any DB by explicitly setting a write concern values
# on initialization.
# @option opts [Logger] :logger (nil) Logger instance to receive driver operation log.
@@ -58,7 +58,7 @@ class ShardedClient < ReplSetClient
# The purpose of seed nodes is to permit the driver to find at least one sharded cluster member even if a member is down.
#
# @example Connect to a sharded cluster and provide two seed nodes.
- # Mongo::ShardedClient.new(['localhost:30000', 'localhost:30001'])
+ # Mongo::MongoShardedClient.new(['localhost:30000', 'localhost:30001'])
#
# @raise [MongoArgumentError] This is raised for usage errors.
#
@@ -71,14 +71,14 @@ def initialize(*args)
if nodes.empty? and ENV.has_key?('MONGODB_URI')
parser = URIParser.new ENV['MONGODB_URI']
if parser.direct?
- raise MongoArgumentError, "Mongo::ShardedClient.new called with no arguments, but ENV['MONGODB_URI'] implies a direct connection."
+ raise MongoArgumentError, "Mongo::MongoShardedClient.new called with no arguments, but ENV['MONGODB_URI'] implies a direct connection."
end
opts = parser.connection_options.merge! opts
nodes = [parser.nodes]
end
unless nodes.length > 0
- raise MongoArgumentError, "A ShardedClient requires at least one seed node."
+ raise MongoArgumentError, "A MongoShardedClient requires at least one seed node."
end
@seeds = nodes.map do |host_port|
@@ -118,7 +118,7 @@ def valid_opts
end
def inspect
- "<Mongo::ShardedClient:0x#{self.object_id.to_s(16)} @seeds=#{@seeds.inspect} " +
+ "<Mongo::MongoShardedClient:0x#{self.object_id.to_s(16)} @seeds=#{@seeds.inspect} " +
"@connected=#{@connected}>"
end
View
4 lib/mongo/networking.rb
@@ -18,7 +18,7 @@ module Networking
# @return [Integer] number of bytes sent
def send_message(operation, message, opts={})
if opts.is_a?(String)
- warn "Client#send_message no longer takes a string log message. " +
+ warn "MongoClient#send_message no longer takes a string log message. " +
"Logging is now handled within the Collection and Cursor classes."
opts = {}
end
@@ -220,7 +220,7 @@ def build_command_message(db_name, query, projection=nil, skip=0, limit=-1)
end
# Constructs a getlasterror message. This method is used exclusively by
- # Client#send_message_with_gle.
+ # MongoClient#send_message_with_gle.
def build_get_last_error_message(db_name, write_concern)
gle = BSON::OrderedHash.new
gle[:getlasterror] = 1
View
2  lib/mongo/util/node.rb
@@ -145,7 +145,7 @@ def split_node(host_port)
end
host = host_port[0]
- port = host_port[1].nil? ? Client::DEFAULT_PORT : host_port[1].to_i
+ port = host_port[1].nil? ? MongoClient::DEFAULT_PORT : host_port[1].to_i
[host, port]
end
View
14 lib/mongo/util/uri_parser.rb
@@ -102,7 +102,7 @@ class URIParser
:sockettimeoutms,
:wtimeoutms
- # Parse a MongoDB URI. This method is used by Client.from_uri.
+ # Parse a MongoDB URI. This method is used by MongoClient.from_uri.
# Returns an array of nodes and an array of db authorizations, if applicable.
#
# @note Passwords can contain any character except for ','
@@ -124,11 +124,11 @@ def initialize(uri)
validate_connect
end
- # Create a Mongo::Client or a Mongo::ReplSetClient based on the URI.
+ # Create a Mongo::MongoClient or a Mongo::MongoReplicaSetClient based on the URI.
#
# @note Don't confuse this with attribute getter method #connect.
#
- # @return [Client,ReplSetClient]
+ # @return [MongoClient,MongoReplicaSetClient]
def connection(extra_opts, legacy=false)
opts = connection_options.merge! extra_opts
if(legacy)
@@ -139,9 +139,9 @@ def connection(extra_opts, legacy=false)
end
else
if replicaset?
- ReplSetClient.new(nodes, opts)
+ MongoReplicaSetClient.new(nodes, opts)
else
- Client.new(host, port, opts)
+ MongoClient.new(host, port, opts)
end
end
end
@@ -179,7 +179,7 @@ def port
nodes[0][1].to_i
end
- # Options that can be passed to Mongo::Client.new or Mongo::ReplSetClient.new
+ # Options that can be passed to Mongo::MongoClient.new or Mongo::MongoReplicaSetClient.new
# @return [Hash]
def connection_options
opts = {}
@@ -251,7 +251,7 @@ def parse_hosts(uri_without_proto)
hosturis.each do |hosturi|
# If port is present, use it, otherwise use default port
- host, port = hosturi.split(':') + [Client::DEFAULT_PORT]
+ host, port = hosturi.split(':') + [MongoClient::DEFAULT_PORT]
if !(port.to_s =~ /^\d+$/)
raise MongoArgumentError, "Invalid port #{port}; port must be specified as digits."
View
2  tasks/benchmark/batch_size_benchmark
@@ -28,7 +28,7 @@ large = {
}
-client = Mongo::Client.new
+client = Mongo::MongoClient.new
db = client['benchmark']
col = db['bigdocs']
View
2  tasks/benchmark/exp_series.rb
@@ -178,7 +178,7 @@ def test_multi_doc
### Mac OS X - sysctl -a hw
def setup_test_set
- @client = Mongo::Client.new
+ @client = Mongo::MongoClient.new
@client.drop_database($db_name)
@db = @client.db($db_name)
@coll = @db.collection($collection_name)
View
2  tasks/benchmark/gridstore_benchmark
@@ -4,7 +4,7 @@ require 'mongo'
include Mongo
-db = Client.new['benchmark-gridfs']
+db = MongoClient.new['benchmark-gridfs']
sample_data = File.open(File.join(File.dirname(__FILE__), 'sample_file.pdf'), 'r').read
db['fs.files'].remove
db['fs.chunks'].remove
View
2  tasks/benchmark/profile_array.rb
@@ -73,7 +73,7 @@ def ruby_prof(iterations)
# system(cmd)
#end
-client = Mongo::Client.new
+client = Mongo::MongoClient.new
db = client['benchmark']
coll = db['profile']
View
4 tasks/benchmark/standard_benchmark
@@ -84,9 +84,9 @@ def benchmark(str, n, coll_name, data, create_index=false, verbosity=true)
end
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
-port = ENV['MONGO_RUBY_DRIVER_PORT'] || Client::DEFAULT_PORT
+port = ENV['MONGO_RUBY_DRIVER_PORT'] || MongoClient::DEFAULT_PORT
-connection = Client.new(host, port)
+connection = MongoClient.new(host, port)
connection.drop_database("benchmark")
@db = connection.db('benchmark')
View
4 tasks/testing.rake
@@ -60,9 +60,9 @@ namespace :test do
puts "[CLEAN-UP] Dropping test databases..."
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'mongo'
- client = Mongo::Client.new(
+ client = Mongo::MongoClient.new(
ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
- ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Client::DEFAULT_PORT)
+ ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::MongoClient::DEFAULT_PORT)
client.database_names.each {|name| client.drop_database(name) if name =~ /^ruby-test/ }
if File.directory?('data')
View
2  test/auxillary/1.4_feature_test.rb
@@ -7,7 +7,7 @@ class Features14Test < Test::Unit::TestCase
context "MongoDB 1.4" do
setup do
- @client = Mongo::Client.new
+ @client = Mongo::MongoClient.new
@db = @client['mongo-ruby-test']
@col = @db['new-features']
end
View
2  test/auxillary/authentication_test.rb
@@ -7,7 +7,7 @@ class AuthenticationTest < Test::Unit::TestCase
include Mongo
def setup
- @client = Mongo::Client.new
+ @client = Mongo::MongoClient.new
@db1 = @client.db('mongo-ruby-test-auth1')
@db2 = @client.db('mongo-ruby-test-auth2')
@admin = @client.db('admin')
View
2  test/auxillary/autoreconnect_test.rb
@@ -6,7 +6,7 @@ class AutoreconnectTest < Test::Unit::TestCase
include Mongo
def setup
- @client = Mongo::Client.new
+ @client = Mongo::MongoClient.new
@db = @client.db('mongo-ruby-test')
@db.drop_collection("test-connect")
@coll = @db.collection("test-connect")
View
6 test/auxillary/repl_set_auth_test.rb
@@ -14,7 +14,7 @@ def teardown
end
def test_repl_set_auth
- @client = ReplSetClient.new(build_seeds(3), :name => @rs.name)
+ @client = MongoReplicaSetClient.new(build_seeds(3), :name => @rs.name)
# Add an admin user
@client['admin'].add_user("me", "secret")
@@ -41,7 +41,7 @@ def test_repl_set_auth
end
# Same should apply to a random secondary
- @slave1 = Client.new(@client.secondary_pools[0].host,
+ @slave1 = MongoClient.new(@client.secondary_pools[0].host,
@client.secondary_pools[0].port, :slave_ok => true)
# Find should fail
@@ -54,7 +54,7 @@ def test_repl_set_auth
assert @slave1['foo']['stuff'].find_one
# Same should apply when using :secondary_only
- @second_only = ReplSetClient.new(build_seeds(3),
+ @second_only = MongoReplicaSetClient.new(build_seeds(3),
:require_primary => false, :read => :secondary_only)
# Find should fail
View
10 test/auxillary/slave_connection_test.rb
@@ -7,8 +7,8 @@ class SlaveConnectionTest < Test::Unit::TestCase
def self.connect_to_slave
@@host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
- @@port = ENV['MONGO_RUBY_DRIVER_PORT'] || Client::DEFAULT_PORT
- conn = Client.new(@@host, @@port, :slave_ok => true)
+ @@port = ENV['MONGO_RUBY_DRIVER_PORT'] || MongoClient::DEFAULT_PORT
+ conn = MongoClient.new(@@host, @@port, :slave_ok => true)
response = conn['admin'].command(:ismaster => 1)
Mongo::Support.ok?(response) && response['ismaster'] != 1
end
@@ -18,19 +18,19 @@ def self.connect_to_slave
def test_connect_to_slave
assert_raise Mongo::ConnectionFailure do
- @db = Client.new(@@host, @@port, :slave_ok => false).db('ruby-mongo-demo')
+ @db = MongoClient.new(@@host, @@port, :slave_ok => false).db('ruby-mongo-demo')
end
end
def test_slave_ok_sent_to_queries
- @con = Client.new(@@host, @@port, :slave_ok => true)
+ @con = MongoClient.new(@@host, @@port, :slave_ok => true)
assert_equal true, @con.slave_ok?
end
else
puts "Not connected to slave; skipping slave connection tests."
def test_slave_ok_false_on_queries
- @client = Client.new(@@host, @@port)
+ @client = MongoClient.new(@@host, @@port)
assert !@client.slave_ok?
end
end
View
4 test/functional/collection_test.rb
@@ -28,8 +28,8 @@ def test_optional_pk_factory
assert_equal BSON::ObjectId, @coll_default_pk.pk_factory
# Create a db with a pk_factory.
- @db = Client.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
- ENV['MONGO_RUBY_DRIVER_PORT'] || Client::DEFAULT_PORT).db(MONGO_TEST_DB, :pk => Object.new)
+ @db = MongoClient.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
+ ENV['MONGO_RUBY_DRIVER_PORT'] || MongoClient::DEFAULT_PORT).db(MONGO_TEST_DB, :pk => Object.new)
@coll = @db.collection('coll-with-pk')
assert @coll.pk_factory.is_a?(Object)
View
22 test/functional/connection_test.rb
@@ -18,7 +18,7 @@ def teardown
def test_connection_failure
assert_raise Mongo::ConnectionFailure do
- Mongo::Client.new('localhost', 27347)
+ Mongo::MongoClient.new('localhost', 27347)
end
end
@@ -39,13 +39,13 @@ def test_ping
end
def test_connection_uri
- con = Client.from_uri("mongodb://#{host_port}")
+ con = MongoClient.from_uri("mongodb://#{host_port}")
assert_equal mongo_host, con.primary_pool.host
assert_equal mongo_port, con.primary_pool.port
end
def test_uri_with_extra_opts
- con = Client.from_uri("mongodb://#{host_port}", :pool_size => 10, :slave_ok => true)
+ con = MongoClient.from_uri("mongodb://#{host_port}", :pool_size => 10, :slave_ok => true)
assert_equal 10, con.pool_size
assert con.slave_ok?
end
@@ -54,7 +54,7 @@ def test_env_mongodb_uri
begin
old_mongodb_uri = ENV['MONGODB_URI']
ENV['MONGODB_URI'] = "mongodb://#{host_port}"
- con = Client.new
+ con = MongoClient.new
assert_equal mongo_host, con.primary_pool.host
assert_equal mongo_port, con.primary_pool.port
ensure
@@ -66,7 +66,7 @@ def test_from_uri_implicit_mongodb_uri
begin
old_mongodb_uri = ENV['MONGODB_URI']
ENV['MONGODB_URI'] = "mongodb://#{host_port}"
- con = Client.from_uri
+ con = MongoClient.from_uri
assert_equal mongo_host, con.primary_pool.host
assert_equal mongo_port, con.primary_pool.port
ensure
@@ -80,7 +80,7 @@ def test_db_from_uri_exists_no_options
old_mongodb_uri = ENV['MONGODB_URI']
ENV['MONGODB_URI'] = "mongodb://#{host_port}/#{db_name}"
- con = Client.from_uri
+ con = MongoClient.from_uri
db = con.db
assert_equal db.name, db_name
ensure
@@ -94,7 +94,7 @@ def test_db_from_uri_exists_options
old_mongodb_uri = ENV['MONGODB_URI']
ENV['MONGODB_URI'] = "mongodb://#{host_port}/#{db_name}?"
- con = Client.from_uri
+ con = MongoClient.from_uri
db = con.db
assert_equal db.name, db_name
ensure
@@ -106,9 +106,9 @@ def test_db_from_uri_exists_no_db_name
begin
old_mongodb_uri = ENV['MONGODB_URI']
ENV['MONGODB_URI'] = "mongodb://#{host_port}/"
- con = Client.from_uri
+ con = MongoClient.from_uri
db = con.db
- assert_equal db.name, Mongo::Client::DEFAULT_DB_NAME
+ assert_equal db.name, Mongo::MongoClient::DEFAULT_DB_NAME
ensure
ENV['MONGODB_URI'] = old_mongodb_uri
end
@@ -227,7 +227,7 @@ def test_drop_database
def test_nodes
silently do
- @client = Client.multi([['foo', 27017], ['bar', 27018]], :connect => false)
+ @client = MongoClient.multi([['foo', 27017], ['bar', 27018]], :connect => false)
end
seeds = @client.seeds
assert_equal 2, seeds.length
@@ -302,7 +302,7 @@ def test_connection_activity
dropped_socket.stub_everything
conn.primary_pool.host = 'localhost'
- conn.primary_pool.port = Mongo::Client::DEFAULT_PORT
+ conn.primary_pool.port = Mongo::MongoClient::DEFAULT_PORT
conn.primary_pool.instance_variable_set("@pids", {dropped_socket => Process.pid})
conn.primary_pool.instance_variable_set("@sockets", [dropped_socket])
View
4 test/functional/db_connection_test.rb
@@ -6,8 +6,8 @@ class DBConnectionTest < Test::Unit::TestCase
def test_no_exceptions
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
- port = ENV['MONGO_RUBY_DRIVER_PORT'] || Client::DEFAULT_PORT
- db = Client.new(host, port).db(MONGO_TEST_DB)
+ port = ENV['MONGO_RUBY_DRIVER_PORT'] || MongoClient::DEFAULT_PORT
+ db = MongoClient.new(host, port).db(MONGO_TEST_DB)
coll = db.collection('test')
coll.remove
db.get_last_error
View
4 test/functional/db_test.rb
@@ -160,10 +160,10 @@ def test_authenticate_read_only
def test_authenticate_with_connection_uri
@@db.add_user('spongebob', 'squarepants')
- assert Mongo::Client.from_uri("mongodb://spongebob:squarepants@#{host_port}/#{@@db.name}")
+ assert Mongo::MongoClient.from_uri("mongodb://spongebob:squarepants@#{host_port}/#{@@db.name}")
assert_raise Mongo::AuthenticationError do
- client = Mongo::Client.from_uri("mongodb://wrong:info@#{host_port}/#{@@db.name}")
+ client = Mongo::MongoClient.from_uri("mongodb://wrong:info@#{host_port}/#{@@db.name}")
client['test']['foo'].find_one
end
end
View
22 test/replica_set/basic_test.rb
@@ -12,7 +12,7 @@ def self.shutdown
end
def test_connect
- client = Mongo::ReplSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name)
+ client = Mongo::MongoReplicaSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name)
assert client.connected?
assert_equal @rs.primary_name, client.primary.join(':')
assert_equal @rs.secondary_names.sort, client.secondaries.collect{|s| s.join(':')}.sort
@@ -20,7 +20,7 @@ def test_connect
client.close
silently do
- client = Mongo::ReplSetClient.new(@rs.repl_set_seeds_old, :name => @rs.repl_set_name)
+ client = Mongo::MongoReplicaSetClient.new(@rs.repl_set_seeds_old, :name => @rs.repl_set_name)
end
assert client.connected?
@@ -28,23 +28,23 @@ def test_connect
end
def test_safe_option
- client = Mongo::ReplSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name)
+ client = Mongo::MongoReplicaSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name)
assert client.connected?
assert client.write_concern[:w] > 0
client.close
- client = Mongo::ReplSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name, :w => 0)
+ client = Mongo::MongoReplicaSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name, :w => 0)
assert client.connected?
assert client.write_concern[:w] < 1
client.close
- client = Mongo::ReplSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name, :w => 2)
+ client = Mongo::MongoReplicaSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name, :w => 2)
assert client.connected?
assert client.write_concern[:w] > 0
client.close
end
def test_multiple_concurrent_replica_set_connection
- client1 = ReplSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name)
- client2 = ReplSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name)
+ client1 = MongoReplicaSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name)
+ client2 = MongoReplicaSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name)
assert client1.connected?
assert client2.connected?
assert client1.manager != client2.manager
@@ -56,7 +56,7 @@ def test_multiple_concurrent_replica_set_connection
def test_cache_original_seed_nodes
host = @rs.servers.first.host
seeds = @rs.repl_set_seeds << "#{host}:19356"
- client = ReplSetClient.new(seeds, :name => @rs.repl_set_name)
+ client = MongoReplicaSetClient.new(seeds, :name => @rs.repl_set_name)
assert client.connected?
assert client.seeds.include?([host, 19356]), "Original seed nodes not cached!"
assert_equal [host, 19356], client.seeds.last, "Original seed nodes not cached!"
@@ -66,7 +66,7 @@ def test_cache_original_seed_nodes
def test_accessors
seeds = @rs.repl_set_seeds
args = {:name => @rs.repl_set_name}
- client = ReplSetClient.new(seeds, args)
+ client = MongoReplicaSetClient.new(seeds, args)
assert_equal @rs.primary_name, [client.host, client.port].join(':')
assert_equal client.host, client.primary_pool.host
assert_equal client.port, client.primary_pool.port
@@ -85,7 +85,7 @@ def test_accessors
setup do
seeds = @rs.repl_set_seeds
args = {:name => @rs.repl_set_name}
- @client = ReplSetClient.new(seeds, args)
+ @client = MongoReplicaSetClient.new(seeds, args)
@coll = @client[MONGO_TEST_DB]['test-connection-exceptions']
end
@@ -121,7 +121,7 @@ def test_accessors
setup do
seeds = @rs.repl_set_seeds
args = {:name => @rs.repl_set_name}
- @client = ReplSetClient.new(seeds, args)
+ @client = MongoReplicaSetClient.new(seeds, args)
@coll = @client[MONGO_TEST_DB]['test-connection-exceptions']
end
View
44 test/replica_set/client_test.rb
@@ -33,7 +33,7 @@ def test_connect_with_deprecated_multi
#replica_host_ports = @rs.replicas.collect{|replica| [replica.host, replica.port]}
host = @rs.replicas.first.host
silently do
- @client = Client.multi([
+ @client = MongoClient.multi([
# guaranteed to have one data-holding member
[host, @rs.replicas[0].port],
[host, @rs.replicas[1].port],
@@ -46,7 +46,7 @@ def test_connect_with_deprecated_multi
def test_connect_bad_name
assert_raise_error(ReplicaSetConnectionError, "-wrong") do
- @client = ReplSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name + "-wrong")
+ @client = MongoReplicaSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name + "-wrong")
end
end
@@ -54,7 +54,7 @@ def test_connect_with_first_secondary_node_terminated
@rs.secondaries.first.stop
rescue_connection_failure do
- @client = ReplSetClient.new @rs.repl_set_seeds
+ @client = MongoReplicaSetClient.new @rs.repl_set_seeds
end
assert @client.connected?
end
@@ -63,17 +63,17 @@ def test_connect_with_last_secondary_node_terminated
@rs.secondaries.last.stop
rescue_connection_failure do
- @client = ReplSetClient.new @rs.repl_set_seeds
+ @client = MongoReplicaSetClient.new @rs.repl_set_seeds
end
assert @client.connected?
end
def test_connect_with_primary_stepped_down
- @client = ReplSetClient.new @rs.repl_set_seeds
+ @client = MongoReplicaSetClient.new @rs.repl_set_seeds
@client[MONGO_TEST_DB]['bar'].save({:a => 1}, {:w => 3})
assert @client[MONGO_TEST_DB]['bar'].find_one
- primary = Mongo::Client.new(@client.primary_pool.host, @client.primary_pool.port)
+ primary = Mongo::MongoClient.new(@client.primary_pool.host, @client.primary_pool.port)
assert_raise Mongo::ConnectionFailure do
primary['admin'].command(step_down_command)
end
@@ -85,7 +85,7 @@ def test_connect_with_primary_stepped_down
end
def test_connect_with_primary_killed
- @client = ReplSetClient.new @rs.repl_set_seeds
+ @client = MongoReplicaSetClient.new @rs.repl_set_seeds
assert @client.connected?
@client[MONGO_TEST_DB]['bar'].save({:a => 1}, {:w => 3})
assert @client[MONGO_TEST_DB]['bar'].find_one
@@ -98,10 +98,10 @@ def test_connect_with_primary_killed
end
def test_save_with_primary_stepped_down
- @client = ReplSetClient.new @rs.repl_set_seeds
+ @client = MongoReplicaSetClient.new @rs.repl_set_seeds
assert @client.connected?
- primary = Mongo::Client.new(@client.primary_pool.host, @client.primary_pool.port)
+ primary = Mongo::MongoClient.new(@client.primary_pool.host, @client.primary_pool.port)
assert_raise Mongo::ConnectionFailure do
primary['admin'].command(step_down_command)
end
@@ -112,11 +112,11 @@ def test_save_with_primary_stepped_down
end
#def test_connect_with_first_node_removed
- # @client = ReplSetClient.new @rs.repl_set_seeds
+ # @client = MongoReplicaSetClient.new @rs.repl_set_seeds
# @client[MONGO_TEST_DB]['bar'].save({:a => 1}, {:w => 3})
#
# old_primary = [@client.primary_pool.host, @client.primary_pool.port]
- # old_primary_conn = Mongo::Client.new(*old_primary)
+ # old_primary_conn = Mongo::MongoClient.new(*old_primary)
# assert_raise Mongo::ConnectionFailure do
# old_primary_conn['admin'].command(step_down_command)
# end
@@ -127,7 +127,7 @@ def test_save_with_primary_stepped_down
# end
#
# new_primary = @rs.get_all_host_pairs_with_state(1).first
- # new_primary_conn = Mongo::Client.new(*new_primary)
+ # new_primary_conn = Mongo::MongoClient.new(*new_primary)
#
# config = nil
#
@@ -151,7 +151,7 @@ def test_save_with_primary_stepped_down
# end
#
# # Make sure a new connection skips the old primary
- # @new_conn = ReplSetClient.new @rs.repl_set_seeds
+ # @new_conn = MongoReplicaSetClient.new @rs.repl_set_seeds
# @new_conn.connect
# new_nodes = [@new_conn.primary] + @new_conn.secondaries
# assert !(new_nodes).include?(old_primary)
@@ -171,7 +171,7 @@ def test_save_with_primary_stepped_down
# begin
# hung_node = IO.popen('nc -lk 127.0.0.1 29999 >/dev/null 2>&1')
#
- # @client = ReplSetClient.new(['localhost:29999'] + @rs.repl_set_seeds,
+ # @client = MongoReplicaSetClient.new(['localhost:29999'] + @rs.repl_set_seeds,
# :connect_timeout => 2)
# @client.connect
# assert ['localhost:29999'] != @client.primary
@@ -182,14 +182,14 @@ def test_save_with_primary_stepped_down
#end
def test_connect_with_connection_string
- @client = Client.from_uri("mongodb://#{@rs.replicas[0].host_port},#{@rs.replicas[1].host_port}?replicaset=#{@rs.repl_set_name}")
+ @client = MongoClient.from_uri("mongodb://#{@rs.replicas[0].host_port},#{@rs.replicas[1].host_port}?replicaset=#{@rs.repl_set_name}")
assert !@client.nil?
assert @client.connected?
end
def test_connect_with_connection_string_in_env_var
ENV['MONGODB_URI'] = "mongodb://#{@rs.replicas[0].host_port},#{@rs.replicas[1].host_port}?replicaset=#{@rs.repl_set_name}"
- @client = ReplSetClient.new
+ @client = MongoReplicaSetClient.new
assert !@client.nil?
assert_equal 2, @client.seeds.length
assert_equal @rs.replicas[0].host, @client.seeds[0][0]
@@ -202,7 +202,7 @@ def test_connect_with_connection_string_in_env_var
def test_connect_with_connection_string_in_implicit_mongodb_uri
ENV['MONGODB_URI'] = "mongodb://#{@rs.replicas[0].host_port},#{@rs.replicas[1].host_port}?replicaset=#{@rs.repl_set_name}"
- @client = Client.from_uri
+ @client = MongoClient.from_uri
assert !@client.nil?
assert_equal 2, @client.seeds.length
assert_equal @rs.replicas[0].host, @client.seeds[0][0]
@@ -214,19 +214,19 @@ def test_connect_with_connection_string_in_implicit_mongodb_uri
end
def test_connect_with_new_seed_format
- @client = ReplSetClient.new @rs.repl_set_seeds
+ @client = MongoReplicaSetClient.new @rs.repl_set_seeds
assert @client.connected?
end
def test_connect_with_old_seed_format
silently do
- @client = ReplSetClient.new(@rs.replicas[0].host_port_a, @rs.replicas[1].host_port_a)
+ @client = MongoReplicaSetClient.new(@rs.replicas[0].host_port_a, @rs.replicas[1].host_port_a)
end
assert @client.connected?
end
def test_connect_with_full_connection_string
- @client = Client.from_uri("mongodb://#{@rs.replicas[0].host_port},#{@rs.replicas[1].host_port}?replicaset=#{@rs.repl_set_name};w=2;fsync=true;slaveok=true")
+ @client = MongoClient.from_uri("mongodb://#{@rs.replicas[0].host_port},#{@rs.replicas[1].host_port}?replicaset=#{@rs.repl_set_name};w=2;fsync=true;slaveok=true")
assert !@client.nil?
assert @client.connected?
assert_equal 2, @client.write_concern[:w]
@@ -236,7 +236,7 @@ def test_connect_with_full_connection_string
def test_connect_with_full_connection_string_in_env_var
ENV['MONGODB_URI'] = "mongodb://#{@rs.replicas[0].host_port},#{@rs.replicas[1].host_port}?replicaset=#{@rs.repl_set_name};w=2;fsync=true;slaveok=true"
- @client = ReplSetClient.new
+ @client = MongoReplicaSetClient.new
assert !@client.nil?
assert @client.connected?
assert_equal 2, @client.write_concern[:w]
@@ -246,7 +246,7 @@ def test_connect_with_full_connection_string_in_env_var
def test_connect_options_override_env_var
ENV['MONGODB_URI'] = "mongodb://#{@rs.replicas[0].host_port},#{@rs.replicas[1].host_port}?replicaset=#{@rs.repl_set_name};w=2;fsync=true;slaveok=true"
- @client = ReplSetClient.new({:w => 0})
+ @client = MongoReplicaSetClient.new({:w => 0})
assert !@client.nil?
assert @client.connected?
assert_equal 0, @client.write_concern[:w]
View
4 test/replica_set/complex_connect_test.rb
@@ -17,9 +17,9 @@ def teardown
def test_complex_connect
host = @rs.servers.first.host
- primary = Client.new(host, @rs.primary.port)
+ primary = MongoClient.new(host, @rs.primary.port)
- @client = ReplSetClient.new([
+ @client = MongoReplicaSetClient.new([
@rs.servers[2].host_port,
@rs.servers[1].host_port,
@rs.servers[0].host_port
View
4 test/replica_set/count_test.rb
@@ -4,9 +4,9 @@ class ReplicaSetCountTest < Test::Unit::TestCase
def setup
ensure_cluster(:rs)
- @client = ReplSetClient.new(@rs.repl_set_seeds, :read => :primary_preferred)
+ @client = MongoReplicaSetClient.new(@rs.repl_set_seeds, :read => :primary_preferred)
assert @client.primary_pool
- @primary = Client.new(@client.primary_pool.host, @client.primary_pool.port)
+ @primary = MongoClient.new(@client.primary_pool.host, @client.primary_pool.port)
@db = @client.db(MONGO_TEST_DB)
@db.drop_collection("test-sets")
@coll = @db.collection("test-sets")
View
6 test/replica_set/cursor_test.rb
@@ -25,7 +25,7 @@ def test_cursors_get_closed
def setup_client(read=:primary)
# Setup ReplicaSet Connection
- @client = Mongo::ReplSetClient.new(
+ @client = Mongo::MongoReplicaSetClient.new(
@rs.repl_set_seeds,
:read => read
)
@@ -42,8 +42,8 @@ def setup_client(read=:primary)
@coll.find_one
# Setup Direct Connections
- @primary = Mongo::Client.new(*@client.manager.primary)
- @read = Mongo::Client.new(*@client.manager.read)
+ @primary = Mongo::MongoClient.new(*@client.manager.primary)
+ @read = Mongo::MongoClient.new(*@client.manager.read)
end
def cursor_count(client)
View
2  test/replica_set/insert_test.rb
@@ -4,7 +4,7 @@ class ReplicaSetInsertTest < Test::Unit::TestCase
def setup
ensure_cluster(:rs)
- @client = ReplSetClient.new @rs.repl_set_seeds
+ @client = MongoReplicaSetClient.new @rs.repl_set_seeds
@db = @client.db(MONGO_TEST_DB)
@db.drop_collection("test-sets")
@coll = @db.collection("test-sets")
View
2  test/replica_set/query_test.rb
@@ -4,7 +4,7 @@ class ReplicaSetQueryTest < Test::Unit::TestCase
def setup
ensure_cluster(:rs)
- @client = ReplSetClient.new @rs.repl_set_seeds
+ @client = MongoReplicaSetClient.new @rs.repl_set_seeds
@db = @client.db(MONGO_TEST_DB)
@db.drop_collection("test-sets")
@coll = @db.collection("test-sets")
View
12 test/replica_set/refresh_test.rb
@@ -16,7 +16,7 @@ def test_connect_and_manual_refresh_with_secondaries_down
@rs.secondaries.each{|s| s.stop}
rescue_connection_failure do
- @client = ReplSetClient.new(@rs.repl_set_seeds, :refresh_mode => false)
+ @client = MongoReplicaSetClient.new(@rs.repl_set_seeds, :refresh_mode => false)
end
assert_equal [], @client.secondaries
@@ -45,7 +45,7 @@ def test_automated_refresh_with_secondaries_down
@rs.secondaries.each{|s| s.stop}
rescue_connection_failure do
- @client = ReplSetClient.new(@rs.repl_set_seeds,
+ @client = MongoReplicaSetClient.new(@rs.repl_set_seeds,
:refresh_interval => 1, :refresh_mode => :sync, :read => :secondary_preferred)
end
@@ -74,7 +74,7 @@ def test_automated_refresh_with_secondaries_down
end
def test_automated_refresh_when_secondary_goes_down
- @client = ReplSetClient.new(@rs.repl_set_seeds,
+ @client = MongoReplicaSetClient.new(@rs.repl_set_seeds,
:refresh_interval => 1, :refresh_mode => :sync)
num_secondaries = @client.secondary_pools.length
@@ -103,7 +103,7 @@ def test_automated_refresh_when_secondary_goes_down
end
=begin
def test_automated_refresh_with_removed_node
- @client = ReplSetClient.new(@rs.repl_set_seeds,
+ @client = MongoReplicaSetClient.new(@rs.repl_set_seeds,
:refresh_interval => 1, :refresh_mode => :sync)
num_secondaries = @client.secondary_pools.length
@@ -125,14 +125,14 @@ def test_automated_refresh_with_removed_node
end
def test_adding_and_removing_nodes
- @client = ReplSetClient.new(build_seeds(3),
+ @client = MongoReplicaSetClient.new(build_seeds(3),
:refresh_interval => 2, :refresh_mode => :sync)
@rs.add_node
sleep(4)
@client['foo']['bar'].find_one
- @conn2 = ReplSetClient.new(build_seeds(3),
+ @conn2 = MongoReplicaSetClient.new(build_seeds(3),
:refresh_interval => 2, :refresh_mode => :sync)
assert @conn2.secondaries.sort == @client.secondaries.sort,
View
4 test/replica_set/replication_ack_test.rb
@@ -4,9 +4,9 @@ class ReplicaSetAckTest < Test::Unit::TestCase
def setup
ensure_cluster(:rs)
- @client = ReplSetClient.new(@rs.repl_set_seeds)
+ @client = MongoReplicaSetClient.new(@rs.repl_set_seeds)
- @slave1 = Client.new(
+ @slave1 = MongoClient.new(
@client.secondary_pools[0].host,
@client.secondary_pools[0].port, :slave_ok => true)
View
10 test/sharded_cluster/basic_test.rb
@@ -13,7 +13,7 @@ def self.shutdown
# TODO member.primary? ==> true
def test_connect
seeds = @sc.mongos_seeds
- @client = Mongo::ShardedClient.new(seeds)
+ @client = Mongo::MongoShardedClient.new(seeds)
assert @client.connected?
assert_equal(seeds.size, @client.seeds.size)
probe(seeds.size)
@@ -22,7 +22,7 @@ def test_connect
def test_hard_refresh
seeds = @sc.mongos_seeds
- @client = Mongo::ShardedClient.new(seeds)
+ @client = Mongo::MongoShardedClient.new(seeds)
assert @client.connected?
@client.hard_refresh!
assert @client.connected?
@@ -31,7 +31,7 @@ def test_hard_refresh
def test_reconnect
seeds = @sc.mongos_seeds
- @client = Mongo::ShardedClient.new(seeds)
+ @client = Mongo::MongoShardedClient.new(seeds)
assert @client.connected?
router = @sc.servers(:routers).first
router.stop
@@ -42,7 +42,7 @@ def test_reconnect
def test_all_down
seeds = @sc.mongos_seeds
- @client = Mongo::ShardedClient.new(seeds)
+ @client = Mongo::MongoShardedClient.new(seeds)
assert @client.connected?
@sc.servers(:routers).each{|router| router.stop}
assert_raises Mongo::ConnectionFailure do
@@ -54,7 +54,7 @@ def test_all_down
def test_cycle
seeds = @sc.mongos_seeds
- @client = Mongo::ShardedClient.new(seeds)
+ @client = Mongo::MongoShardedClient.new(seeds)
assert @client.connected?
routers = @sc.servers(:routers)
while routers.size > 0 do
View
4 test/test_helper.rb
@@ -81,7 +81,7 @@ def silently
end
unless defined? TEST_PORT
- TEST_PORT = ENV['MONGO_RUBY_DRIVER_PORT'] ? ENV['MONGO_RUBY_DRIVER_PORT'].to_i : Mongo::Client::DEFAULT_PORT
+ TEST_PORT = ENV['MONGO_RUBY_DRIVER_PORT'] ? ENV['MONGO_RUBY_DRIVER_PORT'].to_i : Mongo::MongoClient::DEFAULT_PORT
end
unless defined? TEST_HOST
@@ -96,7 +96,7 @@ def self.standard_connection(options={}, legacy=false)
if legacy
Connection.new(TEST_HOST, TEST_PORT, options)
else
- Client.new(TEST_HOST, TEST_PORT, options)
+ MongoClient.new(TEST_HOST, TEST_PORT, options)
end
end
View
8 test/tools/mongo_config.rb
@@ -280,7 +280,7 @@ def verify(verifies = 600)
#puts "DbServer.verify via connection probe - port:#{@port.inspect} iteration:#{i} @pid:#{@pid.inspect} kill:#{Process.kill(0, @pid).inspect} running?:#{running?.inspect} cmd:#{cmd.inspect}"
begin
raise Mongo::ConnectionFailure unless running?
- Mongo::Client.new(@host, @port).close
+ Mongo::MongoClient.new(@host, @port).close
#puts "DbServer.verified via connection - port: #{@port} iteration: #{i}"
return @pid
rescue Mongo::ConnectionFailure
@@ -315,7 +315,7 @@ def command( cmd_servers, db_name, cmd, opts = {} )
cmd_servers.each do |cmd_server|
debug 3, cmd_server.inspect
cmd_server = cmd_server.config if cmd_server.is_a?(DbServer)
- client = Mongo::Client.new(cmd_server[:host], cmd_server[:port])
+ client = Mongo::MongoClient.new(cmd_server[:host], cmd_server[:port])
cmd.each do |c|
debug 3, "ClusterManager.command c:#{c.inspect}"
response = client[db_name].command( c, opts )
@@ -335,7 +335,7 @@ def repl_set_get_status
def repl_set_get_config
host, port = primary_name.split(":")
- client = Mongo::Client.new(host, port)
+ client = Mongo::MongoClient.new(host, port)
client['local']['system.replset'].find_one
end
@@ -481,7 +481,7 @@ def shardcollection( namespace, key, unique = false )
def mongos_discover # can also do @config[:routers] find but only want mongos for connections
(@config[:configs]).collect do |cmd_server|
- client = Mongo::Client.new(cmd_server[:host], cmd_server[:port])
+ client = Mongo::MongoClient.new(cmd_server[:host], cmd_server[:port])
result = client['config']['mongos'].find.to_a
client.close
result
View
4 test/tools/mongo_config_test.rb
@@ -108,7 +108,7 @@ def cluster_test(opts)
cluster_test(Mongo::Config::DEFAULT_REPLICA_SET) do |manager|
servers = manager.servers
servers.each do |server|
- assert_not_nil(Mongo::Client.new(server.host, server.port))
+ assert_not_nil(Mongo::MongoClient.new(server.host, server.port))
assert_match(/oplogSize/, server.cmd, '--oplogSize option should be specified')
assert_match(/smallfiles/, server.cmd, '--smallfiles option should be specified')
assert_no_match(/nojournal/, server.cmd, '--nojournal option should not be specified')
@@ -121,7 +121,7 @@ def cluster_test(opts)
cluster_test(Mongo::Config::DEFAULT_SHARDED_SIMPLE) do |manager|
servers = manager.shards + manager.configs
servers.each do |server|
- assert_not_nil(Mongo::Client.new(server.host, server.port))
+ assert_not_nil(Mongo::MongoClient.new(server.host, server.port))
assert_match(/oplogSize/, server.cmd, '--oplogSize option should be specified')
assert_match(/smallfiles/, server.cmd, '--smallfiles option should be specified')
assert_no_match(/nojournal/, server.cmd, '--nojournal option should not be specified')
View
60 test/unit/client_test.rb
@@ -2,10 +2,10 @@
include Mongo
class ClientTest < Test::Unit::TestCase
- context "Mongo::Client intialization " do
+ context "Mongo::MongoClient intialization " do
context "given a single node" do
setup do
- @client = Client.new('localhost', 27017, :connect => false)
+ @client = MongoClient.new('localhost', 27017, :connect => false)
TCPSocket.stubs(:new).returns(new_mock_socket)
admin_db = new_mock_db
@@ -33,18 +33,18 @@ class ClientTest < Test::Unit::TestCase
should "raise exception for invalid host or port" do
assert_raise MongoArgumentError do
- Client.new(:w => 1)
+ MongoClient.new(:w => 1)
end
assert_raise MongoArgumentError do
- Client.new('localhost', :w => 1)
+ MongoClient.new('localhost', :w => 1)
end
end
should "warn if invalid options are specified" do
- client = Client.allocate
+ client = MongoClient.allocate
opts = {:connect => false}
- ReplSetClient::REPL_SET_OPTS.each do |opt|
+ MongoReplicaSetClient::REPL_SET_OPTS.each do |opt|
client.expects(:warn).with("#{opt} is not a valid option for #{client.class}")
opts[opt] = true
end
@@ -56,10 +56,10 @@ class ClientTest < Test::Unit::TestCase
context "given a replica set" do
should "warn if invalid options are specified" do
- client = ReplSetClient.allocate
+ client = MongoReplicaSetClient.allocate
opts = {:connect => false}
- Client::CLIENT_ONLY_OPTS.each do |opt|
+ MongoClient::CLIENT_ONLY_OPTS.each do |opt|
client.expects(:warn).with("#{opt} is not a valid option for #{client.class}")
opts[opt] = true
end
@@ -72,39 +72,39 @@ class ClientTest < Test::Unit::TestCase
context "initializing with a mongodb uri" do
should "parse a simple uri" do
- @client = Client.from_uri("mongodb://localhost", :connect => false)
+ @client = MongoClient.from_uri("mongodb://localhost", :connect => false)