mongo 1.8.6 → 1.12.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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/LICENSE +1 -1
- data/README.md +114 -282
- data/Rakefile +18 -4
- data/VERSION +1 -1
- data/bin/mongo_console +27 -5
- data/lib/mongo/bulk_write_collection_view.rb +387 -0
- data/lib/mongo/collection.rb +283 -222
- data/lib/mongo/collection_writer.rb +364 -0
- data/lib/mongo/{util → connection}/node.rb +58 -6
- data/lib/mongo/{util → connection}/pool.rb +61 -37
- data/lib/mongo/{util → connection}/pool_manager.rb +72 -22
- data/lib/mongo/{util → connection}/sharding_pool_manager.rb +13 -0
- data/lib/mongo/connection/socket/socket_util.rb +37 -0
- data/lib/mongo/connection/socket/ssl_socket.rb +95 -0
- data/lib/mongo/connection/socket/tcp_socket.rb +87 -0
- data/lib/mongo/connection/socket/unix_socket.rb +39 -0
- data/lib/mongo/connection/socket.rb +18 -0
- data/lib/mongo/connection.rb +19 -0
- data/lib/mongo/cursor.rb +183 -57
- data/lib/mongo/db.rb +302 -138
- data/lib/mongo/exception.rb +145 -0
- data/lib/mongo/functional/authentication.rb +455 -0
- data/lib/mongo/{util → functional}/logging.rb +23 -7
- data/lib/mongo/functional/read_preference.rb +183 -0
- data/lib/mongo/functional/scram.rb +556 -0
- data/lib/mongo/functional/uri_parser.rb +409 -0
- data/lib/mongo/{util → functional}/write_concern.rb +21 -9
- data/lib/mongo/functional.rb +20 -0
- data/lib/mongo/gridfs/grid.rb +19 -8
- data/lib/mongo/gridfs/grid_ext.rb +14 -0
- data/lib/mongo/gridfs/grid_file_system.rb +17 -4
- data/lib/mongo/gridfs/grid_io.rb +21 -9
- data/lib/mongo/gridfs.rb +18 -0
- data/lib/mongo/legacy.rb +76 -7
- data/lib/mongo/mongo_client.rb +246 -206
- data/lib/mongo/mongo_replica_set_client.rb +65 -15
- data/lib/mongo/mongo_sharded_client.rb +18 -3
- data/lib/mongo/networking.rb +47 -18
- data/lib/mongo/{util → utils}/conversions.rb +18 -3
- data/lib/mongo/{util → utils}/core_ext.rb +15 -32
- data/lib/mongo/{util → utils}/server_version.rb +15 -0
- data/lib/mongo/{util → utils}/support.rb +22 -55
- data/lib/mongo/utils/thread_local_variable_manager.rb +25 -0
- data/lib/mongo/utils.rb +19 -0
- data/lib/mongo.rb +44 -26
- data/mongo.gemspec +2 -2
- data/test/functional/authentication_test.rb +31 -10
- data/test/functional/bulk_api_stress_test.rb +133 -0
- data/test/functional/bulk_write_collection_view_test.rb +1198 -0
- data/test/functional/client_test.rb +627 -0
- data/test/functional/collection_test.rb +1419 -654
- data/test/functional/collection_writer_test.rb +83 -0
- data/test/functional/conversions_test.rb +46 -2
- data/test/functional/cursor_fail_test.rb +17 -9
- data/test/functional/cursor_message_test.rb +28 -15
- data/test/functional/cursor_test.rb +300 -165
- data/test/functional/db_api_test.rb +294 -264
- data/test/functional/db_connection_test.rb +15 -3
- data/test/functional/db_test.rb +165 -99
- data/test/functional/grid_file_system_test.rb +124 -112
- data/test/functional/grid_io_test.rb +17 -3
- data/test/functional/grid_test.rb +16 -2
- data/test/functional/pool_test.rb +99 -10
- data/test/functional/safe_test.rb +18 -4
- data/test/functional/ssl_test.rb +29 -0
- data/test/functional/support_test.rb +14 -0
- data/test/functional/timeout_test.rb +27 -27
- data/test/functional/uri_test.rb +268 -22
- data/test/functional/write_concern_test.rb +19 -5
- data/test/helpers/general.rb +50 -0
- data/test/helpers/test_unit.rb +476 -0
- data/test/replica_set/authentication_test.rb +28 -11
- data/test/replica_set/basic_test.rb +79 -23
- data/test/replica_set/client_test.rb +253 -124
- data/test/replica_set/connection_test.rb +59 -37
- data/test/replica_set/count_test.rb +18 -2
- data/test/replica_set/cursor_test.rb +30 -8
- data/test/replica_set/insert_test.rb +109 -2
- data/test/replica_set/max_values_test.rb +85 -10
- data/test/replica_set/pinning_test.rb +66 -2
- data/test/replica_set/query_test.rb +17 -3
- data/test/replica_set/read_preference_test.rb +115 -96
- data/test/replica_set/refresh_test.rb +59 -9
- data/test/replica_set/replication_ack_test.rb +32 -11
- data/test/replica_set/ssl_test.rb +32 -0
- data/test/sharded_cluster/basic_test.rb +73 -25
- data/test/shared/authentication/basic_auth_shared.rb +260 -0
- data/test/shared/authentication/bulk_api_auth_shared.rb +249 -0
- data/test/shared/authentication/gssapi_shared.rb +176 -0
- data/test/shared/authentication/sasl_plain_shared.rb +96 -0
- data/test/shared/authentication/scram_shared.rb +92 -0
- data/test/shared/ssl_shared.rb +235 -0
- data/test/test_helper.rb +47 -196
- data/test/threading/basic_test.rb +42 -2
- data/test/tools/mongo_config.rb +175 -35
- data/test/tools/mongo_config_test.rb +15 -1
- data/test/unit/client_test.rb +186 -57
- data/test/unit/collection_test.rb +44 -54
- data/test/unit/connection_test.rb +160 -71
- data/test/unit/cursor_test.rb +37 -3
- data/test/unit/db_test.rb +38 -14
- data/test/unit/grid_test.rb +15 -1
- data/test/unit/mongo_sharded_client_test.rb +30 -14
- data/test/unit/node_test.rb +16 -1
- data/test/unit/pool_manager_test.rb +21 -4
- data/test/unit/read_pref_test.rb +386 -1
- data/test/unit/read_test.rb +27 -13
- data/test/unit/safe_test.rb +22 -8
- data/test/unit/sharding_pool_manager_test.rb +25 -4
- data/test/unit/write_concern_test.rb +23 -9
- data.tar.gz.sig +0 -0
- metadata +80 -54
- metadata.gz.sig +0 -0
- data/lib/mongo/exceptions.rb +0 -65
- data/lib/mongo/util/read_preference.rb +0 -112
- data/lib/mongo/util/socket_util.rb +0 -20
- data/lib/mongo/util/ssl_socket.rb +0 -51
- data/lib/mongo/util/tcp_socket.rb +0 -62
- data/lib/mongo/util/thread_local_variable_manager.rb +0 -11
- data/lib/mongo/util/unix_socket.rb +0 -23
- data/lib/mongo/util/uri_parser.rb +0 -337
- data/test/functional/connection_test.rb +0 -449
- data/test/functional/threading_test.rb +0 -95
- data/test/replica_set/complex_connect_test.rb +0 -64
- data/test/shared/authentication.rb +0 -66
- data/test/unit/pool_test.rb +0 -9
- data/test/unit/util_test.rb +0 -55
|
@@ -1,6 +1,20 @@
|
|
|
1
|
+
# Copyright (C) 2009-2013 MongoDB, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
1
15
|
require 'test_helper'
|
|
2
16
|
|
|
3
|
-
class
|
|
17
|
+
class ReplicaSetClientTest < Test::Unit::TestCase
|
|
4
18
|
|
|
5
19
|
def setup
|
|
6
20
|
ensure_cluster(:rs)
|
|
@@ -12,7 +26,7 @@ class ClientTest < Test::Unit::TestCase
|
|
|
12
26
|
end
|
|
13
27
|
|
|
14
28
|
def test_reconnection
|
|
15
|
-
@client = MongoReplicaSetClient.
|
|
29
|
+
@client = MongoReplicaSetClient.from_uri(@uri, :op_timeout => TEST_OP_TIMEOUT)
|
|
16
30
|
assert @client.connected?
|
|
17
31
|
|
|
18
32
|
manager = @client.local_manager
|
|
@@ -26,6 +40,21 @@ class ClientTest < Test::Unit::TestCase
|
|
|
26
40
|
assert_equal @client.local_manager, manager
|
|
27
41
|
end
|
|
28
42
|
|
|
43
|
+
def test_reconnect_method
|
|
44
|
+
@client = MongoReplicaSetClient.from_uri(@uri, :op_timeout => TEST_OP_TIMEOUT)
|
|
45
|
+
assert @client.connected?
|
|
46
|
+
|
|
47
|
+
manager = @client.local_manager
|
|
48
|
+
|
|
49
|
+
@client.close
|
|
50
|
+
assert !@client.connected?
|
|
51
|
+
assert !@client.local_manager
|
|
52
|
+
|
|
53
|
+
@client.reconnect
|
|
54
|
+
assert @client.connected?
|
|
55
|
+
assert_equal @client.local_manager, manager
|
|
56
|
+
end
|
|
57
|
+
|
|
29
58
|
# TODO: test connect timeout.
|
|
30
59
|
|
|
31
60
|
def test_connect_with_deprecated_multi
|
|
@@ -62,122 +91,163 @@ class ClientTest < Test::Unit::TestCase
|
|
|
62
91
|
end
|
|
63
92
|
|
|
64
93
|
def test_connect_with_primary_stepped_down
|
|
65
|
-
@client = MongoReplicaSetClient.
|
|
66
|
-
@client[
|
|
67
|
-
assert @client[
|
|
94
|
+
@client = MongoReplicaSetClient.from_uri(@uri)
|
|
95
|
+
@client[TEST_DB]['bar'].save({:a => 1}, {:w => 3})
|
|
96
|
+
assert @client[TEST_DB]['bar'].find_one
|
|
68
97
|
|
|
69
98
|
primary = Mongo::MongoClient.new(*@client.primary)
|
|
99
|
+
authenticate_client(primary)
|
|
70
100
|
assert_raise Mongo::ConnectionFailure do
|
|
71
|
-
primary
|
|
101
|
+
perform_step_down(primary)
|
|
72
102
|
end
|
|
73
103
|
assert @client.connected?
|
|
74
104
|
|
|
75
105
|
rescue_connection_failure do
|
|
76
|
-
@client[
|
|
106
|
+
@client[TEST_DB]['bar'].find_one
|
|
77
107
|
end
|
|
78
|
-
@client[
|
|
108
|
+
@client[TEST_DB]['bar'].find_one
|
|
79
109
|
end
|
|
80
110
|
|
|
81
111
|
def test_connect_with_primary_killed
|
|
82
|
-
@client = MongoReplicaSetClient.
|
|
112
|
+
@client = MongoReplicaSetClient.from_uri(@uri)
|
|
83
113
|
assert @client.connected?
|
|
84
|
-
@client[
|
|
85
|
-
assert @client[
|
|
114
|
+
@client[TEST_DB]['bar'].save({:a => 1}, {:w => 3})
|
|
115
|
+
assert @client[TEST_DB]['bar'].find_one
|
|
86
116
|
|
|
87
117
|
@rs.primary.kill(Signal.list['KILL'])
|
|
88
118
|
|
|
89
119
|
sleep(3)
|
|
90
120
|
|
|
91
121
|
rescue_connection_failure do
|
|
92
|
-
@client[
|
|
122
|
+
@client[TEST_DB]['bar'].find_one
|
|
93
123
|
end
|
|
94
|
-
@client[
|
|
124
|
+
@client[TEST_DB]['bar'].find_one
|
|
95
125
|
end
|
|
96
126
|
|
|
97
127
|
def test_save_with_primary_stepped_down
|
|
98
|
-
@client = MongoReplicaSetClient.
|
|
128
|
+
@client = MongoReplicaSetClient.from_uri(@uri)
|
|
99
129
|
assert @client.connected?
|
|
100
130
|
|
|
101
131
|
primary = Mongo::MongoClient.new(*@client.primary)
|
|
132
|
+
authenticate_client(primary)
|
|
102
133
|
assert_raise Mongo::ConnectionFailure do
|
|
103
|
-
primary
|
|
134
|
+
perform_step_down(primary)
|
|
104
135
|
end
|
|
105
136
|
|
|
106
137
|
rescue_connection_failure do
|
|
107
|
-
@client[
|
|
138
|
+
@client[TEST_DB]['bar'].save({:a => 1}, {:w => 2})
|
|
139
|
+
end
|
|
140
|
+
@client[TEST_DB]['bar'].find_one
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
# def test_connect_with_first_node_removed
|
|
144
|
+
# @client = MongoReplicaSetClient.from_uri(@uri)
|
|
145
|
+
# @client[TEST_DB]['bar'].save({:a => 1}, {:w => 3})
|
|
146
|
+
|
|
147
|
+
# # Make sure everyone's views of optimes are caught up
|
|
148
|
+
# loop do
|
|
149
|
+
# break if @rs.repl_set_get_status.all? do |status|
|
|
150
|
+
# members = status['members']
|
|
151
|
+
# primary_optime = members.find{|m| m['state'] == 1}['optime'].seconds
|
|
152
|
+
# members.any?{|m| m['state'] == 2 && primary_optime - m['optime'].seconds < 5}
|
|
153
|
+
# end
|
|
154
|
+
# sleep 1
|
|
155
|
+
# end
|
|
156
|
+
|
|
157
|
+
# old_primary = [@client.primary_pool.host, @client.primary_pool.port]
|
|
158
|
+
# old_primary_conn = Mongo::MongoClient.new(*old_primary)
|
|
159
|
+
|
|
160
|
+
# assert_raise Mongo::ConnectionFailure do
|
|
161
|
+
# perform_step_down(old_primary_conn)
|
|
162
|
+
# end
|
|
163
|
+
|
|
164
|
+
# # Wait for new primary
|
|
165
|
+
# rescue_connection_failure do
|
|
166
|
+
# sleep 1 until @rs.primary
|
|
167
|
+
# end
|
|
168
|
+
|
|
169
|
+
# new_primary = [@rs.primary.host, @rs.primary.port]
|
|
170
|
+
# new_primary_conn = Mongo::MongoClient.new(*new_primary)
|
|
171
|
+
|
|
172
|
+
# assert new_primary != old_primary
|
|
173
|
+
|
|
174
|
+
# config = nil
|
|
175
|
+
|
|
176
|
+
# # Remove old primary from replset
|
|
177
|
+
# rescue_connection_failure do
|
|
178
|
+
# config = @client['local']['system.replset'].find_one
|
|
179
|
+
# end
|
|
180
|
+
|
|
181
|
+
# old_member = config['members'].select {|m| m['host'] == old_primary.join(':')}.first
|
|
182
|
+
# config['members'].reject! {|m| m['host'] == old_primary.join(':')}
|
|
183
|
+
# config['version'] += 1
|
|
184
|
+
|
|
185
|
+
# begin
|
|
186
|
+
# new_primary_conn['admin'].command({'replSetReconfig' => config})
|
|
187
|
+
# rescue Mongo::ConnectionFailure
|
|
188
|
+
# end
|
|
189
|
+
|
|
190
|
+
# # Wait for the dust to settle
|
|
191
|
+
# rescue_connection_failure do
|
|
192
|
+
# assert @client[TEST_DB]['bar'].find_one
|
|
193
|
+
# end
|
|
194
|
+
|
|
195
|
+
# begin
|
|
196
|
+
# # Make sure a new connection skips the old primary
|
|
197
|
+
# @new_conn = MongoReplicaSetClient.new @rs.repl_set_seeds
|
|
198
|
+
# @new_conn.connect
|
|
199
|
+
# new_nodes = @new_conn.secondaries + [@new_conn.primary]
|
|
200
|
+
# assert !new_nodes.include?(old_primary)
|
|
201
|
+
# ensure
|
|
202
|
+
# # Add the old primary back
|
|
203
|
+
# config['members'] << old_member
|
|
204
|
+
# config['version'] += 1
|
|
205
|
+
|
|
206
|
+
# begin
|
|
207
|
+
# new_primary_conn['admin'].command({'replSetReconfig' => config})
|
|
208
|
+
# rescue Mongo::ConnectionFailure
|
|
209
|
+
# end
|
|
210
|
+
# end
|
|
211
|
+
# end
|
|
212
|
+
|
|
213
|
+
def test_connect_with_hung_first_node
|
|
214
|
+
hung_node = nil
|
|
215
|
+
begin
|
|
216
|
+
hung_node = IO.popen('nc -lk 127.0.0.1 29999 >/dev/null 2>&1')
|
|
217
|
+
|
|
218
|
+
Timeout.timeout(3) do
|
|
219
|
+
@client = MongoReplicaSetClient.new(['localhost:29999'] + @rs.repl_set_seeds,
|
|
220
|
+
:connect_timeout => 2)
|
|
221
|
+
@client.connect
|
|
222
|
+
end
|
|
223
|
+
assert ['localhost:29999'] != @client.primary
|
|
224
|
+
assert !@client.secondaries.include?('localhost:29999')
|
|
225
|
+
ensure
|
|
226
|
+
begin
|
|
227
|
+
Process.kill("KILL", hung_node.pid) if hung_node
|
|
228
|
+
rescue
|
|
229
|
+
# the process ended, was killed already, or the system doesn't support nc
|
|
230
|
+
end
|
|
231
|
+
end
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
def test_read_pref_primary_with_tags
|
|
235
|
+
parser = Mongo::URIParser.new("mongodb://#{@rs.replicas[0].host_port},#{@rs.replicas[1].host_port}" +
|
|
236
|
+
"?replicaset=#{@rs.repl_set_name}&readPreference=primary&" +
|
|
237
|
+
"readPreferenceTags=dc:ny,rack:1")
|
|
238
|
+
assert_raise_error Mongo::MongoArgumentError do
|
|
239
|
+
parser.connection.read_pool
|
|
108
240
|
end
|
|
109
|
-
@client[MONGO_TEST_DB]['bar'].find_one
|
|
110
241
|
end
|
|
111
242
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
# end
|
|
121
|
-
#
|
|
122
|
-
# # Wait for new primary
|
|
123
|
-
# rescue_connection_failure do
|
|
124
|
-
# sleep 1 until @rs.get_node_with_state(1)
|
|
125
|
-
# end
|
|
126
|
-
#
|
|
127
|
-
# new_primary = @rs.get_all_host_pairs_with_state(1).first
|
|
128
|
-
# new_primary_conn = Mongo::MongoClient.new(*new_primary)
|
|
129
|
-
#
|
|
130
|
-
# config = nil
|
|
131
|
-
#
|
|
132
|
-
# # Remove old primary from replset
|
|
133
|
-
# rescue_connection_failure do
|
|
134
|
-
# config = @client['local']['system.replset'].find_one
|
|
135
|
-
# end
|
|
136
|
-
#
|
|
137
|
-
# old_member = config['members'].select {|m| m['host'] == old_primary.join(':')}.first
|
|
138
|
-
# config['members'].reject! {|m| m['host'] == old_primary.join(':')}
|
|
139
|
-
# config['version'] += 1
|
|
140
|
-
#
|
|
141
|
-
# begin
|
|
142
|
-
# new_primary_conn['admin'].command({'replSetReconfig' => config})
|
|
143
|
-
# rescue Mongo::ConnectionFailure
|
|
144
|
-
# end
|
|
145
|
-
#
|
|
146
|
-
# # Wait for the dust to settle
|
|
147
|
-
# rescue_connection_failure do
|
|
148
|
-
# assert @client[MONGO_TEST_DB]['bar'].find_one
|
|
149
|
-
# end
|
|
150
|
-
#
|
|
151
|
-
# # Make sure a new connection skips the old primary
|
|
152
|
-
# @new_conn = MongoReplicaSetClient.new @rs.repl_set_seeds
|
|
153
|
-
# @new_conn.connect
|
|
154
|
-
# new_nodes = [@new_conn.primary] + @new_conn.secondaries
|
|
155
|
-
# assert !(new_nodes).include?(old_primary)
|
|
156
|
-
#
|
|
157
|
-
# # Add the old primary back
|
|
158
|
-
# config['members'] << old_member
|
|
159
|
-
# config['version'] += 1
|
|
160
|
-
#
|
|
161
|
-
# begin
|
|
162
|
-
# new_primary_conn['admin'].command({'replSetReconfig' => config})
|
|
163
|
-
# rescue Mongo::ConnectionFailure
|
|
164
|
-
# end
|
|
165
|
-
#end
|
|
166
|
-
|
|
167
|
-
#def test_connect_with_hung_first_node
|
|
168
|
-
# hung_node = nil
|
|
169
|
-
# begin
|
|
170
|
-
# hung_node = IO.popen('nc -lk 127.0.0.1 29999 >/dev/null 2>&1')
|
|
171
|
-
#
|
|
172
|
-
# @client = MongoReplicaSetClient.new(['localhost:29999'] + @rs.repl_set_seeds,
|
|
173
|
-
# :connect_timeout => 2)
|
|
174
|
-
# @client.connect
|
|
175
|
-
# assert ['localhost:29999'] != @client.primary
|
|
176
|
-
# assert !@client.secondaries.include?('localhost:29999')
|
|
177
|
-
# ensure
|
|
178
|
-
# Process.kill("KILL", hung_node.pid) if hung_node
|
|
179
|
-
# end
|
|
180
|
-
#end
|
|
243
|
+
def test_read_pref_with_tags
|
|
244
|
+
parser = Mongo::URIParser.new("mongodb://#{@rs.replicas[0].host_port},#{@rs.replicas[1].host_port}" +
|
|
245
|
+
"?replicaset=#{@rs.repl_set_name}&" +
|
|
246
|
+
"readPreferenceTags=dc:ny,rack:1")
|
|
247
|
+
assert_raise_error Mongo::MongoArgumentError do
|
|
248
|
+
parser.connection.read_pool
|
|
249
|
+
end
|
|
250
|
+
end
|
|
181
251
|
|
|
182
252
|
def test_connect_with_connection_string
|
|
183
253
|
@client = MongoClient.from_uri("mongodb://#{@rs.replicas[0].host_port},#{@rs.replicas[1].host_port}?replicaset=#{@rs.repl_set_name}")
|
|
@@ -186,29 +256,33 @@ class ClientTest < Test::Unit::TestCase
|
|
|
186
256
|
end
|
|
187
257
|
|
|
188
258
|
def test_connect_with_connection_string_in_env_var
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
259
|
+
uri = "mongodb://#{@rs.replicas[0].host_port},#{@rs.replicas[1].host_port}?replicaset=#{@rs.repl_set_name}"
|
|
260
|
+
with_preserved_env_uri(uri) do
|
|
261
|
+
@client = MongoReplicaSetClient.new
|
|
262
|
+
assert !@client.nil?
|
|
263
|
+
assert_equal 2, @client.seeds.length
|
|
264
|
+
assert_equal @rs.replicas[0].host, @client.seeds[0][0]
|
|
265
|
+
assert_equal @rs.replicas[1].host, @client.seeds[1][0]
|
|
266
|
+
assert_equal @rs.replicas[0].port, @client.seeds[0][1]
|
|
267
|
+
assert_equal @rs.replicas[1].port, @client.seeds[1][1]
|
|
268
|
+
assert_equal @rs.repl_set_name, @client.replica_set_name
|
|
269
|
+
assert @client.connected?
|
|
270
|
+
end
|
|
199
271
|
end
|
|
200
272
|
|
|
201
273
|
def test_connect_with_connection_string_in_implicit_mongodb_uri
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
274
|
+
uri = "mongodb://#{@rs.replicas[0].host_port},#{@rs.replicas[1].host_port}?replicaset=#{@rs.repl_set_name}"
|
|
275
|
+
with_preserved_env_uri(uri) do
|
|
276
|
+
@client = MongoClient.from_uri
|
|
277
|
+
assert !@client.nil?
|
|
278
|
+
assert_equal 2, @client.seeds.length
|
|
279
|
+
assert_equal @rs.replicas[0].host, @client.seeds[0][0]
|
|
280
|
+
assert_equal @rs.replicas[1].host, @client.seeds[1][0]
|
|
281
|
+
assert_equal @rs.replicas[0].port, @client.seeds[0][1]
|
|
282
|
+
assert_equal @rs.replicas[1].port, @client.seeds[1][1]
|
|
283
|
+
assert_equal @rs.repl_set_name, @client.replica_set_name
|
|
284
|
+
assert @client.connected?
|
|
285
|
+
end
|
|
212
286
|
end
|
|
213
287
|
|
|
214
288
|
def test_connect_with_new_seed_format
|
|
@@ -233,32 +307,87 @@ class ClientTest < Test::Unit::TestCase
|
|
|
233
307
|
end
|
|
234
308
|
|
|
235
309
|
def test_connect_with_full_connection_string_in_env_var
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
310
|
+
uri = "mongodb://#{@rs.replicas[0].host_port},#{@rs.replicas[1].host_port}?replicaset=#{@rs.repl_set_name};w=2;fsync=true;slaveok=true"
|
|
311
|
+
with_preserved_env_uri(uri) do
|
|
312
|
+
@client = MongoReplicaSetClient.new
|
|
313
|
+
assert !@client.nil?
|
|
314
|
+
assert @client.connected?
|
|
315
|
+
assert_equal 2, @client.write_concern[:w]
|
|
316
|
+
assert @client.write_concern[:fsync]
|
|
317
|
+
assert @client.read_pool
|
|
318
|
+
end
|
|
243
319
|
end
|
|
244
320
|
|
|
245
321
|
def test_connect_options_override_env_var
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
322
|
+
uri = "mongodb://#{@rs.replicas[0].host_port},#{@rs.replicas[1].host_port}?replicaset=#{@rs.repl_set_name};w=2;fsync=true;slaveok=true"
|
|
323
|
+
with_preserved_env_uri(uri) do
|
|
324
|
+
@client = MongoReplicaSetClient.new({:w => 0})
|
|
325
|
+
assert !@client.nil?
|
|
326
|
+
assert @client.connected?
|
|
327
|
+
assert_equal 0, @client.write_concern[:w]
|
|
328
|
+
end
|
|
329
|
+
end
|
|
330
|
+
|
|
331
|
+
def test_ipv6
|
|
332
|
+
@client = MongoReplicaSetClient.new(@rs.repl_set_seeds)
|
|
333
|
+
with_ipv6_enabled(@client) do
|
|
334
|
+
assert MongoReplicaSetClient.new(["[::1]:#{@rs.replicas[0].port}"])
|
|
335
|
+
end
|
|
336
|
+
end
|
|
337
|
+
|
|
338
|
+
def test_ipv6_with_uri
|
|
339
|
+
@client = MongoReplicaSetClient.new(@rs.repl_set_seeds)
|
|
340
|
+
with_ipv6_enabled(@client) do
|
|
341
|
+
uri = "mongodb://[::1]:#{@rs.replicas[0].port},[::1]:#{@rs.replicas[1].port}"
|
|
342
|
+
with_preserved_env_uri(uri) do
|
|
343
|
+
assert MongoReplicaSetClient.new
|
|
344
|
+
end
|
|
345
|
+
end
|
|
346
|
+
end
|
|
347
|
+
|
|
348
|
+
def test_ipv6_with_uri_opts
|
|
349
|
+
@client = MongoReplicaSetClient.new(@rs.repl_set_seeds)
|
|
350
|
+
with_ipv6_enabled(@client) do
|
|
351
|
+
uri = "mongodb://[::1]:#{@rs.replicas[0].port},[::1]:#{@rs.replicas[1].port}/?safe=true;"
|
|
352
|
+
with_preserved_env_uri(uri) do
|
|
353
|
+
assert MongoReplicaSetClient.new
|
|
354
|
+
end
|
|
355
|
+
end
|
|
356
|
+
end
|
|
357
|
+
|
|
358
|
+
def test_ipv6_with_different_formats
|
|
359
|
+
@client = MongoReplicaSetClient.new(@rs.repl_set_seeds)
|
|
360
|
+
with_ipv6_enabled(@client) do
|
|
361
|
+
uri = "mongodb://[::1]:#{@rs.replicas[0].port},localhost:#{@rs.replicas[1].port}"
|
|
362
|
+
with_preserved_env_uri(uri) do
|
|
363
|
+
assert MongoReplicaSetClient.new
|
|
364
|
+
end
|
|
365
|
+
end
|
|
251
366
|
end
|
|
252
367
|
|
|
253
368
|
def test_find_and_modify_with_secondary_read_preference
|
|
254
|
-
@client = MongoReplicaSetClient.
|
|
255
|
-
collection = @client[
|
|
256
|
-
|
|
369
|
+
@client = MongoReplicaSetClient.from_uri(@uri)
|
|
370
|
+
collection = @client[TEST_DB].collection('test', :read => :secondary)
|
|
371
|
+
id = BSON::ObjectId.new
|
|
372
|
+
collection << { :a => id, :processed => false }
|
|
257
373
|
|
|
258
374
|
collection.find_and_modify(
|
|
259
|
-
:query => {},
|
|
260
|
-
:update => {"$set" => {:processed => true}}
|
|
375
|
+
:query => { 'a' => id },
|
|
376
|
+
:update => { "$set" => { :processed => true }}
|
|
261
377
|
)
|
|
262
|
-
assert_equal collection.find_one({
|
|
378
|
+
assert_equal true, collection.find_one({ 'a' => id }, :read => :primary)['processed']
|
|
379
|
+
end
|
|
380
|
+
|
|
381
|
+
def test_op_timeout_option
|
|
382
|
+
client = MongoReplicaSetClient.new(@rs.repl_set_seeds, :connect => false,
|
|
383
|
+
:op_timeout => nil)
|
|
384
|
+
assert_equal nil, client.op_timeout
|
|
385
|
+
|
|
386
|
+
client = MongoReplicaSetClient.new(@rs.repl_set_seeds, :connect => false,
|
|
387
|
+
:op_timeout => 50)
|
|
388
|
+
assert_equal 50, client.op_timeout
|
|
389
|
+
|
|
390
|
+
client = MongoReplicaSetClient.new(@rs.repl_set_seeds, :connect => false)
|
|
391
|
+
assert_equal Mongo::MongoClient::DEFAULT_OP_TIMEOUT, client.op_timeout
|
|
263
392
|
end
|
|
264
393
|
end
|
|
@@ -1,6 +1,20 @@
|
|
|
1
|
+
# Copyright (C) 2009-2013 MongoDB, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
1
15
|
require 'test_helper'
|
|
2
16
|
|
|
3
|
-
class
|
|
17
|
+
class ReplicaSetConnectionTest < Test::Unit::TestCase
|
|
4
18
|
|
|
5
19
|
def setup
|
|
6
20
|
ensure_cluster(:rs)
|
|
@@ -45,33 +59,37 @@ class ConnectionTest < Test::Unit::TestCase
|
|
|
45
59
|
end
|
|
46
60
|
|
|
47
61
|
def test_connect_with_connection_string_in_env_var
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
62
|
+
uri = "mongodb://#{@rs.repl_set_seeds_uri}?replicaset=#{@rs.repl_set_name}"
|
|
63
|
+
with_preserved_env_uri(uri) do
|
|
64
|
+
@connection = ReplSetConnection.new
|
|
65
|
+
assert !@connection.nil?
|
|
66
|
+
assert_equal 3, @connection.seeds.length
|
|
67
|
+
assert_equal @rs.replicas[0].host, @connection.seeds[0][0]
|
|
68
|
+
assert_equal @rs.replicas[1].host, @connection.seeds[1][0]
|
|
69
|
+
assert_equal @rs.replicas[2].host, @connection.seeds[2][0]
|
|
70
|
+
assert_equal @rs.replicas[0].port, @connection.seeds[0][1]
|
|
71
|
+
assert_equal @rs.replicas[1].port, @connection.seeds[1][1]
|
|
72
|
+
assert_equal @rs.replicas[2].port, @connection.seeds[2][1]
|
|
73
|
+
assert_equal @rs.repl_set_name, @connection.replica_set_name
|
|
74
|
+
assert @connection.connected?
|
|
75
|
+
end
|
|
60
76
|
end
|
|
61
77
|
|
|
62
78
|
def test_connect_with_connection_string_in_implicit_mongodb_uri
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
79
|
+
uri = "mongodb://#{@rs.repl_set_seeds_uri}?replicaset=#{@rs.repl_set_name}"
|
|
80
|
+
with_preserved_env_uri(uri) do
|
|
81
|
+
@connection = Connection.from_uri
|
|
82
|
+
assert !@connection.nil?
|
|
83
|
+
assert_equal 3, @connection.seeds.length
|
|
84
|
+
assert_equal @rs.replicas[0].host, @connection.seeds[0][0]
|
|
85
|
+
assert_equal @rs.replicas[1].host, @connection.seeds[1][0]
|
|
86
|
+
assert_equal @rs.replicas[2].host, @connection.seeds[2][0]
|
|
87
|
+
assert_equal @rs.replicas[0].port, @connection.seeds[0][1]
|
|
88
|
+
assert_equal @rs.replicas[1].port, @connection.seeds[1][1]
|
|
89
|
+
assert_equal @rs.replicas[2].port, @connection.seeds[2][1]
|
|
90
|
+
assert_equal @rs.repl_set_name, @connection.replica_set_name
|
|
91
|
+
assert @connection.connected?
|
|
92
|
+
end
|
|
75
93
|
end
|
|
76
94
|
|
|
77
95
|
def test_connect_with_new_seed_format
|
|
@@ -96,21 +114,25 @@ class ConnectionTest < Test::Unit::TestCase
|
|
|
96
114
|
end
|
|
97
115
|
|
|
98
116
|
def test_connect_with_full_connection_string_in_env_var
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
117
|
+
uri = "mongodb://#{@rs.repl_set_seeds_uri}?replicaset=#{@rs.repl_set_name};safe=true;w=2;fsync=true;slaveok=true"
|
|
118
|
+
with_preserved_env_uri(uri) do
|
|
119
|
+
@connection = ReplSetConnection.new
|
|
120
|
+
assert !@connection.nil?
|
|
121
|
+
assert @connection.connected?
|
|
122
|
+
assert_equal 2, @connection.write_concern[:w]
|
|
123
|
+
assert @connection.write_concern[:fsync]
|
|
124
|
+
assert @connection.read_pool
|
|
125
|
+
end
|
|
106
126
|
end
|
|
107
127
|
|
|
108
128
|
def test_connect_options_override_env_var
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
129
|
+
uri = "mongodb://#{@rs.repl_set_seeds_uri}?replicaset=#{@rs.repl_set_name};safe=true;w=2;fsync=true;slaveok=true"
|
|
130
|
+
with_preserved_env_uri(uri) do
|
|
131
|
+
@connection = ReplSetConnection.new({:safe => {:w => 1}})
|
|
132
|
+
assert !@connection.nil?
|
|
133
|
+
assert @connection.connected?
|
|
134
|
+
assert_equal 1, @connection.write_concern[:w]
|
|
135
|
+
end
|
|
114
136
|
end
|
|
115
137
|
|
|
116
138
|
end
|
|
@@ -1,13 +1,29 @@
|
|
|
1
|
+
# Copyright (C) 2009-2013 MongoDB, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
1
15
|
require 'test_helper'
|
|
2
16
|
|
|
3
17
|
class ReplicaSetCountTest < Test::Unit::TestCase
|
|
4
18
|
|
|
5
19
|
def setup
|
|
6
20
|
ensure_cluster(:rs)
|
|
7
|
-
@client = MongoReplicaSetClient.new(@rs.repl_set_seeds, :read => :primary_preferred)
|
|
21
|
+
@client = MongoReplicaSetClient.new(@rs.repl_set_seeds, :read => :primary_preferred, :op_timeout => TEST_OP_TIMEOUT)
|
|
22
|
+
authenticate_client(@client)
|
|
8
23
|
assert @client.primary_pool
|
|
9
24
|
@primary = MongoClient.new(@client.primary_pool.host, @client.primary_pool.port)
|
|
10
|
-
@
|
|
25
|
+
authenticate_client(@primary)
|
|
26
|
+
@db = @client.db(TEST_DB)
|
|
11
27
|
@db.drop_collection("test-sets")
|
|
12
28
|
@coll = @db.collection("test-sets")
|
|
13
29
|
end
|