From 94fe53d96b92ecb87099e478b50ea20434bc6ec8 Mon Sep 17 00:00:00 2001 From: Mike Dirolf Date: Thu, 20 Aug 2009 18:48:09 -0400 Subject: [PATCH] DEPRECATE Mongo::Mongo in favor of Mongo::Connection --- README.rdoc | 12 +++--- bin/mongo_console | 4 +- bin/standard_benchmark | 4 +- examples/admin.rb | 4 +- examples/benchmarks.rb | 4 +- examples/blog.rb | 4 +- examples/capped.rb | 4 +- examples/cursor.rb | 4 +- examples/gridfs.rb | 4 +- examples/index_test.rb | 4 +- examples/info.rb | 4 +- examples/queries.rb | 4 +- examples/simple.rb | 4 +- examples/strict.rb | 4 +- examples/types.rb | 4 +- lib/mongo.rb | 2 +- lib/mongo/{mongo.rb => connection.rb} | 25 +++++++----- lib/mongo/db.rb | 2 +- mongo-ruby-driver.gemspec | 4 +- test/mongo-qa/admin | 2 +- test/mongo-qa/capped | 2 +- test/mongo-qa/count1 | 2 +- test/mongo-qa/dbs | 2 +- test/mongo-qa/find | 2 +- test/mongo-qa/find1 | 2 +- test/mongo-qa/gridfs_in | 2 +- test/mongo-qa/gridfs_out | 2 +- test/mongo-qa/indices | 2 +- test/mongo-qa/remove | 2 +- test/mongo-qa/stress1 | 2 +- test/mongo-qa/test1 | 2 +- test/mongo-qa/update | 2 +- test/test_admin.rb | 4 +- test/test_chunk.rb | 4 +- test/test_collection.rb | 4 +- test/{test_mongo.rb => test_connection.rb} | 46 ++++++++++++++++------ test/test_cursor.rb | 4 +- test/test_db.rb | 18 ++++----- test/test_db_api.rb | 4 +- test/test_db_connection.rb | 4 +- test/test_grid_store.rb | 4 +- test/test_objectid.rb | 4 +- test/test_threading.rb | 4 +- test/test_xgen.rb | 8 ++-- 44 files changed, 133 insertions(+), 102 deletions(-) rename lib/mongo/{mongo.rb => connection.rb} (86%) rename test/{test_mongo.rb => test_connection.rb} (67%) diff --git a/README.rdoc b/README.rdoc index 93b2fff..c8bafc5 100644 --- a/README.rdoc +++ b/README.rdoc @@ -9,7 +9,7 @@ many more. include Mongo - db = Mongo::Mongo.new('localhost').db('sample-db') + db = Connection.new('localhost').db('sample-db') coll = db.collection('test') coll.clear @@ -80,7 +80,7 @@ Here is some simple example code: require 'mongo' include Mongo - db = Mongo::Mongo.new.db('my-db-name') + db = Connection.new.db('my-db-name') things = db.collection('things') things.clear @@ -147,10 +147,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 Mongo#db method. +the :pk option to the Connection#db method. include Mongo - db = Mongo::Mongo.new.db('dbname', :pk => MyPKFactory.new) + db = Connection.new.db('dbname', :pk => MyPKFactory.new) A primary key factory object must respond to :create_pk, which should take a hash and return a hash which merges the original hash with any primary key @@ -205,7 +205,7 @@ completely harmless; strict mode is a programmer convenience only. To turn on strict mode, either pass in :strict => true when obtaining a DB object or call the :strict= method: - db = Mongo::Mongo.new.db('dbname', :strict => true) + db = Connection.new.db('dbname', :strict => true) # I'm feeling lax db.strict = false # No, I'm not! @@ -233,7 +233,7 @@ If you have the source code, you can run the tests. $ rake test The tests assume that the Mongo database is running on the default port. You -can override the default host (localhost) and port (Mongo::DEFAULT_PORT) by +can override the default host (localhost) and port (Connection::DEFAULT_PORT) by using the environment variables MONGO_RUBY_DRIVER_HOST and MONGO_RUBY_DRIVER_PORT. diff --git a/bin/mongo_console b/bin/mongo_console index 7478a6b..1bfd794 100755 --- a/bin/mongo_console +++ b/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'] || Mongo::Mongo::DEFAULT_PORT +port = org_argv[1] || ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT dbnm = org_argv[2] || ENV['MONGO_RUBY_DRIVER_DB'] || 'ruby-mongo-console' puts "Connecting to #{host}:#{port} (CONN) on with database #{dbnm} (DB)" -CONN = Mongo::Mongo.new(host, port) +CONN = Connection.new(host, port) DB = CONN.db(dbnm) puts "Starting IRB session..." diff --git a/bin/standard_benchmark b/bin/standard_benchmark index 8490097..9746700 100755 --- a/bin/standard_benchmark +++ b/bin/standard_benchmark @@ -50,9 +50,9 @@ def benchmark(str, proc, n, db, coll_name, object, setup=nil) end host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost' -port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT +port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT -connection = Mongo::Mongo.new(host, port) +connection = Connection.new(host, port) connection.drop_database("benchmark") db = connection.db('benchmark') diff --git a/examples/admin.rb b/examples/admin.rb index a7a37f6..ba5fdc0 100644 --- a/examples/admin.rb +++ b/examples/admin.rb @@ -5,10 +5,10 @@ require 'pp' include Mongo host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost' -port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT +port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT puts "Connecting to #{host}:#{port}" -db = Mongo::Mongo.new(host, port).db('ruby-mongo-examples') +db = Connection.new(host, port).db('ruby-mongo-examples') coll = db.create_collection('test') # Erase all records from collection, if any diff --git a/examples/benchmarks.rb b/examples/benchmarks.rb index 5fe59b9..41126b0 100644 --- a/examples/benchmarks.rb +++ b/examples/benchmarks.rb @@ -4,10 +4,10 @@ $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib') require 'mongo' host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost' -port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT +port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Connection::DEFAULT_PORT puts "Connecting to #{host}:#{port}" -db = Mongo::Mongo.new(host, port).db('ruby-mongo-examples') +db = Mongo::Connection.new(host, port).db('ruby-mongo-examples') coll = db.collection('test') coll.clear diff --git a/examples/blog.rb b/examples/blog.rb index 9daafaf..5d0fcc7 100644 --- a/examples/blog.rb +++ b/examples/blog.rb @@ -12,10 +12,10 @@ require 'mongo' include Mongo host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost' -port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT +port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT puts ">> Connecting to #{host}:#{port}" -DB = Mongo::Mongo.new(host, port).db('ruby-mongo-blog') +DB = Connection.new(host, port).db('ruby-mongo-blog') LINE_SIZE = 120 puts "=" * LINE_SIZE diff --git a/examples/capped.rb b/examples/capped.rb index 786cc6a..fb2ba9f 100644 --- a/examples/capped.rb +++ b/examples/capped.rb @@ -4,10 +4,10 @@ require 'mongo' include Mongo host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost' -port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT +port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT puts "Connecting to #{host}:#{port}" -db = Mongo::Mongo.new(host, port).db('ruby-mongo-examples') +db = Connection.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. diff --git a/examples/cursor.rb b/examples/cursor.rb index 6fc5377..8e2e1ad 100644 --- a/examples/cursor.rb +++ b/examples/cursor.rb @@ -5,10 +5,10 @@ require 'pp' include Mongo host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost' -port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT +port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT puts "Connecting to #{host}:#{port}" -db = Mongo::Mongo.new(host, port).db('ruby-mongo-examples') +db = Connection.new(host, port).db('ruby-mongo-examples') coll = db.collection('test') # Erase all records from collection, if any diff --git a/examples/gridfs.rb b/examples/gridfs.rb index 48fb1d6..c614566 100644 --- a/examples/gridfs.rb +++ b/examples/gridfs.rb @@ -6,10 +6,10 @@ include Mongo include GridFS host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost' -port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT +port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT puts "Connecting to #{host}:#{port}" -db = Mongo::Mongo.new(host, port).db('ruby-mongo-examples') +db = Connection.new(host, port).db('ruby-mongo-examples') def dump(db, fname) GridStore.open(db, fname, 'r') { |f| puts f.read } diff --git a/examples/index_test.rb b/examples/index_test.rb index e528c09..12650dd 100644 --- a/examples/index_test.rb +++ b/examples/index_test.rb @@ -10,10 +10,10 @@ require 'mongo' include Mongo host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost' -port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT +port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT puts ">> Connecting to #{host}:#{port}" -db = Mongo::Mongo.new(host, port).db('ruby-mongo-index_test') +db = Connection.new(host, port).db('ruby-mongo-index_test') puts ">> Dropping collection test" begin diff --git a/examples/info.rb b/examples/info.rb index 5d715f5..c8fface 100644 --- a/examples/info.rb +++ b/examples/info.rb @@ -4,10 +4,10 @@ require 'mongo' include Mongo host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost' -port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT +port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT puts "Connecting to #{host}:#{port}" -db = Mongo::Mongo.new(host, port).db('ruby-mongo-examples') +db = Connection.new(host, port).db('ruby-mongo-examples') coll = db.collection('test') # Erase all records from collection, if any diff --git a/examples/queries.rb b/examples/queries.rb index cb19a1f..bab22e4 100644 --- a/examples/queries.rb +++ b/examples/queries.rb @@ -5,10 +5,10 @@ require 'pp' include Mongo host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost' -port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT +port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT puts "Connecting to #{host}:#{port}" -db = Mongo::Mongo.new(host, port).db('ruby-mongo-examples') +db = Connection.new(host, port).db('ruby-mongo-examples') coll = db.collection('test') # Remove all records, if any diff --git a/examples/simple.rb b/examples/simple.rb index 979ab8b..9004be1 100644 --- a/examples/simple.rb +++ b/examples/simple.rb @@ -4,10 +4,10 @@ require 'mongo' include Mongo host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost' -port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT +port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT puts "Connecting to #{host}:#{port}" -db = Mongo::Mongo.new(host, port).db('ruby-mongo-examples') +db = Connection.new(host, port).db('ruby-mongo-examples') coll = db.collection('test') # Erase all records from collection, if any diff --git a/examples/strict.rb b/examples/strict.rb index ee29b5f..571b419 100644 --- a/examples/strict.rb +++ b/examples/strict.rb @@ -4,10 +4,10 @@ require 'mongo' include Mongo host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost' -port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT +port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT puts "Connecting to #{host}:#{port}" -db = Mongo::Mongo.new(host, port).db('ruby-mongo-examples') +db = Connection.new(host, port).db('ruby-mongo-examples') db.drop_collection('does-not-exist') db.create_collection('test') diff --git a/examples/types.rb b/examples/types.rb index 30768ea..1014fa1 100644 --- a/examples/types.rb +++ b/examples/types.rb @@ -5,10 +5,10 @@ require 'pp' include Mongo host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost' -port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT +port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT puts "Connecting to #{host}:#{port}" -db = Mongo::Mongo.new(host, port).db('ruby-mongo-examples') +db = Connection.new(host, port).db('ruby-mongo-examples') coll = db.collection('test') # Remove all records, if any diff --git a/lib/mongo.rb b/lib/mongo.rb index 0df79bb..9d42f96 100644 --- a/lib/mongo.rb +++ b/lib/mongo.rb @@ -5,7 +5,7 @@ require 'mongo/types/regexp_of_holding' require 'mongo/types/undefined' require 'mongo/errors' -require 'mongo/mongo' +require 'mongo/connection' require 'mongo/message' require 'mongo/db' require 'mongo/cursor' diff --git a/lib/mongo/mongo.rb b/lib/mongo/connection.rb similarity index 86% rename from lib/mongo/mongo.rb rename to lib/mongo/connection.rb index a5cf03a..1f05f67 100644 --- a/lib/mongo/mongo.rb +++ b/lib/mongo/connection.rb @@ -18,8 +18,8 @@ require 'mongo/db' module Mongo - # Represents a Mongo database server. - class Mongo + # A connection to MongoDB. + class Connection DEFAULT_PORT = 27017 @@ -50,23 +50,23 @@ module Mongo # # Since that's so confusing, here are a few examples: # - # Mongo.new # localhost, DEFAULT_PORT, !slave - # Mongo.new("localhost") # localhost, DEFAULT_PORT, !slave - # Mongo.new("localhost", 3000) # localhost, 3000, slave not ok + # Connection.new # localhost, DEFAULT_PORT, !slave + # Connection.new("localhost") # localhost, DEFAULT_PORT, !slave + # Connection.new("localhost", 3000) # localhost, 3000, slave not ok # # localhost, 3000, slave ok - # Mongo.new("localhost", 3000, :slave_ok => true) + # Connection.new("localhost", 3000, :slave_ok => true) # # localhost, DEFAULT_PORT, auto reconnect - # Mongo.new(nil, nil, :auto_reconnect => true) + # Connection.new(nil, nil, :auto_reconnect => true) # # # A pair of servers. DB will always talk to the master. On socket # # error or "not master" error, we will auto-reconnect to the # # current master. - # Mongo.new({:left => ["db1.example.com", 3000], + # Connection.new({:left => ["db1.example.com", 3000], # :right => "db2.example.com"}, # DEFAULT_PORT # nil, :auto_reconnect => true) # # # Here, :right is localhost/DEFAULT_PORT. No auto-reconnect. - # Mongo.new({:left => ["db1.example.com", 3000]}) + # Connection.new({:left => ["db1.example.com", 3000]}) # # When a DB object first connects to a pair, it will find the master # instance and connect to that one. @@ -154,6 +154,13 @@ module Mongo db.close if db end end + end + class Mongo < Connection + def initialize(pair_or_host=nil, port=nil, options={}) + super(pair_or_host, port, options) + + warn "Mongo::Mongo is deprecated and will be removed - please use Mongo::Connection" + end end end diff --git a/lib/mongo/db.rb b/lib/mongo/db.rb index abda9aa..bce8263 100644 --- a/lib/mongo/db.rb +++ b/lib/mongo/db.rb @@ -75,7 +75,7 @@ module Mongo # # db_name :: The database name # - # nodes :: An array of [host, port] pairs. See Mongo#new, which offers + # nodes :: An array of [host, port] pairs. See Connection#new, which offers # a more flexible way of defining nodes. # # options :: A hash of options. diff --git a/mongo-ruby-driver.gemspec b/mongo-ruby-driver.gemspec index a2141f3..0b9e7b6 100644 --- a/mongo-ruby-driver.gemspec +++ b/mongo-ruby-driver.gemspec @@ -19,6 +19,7 @@ PACKAGE_FILES = ['README.rdoc', 'Rakefile', 'mongo-ruby-driver.gemspec', 'examples/types.rb', 'lib/mongo/admin.rb', 'lib/mongo/collection.rb', + 'lib/mongo/connection.rb', 'lib/mongo/cursor.rb', 'lib/mongo/db.rb', 'lib/mongo/gridfs/chunk.rb', @@ -36,7 +37,6 @@ PACKAGE_FILES = ['README.rdoc', 'Rakefile', 'mongo-ruby-driver.gemspec', 'lib/mongo/message/remove_message.rb', 'lib/mongo/message/update_message.rb', 'lib/mongo/message.rb', - 'lib/mongo/mongo.rb', 'lib/mongo/query.rb', 'lib/mongo/types/binary.rb', 'lib/mongo/types/code.rb', @@ -68,13 +68,13 @@ TEST_FILES = ['test/mongo-qa/_common.rb', 'test/test_byte_buffer.rb', 'test/test_chunk.rb', 'test/test_collection.rb', + 'test/test_connection.rb', 'test/test_cursor.rb', 'test/test_db.rb', 'test/test_db_api.rb', 'test/test_db_connection.rb', 'test/test_grid_store.rb', 'test/test_message.rb', - 'test/test_mongo.rb', 'test/test_objectid.rb', 'test/test_ordered_hash.rb', 'test/test_threading.rb', diff --git a/test/mongo-qa/admin b/test/mongo-qa/admin index fa7103b..a415bea 100644 --- a/test/mongo-qa/admin +++ b/test/mongo-qa/admin @@ -1,7 +1,7 @@ #!/usr/bin/env ruby require File.join(File.dirname(__FILE__), '_common.rb') -db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) +db = Connection.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) db.collection('test').insert({'test' => 1}) admin = db.admin diff --git a/test/mongo-qa/capped b/test/mongo-qa/capped index 40832f4..907bfcc 100644 --- a/test/mongo-qa/capped +++ b/test/mongo-qa/capped @@ -1,7 +1,7 @@ #!/usr/bin/env ruby require File.join(File.dirname(__FILE__), '_common.rb') -db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) +db = Connection.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) if $DEBUG db.drop_collection('capped1') diff --git a/test/mongo-qa/count1 b/test/mongo-qa/count1 index 771f5d0..11f7918 100644 --- a/test/mongo-qa/count1 +++ b/test/mongo-qa/count1 @@ -1,7 +1,7 @@ #!/usr/bin/env ruby require File.join(File.dirname(__FILE__), '_common.rb') -db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) +db = Connection.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) if $DEBUG 3.times { |i| db.drop_collection("test#{i+1}") } diff --git a/test/mongo-qa/dbs b/test/mongo-qa/dbs index e0e7ebb..92da779 100644 --- a/test/mongo-qa/dbs +++ b/test/mongo-qa/dbs @@ -1,7 +1,7 @@ #!/usr/bin/env ruby require File.join(File.dirname(__FILE__), '_common.rb') -db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) +db = Connection.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) if $DEBUG 3.times { |i| db.drop_collection("dbs_#{i+1}") } diff --git a/test/mongo-qa/find b/test/mongo-qa/find index 700bcac..d9685eb 100644 --- a/test/mongo-qa/find +++ b/test/mongo-qa/find @@ -1,7 +1,7 @@ #!/usr/bin/env ruby require File.join(File.dirname(__FILE__), '_common.rb') -db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) +db = Connection.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) if $DEBUG db.drop_collection('test') diff --git a/test/mongo-qa/find1 b/test/mongo-qa/find1 index f78dda1..60569ca 100644 --- a/test/mongo-qa/find1 +++ b/test/mongo-qa/find1 @@ -1,7 +1,7 @@ #!/usr/bin/env ruby require File.join(File.dirname(__FILE__), '_common.rb') -db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) +db = Connection.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) if $DEBUG db.drop_collection('c') diff --git a/test/mongo-qa/gridfs_in b/test/mongo-qa/gridfs_in index 732238d..040e7c5 100644 --- a/test/mongo-qa/gridfs_in +++ b/test/mongo-qa/gridfs_in @@ -5,7 +5,7 @@ require File.join(File.dirname(__FILE__), '_common.rb') require 'mongo/gridfs' include GridFS -db = Mongo::Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) +db = Connection.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) input_file = ARGV[0] diff --git a/test/mongo-qa/gridfs_out b/test/mongo-qa/gridfs_out index 49492e6..fa2c89c 100644 --- a/test/mongo-qa/gridfs_out +++ b/test/mongo-qa/gridfs_out @@ -5,7 +5,7 @@ require File.join(File.dirname(__FILE__), '_common.rb') require 'mongo/gridfs' include GridFS -db = Mongo::Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) +db = Connection.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) input_file = ARGV[0] output_file = ARGV[1] diff --git a/test/mongo-qa/indices b/test/mongo-qa/indices index 45649bf..729395d 100755 --- a/test/mongo-qa/indices +++ b/test/mongo-qa/indices @@ -4,7 +4,7 @@ require File.join(File.dirname(__FILE__), '_common.rb') include Mongo -db = Mongo::Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) +db = Connection.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) x = db.collection('x') y = db.collection('y') diff --git a/test/mongo-qa/remove b/test/mongo-qa/remove index 6dfc4d9..6bacb35 100644 --- a/test/mongo-qa/remove +++ b/test/mongo-qa/remove @@ -1,7 +1,7 @@ #!/usr/bin/env ruby require File.join(File.dirname(__FILE__), '_common.rb') -db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) +db = Connection.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) if $DEBUG c = db.collection('remove1') diff --git a/test/mongo-qa/stress1 b/test/mongo-qa/stress1 index d9d808c..3cfdd9f 100755 --- a/test/mongo-qa/stress1 +++ b/test/mongo-qa/stress1 @@ -3,7 +3,7 @@ LONG_STRING = "lksjhasoh1298alshasoidiohaskjasiouashoasasiugoas" * 6 require File.join(File.dirname(__FILE__), '_common.rb') -db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) +db = Connection.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) c = db.collection('stress1') n1 = 50_000 diff --git a/test/mongo-qa/test1 b/test/mongo-qa/test1 index b372bc7..b9943cd 100644 --- a/test/mongo-qa/test1 +++ b/test/mongo-qa/test1 @@ -1,7 +1,7 @@ #!/usr/bin/env ruby require File.join(File.dirname(__FILE__), '_common.rb') -db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) +db = Connection.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) coll = db.collection('part1') if $DEBUG diff --git a/test/mongo-qa/update b/test/mongo-qa/update index a575183..cc5271f 100644 --- a/test/mongo-qa/update +++ b/test/mongo-qa/update @@ -1,7 +1,7 @@ #!/usr/bin/env ruby require File.join(File.dirname(__FILE__), '_common.rb') -db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) +db = Connection.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) foo = db.collection('foo') if $DEBUG diff --git a/test/test_admin.rb b/test/test_admin.rb index 61c7761..4897716 100644 --- a/test/test_admin.rb +++ b/test/test_admin.rb @@ -7,8 +7,8 @@ class AdminTest < Test::Unit::TestCase include Mongo - @@db = Mongo.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost', - ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT).db('ruby-mongo-test') + @@db = Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost', + ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT).db('ruby-mongo-test') @@coll = @@db.collection('test') def setup diff --git a/test/test_chunk.rb b/test/test_chunk.rb index 1bc48ce..ff90e2b 100644 --- a/test/test_chunk.rb +++ b/test/test_chunk.rb @@ -8,8 +8,8 @@ class ChunkTest < Test::Unit::TestCase include Mongo include GridFS - @@db = Mongo.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost', - ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT).db('ruby-mongo-utils-test') + @@db = Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost', + ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT).db('ruby-mongo-utils-test') @@files = @@db.collection('gridfs.files') @@chunks = @@db.collection('gridfs.chunks') diff --git a/test/test_collection.rb b/test/test_collection.rb index 455e994..9207abe 100644 --- a/test/test_collection.rb +++ b/test/test_collection.rb @@ -22,8 +22,8 @@ require 'test/unit' class TestCollection < Test::Unit::TestCase include Mongo - @@db = Mongo.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost', - ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT).db('ruby-mongo-test') + @@db = Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost', + ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT).db('ruby-mongo-test') @@test = @@db.collection("test") def setup diff --git a/test/test_mongo.rb b/test/test_connection.rb similarity index 67% rename from test/test_mongo.rb rename to test/test_connection.rb index 764da13..2a74218 100644 --- a/test/test_mongo.rb +++ b/test/test_connection.rb @@ -3,14 +3,14 @@ require 'mongo' require 'test/unit' # NOTE: assumes Mongo is running -class MongoTest < Test::Unit::TestCase +class TestConnection < Test::Unit::TestCase include Mongo def setup @host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost' - @port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT - @mongo = Mongo.new(@host, @port) + @port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT + @mongo = Connection.new(@host, @port) end def teardown @@ -67,23 +67,47 @@ class MongoTest < Test::Unit::TestCase end def test_pair - db = Mongo.new({:left => ['foo', 123]}) + db = Connection.new({:left => ['foo', 123]}) pair = db.instance_variable_get('@pair') assert_equal 2, pair.length assert_equal ['foo', 123], pair[0] - assert_equal ['localhost', Mongo::DEFAULT_PORT], pair[1] + assert_equal ['localhost', Connection::DEFAULT_PORT], pair[1] - db = Mongo.new({:right => 'bar'}) + db = Connection.new({:right => 'bar'}) pair = db.instance_variable_get('@pair') assert_equal 2, pair.length - assert_equal ['localhost', Mongo::DEFAULT_PORT], pair[0] - assert_equal ['bar', Mongo::DEFAULT_PORT], pair[1] + assert_equal ['localhost', Connection::DEFAULT_PORT], pair[0] + assert_equal ['bar', Connection::DEFAULT_PORT], pair[1] - db = Mongo.new({:right => ['foo', 123], :left => 'bar'}) + db = Connection.new({:right => ['foo', 123], :left => 'bar'}) pair = db.instance_variable_get('@pair') assert_equal 2, pair.length - assert_equal ['bar', Mongo::DEFAULT_PORT], pair[0] + assert_equal ['bar', Connection::DEFAULT_PORT], pair[0] assert_equal ['foo', 123], pair[1] end - +end + +# Test for deprecated Mongo class +class TestMongo < Test::Unit::TestCase + + include Mongo + + def setup + @host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost' + @port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT + @mongo = Mongo.new(@host, @port) + end + + def test_database_info + @mongo.drop_database('ruby-mongo-info-test') + @mongo.db('ruby-mongo-info-test').collection('info-test').insert('a' => 1) + + info = @mongo.database_info + assert_not_nil info + assert_kind_of Hash, info + assert_not_nil info['ruby-mongo-info-test'] + assert info['ruby-mongo-info-test'] > 0 + + @mongo.drop_database('ruby-mongo-info-test') + end end diff --git a/test/test_cursor.rb b/test/test_cursor.rb index aedad12..77bb4e1 100644 --- a/test/test_cursor.rb +++ b/test/test_cursor.rb @@ -7,8 +7,8 @@ class CursorTest < Test::Unit::TestCase include Mongo - @@db = Mongo.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost', - ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT).db('ruby-mongo-test') + @@db = Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost', + ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT).db('ruby-mongo-test') @@coll = @@db.collection('test') def setup diff --git a/test/test_db.rb b/test/test_db.rb index a5833c4..ac058fb 100644 --- a/test/test_db.rb +++ b/test/test_db.rb @@ -16,8 +16,8 @@ class DBTest < Test::Unit::TestCase include Mongo @@host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost' - @@port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT - @@db = Mongo.new(@@host, @@port).db('ruby-mongo-test') + @@port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT + @@db = Connection.new(@@host, @@port).db('ruby-mongo-test') @@users = @@db.collection('system.users') def setup @@ -41,7 +41,7 @@ class DBTest < Test::Unit::TestCase rescue => ex assert_match /NilClass/, ex.to_s ensure - @@db = Mongo.new(@@host, @@port).db('ruby-mongo-test') + @@db = Connection.new(@@host, @@port).db('ruby-mongo-test') @@users = @@db.collection('system.users') end end @@ -66,15 +66,15 @@ class DBTest < Test::Unit::TestCase def test_pair @@db.close @@users = nil - @@db = Mongo.new({:left => "this-should-fail", :right => [@@host, @@port]}).db('ruby-mongo-test') + @@db = Connection.new({:left => "this-should-fail", :right => [@@host, @@port]}).db('ruby-mongo-test') assert @@db.connected? ensure - @@db = Mongo.new(@@host, @@port).db('ruby-mongo-test') unless @@db.connected? + @@db = Connection.new(@@host, @@port).db('ruby-mongo-test') unless @@db.connected? @@users = @@db.collection('system.users') end def test_pk_factory - db = Mongo.new(@@host, @@port).db('ruby-mongo-test', :pk => TestPKFactory.new) + db = Connection.new(@@host, @@port).db('ruby-mongo-test', :pk => TestPKFactory.new) coll = db.collection('test') coll.clear @@ -97,7 +97,7 @@ class DBTest < Test::Unit::TestCase end def test_pk_factory_reset - db = Mongo.new(@@host, @@port).db('ruby-mongo-test') + db = Connection.new(@@host, @@port).db('ruby-mongo-test') db.pk_factory = Object.new # first time begin db.pk_factory = Object.new @@ -121,7 +121,7 @@ class DBTest < Test::Unit::TestCase def test_auto_connect @@db.close - db = Mongo.new(@@host, @@port, :auto_reconnect => true).db('ruby-mongo-test') + db = Connection.new(@@host, @@port, :auto_reconnect => true).db('ruby-mongo-test') assert db.connected? assert db.auto_reconnect? db.close @@ -130,7 +130,7 @@ class DBTest < Test::Unit::TestCase db.collection('test').insert('a' => 1) assert db.connected? ensure - @@db = Mongo.new(@@host, @@port).db('ruby-mongo-test') + @@db = Connection.new(@@host, @@port).db('ruby-mongo-test') @@users = @@db.collection('system.users') end diff --git a/test/test_db_api.rb b/test/test_db_api.rb index 7acf1ff..7dd5bae 100644 --- a/test/test_db_api.rb +++ b/test/test_db_api.rb @@ -6,8 +6,8 @@ require 'test/unit' class DBAPITest < Test::Unit::TestCase include Mongo - @@db = Mongo.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost', - ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT).db('ruby-mongo-test') + @@db = Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost', + ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT).db('ruby-mongo-test') @@coll = @@db.collection('test') def setup diff --git a/test/test_db_connection.rb b/test/test_db_connection.rb index 34f7853..992fb26 100644 --- a/test/test_db_connection.rb +++ b/test/test_db_connection.rb @@ -9,8 +9,8 @@ class DBConnectionTest < Test::Unit::TestCase def test_no_exceptions host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost' - port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT - db = Mongo.new(host, port).db('ruby-mongo-demo') + port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT + db = Connection.new(host, port).db('ruby-mongo-demo') coll = db.collection('test') coll.clear db.error diff --git a/test/test_grid_store.rb b/test/test_grid_store.rb index 459acc8..a838b88 100644 --- a/test/test_grid_store.rb +++ b/test/test_grid_store.rb @@ -8,8 +8,8 @@ class GridStoreTest < Test::Unit::TestCase include Mongo include GridFS - @@db = Mongo.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost', - ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT).db('ruby-mongo-test') + @@db = Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost', + ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT).db('ruby-mongo-test') @@files = @@db.collection('fs.files') @@chunks = @@db.collection('fs.chunks') diff --git a/test/test_objectid.rb b/test/test_objectid.rb index 79470b7..2daf08c 100644 --- a/test/test_objectid.rb +++ b/test/test_objectid.rb @@ -53,8 +53,8 @@ class ObjectIDTest < Test::Unit::TestCase def test_save_and_restore host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost' - port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT - db = Mongo.new(host, port).db('ruby-mongo-test') + port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT + db = Connection.new(host, port).db('ruby-mongo-test') coll = db.collection('test') coll.clear diff --git a/test/test_threading.rb b/test/test_threading.rb index e1befb6..aa072e3 100644 --- a/test/test_threading.rb +++ b/test/test_threading.rb @@ -7,8 +7,8 @@ class TestThreading < Test::Unit::TestCase include Mongo @@host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost' - @@port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT - @@db = Mongo.new(@@host, @@port).db('ruby-mongo-test') + @@port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT + @@db = Connection.new(@@host, @@port).db('ruby-mongo-test') @@coll = @@db.collection('thread-test-collection') def test_threading diff --git a/test/test_xgen.rb b/test/test_xgen.rb index 0696877..bc2d88b 100644 --- a/test/test_xgen.rb +++ b/test/test_xgen.rb @@ -19,8 +19,8 @@ require 'test/unit' # TODO these tests should be removed - just testing for the deprecated # XGen::Mongo::Driver include path class TestXGen < Test::Unit::TestCase - @@db = XGen::Mongo::Driver::Mongo.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost', - ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT).db('ruby-mongo-test') + @@db = XGen::Mongo::Driver::Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost', + ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Connection::DEFAULT_PORT).db('ruby-mongo-test') @@test = @@db.collection('test') def setup @@ -48,8 +48,8 @@ class TestXGenInclude < Test::Unit::TestCase include XGen::Mongo::Driver include XGen::Mongo - @@db = Mongo.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost', - ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT).db('ruby-mongo-test') + @@db = Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost', + ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT).db('ruby-mongo-test') @@test = @@db.collection('test') def setup