2011-08-31 21:34:06 +00:00
|
|
|
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
|
|
require './test/replica_sets/rs_test_helper'
|
|
|
|
|
2011-09-06 18:58:03 +00:00
|
|
|
# TODO: enable this once we enable reads from tags.
|
2011-08-31 21:34:06 +00:00
|
|
|
class ReadPreferenceTest < Test::Unit::TestCase
|
|
|
|
include Mongo
|
|
|
|
|
2011-10-12 14:51:57 +00:00
|
|
|
def test_long_write_with_async_refresh
|
|
|
|
conn = ReplSetConnection.new([RS.host, RS.ports[0], RS.host, RS.ports[1]],
|
|
|
|
:read => :secondary, :pool_size => 50,
|
|
|
|
:refresh_mode => :async, :refresh_interval => 5)
|
|
|
|
|
|
|
|
db = conn.db(MONGO_TEST_DB)
|
|
|
|
db.drop_collection("test-sets")
|
|
|
|
col = @db['mongo-test']
|
|
|
|
|
|
|
|
100000.times do |n|
|
|
|
|
col.insert({:n => n, :str => "0000000000"})
|
|
|
|
end
|
|
|
|
|
|
|
|
assert col.find.to_a
|
|
|
|
col.remove
|
|
|
|
end
|
2011-08-31 21:34:06 +00:00
|
|
|
|
2011-09-06 18:58:03 +00:00
|
|
|
# TODO: enable this once we enable reads from tags.
|
|
|
|
# def test_query_tagged
|
|
|
|
# col = @db['mongo-test']
|
2011-08-31 21:34:06 +00:00
|
|
|
|
2011-09-06 18:58:03 +00:00
|
|
|
# col.insert({:a => 1}, :safe => {:w => 3})
|
|
|
|
# col.find_one({}, :read => {:db => "main"})
|
|
|
|
# col.find_one({}, :read => {:dc => "ny"})
|
|
|
|
# col.find_one({}, :read => {:dc => "sf"})
|
2011-08-31 21:34:06 +00:00
|
|
|
|
2011-09-06 18:58:03 +00:00
|
|
|
# assert_raise Mongo::NodeWithTagsNotFound do
|
|
|
|
# col.find_one({}, :read => {:foo => "bar"})
|
|
|
|
# end
|
2011-08-31 21:34:06 +00:00
|
|
|
|
2011-09-06 18:58:03 +00:00
|
|
|
# threads = []
|
|
|
|
# 100.times do
|
|
|
|
# threads << Thread.new do
|
|
|
|
# col.find_one({}, :read => {:dc => "sf"})
|
|
|
|
# end
|
|
|
|
# end
|
2011-08-31 21:34:06 +00:00
|
|
|
|
2011-09-06 18:58:03 +00:00
|
|
|
# threads.each {|t| t.join }
|
2011-08-31 21:34:06 +00:00
|
|
|
|
2011-09-06 18:58:03 +00:00
|
|
|
# col.remove
|
|
|
|
# end
|
2011-08-31 21:34:06 +00:00
|
|
|
|
2011-09-06 18:58:03 +00:00
|
|
|
#def teardown
|
|
|
|
# RS.restart_killed_nodes
|
|
|
|
#end
|
2011-08-31 21:34:06 +00:00
|
|
|
|
|
|
|
end
|