mongo 1.9.2 → 1.10.0.rc0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/LICENSE +1 -1
  5. data/README.md +94 -334
  6. data/Rakefile +6 -4
  7. data/VERSION +1 -1
  8. data/bin/mongo_console +13 -6
  9. data/lib/mongo.rb +22 -27
  10. data/lib/mongo/bulk_write_collection_view.rb +352 -0
  11. data/lib/mongo/collection.rb +128 -188
  12. data/lib/mongo/collection_writer.rb +348 -0
  13. data/lib/mongo/connection.rb +19 -0
  14. data/lib/mongo/{util → connection}/node.rb +15 -1
  15. data/lib/mongo/{util → connection}/pool.rb +34 -19
  16. data/lib/mongo/{util → connection}/pool_manager.rb +8 -2
  17. data/lib/mongo/{util → connection}/sharding_pool_manager.rb +1 -1
  18. data/lib/mongo/connection/socket.rb +18 -0
  19. data/lib/mongo/{util → connection/socket}/socket_util.rb +5 -2
  20. data/lib/mongo/{util → connection/socket}/ssl_socket.rb +3 -4
  21. data/lib/mongo/{util → connection/socket}/tcp_socket.rb +25 -15
  22. data/lib/mongo/{util → connection/socket}/unix_socket.rb +6 -4
  23. data/lib/mongo/cursor.rb +113 -47
  24. data/lib/mongo/db.rb +203 -131
  25. data/lib/mongo/{exceptions.rb → exception.rb} +7 -1
  26. data/lib/mongo/functional.rb +19 -0
  27. data/lib/mongo/functional/authentication.rb +303 -0
  28. data/lib/mongo/{util → functional}/logging.rb +1 -1
  29. data/lib/mongo/{util → functional}/read_preference.rb +49 -1
  30. data/lib/mongo/{util → functional}/uri_parser.rb +81 -69
  31. data/lib/mongo/{util → functional}/write_concern.rb +2 -1
  32. data/{test/unit/pool_test.rb → lib/mongo/gridfs.rb} +5 -10
  33. data/lib/mongo/gridfs/grid.rb +1 -3
  34. data/lib/mongo/gridfs/grid_ext.rb +1 -1
  35. data/lib/mongo/gridfs/grid_file_system.rb +1 -1
  36. data/lib/mongo/gridfs/grid_io.rb +1 -1
  37. data/lib/mongo/legacy.rb +63 -8
  38. data/lib/mongo/mongo_client.rb +128 -154
  39. data/lib/mongo/mongo_replica_set_client.rb +17 -11
  40. data/lib/mongo/mongo_sharded_client.rb +2 -1
  41. data/lib/mongo/networking.rb +19 -10
  42. data/lib/mongo/utils.rb +19 -0
  43. data/lib/mongo/{util → utils}/conversions.rb +1 -1
  44. data/lib/mongo/{util → utils}/core_ext.rb +1 -1
  45. data/lib/mongo/{util → utils}/server_version.rb +1 -1
  46. data/lib/mongo/{util → utils}/support.rb +10 -57
  47. data/lib/mongo/{util → utils}/thread_local_variable_manager.rb +1 -1
  48. data/test/functional/authentication_test.rb +8 -21
  49. data/test/functional/bulk_write_collection_view_test.rb +782 -0
  50. data/test/functional/{connection_test.rb → client_test.rb} +153 -78
  51. data/test/functional/collection_test.rb +343 -97
  52. data/test/functional/collection_writer_test.rb +83 -0
  53. data/test/functional/conversions_test.rb +1 -3
  54. data/test/functional/cursor_fail_test.rb +3 -3
  55. data/test/functional/cursor_message_test.rb +3 -3
  56. data/test/functional/cursor_test.rb +38 -3
  57. data/test/functional/db_api_test.rb +5 -5
  58. data/test/functional/db_connection_test.rb +2 -2
  59. data/test/functional/db_test.rb +35 -11
  60. data/test/functional/grid_file_system_test.rb +2 -2
  61. data/test/functional/grid_io_test.rb +2 -2
  62. data/test/functional/grid_test.rb +2 -2
  63. data/test/functional/pool_test.rb +2 -3
  64. data/test/functional/safe_test.rb +5 -5
  65. data/test/functional/ssl_test.rb +22 -102
  66. data/test/functional/support_test.rb +1 -1
  67. data/test/functional/timeout_test.rb +6 -22
  68. data/test/functional/uri_test.rb +113 -12
  69. data/test/functional/write_concern_test.rb +6 -6
  70. data/test/helpers/general.rb +50 -0
  71. data/test/helpers/test_unit.rb +309 -0
  72. data/test/replica_set/authentication_test.rb +8 -23
  73. data/test/replica_set/basic_test.rb +41 -14
  74. data/test/replica_set/client_test.rb +179 -117
  75. data/test/replica_set/complex_connect_test.rb +6 -7
  76. data/test/replica_set/connection_test.rb +46 -38
  77. data/test/replica_set/count_test.rb +2 -2
  78. data/test/replica_set/cursor_test.rb +8 -8
  79. data/test/replica_set/insert_test.rb +64 -2
  80. data/test/replica_set/max_values_test.rb +59 -10
  81. data/test/replica_set/pinning_test.rb +2 -2
  82. data/test/replica_set/query_test.rb +2 -2
  83. data/test/replica_set/read_preference_test.rb +6 -6
  84. data/test/replica_set/refresh_test.rb +7 -7
  85. data/test/replica_set/replication_ack_test.rb +5 -5
  86. data/test/replica_set/ssl_test.rb +24 -106
  87. data/test/sharded_cluster/basic_test.rb +43 -15
  88. data/test/shared/authentication/basic_auth_shared.rb +215 -0
  89. data/test/shared/authentication/sasl_plain_shared.rb +96 -0
  90. data/test/shared/ssl_shared.rb +173 -0
  91. data/test/test_helper.rb +31 -199
  92. data/test/threading/basic_test.rb +29 -3
  93. data/test/tools/mongo_config.rb +45 -20
  94. data/test/tools/mongo_config_test.rb +1 -1
  95. data/test/unit/client_test.rb +136 -57
  96. data/test/unit/collection_test.rb +31 -55
  97. data/test/unit/connection_test.rb +135 -72
  98. data/test/unit/cursor_test.rb +2 -2
  99. data/test/unit/db_test.rb +19 -15
  100. data/test/unit/grid_test.rb +2 -2
  101. data/test/unit/mongo_sharded_client_test.rb +17 -15
  102. data/test/unit/node_test.rb +2 -2
  103. data/test/unit/pool_manager_test.rb +7 -5
  104. data/test/unit/read_pref_test.rb +82 -2
  105. data/test/unit/read_test.rb +14 -14
  106. data/test/unit/safe_test.rb +9 -9
  107. data/test/unit/sharding_pool_manager_test.rb +11 -5
  108. data/test/unit/write_concern_test.rb +9 -9
  109. metadata +71 -56
  110. metadata.gz.sig +0 -0
  111. data/test/functional/threading_test.rb +0 -109
  112. data/test/shared/authentication.rb +0 -121
  113. data/test/unit/util_test.rb +0 -69
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013 10gen Inc.
1
+ # Copyright (C) 2009-2013 MongoDB, Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -13,34 +13,19 @@
13
13
  # limitations under the License.
14
14
 
15
15
  require 'test_helper'
16
- require 'shared/authentication'
16
+ require 'shared/authentication/basic_auth_shared'
17
+ require 'shared/authentication/sasl_plain_shared'
17
18
 
18
19
  class ReplicaSetAuthenticationTest < Test::Unit::TestCase
19
20
  include Mongo
20
- include AuthenticationTests
21
+ include BasicAuthTests
22
+ include SASLPlainTests
21
23
 
22
24
  def setup
23
25
  ensure_cluster(:rs)
24
- @client = MongoReplicaSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name, :connect_timeout => 60)
25
- @db = @client[MONGO_TEST_DB]
26
+ @client = MongoReplicaSetClient.new(@rs.repl_set_seeds)
27
+ @db = @client[TEST_DB]
28
+ @host_info = @rs.repl_set_seeds.join(',')
26
29
  init_auth
27
30
  end
28
-
29
- def test_authenticate_with_connection_uri
30
- @db.add_user('eunice', 'uritest')
31
-
32
- client =
33
- MongoReplicaSetClient.from_uri(
34
- "mongodb://eunice:uritest@#{@rs.repl_set_seeds.join(',')}/#{@db.name}" +
35
- "?replicaSet=#{@rs.repl_set_name}")
36
-
37
- assert client
38
- assert_equal client.auths.size, 1
39
- assert client[MONGO_TEST_DB]['auth_test'].count
40
-
41
- auth = client.auths.first
42
- assert_equal @db.name, auth[:db_name]
43
- assert_equal 'eunice', auth[:username]
44
- assert_equal 'uritest', auth[:password]
45
- end
46
31
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013 10gen Inc.
1
+ # Copyright (C) 2009-2013 MongoDB, Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
14
14
 
15
15
  require 'test_helper'
16
16
 
17
- class BasicTest < Test::Unit::TestCase
17
+ class ReplicaSetBasicTest < Test::Unit::TestCase
18
18
 
19
19
  def setup
20
20
  ensure_cluster(:rs)
@@ -88,30 +88,57 @@ class BasicTest < Test::Unit::TestCase
88
88
  client.close
89
89
  end
90
90
 
91
+ def test_write_commands_and_operations
92
+ seeds = @rs.repl_set_seeds
93
+ args = {:name => @rs.repl_set_name}
94
+ @client = MongoReplicaSetClient.new(seeds, args)
95
+ @coll = @client[TEST_DB]['test-write-commands-and-operations']
96
+ with_write_commands_and_operations(@client) do
97
+ @coll.remove
98
+ @coll.insert({:foo => "bar"})
99
+ assert_equal(1, @coll.count)
100
+ end
101
+ end
102
+
91
103
  context "Socket pools" do
92
104
  context "checking out writers" do
93
105
  setup do
94
106
  seeds = @rs.repl_set_seeds
95
107
  args = {:name => @rs.repl_set_name}
96
108
  @client = MongoReplicaSetClient.new(seeds, args)
97
- @coll = @client[MONGO_TEST_DB]['test-connection-exceptions']
109
+ @coll = @client[TEST_DB]['test-connection-exceptions']
98
110
  end
99
111
 
100
112
  should "close the connection on send_message for major exceptions" do
101
- @client.expects(:checkout_writer).raises(SystemStackError)
102
- @client.expects(:close)
103
- begin
104
- @coll.insert({:foo => "bar"})
105
- rescue SystemStackError
113
+ with_write_operations(@client) do # explicit even if w 0 maps to write operations
114
+ @client.expects(:checkout_writer).raises(SystemStackError)
115
+ @client.expects(:close)
116
+ begin
117
+ @coll.insert({:foo => "bar"}, :w => 0)
118
+ rescue SystemStackError
119
+ end
120
+ end
121
+ end
122
+
123
+ should "close the connection on send_write_command for major exceptions" do
124
+ with_write_commands(@client) do
125
+ @client.expects(:checkout_reader).raises(SystemStackError)
126
+ @client.expects(:close)
127
+ begin
128
+ @coll.insert({:foo => "bar"})
129
+ rescue SystemStackError
130
+ end
106
131
  end
107
132
  end
108
133
 
109
134
  should "close the connection on send_message_with_gle for major exceptions" do
110
- @client.expects(:checkout_writer).raises(SystemStackError)
111
- @client.expects(:close)
112
- begin
113
- @coll.insert({:foo => "bar"})
114
- rescue SystemStackError
135
+ with_write_operations(@client) do
136
+ @client.expects(:checkout_writer).raises(SystemStackError)
137
+ @client.expects(:close)
138
+ begin
139
+ @coll.insert({:foo => "bar"})
140
+ rescue SystemStackError
141
+ end
115
142
  end
116
143
  end
117
144
 
@@ -130,7 +157,7 @@ class BasicTest < Test::Unit::TestCase
130
157
  seeds = @rs.repl_set_seeds
131
158
  args = {:name => @rs.repl_set_name}
132
159
  @client = MongoReplicaSetClient.new(seeds, args)
133
- @coll = @client[MONGO_TEST_DB]['test-connection-exceptions']
160
+ @coll = @client[TEST_DB]['test-connection-exceptions']
134
161
  end
135
162
 
136
163
  should "close the connection on receive_message for major exceptions" do
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013 10gen Inc.
1
+ # Copyright (C) 2009-2013 MongoDB, Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
14
14
 
15
15
  require 'test_helper'
16
16
 
17
- class ClientTest < Test::Unit::TestCase
17
+ class ReplicaSetClientTest < Test::Unit::TestCase
18
18
 
19
19
  def setup
20
20
  ensure_cluster(:rs)
@@ -77,35 +77,35 @@ class ClientTest < Test::Unit::TestCase
77
77
 
78
78
  def test_connect_with_primary_stepped_down
79
79
  @client = MongoReplicaSetClient.new @rs.repl_set_seeds
80
- @client[MONGO_TEST_DB]['bar'].save({:a => 1}, {:w => 3})
81
- assert @client[MONGO_TEST_DB]['bar'].find_one
80
+ @client[TEST_DB]['bar'].save({:a => 1}, {:w => 3})
81
+ assert @client[TEST_DB]['bar'].find_one
82
82
 
83
83
  primary = Mongo::MongoClient.new(*@client.primary)
84
84
  assert_raise Mongo::ConnectionFailure do
85
- primary['admin'].command(step_down_command)
85
+ perform_step_down(primary)
86
86
  end
87
87
  assert @client.connected?
88
88
 
89
89
  rescue_connection_failure do
90
- @client[MONGO_TEST_DB]['bar'].find_one
90
+ @client[TEST_DB]['bar'].find_one
91
91
  end
92
- @client[MONGO_TEST_DB]['bar'].find_one
92
+ @client[TEST_DB]['bar'].find_one
93
93
  end
94
94
 
95
95
  def test_connect_with_primary_killed
96
96
  @client = MongoReplicaSetClient.new @rs.repl_set_seeds
97
97
  assert @client.connected?
98
- @client[MONGO_TEST_DB]['bar'].save({:a => 1}, {:w => 3})
99
- assert @client[MONGO_TEST_DB]['bar'].find_one
98
+ @client[TEST_DB]['bar'].save({:a => 1}, {:w => 3})
99
+ assert @client[TEST_DB]['bar'].find_one
100
100
 
101
101
  @rs.primary.kill(Signal.list['KILL'])
102
102
 
103
103
  sleep(3)
104
104
 
105
105
  rescue_connection_failure do
106
- @client[MONGO_TEST_DB]['bar'].find_one
106
+ @client[TEST_DB]['bar'].find_one
107
107
  end
108
- @client[MONGO_TEST_DB]['bar'].find_one
108
+ @client[TEST_DB]['bar'].find_one
109
109
  end
110
110
 
111
111
  def test_save_with_primary_stepped_down
@@ -114,84 +114,101 @@ class ClientTest < Test::Unit::TestCase
114
114
 
115
115
  primary = Mongo::MongoClient.new(*@client.primary)
116
116
  assert_raise Mongo::ConnectionFailure do
117
- primary['admin'].command(step_down_command)
117
+ perform_step_down(primary)
118
118
  end
119
119
 
120
120
  rescue_connection_failure do
121
- @client[MONGO_TEST_DB]['bar'].save({:a => 1}, {:w => 2})
121
+ @client[TEST_DB]['bar'].save({:a => 1}, {:w => 2})
122
122
  end
123
- @client[MONGO_TEST_DB]['bar'].find_one
123
+ @client[TEST_DB]['bar'].find_one
124
124
  end
125
125
 
126
- #def test_connect_with_first_node_removed
127
- # @client = MongoReplicaSetClient.new @rs.repl_set_seeds
128
- # @client[MONGO_TEST_DB]['bar'].save({:a => 1}, {:w => 3})
129
- #
130
- # old_primary = [@client.primary_pool.host, @client.primary_pool.port]
131
- # old_primary_conn = Mongo::MongoClient.new(*old_primary)
132
- # assert_raise Mongo::ConnectionFailure do
133
- # old_primary_conn['admin'].command(step_down_command)
134
- # end
135
- #
136
- # # Wait for new primary
137
- # rescue_connection_failure do
138
- # sleep 1 until @rs.get_node_with_state(1)
139
- # end
140
- #
141
- # new_primary = @rs.get_all_host_pairs_with_state(1).first
142
- # new_primary_conn = Mongo::MongoClient.new(*new_primary)
143
- #
144
- # config = nil
145
- #
146
- # # Remove old primary from replset
147
- # rescue_connection_failure do
148
- # config = @client['local']['system.replset'].find_one
149
- # end
150
- #
151
- # old_member = config['members'].select {|m| m['host'] == old_primary.join(':')}.first
152
- # config['members'].reject! {|m| m['host'] == old_primary.join(':')}
153
- # config['version'] += 1
154
- #
155
- # begin
156
- # new_primary_conn['admin'].command({'replSetReconfig' => config})
157
- # rescue Mongo::ConnectionFailure
158
- # end
159
- #
160
- # # Wait for the dust to settle
161
- # rescue_connection_failure do
162
- # assert @client[MONGO_TEST_DB]['bar'].find_one
163
- # end
164
- #
165
- # # Make sure a new connection skips the old primary
166
- # @new_conn = MongoReplicaSetClient.new @rs.repl_set_seeds
167
- # @new_conn.connect
168
- # new_nodes = [@new_conn.primary] + @new_conn.secondaries
169
- # assert !(new_nodes).include?(old_primary)
170
- #
171
- # # Add the old primary back
172
- # config['members'] << old_member
173
- # config['version'] += 1
174
- #
175
- # begin
176
- # new_primary_conn['admin'].command({'replSetReconfig' => config})
177
- # rescue Mongo::ConnectionFailure
178
- # end
179
- #end
180
-
181
- #def test_connect_with_hung_first_node
182
- # hung_node = nil
183
- # begin
184
- # hung_node = IO.popen('nc -lk 127.0.0.1 29999 >/dev/null 2>&1')
185
- #
186
- # @client = MongoReplicaSetClient.new(['localhost:29999'] + @rs.repl_set_seeds,
187
- # :connect_timeout => 2)
188
- # @client.connect
189
- # assert ['localhost:29999'] != @client.primary
190
- # assert !@client.secondaries.include?('localhost:29999')
191
- # ensure
192
- # Process.kill("KILL", hung_node.pid) if hung_node
193
- # end
194
- #end
126
+ # def test_connect_with_first_node_removed
127
+ # @client = MongoReplicaSetClient.new @rs.repl_set_seeds
128
+ # @client[TEST_DB]['bar'].save({:a => 1}, {:w => 3})
129
+
130
+ # # Make sure everyone's views of optimes are caught up
131
+ # loop do
132
+ # break if @rs.repl_set_get_status.all? do |status|
133
+ # members = status['members']
134
+ # primary_optime = members.find{|m| m['state'] == 1}['optime'].seconds
135
+ # members.any?{|m| m['state'] == 2 && primary_optime - m['optime'].seconds < 5}
136
+ # end
137
+ # sleep 1
138
+ # end
139
+
140
+ # old_primary = [@client.primary_pool.host, @client.primary_pool.port]
141
+ # old_primary_conn = Mongo::MongoClient.new(*old_primary)
142
+
143
+ # assert_raise Mongo::ConnectionFailure do
144
+ # perform_step_down(old_primary_conn)
145
+ # end
146
+
147
+ # # Wait for new primary
148
+ # rescue_connection_failure do
149
+ # sleep 1 until @rs.primary
150
+ # end
151
+
152
+ # new_primary = [@rs.primary.host, @rs.primary.port]
153
+ # new_primary_conn = Mongo::MongoClient.new(*new_primary)
154
+
155
+ # assert new_primary != old_primary
156
+
157
+ # config = nil
158
+
159
+ # # Remove old primary from replset
160
+ # rescue_connection_failure do
161
+ # config = @client['local']['system.replset'].find_one
162
+ # end
163
+
164
+ # old_member = config['members'].select {|m| m['host'] == old_primary.join(':')}.first
165
+ # config['members'].reject! {|m| m['host'] == old_primary.join(':')}
166
+ # config['version'] += 1
167
+
168
+ # begin
169
+ # new_primary_conn['admin'].command({'replSetReconfig' => config})
170
+ # rescue Mongo::ConnectionFailure
171
+ # end
172
+
173
+ # # Wait for the dust to settle
174
+ # rescue_connection_failure do
175
+ # assert @client[TEST_DB]['bar'].find_one
176
+ # end
177
+
178
+ # begin
179
+ # # Make sure a new connection skips the old primary
180
+ # @new_conn = MongoReplicaSetClient.new @rs.repl_set_seeds
181
+ # @new_conn.connect
182
+ # new_nodes = @new_conn.secondaries + [@new_conn.primary]
183
+ # assert !new_nodes.include?(old_primary)
184
+ # ensure
185
+ # # Add the old primary back
186
+ # config['members'] << old_member
187
+ # config['version'] += 1
188
+
189
+ # begin
190
+ # new_primary_conn['admin'].command({'replSetReconfig' => config})
191
+ # rescue Mongo::ConnectionFailure
192
+ # end
193
+ # end
194
+ # end
195
+
196
+ def test_connect_with_hung_first_node
197
+ hung_node = nil
198
+ begin
199
+ hung_node = IO.popen('nc -lk 127.0.0.1 29999 >/dev/null 2>&1')
200
+
201
+ Timeout.timeout(3) do
202
+ @client = MongoReplicaSetClient.new(['localhost:29999'] + @rs.repl_set_seeds,
203
+ :connect_timeout => 2)
204
+ @client.connect
205
+ end
206
+ assert ['localhost:29999'] != @client.primary
207
+ assert !@client.secondaries.include?('localhost:29999')
208
+ ensure
209
+ Process.kill("KILL", hung_node.pid) if hung_node
210
+ end
211
+ end
195
212
 
196
213
  def test_connect_with_connection_string
197
214
  @client = MongoClient.from_uri("mongodb://#{@rs.replicas[0].host_port},#{@rs.replicas[1].host_port}?replicaset=#{@rs.repl_set_name}")
@@ -200,29 +217,33 @@ class ClientTest < Test::Unit::TestCase
200
217
  end
201
218
 
202
219
  def test_connect_with_connection_string_in_env_var
203
- ENV['MONGODB_URI'] = "mongodb://#{@rs.replicas[0].host_port},#{@rs.replicas[1].host_port}?replicaset=#{@rs.repl_set_name}"
204
- @client = MongoReplicaSetClient.new
205
- assert !@client.nil?
206
- assert_equal 2, @client.seeds.length
207
- assert_equal @rs.replicas[0].host, @client.seeds[0][0]
208
- assert_equal @rs.replicas[1].host, @client.seeds[1][0]
209
- assert_equal @rs.replicas[0].port, @client.seeds[0][1]
210
- assert_equal @rs.replicas[1].port, @client.seeds[1][1]
211
- assert_equal @rs.repl_set_name, @client.replica_set_name
212
- assert @client.connected?
220
+ uri = "mongodb://#{@rs.replicas[0].host_port},#{@rs.replicas[1].host_port}?replicaset=#{@rs.repl_set_name}"
221
+ with_preserved_env_uri(uri) do
222
+ @client = MongoReplicaSetClient.new
223
+ assert !@client.nil?
224
+ assert_equal 2, @client.seeds.length
225
+ assert_equal @rs.replicas[0].host, @client.seeds[0][0]
226
+ assert_equal @rs.replicas[1].host, @client.seeds[1][0]
227
+ assert_equal @rs.replicas[0].port, @client.seeds[0][1]
228
+ assert_equal @rs.replicas[1].port, @client.seeds[1][1]
229
+ assert_equal @rs.repl_set_name, @client.replica_set_name
230
+ assert @client.connected?
231
+ end
213
232
  end
214
233
 
215
234
  def test_connect_with_connection_string_in_implicit_mongodb_uri
216
- ENV['MONGODB_URI'] = "mongodb://#{@rs.replicas[0].host_port},#{@rs.replicas[1].host_port}?replicaset=#{@rs.repl_set_name}"
217
- @client = MongoClient.from_uri
218
- assert !@client.nil?
219
- assert_equal 2, @client.seeds.length
220
- assert_equal @rs.replicas[0].host, @client.seeds[0][0]
221
- assert_equal @rs.replicas[1].host, @client.seeds[1][0]
222
- assert_equal @rs.replicas[0].port, @client.seeds[0][1]
223
- assert_equal @rs.replicas[1].port, @client.seeds[1][1]
224
- assert_equal @rs.repl_set_name, @client.replica_set_name
225
- assert @client.connected?
235
+ uri = "mongodb://#{@rs.replicas[0].host_port},#{@rs.replicas[1].host_port}?replicaset=#{@rs.repl_set_name}"
236
+ with_preserved_env_uri(uri) do
237
+ @client = MongoClient.from_uri
238
+ assert !@client.nil?
239
+ assert_equal 2, @client.seeds.length
240
+ assert_equal @rs.replicas[0].host, @client.seeds[0][0]
241
+ assert_equal @rs.replicas[1].host, @client.seeds[1][0]
242
+ assert_equal @rs.replicas[0].port, @client.seeds[0][1]
243
+ assert_equal @rs.replicas[1].port, @client.seeds[1][1]
244
+ assert_equal @rs.repl_set_name, @client.replica_set_name
245
+ assert @client.connected?
246
+ end
226
247
  end
227
248
 
228
249
  def test_connect_with_new_seed_format
@@ -247,26 +268,67 @@ class ClientTest < Test::Unit::TestCase
247
268
  end
248
269
 
249
270
  def test_connect_with_full_connection_string_in_env_var
250
- ENV['MONGODB_URI'] = "mongodb://#{@rs.replicas[0].host_port},#{@rs.replicas[1].host_port}?replicaset=#{@rs.repl_set_name};w=2;fsync=true;slaveok=true"
251
- @client = MongoReplicaSetClient.new
252
- assert !@client.nil?
253
- assert @client.connected?
254
- assert_equal 2, @client.write_concern[:w]
255
- assert @client.write_concern[:fsync]
256
- assert @client.read_pool
271
+ uri = "mongodb://#{@rs.replicas[0].host_port},#{@rs.replicas[1].host_port}?replicaset=#{@rs.repl_set_name};w=2;fsync=true;slaveok=true"
272
+ with_preserved_env_uri(uri) do
273
+ @client = MongoReplicaSetClient.new
274
+ assert !@client.nil?
275
+ assert @client.connected?
276
+ assert_equal 2, @client.write_concern[:w]
277
+ assert @client.write_concern[:fsync]
278
+ assert @client.read_pool
279
+ end
257
280
  end
258
281
 
259
282
  def test_connect_options_override_env_var
260
- ENV['MONGODB_URI'] = "mongodb://#{@rs.replicas[0].host_port},#{@rs.replicas[1].host_port}?replicaset=#{@rs.repl_set_name};w=2;fsync=true;slaveok=true"
261
- @client = MongoReplicaSetClient.new({:w => 0})
262
- assert !@client.nil?
263
- assert @client.connected?
264
- assert_equal 0, @client.write_concern[:w]
283
+ uri = "mongodb://#{@rs.replicas[0].host_port},#{@rs.replicas[1].host_port}?replicaset=#{@rs.repl_set_name};w=2;fsync=true;slaveok=true"
284
+ with_preserved_env_uri(uri) do
285
+ @client = MongoReplicaSetClient.new({:w => 0})
286
+ assert !@client.nil?
287
+ assert @client.connected?
288
+ assert_equal 0, @client.write_concern[:w]
289
+ end
290
+ end
291
+
292
+ def test_ipv6
293
+ @client = MongoReplicaSetClient.new(@rs.repl_set_seeds)
294
+ with_ipv6_enabled(@client) do
295
+ assert MongoReplicaSetClient.new(["[::1]:#{@rs.replicas[0].port}"])
296
+ end
297
+ end
298
+
299
+ def test_ipv6_with_uri
300
+ @client = MongoReplicaSetClient.new(@rs.repl_set_seeds)
301
+ with_ipv6_enabled(@client) do
302
+ uri = "mongodb://[::1]:#{@rs.replicas[0].port},[::1]:#{@rs.replicas[1].port}"
303
+ with_preserved_env_uri(uri) do
304
+ assert MongoReplicaSetClient.new
305
+ end
306
+ end
307
+ end
308
+
309
+ def test_ipv6_with_uri_opts
310
+ @client = MongoReplicaSetClient.new(@rs.repl_set_seeds)
311
+ with_ipv6_enabled(@client) do
312
+ uri = "mongodb://[::1]:#{@rs.replicas[0].port},[::1]:#{@rs.replicas[1].port}/?safe=true;"
313
+ with_preserved_env_uri(uri) do
314
+ assert MongoReplicaSetClient.new
315
+ end
316
+ end
317
+ end
318
+
319
+ def test_ipv6_with_different_formats
320
+ @client = MongoReplicaSetClient.new(@rs.repl_set_seeds)
321
+ with_ipv6_enabled(@client) do
322
+ uri = "mongodb://[::1]:#{@rs.replicas[0].port},localhost:#{@rs.replicas[1].port}"
323
+ with_preserved_env_uri(uri) do
324
+ assert MongoReplicaSetClient.new
325
+ end
326
+ end
265
327
  end
266
328
 
267
329
  def test_find_and_modify_with_secondary_read_preference
268
- @client = MongoReplicaSetClient.new
269
- collection = @client[MONGO_TEST_DB].collection('test', :read => :secondary)
330
+ @client = MongoReplicaSetClient.new @rs.repl_set_seeds
331
+ collection = @client[TEST_DB].collection('test', :read => :secondary)
270
332
  collection << { :a => 1, :processed => false}
271
333
 
272
334
  collection.find_and_modify(