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.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data/{LICENSE.txt → LICENSE} +1 -1
- data/README.md +122 -271
- data/Rakefile +25 -209
- data/VERSION +1 -0
- data/bin/mongo_console +31 -9
- data/lib/mongo/bulk_write_collection_view.rb +387 -0
- data/lib/mongo/collection.rb +576 -269
- data/lib/mongo/collection_writer.rb +364 -0
- data/lib/mongo/connection/node.rb +249 -0
- data/lib/mongo/connection/pool.rb +340 -0
- data/lib/mongo/connection/pool_manager.rb +320 -0
- data/lib/mongo/connection/sharding_pool_manager.rb +67 -0
- data/lib/mongo/connection/socket/socket_util.rb +37 -0
- data/lib/mongo/connection/socket/ssl_socket.rb +95 -0
- data/lib/mongo/connection/socket/tcp_socket.rb +87 -0
- data/lib/mongo/connection/socket/unix_socket.rb +39 -0
- data/lib/mongo/connection/socket.rb +18 -0
- data/lib/mongo/connection.rb +7 -875
- data/lib/mongo/cursor.rb +403 -117
- data/lib/mongo/db.rb +444 -243
- data/lib/mongo/exception.rb +145 -0
- data/lib/mongo/functional/authentication.rb +455 -0
- data/lib/mongo/functional/logging.rb +85 -0
- data/lib/mongo/functional/read_preference.rb +183 -0
- data/lib/mongo/functional/scram.rb +556 -0
- data/lib/mongo/functional/uri_parser.rb +409 -0
- data/lib/mongo/functional/write_concern.rb +66 -0
- data/lib/mongo/functional.rb +20 -0
- data/lib/mongo/gridfs/grid.rb +30 -24
- data/lib/mongo/gridfs/grid_ext.rb +6 -10
- data/lib/mongo/gridfs/grid_file_system.rb +38 -20
- data/lib/mongo/gridfs/grid_io.rb +84 -75
- data/lib/mongo/gridfs.rb +18 -0
- data/lib/mongo/legacy.rb +140 -0
- data/lib/mongo/mongo_client.rb +697 -0
- data/lib/mongo/mongo_replica_set_client.rb +535 -0
- data/lib/mongo/mongo_sharded_client.rb +159 -0
- data/lib/mongo/networking.rb +372 -0
- data/lib/mongo/{util → utils}/conversions.rb +29 -8
- data/lib/mongo/{util → utils}/core_ext.rb +28 -18
- data/lib/mongo/{util → utils}/server_version.rb +4 -6
- data/lib/mongo/{util → utils}/support.rb +29 -31
- data/lib/mongo/utils/thread_local_variable_manager.rb +25 -0
- data/lib/mongo/utils.rb +19 -0
- data/lib/mongo.rb +51 -50
- data/mongo.gemspec +29 -32
- data/test/functional/authentication_test.rb +39 -0
- data/test/functional/bulk_api_stress_test.rb +133 -0
- data/test/functional/bulk_write_collection_view_test.rb +1198 -0
- data/test/functional/client_test.rb +627 -0
- data/test/functional/collection_test.rb +2175 -0
- data/test/functional/collection_writer_test.rb +83 -0
- data/test/{conversions_test.rb → functional/conversions_test.rb} +47 -3
- data/test/functional/cursor_fail_test.rb +57 -0
- data/test/functional/cursor_message_test.rb +56 -0
- data/test/functional/cursor_test.rb +683 -0
- data/test/functional/db_api_test.rb +835 -0
- data/test/functional/db_connection_test.rb +25 -0
- data/test/functional/db_test.rb +348 -0
- data/test/functional/grid_file_system_test.rb +285 -0
- data/test/{grid_io_test.rb → functional/grid_io_test.rb} +72 -11
- data/test/{grid_test.rb → functional/grid_test.rb} +88 -15
- data/test/functional/pool_test.rb +136 -0
- data/test/functional/safe_test.rb +98 -0
- data/test/functional/ssl_test.rb +29 -0
- data/test/functional/support_test.rb +62 -0
- data/test/functional/timeout_test.rb +60 -0
- data/test/functional/uri_test.rb +446 -0
- data/test/functional/write_concern_test.rb +118 -0
- data/test/helpers/general.rb +50 -0
- data/test/helpers/test_unit.rb +476 -0
- data/test/replica_set/authentication_test.rb +37 -0
- data/test/replica_set/basic_test.rb +189 -0
- data/test/replica_set/client_test.rb +393 -0
- data/test/replica_set/connection_test.rb +138 -0
- data/test/replica_set/count_test.rb +66 -0
- data/test/replica_set/cursor_test.rb +220 -0
- data/test/replica_set/insert_test.rb +157 -0
- data/test/replica_set/max_values_test.rb +151 -0
- data/test/replica_set/pinning_test.rb +105 -0
- data/test/replica_set/query_test.rb +73 -0
- data/test/replica_set/read_preference_test.rb +219 -0
- data/test/replica_set/refresh_test.rb +211 -0
- data/test/replica_set/replication_ack_test.rb +95 -0
- data/test/replica_set/ssl_test.rb +32 -0
- data/test/sharded_cluster/basic_test.rb +203 -0
- data/test/shared/authentication/basic_auth_shared.rb +260 -0
- data/test/shared/authentication/bulk_api_auth_shared.rb +249 -0
- data/test/shared/authentication/gssapi_shared.rb +176 -0
- data/test/shared/authentication/sasl_plain_shared.rb +96 -0
- data/test/shared/authentication/scram_shared.rb +92 -0
- data/test/shared/ssl_shared.rb +235 -0
- data/test/test_helper.rb +53 -94
- data/test/threading/basic_test.rb +120 -0
- data/test/tools/mongo_config.rb +708 -0
- data/test/tools/mongo_config_test.rb +160 -0
- data/test/unit/client_test.rb +381 -0
- data/test/unit/collection_test.rb +89 -53
- data/test/unit/connection_test.rb +282 -32
- data/test/unit/cursor_test.rb +206 -8
- data/test/unit/db_test.rb +55 -13
- data/test/unit/grid_test.rb +43 -16
- data/test/unit/mongo_sharded_client_test.rb +48 -0
- data/test/unit/node_test.rb +93 -0
- data/test/unit/pool_manager_test.rb +111 -0
- data/test/unit/read_pref_test.rb +406 -0
- data/test/unit/read_test.rb +159 -0
- data/test/unit/safe_test.rb +69 -36
- data/test/unit/sharding_pool_manager_test.rb +84 -0
- data/test/unit/write_concern_test.rb +175 -0
- data.tar.gz.sig +3 -0
- metadata +227 -216
- metadata.gz.sig +0 -0
- data/docs/CREDITS.md +0 -123
- data/docs/FAQ.md +0 -116
- data/docs/GridFS.md +0 -158
- data/docs/HISTORY.md +0 -244
- data/docs/RELEASES.md +0 -33
- data/docs/REPLICA_SETS.md +0 -72
- data/docs/TUTORIAL.md +0 -247
- data/docs/WRITE_CONCERN.md +0 -28
- data/lib/mongo/exceptions.rb +0 -71
- data/lib/mongo/gridfs/grid_io_fix.rb +0 -38
- data/lib/mongo/repl_set_connection.rb +0 -342
- data/lib/mongo/test.rb +0 -20
- data/lib/mongo/util/pool.rb +0 -177
- data/lib/mongo/util/uri_parser.rb +0 -185
- data/test/async/collection_test.rb +0 -224
- data/test/async/connection_test.rb +0 -24
- data/test/async/cursor_test.rb +0 -162
- data/test/async/worker_pool_test.rb +0 -99
- data/test/auxillary/1.4_features.rb +0 -166
- data/test/auxillary/authentication_test.rb +0 -68
- data/test/auxillary/autoreconnect_test.rb +0 -41
- data/test/auxillary/fork_test.rb +0 -30
- data/test/auxillary/repl_set_auth_test.rb +0 -58
- data/test/auxillary/slave_connection_test.rb +0 -36
- data/test/auxillary/threaded_authentication_test.rb +0 -101
- data/test/bson/binary_test.rb +0 -15
- data/test/bson/bson_test.rb +0 -649
- data/test/bson/byte_buffer_test.rb +0 -208
- data/test/bson/hash_with_indifferent_access_test.rb +0 -38
- data/test/bson/json_test.rb +0 -17
- data/test/bson/object_id_test.rb +0 -154
- data/test/bson/ordered_hash_test.rb +0 -204
- data/test/bson/timestamp_test.rb +0 -24
- data/test/collection_test.rb +0 -910
- data/test/connection_test.rb +0 -309
- data/test/cursor_fail_test.rb +0 -75
- data/test/cursor_message_test.rb +0 -43
- data/test/cursor_test.rb +0 -483
- data/test/db_api_test.rb +0 -726
- data/test/db_connection_test.rb +0 -15
- data/test/db_test.rb +0 -287
- data/test/grid_file_system_test.rb +0 -243
- data/test/load/resque/load.rb +0 -21
- data/test/load/resque/processor.rb +0 -26
- data/test/load/thin/load.rb +0 -24
- data/test/load/unicorn/load.rb +0 -23
- data/test/load/unicorn/unicorn.rb +0 -29
- data/test/replica_sets/connect_test.rb +0 -94
- data/test/replica_sets/connection_string_test.rb +0 -32
- data/test/replica_sets/count_test.rb +0 -35
- data/test/replica_sets/insert_test.rb +0 -53
- data/test/replica_sets/pooled_insert_test.rb +0 -55
- data/test/replica_sets/query_secondaries.rb +0 -96
- data/test/replica_sets/query_test.rb +0 -51
- data/test/replica_sets/replication_ack_test.rb +0 -66
- data/test/replica_sets/rs_test_helper.rb +0 -27
- data/test/safe_test.rb +0 -68
- data/test/support/hash_with_indifferent_access.rb +0 -186
- data/test/support/keys.rb +0 -45
- data/test/support_test.rb +0 -18
- data/test/threading/threading_with_large_pool_test.rb +0 -90
- data/test/threading_test.rb +0 -87
- data/test/tools/auth_repl_set_manager.rb +0 -14
- data/test/tools/load.rb +0 -58
- data/test/tools/repl_set_manager.rb +0 -266
- data/test/tools/sharding_manager.rb +0 -202
- data/test/tools/test.rb +0 -4
- data/test/unit/pool_test.rb +0 -9
- data/test/unit/repl_set_connection_test.rb +0 -59
- data/test/uri_test.rb +0 -91
data/test/connection_test.rb
DELETED
@@ -1,309 +0,0 @@
|
|
1
|
-
require './test/test_helper'
|
2
|
-
require 'logger'
|
3
|
-
require 'stringio'
|
4
|
-
require 'thread'
|
5
|
-
|
6
|
-
class TestConnection < Test::Unit::TestCase
|
7
|
-
|
8
|
-
include Mongo
|
9
|
-
include BSON
|
10
|
-
|
11
|
-
def setup
|
12
|
-
@conn = standard_connection
|
13
|
-
end
|
14
|
-
|
15
|
-
def teardown
|
16
|
-
@conn[MONGO_TEST_DB].get_last_error
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_connection_failure
|
20
|
-
assert_raise Mongo::ConnectionFailure do
|
21
|
-
Mongo::Connection.new('localhost', 27347)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_host_port_accessors
|
26
|
-
assert_equal @conn.host, TEST_HOST
|
27
|
-
assert_equal @conn.port, TEST_PORT
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_server_info
|
31
|
-
server_info = @conn.server_info
|
32
|
-
assert server_info.keys.include?("version")
|
33
|
-
assert Mongo::Support.ok?(server_info)
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_ping
|
37
|
-
ping = @conn.ping
|
38
|
-
assert ping['ok']
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_connection_uri
|
42
|
-
con = Connection.from_uri("mongodb://#{host_port}")
|
43
|
-
assert_equal mongo_host, con.primary_pool.host
|
44
|
-
assert_equal mongo_port, con.primary_pool.port
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_server_version
|
48
|
-
assert_match(/\d\.\d+(\.\d+)?/, @conn.server_version.to_s)
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_invalid_database_names
|
52
|
-
assert_raise TypeError do @conn.db(4) end
|
53
|
-
|
54
|
-
assert_raise Mongo::InvalidNSName do @conn.db('') end
|
55
|
-
assert_raise Mongo::InvalidNSName do @conn.db('te$t') end
|
56
|
-
assert_raise Mongo::InvalidNSName do @conn.db('te.t') end
|
57
|
-
assert_raise Mongo::InvalidNSName do @conn.db('te\\t') end
|
58
|
-
assert_raise Mongo::InvalidNSName do @conn.db('te/t') end
|
59
|
-
assert_raise Mongo::InvalidNSName do @conn.db('te st') end
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_options_passed_to_db
|
63
|
-
@pk_mock = Object.new
|
64
|
-
db = @conn.db('test', :pk => @pk_mock, :strict => true)
|
65
|
-
assert_equal @pk_mock, db.pk_factory
|
66
|
-
assert db.strict?
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_database_info
|
70
|
-
@conn.drop_database(MONGO_TEST_DB)
|
71
|
-
@conn.db(MONGO_TEST_DB).collection('info-test').insert('a' => 1)
|
72
|
-
|
73
|
-
info = @conn.database_info
|
74
|
-
assert_not_nil info
|
75
|
-
assert_kind_of Hash, info
|
76
|
-
assert_not_nil info[MONGO_TEST_DB]
|
77
|
-
assert info[MONGO_TEST_DB] > 0
|
78
|
-
|
79
|
-
@conn.drop_database(MONGO_TEST_DB)
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_copy_database
|
83
|
-
@conn.db('old').collection('copy-test').insert('a' => 1)
|
84
|
-
@conn.copy_database('old', 'new', host_port)
|
85
|
-
old_object = @conn.db('old').collection('copy-test').find.next_document
|
86
|
-
new_object = @conn.db('new').collection('copy-test').find.next_document
|
87
|
-
assert_equal old_object, new_object
|
88
|
-
@conn.drop_database('old')
|
89
|
-
@conn.drop_database('new')
|
90
|
-
end
|
91
|
-
|
92
|
-
def test_copy_database_with_auth
|
93
|
-
@conn.db('old').collection('copy-test').insert('a' => 1)
|
94
|
-
@conn.db('old').add_user('bob', 'secret')
|
95
|
-
|
96
|
-
assert_raise Mongo::OperationFailure do
|
97
|
-
@conn.copy_database('old', 'new', host_port, 'bob', 'badpassword')
|
98
|
-
end
|
99
|
-
|
100
|
-
result = @conn.copy_database('old', 'new', host_port, 'bob', 'secret')
|
101
|
-
assert Mongo::Support.ok?(result)
|
102
|
-
|
103
|
-
@conn.drop_database('old')
|
104
|
-
@conn.drop_database('new')
|
105
|
-
end
|
106
|
-
|
107
|
-
def test_database_names
|
108
|
-
@conn.drop_database(MONGO_TEST_DB)
|
109
|
-
@conn.db(MONGO_TEST_DB).collection('info-test').insert('a' => 1)
|
110
|
-
|
111
|
-
names = @conn.database_names
|
112
|
-
assert_not_nil names
|
113
|
-
assert_kind_of Array, names
|
114
|
-
assert names.length >= 1
|
115
|
-
assert names.include?(MONGO_TEST_DB)
|
116
|
-
end
|
117
|
-
|
118
|
-
def test_logging
|
119
|
-
output = StringIO.new
|
120
|
-
logger = Logger.new(output)
|
121
|
-
logger.level = Logger::DEBUG
|
122
|
-
connection = standard_connection(:logger => logger).db(MONGO_TEST_DB)
|
123
|
-
assert output.string.include?("admin['$cmd'].find")
|
124
|
-
end
|
125
|
-
|
126
|
-
def test_connection_logger
|
127
|
-
output = StringIO.new
|
128
|
-
logger = Logger.new(output)
|
129
|
-
logger.level = Logger::DEBUG
|
130
|
-
connection = standard_connection(:logger => logger)
|
131
|
-
assert_equal logger, connection.logger
|
132
|
-
|
133
|
-
connection.logger.debug 'testing'
|
134
|
-
assert output.string.include?('testing')
|
135
|
-
end
|
136
|
-
|
137
|
-
def test_drop_database
|
138
|
-
db = @conn.db('ruby-mongo-will-be-deleted')
|
139
|
-
coll = db.collection('temp')
|
140
|
-
coll.remove
|
141
|
-
coll.insert(:name => 'temp')
|
142
|
-
assert_equal 1, coll.count()
|
143
|
-
assert @conn.database_names.include?('ruby-mongo-will-be-deleted')
|
144
|
-
|
145
|
-
@conn.drop_database('ruby-mongo-will-be-deleted')
|
146
|
-
assert !@conn.database_names.include?('ruby-mongo-will-be-deleted')
|
147
|
-
end
|
148
|
-
|
149
|
-
def test_nodes
|
150
|
-
db = Connection.multi([['foo', 27017], ['bar', 27018]], :connect => false)
|
151
|
-
nodes = db.nodes
|
152
|
-
assert_equal 2, nodes.length
|
153
|
-
assert_equal ['foo', 27017], nodes[0]
|
154
|
-
assert_equal ['bar', 27018], nodes[1]
|
155
|
-
end
|
156
|
-
|
157
|
-
def test_fsync_lock
|
158
|
-
assert !@conn.locked?
|
159
|
-
@conn.lock!
|
160
|
-
assert @conn.locked?
|
161
|
-
assert_equal 1, @conn['admin']['$cmd.sys.inprog'].find_one['fsyncLock'], "Not fsync-locked"
|
162
|
-
assert_match(/unlock/, @conn.unlock!['info'])
|
163
|
-
unlocked = false
|
164
|
-
counter = 0
|
165
|
-
while counter < 5
|
166
|
-
if @conn['admin']['$cmd.sys.inprog'].find_one['fsyncLock'].nil?
|
167
|
-
unlocked = true
|
168
|
-
break
|
169
|
-
else
|
170
|
-
sleep(1)
|
171
|
-
counter += 1
|
172
|
-
end
|
173
|
-
end
|
174
|
-
assert !@conn.locked?
|
175
|
-
assert unlocked, "mongod failed to unlock"
|
176
|
-
end
|
177
|
-
|
178
|
-
def test_max_bson_size_value
|
179
|
-
conn = standard_connection
|
180
|
-
if conn.server_version > "1.7.2"
|
181
|
-
assert_equal conn['admin'].command({:ismaster => 1})['maxBsonObjectSize'], conn.max_bson_size
|
182
|
-
end
|
183
|
-
|
184
|
-
conn.connect
|
185
|
-
assert_equal BSON::BSON_CODER.max_bson_size, conn.max_bson_size
|
186
|
-
doc = {'n' => 'a' * (BSON_CODER.max_bson_size - 11)}
|
187
|
-
assert_raise InvalidDocument do
|
188
|
-
assert BSON::BSON_CODER.serialize(doc)
|
189
|
-
end
|
190
|
-
|
191
|
-
limit = 7 * 1024 * 1024
|
192
|
-
conn.stubs(:max_bson_size).returns(limit)
|
193
|
-
conn.connect
|
194
|
-
assert_equal limit, conn.max_bson_size
|
195
|
-
assert_equal limit, BSON::BSON_CODER.max_bson_size
|
196
|
-
doc = {'n' => 'a' * ((limit) - 11)}
|
197
|
-
assert_raise_error InvalidDocument, "limited to #{limit}" do
|
198
|
-
assert BSON::BSON_CODER.serialize(doc)
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
def test_max_bson_size_with_old_mongod
|
203
|
-
conn = standard_connection(:connect => false)
|
204
|
-
|
205
|
-
admin_db = Object.new
|
206
|
-
admin_db.expects(:command).returns({'ok' => 1, 'ismaster' => 1}).twice
|
207
|
-
conn.expects(:[]).with('admin').returns(admin_db).twice
|
208
|
-
|
209
|
-
conn.connect
|
210
|
-
assert_equal Mongo::DEFAULT_MAX_BSON_SIZE, BSON::BSON_CODER.max_bson_size
|
211
|
-
end
|
212
|
-
|
213
|
-
def test_connection_activity
|
214
|
-
conn = standard_connection
|
215
|
-
assert conn.active?
|
216
|
-
|
217
|
-
conn.primary_pool.close
|
218
|
-
assert !conn.active?
|
219
|
-
|
220
|
-
# Simulate a dropped connection.
|
221
|
-
dropped_socket = Mocha::Mock.new
|
222
|
-
dropped_socket.stubs(:read).raises(Errno::ECONNRESET)
|
223
|
-
dropped_socket.stubs(:send).raises(Errno::ECONNRESET)
|
224
|
-
dropped_socket.stub_everything
|
225
|
-
|
226
|
-
conn.primary_pool.host = 'localhost'
|
227
|
-
conn.primary_pool.port = Mongo::Connection::DEFAULT_PORT
|
228
|
-
conn.primary_pool.instance_variable_set("@pids", {dropped_socket => Process.pid})
|
229
|
-
conn.primary_pool.instance_variable_set("@sockets", [dropped_socket])
|
230
|
-
|
231
|
-
assert !conn.active?
|
232
|
-
end
|
233
|
-
|
234
|
-
context "Saved authentications" do
|
235
|
-
setup do
|
236
|
-
@conn = standard_connection
|
237
|
-
@auth = {'db_name' => 'test', 'username' => 'bob', 'password' => 'secret'}
|
238
|
-
@conn.add_auth(@auth['db_name'], @auth['username'], @auth['password'])
|
239
|
-
end
|
240
|
-
|
241
|
-
should "save the authentication" do
|
242
|
-
assert_equal @auth, @conn.auths[0]
|
243
|
-
end
|
244
|
-
|
245
|
-
should "replace the auth if given a new auth for the same db" do
|
246
|
-
auth = {'db_name' => 'test', 'username' => 'mickey', 'password' => 'm0u53'}
|
247
|
-
@conn.add_auth(auth['db_name'], auth['username'], auth['password'])
|
248
|
-
assert_equal 1, @conn.auths.length
|
249
|
-
assert_equal auth, @conn.auths[0]
|
250
|
-
end
|
251
|
-
|
252
|
-
should "remove auths by database" do
|
253
|
-
@conn.remove_auth('non-existent database')
|
254
|
-
assert_equal 1, @conn.auths.length
|
255
|
-
|
256
|
-
@conn.remove_auth('test')
|
257
|
-
assert_equal 0, @conn.auths.length
|
258
|
-
end
|
259
|
-
|
260
|
-
should "remove all auths" do
|
261
|
-
@conn.clear_auths
|
262
|
-
assert_equal 0, @conn.auths.length
|
263
|
-
end
|
264
|
-
end
|
265
|
-
|
266
|
-
context "Connection exceptions" do
|
267
|
-
setup do
|
268
|
-
@con = standard_connection(:pool_size => 10, :timeout => 10)
|
269
|
-
@coll = @con[MONGO_TEST_DB]['test-connection-exceptions']
|
270
|
-
end
|
271
|
-
|
272
|
-
should "release connection if an exception is raised on send_message" do
|
273
|
-
@con.stubs(:send_message_on_socket).raises(ConnectionFailure)
|
274
|
-
assert_equal 0, @con.primary_pool.checked_out.size
|
275
|
-
assert_raise ConnectionFailure do
|
276
|
-
@coll.insert({:test => "insert"})
|
277
|
-
end
|
278
|
-
assert_equal 0, @con.primary_pool.checked_out.size
|
279
|
-
end
|
280
|
-
|
281
|
-
should "release connection if an exception is raised on send_with_safe_check" do
|
282
|
-
@con.stubs(:receive).raises(ConnectionFailure)
|
283
|
-
assert_equal 0, @con.primary_pool.checked_out.size
|
284
|
-
assert_raise ConnectionFailure do
|
285
|
-
@coll.insert({:test => "insert"}, :safe => true)
|
286
|
-
end
|
287
|
-
assert_equal 0, @con.primary_pool.checked_out.size
|
288
|
-
end
|
289
|
-
|
290
|
-
should "release connection if an exception is raised on receive_message" do
|
291
|
-
@con.stubs(:receive).raises(ConnectionFailure)
|
292
|
-
assert_equal 0, @con.primary_pool.checked_out.size
|
293
|
-
assert_raise ConnectionFailure do
|
294
|
-
@coll.find.to_a
|
295
|
-
end
|
296
|
-
assert_equal 0, @con.primary_pool.checked_out.size
|
297
|
-
end
|
298
|
-
|
299
|
-
should "show a proper exception message if an IOError is raised while closing a socket" do
|
300
|
-
fake_socket = Mocha::Mock.new
|
301
|
-
fake_socket.stubs(:close).raises(IOError.new)
|
302
|
-
fake_socket.stub_everything
|
303
|
-
TCPSocket.expects(:new).returns(fake_socket)
|
304
|
-
|
305
|
-
@con.primary_pool.checkout_new_socket
|
306
|
-
assert_equal [], @con.primary_pool.close
|
307
|
-
end
|
308
|
-
end
|
309
|
-
end
|
data/test/cursor_fail_test.rb
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
require './test/test_helper'
|
2
|
-
require 'logger'
|
3
|
-
|
4
|
-
class CursorFailTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
include Mongo
|
7
|
-
|
8
|
-
@@connection = standard_connection
|
9
|
-
@@db = @@connection.db(MONGO_TEST_DB)
|
10
|
-
@@coll = @@db.collection('test')
|
11
|
-
@@version = @@connection.server_version
|
12
|
-
|
13
|
-
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"
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_refill_via_get_more
|
20
|
-
assert_equal 1, @@coll.count
|
21
|
-
1000.times { |i|
|
22
|
-
assert_equal 1 + i, @@coll.count
|
23
|
-
@@coll.insert('a' => i)
|
24
|
-
}
|
25
|
-
|
26
|
-
assert_equal 1001, @@coll.count
|
27
|
-
count = 0
|
28
|
-
@@coll.find.each { |obj|
|
29
|
-
count += obj['a']
|
30
|
-
}
|
31
|
-
assert_equal 1001, @@coll.count
|
32
|
-
|
33
|
-
# do the same thing again for debugging
|
34
|
-
assert_equal 1001, @@coll.count
|
35
|
-
count2 = 0
|
36
|
-
@@coll.find.each { |obj|
|
37
|
-
count2 += obj['a']
|
38
|
-
}
|
39
|
-
assert_equal 1001, @@coll.count
|
40
|
-
|
41
|
-
assert_equal count, count2
|
42
|
-
assert_equal 499501, count
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_refill_via_get_more_alt_coll
|
46
|
-
coll = @@db.collection('test-alt-coll')
|
47
|
-
coll.remove
|
48
|
-
coll.insert('a' => 1) # collection not created until it's used
|
49
|
-
assert_equal 1, coll.count
|
50
|
-
|
51
|
-
1000.times { |i|
|
52
|
-
assert_equal 1 + i, coll.count
|
53
|
-
coll.insert('a' => i)
|
54
|
-
}
|
55
|
-
|
56
|
-
assert_equal 1001, coll.count
|
57
|
-
count = 0
|
58
|
-
coll.find.each { |obj|
|
59
|
-
count += obj['a']
|
60
|
-
}
|
61
|
-
assert_equal 1001, coll.count
|
62
|
-
|
63
|
-
# do the same thing again for debugging
|
64
|
-
assert_equal 1001, coll.count
|
65
|
-
count2 = 0
|
66
|
-
coll.find.each { |obj|
|
67
|
-
count2 += obj['a']
|
68
|
-
}
|
69
|
-
assert_equal 1001, coll.count
|
70
|
-
|
71
|
-
assert_equal count, count2
|
72
|
-
assert_equal 499501, count
|
73
|
-
end
|
74
|
-
|
75
|
-
end
|
data/test/cursor_message_test.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
require './test/test_helper'
|
2
|
-
require 'logger'
|
3
|
-
|
4
|
-
class CursorMessageTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
include Mongo
|
7
|
-
|
8
|
-
@@connection = standard_connection
|
9
|
-
@@db = @@connection.db(MONGO_TEST_DB)
|
10
|
-
@@coll = @@db.collection('test')
|
11
|
-
@@version = @@connection.server_version
|
12
|
-
|
13
|
-
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"
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_valid_batch_sizes
|
20
|
-
assert_raise ArgumentError do
|
21
|
-
@@coll.find({}, :batch_size => 1, :limit => 5)
|
22
|
-
end
|
23
|
-
|
24
|
-
assert_raise ArgumentError do
|
25
|
-
@@coll.find({}, :batch_size => -1, :limit => 5)
|
26
|
-
end
|
27
|
-
|
28
|
-
assert @@coll.find({}, :batch_size => 0, :limit => 5)
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_batch_size
|
32
|
-
@@coll.remove
|
33
|
-
200.times do |n|
|
34
|
-
@@coll.insert({:a => n})
|
35
|
-
end
|
36
|
-
|
37
|
-
list = @@coll.find({}, :batch_size => 2, :limit => 6).to_a
|
38
|
-
assert_equal 6, list.length
|
39
|
-
|
40
|
-
list = @@coll.find({}, :batch_size => 100, :limit => 101).to_a
|
41
|
-
assert_equal 101, list.length
|
42
|
-
end
|
43
|
-
end
|