log messages read like valid ruby driver code
This commit is contained in:
parent
bca5daa87b
commit
bff177f3e2
|
@ -265,13 +265,13 @@ module Mongo
|
||||||
|
|
||||||
if opts[:safe]
|
if opts[:safe]
|
||||||
@connection.send_message_with_safe_check(Mongo::Constants::OP_DELETE, message, @db.name,
|
@connection.send_message_with_safe_check(Mongo::Constants::OP_DELETE, message, @db.name,
|
||||||
"db.#{@db.name}.remove(#{selector.inspect})")
|
"#{@db.name}['#{@name}'].remove(#{selector.inspect})")
|
||||||
# the return value of send_message_with_safe_check isn't actually meaningful --
|
# the return value of send_message_with_safe_check isn't actually meaningful --
|
||||||
# only the fact that it didn't raise an error is -- so just return true
|
# only the fact that it didn't raise an error is -- so just return true
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
@connection.send_message(Mongo::Constants::OP_DELETE, message,
|
@connection.send_message(Mongo::Constants::OP_DELETE, message,
|
||||||
"db.#{@db.name}.remove(#{selector.inspect})")
|
"#{@db.name}['#{@name}'].remove(#{selector.inspect})")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -307,10 +307,10 @@ module Mongo
|
||||||
message.put_array(BSON.serialize(document, false, true).to_a)
|
message.put_array(BSON.serialize(document, false, true).to_a)
|
||||||
if options[:safe]
|
if options[:safe]
|
||||||
@connection.send_message_with_safe_check(Mongo::Constants::OP_UPDATE, message, @db.name,
|
@connection.send_message_with_safe_check(Mongo::Constants::OP_UPDATE, message, @db.name,
|
||||||
"db.#{@name}.update(#{selector.inspect}, #{document.inspect})")
|
"#{@db.name}['#{@name}'].update(#{selector.inspect}, #{document.inspect})")
|
||||||
else
|
else
|
||||||
@connection.send_message(Mongo::Constants::OP_UPDATE, message,
|
@connection.send_message(Mongo::Constants::OP_UPDATE, message,
|
||||||
"db.#{@name}.update(#{selector.inspect}, #{document.inspect})")
|
"#{@db.name}['#{@name}'].update(#{selector.inspect}, #{document.inspect})")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -634,10 +634,10 @@ module Mongo
|
||||||
documents.each { |doc| message.put_array(BSON.serialize(doc, check_keys, true).to_a) }
|
documents.each { |doc| message.put_array(BSON.serialize(doc, check_keys, true).to_a) }
|
||||||
if safe
|
if safe
|
||||||
@connection.send_message_with_safe_check(Mongo::Constants::OP_INSERT, message, @db.name,
|
@connection.send_message_with_safe_check(Mongo::Constants::OP_INSERT, message, @db.name,
|
||||||
"db.#{collection_name}.insert(#{documents.inspect})")
|
"#{@db.name}['#{collection_name}'].insert(#{documents.inspect})")
|
||||||
else
|
else
|
||||||
@connection.send_message(Mongo::Constants::OP_INSERT, message,
|
@connection.send_message(Mongo::Constants::OP_INSERT, message,
|
||||||
"db.#{collection_name}.insert(#{documents.inspect})")
|
"#{@db.name}['#{collection_name}'].insert(#{documents.inspect})")
|
||||||
end
|
end
|
||||||
documents.collect { |o| o[:_id] || o['_id'] }
|
documents.collect { |o| o[:_id] || o['_id'] }
|
||||||
end
|
end
|
||||||
|
|
|
@ -230,7 +230,7 @@ module Mongo
|
||||||
message = ByteBuffer.new([0, 0, 0, 0])
|
message = ByteBuffer.new([0, 0, 0, 0])
|
||||||
message.put_int(1)
|
message.put_int(1)
|
||||||
message.put_long(@cursor_id)
|
message.put_long(@cursor_id)
|
||||||
@connection.send_message(Mongo::Constants::OP_KILL_CURSORS, message, "cursor.close()")
|
@connection.send_message(Mongo::Constants::OP_KILL_CURSORS, message, "cursor.close")
|
||||||
end
|
end
|
||||||
@cursor_id = 0
|
@cursor_id = 0
|
||||||
@closed = true
|
@closed = true
|
||||||
|
@ -362,7 +362,7 @@ module Mongo
|
||||||
end
|
end
|
||||||
|
|
||||||
def query_log_message
|
def query_log_message
|
||||||
"#{@admin ? 'admin' : @db.name}.#{@collection.name}.find(#{@selector.inspect}, #{@fields ? @fields.inspect : '{}'})" +
|
"#{@admin ? 'admin' : @db.name}['#{@collection.name}'].find(#{@selector.inspect}, #{@fields ? @fields.inspect : '{}'})" +
|
||||||
"#{@skip != 0 ? ('.skip(' + @skip.to_s + ')') : ''}#{@limit != 0 ? ('.limit(' + @limit.to_s + ')') : ''}" +
|
"#{@skip != 0 ? ('.skip(' + @skip.to_s + ')') : ''}#{@limit != 0 ? ('.limit(' + @limit.to_s + ')') : ''}" +
|
||||||
"#{@order ? ('.sort(' + @order.inspect + ')') : ''}"
|
"#{@order ? ('.sort(' + @order.inspect + ')') : ''}"
|
||||||
end
|
end
|
||||||
|
|
|
@ -93,7 +93,7 @@ class TestConnection < Test::Unit::TestCase
|
||||||
logger = Logger.new(output)
|
logger = Logger.new(output)
|
||||||
logger.level = Logger::DEBUG
|
logger.level = Logger::DEBUG
|
||||||
db = Connection.new(@host, @port, :logger => logger).db('ruby-mongo-test')
|
db = Connection.new(@host, @port, :logger => logger).db('ruby-mongo-test')
|
||||||
assert output.string.include?("admin.$cmd.find")
|
assert output.string.include?("admin['$cmd'].find")
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_connection_logger
|
def test_connection_logger
|
||||||
|
|
|
@ -12,7 +12,7 @@ class CollectionTest < Test::Unit::TestCase
|
||||||
@db = @conn['testing']
|
@db = @conn['testing']
|
||||||
@coll = @db.collection('books')
|
@coll = @db.collection('books')
|
||||||
@conn.expects(:send_message).with do |op, msg, log|
|
@conn.expects(:send_message).with do |op, msg, log|
|
||||||
op == 2001 && log.include?("db.books.update")
|
op == 2001 && log.include?("testing['books'].update")
|
||||||
end
|
end
|
||||||
@coll.update({}, {:title => 'Moby Dick'})
|
@coll.update({}, {:title => 'Moby Dick'})
|
||||||
end
|
end
|
||||||
|
@ -22,7 +22,7 @@ class CollectionTest < Test::Unit::TestCase
|
||||||
@db = @conn['testing']
|
@db = @conn['testing']
|
||||||
@coll = @db.collection('books')
|
@coll = @db.collection('books')
|
||||||
@conn.expects(:send_message).with do |op, msg, log|
|
@conn.expects(:send_message).with do |op, msg, log|
|
||||||
op == 2002 && log.include?("db.books.insert")
|
op == 2002 && log.include?("testing['books'].insert")
|
||||||
end
|
end
|
||||||
@coll.insert({:title => 'Moby Dick'})
|
@coll.insert({:title => 'Moby Dick'})
|
||||||
end
|
end
|
||||||
|
@ -53,7 +53,7 @@ class CollectionTest < Test::Unit::TestCase
|
||||||
@db = @conn['testing']
|
@db = @conn['testing']
|
||||||
@coll = @db.collection('books')
|
@coll = @db.collection('books')
|
||||||
@conn.expects(:send_message_with_safe_check).with do |op, msg, db_name, log|
|
@conn.expects(:send_message_with_safe_check).with do |op, msg, db_name, log|
|
||||||
op == 2001 && log.include?("db.books.update")
|
op == 2001 && log.include?("testing['books'].update")
|
||||||
end
|
end
|
||||||
@coll.update({}, {:title => 'Moby Dick'}, :safe => true)
|
@coll.update({}, {:title => 'Moby Dick'}, :safe => true)
|
||||||
end
|
end
|
||||||
|
@ -63,7 +63,7 @@ class CollectionTest < Test::Unit::TestCase
|
||||||
@db = @conn['testing']
|
@db = @conn['testing']
|
||||||
@coll = @db.collection('books')
|
@coll = @db.collection('books')
|
||||||
@conn.expects(:send_message_with_safe_check).with do |op, msg, db_name, log|
|
@conn.expects(:send_message_with_safe_check).with do |op, msg, db_name, log|
|
||||||
op == 2001 && log.include?("db.books.update")
|
op == 2001 && log.include?("testing['books'].update")
|
||||||
end
|
end
|
||||||
@coll.update({}, {:title => 'Moby Dick'}, :safe => true)
|
@coll.update({}, {:title => 'Moby Dick'}, :safe => true)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue