mongo 1.8.0 → 1.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. data/README.md +14 -29
  2. data/VERSION +1 -1
  3. data/lib/mongo.rb +3 -0
  4. data/lib/mongo/collection.rb +99 -49
  5. data/lib/mongo/cursor.rb +17 -17
  6. data/lib/mongo/db.rb +30 -14
  7. data/lib/mongo/gridfs/grid.rb +5 -3
  8. data/lib/mongo/gridfs/grid_file_system.rb +5 -3
  9. data/lib/mongo/gridfs/grid_io.rb +5 -3
  10. data/lib/mongo/legacy.rb +9 -2
  11. data/lib/mongo/mongo_client.rb +100 -72
  12. data/lib/mongo/mongo_replica_set_client.rb +46 -60
  13. data/lib/mongo/mongo_sharded_client.rb +5 -66
  14. data/lib/mongo/networking.rb +2 -1
  15. data/lib/mongo/util/node.rb +41 -42
  16. data/lib/mongo/util/pool.rb +15 -43
  17. data/lib/mongo/util/pool_manager.rb +16 -65
  18. data/lib/mongo/util/read_preference.rb +82 -0
  19. data/lib/mongo/util/sharding_pool_manager.rb +0 -86
  20. data/lib/mongo/util/ssl_socket.rb +2 -1
  21. data/lib/mongo/util/support.rb +8 -18
  22. data/lib/mongo/util/tcp_socket.rb +5 -4
  23. data/lib/mongo/util/thread_local_variable_manager.rb +29 -0
  24. data/lib/mongo/util/unix_socket.rb +23 -0
  25. data/lib/mongo/util/uri_parser.rb +31 -18
  26. data/lib/mongo/util/write_concern.rb +7 -2
  27. data/mongo.gemspec +1 -1
  28. data/test/auxillary/repl_set_auth_test.rb +2 -2
  29. data/test/bson/bson_test.rb +1 -1
  30. data/test/bson/byte_buffer_test.rb +24 -26
  31. data/test/bson/hash_with_indifferent_access_test.rb +11 -1
  32. data/test/functional/collection_test.rb +16 -16
  33. data/test/functional/connection_test.rb +1 -4
  34. data/test/functional/db_api_test.rb +14 -10
  35. data/test/functional/pool_test.rb +23 -31
  36. data/test/functional/timeout_test.rb +3 -5
  37. data/test/functional/uri_test.rb +10 -5
  38. data/test/replica_set/basic_test.rb +3 -8
  39. data/test/replica_set/client_test.rb +47 -31
  40. data/test/replica_set/complex_connect_test.rb +12 -10
  41. data/test/replica_set/connection_test.rb +8 -151
  42. data/test/replica_set/count_test.rb +9 -5
  43. data/test/replica_set/cursor_test.rb +17 -27
  44. data/test/replica_set/insert_test.rb +5 -10
  45. data/test/replica_set/query_test.rb +4 -9
  46. data/test/replica_set/read_preference_test.rb +200 -0
  47. data/test/replica_set/refresh_test.rb +54 -65
  48. data/test/replica_set/replication_ack_test.rb +16 -14
  49. data/test/sharded_cluster/basic_test.rb +30 -0
  50. data/test/test_helper.rb +33 -15
  51. data/test/threading/basic_test.rb +79 -0
  52. data/test/tools/mongo_config.rb +62 -22
  53. data/test/unit/client_test.rb +36 -14
  54. data/test/unit/collection_test.rb +23 -0
  55. data/test/unit/connection_test.rb +30 -14
  56. data/test/unit/cursor_test.rb +137 -7
  57. data/test/unit/db_test.rb +17 -4
  58. data/test/unit/grid_test.rb +2 -2
  59. data/test/unit/node_test.rb +2 -1
  60. data/test/unit/pool_manager_test.rb +29 -1
  61. data/test/unit/read_test.rb +15 -15
  62. data/test/unit/safe_test.rb +4 -4
  63. data/test/unit/write_concern_test.rb +4 -4
  64. metadata +134 -143
  65. data/examples/admin.rb +0 -43
  66. data/examples/capped.rb +0 -22
  67. data/examples/cursor.rb +0 -48
  68. data/examples/gridfs.rb +0 -44
  69. data/examples/index_test.rb +0 -126
  70. data/examples/info.rb +0 -31
  71. data/examples/queries.rb +0 -74
  72. data/examples/replica_set.rb +0 -26
  73. data/examples/simple.rb +0 -25
  74. data/examples/strict.rb +0 -35
  75. data/examples/types.rb +0 -36
  76. data/examples/web/thin/load.rb +0 -23
  77. data/examples/web/unicorn/load.rb +0 -25
  78. data/test/support/hash_with_indifferent_access.rb +0 -186
  79. data/test/support/keys.rb +0 -45
  80. data/test/threading/threading_with_large_pool_test.rb +0 -90
@@ -16,11 +16,6 @@ class ReplicaSetCountTest < Test::Unit::TestCase
16
16
  @client.close if @conn
17
17
  end
18
18
 
19
- def self.shutdown
20
- @@cluster.stop
21
- @@cluster.clobber
22
- end
23
-
24
19
  def test_correct_count_after_insertion_reconnect
25
20
  @coll.insert({:a => 20}, :w => 2, :wtimeout => 10000)
26
21
  assert_equal 1, @coll.count
@@ -43,4 +38,13 @@ class ReplicaSetCountTest < Test::Unit::TestCase
43
38
  count_after = @primary['admin'].command({:serverStatus => 1})['opcounters']['command']
44
39
  assert_equal 2, count_after - count_before
45
40
  end
41
+
42
+ def test_count_with_read
43
+ @coll.insert({:a => 20}, :w => 2, :wtimeout => 10000)
44
+ count_before = @primary['admin'].command({:serverStatus => 1})['opcounters']['command']
45
+ assert_equal 1, @coll.count(:read => :secondary)
46
+ assert_equal 1, @coll.find({}, :read => :secondary).count()
47
+ count_after = @primary['admin'].command({:serverStatus => 1})['opcounters']['command']
48
+ assert_equal 1, count_after - count_before
49
+ end
46
50
  end
@@ -6,37 +6,29 @@ class ReplicaSetCursorTest < Test::Unit::TestCase
6
6
  ensure_cluster(:rs)
7
7
  end
8
8
 
9
- def self.shutdown
10
- @@cluster.stop
11
- @@cluster.clobber
12
- end
13
-
14
9
  def test_cursors_get_closed
15
10
  setup_client
16
11
  assert_cursor_count
17
12
  end
18
13
 
19
- #def test_cursors_get_closed_secondary
20
- # setup_client(:secondary)
21
- # assert_cursor_count
22
- #end
14
+ def test_cursors_get_closed_secondary
15
+ setup_client(:secondary)
16
+ assert_cursor_count
17
+ end
23
18
 
24
19
  private
25
20
 
26
21
  def setup_client(read=:primary)
27
22
  # Setup ReplicaSet Connection
28
- @client = MongoReplicaSetClient.new(
29
- @rs.repl_set_seeds,
30
- :read => read
31
- )
23
+ @client = MongoReplicaSetClient.new(@rs.repl_set_seeds, :read => read)
32
24
 
33
25
  @db = @client.db(MONGO_TEST_DB)
34
26
  @db.drop_collection("cursor_tests")
35
27
  @coll = @db.collection("cursor_tests")
36
28
 
37
- @coll.insert({:a => 1}, :w => 3)
38
- @coll.insert({:b => 2}, :w => 3)
39
- @coll.insert({:c => 3}, :w => 3)
29
+ @coll.insert({:a => 1}, :w => 2)
30
+ @coll.insert({:b => 2}, :w => 2)
31
+ @coll.insert({:c => 3}, :w => 2)
40
32
 
41
33
  # Pin reader
42
34
  @coll.find_one
@@ -55,21 +47,19 @@ class ReplicaSetCursorTest < Test::Unit::TestCase
55
47
  end
56
48
 
57
49
  def assert_cursor_count
58
- before_primary = cursor_count(@primary)
59
- before_read = cursor_count(@read)
60
- before_query = query_count(@read)
50
+ before_primary_cursor = cursor_count(@primary)
51
+ before_read_cursor = cursor_count(@read)
52
+ before_read_query = query_count(@read)
61
53
 
62
54
  @coll.find.limit(2).to_a
63
- sleep(1)
64
55
 
65
- after_primary = cursor_count(@primary)
66
- after_read = cursor_count(@read)
67
- after_query = query_count(@read)
56
+ after_primary_cursor = cursor_count(@primary)
57
+ after_read_cursor = cursor_count(@read)
58
+ after_read_query = query_count(@read)
68
59
 
69
- assert_equal before_primary, after_primary
70
- assert_equal before_read, after_read
71
- assert_equal 1, after_query - before_query
60
+ assert_equal before_primary_cursor, after_primary_cursor
61
+ assert_equal before_read_cursor, after_read_cursor
62
+ assert_equal 1, after_read_query - before_read_query
72
63
  end
73
64
 
74
65
  end
75
-
@@ -14,24 +14,19 @@ class ReplicaSetInsertTest < Test::Unit::TestCase
14
14
  @client.close if @conn
15
15
  end
16
16
 
17
- def self.shutdown
18
- @@cluster.stop
19
- @@cluster.clobber
20
- end
21
-
22
17
  def test_insert
23
18
  @coll.save({:a => 20}, :w => 2)
24
19
 
25
20
  @rs.primary.stop
26
21
 
27
22
  rescue_connection_failure do
28
- @coll.save({:a => 30}, :w => 2)
23
+ @coll.save({:a => 30}, :w => 1)
29
24
  end
30
25
 
31
- @coll.save({:a => 40}, :w => 2)
32
- @coll.save({:a => 50}, :w => 2)
33
- @coll.save({:a => 60}, :w => 2)
34
- @coll.save({:a => 70}, :w => 2)
26
+ @coll.save({:a => 40}, :w => 1)
27
+ @coll.save({:a => 50}, :w => 1)
28
+ @coll.save({:a => 60}, :w => 1)
29
+ @coll.save({:a => 70}, :w => 1)
35
30
 
36
31
  # Restart the old master and wait for sync
37
32
  @rs.start
@@ -14,15 +14,10 @@ class ReplicaSetQueryTest < Test::Unit::TestCase
14
14
  @client.close if @conn
15
15
  end
16
16
 
17
- def self.shutdown
18
- @@cluster.stop
19
- @@cluster.clobber
20
- end
21
-
22
17
  def test_query
23
- @coll.save({:a => 20}, :w => 3)
24
- @coll.save({:a => 30}, :w => 3)
25
- @coll.save({:a => 40}, :w => 3)
18
+ @coll.save({:a => 20}, :w => 2)
19
+ @coll.save({:a => 30}, :w => 2)
20
+ @coll.save({:a => 40}, :w => 2)
26
21
  results = []
27
22
  @coll.find.each {|r| results << r}
28
23
  [20, 30, 40].each do |a|
@@ -48,7 +43,7 @@ class ReplicaSetQueryTest < Test::Unit::TestCase
48
43
  # primary, where it does not exist.
49
44
  # def test_secondary_getmore
50
45
  # 200.times do |i|
51
- # @coll.save({:a => i}, :w => 3)
46
+ # @coll.save({:a => i}, :w => 2)
52
47
  # end
53
48
  # as = []
54
49
  # # Set an explicit batch size, in case the default ever changes.
@@ -0,0 +1,200 @@
1
+ require 'test_helper'
2
+
3
+ class ReadPreferenceTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ ensure_cluster(:rs, :replicas => 2, :arbiters => 0)
7
+
8
+ # Insert data
9
+ primary = @rs.primary
10
+ conn = Connection.new(primary.host, primary.port)
11
+ db = conn.db(MONGO_TEST_DB)
12
+ coll = db.collection("test-sets")
13
+ coll.save({:a => 20}, {:w => 2})
14
+ end
15
+
16
+ def test_read_primary
17
+ conn = make_connection
18
+ rescue_connection_failure do
19
+ assert conn.read_primary?
20
+ assert conn.primary?
21
+ end
22
+
23
+ conn = make_connection(:primary_preferred)
24
+ rescue_connection_failure do
25
+ assert conn.read_primary?
26
+ assert conn.primary?
27
+ end
28
+
29
+ conn = make_connection(:secondary)
30
+ rescue_connection_failure do
31
+ assert !conn.read_primary?
32
+ assert !conn.primary?
33
+ end
34
+
35
+ conn = make_connection(:secondary_preferred)
36
+ rescue_connection_failure do
37
+ assert !conn.read_primary?
38
+ assert !conn.primary?
39
+ end
40
+ end
41
+
42
+ def test_connection_pools
43
+ conn = make_connection
44
+ assert conn.primary_pool, "No primary pool!"
45
+ assert conn.read_pool, "No read pool!"
46
+ assert conn.primary_pool.port == conn.read_pool.port,
47
+ "Primary port and read port are not the same!"
48
+
49
+ conn = make_connection(:primary_preferred)
50
+ assert conn.primary_pool, "No primary pool!"
51
+ assert conn.read_pool, "No read pool!"
52
+ assert conn.primary_pool.port == conn.read_pool.port,
53
+ "Primary port and read port are not the same!"
54
+
55
+ conn = make_connection(:secondary)
56
+ assert conn.primary_pool, "No primary pool!"
57
+ assert conn.read_pool, "No read pool!"
58
+ assert conn.primary_pool.port != conn.read_pool.port,
59
+ "Primary port and read port are the same!"
60
+
61
+ conn = make_connection(:secondary_preferred)
62
+ assert conn.primary_pool, "No primary pool!"
63
+ assert conn.read_pool, "No read pool!"
64
+ assert conn.primary_pool.port != conn.read_pool.port,
65
+ "Primary port and read port are the same!"
66
+ end
67
+
68
+ def test_read_routing
69
+ prepare_routing_test
70
+
71
+ # Test that reads are going to the right members
72
+ assert_query_route(@primary, @primary_direct)
73
+ assert_query_route(@primary_preferred, @primary_direct)
74
+ assert_query_route(@secondary, @secondary_direct)
75
+ assert_query_route(@secondary_preferred, @secondary_direct)
76
+ end
77
+
78
+ def test_read_routing_with_primary_down
79
+ prepare_routing_test
80
+
81
+ # Test that reads are going to the right members
82
+ assert_query_route(@primary, @primary_direct)
83
+ assert_query_route(@primary_preferred, @primary_direct)
84
+ assert_query_route(@secondary, @secondary_direct)
85
+ assert_query_route(@secondary_preferred, @secondary_direct)
86
+
87
+ # Kill the primary so only a single secondary exists
88
+ @rs.primary.kill
89
+
90
+ # Test that reads are going to the right members
91
+ assert_raise_error ConnectionFailure do
92
+ @primary[MONGO_TEST_DB]['test-sets'].find_one
93
+ end
94
+ assert_query_route(@primary_preferred, @secondary_direct)
95
+ assert_query_route(@secondary, @secondary_direct)
96
+ assert_query_route(@secondary_preferred, @secondary_direct)
97
+
98
+ # Restore set
99
+ @rs.restart
100
+ sleep(1)
101
+ @repl_cons.each { |con| con.refresh }
102
+ sleep(1)
103
+ @primary_direct = Connection.new(
104
+ @rs.config['host'],
105
+ @primary.read_pool.port
106
+ )
107
+
108
+ # Test that reads are going to the right members
109
+ assert_query_route(@primary, @primary_direct)
110
+ assert_query_route(@primary_preferred, @primary_direct)
111
+ assert_query_route(@secondary, @secondary_direct)
112
+ assert_query_route(@secondary_preferred, @secondary_direct)
113
+ end
114
+
115
+ def test_read_routing_with_secondary_down
116
+ prepare_routing_test
117
+
118
+ # Test that reads are going to the right members
119
+ assert_query_route(@primary, @primary_direct)
120
+ assert_query_route(@primary_preferred, @primary_direct)
121
+ assert_query_route(@secondary, @secondary_direct)
122
+ assert_query_route(@secondary_preferred, @secondary_direct)
123
+
124
+ # Kill the secondary so that only primary exists
125
+ @rs.secondaries.first.kill
126
+
127
+ # Test that reads are going to the right members
128
+ assert_query_route(@primary, @primary_direct)
129
+ assert_query_route(@primary_preferred, @primary_direct)
130
+ assert_raise_error ConnectionFailure do
131
+ @secondary[MONGO_TEST_DB]['test-sets'].find_one
132
+ end
133
+ assert_query_route(@secondary_preferred, @primary_direct)
134
+
135
+ # Restore set
136
+ @rs.restart
137
+ sleep(1)
138
+ @repl_cons.each { |con| con.refresh }
139
+ sleep(1)
140
+ @secondary_direct = Connection.new(
141
+ @rs.config['host'],
142
+ @secondary.read_pool.port,
143
+ :slave_ok => true
144
+ )
145
+
146
+ # Test that reads are going to the right members
147
+ assert_query_route(@primary, @primary_direct)
148
+ assert_query_route(@primary_preferred, @primary_direct)
149
+ assert_query_route(@secondary, @secondary_direct)
150
+ assert_query_route(@secondary_preferred, @secondary_direct)
151
+ end
152
+
153
+ def test_write_lots_of_data
154
+ @conn = make_connection(:secondary_preferred)
155
+ @db = @conn[MONGO_TEST_DB]
156
+ @coll = @db.collection("test-sets", {:w => 2})
157
+
158
+ 6000.times do |n|
159
+ @coll.save({:a => n})
160
+ end
161
+
162
+ cursor = @coll.find()
163
+ cursor.next
164
+ cursor.close
165
+ end
166
+
167
+ private
168
+
169
+ def prepare_routing_test
170
+ # Setup replica set connections
171
+ @primary = make_connection(:primary)
172
+ @primary_preferred = make_connection(:primary_preferred)
173
+ @secondary = make_connection(:secondary)
174
+ @secondary_preferred = make_connection(:secondary_preferred)
175
+ @repl_cons = [@primary, @primary_preferred, @secondary, @secondary_preferred]
176
+
177
+ # Setup direct connections
178
+ @primary_direct = Connection.new(@rs.config['host'], @primary.read_pool.port)
179
+ @secondary_direct = Connection.new(@rs.config['host'], @secondary.read_pool.port, :slave_ok => true)
180
+ end
181
+
182
+ def make_connection(mode = :primary, opts = {})
183
+ opts.merge!({:read => mode})
184
+ MongoReplicaSetClient.new(@rs.repl_set_seeds, opts)
185
+ end
186
+
187
+ def query_count(connection)
188
+ connection['admin'].command({:serverStatus => 1})['opcounters']['query']
189
+ end
190
+
191
+ def assert_query_route(test_connection, expected_target)
192
+ #puts "#{test_connection.read_pool.port} #{expected_target.read_pool.port}"
193
+ queries_before = query_count(expected_target)
194
+ assert_nothing_raised do
195
+ test_connection['MONGO_TEST_DB']['test-sets'].find_one
196
+ end
197
+ queries_after = query_count(expected_target)
198
+ assert_equal 1, queries_after - queries_before
199
+ end
200
+ end
@@ -7,147 +7,136 @@ class ReplicaSetRefreshTest < Test::Unit::TestCase
7
7
  ensure_cluster(:rs)
8
8
  end
9
9
 
10
- def self.shutdown
11
- @@cluster.stop
12
- @@cluster.clobber
13
- end
14
-
15
10
  def test_connect_and_manual_refresh_with_secondaries_down
16
11
  @rs.secondaries.each{|s| s.stop}
12
+ client = MongoReplicaSetClient.new(@rs.repl_set_seeds, :refresh_mode => false)
17
13
 
18
- rescue_connection_failure do
19
- @client = MongoReplicaSetClient.new(@rs.repl_set_seeds, :refresh_mode => false)
20
- end
21
-
22
- assert_equal [], @client.secondaries
23
- assert @client.connected?
24
- assert_equal @client.read_pool, @client.primary_pool
14
+ assert_equal Set.new, client.secondaries
15
+ assert client.connected?
16
+ assert_equal client.read_pool, client.primary_pool
25
17
 
26
18
  # Refresh with no change to set
27
- @client.refresh
28
- assert_equal [], @client.secondaries
29
- assert @client.connected?
30
- assert_equal @client.read_pool, @client.primary_pool
19
+ client.refresh
20
+ assert_equal Set.new, client.secondaries
21
+ assert client.connected?
22
+ assert_equal client.read_pool, client.primary_pool
31
23
 
32
24
  # Test no changes after restart until manual refresh
33
25
  @rs.restart
34
- assert_equal [], @client.secondaries
35
- assert @client.connected?
36
- assert_equal @client.read_pool, @client.primary_pool
26
+ assert_equal Set.new, client.secondaries
27
+ assert client.connected?
28
+ assert_equal client.read_pool, client.primary_pool
37
29
 
38
30
  # Refresh and ensure state
39
- @client.refresh
40
- assert_equal @client.read_pool, @client.primary_pool
41
- #assert_equal 2, @client.secondaries.length
31
+ client.refresh
32
+ assert_equal client.read_pool, client.primary_pool
33
+ assert_equal 1, client.secondaries.length
42
34
  end
43
35
 
44
36
  def test_automated_refresh_with_secondaries_down
45
37
  @rs.secondaries.each{|s| s.stop}
46
-
47
- rescue_connection_failure do
48
- @client = MongoReplicaSetClient.new(@rs.repl_set_seeds,
49
- :refresh_interval => 1, :refresh_mode => :sync, :read => :secondary_preferred)
50
- end
38
+ client = MongoReplicaSetClient.new(@rs.repl_set_seeds,
39
+ :refresh_interval => 1, :refresh_mode => :sync, :read => :secondary_preferred)
51
40
 
52
41
  # Ensure secondaries not available and read from primary
53
- assert_equal [], @client.secondaries
54
- assert @client.connected?
55
- assert_equal @client.manager.read, @client.manager.primary
56
- old_refresh_version = @client.refresh_version
42
+ assert_equal Set.new, client.secondaries
43
+ assert client.connected?
44
+ assert client.manager.pools.member?(client.manager.read_pool)
45
+ old_refresh_version = client.refresh_version
57
46
 
58
47
  # Restart nodes and ensure refresh interval has passed
59
48
  @rs.restart
60
49
  sleep(2)
61
50
 
62
- assert @client.refresh_version == old_refresh_version,
51
+ assert client.refresh_version == old_refresh_version,
63
52
  "Refresh version has changed."
64
53
 
65
54
  # Trigger synchronous refresh
66
- @client['foo']['bar'].find_one
55
+ client['foo']['bar'].find_one
67
56
 
68
- assert @client.refresh_version > old_refresh_version,
57
+ assert client.refresh_version > old_refresh_version,
69
58
  "Refresh version hasn't changed."
70
- assert @client.secondaries.length == 2,
59
+ assert client.secondaries.length == 1,
71
60
  "No secondaries have been added."
72
- assert @client.manager.read != @client.manager.primary,
61
+ assert client.manager.read_pool != client.manager.primary,
73
62
  "Read pool and primary pool are identical."
74
63
  end
75
64
 
76
65
  def test_automated_refresh_when_secondary_goes_down
77
- @client = MongoReplicaSetClient.new(@rs.repl_set_seeds,
66
+ client = MongoReplicaSetClient.new(@rs.repl_set_seeds,
78
67
  :refresh_interval => 1, :refresh_mode => :sync)
79
68
 
80
- num_secondaries = @client.secondary_pools.length
81
- old_refresh_version = @client.refresh_version
69
+ num_secondaries = client.secondary_pools.length
70
+ old_refresh_version = client.refresh_version
82
71
 
83
- @rs.secondaries.first.kill
84
- sleep(2)
72
+ @rs.kill_secondary
73
+ sleep(1)
85
74
 
86
- assert @client.refresh_version == old_refresh_version,
75
+ assert client.refresh_version == old_refresh_version,
87
76
  "Refresh version has changed."
88
77
 
89
- @client['foo']['bar'].find_one
78
+ client['foo']['bar'].find_one
90
79
 
91
- assert @client.refresh_version > old_refresh_version,
80
+ assert client.refresh_version > old_refresh_version,
92
81
  "Refresh version hasn't changed."
93
- assert_equal num_secondaries - 1, @client.secondaries.length
94
- assert_equal num_secondaries - 1, @client.secondary_pools.length
82
+ assert_equal num_secondaries - 1, client.secondaries.length
83
+ assert_equal num_secondaries - 1, client.secondary_pools.length
95
84
 
96
85
  @rs.start
97
86
  sleep(2)
98
87
 
99
- @client['foo']['bar'].find_one
88
+ client['foo']['bar'].find_one
100
89
 
101
- assert_equal num_secondaries, @client.secondaries.length
102
- assert_equal num_secondaries, @client.secondary_pools.length
90
+ assert_equal num_secondaries, client.secondaries.length
91
+ assert_equal num_secondaries, client.secondary_pools.length
103
92
  end
104
93
  =begin
105
94
  def test_automated_refresh_with_removed_node
106
- @client = MongoReplicaSetClient.new(@rs.repl_set_seeds,
95
+ client = MongoReplicaSetClient.new(@rs.repl_set_seeds,
107
96
  :refresh_interval => 1, :refresh_mode => :sync)
108
97
 
109
- num_secondaries = @client.secondary_pools.length
110
- old_refresh_version = @client.refresh_version
98
+ num_secondaries = client.secondary_pools.length
99
+ old_refresh_version = client.refresh_version
111
100
 
112
101
  n = @rs.repl_set_remove_node(2)
113
102
  sleep(2)
114
103
 
115
104
  rescue_connection_failure do
116
- @client['foo']['bar'].find_one
105
+ client['foo']['bar'].find_one
117
106
  end
118
107
 
119
- assert @client.refresh_version > old_refresh_version,
108
+ assert client.refresh_version > old_refresh_version,
120
109
  "Refresh version hasn't changed."
121
- assert_equal num_secondaries - 1, @client.secondaries.length
122
- assert_equal num_secondaries - 1, @client.secondary_pools.length
110
+ assert_equal num_secondaries - 1, client.secondaries.length
111
+ assert_equal num_secondaries - 1, client.secondary_pools.length
123
112
 
124
113
  #@rs.add_node(n)
125
114
  end
126
115
 
127
116
  def test_adding_and_removing_nodes
128
- @client = MongoReplicaSetClient.new(build_seeds(3),
117
+ client = MongoReplicaSetClient.new(build_seeds(3),
129
118
  :refresh_interval => 2, :refresh_mode => :sync)
130
119
 
131
120
  @rs.add_node
132
121
  sleep(4)
133
- @client['foo']['bar'].find_one
122
+ client['foo']['bar'].find_one
134
123
 
135
124
  @conn2 = MongoReplicaSetClient.new(build_seeds(3),
136
125
  :refresh_interval => 2, :refresh_mode => :sync)
137
126
 
138
- assert @conn2.secondaries.sort == @client.secondaries.sort,
127
+ assert @conn2.secondaries.sort == client.secondaries.sort,
139
128
  "Second connection secondaries not equal to first."
140
- assert_equal 3, @client.secondary_pools.length
141
- assert_equal 3, @client.secondaries.length
129
+ assert_equal 3, client.secondary_pools.length
130
+ assert_equal 3, client.secondaries.length
142
131
 
143
- config = @client['admin'].command({:ismaster => 1})
132
+ config = client['admin'].command({:ismaster => 1})
144
133
 
145
134
  @rs.remove_secondary_node
146
135
  sleep(4)
147
- config = @client['admin'].command({:ismaster => 1})
136
+ config = client['admin'].command({:ismaster => 1})
148
137
 
149
- assert_equal 2, @client.secondary_pools.length
150
- assert_equal 2, @client.secondaries.length
138
+ assert_equal 2, client.secondary_pools.length
139
+ assert_equal 2, client.secondaries.length
151
140
  end
152
141
  =end
153
142
  end