mongo 1.1.4 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +50 -69
- data/docs/CREDITS.md +4 -0
- data/docs/HISTORY.md +9 -0
- data/docs/REPLICA_SETS.md +8 -10
- data/lib/mongo.rb +3 -1
- data/lib/mongo/collection.rb +2 -1
- data/lib/mongo/connection.rb +146 -314
- data/lib/mongo/db.rb +6 -2
- data/lib/mongo/gridfs/grid.rb +1 -1
- data/lib/mongo/gridfs/grid_io.rb +29 -5
- data/lib/mongo/repl_set_connection.rb +290 -0
- data/lib/mongo/util/pool.rb +6 -8
- data/lib/mongo/util/uri_parser.rb +71 -0
- data/mongo.gemspec +1 -2
- data/test/collection_test.rb +9 -7
- data/test/connection_test.rb +0 -6
- data/test/grid_file_system_test.rb +2 -2
- data/test/grid_io_test.rb +33 -1
- data/test/grid_test.rb +36 -6
- data/test/replica_sets/connect_test.rb +59 -21
- data/test/replica_sets/count_test.rb +9 -7
- data/test/replica_sets/insert_test.rb +11 -9
- data/test/replica_sets/pooled_insert_test.rb +12 -13
- data/test/replica_sets/query_secondaries.rb +48 -8
- data/test/replica_sets/query_test.rb +10 -9
- data/test/replica_sets/replication_ack_test.rb +15 -22
- data/test/replica_sets/rs_test_helper.rb +29 -0
- data/test/test_helper.rb +13 -20
- data/test/threading/{test_threading_large_pool.rb → threading_with_large_pool_test.rb} +1 -1
- data/test/tools/repl_set_manager.rb +241 -0
- data/test/tools/test.rb +13 -0
- data/test/unit/connection_test.rb +3 -85
- data/test/unit/repl_set_connection_test.rb +82 -0
- metadata +19 -21
- data/test/replica_pairs/count_test.rb +0 -34
- data/test/replica_pairs/insert_test.rb +0 -50
- data/test/replica_pairs/pooled_insert_test.rb +0 -54
- data/test/replica_pairs/query_test.rb +0 -39
- data/test/replica_sets/node_type_test.rb +0 -42
- data/test/rs.rb +0 -24
data/mongo.gemspec
CHANGED
@@ -21,7 +21,6 @@ Gem::Specification.new do |s|
|
|
21
21
|
|
22
22
|
s.has_rdoc = true
|
23
23
|
s.test_files = Dir['test/**/*.rb']
|
24
|
-
s.test_files -= Dir['test/mongo_bson/*.rb'] # remove these files from the manifest
|
25
24
|
|
26
25
|
s.has_rdoc = true
|
27
26
|
s.rdoc_options = ['--main', 'README.md', '--inline-source']
|
@@ -31,5 +30,5 @@ Gem::Specification.new do |s|
|
|
31
30
|
s.email = 'mongodb-dev@googlegroups.com'
|
32
31
|
s.homepage = 'http://www.mongodb.org'
|
33
32
|
|
34
|
-
s.add_dependency(%q<bson>, [">=
|
33
|
+
s.add_dependency(%q<bson>, [">= #{Mongo::VERSION}"])
|
35
34
|
end
|
data/test/collection_test.rb
CHANGED
@@ -263,13 +263,12 @@ class TestCollection < Test::Unit::TestCase
|
|
263
263
|
@db = @conn[MONGO_TEST_DB]
|
264
264
|
@test = @db['test-safe-remove']
|
265
265
|
@test.save({:a => 50})
|
266
|
-
@test.remove({}, :safe => true)
|
266
|
+
assert_equal 1, @test.remove({}, :safe => true)["n"]
|
267
267
|
@test.drop
|
268
268
|
end
|
269
269
|
|
270
270
|
def test_remove_return_value
|
271
|
-
assert_equal
|
272
|
-
assert_equal 57, @@test.remove({"x" => 1})
|
271
|
+
assert_equal true, @@test.remove({})
|
273
272
|
end
|
274
273
|
|
275
274
|
def test_count
|
@@ -579,13 +578,16 @@ class TestCollection < Test::Unit::TestCase
|
|
579
578
|
@@test.ensure_index([["x", Mongo::ASCENDING]])
|
580
579
|
assert @@test.index_information.keys.include? "x_1"
|
581
580
|
|
581
|
+
@@test.ensure_index([["type", 1], ["date", -1]])
|
582
|
+
assert @@test.index_information.keys.include? "type_1_date_-1"
|
583
|
+
|
582
584
|
@@test.drop_index("x_1")
|
583
|
-
assert_equal
|
585
|
+
assert_equal 3, @@test.index_information.keys.count
|
584
586
|
@@test.drop_index("x_-1")
|
585
|
-
assert_equal 1, @@test.index_information.keys.count
|
586
|
-
|
587
|
-
@@test.ensure_index([["x", Mongo::DESCENDING]], {}) #should work as not cached.
|
588
587
|
assert_equal 2, @@test.index_information.keys.count
|
588
|
+
|
589
|
+
@@test.ensure_index([["x", Mongo::DESCENDING]], {})
|
590
|
+
assert_equal 3, @@test.index_information.keys.count
|
589
591
|
assert @@test.index_information.keys.include? "x_-1"
|
590
592
|
|
591
593
|
# Make sure that drop_index expires cache properly
|
data/test/connection_test.rb
CHANGED
@@ -49,12 +49,6 @@ class TestConnection < Test::Unit::TestCase
|
|
49
49
|
assert_raise Mongo::InvalidNSName do @conn.db('te st') end
|
50
50
|
end
|
51
51
|
|
52
|
-
def test_replica_set_connection_name
|
53
|
-
assert_raise Mongo::ReplicaSetConnectionError do
|
54
|
-
standard_connection(:rs_name => "replica-set-wrong-name")
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
52
|
def test_options_passed_to_db
|
59
53
|
@pk_mock = Object.new
|
60
54
|
db = @conn.db('test', :pk => @pk_mock, :strict => true)
|
data/test/grid_io_test.rb
CHANGED
@@ -33,6 +33,39 @@ class GridIOTest < Test::Unit::TestCase
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
+
context "Seeking" do
|
37
|
+
setup do
|
38
|
+
@filename = 'test'
|
39
|
+
@mode = 'w'
|
40
|
+
@data = "1" * 1024 * 1024
|
41
|
+
@file = GridIO.new(@files, @chunks, @filename, @mode)
|
42
|
+
@file.write(@data)
|
43
|
+
@file.close
|
44
|
+
end
|
45
|
+
|
46
|
+
should "read all data using read_length and then be able to seek" do
|
47
|
+
file = GridIO.new(@files, @chunks, nil, "r", :query => {:_id => @file.files_id})
|
48
|
+
assert_equal @data, file.read(1024 * 1024)
|
49
|
+
file.seek(0)
|
50
|
+
assert_equal @data, file.read
|
51
|
+
end
|
52
|
+
|
53
|
+
should "read all data using read_all and then be able to seek" do
|
54
|
+
file = GridIO.new(@files, @chunks, nil, "r", :query => {:_id => @file.files_id})
|
55
|
+
assert_equal @data, file.read
|
56
|
+
file.seek(0)
|
57
|
+
assert_equal @data, file.read
|
58
|
+
file.seek(1024 * 512)
|
59
|
+
assert_equal 524288, file.file_position
|
60
|
+
assert_equal @data.length / 2, file.read.length
|
61
|
+
assert_equal 1048576, file.file_position
|
62
|
+
assert_nil file.read
|
63
|
+
file.seek(1024 * 512)
|
64
|
+
assert_equal 524288, file.file_position
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
36
69
|
context "Grid MD5 check" do
|
37
70
|
should "run in safe mode" do
|
38
71
|
file = GridIO.new(@files, @chunks, 'smallfile', 'w', :safe => true)
|
@@ -62,7 +95,6 @@ class GridIOTest < Test::Unit::TestCase
|
|
62
95
|
end
|
63
96
|
|
64
97
|
context "Content types" do
|
65
|
-
|
66
98
|
if defined?(MIME)
|
67
99
|
should "determine common content types from the extension" do
|
68
100
|
file = GridIO.new(@files, @chunks, 'sample.pdf', 'w')
|
data/test/grid_test.rb
CHANGED
@@ -18,7 +18,8 @@ class GridTest < Test::Unit::TestCase
|
|
18
18
|
setup do
|
19
19
|
@data = "GRIDDATA" * 50000
|
20
20
|
@grid = Grid.new(@db, 'test-fs')
|
21
|
-
@id = @grid.put(@data, :filename => 'sample',
|
21
|
+
@id = @grid.put(@data, :filename => 'sample',
|
22
|
+
:metadata => {'app' => 'photos'})
|
22
23
|
end
|
23
24
|
|
24
25
|
should "check existence" do
|
@@ -120,7 +121,8 @@ class GridTest < Test::Unit::TestCase
|
|
120
121
|
context "Storing data with a length of zero" do
|
121
122
|
setup do
|
122
123
|
@grid = Grid.new(@db, 'test-fs')
|
123
|
-
@id = @grid.put('', :filename => 'sample',
|
124
|
+
@id = @grid.put('', :filename => 'sample',
|
125
|
+
:metadata => {'app' => 'photos'})
|
124
126
|
end
|
125
127
|
|
126
128
|
should "return the zero length" do
|
@@ -129,6 +131,34 @@ class GridTest < Test::Unit::TestCase
|
|
129
131
|
end
|
130
132
|
end
|
131
133
|
|
134
|
+
context "Grid streaming: " do
|
135
|
+
setup do
|
136
|
+
@grid = Grid.new(@db, 'test-fs')
|
137
|
+
filename = 'sample_data'
|
138
|
+
@io = File.open(File.join(File.dirname(__FILE__), 'data', filename), 'r')
|
139
|
+
id = @grid.put(@io, :filename => filename)
|
140
|
+
@file = @grid.get(id)
|
141
|
+
@io.rewind
|
142
|
+
@data = @io.read
|
143
|
+
if @data.respond_to?(:force_encoding)
|
144
|
+
@data.force_encoding("binary")
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
should "read the file" do
|
149
|
+
read_data = ""
|
150
|
+
@file.each do |chunk|
|
151
|
+
read_data << chunk
|
152
|
+
end
|
153
|
+
assert_equal @data.length, read_data.length
|
154
|
+
end
|
155
|
+
|
156
|
+
should "read the file if no block is given" do
|
157
|
+
read_data = @file.each
|
158
|
+
assert_equal @data.length, read_data.length
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
132
162
|
context "Streaming: " do || {}
|
133
163
|
setup do
|
134
164
|
def read_and_write_stream(filename, read_length, opts={})
|
@@ -158,12 +188,12 @@ class GridTest < Test::Unit::TestCase
|
|
158
188
|
read_and_write_stream('small_data.txt', 1)
|
159
189
|
end
|
160
190
|
|
161
|
-
should "put and get a large io object
|
162
|
-
read_and_write_stream('
|
191
|
+
should "put and get a large io object if reading less than the chunk size" do
|
192
|
+
read_and_write_stream('sample_data', 256 * 1024)
|
163
193
|
end
|
164
194
|
|
165
|
-
should "put and get a large io object
|
166
|
-
read_and_write_stream('
|
195
|
+
should "put and get a large io object if reading more than the chunk size" do
|
196
|
+
read_and_write_stream('sample_data', 300 * 1024)
|
167
197
|
end
|
168
198
|
end
|
169
199
|
end
|
@@ -1,46 +1,84 @@
|
|
1
1
|
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
-
require '
|
3
|
-
require 'test/unit'
|
4
|
-
require './test/test_helper'
|
2
|
+
require './test/replica_sets/rs_test_helper'
|
5
3
|
|
6
|
-
# NOTE: This test expects a replica set of three nodes to be running on
|
4
|
+
# NOTE: This test expects a replica set of three nodes to be running on RS.host,
|
5
|
+
# on ports TEST_PORT, RS.ports[1], and TEST + 2.
|
7
6
|
class ConnectTest < Test::Unit::TestCase
|
8
7
|
include Mongo
|
9
8
|
|
9
|
+
def setup
|
10
|
+
RS.restart_killed_nodes
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown
|
14
|
+
RS.restart_killed_nodes
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_connect_with_deprecated_multi
|
18
|
+
@conn = Connection.multi([[RS.host, RS.ports[0]], [RS.host, RS.ports[1]]], :name => RS.name)
|
19
|
+
assert @conn.connected?
|
20
|
+
assert @conn.is_a?(ReplSetConnection)
|
21
|
+
end
|
22
|
+
|
10
23
|
def test_connect_bad_name
|
11
|
-
assert_raise_error(ReplicaSetConnectionError, "
|
12
|
-
|
13
|
-
:rs_name => "wrong
|
24
|
+
assert_raise_error(ReplicaSetConnectionError, "-wrong") do
|
25
|
+
ReplSetConnection.new([RS.host, RS.ports[0]], [RS.host, RS.ports[1]],
|
26
|
+
[RS.host, RS.ports[2]], :rs_name => RS.name + "-wrong")
|
14
27
|
end
|
15
28
|
end
|
16
29
|
|
17
30
|
def test_connect
|
18
|
-
@conn =
|
19
|
-
|
31
|
+
@conn = ReplSetConnection.new([RS.host, RS.ports[0]], [RS.host, RS.ports[1]],
|
32
|
+
[RS.host, RS.ports[2]], :name => RS.name)
|
20
33
|
assert @conn.connected?
|
34
|
+
|
35
|
+
assert_equal RS.primary, @conn.primary
|
36
|
+
assert_equal RS.secondaries.sort, @conn.secondaries.sort
|
37
|
+
assert_equal RS.arbiters.sort, @conn.arbiters.sort
|
21
38
|
end
|
22
39
|
|
23
|
-
def
|
24
|
-
|
25
|
-
gets
|
40
|
+
def test_connect_with_primary_node_killed
|
41
|
+
node = RS.kill_primary
|
26
42
|
|
27
|
-
|
43
|
+
# Becuase we're killing the primary and trying to connect right away,
|
44
|
+
# this is going to fail right away.
|
45
|
+
assert_raise_error(ConnectionFailure, "Failed to connect to primary node") do
|
46
|
+
@conn = ReplSetConnection.new([RS.host, RS.ports[0]], [RS.host, RS.ports[1]],
|
47
|
+
[RS.host, RS.ports[2]])
|
48
|
+
end
|
49
|
+
|
50
|
+
# This allows the secondary to come up as a primary
|
51
|
+
rescue_connection_failure do
|
52
|
+
@conn = ReplSetConnection.new([RS.host, RS.ports[0]], [RS.host, RS.ports[1]],
|
53
|
+
[RS.host, RS.ports[2]])
|
54
|
+
end
|
55
|
+
assert @conn.connected?
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_connect_with_secondary_node_killed
|
59
|
+
node = RS.kill_secondary
|
60
|
+
|
61
|
+
@conn = ReplSetConnection.new([RS.host, RS.ports[0]], [RS.host, RS.ports[1]],
|
62
|
+
[RS.host, RS.ports[2]])
|
28
63
|
assert @conn.connected?
|
29
64
|
end
|
30
65
|
|
31
|
-
def
|
32
|
-
|
33
|
-
gets
|
66
|
+
def test_connect_with_third_node_killed
|
67
|
+
RS.kill(RS.get_node_from_port(RS.ports[2]))
|
34
68
|
|
35
|
-
@conn =
|
69
|
+
@conn = ReplSetConnection.new([RS.host, RS.ports[0]], [RS.host, RS.ports[1]],
|
70
|
+
[RS.host, RS.ports[2]])
|
36
71
|
assert @conn.connected?
|
37
72
|
end
|
38
73
|
|
39
|
-
def
|
40
|
-
|
41
|
-
gets
|
74
|
+
def test_connect_with_primary_stepped_down
|
75
|
+
RS.step_down_primary
|
42
76
|
|
43
|
-
|
77
|
+
rescue_connection_failure do
|
78
|
+
@conn = ReplSetConnection.new([RS.host, RS.ports[0]], [RS.host, RS.ports[1]],
|
79
|
+
[RS.host, RS.ports[2]])
|
80
|
+
end
|
44
81
|
assert @conn.connected?
|
45
82
|
end
|
83
|
+
|
46
84
|
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
-
require '
|
3
|
-
require 'test/unit'
|
4
|
-
require './test/test_helper'
|
2
|
+
require './test/replica_sets/rs_test_helper'
|
5
3
|
|
6
4
|
# NOTE: This test expects a replica set of three nodes to be running
|
7
5
|
# on the local host.
|
@@ -9,18 +7,22 @@ class ReplicaSetCountTest < Test::Unit::TestCase
|
|
9
7
|
include Mongo
|
10
8
|
|
11
9
|
def setup
|
12
|
-
@conn =
|
10
|
+
@conn = ReplSetConnection.new([RS.host, RS.ports[0]], [RS.host, RS.ports[1]], [RS.host, RS.ports[2]])
|
13
11
|
@db = @conn.db(MONGO_TEST_DB)
|
14
12
|
@db.drop_collection("test-sets")
|
15
13
|
@coll = @db.collection("test-sets")
|
16
14
|
end
|
17
15
|
|
16
|
+
def teardown
|
17
|
+
RS.restart_killed_nodes
|
18
|
+
end
|
19
|
+
|
18
20
|
def test_correct_count_after_insertion_reconnect
|
19
|
-
@coll.insert({:a => 20}
|
21
|
+
@coll.insert({:a => 20}, :safe => {:w => 2, :wtimeout => 10000})
|
20
22
|
assert_equal 1, @coll.count
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
+
# Kill the current master node
|
25
|
+
@node = RS.kill_primary
|
24
26
|
|
25
27
|
rescue_connection_failure do
|
26
28
|
@coll.insert({:a => 30}, :safe => true)
|
@@ -1,7 +1,5 @@
|
|
1
1
|
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
-
require '
|
3
|
-
require 'test/unit'
|
4
|
-
require './test/test_helper'
|
2
|
+
require './test/replica_sets/rs_test_helper'
|
5
3
|
|
6
4
|
# NOTE: This test expects a replica set of three nodes to be running
|
7
5
|
# on the local host.
|
@@ -9,16 +7,20 @@ class ReplicaSetInsertTest < Test::Unit::TestCase
|
|
9
7
|
include Mongo
|
10
8
|
|
11
9
|
def setup
|
12
|
-
@conn =
|
10
|
+
@conn = ReplSetConnection.new([TEST_HOST, RS.ports[0]], [TEST_HOST, RS.ports[1]], [TEST_HOST, RS.ports[2]])
|
13
11
|
@db = @conn.db(MONGO_TEST_DB)
|
14
12
|
@db.drop_collection("test-sets")
|
15
13
|
@coll = @db.collection("test-sets")
|
16
14
|
end
|
17
15
|
|
16
|
+
def teardown
|
17
|
+
RS.restart_killed_nodes
|
18
|
+
end
|
19
|
+
|
18
20
|
def test_insert
|
19
21
|
@coll.save({:a => 20}, :safe => true)
|
20
|
-
|
21
|
-
|
22
|
+
|
23
|
+
RS.kill_primary
|
22
24
|
|
23
25
|
rescue_connection_failure do
|
24
26
|
@coll.save({:a => 30}, :safe => true)
|
@@ -29,9 +31,9 @@ class ReplicaSetInsertTest < Test::Unit::TestCase
|
|
29
31
|
@coll.save({:a => 60}, :safe => true)
|
30
32
|
@coll.save({:a => 70}, :safe => true)
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
34
|
+
# Restart the old master and wait for sync
|
35
|
+
RS.restart_killed_nodes
|
36
|
+
sleep(1)
|
35
37
|
results = []
|
36
38
|
|
37
39
|
rescue_connection_failure do
|
@@ -1,7 +1,5 @@
|
|
1
1
|
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
-
require '
|
3
|
-
require 'test/unit'
|
4
|
-
require './test/test_helper'
|
2
|
+
require './test/replica_sets/rs_test_helper'
|
5
3
|
|
6
4
|
# NOTE: This test expects a replica set of three nodes to be running
|
7
5
|
# on the local host.
|
@@ -9,18 +7,22 @@ class ReplicaSetPooledInsertTest < Test::Unit::TestCase
|
|
9
7
|
include Mongo
|
10
8
|
|
11
9
|
def setup
|
12
|
-
@conn =
|
13
|
-
|
10
|
+
@conn = ReplSetConnection.new([RS.host, RS.ports[0]], [RS.host, RS.ports[1]],
|
11
|
+
[RS.host, RS.ports[2]], :pool_size => 10, :timeout => 5)
|
14
12
|
@db = @conn.db(MONGO_TEST_DB)
|
15
13
|
@db.drop_collection("test-sets")
|
16
14
|
@coll = @db.collection("test-sets")
|
17
15
|
end
|
18
16
|
|
17
|
+
def teardown
|
18
|
+
RS.restart_killed_nodes
|
19
|
+
end
|
20
|
+
|
19
21
|
def test_insert
|
20
22
|
expected_results = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
21
23
|
@coll.save({:a => -1}, :safe => true)
|
22
|
-
|
23
|
-
|
24
|
+
|
25
|
+
RS.kill_primary
|
24
26
|
|
25
27
|
threads = []
|
26
28
|
10.times do |i|
|
@@ -31,12 +33,9 @@ class ReplicaSetPooledInsertTest < Test::Unit::TestCase
|
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
"after restarting the old master so that all the data has had a chance to sync." +
|
38
|
-
"This is a case of eventual consistency."
|
39
|
-
gets
|
36
|
+
# Restart the old master and wait for sync
|
37
|
+
RS.restart_killed_nodes
|
38
|
+
sleep(1)
|
40
39
|
results = []
|
41
40
|
|
42
41
|
rescue_connection_failure do
|
@@ -1,7 +1,5 @@
|
|
1
1
|
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
-
require '
|
3
|
-
require 'test/unit'
|
4
|
-
require './test/test_helper'
|
2
|
+
require './test/replica_sets/rs_test_helper'
|
5
3
|
|
6
4
|
# NOTE: This test expects a replica set of three nodes to be running
|
7
5
|
# on the local host.
|
@@ -9,13 +7,24 @@ class ReplicaSetQuerySecondariesTest < Test::Unit::TestCase
|
|
9
7
|
include Mongo
|
10
8
|
|
11
9
|
def setup
|
12
|
-
@conn =
|
10
|
+
@conn = ReplSetConnection.new([RS.host, RS.ports[0]], :read_secondary => true)
|
13
11
|
@db = @conn.db(MONGO_TEST_DB)
|
14
12
|
@db.drop_collection("test-sets")
|
15
|
-
@coll = @db.collection("test-sets", :safe => {:w => 2, :wtimeout => 100})
|
16
13
|
end
|
17
14
|
|
18
|
-
def
|
15
|
+
def teardown
|
16
|
+
RS.restart_killed_nodes
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_con
|
20
|
+
assert @conn.primary_pool, "No primary pool!"
|
21
|
+
assert @conn.read_pool, "No read pool!"
|
22
|
+
assert @conn.primary_pool.port != @conn.read_pool.port,
|
23
|
+
"Primary port and read port at the same!"
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_query_secondaries
|
27
|
+
@coll = @db.collection("test-sets", :safe => {:w => 3, :wtimeout => 10000})
|
19
28
|
@coll.save({:a => 20})
|
20
29
|
@coll.save({:a => 30})
|
21
30
|
@coll.save({:a => 40})
|
@@ -25,8 +34,7 @@ class ReplicaSetQuerySecondariesTest < Test::Unit::TestCase
|
|
25
34
|
assert results.include?(30)
|
26
35
|
assert results.include?(40)
|
27
36
|
|
28
|
-
|
29
|
-
gets
|
37
|
+
RS.kill_primary
|
30
38
|
|
31
39
|
results = []
|
32
40
|
rescue_connection_failure do
|
@@ -37,4 +45,36 @@ class ReplicaSetQuerySecondariesTest < Test::Unit::TestCase
|
|
37
45
|
end
|
38
46
|
end
|
39
47
|
|
48
|
+
def test_kill_primary
|
49
|
+
@coll = @db.collection("test-sets", :safe => {:w => 3, :wtimeout => 10000})
|
50
|
+
@coll.save({:a => 20})
|
51
|
+
@coll.save({:a => 30})
|
52
|
+
assert_equal 2, @coll.find.to_a.length
|
53
|
+
|
54
|
+
# Should still be able to read immediately after killing master node
|
55
|
+
RS.kill_primary
|
56
|
+
assert_equal 2, @coll.find.to_a.length
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_kill_secondary
|
60
|
+
@coll = @db.collection("test-sets", {:safe => {:w => 3, :wtimeout => 10000}})
|
61
|
+
@coll.save({:a => 20})
|
62
|
+
@coll.save({:a => 30})
|
63
|
+
assert_equal 2, @coll.find.to_a.length
|
64
|
+
|
65
|
+
read_node = RS.get_node_from_port(@conn.read_pool.port)
|
66
|
+
RS.kill(read_node)
|
67
|
+
|
68
|
+
# Should fail immediately on next read
|
69
|
+
assert_raise ConnectionFailure do
|
70
|
+
@coll.find.to_a.length
|
71
|
+
end
|
72
|
+
|
73
|
+
# Should eventually reconnect and be able to read
|
74
|
+
rescue_connection_failure do
|
75
|
+
length = @coll.find.to_a.length
|
76
|
+
assert_equal 2, length
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
40
80
|
end
|