RUBY-167 Cursor#alive?

This commit is contained in:
Kyle Banker 2011-08-05 17:51:37 -04:00
parent eca6653bc2
commit 91308cdc60
2 changed files with 28 additions and 0 deletions

View File

@ -93,6 +93,18 @@ module Mongo
end
end
# Guess whether the cursor is alive on the server.
#
# Note that this method only checks whether we have
# a cursor id. The cursor may still have timed out
# on the server. This will be indicated in the next
# call to Cursor#next_document.
#
# @return [Boolean]
def alive?
@cursor_id && @cursor_id != 0
end
# Get the next document specified the cursor options.
#
# @return [Hash, Nil] the next document or Nil if no documents remain.

View File

@ -16,6 +16,22 @@ class CursorTest < Test::Unit::TestCase
@@coll_full_name = "#{MONGO_TEST_DB}.test"
end
def test_alive
batch = []
5000.times do |n|
batch << {:a => n}
end
@@coll.insert(batch)
cursor = @@coll.find
assert !cursor.alive?
cursor.next
assert cursor.alive?
cursor.close
assert !cursor.alive?
@@coll.remove
end
def test_add_options
c = @@coll.find
c.add_option(OP_QUERY_EXHAUST)