mongo 1.3.0 → 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 (185) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/{LICENSE.txt → LICENSE} +1 -1
  4. data/README.md +122 -271
  5. data/Rakefile +25 -209
  6. data/VERSION +1 -0
  7. data/bin/mongo_console +31 -9
  8. data/lib/mongo/bulk_write_collection_view.rb +387 -0
  9. data/lib/mongo/collection.rb +576 -269
  10. data/lib/mongo/collection_writer.rb +364 -0
  11. data/lib/mongo/connection/node.rb +249 -0
  12. data/lib/mongo/connection/pool.rb +340 -0
  13. data/lib/mongo/connection/pool_manager.rb +320 -0
  14. data/lib/mongo/connection/sharding_pool_manager.rb +67 -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 +7 -875
  21. data/lib/mongo/cursor.rb +403 -117
  22. data/lib/mongo/db.rb +444 -243
  23. data/lib/mongo/exception.rb +145 -0
  24. data/lib/mongo/functional/authentication.rb +455 -0
  25. data/lib/mongo/functional/logging.rb +85 -0
  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/functional/write_concern.rb +66 -0
  30. data/lib/mongo/functional.rb +20 -0
  31. data/lib/mongo/gridfs/grid.rb +30 -24
  32. data/lib/mongo/gridfs/grid_ext.rb +6 -10
  33. data/lib/mongo/gridfs/grid_file_system.rb +38 -20
  34. data/lib/mongo/gridfs/grid_io.rb +84 -75
  35. data/lib/mongo/gridfs.rb +18 -0
  36. data/lib/mongo/legacy.rb +140 -0
  37. data/lib/mongo/mongo_client.rb +697 -0
  38. data/lib/mongo/mongo_replica_set_client.rb +535 -0
  39. data/lib/mongo/mongo_sharded_client.rb +159 -0
  40. data/lib/mongo/networking.rb +372 -0
  41. data/lib/mongo/{util → utils}/conversions.rb +29 -8
  42. data/lib/mongo/{util → utils}/core_ext.rb +28 -18
  43. data/lib/mongo/{util → utils}/server_version.rb +4 -6
  44. data/lib/mongo/{util → utils}/support.rb +29 -31
  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 +51 -50
  48. data/mongo.gemspec +29 -32
  49. data/test/functional/authentication_test.rb +39 -0
  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 +2175 -0
  54. data/test/functional/collection_writer_test.rb +83 -0
  55. data/test/{conversions_test.rb → functional/conversions_test.rb} +47 -3
  56. data/test/functional/cursor_fail_test.rb +57 -0
  57. data/test/functional/cursor_message_test.rb +56 -0
  58. data/test/functional/cursor_test.rb +683 -0
  59. data/test/functional/db_api_test.rb +835 -0
  60. data/test/functional/db_connection_test.rb +25 -0
  61. data/test/functional/db_test.rb +348 -0
  62. data/test/functional/grid_file_system_test.rb +285 -0
  63. data/test/{grid_io_test.rb → functional/grid_io_test.rb} +72 -11
  64. data/test/{grid_test.rb → functional/grid_test.rb} +88 -15
  65. data/test/functional/pool_test.rb +136 -0
  66. data/test/functional/safe_test.rb +98 -0
  67. data/test/functional/ssl_test.rb +29 -0
  68. data/test/functional/support_test.rb +62 -0
  69. data/test/functional/timeout_test.rb +60 -0
  70. data/test/functional/uri_test.rb +446 -0
  71. data/test/functional/write_concern_test.rb +118 -0
  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 +37 -0
  75. data/test/replica_set/basic_test.rb +189 -0
  76. data/test/replica_set/client_test.rb +393 -0
  77. data/test/replica_set/connection_test.rb +138 -0
  78. data/test/replica_set/count_test.rb +66 -0
  79. data/test/replica_set/cursor_test.rb +220 -0
  80. data/test/replica_set/insert_test.rb +157 -0
  81. data/test/replica_set/max_values_test.rb +151 -0
  82. data/test/replica_set/pinning_test.rb +105 -0
  83. data/test/replica_set/query_test.rb +73 -0
  84. data/test/replica_set/read_preference_test.rb +219 -0
  85. data/test/replica_set/refresh_test.rb +211 -0
  86. data/test/replica_set/replication_ack_test.rb +95 -0
  87. data/test/replica_set/ssl_test.rb +32 -0
  88. data/test/sharded_cluster/basic_test.rb +203 -0
  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 +53 -94
  96. data/test/threading/basic_test.rb +120 -0
  97. data/test/tools/mongo_config.rb +708 -0
  98. data/test/tools/mongo_config_test.rb +160 -0
  99. data/test/unit/client_test.rb +381 -0
  100. data/test/unit/collection_test.rb +89 -53
  101. data/test/unit/connection_test.rb +282 -32
  102. data/test/unit/cursor_test.rb +206 -8
  103. data/test/unit/db_test.rb +55 -13
  104. data/test/unit/grid_test.rb +43 -16
  105. data/test/unit/mongo_sharded_client_test.rb +48 -0
  106. data/test/unit/node_test.rb +93 -0
  107. data/test/unit/pool_manager_test.rb +111 -0
  108. data/test/unit/read_pref_test.rb +406 -0
  109. data/test/unit/read_test.rb +159 -0
  110. data/test/unit/safe_test.rb +69 -36
  111. data/test/unit/sharding_pool_manager_test.rb +84 -0
  112. data/test/unit/write_concern_test.rb +175 -0
  113. data.tar.gz.sig +3 -0
  114. metadata +227 -216
  115. metadata.gz.sig +0 -0
  116. data/docs/CREDITS.md +0 -123
  117. data/docs/FAQ.md +0 -116
  118. data/docs/GridFS.md +0 -158
  119. data/docs/HISTORY.md +0 -244
  120. data/docs/RELEASES.md +0 -33
  121. data/docs/REPLICA_SETS.md +0 -72
  122. data/docs/TUTORIAL.md +0 -247
  123. data/docs/WRITE_CONCERN.md +0 -28
  124. data/lib/mongo/exceptions.rb +0 -71
  125. data/lib/mongo/gridfs/grid_io_fix.rb +0 -38
  126. data/lib/mongo/repl_set_connection.rb +0 -342
  127. data/lib/mongo/test.rb +0 -20
  128. data/lib/mongo/util/pool.rb +0 -177
  129. data/lib/mongo/util/uri_parser.rb +0 -185
  130. data/test/async/collection_test.rb +0 -224
  131. data/test/async/connection_test.rb +0 -24
  132. data/test/async/cursor_test.rb +0 -162
  133. data/test/async/worker_pool_test.rb +0 -99
  134. data/test/auxillary/1.4_features.rb +0 -166
  135. data/test/auxillary/authentication_test.rb +0 -68
  136. data/test/auxillary/autoreconnect_test.rb +0 -41
  137. data/test/auxillary/fork_test.rb +0 -30
  138. data/test/auxillary/repl_set_auth_test.rb +0 -58
  139. data/test/auxillary/slave_connection_test.rb +0 -36
  140. data/test/auxillary/threaded_authentication_test.rb +0 -101
  141. data/test/bson/binary_test.rb +0 -15
  142. data/test/bson/bson_test.rb +0 -649
  143. data/test/bson/byte_buffer_test.rb +0 -208
  144. data/test/bson/hash_with_indifferent_access_test.rb +0 -38
  145. data/test/bson/json_test.rb +0 -17
  146. data/test/bson/object_id_test.rb +0 -154
  147. data/test/bson/ordered_hash_test.rb +0 -204
  148. data/test/bson/timestamp_test.rb +0 -24
  149. data/test/collection_test.rb +0 -910
  150. data/test/connection_test.rb +0 -309
  151. data/test/cursor_fail_test.rb +0 -75
  152. data/test/cursor_message_test.rb +0 -43
  153. data/test/cursor_test.rb +0 -483
  154. data/test/db_api_test.rb +0 -726
  155. data/test/db_connection_test.rb +0 -15
  156. data/test/db_test.rb +0 -287
  157. data/test/grid_file_system_test.rb +0 -243
  158. data/test/load/resque/load.rb +0 -21
  159. data/test/load/resque/processor.rb +0 -26
  160. data/test/load/thin/load.rb +0 -24
  161. data/test/load/unicorn/load.rb +0 -23
  162. data/test/load/unicorn/unicorn.rb +0 -29
  163. data/test/replica_sets/connect_test.rb +0 -94
  164. data/test/replica_sets/connection_string_test.rb +0 -32
  165. data/test/replica_sets/count_test.rb +0 -35
  166. data/test/replica_sets/insert_test.rb +0 -53
  167. data/test/replica_sets/pooled_insert_test.rb +0 -55
  168. data/test/replica_sets/query_secondaries.rb +0 -96
  169. data/test/replica_sets/query_test.rb +0 -51
  170. data/test/replica_sets/replication_ack_test.rb +0 -66
  171. data/test/replica_sets/rs_test_helper.rb +0 -27
  172. data/test/safe_test.rb +0 -68
  173. data/test/support/hash_with_indifferent_access.rb +0 -186
  174. data/test/support/keys.rb +0 -45
  175. data/test/support_test.rb +0 -18
  176. data/test/threading/threading_with_large_pool_test.rb +0 -90
  177. data/test/threading_test.rb +0 -87
  178. data/test/tools/auth_repl_set_manager.rb +0 -14
  179. data/test/tools/load.rb +0 -58
  180. data/test/tools/repl_set_manager.rb +0 -266
  181. data/test/tools/sharding_manager.rb +0 -202
  182. data/test/tools/test.rb +0 -4
  183. data/test/unit/pool_test.rb +0 -9
  184. data/test/unit/repl_set_connection_test.rb +0 -59
  185. data/test/uri_test.rb +0 -91
data/test/test_helper.rb CHANGED
@@ -1,102 +1,61 @@
1
- $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- require 'rubygems' if RUBY_VERSION < '1.9.0' && ENV['C_EXT']
3
- require 'mongo'
4
- require 'test/unit'
5
-
6
- def silently
7
- warn_level = $VERBOSE
8
- $VERBOSE = nil
9
- result = yield
10
- $VERBOSE = warn_level
11
- result
12
- end
13
-
14
- begin
15
- require 'rubygems' if RUBY_VERSION < "1.9.0" && !ENV['C_EXT']
16
- silently { require 'shoulda' }
17
- silently { require 'mocha' }
18
- rescue LoadError
19
- puts <<MSG
20
-
21
- This test suite requires shoulda and mocha.
22
- You can install them as follows:
23
- gem install shoulda
24
- gem install mocha
25
-
26
- MSG
27
-
28
- exit
29
- end
30
-
31
- require 'bson_ext/cbson' if !(RUBY_PLATFORM =~ /java/) && ENV['C_EXT']
32
-
33
- unless defined? MONGO_TEST_DB
34
- MONGO_TEST_DB = 'ruby-test-db'
35
- end
36
-
37
- unless defined? TEST_PORT
38
- TEST_PORT = ENV['MONGO_RUBY_DRIVER_PORT'] ? ENV['MONGO_RUBY_DRIVER_PORT'].to_i : Mongo::Connection::DEFAULT_PORT
39
- end
40
-
41
- unless defined? TEST_HOST
42
- TEST_HOST = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
43
- end
44
-
45
- class Test::Unit::TestCase
46
- include Mongo
47
- include BSON
48
-
49
- def self.standard_connection(options={})
50
- Connection.new(TEST_HOST, TEST_PORT, options)
51
- end
52
-
53
- def standard_connection(options={})
54
- self.class.standard_connection(options)
55
- end
56
-
57
- def self.host_port
58
- "#{mongo_host}:#{mongo_port}"
59
- end
60
-
61
- def self.mongo_host
62
- TEST_HOST
63
- end
64
-
65
- def self.mongo_port
66
- TEST_PORT
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
+ # NOTE: on ruby <1.9 you need to run individual tests with 'bundle exec'
16
+
17
+ unless RUBY_VERSION < '1.9' || ENV.key?('JENKINS_CI')
18
+ require 'simplecov'
19
+ require 'coveralls'
20
+
21
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
22
+ SimpleCov::Formatter::HTMLFormatter,
23
+ Coveralls::SimpleCov::Formatter
24
+ ]
25
+
26
+ SimpleCov.start do
27
+ add_group 'Driver', 'lib/mongo'
28
+ add_group 'BSON', 'lib/bson'
29
+
30
+ add_filter 'tasks'
31
+ add_filter 'test'
32
+ add_filter 'bin'
67
33
  end
34
+ end
68
35
 
69
- def host_port
70
- self.class.host_port
71
- end
36
+ # required for at_exit, at_start hooks
37
+ require 'test-unit'
72
38
 
73
- def mongo_host
74
- self.class.mongo_host
75
- end
39
+ require 'test/unit'
40
+ require 'shoulda'
41
+ require 'mocha/setup'
76
42
 
77
- def mongo_port
78
- self.class.mongo_port
79
- end
43
+ # cluster manager
44
+ require 'tools/mongo_config'
80
45
 
81
- def new_mock_socket(host='localhost', port=27017)
82
- socket = Object.new
83
- socket.stubs(:setsockopt).with(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
84
- socket.stubs(:close)
85
- socket
86
- end
46
+ # For kerberos testing.
47
+ begin
48
+ require 'mongo_kerberos'
49
+ rescue LoadError; end
87
50
 
88
- def new_mock_db
89
- db = Object.new
90
- end
51
+ # test helpers
52
+ require 'helpers/general'
53
+ require 'helpers/test_unit'
91
54
 
92
- def assert_raise_error(klass, message)
93
- begin
94
- yield
95
- rescue => e
96
- assert_equal klass, e.class
97
- assert e.message.include?(message), "#{e.message} does not include #{message}."
98
- else
99
- flunk "Expected assertion #{klass} but none was raised."
100
- end
101
- end
55
+ # optional development and debug utilities
56
+ begin
57
+ require 'pry-rescue'
58
+ require 'pry-nav'
59
+ rescue LoadError
60
+ # failed to load, skipping pry
102
61
  end
@@ -0,0 +1,120 @@
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 ThreadingTest < Test::Unit::TestCase
18
+
19
+ include Mongo
20
+
21
+ def setup
22
+ @client = standard_connection(:pool_size => 10, :pool_timeout => 30)
23
+ @db = @client.db(TEST_DB)
24
+ @coll = @db.collection('thread-test-collection')
25
+ @coll.drop
26
+
27
+ collections = ['duplicate', 'unique']
28
+
29
+ collections.each do |coll_name|
30
+ coll = @db.collection(coll_name)
31
+ coll.drop
32
+ coll.insert("test" => "insert")
33
+ coll.insert("test" => "update")
34
+ instance_variable_set("@#{coll_name}", coll)
35
+ end
36
+
37
+ @unique.create_index("test", :unique => true)
38
+ end
39
+
40
+ def test_safe_update
41
+ threads = []
42
+ 300.times do |i|
43
+ threads << Thread.new do
44
+ if i % 2 == 0
45
+ assert_raise Mongo::OperationFailure do
46
+ @unique.update({"test" => "insert"}, {"$set" => {"test" => "update"}})
47
+ end
48
+ else
49
+ @duplicate.update({"test" => "insert"}, {"$set" => {"test" => "update"}})
50
+ @duplicate.update({"test" => "update"}, {"$set" => {"test" => "insert"}})
51
+ end
52
+ end
53
+ end
54
+
55
+ threads.each {|thread| thread.join}
56
+ end
57
+
58
+ def test_safe_insert
59
+ threads = []
60
+ 300.times do |i|
61
+ threads << Thread.new do
62
+ if i % 2 == 0
63
+ assert_raise Mongo::OperationFailure do
64
+ @unique.insert({"test" => "insert"})
65
+ end
66
+ else
67
+ @duplicate.insert({"test" => "insert"})
68
+ end
69
+ end
70
+ end
71
+
72
+ threads.each {|thread| thread.join}
73
+ end
74
+
75
+ def test_concurrent_find
76
+ n_threads = 50
77
+
78
+ 1000.times do |i|
79
+ @coll.insert({ "x" => "a" })
80
+ end
81
+
82
+ threads = []
83
+ n_threads.times do |i|
84
+ threads << Thread.new do
85
+ sum = 0
86
+ @coll.find.to_a.size
87
+ end
88
+ end
89
+
90
+ thread_values = threads.map(&:value)
91
+ assert thread_values.all?{|v| v == 1000}
92
+ assert_equal thread_values.size, n_threads
93
+ end
94
+
95
+ def test_threading
96
+ @coll.drop
97
+ @coll = @db.collection('thread-test-collection')
98
+
99
+ docs = []
100
+ 1000.times {|i| docs << {:x => i}}
101
+ @coll.insert(docs)
102
+
103
+ threads = []
104
+
105
+ 10.times do |i|
106
+ threads[i] = Thread.new do
107
+ sum = 0
108
+ @coll.find().each do |document|
109
+ sum += document["x"]
110
+ end
111
+ assert_equal 499500, sum
112
+ end
113
+ end
114
+
115
+ 10.times do |i|
116
+ threads[i].join
117
+ end
118
+ end
119
+
120
+ end