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
@@ -1,186 +0,0 @@
1
- # Note: HashWithIndifferentAccess is so commonly used
2
- # that we always need to make sure that the driver works
3
- # with it.
4
- #require File.join(File.dirname(__FILE__), 'keys.rb')
5
-
6
- # This class has dubious semantics and we only have it so that
7
- # people can write params[:key] instead of params['key']
8
- # and they get the same value for both keys.
9
-
10
- class Hash
11
- # Return a new hash with all keys converted to strings.
12
- def stringify_keys
13
- dup.stringify_keys!
14
- end
15
-
16
- # Destructively convert all keys to strings.
17
- def stringify_keys!
18
- keys.each do |key|
19
- self[key.to_s] = delete(key)
20
- end
21
- self
22
- end
23
-
24
- # Return a new hash with all keys converted to symbols, as long as
25
- # they respond to +to_sym+.
26
- def symbolize_keys
27
- dup.symbolize_keys!
28
- end
29
-
30
- # Destructively convert all keys to symbols, as long as they respond
31
- # to +to_sym+.
32
- def symbolize_keys!
33
- keys.each do |key|
34
- self[(key.to_sym rescue key) || key] = delete(key)
35
- end
36
- self
37
- end
38
-
39
- alias_method :to_options, :symbolize_keys
40
- #alias_method :to_options!, :symbolize_keys!
41
- end
42
-
43
- module ActiveSupport
44
- class HashWithIndifferentAccess < Hash
45
- def extractable_options?
46
- true
47
- end
48
-
49
- def initialize(constructor = {})
50
- if constructor.is_a?(Hash)
51
- super()
52
- update(constructor)
53
- else
54
- super(constructor)
55
- end
56
- end
57
-
58
- def default(key = nil)
59
- if key.is_a?(Symbol) && include?(key = key.to_s)
60
- self[key]
61
- else
62
- super
63
- end
64
- end
65
-
66
- def self.new_from_hash_copying_default(hash)
67
- ActiveSupport::HashWithIndifferentAccess.new(hash).tap do |new_hash|
68
- new_hash.default = hash.default
69
- end
70
- end
71
-
72
- alias_method :regular_writer, :[]= unless method_defined?(:regular_writer)
73
- alias_method :regular_update, :update unless method_defined?(:regular_update)
74
-
75
- # Assigns a new value to the hash:
76
- #
77
- # hash = HashWithIndifferentAccess.new
78
- # hash[:key] = "value"
79
- #
80
- def []=(key, value)
81
- regular_writer(convert_key(key), convert_value(value))
82
- end
83
-
84
- # Updates the instantized hash with values from the second:
85
- #
86
- # hash_1 = HashWithIndifferentAccess.new
87
- # hash_1[:key] = "value"
88
- #
89
- # hash_2 = HashWithIndifferentAccess.new
90
- # hash_2[:key] = "New Value!"
91
- #
92
- # hash_1.update(hash_2) # => {"key"=>"New Value!"}
93
- #
94
- def update(other_hash)
95
- other_hash.each_pair { |key, value| regular_writer(convert_key(key), convert_value(value)) }
96
- self
97
- end
98
-
99
- alias_method :merge!, :update
100
-
101
- # Checks the hash for a key matching the argument passed in:
102
- #
103
- # hash = HashWithIndifferentAccess.new
104
- # hash["key"] = "value"
105
- # hash.key? :key # => true
106
- # hash.key? "key" # => true
107
- #
108
- def key?(key)
109
- super(convert_key(key))
110
- end
111
-
112
- alias_method :include?, :key?
113
- alias_method :has_key?, :key?
114
- alias_method :member?, :key?
115
-
116
- # Fetches the value for the specified key, same as doing hash[key]
117
- def fetch(key, *extras)
118
- super(convert_key(key), *extras)
119
- end
120
-
121
- # Returns an array of the values at the specified indices:
122
- #
123
- # hash = HashWithIndifferentAccess.new
124
- # hash[:a] = "x"
125
- # hash[:b] = "y"
126
- # hash.values_at("a", "b") # => ["x", "y"]
127
- #
128
- def values_at(*indices)
129
- indices.collect {|key| self[convert_key(key)]}
130
- end
131
-
132
- # Returns an exact copy of the hash.
133
- def dup
134
- HashWithIndifferentAccess.new(self)
135
- end
136
-
137
- # Merges the instantized and the specified hashes together, giving precedence to the values from the second hash
138
- # Does not overwrite the existing hash.
139
- def merge(hash)
140
- self.dup.update(hash)
141
- end
142
-
143
- # Performs the opposite of merge, with the keys and values from the first hash taking precedence over the second.
144
- # This overloaded definition prevents returning a regular hash, if reverse_merge is called on a HashWithDifferentAccess.
145
- def reverse_merge(other_hash)
146
- super self.class.new_from_hash_copying_default(other_hash)
147
- end
148
-
149
- def reverse_merge!(other_hash)
150
- replace(reverse_merge( other_hash ))
151
- end
152
-
153
- # Removes a specified key from the hash.
154
- def delete(key)
155
- super(convert_key(key))
156
- end
157
-
158
- def stringify_keys!; self end
159
- def stringify_keys; dup end
160
- def symbolize_keys; to_hash.symbolize_keys end
161
- def to_options!; self end
162
-
163
- # Convert to a Hash with String keys.
164
- def to_hash
165
- Hash.new(default).merge!(self)
166
- end
167
-
168
- protected
169
- def convert_key(key)
170
- key.kind_of?(Symbol) ? key.to_s : key
171
- end
172
-
173
- def convert_value(value)
174
- case value
175
- when Hash
176
- self.class.new_from_hash_copying_default(value)
177
- when Array
178
- value.collect { |e| e.is_a?(Hash) ? self.class.new_from_hash_copying_default(e) : e }
179
- else
180
- value
181
- end
182
- end
183
- end
184
- end
185
-
186
- HashWithIndifferentAccess = ActiveSupport::HashWithIndifferentAccess
data/test/support/keys.rb DELETED
@@ -1,45 +0,0 @@
1
- class Hash
2
- # Return a new hash with all keys converted to strings.
3
- def stringify_keys
4
- dup.stringify_keys!
5
- end
6
-
7
- # Destructively convert all keys to strings.
8
- def stringify_keys!
9
- keys.each do |key|
10
- self[key.to_s] = delete(key)
11
- end
12
- self
13
- end
14
-
15
- # Return a new hash with all keys converted to symbols, as long as
16
- # they respond to +to_sym+.
17
- def symbolize_keys
18
- dup.symbolize_keys!
19
- end
20
-
21
- # Destructively convert all keys to symbols, as long as they respond
22
- # to +to_sym+.
23
- def symbolize_keys!
24
- keys.each do |key|
25
- self[(key.to_sym rescue key) || key] = delete(key)
26
- end
27
- self
28
- end
29
-
30
- alias_method :to_options, :symbolize_keys
31
- #alias_method :to_options!, :symbolize_keys!
32
-
33
- # Validate all keys in a hash match *valid keys, raising ArgumentError on a mismatch.
34
- # Note that keys are NOT treated indifferently, meaning if you use strings for keys but assert symbols
35
- # as keys, this will fail.
36
- #
37
- # ==== Examples
38
- # { :name => "Rob", :years => "28" }.assert_valid_keys(:name, :age) # => raises "ArgumentError: Unknown key(s): years"
39
- # { :name => "Rob", :age => "28" }.assert_valid_keys("name", "age") # => raises "ArgumentError: Unknown key(s): name, age"
40
- # { :name => "Rob", :age => "28" }.assert_valid_keys(:name, :age) # => passes, raises nothing
41
- def assert_valid_keys(*valid_keys)
42
- unknown_keys = keys - [valid_keys].flatten
43
- raise(ArgumentError, "Unknown key(s): #{unknown_keys.join(", ")}") unless unknown_keys.empty?
44
- end
45
- end
data/test/support_test.rb DELETED
@@ -1,18 +0,0 @@
1
- require './test/test_helper'
2
-
3
- class SupportTest < Test::Unit::TestCase
4
-
5
- def test_command_response_succeeds
6
- assert Support.ok?('ok' => 1)
7
- assert Support.ok?('ok' => 1.0)
8
- assert Support.ok?('ok' => true)
9
- end
10
-
11
- def test_command_response_fails
12
- assert !Support.ok?('ok' => 0)
13
- assert !Support.ok?('ok' => 0.0)
14
- assert !Support.ok?('ok' => 0.0)
15
- assert !Support.ok?('ok' => 'str')
16
- assert !Support.ok?('ok' => false)
17
- end
18
- end
@@ -1,90 +0,0 @@
1
- require './test/test_helper'
2
-
3
- # Essentialy the same as test_threading.rb but with an expanded pool for
4
- # testing multiple connections.
5
- class TestThreadingLargePool < Test::Unit::TestCase
6
-
7
- include Mongo
8
-
9
- @@db = standard_connection(:pool_size => 50, :timeout => 60).db(MONGO_TEST_DB)
10
- @@coll = @@db.collection('thread-test-collection')
11
-
12
- def set_up_safe_data
13
- @@db.drop_collection('duplicate')
14
- @@db.drop_collection('unique')
15
- @duplicate = @@db.collection('duplicate')
16
- @unique = @@db.collection('unique')
17
-
18
- @duplicate.insert("test" => "insert")
19
- @duplicate.insert("test" => "update")
20
- @unique.insert("test" => "insert")
21
- @unique.insert("test" => "update")
22
- @unique.create_index("test", :unique => true)
23
- end
24
-
25
- def test_safe_update
26
- set_up_safe_data
27
- threads = []
28
- 300.times do |i|
29
- threads[i] = Thread.new do
30
- if i % 2 == 0
31
- assert_raise Mongo::OperationFailure do
32
- @unique.update({"test" => "insert"}, {"$set" => {"test" => "update"}}, :safe => true)
33
- end
34
- else
35
- @duplicate.update({"test" => "insert"}, {"$set" => {"test" => "update"}}, :safe => true)
36
- end
37
- end
38
- end
39
-
40
- 300.times do |i|
41
- threads[i].join
42
- end
43
- end
44
-
45
- def test_safe_insert
46
- set_up_safe_data
47
- threads = []
48
- 300.times do |i|
49
- threads[i] = Thread.new do
50
- if i % 2 == 0
51
- assert_raise Mongo::OperationFailure do
52
- @unique.insert({"test" => "insert"}, :safe => true)
53
- end
54
- else
55
- @duplicate.insert({"test" => "insert"}, :safe => true)
56
- end
57
- end
58
- end
59
-
60
- 300.times do |i|
61
- threads[i].join
62
- end
63
- end
64
-
65
- def test_threading
66
- @@coll.drop
67
- @@coll = @@db.collection('thread-test-collection')
68
-
69
- 1000.times do |i|
70
- @@coll.insert("x" => i)
71
- end
72
-
73
- threads = []
74
-
75
- 10.times do |i|
76
- threads[i] = Thread.new do
77
- sum = 0
78
- @@coll.find().each do |document|
79
- sum += document["x"]
80
- end
81
- assert_equal 499500, sum
82
- end
83
- end
84
-
85
- 10.times do |i|
86
- threads[i].join
87
- end
88
- end
89
-
90
- end
@@ -1,87 +0,0 @@
1
- require './test/test_helper'
2
-
3
- class TestThreading < Test::Unit::TestCase
4
-
5
- include Mongo
6
-
7
- @@db = standard_connection(:pool_size => 1, :timeout => 30).db(MONGO_TEST_DB)
8
- @@coll = @@db.collection('thread-test-collection')
9
-
10
- def set_up_safe_data
11
- @@db.drop_collection('duplicate')
12
- @@db.drop_collection('unique')
13
- @duplicate = @@db.collection('duplicate')
14
- @unique = @@db.collection('unique')
15
-
16
- @duplicate.insert("test" => "insert")
17
- @duplicate.insert("test" => "update")
18
- @unique.insert("test" => "insert")
19
- @unique.insert("test" => "update")
20
- @unique.create_index("test", :unique => true)
21
- end
22
-
23
- def test_safe_update
24
- set_up_safe_data
25
- threads = []
26
- 100.times do |i|
27
- threads[i] = Thread.new do
28
- if i % 2 == 0
29
- assert_raise Mongo::OperationFailure do
30
- @unique.update({"test" => "insert"}, {"$set" => {"test" => "update"}}, :safe => true)
31
- end
32
- else
33
- @duplicate.update({"test" => "insert"}, {"$set" => {"test" => "update"}}, :safe => true)
34
- end
35
- end
36
- end
37
-
38
- 100.times do |i|
39
- threads[i].join
40
- end
41
- end
42
-
43
- def test_safe_insert
44
- set_up_safe_data
45
- threads = []
46
- 100.times do |i|
47
- threads[i] = Thread.new do
48
- if i % 2 == 0
49
- assert_raise Mongo::OperationFailure do
50
- @unique.insert({"test" => "insert"}, :safe => true)
51
- end
52
- else
53
- @duplicate.insert({"test" => "insert"}, :safe => true)
54
- end
55
- end
56
- end
57
-
58
- 100.times do |i|
59
- threads[i].join
60
- end
61
- end
62
-
63
- def test_threading
64
- @@coll.drop
65
- @@coll = @@db.collection('thread-test-collection')
66
-
67
- 1000.times do |i|
68
- @@coll.insert("x" => i)
69
- end
70
-
71
- threads = []
72
-
73
- 10.times do |i|
74
- threads[i] = Thread.new do
75
- sum = 0
76
- @@coll.find().each do |document|
77
- sum += document["x"]
78
- end
79
- assert_equal 499500, sum
80
- end
81
- end
82
-
83
- 10.times do |i|
84
- threads[i].join
85
- end
86
- end
87
- end
@@ -1,14 +0,0 @@
1
- require File.join((File.expand_path(File.dirname(__FILE__))), 'repl_set_manager')
2
-
3
- class AuthReplSetManager < ReplSetManager
4
- def initialize(opts={})
5
- super(opts)
6
-
7
- @key_path = opts[:key_path] || File.join(File.expand_path(File.dirname(__FILE__)), "keyfile.txt")
8
- system("chmod 600 #{@key_path}")
9
- end
10
-
11
- def start_cmd(n)
12
- super + " --keyFile #{@key_path}"
13
- end
14
- end
data/test/tools/load.rb DELETED
@@ -1,58 +0,0 @@
1
- require 'rubygems'
2
- require 'mongo'
3
- require 'sharding_manager'
4
-
5
- class MongoLoader
6
-
7
- def initialize
8
- @mongo = Mongo::Connection.new("localhost", 50000)
9
- @data = BSON::Binary.new(File.open("tools.gz").read)
10
- @count = 0
11
- @manager = ShardingManager.new(:config_count => 3)
12
- @manager.start_cluster
13
- end
14
-
15
- def kill
16
- @manager.kill_random
17
- end
18
-
19
- def restart
20
- @manager.restart_killed_nodes
21
- end
22
-
23
- def run
24
- Thread.new do
25
- ("a".."z").each do |p|
26
- seed(p)
27
- end
28
- end
29
- end
30
-
31
- def seed(prefix)
32
- @queue = []
33
- 1000.times do |n|
34
- id = BSON::OrderedHash.new
35
- id[:p] = prefix
36
- id[:c] = n
37
- @queue << {:tid => id, :data => @data}
38
- end
39
-
40
- while @queue.length > 0 do
41
- begin
42
- doc = @queue.pop
43
- @mongo['app']['photos'].insert(doc, :safe => {:w => 3})
44
- @count += 1
45
- p @count
46
- rescue StandardError => e
47
- p e
48
- p @count
49
- @queue.push(doc)
50
- @count -= 1
51
- sleep(10)
52
- retry
53
- end
54
- end
55
- end
56
- end
57
-
58
- @m = MongoLoader.new