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
data/lib/mongo.rb CHANGED
@@ -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
  module Mongo
2
16
  ASCENDING = 1
3
17
  DESCENDING = -1
@@ -36,45 +50,49 @@ module Mongo
36
50
  OP_QUERY_NO_CURSOR_TIMEOUT = 2 ** 4
37
51
  OP_QUERY_AWAIT_DATA = 2 ** 5
38
52
  OP_QUERY_EXHAUST = 2 ** 6
53
+ OP_QUERY_PARTIAL = 2 ** 7
39
54
 
40
55
  REPLY_CURSOR_NOT_FOUND = 2 ** 0
41
56
  REPLY_QUERY_FAILURE = 2 ** 1
42
57
  REPLY_SHARD_CONFIG_STALE = 2 ** 2
43
58
  REPLY_AWAIT_CAPABLE = 2 ** 3
44
59
  end
60
+
61
+ module ErrorCode # MongoDB Core Server src/mongo/base/error_codes.err
62
+ BAD_VALUE = 2
63
+ UNKNOWN_ERROR = 8
64
+ INVALID_BSON = 22
65
+ WRITE_CONCERN_FAILED = 64
66
+ MULTIPLE_ERRORS_OCCURRED = 65
67
+ UNAUTHORIZED = 13
68
+
69
+ # mongod/s 2.6 and above return code 59 when a command doesn't exist.
70
+ # mongod versions previous to 2.6 and mongos 2.4.x return no error code
71
+ # when a command does exist.
72
+ # mongos versions previous to 2.4.0 return code 13390 when a command
73
+ # does not exist.
74
+ COMMAND_NOT_FOUND_CODES = [nil, 59, 13390]
75
+ end
45
76
  end
46
77
 
47
78
  require 'bson'
48
79
 
49
- require 'mongo/util/thread_local_variable_manager'
50
- require 'mongo/util/conversions'
51
- require 'mongo/util/support'
52
- require 'mongo/util/read_preference'
53
- require 'mongo/util/write_concern'
54
- require 'mongo/util/core_ext'
55
- require 'mongo/util/logging'
56
- require 'mongo/util/node'
57
- require 'mongo/util/pool'
58
- require 'mongo/util/pool_manager'
59
- require 'mongo/util/sharding_pool_manager'
60
- require 'mongo/util/server_version'
61
- require 'mongo/util/socket_util'
62
- require 'mongo/util/ssl_socket'
63
- require 'mongo/util/tcp_socket'
64
- require 'mongo/util/unix_socket'
65
- require 'mongo/util/uri_parser'
66
-
80
+ require 'set'
81
+ require 'thread'
82
+ require 'monitor'
67
83
 
84
+ require 'mongo/utils'
85
+ require 'mongo/exception'
86
+ require 'mongo/functional'
87
+ require 'mongo/connection'
88
+ require 'mongo/collection_writer'
89
+ require 'mongo/collection'
90
+ require 'mongo/bulk_write_collection_view'
91
+ require 'mongo/cursor'
92
+ require 'mongo/db'
93
+ require 'mongo/gridfs'
68
94
  require 'mongo/networking'
69
95
  require 'mongo/mongo_client'
70
96
  require 'mongo/mongo_replica_set_client'
71
97
  require 'mongo/mongo_sharded_client'
72
98
  require 'mongo/legacy'
73
- require 'mongo/collection'
74
- require 'mongo/cursor'
75
- require 'mongo/db'
76
- require 'mongo/exceptions'
77
- require 'mongo/gridfs/grid_ext'
78
- require 'mongo/gridfs/grid'
79
- require 'mongo/gridfs/grid_io'
80
- require 'mongo/gridfs/grid_file_system'
data/mongo.gemspec CHANGED
@@ -3,7 +3,7 @@ Gem::Specification.new do |s|
3
3
 
4
4
  s.version = File.read(File.join(File.dirname(__FILE__), 'VERSION'))
5
5
  s.platform = Gem::Platform::RUBY
6
- s.authors = ['Tyler Brock', 'Gary Murakami', 'Emily Stolfo', 'Brandon Black', 'Durran Jordan']
6
+ s.authors = ['Emily Stolfo', 'Durran Jordan', 'Gary Murakami', 'Tyler Brock', 'Brandon Black']
7
7
  s.email = 'mongodb-dev@googlegroups.com'
8
8
  s.homepage = 'http://www.mongodb.org'
9
9
  s.summary = 'Ruby driver for MongoDB'
@@ -27,5 +27,5 @@ Gem::Specification.new do |s|
27
27
  s.require_paths = ['lib']
28
28
  s.has_rdoc = 'yard'
29
29
 
30
- s.add_dependency('bson', "~> #{s.version}")
30
+ s.add_dependency('bson', "#{s.version}")
31
31
  end
@@ -1,18 +1,39 @@
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 'shared/authentication'
16
+ require 'shared/authentication/basic_auth_shared'
17
+ require 'shared/authentication/sasl_plain_shared'
18
+ require 'shared/authentication/bulk_api_auth_shared'
19
+ require 'shared/authentication/gssapi_shared'
20
+ require 'shared/authentication/scram_shared'
21
+
3
22
 
4
23
  class AuthenticationTest < Test::Unit::TestCase
5
24
  include Mongo
6
- include AuthenticationTests
25
+ include BasicAuthTests
26
+ include SASLPlainTests
27
+ include BulkAPIAuthTests
28
+ include GSSAPITests
29
+ include SCRAMTests
7
30
 
8
31
  def setup
9
- @client = MongoClient.new
10
- @db = @client[MONGO_TEST_DB]
11
- init_auth
12
- end
13
-
14
- def test_authenticate_with_connection_uri
15
- @db.add_user('eunice', 'uritest')
16
- assert MongoClient.from_uri("mongodb://eunice:uritest@#{host_port}/#{@db.name}")
32
+ @client = standard_connection
33
+ omit("auth not enabled on mongod") unless auth_enabled?(@client)
34
+ @admin = @client['admin']
35
+ @version = @client.server_version
36
+ @db = @client['ruby-test']
37
+ @host_info = host_port
17
38
  end
18
39
  end
@@ -0,0 +1,133 @@
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
+ class BulkApiStressTest < Test::Unit::TestCase
18
+
19
+ # Generate a large string of 'size' MB (estimated
20
+ # by a string of 'size' * 1024 * 1024 characters).
21
+ def generate_large_string(size)
22
+ s = "a" * (size * 1024 * 1024)
23
+ end
24
+
25
+ def setup
26
+ @client = standard_connection
27
+ @db = @client[TEST_DB]
28
+ @coll = @db["bulk-api-stress-tests"]
29
+ @coll.remove
30
+ end
31
+
32
+ def test_ordered_batch_large_inserts
33
+ bulk = @coll.initialize_ordered_bulk_op
34
+ s = generate_large_string(4)
35
+
36
+ for i in 0..5
37
+ bulk.insert({:_id => i, :msg => s})
38
+ end
39
+ bulk.insert({:_id => 3}) # error
40
+ bulk.insert({:_id => 100})
41
+
42
+ ex = assert_raise BulkWriteError do
43
+ bulk.execute
44
+ end
45
+
46
+ error_details = ex.result
47
+ assert_equal 6, error_details["nInserted"]
48
+ assert_equal 1, error_details["writeErrors"].length
49
+ error = error_details["writeErrors"][0]
50
+ assert_equal 11000, error["code"] # duplicate key error
51
+ assert error["errmsg"].kind_of? String
52
+ assert_equal 6, error["index"]
53
+ assert_equal 6, @coll.count()
54
+ end
55
+
56
+ def test_unordered_batch_large_inserts
57
+ bulk = @coll.initialize_unordered_bulk_op
58
+ s = generate_large_string(4)
59
+
60
+ for i in 0..5
61
+ bulk.insert({:_id => i, :msg => s})
62
+ end
63
+ bulk.insert({:_id => 3}) # error
64
+ bulk.insert({:_id => 100})
65
+
66
+ ex = assert_raise BulkWriteError do
67
+ bulk.execute
68
+ end
69
+
70
+ error_details = ex.result
71
+ assert_equal 7, error_details["nInserted"]
72
+ assert_equal 1, error_details["writeErrors"].length
73
+ error = error_details["writeErrors"][0]
74
+ assert_equal 11000, error["code"] # duplicate key error
75
+ assert error["errmsg"].kind_of? String
76
+ assert_equal 6, error["index"]
77
+ assert_equal 7, @coll.count()
78
+ end
79
+
80
+ def test_large_single_insert
81
+ bulk = @coll.initialize_unordered_bulk_op
82
+ s = generate_large_string(17)
83
+ bulk.insert({:a => s})
84
+ # RUBY-730:
85
+ # ex = assert_raise BulkWriteError do
86
+ # bulk.execute
87
+ # end
88
+ end
89
+
90
+ def test_ordered_batch_large_batch
91
+ bulk = @coll.initialize_ordered_bulk_op
92
+
93
+ bulk.insert({:_id => 1600})
94
+ for i in 0..2000
95
+ bulk.insert({:_id => i})
96
+ end
97
+
98
+ ex = assert_raise BulkWriteError do
99
+ bulk.execute
100
+ end
101
+
102
+ error_details = ex.result
103
+ assert_equal 1601, error_details["nInserted"]
104
+ assert_equal 1, error_details["writeErrors"].length
105
+ error = error_details["writeErrors"][0]
106
+ assert_equal 11000, error["code"] # duplicate key error
107
+ assert error["errmsg"].kind_of? String
108
+ assert_equal 1601, error["index"]
109
+ assert_equal 1601, @coll.count()
110
+ end
111
+
112
+ def test_unordered_batch_large_batch
113
+ bulk = @coll.initialize_unordered_bulk_op
114
+
115
+ bulk.insert({:_id => 1600})
116
+ for i in 0..2000
117
+ bulk.insert({:_id => i})
118
+ end
119
+
120
+ ex = assert_raise BulkWriteError do
121
+ bulk.execute
122
+ end
123
+
124
+ error_details = ex.result
125
+ assert_equal 2001, error_details["nInserted"]
126
+ assert_equal 1, error_details["writeErrors"].length
127
+ error = error_details["writeErrors"][0]
128
+ assert_equal 11000, error["code"] # duplicate key error
129
+ assert error["errmsg"].kind_of? String
130
+ assert_equal 1601, error["index"]
131
+ assert_equal 2001, @coll.count()
132
+ end
133
+ end