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
@@ -0,0 +1,83 @@
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
+ require 'test_helper'
16
+
17
+ module Mongo
18
+ class Collection
19
+ public :batch_write
20
+ end
21
+ class CollectionWriter
22
+ public :sort_by_first_sym, :ordered_group_by_first
23
+ end
24
+ end
25
+
26
+ class CollectionWriterTest < Test::Unit::TestCase
27
+
28
+ DATABASE_NAME = 'ruby_test_collection_writer'
29
+ COLLECTION_NAME = 'test'
30
+
31
+ def default_setup
32
+ @client = MongoClient.from_uri(TEST_URI)
33
+ @db = @client[DATABASE_NAME]
34
+ @collection = @db[COLLECTION_NAME]
35
+ @collection.drop
36
+ end
37
+
38
+ context "Bulk API Execute" do
39
+ setup do
40
+ default_setup
41
+ end
42
+
43
+ should "sort_by_first_sym for grouping unordered ops" do
44
+ pairs = [
45
+ [:insert, {:n => 0}],
46
+ [:update, {:n => 1}], [:update, {:n => 2}],
47
+ [:delete, {:n => 3}],
48
+ [:insert, {:n => 5}], [:insert, {:n => 6}], [:insert, {:n => 7}],
49
+ [:update, {:n => 8}],
50
+ [:delete, {:n => 9}], [:delete, {:n => 10}]
51
+ ]
52
+ result = @collection.command_writer.sort_by_first_sym(pairs)
53
+ expected = [
54
+ :delete, :delete, :delete,
55
+ :insert, :insert, :insert, :insert,
56
+ :update, :update, :update
57
+ ]
58
+ assert_equal expected, result.collect{|first, rest| first}
59
+ end
60
+
61
+ should "calculate ordered_group_by_first" do
62
+ pairs = [
63
+ [:insert, {:n => 0}],
64
+ [:update, {:n => 1}], [:update, {:n => 2}],
65
+ [:delete, {:n => 3}],
66
+ [:insert, {:n => 5}], [:insert, {:n => 6}], [:insert, {:n => 7}],
67
+ [:update, {:n => 8}],
68
+ [:delete, {:n => 9}], [:delete, {:n => 10}]
69
+ ]
70
+ result = @collection.command_writer.ordered_group_by_first(pairs)
71
+ expected = [
72
+ [:insert, [{:n => 0}]],
73
+ [:update, [{:n => 1}, {:n => 2}]],
74
+ [:delete, [{:n => 3}]],
75
+ [:insert, [{:n => 5}, {:n => 6}, {:n => 7}]],
76
+ [:update, [{:n => 8}]],
77
+ [:delete, [{:n => 9}, {:n => 10}]]
78
+ ]
79
+ assert_equal expected, result
80
+ end
81
+
82
+ end
83
+ end
@@ -1,6 +1,18 @@
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
- require 'mongo/exceptions'
3
- require 'mongo/util/conversions'
4
16
 
5
17
  class ConversionsTest < Test::Unit::TestCase
6
18
  include Mongo::Conversions
@@ -15,6 +27,34 @@ class ConversionsTest < Test::Unit::TestCase
15
27
  assert_equal({ "field1" => 1, "field2" => -1 }, params)
16
28
  end
17
29
 
30
+ def test_array_as_sort_parameters_with_array_of_key_and_hash
31
+ params = array_as_sort_parameters(["score", {"$meta" => "textScore"}])
32
+ assert_equal({"score" => {"$meta" => "textScore"}}, params)
33
+ end
34
+
35
+ def test_array_as_sort_parameters_with_array_of_key_and_hashes
36
+ params = array_as_sort_parameters([["field1", :asc],["score", {"$meta" => "textScore"}]])
37
+ assert_equal({"field1" => 1, "score" => {"$meta" => "textScore"}}, params)
38
+ end
39
+
40
+ def test_hash_as_sort_parameters_with_string
41
+ sort = BSON::OrderedHash["field", "asc"]
42
+ params = hash_as_sort_parameters(sort)
43
+ assert_equal({"field" => 1}, params)
44
+ end
45
+
46
+ def test_hash_as_sort_parameters_with_hash
47
+ sort = BSON::OrderedHash["score", {"$meta" => "textScore"}]
48
+ params = hash_as_sort_parameters(sort)
49
+ assert_equal({"score" => {"$meta" => "textScore"}}, params)
50
+ end
51
+
52
+ def test_hash_as_sort_parameters_with_hash_and_string
53
+ sort = BSON::OrderedHash["score", {"$meta" => "textScore"}, "field", "asc"]
54
+ params = hash_as_sort_parameters(sort)
55
+ assert_equal({ "score" => {"$meta" => "textScore"}, "field" => 1 }, params)
56
+ end
57
+
18
58
  def test_string_as_sort_parameters_with_string
19
59
  params = string_as_sort_parameters("field")
20
60
  assert_equal({ "field" => 1 }, params)
@@ -110,6 +150,10 @@ class ConversionsTest < Test::Unit::TestCase
110
150
  assert_equal(-1, sort_value(:DESC))
111
151
  end
112
152
 
153
+ def test_sort_value_when_value_is_hash
154
+ assert_equal({"$meta" => "textScore"}, sort_value("$meta" => "textScore"))
155
+ end
156
+
113
157
  def test_sort_value_when_value_is_invalid
114
158
  assert_raise Mongo::InvalidSortValueError do
115
159
  sort_value(2)
@@ -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
  require 'logger'
3
17
 
@@ -5,19 +19,13 @@ class CursorFailTest < Test::Unit::TestCase
5
19
 
6
20
  include Mongo
7
21
 
8
- @@connection = standard_connection
9
- @@db = @@connection.db(MONGO_TEST_DB)
10
- @@coll = @@db.collection('test')
11
- @@version = @@connection.server_version
12
-
13
22
  def setup
14
- @@coll.remove({})
15
- @@coll.insert({'a' => 1}) # collection not created until it's used
16
- @@coll_full_name = "#{MONGO_TEST_DB}.test"
23
+ @connection = standard_connection
24
+ @db = @connection[TEST_DB]
17
25
  end
18
26
 
19
27
  def test_refill_via_get_more_alt_coll
20
- coll = @@db.collection('test-alt-coll')
28
+ coll = @db.collection('test-alt-coll')
21
29
  coll.remove
22
30
  coll.insert('a' => 1) # collection not created until it's used
23
31
  assert_equal 1, coll.count
@@ -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
  require 'logger'
3
17
 
@@ -5,39 +19,38 @@ class CursorMessageTest < Test::Unit::TestCase
5
19
 
6
20
  include Mongo
7
21
 
8
- @@connection = standard_connection
9
- @@db = @@connection.db(MONGO_TEST_DB)
10
- @@coll = @@db.collection('test')
11
- @@version = @@connection.server_version
12
-
13
22
  def setup
14
- @@coll.remove
15
- @@coll.insert('a' => 1) # collection not created until it's used
16
- @@coll_full_name = "#{MONGO_TEST_DB}.test"
23
+ @connection = standard_connection
24
+ @db = @connection.db(TEST_DB)
25
+ @coll = @db.collection('test')
26
+ @version = @connection.server_version
27
+ @coll.remove
28
+ @coll.insert('a' => 1) # collection not created until it's used
29
+ @coll_full_name = "#{TEST_DB}.test"
17
30
  end
18
31
 
19
32
  def test_valid_batch_sizes
20
33
  assert_raise ArgumentError do
21
- @@coll.find({}, :batch_size => 1, :limit => 5)
34
+ @coll.find({}, :batch_size => 1, :limit => 5)
22
35
  end
23
36
 
24
37
  assert_raise ArgumentError do
25
- @@coll.find({}, :batch_size => -1, :limit => 5)
38
+ @coll.find({}, :batch_size => -1, :limit => 5)
26
39
  end
27
40
 
28
- assert @@coll.find({}, :batch_size => 0, :limit => 5)
41
+ assert @coll.find({}, :batch_size => 0, :limit => 5)
29
42
  end
30
43
 
31
44
  def test_batch_size
32
- @@coll.remove
45
+ @coll.remove
33
46
  200.times do |n|
34
- @@coll.insert({:a => n})
47
+ @coll.insert({:a => n})
35
48
  end
36
49
 
37
- list = @@coll.find({}, :batch_size => 2, :limit => 6).to_a
50
+ list = @coll.find({}, :batch_size => 2, :limit => 6).to_a
38
51
  assert_equal 6, list.length
39
52
 
40
- list = @@coll.find({}, :batch_size => 100, :limit => 101).to_a
53
+ list = @coll.find({}, :batch_size => 100, :limit => 101).to_a
41
54
  assert_equal 101, list.length
42
55
  end
43
56
  end