mongo 1.5.2 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +24 -8
- data/docs/HISTORY.md +15 -0
- data/docs/READ_PREFERENCE.md +1 -1
- data/docs/RELEASES.md +18 -4
- data/docs/REPLICA_SETS.md +5 -5
- data/docs/WRITE_CONCERN.md +1 -1
- data/lib/mongo/collection.rb +49 -10
- data/lib/mongo/connection.rb +7 -24
- data/lib/mongo/cursor.rb +3 -1
- data/lib/mongo/db.rb +5 -1
- data/lib/mongo/exceptions.rb +0 -3
- data/lib/mongo/gridfs/grid.rb +1 -1
- data/lib/mongo/gridfs/grid_file_system.rb +11 -3
- data/lib/mongo/networking.rb +7 -3
- data/lib/mongo/repl_set_connection.rb +58 -82
- data/lib/mongo/util/logging.rb +26 -18
- data/lib/mongo/util/node.rb +11 -2
- data/lib/mongo/util/pool_manager.rb +7 -5
- data/lib/mongo/util/support.rb +2 -2
- data/lib/mongo/util/uri_parser.rb +74 -36
- data/lib/mongo/version.rb +1 -1
- data/mongo.gemspec +2 -2
- data/test/auxillary/authentication_test.rb +8 -0
- data/test/auxillary/repl_set_auth_test.rb +1 -2
- data/test/bson/ordered_hash_test.rb +1 -1
- data/test/bson/test_helper.rb +2 -1
- data/test/collection_test.rb +71 -0
- data/test/connection_test.rb +9 -0
- data/test/db_test.rb +7 -0
- data/test/grid_file_system_test.rb +12 -0
- data/test/load/thin/load.rb +1 -1
- data/test/replica_sets/basic_test.rb +36 -26
- data/test/replica_sets/complex_connect_test.rb +44 -0
- data/test/replica_sets/connect_test.rb +48 -22
- data/test/replica_sets/count_test.rb +4 -6
- data/test/replica_sets/insert_test.rb +13 -14
- data/test/replica_sets/pooled_insert_test.rb +9 -10
- data/test/replica_sets/query_test.rb +4 -4
- data/test/replica_sets/read_preference_test.rb +48 -14
- data/test/replica_sets/refresh_test.rb +43 -42
- data/test/replica_sets/refresh_with_threads_test.rb +10 -9
- data/test/replica_sets/replication_ack_test.rb +3 -3
- data/test/replica_sets/rs_test_helper.rb +17 -11
- data/test/test_helper.rb +2 -1
- data/test/tools/repl_set_manager.rb +63 -39
- data/test/unit/collection_test.rb +2 -1
- data/test/unit/connection_test.rb +22 -0
- data/test/unit/cursor_test.rb +6 -3
- data/test/unit/read_test.rb +1 -1
- data/test/uri_test.rb +17 -2
- metadata +151 -167
@@ -0,0 +1,44 @@
|
|
1
|
+
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
require 'logger'
|
3
|
+
require './test/replica_sets/rs_test_helper'
|
4
|
+
|
5
|
+
class ComplexConnectTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
ensure_rs
|
9
|
+
end
|
10
|
+
|
11
|
+
def teardown
|
12
|
+
@rs.restart_killed_nodes
|
13
|
+
@conn.close if defined?(@conn) && @conn
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_complex_connect
|
17
|
+
logger = Logger.new(STDOUT)
|
18
|
+
primary = Connection.new(@rs.host, @rs.ports[0])
|
19
|
+
|
20
|
+
@conn = ReplSetConnection.new([@rs.host, @rs.ports[2]], [@rs.host, @rs.ports[1]],
|
21
|
+
[@rs.host, @rs.ports[0]], :logger => logger)
|
22
|
+
|
23
|
+
@conn['test']['foo'].insert({:a => 1})
|
24
|
+
assert @conn['test']['foo'].find_one
|
25
|
+
|
26
|
+
config = primary['local']['system.replset'].find_one
|
27
|
+
config['version'] += 1
|
28
|
+
config['members'].delete_if do |member|
|
29
|
+
member['host'].include?(@rs.ports[2].to_s)
|
30
|
+
end
|
31
|
+
|
32
|
+
assert_raise ConnectionFailure do
|
33
|
+
primary['admin'].command({:replSetReconfig => config})
|
34
|
+
end
|
35
|
+
@rs.ensure_up
|
36
|
+
assert_raise ConnectionFailure do
|
37
|
+
primary['admin'].command({:replSetStepDown => 1})
|
38
|
+
end
|
39
|
+
|
40
|
+
rescue_connection_failure do
|
41
|
+
assert @conn['test']['foo'].find_one
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -2,75 +2,73 @@ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
2
2
|
require './test/replica_sets/rs_test_helper'
|
3
3
|
|
4
4
|
class ConnectTest < Test::Unit::TestCase
|
5
|
-
|
5
|
+
def setup
|
6
|
+
ensure_rs
|
7
|
+
end
|
6
8
|
|
7
9
|
def teardown
|
8
|
-
|
10
|
+
@rs.restart_killed_nodes
|
9
11
|
@conn.close if defined?(@conn) && @conn
|
10
12
|
end
|
11
13
|
|
12
14
|
# TODO: test connect timeout.
|
13
15
|
|
14
16
|
def test_connect_with_deprecated_multi
|
15
|
-
@conn = Connection.multi([[
|
17
|
+
@conn = Connection.multi([[@rs.host, @rs.ports[0]], [@rs.host, @rs.ports[1]]], :name => @rs.name)
|
16
18
|
assert @conn.is_a?(ReplSetConnection)
|
17
19
|
assert @conn.connected?
|
18
20
|
end
|
19
21
|
|
20
22
|
def test_connect_bad_name
|
21
23
|
assert_raise_error(ReplicaSetConnectionError, "-wrong") do
|
22
|
-
@conn = ReplSetConnection.new(
|
23
|
-
[self.rs.host, self.rs.ports[2]], :name => self.rs.name + "-wrong")
|
24
|
+
@conn = ReplSetConnection.new(build_seeds(3), :name => @rs.name + "-wrong")
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
27
28
|
def test_connect_with_primary_node_killed
|
28
|
-
node =
|
29
|
+
node = @rs.kill_primary
|
29
30
|
|
30
31
|
# Becuase we're killing the primary and trying to connect right away,
|
31
32
|
# this is going to fail right away.
|
32
33
|
assert_raise_error(ConnectionFailure, "Failed to connect to primary node") do
|
33
|
-
@conn = ReplSetConnection.new(
|
34
|
-
[self.rs.host, self.rs.ports[2]])
|
34
|
+
@conn = ReplSetConnection.new build_seeds(3)
|
35
35
|
end
|
36
36
|
|
37
37
|
# This allows the secondary to come up as a primary
|
38
38
|
rescue_connection_failure do
|
39
|
-
@conn = ReplSetConnection.new(
|
40
|
-
[self.rs.host, self.rs.ports[2]])
|
39
|
+
@conn = ReplSetConnection.new build_seeds(3)
|
41
40
|
end
|
42
41
|
end
|
43
42
|
|
44
43
|
def test_connect_with_secondary_node_killed
|
45
|
-
node =
|
44
|
+
node = @rs.kill_secondary
|
46
45
|
|
47
46
|
rescue_connection_failure do
|
48
|
-
@conn = ReplSetConnection.new(
|
49
|
-
[self.rs.host, self.rs.ports[2]])
|
47
|
+
@conn = ReplSetConnection.new build_seeds(3)
|
50
48
|
end
|
51
49
|
assert @conn.connected?
|
52
50
|
end
|
53
51
|
|
54
52
|
def test_connect_with_third_node_killed
|
55
|
-
|
53
|
+
@rs.kill(@rs.get_node_from_port(@rs.ports[2]))
|
56
54
|
|
57
55
|
rescue_connection_failure do
|
58
|
-
@conn = ReplSetConnection.new(
|
59
|
-
[self.rs.host, self.rs.ports[2]])
|
56
|
+
@conn = ReplSetConnection.new build_seeds(3)
|
60
57
|
end
|
61
58
|
assert @conn.connected?
|
62
59
|
end
|
63
60
|
|
64
61
|
def test_connect_with_primary_stepped_down
|
65
|
-
@conn = ReplSetConnection.new(
|
66
|
-
[self.rs.host, self.rs.ports[2]])
|
62
|
+
@conn = ReplSetConnection.new build_seeds(3)
|
67
63
|
@conn[MONGO_TEST_DB]['bar'].save({:a => 1}, {:safe => {:w => 3}})
|
68
64
|
assert @conn[MONGO_TEST_DB]['bar'].find_one
|
69
65
|
|
70
66
|
primary = Mongo::Connection.new(@conn.primary_pool.host, @conn.primary_pool.port)
|
71
|
-
|
67
|
+
assert_raise Mongo::ConnectionFailure do
|
68
|
+
primary['admin'].command({:replSetStepDown => 60})
|
69
|
+
end
|
72
70
|
assert @conn.connected?
|
73
|
-
|
71
|
+
assert_raise Mongo::ConnectionFailure do
|
74
72
|
@conn[MONGO_TEST_DB]['bar'].find_one
|
75
73
|
end
|
76
74
|
assert !@conn.connected?
|
@@ -80,14 +78,42 @@ class ConnectTest < Test::Unit::TestCase
|
|
80
78
|
end
|
81
79
|
end
|
82
80
|
|
81
|
+
def test_save_with_primary_stepped_down
|
82
|
+
@conn = ReplSetConnection.new build_seeds(3)
|
83
|
+
|
84
|
+
primary = Mongo::Connection.new(@conn.primary_pool.host, @conn.primary_pool.port)
|
85
|
+
|
86
|
+
# Adding force=true to avoid 'no secondaries within 10 seconds of my optime' errors
|
87
|
+
step_down_command = BSON::OrderedHash.new
|
88
|
+
step_down_command[:replSetStepDown] = 60
|
89
|
+
step_down_command[:force] = true
|
90
|
+
assert_raise Mongo::ConnectionFailure do
|
91
|
+
primary['admin'].command(step_down_command)
|
92
|
+
end
|
93
|
+
|
94
|
+
rescue_connection_failure do
|
95
|
+
@conn[MONGO_TEST_DB]['bar'].save({:a => 1}, {:safe => {:w => 3}})
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
83
99
|
def test_connect_with_connection_string
|
84
|
-
@conn = Connection.from_uri("mongodb://#{
|
100
|
+
@conn = Connection.from_uri("mongodb://#{@rs.host}:#{@rs.ports[0]},#{@rs.host}:#{@rs.ports[1]}?replicaset=#{@rs.name}")
|
85
101
|
assert @conn.is_a?(ReplSetConnection)
|
86
102
|
assert @conn.connected?
|
87
103
|
end
|
104
|
+
|
105
|
+
def test_connect_with_new_seed_format
|
106
|
+
@conn = ReplSetConnection.new build_seeds(3)
|
107
|
+
assert @conn.connected?
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_connect_with_old_seed_format
|
111
|
+
@conn = ReplSetConnection.new([@rs.host, @rs.ports[0]], [@rs.host, @rs.ports[1]], [@rs.host, @rs.ports[2]])
|
112
|
+
assert @conn.connected?
|
113
|
+
end
|
88
114
|
|
89
115
|
def test_connect_with_full_connection_string
|
90
|
-
@conn = Connection.from_uri("mongodb://#{
|
116
|
+
@conn = Connection.from_uri("mongodb://#{@rs.host}:#{@rs.ports[0]},#{@rs.host}:#{@rs.ports[1]}?replicaset=#{@rs.name};safe=true;w=2;fsync=true;slaveok=true")
|
91
117
|
assert @conn.is_a?(ReplSetConnection)
|
92
118
|
assert @conn.connected?
|
93
119
|
assert_equal 2, @conn.safe[:w]
|
@@ -2,12 +2,10 @@ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
2
2
|
require './test/replica_sets/rs_test_helper'
|
3
3
|
|
4
4
|
class ReplicaSetCountTest < Test::Unit::TestCase
|
5
|
-
include ReplicaSetTest
|
6
5
|
|
7
6
|
def setup
|
8
|
-
|
9
|
-
|
10
|
-
:read => :secondary)
|
7
|
+
ensure_rs
|
8
|
+
@conn = ReplSetConnection.new(build_seeds(3), :read => :secondary)
|
11
9
|
assert @conn.primary_pool
|
12
10
|
@primary = Connection.new(@conn.primary_pool.host, @conn.primary_pool.port)
|
13
11
|
@db = @conn.db(MONGO_TEST_DB)
|
@@ -16,7 +14,7 @@ class ReplicaSetCountTest < Test::Unit::TestCase
|
|
16
14
|
end
|
17
15
|
|
18
16
|
def teardown
|
19
|
-
|
17
|
+
@rs.restart_killed_nodes
|
20
18
|
@conn.close if @conn
|
21
19
|
end
|
22
20
|
|
@@ -25,7 +23,7 @@ class ReplicaSetCountTest < Test::Unit::TestCase
|
|
25
23
|
assert_equal 1, @coll.count
|
26
24
|
|
27
25
|
# Kill the current master node
|
28
|
-
@node =
|
26
|
+
@node = @rs.kill_primary
|
29
27
|
|
30
28
|
rescue_connection_failure do
|
31
29
|
@coll.insert({:a => 30}, :safe => true)
|
@@ -2,38 +2,37 @@ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
2
2
|
require './test/replica_sets/rs_test_helper'
|
3
3
|
|
4
4
|
class ReplicaSetInsertTest < Test::Unit::TestCase
|
5
|
-
include ReplicaSetTest
|
6
5
|
|
7
6
|
def setup
|
8
|
-
|
9
|
-
|
7
|
+
ensure_rs
|
8
|
+
@conn = ReplSetConnection.new build_seeds(3)
|
10
9
|
@db = @conn.db(MONGO_TEST_DB)
|
11
10
|
@db.drop_collection("test-sets")
|
12
11
|
@coll = @db.collection("test-sets")
|
13
12
|
end
|
14
13
|
|
15
14
|
def teardown
|
16
|
-
|
15
|
+
@rs.restart_killed_nodes
|
17
16
|
@conn.close if @conn
|
18
17
|
end
|
19
18
|
|
20
19
|
def test_insert
|
21
|
-
@coll.save({:a => 20}, :safe =>
|
20
|
+
@coll.save({:a => 20}, :safe => {:w => 2})
|
22
21
|
|
23
|
-
|
22
|
+
@rs.kill_primary
|
24
23
|
|
25
24
|
rescue_connection_failure do
|
26
|
-
@coll.save({:a => 30}, :safe =>
|
25
|
+
@coll.save({:a => 30}, :safe => {:w => 2})
|
27
26
|
end
|
28
27
|
|
29
|
-
@coll.save({:a => 40}, :safe =>
|
30
|
-
@coll.save({:a => 50}, :safe =>
|
31
|
-
@coll.save({:a => 60}, :safe =>
|
32
|
-
@coll.save({:a => 70}, :safe =>
|
28
|
+
@coll.save({:a => 40}, :safe => {:w => 2})
|
29
|
+
@coll.save({:a => 50}, :safe => {:w => 2})
|
30
|
+
@coll.save({:a => 60}, :safe => {:w => 2})
|
31
|
+
@coll.save({:a => 70}, :safe => {:w => 2})
|
33
32
|
|
34
33
|
# Restart the old master and wait for sync
|
35
|
-
|
36
|
-
sleep(
|
34
|
+
@rs.restart_killed_nodes
|
35
|
+
sleep(5)
|
37
36
|
results = []
|
38
37
|
|
39
38
|
rescue_connection_failure do
|
@@ -43,7 +42,7 @@ class ReplicaSetInsertTest < Test::Unit::TestCase
|
|
43
42
|
end
|
44
43
|
end
|
45
44
|
|
46
|
-
@coll.save({:a => 80}, :safe =>
|
45
|
+
@coll.save({:a => 80}, :safe => {:w => 2})
|
47
46
|
@coll.find.each {|r| results << r}
|
48
47
|
[20, 30, 40, 50, 60, 70, 80].each do |a|
|
49
48
|
assert results.any? {|r| r['a'] == a}, "Could not find record for a => #{a} on second find"
|
@@ -4,32 +4,31 @@ require './test/replica_sets/rs_test_helper'
|
|
4
4
|
# NOTE: This test expects a replica set of three nodes to be running
|
5
5
|
# on the local host.
|
6
6
|
class ReplicaSetPooledInsertTest < Test::Unit::TestCase
|
7
|
-
include ReplicaSetTest
|
8
7
|
|
9
8
|
def setup
|
10
|
-
|
11
|
-
|
9
|
+
ensure_rs
|
10
|
+
@conn = ReplSetConnection.new(build_seeds(3), :pool_size => 5, :timeout => 5, :refresh_mode => false)
|
12
11
|
@db = @conn.db(MONGO_TEST_DB)
|
13
12
|
@db.drop_collection("test-sets")
|
14
13
|
@coll = @db.collection("test-sets")
|
15
14
|
end
|
16
15
|
|
17
16
|
def teardown
|
18
|
-
|
17
|
+
@rs.restart_killed_nodes
|
19
18
|
@conn.close if @conn
|
20
19
|
end
|
21
20
|
|
22
21
|
def test_insert
|
23
22
|
expected_results = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
24
|
-
@coll.save({:a => -1}, :safe =>
|
23
|
+
@coll.save({:a => -1}, :safe => {:w => 2})
|
25
24
|
|
26
|
-
|
25
|
+
@rs.kill_primary
|
27
26
|
|
28
27
|
threads = []
|
29
28
|
10.times do |i|
|
30
29
|
threads[i] = Thread.new do
|
31
30
|
rescue_connection_failure do
|
32
|
-
@coll.save({:a => i}, :safe =>
|
31
|
+
@coll.save({:a => i}, :safe => {:w => 2})
|
33
32
|
end
|
34
33
|
end
|
35
34
|
end
|
@@ -37,8 +36,8 @@ class ReplicaSetPooledInsertTest < Test::Unit::TestCase
|
|
37
36
|
threads.each {|t| t.join}
|
38
37
|
|
39
38
|
# Restart the old master and wait for sync
|
40
|
-
|
41
|
-
sleep(
|
39
|
+
@rs.restart_killed_nodes
|
40
|
+
sleep(5)
|
42
41
|
results = []
|
43
42
|
|
44
43
|
rescue_connection_failure do
|
@@ -48,7 +47,7 @@ class ReplicaSetPooledInsertTest < Test::Unit::TestCase
|
|
48
47
|
end
|
49
48
|
end
|
50
49
|
|
51
|
-
@coll.save({:a => 10}, :safe =>
|
50
|
+
@coll.save({:a => 10}, :safe => {:w => 2})
|
52
51
|
@coll.find.each {|r| results << r}
|
53
52
|
(expected_results + [10]).each do |a|
|
54
53
|
assert results.any? {|r| r['a'] == a}, "Could not find record for a => #{a} on second find"
|
@@ -2,17 +2,17 @@ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
2
2
|
require './test/replica_sets/rs_test_helper'
|
3
3
|
|
4
4
|
class ReplicaSetQueryTest < Test::Unit::TestCase
|
5
|
-
include ReplicaSetTest
|
6
5
|
|
7
6
|
def setup
|
8
|
-
|
7
|
+
ensure_rs
|
8
|
+
@conn = ReplSetConnection.new build_seeds(1)
|
9
9
|
@db = @conn.db(MONGO_TEST_DB)
|
10
10
|
@db.drop_collection("test-sets")
|
11
11
|
@coll = @db.collection("test-sets")
|
12
12
|
end
|
13
13
|
|
14
14
|
def teardown
|
15
|
-
|
15
|
+
@rs.restart_killed_nodes
|
16
16
|
@conn.close if @conn
|
17
17
|
end
|
18
18
|
|
@@ -28,7 +28,7 @@ class ReplicaSetQueryTest < Test::Unit::TestCase
|
|
28
28
|
|
29
29
|
puts "Benchmark before failover: #{benchmark_queries}"
|
30
30
|
|
31
|
-
|
31
|
+
@rs.kill_primary
|
32
32
|
|
33
33
|
results = []
|
34
34
|
rescue_connection_failure do
|
@@ -3,21 +3,25 @@ require './test/replica_sets/rs_test_helper'
|
|
3
3
|
require 'logger'
|
4
4
|
|
5
5
|
class ReadPreferenceTest < Test::Unit::TestCase
|
6
|
-
include ReplicaSetTest
|
7
6
|
|
8
7
|
def setup
|
8
|
+
ensure_rs
|
9
9
|
log = Logger.new("test.log")
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
seeds = build_seeds(2)
|
11
|
+
args = {
|
12
|
+
:read => :secondary,
|
13
|
+
:pool_size => 50,
|
14
|
+
:refresh_mode => false,
|
15
|
+
:refresh_interval => 5,
|
16
|
+
:logger => log
|
17
|
+
}
|
18
|
+
@conn = ReplSetConnection.new(seeds, args)
|
14
19
|
@db = @conn.db(MONGO_TEST_DB)
|
15
20
|
@db.drop_collection("test-sets")
|
16
|
-
col = @db['mongo-test']
|
17
21
|
end
|
18
22
|
|
19
23
|
def teardown
|
20
|
-
|
24
|
+
@rs.restart_killed_nodes
|
21
25
|
end
|
22
26
|
|
23
27
|
def test_read_primary
|
@@ -34,8 +38,38 @@ class ReadPreferenceTest < Test::Unit::TestCase
|
|
34
38
|
"Primary port and read port at the same!"
|
35
39
|
end
|
36
40
|
|
41
|
+
def test_read_secondary_only
|
42
|
+
@rs.add_arbiter
|
43
|
+
@rs.remove_secondary_node
|
44
|
+
|
45
|
+
@conn = ReplSetConnection.new(build_seeds(2), :read => :secondary_only)
|
46
|
+
|
47
|
+
@db = @conn.db(MONGO_TEST_DB)
|
48
|
+
@coll = @db.collection("test-sets")
|
49
|
+
|
50
|
+
@coll.save({:a => 20}, :safe => {:w => 2})
|
51
|
+
|
52
|
+
# Test that reads are going to secondary on ReplSetConnection
|
53
|
+
@secondary = Connection.new(@rs.host, @conn.read_pool.port, :slave_ok => true)
|
54
|
+
queries_before = @secondary['admin'].command({:serverStatus => 1})['opcounters']['query']
|
55
|
+
@coll.find_one
|
56
|
+
queries_after = @secondary['admin'].command({:serverStatus => 1})['opcounters']['query']
|
57
|
+
assert_equal 1, queries_after - queries_before
|
58
|
+
|
59
|
+
@rs.kill_secondary
|
60
|
+
@conn.refresh
|
61
|
+
|
62
|
+
# Test that reads are only allowed from secondaries
|
63
|
+
assert_raise ConnectionFailure.new("Could not connect to a secondary for reading.") do
|
64
|
+
@coll.find_one
|
65
|
+
end
|
66
|
+
|
67
|
+
@rs = ReplSetManager.new
|
68
|
+
@rs.start_set
|
69
|
+
end
|
70
|
+
|
37
71
|
def test_query_secondaries
|
38
|
-
@secondary = Connection.new(
|
72
|
+
@secondary = Connection.new(@rs.host, @conn.read_pool.port, :slave_ok => true)
|
39
73
|
@coll = @db.collection("test-sets", :safe => {:w => 3, :wtimeout => 20000})
|
40
74
|
@coll.save({:a => 20})
|
41
75
|
@coll.save({:a => 30})
|
@@ -49,7 +83,7 @@ class ReadPreferenceTest < Test::Unit::TestCase
|
|
49
83
|
assert results.include?(30)
|
50
84
|
assert results.include?(40)
|
51
85
|
|
52
|
-
|
86
|
+
@rs.kill_primary
|
53
87
|
|
54
88
|
results = []
|
55
89
|
rescue_connection_failure do
|
@@ -68,13 +102,13 @@ class ReadPreferenceTest < Test::Unit::TestCase
|
|
68
102
|
assert_equal 2, @coll.find.to_a.length
|
69
103
|
|
70
104
|
# Should still be able to read immediately after killing master node
|
71
|
-
|
105
|
+
@rs.kill_primary
|
72
106
|
assert_equal 2, @coll.find.to_a.length
|
73
107
|
rescue_connection_failure do
|
74
108
|
puts "@coll.save()"
|
75
109
|
@coll.save({:a => 50}, :safe => {:w => 2, :wtimeout => 10000})
|
76
110
|
end
|
77
|
-
|
111
|
+
@rs.restart_killed_nodes
|
78
112
|
@coll.save({:a => 50}, :safe => {:w => 2, :wtimeout => 10000})
|
79
113
|
assert_equal 4, @coll.find.to_a.length
|
80
114
|
end
|
@@ -85,8 +119,8 @@ class ReadPreferenceTest < Test::Unit::TestCase
|
|
85
119
|
@coll.save({:a => 30})
|
86
120
|
assert_equal 2, @coll.find.to_a.length
|
87
121
|
|
88
|
-
read_node =
|
89
|
-
|
122
|
+
read_node = @rs.get_node_from_port(@conn.read_pool.port)
|
123
|
+
@rs.kill(read_node)
|
90
124
|
|
91
125
|
# Should fail immediately on next read
|
92
126
|
old_read_pool_port = @conn.read_pool.port
|
@@ -141,7 +175,7 @@ class ReadPreferenceTest < Test::Unit::TestCase
|
|
141
175
|
# end
|
142
176
|
|
143
177
|
#def teardown
|
144
|
-
#
|
178
|
+
# @rs.restart_killed_nodes
|
145
179
|
#end
|
146
180
|
|
147
181
|
end
|