[DRE-commits] [ruby-mongo] 01/04: Imported Upstream version 1.9.2
Prach Pongpanich
prach-guest at alioth.debian.org
Thu Sep 5 05:07:52 UTC 2013
This is an automated email from the git hooks/post-receive script.
prach-guest pushed a commit to annotated tag debian/1.9.2-1
in repository ruby-mongo.
commit 52d0b1802c4e01ecb8d3e043d0a31bd3cbbc7d59
Author: Prach Pongpanich <prachpub at gmail.com>
Date: Thu Sep 5 11:55:24 2013 +0700
Imported Upstream version 1.9.2
---
VERSION | 2 +-
checksums.yaml.gz | Bin 267 -> 267 bytes
checksums.yaml.gz.sig | Bin 256 -> 256 bytes
data.tar.gz.sig | Bin 256 -> 256 bytes
lib/mongo/collection.rb | 36 +++++++++++++++++++++++-------------
lib/mongo/cursor.rb | 26 +++++++++++++++++++++++---
lib/mongo/mongo_client.rb | 15 +++++----------
lib/mongo/networking.rb | 2 +-
lib/mongo/util/node.rb | 9 ++++++++-
lib/mongo/util/uri_parser.rb | 21 ++++++++++++++-------
metadata.gz.sig | 3 ++-
metadata.yml | 10 +++++-----
test/functional/collection_test.rb | 31 ++++++++++++++++++++++++++++++-
test/functional/connection_test.rb | 14 +++++++++++++-
test/functional/cursor_test.rb | 28 ++++++++++++++++++++++++++++
test/functional/uri_test.rb | 12 ++++++++++++
16 files changed, 165 insertions(+), 44 deletions(-)
diff --git a/VERSION b/VERSION
index ee672d8..6f2d365 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-1.9.1
\ No newline at end of file
+1.9.2
\ No newline at end of file
diff --git a/checksums.yaml.gz b/checksums.yaml.gz
index c13ce4c..a548427 100644
Binary files a/checksums.yaml.gz and b/checksums.yaml.gz differ
diff --git a/checksums.yaml.gz.sig b/checksums.yaml.gz.sig
index bcc50ec..6d9c27a 100644
Binary files a/checksums.yaml.gz.sig and b/checksums.yaml.gz.sig differ
diff --git a/data.tar.gz.sig b/data.tar.gz.sig
index 390ddd7..cf49da9 100644
Binary files a/data.tar.gz.sig and b/data.tar.gz.sig differ
diff --git a/lib/mongo/collection.rb b/lib/mongo/collection.rb
index 91357f0..6d93f2b 100644
--- a/lib/mongo/collection.rb
+++ b/lib/mongo/collection.rb
@@ -616,25 +616,36 @@ module Mongo
# Atomically update and return a document using MongoDB's findAndModify command. (MongoDB > 1.3.0)
#
- # @option opts [Hash] :query ({}) a query selector document for matching the desired document.
- # @option opts [Hash] :update (nil) the update operation to perform on the matched document.
- # @option opts [Array, String, OrderedHash] :sort ({}) specify a sort option for the query using any
- # of the sort options available for Cursor#sort. Sort order is important if the query will be matching
- # multiple documents since only the first matching document will be updated and returned.
- # @option opts [Boolean] :remove (false) If true, removes the the returned document from the collection.
- # @option opts [Boolean] :new (false) If true, returns the updated document; otherwise, returns the document
- # prior to update.
+ # @option opts [Hash] :query ({}) a query selector document for matching
+ # the desired document.
+ # @option opts [Hash] :update (nil) the update operation to perform on the
+ # matched document.
+ # @option opts [Array, String, OrderedHash] :sort ({}) specify a sort
+ # option for the query using any
+ # of the sort options available for Cursor#sort. Sort order is important
+ # if the query will be matching multiple documents since only the first
+ # matching document will be updated and returned.
+ # @option opts [Boolean] :remove (false) If true, removes the the returned
+ # document from the collection.
+ # @option opts [Boolean] :new (false) If true, returns the updated
+ # document; otherwise, returns the document prior to update.
+ # @option opts [Boolean] :full_response (false) If true, returns the entire
+ # response object from the server including 'ok' and 'lastErrorObject'.
#
# @return [Hash] the matched document.
#
# @core findandmodify find_and_modify-instance_method
def find_and_modify(opts={})
+ full_response = opts.delete(:full_response)
+
cmd = BSON::OrderedHash.new
cmd[:findandmodify] = @name
cmd.merge!(opts)
- cmd[:sort] = Mongo::Support.format_order_clause(opts[:sort]) if opts[:sort]
- @db.command(cmd)['value']
+ cmd[:sort] =
+ Mongo::Support.format_order_clause(opts[:sort]) if opts[:sort]
+
+ full_response ? @db.command(cmd) : @db.command(cmd)['value']
end
# Perform an aggregation using the aggregation framework on the current collection.
@@ -1098,8 +1109,7 @@ module Mongo
def insert_batch(message, documents, write_concern, continue_on_error, errors, collection_name=@name)
begin
send_insert_message(message, documents, collection_name, write_concern)
- rescue ConnectionFailure, OperationFailure, OperationTimeout, SystemStackError,
- NoMemoryError, SystemCallError => ex
+ rescue OperationFailure => ex
raise ex unless continue_on_error
errors << ex
end
@@ -1159,7 +1169,7 @@ module Mongo
insert_batch(message, docs_to_insert, write_concern, continue_on_error, errors, collection_name)
# insert_batch collects errors if w > 0 and continue_on_error is true,
# so raise the error here, as this is the last or only msg sent
- raise errors.first unless errors.empty?
+ raise errors.last unless errors.empty?
end
collect_on_error ? [inserted_ids, error_docs] : inserted_ids
diff --git a/lib/mongo/cursor.rb b/lib/mongo/cursor.rb
index 307dd8a..e0dd609 100644
--- a/lib/mongo/cursor.rb
+++ b/lib/mongo/cursor.rb
@@ -117,7 +117,7 @@ module Mongo
# @return [Hash, Nil] the next document or Nil if no documents remain.
def next
if @cache.length == 0
- if @query_run && (@options & OP_QUERY_EXHAUST != 0)
+ if @query_run && exhaust?
close
return nil
else
@@ -224,6 +224,11 @@ module Mongo
def limit(number_to_return=nil)
return @limit unless number_to_return
check_modifiable
+
+ if (number_to_return != 0) && exhaust?
+ raise MongoArgumentError, "Limit is incompatible with exhaust option."
+ end
+
@limit = number_to_return
self
end
@@ -381,6 +386,14 @@ module Mongo
def add_option(opt)
check_modifiable
+ if exhaust?(opt)
+ if @limit != 0
+ raise MongoArgumentError, "Exhaust is incompatible with limit."
+ elsif @connection.mongos?
+ raise MongoArgumentError, "Exhaust is incompatible with mongos."
+ end
+ end
+
@options |= opt
@options
end
@@ -447,7 +460,7 @@ module Mongo
# Return the number of documents remaining for this cursor.
def num_remaining
if @cache.length == 0
- if @query_run && (@options & OP_QUERY_EXHAUST != 0)
+ if @query_run && exhaust?
close
return 0
else
@@ -483,7 +496,7 @@ module Mongo
socket = @socket || checkout_socket_from_connection
results, @n_received, @cursor_id = @connection.receive_message(
Mongo::Constants::OP_QUERY, message, nil, socket, @command,
- nil, @options & OP_QUERY_EXHAUST != 0)
+ nil, exhaust?)
rescue ConnectionFailure => ex
socket.close if socket
@pool = nil
@@ -621,6 +634,13 @@ module Mongo
end
end
+ # Check whether the exhaust option is set
+ #
+ # @return [true, false] The state of the exhaust flag.
+ def exhaust?(opts = options)
+ !(opts & OP_QUERY_EXHAUST).zero?
+ end
+
def check_modifiable
if @query_run || @closed
raise InvalidOperation, "Cannot modify the query once it has been run or closed."
diff --git a/lib/mongo/mongo_client.rb b/lib/mongo/mongo_client.rb
index ed3afe4..e5c90ba 100644
--- a/lib/mongo/mongo_client.rb
+++ b/lib/mongo/mongo_client.rb
@@ -30,7 +30,7 @@ module Mongo
DEFAULT_HOST = 'localhost'
DEFAULT_PORT = 27017
DEFAULT_DB_NAME = 'test'
- GENERIC_OPTS = [:auths, :logger, :connect]
+ GENERIC_OPTS = [:auths, :logger, :connect, :default_db]
TIMEOUT_OPTS = [:timeout, :op_timeout, :connect_timeout]
SSL_OPTS = [:ssl, :ssl_key, :ssl_cert, :ssl_verify, :ssl_ca_cert]
POOL_OPTS = [:pool_size, :pool_timeout]
@@ -199,7 +199,7 @@ module Mongo
#
# @return [Mongo::MongoClient, Mongo::MongoReplicaSetClient]
def self.from_uri(uri = ENV['MONGODB_URI'], extra_opts={})
- parser = URIParser.new uri
+ parser = URIParser.new(uri)
parser.connection(extra_opts)
end
@@ -210,7 +210,7 @@ module Mongo
raise MongoArgumentError,
"ENV['MONGODB_URI'] implies a replica set."
end
- opts.merge! parser.connection_options
+ opts.merge!(parser.connection_options)
[parser.host, parser.port]
else
[host || DEFAULT_HOST, port || DEFAULT_PORT]
@@ -358,13 +358,7 @@ module Mongo
# @return [Mongo::DB]
#
# @core databases db-instance_method
- def db(db_name=nil, opts={})
- if !db_name && uri = ENV['MONGODB_URI']
- db_name = uri[%r{/([^/\?]+)(\?|$)}, 1]
- end
-
- db_name ||= DEFAULT_DB_NAME
-
+ def db(db_name = @default_db, opts = {})
DB.new(db_name, self, opts)
end
@@ -689,6 +683,7 @@ module Mongo
end
Mongo::ReadPreference::validate(@read)
+ @default_db = opts.delete(:default_db) || DEFAULT_DB_NAME
@tag_sets = opts.delete(:tag_sets) || []
@acceptable_latency = opts.delete(:secondary_acceptable_latency_ms) || 15
diff --git a/lib/mongo/networking.rb b/lib/mongo/networking.rb
index 857054f..1bcc635 100644
--- a/lib/mongo/networking.rb
+++ b/lib/mongo/networking.rb
@@ -208,7 +208,7 @@ module Mongo
raise Mongo::OperationFailure, "Query response returned CURSOR_NOT_FOUND. " +
"Either an invalid cursor was specified, or the cursor may have timed out on the server."
elsif flags & Mongo::Constants::REPLY_QUERY_FAILURE != 0
- # Getting odd failures when a exception is raised here.
+ # Mongo query reply failures are handled in Cursor#next.
end
end
diff --git a/lib/mongo/util/node.rb b/lib/mongo/util/node.rb
index 3206acc..df3418e 100644
--- a/lib/mongo/util/node.rb
+++ b/lib/mongo/util/node.rb
@@ -105,7 +105,14 @@ module Mongo
@last_state = @config['ismaster'] ? :primary : :other
end
- @config = @client['admin'].command({:ismaster => 1}, :socket => @socket)
+ if @client.connect_timeout
+ Timeout::timeout(@client.connect_timeout, OperationTimeout) do
+ @config = @client['admin'].command({:ismaster => 1}, :socket => @socket)
+ end
+ else
+ @config = @client['admin'].command({:ismaster => 1}, :socket => @socket)
+ end
+
update_max_sizes
if @config['msg']
diff --git a/lib/mongo/util/uri_parser.rb b/lib/mongo/util/uri_parser.rb
index db639b3..fdf7738 100644
--- a/lib/mongo/util/uri_parser.rb
+++ b/lib/mongo/util/uri_parser.rb
@@ -13,11 +13,12 @@
# limitations under the License.
require 'cgi'
+require 'uri'
module Mongo
class URIParser
- USER_REGEX = /([-.\w:]+)/
+ USER_REGEX = /(.+)/
PASS_REGEX = /([^@,]+)/
AUTH_REGEX = /(#{USER_REGEX}:#{PASS_REGEX}@)?/
@@ -108,7 +109,7 @@ module Mongo
:w => lambda { |arg| Mongo::Support.is_i?(arg) ? arg.to_i : arg.to_sym },
:wtimeout => lambda { |arg| arg.to_i },
:wtimeoutms => lambda { |arg| arg.to_i }
- }
+ }
attr_reader :auths,
:connect,
@@ -253,6 +254,7 @@ module Mongo
opts[:name] = replicaset
end
+ opts[:default_db] = @db
opts[:connect] = connect?
opts
@@ -277,7 +279,7 @@ module Mongo
uname = matches[2]
pwd = matches[3]
hosturis = matches[4].split(',')
- db = matches[8]
+ @db = matches[8]
hosturis.each do |hosturi|
# If port is present, use it, otherwise use default port
@@ -295,11 +297,16 @@ module Mongo
raise MongoArgumentError, "No nodes specified. Please ensure that you've provided at least one node."
end
- if uname && pwd && db
- auths << {:db_name => db, :username => uname, :password => pwd}
+ if uname && pwd && @db
+ auths << {
+ :db_name => @db,
+ :username => URI.unescape(uname),
+ :password => URI.unescape(pwd)
+ }
elsif uname || pwd
- raise MongoArgumentError, "MongoDB URI must include username, password, "
- "and db if username and password are specified."
+ raise MongoArgumentError, 'MongoDB URI must include username, ' +
+ 'password, and db if username and ' +
+ 'password are specified.'
end
end
diff --git a/metadata.gz.sig b/metadata.gz.sig
index 735f3e6..a811c8f 100644
--- a/metadata.gz.sig
+++ b/metadata.gz.sig
@@ -1 +1,2 @@
-tH�k#D�R&ۚ7��
2�b��q�M���H�
�YT{���(7]�+�J���P�'3����[�����#R��-�hr�w�����VІii�
0�
m�|��ŷR$�z�R�;���SL?����rW,o�*�Q�N��R ��=��WC|G`���
�D��k�
��O�qd�_{>��a|I��v�N��LjҜ,��?��ЩS�� ��A}6T}kq��#�-�5b9�W���X0��8��O��DW�t�V
\ No newline at end of file
+����d��
�8
�;��hW5���5�_FG��;rF����mh=��;%Gʜ4ݦ{�q5m:!�{|{���
�J�j��C���{
Wl_�Y�s�K:���L�Ec�
�� Ib
���!��u
+;5����ʼn_�]d�e��41E�.HR�
g��v�鸁\
�z`��O�}t�1�T*4]�y��]<ĀwR�*�qڙcO��pa��hg1_ZW��a�\0r����!L�k��%kN��G7A��֯Ђθ�_����
\ No newline at end of file
diff --git a/metadata.yml b/metadata.yml
index a42f7b3..63f81d9 100644
--- a/metadata.yml
+++ b/metadata.yml
@@ -1,7 +1,7 @@
--- !ruby/object:Gem::Specification
name: mongo
version: !ruby/object:Gem::Version
- version: 1.9.1
+ version: 1.9.2
platform: ruby
authors:
- Tyler Brock
@@ -33,7 +33,7 @@ cert_chain:
8v7zLF2XliYbfurYIwkcXs8yPn8ggApBIy9bX6VJxRs/l2+UvqzaHIFaFy/F8/GP
RNTuXsVG5NDACo7Q
-----END CERTIFICATE-----
-date: 2013-07-09 00:00:00.000000000 Z
+date: 2013-08-21 00:00:00.000000000 Z
dependencies:
- !ruby/object:Gem::Dependency
name: bson
@@ -41,14 +41,14 @@ dependencies:
requirements:
- - ~>
- !ruby/object:Gem::Version
- version: 1.9.1
+ version: 1.9.2
type: :runtime
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - ~>
- !ruby/object:Gem::Version
- version: 1.9.1
+ version: 1.9.2
description: A Ruby driver for MongoDB. For more information about Mongo, see http://www.mongodb.org.
email: mongodb-dev at googlegroups.com
executables:
@@ -171,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
version: '0'
requirements: []
rubyforge_project: mongo
-rubygems_version: 2.0.3
+rubygems_version: 2.0.7
signing_key:
specification_version: 4
summary: Ruby driver for MongoDB
diff --git a/test/functional/collection_test.rb b/test/functional/collection_test.rb
index d3c5baf..0747ceb 100644
--- a/test/functional/collection_test.rb
+++ b/test/functional/collection_test.rb
@@ -292,6 +292,18 @@ class TestCollection < Test::Unit::TestCase
return conn.db(MONGO_TEST_DB)["test"]
end
+ def test_non_operation_failure_halts_insertion_with_continue_on_error
+ coll = limited_collection
+ coll.stubs(:send_insert_message).raises(OperationTimeout).times(1)
+ docs = []
+ 10.times do
+ docs << {'foo' => 'a' * 950}
+ end
+ assert_raise OperationTimeout do
+ coll.insert(docs, :continue_on_error => true)
+ end
+ end
+
def test_chunking_batch_insert
docs = []
10.times do
@@ -955,7 +967,9 @@ class TestCollection < Test::Unit::TestCase
@@test << { :a => 2, :processed => false }
@@test << { :a => 3, :processed => false }
- @@test.find_and_modify(:query => {}, :sort => [['a', -1]], :update => {"$set" => {:processed => true}})
+ @@test.find_and_modify(:query => {},
+ :sort => [['a', -1]],
+ :update => {"$set" => {:processed => true}})
assert @@test.find_one({:a => 3})['processed']
end
@@ -969,6 +983,21 @@ class TestCollection < Test::Unit::TestCase
@@test.find_and_modify(:blimey => {})
end
end
+
+ def test_find_and_modify_with_full_response
+ @@test << { :a => 1, :processed => false }
+ @@test << { :a => 2, :processed => false }
+ @@test << { :a => 3, :processed => false }
+
+ doc = @@test.find_and_modify(:query => {},
+ :sort => [['a', -1]],
+ :update => {"$set" => {:processed => true}},
+ :full_response => true,
+ :new => true)
+
+ assert doc['value']['processed']
+ assert ['ok', 'value', 'lastErrorObject'].all? { |key| doc.key?(key) }
+ end
end
if @@version >= "1.3.5"
diff --git a/test/functional/connection_test.rb b/test/functional/connection_test.rb
index 3a285db..7370c65 100644
--- a/test/functional/connection_test.rb
+++ b/test/functional/connection_test.rb
@@ -122,12 +122,24 @@ class TestConnection < Test::Unit::TestCase
ENV['MONGODB_URI'] = "mongodb://#{host_port}/"
con = MongoClient.from_uri
db = con.db
- assert_equal db.name, Mongo::MongoClient::DEFAULT_DB_NAME
+ assert_equal db.name, MongoClient::DEFAULT_DB_NAME
ensure
ENV['MONGODB_URI'] = old_mongodb_uri
end
end
+ def test_db_from_uri_from_string_param
+ db_name = "_database"
+ db = MongoClient.from_uri("mongodb://#{host_port}/#{db_name}").db
+ assert_equal db.name, db_name
+ end
+
+ def test_db_from_uri_from_string_param_no_db_name
+ db = MongoClient.from_uri("mongodb://#{host_port}").db
+ assert_equal db.name, MongoClient::DEFAULT_DB_NAME
+ end
+
+
def test_server_version
assert_match(/\d\.\d+(\.\d+)?/, @client.server_version.to_s)
end
diff --git a/test/functional/cursor_test.rb b/test/functional/cursor_test.rb
index 04e2935..0921ebd 100644
--- a/test/functional/cursor_test.rb
+++ b/test/functional/cursor_test.rb
@@ -91,6 +91,34 @@ class CursorTest < Test::Unit::TestCase
end
end
+ def test_exhaust_after_limit_error
+ c = Cursor.new(@@coll, :limit => 17)
+ assert_raise MongoArgumentError do
+ c.add_option(OP_QUERY_EXHAUST)
+ end
+
+ assert_raise MongoArgumentError do
+ c.add_option(OP_QUERY_EXHAUST + OP_QUERY_SLAVE_OK)
+ end
+ end
+
+ def test_limit_after_exhaust_error
+ c = Cursor.new(@@coll)
+ c.add_option(OP_QUERY_EXHAUST)
+ assert_raise MongoArgumentError do
+ c.limit(17)
+ end
+ end
+
+ def test_exhaust_with_mongos
+ @@connection.expects(:mongos?).returns(:true)
+ c = Cursor.new(@@coll)
+
+ assert_raise MongoArgumentError do
+ c.add_option(OP_QUERY_EXHAUST)
+ end
+ end
+
def test_inspect
selector = {:a => 1}
cursor = @@coll.find(selector)
diff --git a/test/functional/uri_test.rb b/test/functional/uri_test.rb
index bddd882..5760b9f 100644
--- a/test/functional/uri_test.rb
+++ b/test/functional/uri_test.rb
@@ -53,6 +53,18 @@ class URITest < Test::Unit::TestCase
assert_equal "b:ob", parser.auths[0][:username]
end
+ def test_username_with_encoded_symbol
+ parser = Mongo::URIParser.new('mongodb://f%40o:bar@localhost/admin')
+ username = parser.auths.first[:username]
+ assert_equal 'f at o', username
+ end
+
+ def test_password_with_encoded_symbol
+ parser = Mongo::URIParser.new('mongodb://foo:b%40r@localhost/admin')
+ password = parser.auths.first[:password]
+ assert_equal 'b at r', password
+ end
+
def test_passwords_contain_no_commas
assert_raise MongoArgumentError do
Mongo::URIParser.new('mongodb://bob:a,b@a.example.com:27018/test')
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-mongo.git
More information about the Pkg-ruby-extras-commits
mailing list