RUBY-267 Cursor#alive?
This commit is contained in:
parent
eecb1d35de
commit
96b39313bf
|
@ -93,6 +93,18 @@ module Mongo
|
||||||
end
|
end
|
||||||
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.
|
# Get the next document specified the cursor options.
|
||||||
#
|
#
|
||||||
# @return [Hash, Nil] the next document or Nil if no documents remain.
|
# @return [Hash, Nil] the next document or Nil if no documents remain.
|
||||||
|
|
|
@ -16,6 +16,22 @@ class CursorTest < Test::Unit::TestCase
|
||||||
@@coll_full_name = "#{MONGO_TEST_DB}.test"
|
@@coll_full_name = "#{MONGO_TEST_DB}.test"
|
||||||
end
|
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
|
def test_add_options
|
||||||
c = @@coll.find
|
c = @@coll.find
|
||||||
c.add_option(OP_QUERY_EXHAUST)
|
c.add_option(OP_QUERY_EXHAUST)
|
||||||
|
|
Loading…
Reference in New Issue