mongo 1.7.1 → 1.8.0

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 (138) hide show
  1. data/{LICENSE.txt → LICENSE} +0 -0
  2. data/README.md +124 -111
  3. data/Rakefile +9 -325
  4. data/VERSION +1 -0
  5. data/bin/mongo_console +4 -4
  6. data/examples/admin.rb +43 -0
  7. data/examples/capped.rb +22 -0
  8. data/examples/cursor.rb +48 -0
  9. data/examples/gridfs.rb +44 -0
  10. data/examples/index_test.rb +126 -0
  11. data/examples/info.rb +31 -0
  12. data/examples/queries.rb +74 -0
  13. data/examples/replica_set.rb +26 -0
  14. data/examples/simple.rb +25 -0
  15. data/examples/strict.rb +35 -0
  16. data/examples/types.rb +36 -0
  17. data/{test/load → examples/web}/thin/load.rb +3 -1
  18. data/{test/load → examples/web}/unicorn/load.rb +5 -3
  19. data/lib/mongo.rb +8 -10
  20. data/lib/mongo/collection.rb +134 -114
  21. data/lib/mongo/cursor.rb +21 -14
  22. data/lib/mongo/db.rb +30 -28
  23. data/lib/mongo/exceptions.rb +1 -1
  24. data/lib/mongo/gridfs/grid.rb +8 -7
  25. data/lib/mongo/gridfs/grid_ext.rb +1 -1
  26. data/lib/mongo/gridfs/grid_file_system.rb +6 -5
  27. data/lib/mongo/gridfs/grid_io.rb +22 -19
  28. data/lib/mongo/legacy.rb +82 -0
  29. data/lib/mongo/{connection.rb → mongo_client.rb} +82 -61
  30. data/lib/mongo/{repl_set_connection.rb → mongo_replica_set_client.rb} +54 -39
  31. data/lib/mongo/{sharded_connection.rb → mongo_sharded_client.rb} +9 -9
  32. data/lib/mongo/networking.rb +25 -20
  33. data/lib/mongo/util/conversions.rb +1 -1
  34. data/lib/mongo/util/core_ext.rb +1 -1
  35. data/lib/mongo/util/logging.rb +20 -4
  36. data/lib/mongo/util/node.rb +16 -16
  37. data/lib/mongo/util/pool.rb +56 -27
  38. data/lib/mongo/util/pool_manager.rb +28 -27
  39. data/lib/mongo/util/server_version.rb +1 -1
  40. data/lib/mongo/util/sharding_pool_manager.rb +8 -8
  41. data/lib/mongo/util/ssl_socket.rb +1 -5
  42. data/lib/mongo/util/support.rb +24 -8
  43. data/lib/mongo/util/tcp_socket.rb +0 -4
  44. data/lib/mongo/util/uri_parser.rb +54 -38
  45. data/lib/mongo/util/write_concern.rb +67 -0
  46. data/mongo.gemspec +21 -32
  47. data/test/auxillary/{1.4_features.rb → 1.4_feature_test.rb} +4 -5
  48. data/test/auxillary/authentication_test.rb +18 -20
  49. data/test/auxillary/autoreconnect_test.rb +3 -5
  50. data/test/auxillary/fork_test.rb +5 -7
  51. data/test/auxillary/repl_set_auth_test.rb +13 -15
  52. data/test/auxillary/slave_connection_test.rb +8 -7
  53. data/test/auxillary/threaded_authentication_test.rb +15 -17
  54. data/test/bson/binary_test.rb +1 -1
  55. data/test/bson/bson_test.rb +60 -36
  56. data/test/bson/byte_buffer_test.rb +1 -1
  57. data/test/bson/hash_with_indifferent_access_test.rb +2 -2
  58. data/test/bson/json_test.rb +1 -2
  59. data/test/bson/object_id_test.rb +1 -2
  60. data/test/bson/ordered_hash_test.rb +1 -1
  61. data/test/bson/timestamp_test.rb +1 -1
  62. data/test/{collection_test.rb → functional/collection_test.rb} +57 -57
  63. data/test/{connection_test.rb → functional/connection_test.rb} +75 -89
  64. data/test/{conversions_test.rb → functional/conversions_test.rb} +1 -1
  65. data/test/{cursor_fail_test.rb → functional/cursor_fail_test.rb} +3 -29
  66. data/test/{cursor_message_test.rb → functional/cursor_message_test.rb} +1 -1
  67. data/test/{cursor_test.rb → functional/cursor_test.rb} +5 -1
  68. data/test/{db_api_test.rb → functional/db_api_test.rb} +8 -9
  69. data/test/{db_connection_test.rb → functional/db_connection_test.rb} +3 -5
  70. data/test/{db_test.rb → functional/db_test.rb} +13 -13
  71. data/test/{grid_file_system_test.rb → functional/grid_file_system_test.rb} +2 -2
  72. data/test/{grid_io_test.rb → functional/grid_io_test.rb} +6 -6
  73. data/test/{grid_test.rb → functional/grid_test.rb} +4 -10
  74. data/test/{pool_test.rb → functional/pool_test.rb} +1 -1
  75. data/test/functional/safe_test.rb +84 -0
  76. data/test/{support_test.rb → functional/support_test.rb} +1 -1
  77. data/test/{threading_test.rb → functional/threading_test.rb} +9 -9
  78. data/test/{timeout_test.rb → functional/timeout_test.rb} +1 -1
  79. data/test/{uri_test.rb → functional/uri_test.rb} +1 -1
  80. data/test/functional/write_concern_test.rb +104 -0
  81. data/test/replica_set/basic_test.rb +139 -0
  82. data/test/replica_set/client_test.rb +255 -0
  83. data/test/replica_set/complex_connect_test.rb +62 -0
  84. data/test/replica_set/connection_test.rb +255 -0
  85. data/test/{replica_sets → replica_set}/count_test.rb +17 -14
  86. data/test/replica_set/cursor_test.rb +75 -0
  87. data/test/{replica_sets → replica_set}/insert_test.rb +19 -16
  88. data/test/replica_set/query_test.rb +64 -0
  89. data/test/replica_set/refresh_test.rb +153 -0
  90. data/test/{replica_sets → replica_set}/replication_ack_test.rb +21 -17
  91. data/test/sharded_cluster/basic_test.rb +31 -50
  92. data/test/support/hash_with_indifferent_access.rb +1 -1
  93. data/test/test_helper.rb +56 -9
  94. data/test/threading/threading_with_large_pool_test.rb +8 -8
  95. data/test/tools/mongo_config.rb +270 -58
  96. data/test/tools/mongo_config_test.rb +146 -0
  97. data/test/unit/client_test.rb +230 -0
  98. data/test/unit/collection_test.rb +45 -32
  99. data/test/unit/connection_test.rb +82 -74
  100. data/test/unit/cursor_test.rb +14 -6
  101. data/test/unit/db_test.rb +8 -8
  102. data/test/unit/grid_test.rb +11 -11
  103. data/test/unit/node_test.rb +24 -24
  104. data/test/unit/pool_manager_test.rb +13 -13
  105. data/test/unit/pool_test.rb +1 -1
  106. data/test/unit/read_test.rb +21 -26
  107. data/test/unit/safe_test.rb +52 -33
  108. data/test/unit/util_test.rb +55 -0
  109. data/test/unit/write_concern_test.rb +161 -0
  110. metadata +158 -171
  111. data/docs/CREDITS.md +0 -123
  112. data/docs/FAQ.md +0 -116
  113. data/docs/GRID_FS.md +0 -158
  114. data/docs/HISTORY.md +0 -392
  115. data/docs/READ_PREFERENCE.md +0 -99
  116. data/docs/RELEASES.md +0 -54
  117. data/docs/REPLICA_SETS.md +0 -113
  118. data/docs/TAILABLE_CURSORS.md +0 -51
  119. data/docs/TUTORIAL.md +0 -356
  120. data/docs/WRITE_CONCERN.md +0 -31
  121. data/lib/mongo/gridfs/grid_io_fix.rb +0 -38
  122. data/lib/mongo/version.rb +0 -3
  123. data/test/bson/test_helper.rb +0 -30
  124. data/test/replica_sets/basic_test.rb +0 -119
  125. data/test/replica_sets/complex_connect_test.rb +0 -57
  126. data/test/replica_sets/complex_read_preference_test.rb +0 -237
  127. data/test/replica_sets/connect_test.rb +0 -156
  128. data/test/replica_sets/cursor_test.rb +0 -70
  129. data/test/replica_sets/pooled_insert_test.rb +0 -57
  130. data/test/replica_sets/query_test.rb +0 -50
  131. data/test/replica_sets/read_preference_test.rb +0 -234
  132. data/test/replica_sets/refresh_test.rb +0 -156
  133. data/test/replica_sets/refresh_with_threads_test.rb +0 -60
  134. data/test/replica_sets/rs_test_helper.rb +0 -39
  135. data/test/safe_test.rb +0 -68
  136. data/test/sharded_cluster/mongo_config_test.rb +0 -126
  137. data/test/sharded_cluster/sc_test_helper.rb +0 -39
  138. data/test/tools/repl_set_manager.rb +0 -418
@@ -1,5 +1,5 @@
1
1
  # encoding: binary
2
- require File.expand_path("../test_helper", __FILE__)
2
+ require 'test_helper'
3
3
 
4
4
  class ByteBufferTest < Test::Unit::TestCase
5
5
  include BSON
@@ -1,6 +1,6 @@
1
1
  # encoding:utf-8
2
- require File.expand_path("../test_helper", __FILE__)
3
- require './test/support/hash_with_indifferent_access'
2
+ require 'test_helper'
3
+ require 'support/hash_with_indifferent_access'
4
4
 
5
5
  class HashWithIndifferentAccessTest < Test::Unit::TestCase
6
6
  include BSON
@@ -1,5 +1,4 @@
1
- require File.expand_path("../test_helper", __FILE__)
2
- require 'rubygems'
1
+ require 'test_helper'
3
2
  require 'json'
4
3
 
5
4
  class JSONTest < Test::Unit::TestCase
@@ -1,5 +1,4 @@
1
- require File.expand_path("../test_helper", __FILE__)
2
- require 'rubygems'
1
+ require 'test_helper'
3
2
  require 'json'
4
3
 
5
4
  class ObjectIdTest < Test::Unit::TestCase
@@ -1,4 +1,4 @@
1
- require File.expand_path("../test_helper", __FILE__)
1
+ require 'test_helper'
2
2
 
3
3
  class OrderedHashTest < Test::Unit::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path("../test_helper", __FILE__)
1
+ require 'test_helper'
2
2
 
3
3
  class TimestampTest < Test::Unit::TestCase
4
4
 
@@ -1,11 +1,11 @@
1
- require File.expand_path("../test_helper", __FILE__)
2
1
  require 'rbconfig'
2
+ require 'test_helper'
3
3
 
4
4
  class TestCollection < Test::Unit::TestCase
5
- @@connection ||= standard_connection(:op_timeout => 10)
6
- @@db = @@connection.db(MONGO_TEST_DB)
7
- @@test = @@db.collection("test")
8
- @@version = @@connection.server_version
5
+ @@client ||= standard_connection(:op_timeout => 10)
6
+ @@db = @@client.db(MONGO_TEST_DB)
7
+ @@test = @@db.collection("test")
8
+ @@version = @@client.server_version
9
9
 
10
10
  def setup
11
11
  @@test.remove
@@ -28,8 +28,8 @@ class TestCollection < Test::Unit::TestCase
28
28
  assert_equal BSON::ObjectId, @coll_default_pk.pk_factory
29
29
 
30
30
  # Create a db with a pk_factory.
31
- @db = Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
32
- ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT).db(MONGO_TEST_DB, :pk => Object.new)
31
+ @db = MongoClient.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
32
+ ENV['MONGO_RUBY_DRIVER_PORT'] || MongoClient::DEFAULT_PORT).db(MONGO_TEST_DB, :pk => Object.new)
33
33
  @coll = @db.collection('coll-with-pk')
34
34
  assert @coll.pk_factory.is_a?(Object)
35
35
 
@@ -92,23 +92,23 @@ class TestCollection < Test::Unit::TestCase
92
92
  end
93
93
 
94
94
  def test_nil_id
95
- assert_equal 5, @@test.insert({"_id" => 5, "foo" => "bar"}, {:safe => true})
96
- assert_equal 5, @@test.save({"_id" => 5, "foo" => "baz"}, {:safe => true})
95
+ assert_equal 5, @@test.insert({"_id" => 5, "foo" => "bar"})
96
+ assert_equal 5, @@test.save({"_id" => 5, "foo" => "baz"})
97
97
  assert_equal nil, @@test.find_one("foo" => "bar")
98
98
  assert_equal "baz", @@test.find_one(:_id => 5)["foo"]
99
99
  assert_raise OperationFailure do
100
- @@test.insert({"_id" => 5, "foo" => "bar"}, {:safe => true})
100
+ @@test.insert({"_id" => 5, "foo" => "bar"})
101
101
  end
102
102
 
103
- assert_equal nil, @@test.insert({"_id" => nil, "foo" => "bar"}, {:safe => true})
104
- assert_equal nil, @@test.save({"_id" => nil, "foo" => "baz"}, {:safe => true})
103
+ assert_equal nil, @@test.insert({"_id" => nil, "foo" => "bar"})
104
+ assert_equal nil, @@test.save({"_id" => nil, "foo" => "baz"})
105
105
  assert_equal nil, @@test.find_one("foo" => "bar")
106
106
  assert_equal "baz", @@test.find_one(:_id => nil)["foo"]
107
107
  assert_raise OperationFailure do
108
- @@test.insert({"_id" => nil, "foo" => "bar"}, {:safe => true})
108
+ @@test.insert({"_id" => nil, "foo" => "bar"})
109
109
  end
110
110
  assert_raise OperationFailure do
111
- @@test.insert({:_id => nil, "foo" => "bar"}, {:safe => true})
111
+ @@test.insert({:_id => nil, "foo" => "bar"})
112
112
  end
113
113
  end
114
114
 
@@ -146,11 +146,11 @@ class TestCollection < Test::Unit::TestCase
146
146
  @@test.create_index("hello", :unique => true)
147
147
  a = {"hello" => "world"}
148
148
  @@test.insert(a)
149
- @@test.insert(a)
149
+ @@test.insert(a, :w => 0)
150
150
  assert(@@db.get_last_error['err'].include?("11000"))
151
151
 
152
152
  assert_raise OperationFailure do
153
- @@test.insert(a, :safe => true)
153
+ @@test.insert(a)
154
154
  end
155
155
  end
156
156
 
@@ -174,7 +174,7 @@ class TestCollection < Test::Unit::TestCase
174
174
  docs << {:foo => 2}
175
175
  docs << {:foo => 3}
176
176
  assert_raise OperationFailure do
177
- @@test.insert(docs, :safe => true)
177
+ @@test.insert(docs)
178
178
  end
179
179
  assert_equal 1, @@test.count
180
180
  @@test.remove
@@ -185,7 +185,7 @@ class TestCollection < Test::Unit::TestCase
185
185
  docs << {:foo => 2}
186
186
  docs << {:foo => 3}
187
187
  assert_raise OperationFailure do
188
- @@test.insert(docs, :safe => true, :continue_on_error => true)
188
+ @@test.insert(docs, :continue_on_error => true)
189
189
  end
190
190
  assert_equal 3, @@test.count
191
191
 
@@ -255,26 +255,26 @@ class TestCollection < Test::Unit::TestCase
255
255
  end
256
256
  end
257
257
 
258
- if @@version >= "1.5.1"
259
- def test_safe_mode_with_advanced_safe_with_invalid_options
260
- assert_raise_error ArgumentError, "Unknown key(s): wtime" do
261
- @@test.insert({:foo => 1}, :safe => {:w => 2, :wtime => 1, :fsync => true})
262
- end
263
- assert_raise_error ArgumentError, "Unknown key(s): wtime" do
264
- @@test.update({:foo => 1}, {:foo => 2}, :safe => {:w => 2, :wtime => 1, :fsync => true})
265
- end
266
-
267
- assert_raise_error ArgumentError, "Unknown key(s): wtime" do
268
- @@test.remove({:foo => 2}, :safe => {:w => 2, :wtime => 1, :fsync => true})
269
- end
270
- end
271
- end
258
+ #if @@version >= "1.5.1"
259
+ # def test_safe_mode_with_advanced_safe_with_invalid_options
260
+ # assert_raise_error ArgumentError, "Unknown key(s): wtime" do
261
+ # @@test.insert({:foo => 1}, :w => 2, :wtime => 1, :fsync => true)
262
+ # end
263
+ # assert_raise_error ArgumentError, "Unknown key(s): wtime" do
264
+ # @@test.update({:foo => 1}, {:foo => 2}, :w => 2, :wtime => 1, :fsync => true)
265
+ # end
266
+ #
267
+ # assert_raise_error ArgumentError, "Unknown key(s): wtime" do
268
+ # @@test.remove({:foo => 2}, :w => 2, :wtime => 1, :fsync => true)
269
+ # end
270
+ # end
271
+ #end
272
272
 
273
273
  if @@version >= "2.0.0"
274
274
  def test_safe_mode_with_journal_commit_option
275
- @@test.insert({:foo => 1}, :safe => {:j => true})
276
- @@test.update({:foo => 1}, {:foo => 2}, :safe => {:j => true})
277
- @@test.remove({:foo => 2}, :safe => {:j => true})
275
+ @@test.insert({:foo => 1}, :j => true)
276
+ @@test.update({:foo => 1}, {:foo => 2}, :j => true)
277
+ @@test.remove({:foo => 2}, :j => true)
278
278
  end
279
279
  end
280
280
 
@@ -332,7 +332,7 @@ class TestCollection < Test::Unit::TestCase
332
332
 
333
333
  # Can't change an index.
334
334
  assert_raise OperationFailure do
335
- @@test.update({}, {"$inc" => {"x" => 1}}, :safe => true)
335
+ @@test.update({}, {"$inc" => {"x" => 1}})
336
336
  end
337
337
  @@test.drop
338
338
  end
@@ -348,7 +348,7 @@ class TestCollection < Test::Unit::TestCase
348
348
 
349
349
  # Can't duplicate an index.
350
350
  assert_raise OperationFailure do
351
- @@test.update({}, {"x" => 10}, :safe => true)
351
+ @@test.update({}, {"x" => 10})
352
352
  end
353
353
  @@test.drop
354
354
  end
@@ -358,39 +358,39 @@ class TestCollection < Test::Unit::TestCase
358
358
  @@test.create_index("hello", :unique => true)
359
359
 
360
360
  @@test.save("hello" => "world")
361
- @@test.save("hello" => "world")
361
+ @@test.save({"hello" => "world"}, :w => 0)
362
362
 
363
363
  assert_raise OperationFailure do
364
- @@test.save({"hello" => "world"}, :safe => true)
364
+ @@test.save({"hello" => "world"})
365
365
  end
366
366
  @@test.drop
367
367
  end
368
368
 
369
369
  def test_mocked_safe_remove
370
- @conn = standard_connection
371
- @db = @conn[MONGO_TEST_DB]
370
+ @client = standard_connection
371
+ @db = @client[MONGO_TEST_DB]
372
372
  @test = @db['test-safe-remove']
373
373
  @test.save({:a => 20})
374
- @conn.stubs(:receive).returns([[{'ok' => 0, 'err' => 'failed'}], 1, 0])
374
+ @client.stubs(:receive).returns([[{'ok' => 0, 'err' => 'failed'}], 1, 0])
375
375
 
376
376
  assert_raise OperationFailure do
377
- @test.remove({}, :safe => true)
377
+ @test.remove({})
378
378
  end
379
379
  @test.drop
380
380
  end
381
381
 
382
382
  def test_safe_remove
383
- @conn = standard_connection
384
- @db = @conn[MONGO_TEST_DB]
383
+ @client = standard_connection
384
+ @db = @client[MONGO_TEST_DB]
385
385
  @test = @db['test-safe-remove']
386
386
  @test.remove
387
387
  @test.save({:a => 50})
388
- assert_equal 1, @test.remove({}, :safe => true)["n"]
388
+ assert_equal 1, @test.remove({})["n"]
389
389
  @test.drop
390
390
  end
391
391
 
392
392
  def test_remove_return_value
393
- assert_equal true, @@test.remove({})
393
+ assert_equal true, @@test.remove({}, :w => 0)
394
394
  end
395
395
 
396
396
  def test_count
@@ -542,7 +542,7 @@ class TestCollection < Test::Unit::TestCase
542
542
  "_id" => 1,
543
543
  "title" => "this is my title",
544
544
  "author" => "bob",
545
- "posted" => Time.utc(1500),
545
+ "posted" => Time.utc(2000),
546
546
  "pageViews" => 5 ,
547
547
  "tags" => [ "fun" , "good" , "fun" ],
548
548
  "comments" => [
@@ -556,7 +556,7 @@ class TestCollection < Test::Unit::TestCase
556
556
  "_id" => 2,
557
557
  "title" => "this is your title",
558
558
  "author" => "dave",
559
- "posted" => Time.utc(1600),
559
+ "posted" => Time.utc(2001),
560
560
  "pageViews" => 7,
561
561
  "tags" => [ "fun" , "nasty" ],
562
562
  "comments" => [
@@ -570,7 +570,7 @@ class TestCollection < Test::Unit::TestCase
570
570
  "_id" => 3,
571
571
  "title" => "this is some other title",
572
572
  "author" => "jane",
573
- "posted" => Time.utc(1700),
573
+ "posted" => Time.utc(2002),
574
574
  "pageViews" => 6 ,
575
575
  "tags" => [ "nasty", "filthy" ],
576
576
  "comments" => [
@@ -631,25 +631,25 @@ class TestCollection < Test::Unit::TestCase
631
631
 
632
632
  def test_aggregate_pipeline_unwind
633
633
  setup_aggregate_data
634
- desired_results = [ {"_id"=>1, "title"=>"this is my title", "author"=>"bob", "posted"=>Time.utc(1500),
634
+ desired_results = [ {"_id"=>1, "title"=>"this is my title", "author"=>"bob", "posted"=>Time.utc(2000),
635
635
  "pageViews"=>5, "tags"=>"fun", "comments"=>[{"author"=>"joe", "text"=>"this is cool"},
636
636
  {"author"=>"sam", "text"=>"this is bad"}], "other"=>{"foo"=>5 } },
637
- {"_id"=>1, "title"=>"this is my title", "author"=>"bob", "posted"=>Time.utc(1500),
637
+ {"_id"=>1, "title"=>"this is my title", "author"=>"bob", "posted"=>Time.utc(2000),
638
638
  "pageViews"=>5, "tags"=>"good", "comments"=>[{"author"=>"joe", "text"=>"this is cool"},
639
639
  {"author"=>"sam", "text"=>"this is bad"}], "other"=>{"foo"=>5 } },
640
- {"_id"=>1, "title"=>"this is my title", "author"=>"bob", "posted"=>Time.utc(1500),
640
+ {"_id"=>1, "title"=>"this is my title", "author"=>"bob", "posted"=>Time.utc(2000),
641
641
  "pageViews"=>5, "tags"=>"fun", "comments"=>[{"author"=>"joe", "text"=>"this is cool"},
642
642
  {"author"=>"sam", "text"=>"this is bad"}], "other"=>{"foo"=>5 } },
643
- {"_id"=>2, "title"=>"this is your title", "author"=>"dave", "posted"=>Time.utc(1600),
643
+ {"_id"=>2, "title"=>"this is your title", "author"=>"dave", "posted"=>Time.utc(2001),
644
644
  "pageViews"=>7, "tags"=>"fun", "comments"=>[{"author"=>"barbara", "text"=>"this is interesting"},
645
645
  {"author"=>"jenny", "text"=>"i like to play pinball", "votes"=>10 }], "other"=>{"bar"=>14 } },
646
- {"_id"=>2, "title"=>"this is your title", "author"=>"dave", "posted"=>Time.utc(1600),
646
+ {"_id"=>2, "title"=>"this is your title", "author"=>"dave", "posted"=>Time.utc(2001),
647
647
  "pageViews"=>7, "tags"=>"nasty", "comments"=>[{"author"=>"barbara", "text"=>"this is interesting"},
648
648
  {"author"=>"jenny", "text"=>"i like to play pinball", "votes"=>10 }], "other"=>{"bar"=>14 } },
649
- {"_id"=>3, "title"=>"this is some other title", "author"=>"jane", "posted"=>Time.utc(1700),
649
+ {"_id"=>3, "title"=>"this is some other title", "author"=>"jane", "posted"=>Time.utc(2002),
650
650
  "pageViews"=>6, "tags"=>"nasty", "comments"=>[{"author"=>"will", "text"=>"i don't like the color"},
651
651
  {"author"=>"jenny", "text"=>"can i get that in green?"}], "other"=>{"bar"=>14 } },
652
- {"_id"=>3, "title"=>"this is some other title", "author"=>"jane", "posted"=>Time.utc(1700),
652
+ {"_id"=>3, "title"=>"this is some other title", "author"=>"jane", "posted"=>Time.utc(2002),
653
653
  "pageViews"=>6, "tags"=>"filthy", "comments"=>[{"author"=>"will", "text"=>"i don't like the color"},
654
654
  {"author"=>"jenny", "text"=>"can i get that in green?"}], "other"=>{"bar"=>14 } }
655
655
  ]
@@ -1,4 +1,4 @@
1
- require File.expand_path("../test_helper", __FILE__)
1
+ require 'test_helper'
2
2
  require 'logger'
3
3
  require 'stringio'
4
4
  require 'thread'
@@ -9,66 +9,52 @@ class TestConnection < Test::Unit::TestCase
9
9
  include BSON
10
10
 
11
11
  def setup
12
- @conn = standard_connection
12
+ @client = standard_connection
13
13
  end
14
14
 
15
15
  def teardown
16
- @conn.close
16
+ @client.close
17
17
  end
18
18
 
19
19
  def test_connection_failure
20
20
  assert_raise Mongo::ConnectionFailure do
21
- Mongo::Connection.new('localhost', 27347)
21
+ MongoClient.new('localhost', 27347)
22
22
  end
23
23
  end
24
24
 
25
- # def test_connection_timeout
26
- # passed = false
27
- # begin
28
- # t0 = Time.now
29
- # Mongo::Connection.new('foo.bar', 27017, :connect_timeout => 3)
30
- # rescue OperationTimeout
31
- # passed = true
32
- # t1 = Time.now
33
- # end
34
-
35
- # assert passed
36
- # assert t1 - t0 < 4
37
- # end
38
-
39
25
  def test_host_port_accessors
40
- assert_equal @conn.host, TEST_HOST
41
- assert_equal @conn.port, TEST_PORT
26
+ assert_equal @client.host, TEST_HOST
27
+ assert_equal @client.port, TEST_PORT
42
28
  end
43
29
 
44
30
  def test_server_info
45
- server_info = @conn.server_info
31
+ server_info = @client.server_info
46
32
  assert server_info.keys.include?("version")
47
33
  assert Mongo::Support.ok?(server_info)
48
34
  end
49
35
 
50
36
  def test_ping
51
- ping = @conn.ping
37
+ ping = @client.ping
52
38
  assert ping['ok']
53
39
  end
54
40
 
55
41
  def test_connection_uri
56
- con = Connection.from_uri("mongodb://#{host_port}")
42
+ con = MongoClient.from_uri("mongodb://#{host_port}")
57
43
  assert_equal mongo_host, con.primary_pool.host
58
44
  assert_equal mongo_port, con.primary_pool.port
59
45
  end
60
46
 
61
47
  def test_uri_with_extra_opts
62
- con = Connection.from_uri("mongodb://#{host_port}", :pool_size => 10, :slave_ok => true)
48
+ con = MongoClient.from_uri("mongodb://#{host_port}", :pool_size => 10, :slave_ok => true)
63
49
  assert_equal 10, con.pool_size
64
- assert_true con.slave_ok?
50
+ assert con.slave_ok?
65
51
  end
66
52
 
67
53
  def test_env_mongodb_uri
68
54
  begin
69
55
  old_mongodb_uri = ENV['MONGODB_URI']
70
56
  ENV['MONGODB_URI'] = "mongodb://#{host_port}"
71
- con = Connection.new
57
+ con = MongoClient.new
72
58
  assert_equal mongo_host, con.primary_pool.host
73
59
  assert_equal mongo_port, con.primary_pool.port
74
60
  ensure
@@ -80,7 +66,7 @@ class TestConnection < Test::Unit::TestCase
80
66
  begin
81
67
  old_mongodb_uri = ENV['MONGODB_URI']
82
68
  ENV['MONGODB_URI'] = "mongodb://#{host_port}"
83
- con = Connection.from_uri
69
+ con = MongoClient.from_uri
84
70
  assert_equal mongo_host, con.primary_pool.host
85
71
  assert_equal mongo_port, con.primary_pool.port
86
72
  ensure
@@ -94,7 +80,7 @@ class TestConnection < Test::Unit::TestCase
94
80
 
95
81
  old_mongodb_uri = ENV['MONGODB_URI']
96
82
  ENV['MONGODB_URI'] = "mongodb://#{host_port}/#{db_name}"
97
- con = Connection.from_uri
83
+ con = MongoClient.from_uri
98
84
  db = con.db
99
85
  assert_equal db.name, db_name
100
86
  ensure
@@ -108,7 +94,7 @@ class TestConnection < Test::Unit::TestCase
108
94
 
109
95
  old_mongodb_uri = ENV['MONGODB_URI']
110
96
  ENV['MONGODB_URI'] = "mongodb://#{host_port}/#{db_name}?"
111
- con = Connection.from_uri
97
+ con = MongoClient.from_uri
112
98
  db = con.db
113
99
  assert_equal db.name, db_name
114
100
  ensure
@@ -120,79 +106,79 @@ class TestConnection < Test::Unit::TestCase
120
106
  begin
121
107
  old_mongodb_uri = ENV['MONGODB_URI']
122
108
  ENV['MONGODB_URI'] = "mongodb://#{host_port}/"
123
- con = Connection.from_uri
109
+ con = MongoClient.from_uri
124
110
  db = con.db
125
- assert_equal db.name, Mongo::Connection::DEFAULT_DB_NAME
111
+ assert_equal db.name, Mongo::MongoClient::DEFAULT_DB_NAME
126
112
  ensure
127
113
  ENV['MONGODB_URI'] = old_mongodb_uri
128
114
  end
129
115
  end
130
116
 
131
117
  def test_server_version
132
- assert_match(/\d\.\d+(\.\d+)?/, @conn.server_version.to_s)
118
+ assert_match(/\d\.\d+(\.\d+)?/, @client.server_version.to_s)
133
119
  end
134
120
 
135
121
  def test_invalid_database_names
136
- assert_raise TypeError do @conn.db(4) end
122
+ assert_raise TypeError do @client.db(4) end
137
123
 
138
- assert_raise Mongo::InvalidNSName do @conn.db('') end
139
- assert_raise Mongo::InvalidNSName do @conn.db('te$t') end
140
- assert_raise Mongo::InvalidNSName do @conn.db('te.t') end
141
- assert_raise Mongo::InvalidNSName do @conn.db('te\\t') end
142
- assert_raise Mongo::InvalidNSName do @conn.db('te/t') end
143
- assert_raise Mongo::InvalidNSName do @conn.db('te st') end
124
+ assert_raise Mongo::InvalidNSName do @client.db('') end
125
+ assert_raise Mongo::InvalidNSName do @client.db('te$t') end
126
+ assert_raise Mongo::InvalidNSName do @client.db('te.t') end
127
+ assert_raise Mongo::InvalidNSName do @client.db('te\\t') end
128
+ assert_raise Mongo::InvalidNSName do @client.db('te/t') end
129
+ assert_raise Mongo::InvalidNSName do @client.db('te st') end
144
130
  end
145
131
 
146
132
  def test_options_passed_to_db
147
133
  @pk_mock = Object.new
148
- db = @conn.db('test', :pk => @pk_mock, :strict => true)
134
+ db = @client.db('test', :pk => @pk_mock, :strict => true)
149
135
  assert_equal @pk_mock, db.pk_factory
150
136
  assert db.strict?
151
137
  end
152
138
 
153
139
  def test_database_info
154
- @conn.drop_database(MONGO_TEST_DB)
155
- @conn.db(MONGO_TEST_DB).collection('info-test').insert('a' => 1)
140
+ @client.drop_database(MONGO_TEST_DB)
141
+ @client.db(MONGO_TEST_DB).collection('info-test').insert('a' => 1)
156
142
 
157
- info = @conn.database_info
143
+ info = @client.database_info
158
144
  assert_not_nil info
159
145
  assert_kind_of Hash, info
160
146
  assert_not_nil info[MONGO_TEST_DB]
161
147
  assert info[MONGO_TEST_DB] > 0
162
148
 
163
- @conn.drop_database(MONGO_TEST_DB)
149
+ @client.drop_database(MONGO_TEST_DB)
164
150
  end
165
151
 
166
152
  def test_copy_database
167
- @conn.db('old').collection('copy-test').insert('a' => 1)
168
- @conn.copy_database('old', 'new', host_port)
169
- old_object = @conn.db('old').collection('copy-test').find.next_document
170
- new_object = @conn.db('new').collection('copy-test').find.next_document
153
+ @client.db('old').collection('copy-test').insert('a' => 1)
154
+ @client.copy_database('old', 'new', host_port)
155
+ old_object = @client.db('old').collection('copy-test').find.next_document
156
+ new_object = @client.db('new').collection('copy-test').find.next_document
171
157
  assert_equal old_object, new_object
172
- @conn.drop_database('old')
173
- @conn.drop_database('new')
158
+ @client.drop_database('old')
159
+ @client.drop_database('new')
174
160
  end
175
161
 
176
162
  def test_copy_database_with_auth
177
- @conn.db('old').collection('copy-test').insert('a' => 1)
178
- @conn.db('old').add_user('bob', 'secret')
163
+ @client.db('old').collection('copy-test').insert('a' => 1)
164
+ @client.db('old').add_user('bob', 'secret')
179
165
 
180
166
  assert_raise Mongo::OperationFailure do
181
- @conn.copy_database('old', 'new', host_port, 'bob', 'badpassword')
167
+ @client.copy_database('old', 'new', host_port, 'bob', 'badpassword')
182
168
  end
183
169
 
184
- result = @conn.copy_database('old', 'new', host_port, 'bob', 'secret')
170
+ result = @client.copy_database('old', 'new', host_port, 'bob', 'secret')
185
171
  assert Mongo::Support.ok?(result)
186
172
 
187
- @conn.drop_database('old')
188
- @conn.drop_database('new')
173
+ @client.drop_database('old')
174
+ @client.drop_database('new')
189
175
  end
190
176
 
191
177
  def test_database_names
192
- @conn.drop_database(MONGO_TEST_DB)
193
- @conn.db(MONGO_TEST_DB).collection('info-test').insert('a' => 1)
178
+ @client.drop_database(MONGO_TEST_DB)
179
+ @client.db(MONGO_TEST_DB).collection('info-test').insert('a' => 1)
194
180
 
195
- names = @conn.database_names
181
+ names = @client.database_names
196
182
  assert_not_nil names
197
183
  assert_kind_of Array, names
198
184
  assert names.length >= 1
@@ -212,7 +198,7 @@ class TestConnection < Test::Unit::TestCase
212
198
  logger = Logger.new(output)
213
199
  logger.level = Logger::DEBUG
214
200
  standard_connection(:logger => logger).db(MONGO_TEST_DB)
215
- assert_match(/\(\d+ms\)/, output.string)
201
+ assert_match(/\(\d+.\d{1}ms\)/, output.string)
216
202
  assert output.string.include?("admin['$cmd'].find")
217
203
  end
218
204
 
@@ -228,37 +214,37 @@ class TestConnection < Test::Unit::TestCase
228
214
  end
229
215
 
230
216
  def test_drop_database
231
- db = @conn.db('ruby-mongo-will-be-deleted')
217
+ db = @client.db('ruby-mongo-will-be-deleted')
232
218
  coll = db.collection('temp')
233
219
  coll.remove
234
220
  coll.insert(:name => 'temp')
235
221
  assert_equal 1, coll.count()
236
- assert @conn.database_names.include?('ruby-mongo-will-be-deleted')
222
+ assert @client.database_names.include?('ruby-mongo-will-be-deleted')
237
223
 
238
- @conn.drop_database('ruby-mongo-will-be-deleted')
239
- assert !@conn.database_names.include?('ruby-mongo-will-be-deleted')
224
+ @client.drop_database('ruby-mongo-will-be-deleted')
225
+ assert !@client.database_names.include?('ruby-mongo-will-be-deleted')
240
226
  end
241
227
 
242
228
  def test_nodes
243
229
  silently do
244
- @conn = Connection.multi([['foo', 27017], ['bar', 27018]], :connect => false)
230
+ @client = MongoClient.multi([['foo', 27017], ['bar', 27018]], :connect => false)
245
231
  end
246
- seeds = @conn.seeds
232
+ seeds = @client.seeds
247
233
  assert_equal 2, seeds.length
248
234
  assert_equal ['foo', 27017], seeds[0]
249
235
  assert_equal ['bar', 27018], seeds[1]
250
236
  end
251
237
 
252
238
  def test_fsync_lock
253
- assert !@conn.locked?
254
- @conn.lock!
255
- assert @conn.locked?
256
- assert [1, true].include?(@conn['admin']['$cmd.sys.inprog'].find_one['fsyncLock'])
257
- assert_match(/unlock/, @conn.unlock!['info'])
239
+ assert !@client.locked?
240
+ @client.lock!
241
+ assert @client.locked?
242
+ assert [1, true].include?(@client['admin']['$cmd.sys.inprog'].find_one['fsyncLock'])
243
+ assert_match(/unlock/, @client.unlock!['info'])
258
244
  unlocked = false
259
245
  counter = 0
260
246
  while counter < 5
261
- if @conn['admin']['$cmd.sys.inprog'].find_one['fsyncLock'].nil?
247
+ if @client['admin']['$cmd.sys.inprog'].find_one['fsyncLock'].nil?
262
248
  unlocked = true
263
249
  break
264
250
  else
@@ -266,7 +252,7 @@ class TestConnection < Test::Unit::TestCase
266
252
  counter += 1
267
253
  end
268
254
  end
269
- assert !@conn.locked?
255
+ assert !@client.locked?
270
256
  assert unlocked, "mongod failed to unlock"
271
257
  end
272
258
 
@@ -287,7 +273,7 @@ class TestConnection < Test::Unit::TestCase
287
273
  conn.connect
288
274
  doc = {'n' => 'a' * (conn.max_bson_size)}
289
275
  assert_raise InvalidDocument do
290
- assert BSON::BSON_CODER.serialize(doc, false, true, @conn.max_bson_size)
276
+ assert BSON::BSON_CODER.serialize(doc, false, true, @client.max_bson_size)
291
277
  end
292
278
  end
293
279
 
@@ -316,7 +302,7 @@ class TestConnection < Test::Unit::TestCase
316
302
  dropped_socket.stub_everything
317
303
 
318
304
  conn.primary_pool.host = 'localhost'
319
- conn.primary_pool.port = Mongo::Connection::DEFAULT_PORT
305
+ conn.primary_pool.port = Mongo::MongoClient::DEFAULT_PORT
320
306
  conn.primary_pool.instance_variable_set("@pids", {dropped_socket => Process.pid})
321
307
  conn.primary_pool.instance_variable_set("@sockets", [dropped_socket])
322
308
 
@@ -325,37 +311,37 @@ class TestConnection < Test::Unit::TestCase
325
311
 
326
312
  context "Saved authentications" do
327
313
  setup do
328
- @conn = standard_connection
314
+ @client = standard_connection
329
315
  @auth = {'db_name' => 'test', 'username' => 'bob', 'password' => 'secret'}
330
- @conn.add_auth(@auth['db_name'], @auth['username'], @auth['password'])
316
+ @client.add_auth(@auth['db_name'], @auth['username'], @auth['password'])
331
317
  end
332
318
 
333
319
  teardown do
334
- @conn.clear_auths
320
+ @client.clear_auths
335
321
  end
336
322
 
337
323
  should "save the authentication" do
338
- assert_equal @auth, @conn.auths[0]
324
+ assert_equal @auth, @client.auths[0]
339
325
  end
340
326
 
341
327
  should "replace the auth if given a new auth for the same db" do
342
328
  auth = {'db_name' => 'test', 'username' => 'mickey', 'password' => 'm0u53'}
343
- @conn.add_auth(auth['db_name'], auth['username'], auth['password'])
344
- assert_equal 1, @conn.auths.length
345
- assert_equal auth, @conn.auths[0]
329
+ @client.add_auth(auth['db_name'], auth['username'], auth['password'])
330
+ assert_equal 1, @client.auths.length
331
+ assert_equal auth, @client.auths[0]
346
332
  end
347
333
 
348
334
  should "remove auths by database" do
349
- @conn.remove_auth('non-existent database')
350
- assert_equal 1, @conn.auths.length
335
+ @client.remove_auth('non-existent database')
336
+ assert_equal 1, @client.auths.length
351
337
 
352
- @conn.remove_auth('test')
353
- assert_equal 0, @conn.auths.length
338
+ @client.remove_auth('test')
339
+ assert_equal 0, @client.auths.length
354
340
  end
355
341
 
356
342
  should "remove all auths" do
357
- @conn.clear_auths
358
- assert_equal 0, @conn.auths.length
343
+ @client.clear_auths
344
+ assert_equal 0, @client.auths.length
359
345
  end
360
346
  end
361
347
 
@@ -375,7 +361,7 @@ class TestConnection < Test::Unit::TestCase
375
361
  end
376
362
  end
377
363
 
378
- should "close the connection on send_message_with_safe_check for major exceptions" do
364
+ should "close the connection on send_message_with_gle for major exceptions" do
379
365
  @con.expects(:checkout_writer).raises(SystemStackError)
380
366
  @con.expects(:close)
381
367
  begin