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.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/LICENSE +1 -1
  4. data/README.md +114 -282
  5. data/Rakefile +18 -4
  6. data/VERSION +1 -1
  7. data/bin/mongo_console +27 -5
  8. data/lib/mongo/bulk_write_collection_view.rb +387 -0
  9. data/lib/mongo/collection.rb +283 -222
  10. data/lib/mongo/collection_writer.rb +364 -0
  11. data/lib/mongo/{util → connection}/node.rb +58 -6
  12. data/lib/mongo/{util → connection}/pool.rb +61 -37
  13. data/lib/mongo/{util → connection}/pool_manager.rb +72 -22
  14. data/lib/mongo/{util → connection}/sharding_pool_manager.rb +13 -0
  15. data/lib/mongo/connection/socket/socket_util.rb +37 -0
  16. data/lib/mongo/connection/socket/ssl_socket.rb +95 -0
  17. data/lib/mongo/connection/socket/tcp_socket.rb +87 -0
  18. data/lib/mongo/connection/socket/unix_socket.rb +39 -0
  19. data/lib/mongo/connection/socket.rb +18 -0
  20. data/lib/mongo/connection.rb +19 -0
  21. data/lib/mongo/cursor.rb +183 -57
  22. data/lib/mongo/db.rb +302 -138
  23. data/lib/mongo/exception.rb +145 -0
  24. data/lib/mongo/functional/authentication.rb +455 -0
  25. data/lib/mongo/{util → functional}/logging.rb +23 -7
  26. data/lib/mongo/functional/read_preference.rb +183 -0
  27. data/lib/mongo/functional/scram.rb +556 -0
  28. data/lib/mongo/functional/uri_parser.rb +409 -0
  29. data/lib/mongo/{util → functional}/write_concern.rb +21 -9
  30. data/lib/mongo/functional.rb +20 -0
  31. data/lib/mongo/gridfs/grid.rb +19 -8
  32. data/lib/mongo/gridfs/grid_ext.rb +14 -0
  33. data/lib/mongo/gridfs/grid_file_system.rb +17 -4
  34. data/lib/mongo/gridfs/grid_io.rb +21 -9
  35. data/lib/mongo/gridfs.rb +18 -0
  36. data/lib/mongo/legacy.rb +76 -7
  37. data/lib/mongo/mongo_client.rb +246 -206
  38. data/lib/mongo/mongo_replica_set_client.rb +65 -15
  39. data/lib/mongo/mongo_sharded_client.rb +18 -3
  40. data/lib/mongo/networking.rb +47 -18
  41. data/lib/mongo/{util → utils}/conversions.rb +18 -3
  42. data/lib/mongo/{util → utils}/core_ext.rb +15 -32
  43. data/lib/mongo/{util → utils}/server_version.rb +15 -0
  44. data/lib/mongo/{util → utils}/support.rb +22 -55
  45. data/lib/mongo/utils/thread_local_variable_manager.rb +25 -0
  46. data/lib/mongo/utils.rb +19 -0
  47. data/lib/mongo.rb +44 -26
  48. data/mongo.gemspec +2 -2
  49. data/test/functional/authentication_test.rb +31 -10
  50. data/test/functional/bulk_api_stress_test.rb +133 -0
  51. data/test/functional/bulk_write_collection_view_test.rb +1198 -0
  52. data/test/functional/client_test.rb +627 -0
  53. data/test/functional/collection_test.rb +1419 -654
  54. data/test/functional/collection_writer_test.rb +83 -0
  55. data/test/functional/conversions_test.rb +46 -2
  56. data/test/functional/cursor_fail_test.rb +17 -9
  57. data/test/functional/cursor_message_test.rb +28 -15
  58. data/test/functional/cursor_test.rb +300 -165
  59. data/test/functional/db_api_test.rb +294 -264
  60. data/test/functional/db_connection_test.rb +15 -3
  61. data/test/functional/db_test.rb +165 -99
  62. data/test/functional/grid_file_system_test.rb +124 -112
  63. data/test/functional/grid_io_test.rb +17 -3
  64. data/test/functional/grid_test.rb +16 -2
  65. data/test/functional/pool_test.rb +99 -10
  66. data/test/functional/safe_test.rb +18 -4
  67. data/test/functional/ssl_test.rb +29 -0
  68. data/test/functional/support_test.rb +14 -0
  69. data/test/functional/timeout_test.rb +27 -27
  70. data/test/functional/uri_test.rb +268 -22
  71. data/test/functional/write_concern_test.rb +19 -5
  72. data/test/helpers/general.rb +50 -0
  73. data/test/helpers/test_unit.rb +476 -0
  74. data/test/replica_set/authentication_test.rb +28 -11
  75. data/test/replica_set/basic_test.rb +79 -23
  76. data/test/replica_set/client_test.rb +253 -124
  77. data/test/replica_set/connection_test.rb +59 -37
  78. data/test/replica_set/count_test.rb +18 -2
  79. data/test/replica_set/cursor_test.rb +30 -8
  80. data/test/replica_set/insert_test.rb +109 -2
  81. data/test/replica_set/max_values_test.rb +85 -10
  82. data/test/replica_set/pinning_test.rb +66 -2
  83. data/test/replica_set/query_test.rb +17 -3
  84. data/test/replica_set/read_preference_test.rb +115 -96
  85. data/test/replica_set/refresh_test.rb +59 -9
  86. data/test/replica_set/replication_ack_test.rb +32 -11
  87. data/test/replica_set/ssl_test.rb +32 -0
  88. data/test/sharded_cluster/basic_test.rb +73 -25
  89. data/test/shared/authentication/basic_auth_shared.rb +260 -0
  90. data/test/shared/authentication/bulk_api_auth_shared.rb +249 -0
  91. data/test/shared/authentication/gssapi_shared.rb +176 -0
  92. data/test/shared/authentication/sasl_plain_shared.rb +96 -0
  93. data/test/shared/authentication/scram_shared.rb +92 -0
  94. data/test/shared/ssl_shared.rb +235 -0
  95. data/test/test_helper.rb +47 -196
  96. data/test/threading/basic_test.rb +42 -2
  97. data/test/tools/mongo_config.rb +175 -35
  98. data/test/tools/mongo_config_test.rb +15 -1
  99. data/test/unit/client_test.rb +186 -57
  100. data/test/unit/collection_test.rb +44 -54
  101. data/test/unit/connection_test.rb +160 -71
  102. data/test/unit/cursor_test.rb +37 -3
  103. data/test/unit/db_test.rb +38 -14
  104. data/test/unit/grid_test.rb +15 -1
  105. data/test/unit/mongo_sharded_client_test.rb +30 -14
  106. data/test/unit/node_test.rb +16 -1
  107. data/test/unit/pool_manager_test.rb +21 -4
  108. data/test/unit/read_pref_test.rb +386 -1
  109. data/test/unit/read_test.rb +27 -13
  110. data/test/unit/safe_test.rb +22 -8
  111. data/test/unit/sharding_pool_manager_test.rb +25 -4
  112. data/test/unit/write_concern_test.rb +23 -9
  113. data.tar.gz.sig +0 -0
  114. metadata +80 -54
  115. metadata.gz.sig +0 -0
  116. data/lib/mongo/exceptions.rb +0 -65
  117. data/lib/mongo/util/read_preference.rb +0 -112
  118. data/lib/mongo/util/socket_util.rb +0 -20
  119. data/lib/mongo/util/ssl_socket.rb +0 -51
  120. data/lib/mongo/util/tcp_socket.rb +0 -62
  121. data/lib/mongo/util/thread_local_variable_manager.rb +0 -11
  122. data/lib/mongo/util/unix_socket.rb +0 -23
  123. data/lib/mongo/util/uri_parser.rb +0 -337
  124. data/test/functional/connection_test.rb +0 -449
  125. data/test/functional/threading_test.rb +0 -95
  126. data/test/replica_set/complex_connect_test.rb +0 -64
  127. data/test/shared/authentication.rb +0 -66
  128. data/test/unit/pool_test.rb +0 -9
  129. data/test/unit/util_test.rb +0 -55
@@ -1,3 +1,17 @@
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 URITest < Test::Unit::TestCase
@@ -17,6 +31,64 @@ class URITest < Test::Unit::TestCase
17
31
  assert_equal 27018, parser.nodes[0][1]
18
32
  end
19
33
 
34
+ def test_unix_socket
35
+ parser = Mongo::URIParser.new('mongodb:///tmp/mongod.sock')
36
+ assert_equal 1, parser.nodes.length
37
+ assert_equal '/tmp/mongod.sock', parser.nodes[0][0]
38
+ end
39
+
40
+ def test_unix_socket_with_user
41
+ parser = Mongo::URIParser.new('mongodb://bob:secret.word@/tmp/mongod.sock')
42
+ assert_equal 1, parser.nodes.length
43
+ assert_equal '/tmp/mongod.sock', parser.nodes[0][0]
44
+ assert_equal "bob", parser.auths.first[:username]
45
+ assert_equal "secret.word", parser.auths.first[:password]
46
+ assert_equal 'admin', parser.auths.first[:source]
47
+ end
48
+
49
+ def test_unix_socket_with_db
50
+ parser = Mongo::URIParser.new('mongodb://bob:secret.word@/tmp/mongod.sock/some_db')
51
+ assert_equal 1, parser.nodes.length
52
+ assert_equal '/tmp/mongod.sock', parser.nodes[0][0]
53
+ assert_equal 'bob', parser.auths.first[:username]
54
+ assert_equal 'secret.word', parser.auths.first[:password]
55
+ assert_equal 'some_db', parser.auths.first[:source]
56
+ end
57
+
58
+ def test_ipv6_format
59
+ parser = Mongo::URIParser.new('mongodb://[::1]:27018')
60
+ assert_equal 1, parser.nodes.length
61
+ assert_equal '::1', parser.nodes[0][0]
62
+ assert_equal 27018, parser.nodes[0][1]
63
+
64
+ parser = Mongo::URIParser.new('mongodb://[::1]')
65
+ assert_equal 1, parser.nodes.length
66
+ assert_equal '::1', parser.nodes[0][0]
67
+ end
68
+
69
+ def test_ipv6_format_multi
70
+ parser = Mongo::URIParser.new('mongodb://[::1]:27017,[::1]:27018')
71
+ assert_equal 2, parser.nodes.length
72
+ assert_equal '::1', parser.nodes[0][0]
73
+ assert_equal 27017, parser.nodes[0][1]
74
+ assert_equal '::1', parser.nodes[1][0]
75
+ assert_equal 27018, parser.nodes[1][1]
76
+
77
+ parser = Mongo::URIParser.new('mongodb://[::1]:27017,localhost:27018')
78
+ assert_equal 2, parser.nodes.length
79
+ assert_equal '::1', parser.nodes[0][0]
80
+ assert_equal 27017, parser.nodes[0][1]
81
+ assert_equal 'localhost', parser.nodes[1][0]
82
+ assert_equal 27018, parser.nodes[1][1]
83
+
84
+ parser = Mongo::URIParser.new('mongodb://localhost:27017,[::1]:27018')
85
+ assert_equal 2, parser.nodes.length
86
+ assert_equal 'localhost', parser.nodes[0][0]
87
+ assert_equal 27017, parser.nodes[0][1]
88
+ assert_equal '::1', parser.nodes[1][0]
89
+ assert_equal 27018, parser.nodes[1][1]
90
+ end
91
+
20
92
  def test_multiple_uris
21
93
  parser = Mongo::URIParser.new('mongodb://a.example.com:27018,b.example.com')
22
94
  assert_equal 2, parser.nodes.length
@@ -24,39 +96,89 @@ class URITest < Test::Unit::TestCase
24
96
  assert_equal ['b.example.com', 27017], parser.nodes[1]
25
97
  end
26
98
 
99
+ def test_username_without_password
100
+ parser = Mongo::URIParser.new('mongodb://bob:@localhost?authMechanism=GSSAPI')
101
+ assert_equal "bob", parser.auths.first[:username]
102
+ assert_equal nil, parser.auths.first[:password]
103
+
104
+ parser = Mongo::URIParser.new('mongodb://bob@localhost?authMechanism=GSSAPI')
105
+ assert_equal nil, parser.auths.first[:password]
106
+
107
+ assert_raise_error MongoArgumentError do
108
+ Mongo::URIParser.new('mongodb://bob:@localhost')
109
+ end
110
+
111
+ assert_raise_error MongoArgumentError do
112
+ Mongo::URIParser.new('mongodb://bob@localhost')
113
+ end
114
+ end
115
+
116
+ def test_username_without_password_unix_socket
117
+ parser = Mongo::URIParser.new('mongodb://bob:@/tmp/mongod.sock?authMechanism=GSSAPI')
118
+ assert_equal "bob", parser.auths.first[:username]
119
+ assert_equal nil, parser.auths.first[:password]
120
+
121
+ parser = Mongo::URIParser.new('mongodb://bob@/tmp/mongod.sock?authMechanism=GSSAPI')
122
+ assert_equal nil, parser.auths.first[:password]
123
+
124
+ assert_raise_error MongoArgumentError do
125
+ Mongo::URIParser.new('mongodb://bob:@/tmp/mongod.sock')
126
+ end
127
+
128
+ assert_raise_error MongoArgumentError do
129
+ Mongo::URIParser.new('mongodb://bob@/tmp/mongod.sock')
130
+ end
131
+ end
132
+
27
133
  def test_complex_passwords
28
134
  parser = Mongo::URIParser.new('mongodb://bob:secret.word@a.example.com:27018/test')
29
- assert_equal "bob", parser.auths[0][:username]
30
- assert_equal "secret.word", parser.auths[0][:password]
135
+ assert_equal "bob", parser.auths.first[:username]
136
+ assert_equal "secret.word", parser.auths.first[:password]
31
137
 
32
138
  parser = Mongo::URIParser.new('mongodb://bob:s-_3#%R.t@a.example.com:27018/test')
33
- assert_equal "bob", parser.auths[0][:username]
34
- assert_equal "s-_3#%R.t", parser.auths[0][:password]
139
+ assert_equal "bob", parser.auths.first[:username]
140
+ assert_equal "s-_3#%R.t", parser.auths.first[:password]
141
+
142
+ assert_raise_error MongoArgumentError do
143
+ Mongo::URIParser.new('mongodb://doctor:bad:wolf@gallifrey.com:27018/test')
144
+ end
145
+
146
+ assert_raise_error MongoArgumentError do
147
+ Mongo::URIParser.new('mongodb://doctor:bow@tie@gallifrey.com:27018/test')
148
+ end
35
149
  end
36
150
 
37
151
  def test_complex_usernames
38
- parser = Mongo::URIParser.new('mongodb://b:ob:secret.word@a.example.com:27018/test')
39
- assert_equal "b:ob", parser.auths[0][:username]
40
- end
152
+ parser = Mongo::URIParser.new('mongodb://s-_3#%R.t:secret.word@a.example.com:27018/test')
153
+ assert_equal "s-_3#%R.t", parser.auths.first[:username]
154
+
155
+ assert_raise_error MongoArgumentError do
156
+ Mongo::URIParser.new('mongodb://doc:tor:badwolf@gallifrey.com:27018/test')
157
+ end
41
158
 
42
- def test_passwords_contain_no_commas
43
- assert_raise MongoArgumentError do
44
- Mongo::URIParser.new('mongodb://bob:a,b@a.example.com:27018/test')
159
+ assert_raise_error MongoArgumentError do
160
+ Mongo::URIParser.new('mongodb://d@ctor:bowtie@gallifrey.com:27018/test')
45
161
  end
46
162
  end
47
163
 
48
- def test_multiple_uris_with_auths
49
- parser = Mongo::URIParser.new('mongodb://bob:secret@a.example.com:27018,b.example.com/test')
50
- assert_equal 2, parser.nodes.length
51
- assert_equal ['a.example.com', 27018], parser.nodes[0]
52
- assert_equal ['b.example.com', 27017], parser.nodes[1]
53
- assert_equal 2, parser.auths.length
54
- assert_equal "bob", parser.auths[0][:username]
55
- assert_equal "secret", parser.auths[0][:password]
56
- assert_equal "test", parser.auths[0][:db_name]
57
- assert_equal "bob", parser.auths[1][:username]
58
- assert_equal "secret", parser.auths[1][:password]
59
- assert_equal "test", parser.auths[1][:db_name]
164
+ def test_username_with_encoded_symbol
165
+ parser = Mongo::URIParser.new('mongodb://f%40o:bar@localhost/admin')
166
+ username = parser.auths.first[:username]
167
+ assert_equal 'f@o', username
168
+
169
+ parser = Mongo::URIParser.new('mongodb://f%3Ao:bar@localhost/admin')
170
+ username = parser.auths.first[:username]
171
+ assert_equal 'f:o', username
172
+ end
173
+
174
+ def test_password_with_encoded_symbol
175
+ parser = Mongo::URIParser.new('mongodb://foo:b%40r@localhost/admin')
176
+ password = parser.auths.first[:password]
177
+ assert_equal 'b@r', password
178
+
179
+ parser = Mongo::URIParser.new('mongodb://foo:b%3Ar@localhost/admin')
180
+ password = parser.auths.first[:password]
181
+ assert_equal 'b:r', password
60
182
  end
61
183
 
62
184
  def test_opts_with_semincolon_separator
@@ -134,6 +256,11 @@ class URITest < Test::Unit::TestCase
134
256
  assert_equal :primary, parser.readpreference
135
257
  end
136
258
 
259
+ def test_read_preference_option_primary_unix_sock
260
+ parser = Mongo::URIParser.new("mongodb:///tmp/mongod.sock?readPreference=primary")
261
+ assert_equal :primary, parser.readpreference
262
+ end
263
+
137
264
  def test_read_preference_option_primary_preferred
138
265
  parser = Mongo::URIParser.new("mongodb://localhost:27018?readPreference=primaryPreferred")
139
266
  assert_equal :primary_preferred, parser.readpreference
@@ -175,6 +302,34 @@ class URITest < Test::Unit::TestCase
175
302
  assert_equal :nearest, parser.connection_options[:read]
176
303
  end
177
304
 
305
+ def test_read_preference_tags
306
+ parser = Mongo::URIParser.new("mongodb://localhost:27017?replicaset=test&" +
307
+ "readPreferenceTags=dc:ny,rack:1")
308
+ expected_tags = [{ 'dc' => 'ny', 'rack' => '1' }]
309
+ assert_equal expected_tags, parser.connection_options[:tag_sets]
310
+ end
311
+
312
+ def test_read_preference_tags_multiple
313
+ parser = Mongo::URIParser.new("mongodb://localhost:27017?replicaset=test&" +
314
+ "readPreferenceTags=dc:ny,rack:1&readPreferenceTags=dc:bos")
315
+ expected_tags = [{'dc' => 'ny', 'rack' => '1'}, { 'dc' => 'bos' }]
316
+ assert_equal expected_tags, parser.connection_options[:tag_sets]
317
+ end
318
+
319
+ def test_invalid_read_preference_tags
320
+ assert_raise_error MongoArgumentError do
321
+ Mongo::URIParser.new("mongodb://localhost:27017?replicaset=test&" +
322
+ "readPreferenceTags=dc")
323
+ end
324
+ end
325
+
326
+ def test_invalid_read_preference_tags_multiple
327
+ assert_raise_error MongoArgumentError do
328
+ Mongo::URIParser.new("mongodb://localhost:27017?replicaset=test&" +
329
+ "readPreferenceTags=dc:nyc&readPreferenceTags=dc")
330
+ end
331
+ end
332
+
178
333
  def test_connection_when_sharded_with_no_options
179
334
  parser = Mongo::URIParser.new("mongodb://localhost:27017,localhost:27018")
180
335
  client = parser.connection({}, false, true)
@@ -197,4 +352,95 @@ class URITest < Test::Unit::TestCase
197
352
  assert_equal :nearest, client.read
198
353
  assert_true client.mongos?
199
354
  end
355
+
356
+ def test_auth_source
357
+ parser = Mongo::URIParser.new("mongodb://user:pass@localhost?authSource=foobar")
358
+ assert_equal 'foobar', parser.authsource
359
+ end
360
+
361
+ def test_auth_mechanism
362
+ parser = Mongo::URIParser.new("mongodb://user@localhost?authMechanism=MONGODB-X509")
363
+ assert_equal 'MONGODB-X509', parser.authmechanism
364
+
365
+ assert_raise_error MongoArgumentError do
366
+ Mongo::URIParser.new("mongodb://user@localhost?authMechanism=INVALID")
367
+ end
368
+ end
369
+
370
+ def test_auth_mechanism_properties
371
+ uri = "mongodb://user@localhost?authMechanism=GSSAPI&authMechanismProperties=SERVICE_NAME" +
372
+ ":mongodb,CANONICALIZE_HOST_NAME:true"
373
+ parser = Mongo::URIParser.new(uri)
374
+ properties = {:service_name => "mongodb", :canonicalize_host_name => true}
375
+ assert_equal properties, parser.authmechanismproperties
376
+ assert_equal 'GSSAPI', parser.authmechanism
377
+
378
+ uri = "mongodb://user@localhost?authMechanism=GSSAPI&authMechanismProperties=SERVICE_NAME" +
379
+ ":MongoDB,CANONICALIZE_HOST_NAME:false,SERVICE_REALM:test"
380
+ parser = Mongo::URIParser.new(uri)
381
+ properties = {:service_name => "MongoDB", :canonicalize_host_name => false, :service_realm => "test"}
382
+ assert_equal properties, parser.authmechanismproperties
383
+ assert_equal 'GSSAPI', parser.authmechanism
384
+ end
385
+
386
+ def test_invalid_auth_mechanism_properties
387
+ uri = "mongodb://user@localhost?authMechanism=GSSAPI&authMechanismProperties=SERVICE_NAME" +
388
+ ":mongodb,INVALID_PROPERTY:true"
389
+ assert_raise_error MongoArgumentError do
390
+ parser = Mongo::URIParser.new(uri)
391
+ end
392
+
393
+ uri = "mongodb://user@localhost?authMechanism=PLAIN&authMechanismProperties="+
394
+ "SERVICE_NAME:mongodb"
395
+ assert_raise_error MongoArgumentError do
396
+ parser = Mongo::URIParser.new(uri)
397
+ end
398
+ end
399
+
400
+ def test_sasl_plain
401
+ parser = Mongo::URIParser.new("mongodb://user:pass@localhost?authMechanism=PLAIN")
402
+ assert_equal 'PLAIN', parser.auths.first[:mechanism]
403
+ assert_equal 'user', parser.auths.first[:username]
404
+ assert_equal 'pass', parser.auths.first[:password]
405
+ assert_equal 'admin', parser.auths.first[:source]
406
+
407
+ parser = Mongo::URIParser.new("mongodb://foo%2Fbar%40example.net:pass@localhost/some_db?authMechanism=PLAIN")
408
+ assert_equal 'PLAIN', parser.auths.first[:mechanism]
409
+ assert_equal 'foo/bar@example.net', parser.auths.first[:username]
410
+ assert_equal 'pass', parser.auths.first[:password]
411
+ assert_equal 'some_db', parser.auths.first[:source]
412
+
413
+ assert_raise_error MongoArgumentError do
414
+ Mongo::URIParser.new("mongodb://user@localhost/some_db?authMechanism=PLAIN")
415
+ end
416
+ end
417
+
418
+ def test_gssapi
419
+ uri = "mongodb://foo%2Fbar%40example.net@localhost?authMechanism=GSSAPI;"
420
+ parser = Mongo::URIParser.new(uri)
421
+ assert_equal 'GSSAPI', parser.auths.first[:mechanism]
422
+ assert_equal 'foo/bar@example.net', parser.auths.first[:username]
423
+
424
+
425
+ uri = "mongodb://foo%2Fbar%40example.net@localhost?authMechanism=GSSAPI;" +
426
+ "authMechanismProperties=SERVICE_NAME:mongodb,SERVICE_REALM:example," +
427
+ "CANONICALIZE_HOST_NAME:true"
428
+ parser = Mongo::URIParser.new(uri)
429
+ assert_equal 'GSSAPI', parser.auths.first[:mechanism]
430
+ assert_equal 'foo/bar@example.net', parser.auths.first[:username]
431
+ assert_equal 'mongodb', parser.auths.first[:extra][:service_name]
432
+ assert_equal true, parser.auths.first[:extra][:canonicalize_host_name]
433
+ assert_equal 'example', parser.auths.first[:extra][:service_realm]
434
+ end
435
+
436
+ def test_opts_case_sensitivity
437
+ # options authsource, replicaset, w should be case sensitive
438
+ uri = "mongodb://localhost?authSource=FooBar;" +
439
+ "replicaSet=Foo;" +
440
+ "w=Majority"
441
+ parser = Mongo::URIParser.new(uri)
442
+ assert_equal 'FooBar', parser.authsource
443
+ assert_equal 'Foo', parser.replicaset
444
+ assert_equal :Majority, parser.w
445
+ end
200
446
  end
@@ -1,3 +1,17 @@
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
  include Mongo
3
17
 
@@ -5,7 +19,7 @@ class WriteConcernTest < Test::Unit::TestCase
5
19
  context "Write concern propogation: " do
6
20
  setup do
7
21
  @con = standard_connection
8
- @db = @con[MONGO_TEST_DB]
22
+ @db = @con[TEST_DB]
9
23
  @col = @db['test-safe']
10
24
  @col.create_index([[:a, 1]], :unique => true)
11
25
  @col.remove
@@ -45,7 +59,7 @@ class WriteConcernTest < Test::Unit::TestCase
45
59
  context "Write concern error objects" do
46
60
  setup do
47
61
  @con = standard_connection
48
- @db = @con[MONGO_TEST_DB]
62
+ @db = @con[TEST_DB]
49
63
  @col = @db['test']
50
64
  @col.remove
51
65
  @col.insert({:a => 1})
@@ -57,8 +71,8 @@ class WriteConcernTest < Test::Unit::TestCase
57
71
  response = @col.update({:a => 1}, {"$set" => {:a => 2}},
58
72
  :multi => true)
59
73
 
60
- assert response['updatedExisting']
61
- assert_equal 3, response['n']
74
+ assert(response['updatedExisting'] || @db.connection.wire_version_feature?(Mongo::MongoClient::BATCH_COMMANDS)) # TODO - review new write command return values
75
+ assert(response['n'] == 3 || @db.connection.wire_version_feature?(Mongo::MongoClient::BATCH_COMMANDS)) # TODO - update command top pending
62
76
  end
63
77
 
64
78
  should "return object on remove" do
@@ -69,7 +83,7 @@ class WriteConcernTest < Test::Unit::TestCase
69
83
 
70
84
  context "Write concern in gridfs" do
71
85
  setup do
72
- @db = standard_connection.db(MONGO_TEST_DB)
86
+ @db = standard_connection.db(TEST_DB)
73
87
  @grid = Mongo::GridFileSystem.new(@db)
74
88
  @filename = 'sample'
75
89
  end
@@ -0,0 +1,50 @@
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
+
15
+ # Redirects output while yielding a given block of code.
16
+ #
17
+ # @return [Object] The result of the block.
18
+ def silently
19
+ warn_level = $VERBOSE
20
+ $VERBOSE = nil
21
+ begin
22
+ result = yield
23
+ ensure
24
+ $VERBOSE = warn_level
25
+ end
26
+ result
27
+ end
28
+
29
+ class Hash
30
+ def stringify_keys
31
+ dup.stringify_keys!
32
+ end
33
+
34
+ def stringify_keys!
35
+ keys.each do |key|
36
+ self[key.to_s] = delete(key)
37
+ end
38
+ self
39
+ end
40
+
41
+ def except(*keys)
42
+ dup.except!(*keys)
43
+ end
44
+
45
+ # Replaces the hash without the given keys.
46
+ def except!(*keys)
47
+ keys.each { |key| delete(key) }
48
+ self
49
+ end
50
+ end