RUBY-115 tailable cursors
This commit is contained in:
parent
860ab356d2
commit
acc42dce65
|
@ -19,6 +19,7 @@ module Mongo
|
|||
OP_DELETE = 2006
|
||||
OP_KILL_CURSORS = 2007
|
||||
|
||||
OP_QUERY_TAILABLE = 2
|
||||
OP_QUERY_SLAVE_OK = 4
|
||||
OP_QUERY_NO_CURSOR_TIMEOUT = 16
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@ module Mongo
|
|||
@timeout = options[:timeout] || false
|
||||
@explain = options[:explain]
|
||||
@socket = options[:socket]
|
||||
@tailable = options[:tailable] || false
|
||||
@batch_size = options[:batch_size] || Mongo::Constants::DEFAULT_BATCH_SIZE
|
||||
|
||||
@full_collection_name = "#{@collection.db.name}.#{@collection.name}"
|
||||
|
@ -251,7 +252,8 @@ module Mongo
|
|||
def query_opts
|
||||
timeout = @timeout ? 0 : Mongo::Constants::OP_QUERY_NO_CURSOR_TIMEOUT
|
||||
slave_ok = @connection.slave_ok? ? Mongo::Constants::OP_QUERY_SLAVE_OK : 0
|
||||
slave_ok + timeout
|
||||
tailable = @tailable ? Mongo::Constants::OP_QUERY_TAILABLE : 0
|
||||
slave_ok + timeout + tailable
|
||||
end
|
||||
|
||||
# Get the query options for this Cursor.
|
||||
|
|
|
@ -594,4 +594,42 @@ class TestCollection < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "Capped collections" do
|
||||
setup do
|
||||
@@db.drop_collection('log')
|
||||
@capped = @@db.create_collection('log', :capped => true, :size => 1024)
|
||||
|
||||
10.times { |n| @capped.insert({:n => n}) }
|
||||
end
|
||||
|
||||
should "find using a standard cursor" do
|
||||
cursor = @capped.find
|
||||
10.times do
|
||||
assert cursor.next_document
|
||||
end
|
||||
assert_nil cursor.next_document
|
||||
@capped.insert({:n => 100})
|
||||
assert_nil cursor.next_document
|
||||
end
|
||||
|
||||
should "" do
|
||||
col = @@db['regular-collection']
|
||||
col.insert({:a => 1000})
|
||||
tail = Cursor.new(col, :tailable => true, :order => [['$natural', 1]])
|
||||
assert_raise OperationFailure do
|
||||
tail.next_document
|
||||
end
|
||||
end
|
||||
|
||||
should "find using a tailable cursor" do
|
||||
tail = Cursor.new(@capped, :tailable => true, :order => [['$natural', 1]])
|
||||
10.times do
|
||||
assert tail.next_document
|
||||
end
|
||||
assert_nil tail.next_document
|
||||
@capped.insert({:n => 100})
|
||||
assert tail.next_document
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue