kbaum-mongo 0.18.3p
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +202 -0
- data/README.rdoc +339 -0
- data/Rakefile +138 -0
- data/bin/bson_benchmark.rb +59 -0
- data/bin/fail_if_no_c.rb +11 -0
- data/examples/admin.rb +42 -0
- data/examples/capped.rb +22 -0
- data/examples/cursor.rb +48 -0
- data/examples/gridfs.rb +88 -0
- data/examples/index_test.rb +126 -0
- data/examples/info.rb +31 -0
- data/examples/queries.rb +70 -0
- data/examples/simple.rb +24 -0
- data/examples/strict.rb +35 -0
- data/examples/types.rb +36 -0
- data/lib/mongo/collection.rb +609 -0
- data/lib/mongo/connection.rb +672 -0
- data/lib/mongo/cursor.rb +403 -0
- data/lib/mongo/db.rb +555 -0
- data/lib/mongo/exceptions.rb +66 -0
- data/lib/mongo/gridfs/chunk.rb +91 -0
- data/lib/mongo/gridfs/grid.rb +79 -0
- data/lib/mongo/gridfs/grid_file_system.rb +101 -0
- data/lib/mongo/gridfs/grid_io.rb +338 -0
- data/lib/mongo/gridfs/grid_store.rb +580 -0
- data/lib/mongo/gridfs.rb +25 -0
- data/lib/mongo/types/binary.rb +52 -0
- data/lib/mongo/types/code.rb +36 -0
- data/lib/mongo/types/dbref.rb +40 -0
- data/lib/mongo/types/min_max_keys.rb +58 -0
- data/lib/mongo/types/objectid.rb +180 -0
- data/lib/mongo/types/regexp_of_holding.rb +45 -0
- data/lib/mongo/util/bson_c.rb +18 -0
- data/lib/mongo/util/bson_ruby.rb +606 -0
- data/lib/mongo/util/byte_buffer.rb +222 -0
- data/lib/mongo/util/conversions.rb +87 -0
- data/lib/mongo/util/ordered_hash.rb +140 -0
- data/lib/mongo/util/server_version.rb +69 -0
- data/lib/mongo/util/support.rb +26 -0
- data/lib/mongo.rb +63 -0
- data/mongo-ruby-driver.gemspec +28 -0
- data/test/auxillary/autoreconnect_test.rb +42 -0
- data/test/binary_test.rb +15 -0
- data/test/bson_test.rb +427 -0
- data/test/byte_buffer_test.rb +81 -0
- data/test/chunk_test.rb +82 -0
- data/test/collection_test.rb +515 -0
- data/test/connection_test.rb +160 -0
- data/test/conversions_test.rb +120 -0
- data/test/cursor_test.rb +379 -0
- data/test/db_api_test.rb +780 -0
- data/test/db_connection_test.rb +16 -0
- data/test/db_test.rb +272 -0
- data/test/grid_file_system_test.rb +210 -0
- data/test/grid_io_test.rb +78 -0
- data/test/grid_store_test.rb +334 -0
- data/test/grid_test.rb +87 -0
- data/test/objectid_test.rb +125 -0
- data/test/ordered_hash_test.rb +172 -0
- data/test/replica/count_test.rb +34 -0
- data/test/replica/insert_test.rb +50 -0
- data/test/replica/pooled_insert_test.rb +54 -0
- data/test/replica/query_test.rb +39 -0
- data/test/slave_connection_test.rb +36 -0
- data/test/test_helper.rb +42 -0
- data/test/threading/test_threading_large_pool.rb +90 -0
- data/test/threading_test.rb +87 -0
- data/test/unit/collection_test.rb +61 -0
- data/test/unit/connection_test.rb +117 -0
- data/test/unit/cursor_test.rb +93 -0
- data/test/unit/db_test.rb +98 -0
- metadata +127 -0
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
require 'mongo/exceptions'
|
3
|
+
require 'mongo/util/conversions'
|
4
|
+
require 'mongo/util/ordered_hash'
|
5
|
+
|
6
|
+
class ConversionsTest < Test::Unit::TestCase
|
7
|
+
include Mongo::Conversions
|
8
|
+
|
9
|
+
def test_array_as_sort_parameters_with_array_of_key_and_value
|
10
|
+
params = array_as_sort_parameters(["field1", "asc"])
|
11
|
+
assert_equal({"field1" => 1}, params)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_array_as_sort_parameters_with_array_of_string_and_values
|
15
|
+
params = array_as_sort_parameters([["field1", :asc], ["field2", :desc]])
|
16
|
+
assert_equal({ "field1" => 1, "field2" => -1 }, params)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_string_as_sort_parameters_with_string
|
20
|
+
params = string_as_sort_parameters("field")
|
21
|
+
assert_equal({ "field" => 1 }, params)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_string_as_sort_parameters_with_empty_string
|
25
|
+
params = string_as_sort_parameters("")
|
26
|
+
assert_equal({}, params)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_symbol_as_sort_parameters
|
30
|
+
params = string_as_sort_parameters(:field)
|
31
|
+
assert_equal({ "field" => 1 }, params)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_sort_value_when_value_is_one
|
35
|
+
assert_equal 1, sort_value(1)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_sort_value_when_value_is_one_as_a_string
|
39
|
+
assert_equal 1, sort_value("1")
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_sort_value_when_value_is_negative_one
|
43
|
+
assert_equal -1, sort_value(-1)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_sort_value_when_value_is_negative_one_as_a_string
|
47
|
+
assert_equal -1, sort_value("-1")
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_sort_value_when_value_is_ascending
|
51
|
+
assert_equal 1, sort_value("ascending")
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_sort_value_when_value_is_asc
|
55
|
+
assert_equal 1, sort_value("asc")
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_sort_value_when_value_is_uppercase_ascending
|
59
|
+
assert_equal 1, sort_value("ASCENDING")
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_sort_value_when_value_is_uppercase_asc
|
63
|
+
assert_equal 1, sort_value("ASC")
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_sort_value_when_value_is_symbol_ascending
|
67
|
+
assert_equal 1, sort_value(:ascending)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_sort_value_when_value_is_symbol_asc
|
71
|
+
assert_equal 1, sort_value(:asc)
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_sort_value_when_value_is_symbol_uppercase_ascending
|
75
|
+
assert_equal 1, sort_value(:ASCENDING)
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_sort_value_when_value_is_symbol_uppercase_asc
|
79
|
+
assert_equal 1, sort_value(:ASC)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_sort_value_when_value_is_descending
|
83
|
+
assert_equal -1, sort_value("descending")
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_sort_value_when_value_is_desc
|
87
|
+
assert_equal -1, sort_value("desc")
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_sort_value_when_value_is_uppercase_descending
|
91
|
+
assert_equal -1, sort_value("DESCENDING")
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_sort_value_when_value_is_uppercase_desc
|
95
|
+
assert_equal -1, sort_value("DESC")
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_sort_value_when_value_is_symbol_descending
|
99
|
+
assert_equal -1, sort_value(:descending)
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_sort_value_when_value_is_symbol_desc
|
103
|
+
assert_equal -1, sort_value(:desc)
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_sort_value_when_value_is_uppercase_symbol_descending
|
107
|
+
assert_equal -1, sort_value(:DESCENDING)
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_sort_value_when_value_is_uppercase_symbol_desc
|
111
|
+
assert_equal -1, sort_value(:DESC)
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_sort_value_when_value_is_invalid
|
115
|
+
assert_raise Mongo::InvalidSortValueError do
|
116
|
+
sort_value(2)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
data/test/cursor_test.rb
ADDED
@@ -0,0 +1,379 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
require 'logger'
|
3
|
+
|
4
|
+
# NOTE: assumes Mongo is running
|
5
|
+
class CursorTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
include Mongo
|
8
|
+
|
9
|
+
@@connection = Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
|
10
|
+
ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT)
|
11
|
+
@@db = @@connection.db('ruby-mongo-test')
|
12
|
+
@@coll = @@db.collection('test')
|
13
|
+
@@version = @@connection.server_version
|
14
|
+
|
15
|
+
def setup
|
16
|
+
@@coll.remove
|
17
|
+
@@coll.insert('a' => 1) # collection not created until it's used
|
18
|
+
@@coll_full_name = 'ruby-mongo-test.test'
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_explain
|
22
|
+
cursor = @@coll.find('a' => 1)
|
23
|
+
explaination = cursor.explain
|
24
|
+
assert_not_nil explaination['cursor']
|
25
|
+
assert_kind_of Numeric, explaination['n']
|
26
|
+
assert_kind_of Numeric, explaination['millis']
|
27
|
+
assert_kind_of Numeric, explaination['nscanned']
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_count
|
31
|
+
@@coll.remove
|
32
|
+
|
33
|
+
assert_equal 0, @@coll.find().count()
|
34
|
+
|
35
|
+
10.times do |i|
|
36
|
+
@@coll.save("x" => i)
|
37
|
+
end
|
38
|
+
|
39
|
+
assert_equal 10, @@coll.find().count()
|
40
|
+
assert_kind_of Integer, @@coll.find().count()
|
41
|
+
assert_equal 10, @@coll.find({}, :limit => 5).count()
|
42
|
+
assert_equal 10, @@coll.find({}, :skip => 5).count()
|
43
|
+
|
44
|
+
assert_equal 1, @@coll.find({"x" => 1}).count()
|
45
|
+
assert_equal 5, @@coll.find({"x" => {"$lt" => 5}}).count()
|
46
|
+
|
47
|
+
a = @@coll.find()
|
48
|
+
b = a.count()
|
49
|
+
a.each do |doc|
|
50
|
+
break
|
51
|
+
end
|
52
|
+
assert_equal b, a.count()
|
53
|
+
|
54
|
+
assert_equal 0, @@db['acollectionthatdoesn'].count()
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_sort
|
58
|
+
@@coll.remove
|
59
|
+
5.times{|x| @@coll.insert({"age" => x}) }
|
60
|
+
|
61
|
+
assert_kind_of Cursor, @@coll.find().sort(:age, 1)
|
62
|
+
|
63
|
+
assert_equal 0, @@coll.find().sort(:age, 1).next_document["age"]
|
64
|
+
assert_equal 4, @@coll.find().sort(:age, -1).next_document["age"]
|
65
|
+
assert_equal 0, @@coll.find().sort([["age", :asc]]).next_document["age"]
|
66
|
+
|
67
|
+
assert_kind_of Cursor, @@coll.find().sort([[:age, -1], [:b, 1]])
|
68
|
+
|
69
|
+
assert_equal 4, @@coll.find().sort(:age, 1).sort(:age, -1).next_document["age"]
|
70
|
+
assert_equal 0, @@coll.find().sort(:age, -1).sort(:age, 1).next_document["age"]
|
71
|
+
|
72
|
+
assert_equal 4, @@coll.find().sort([:age, :asc]).sort(:age, -1).next_document["age"]
|
73
|
+
assert_equal 0, @@coll.find().sort([:age, :desc]).sort(:age, 1).next_document["age"]
|
74
|
+
|
75
|
+
cursor = @@coll.find()
|
76
|
+
cursor.next_document
|
77
|
+
assert_raise InvalidOperation do
|
78
|
+
cursor.sort(["age"])
|
79
|
+
end
|
80
|
+
|
81
|
+
assert_raise InvalidSortValueError do
|
82
|
+
@@coll.find().sort(:age, 25).next_document
|
83
|
+
end
|
84
|
+
|
85
|
+
assert_raise InvalidSortValueError do
|
86
|
+
@@coll.find().sort(25).next_document
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_sort_date
|
91
|
+
@@coll.remove
|
92
|
+
5.times{|x| @@coll.insert({"created_at" => Time.utc(2000 + x)}) }
|
93
|
+
|
94
|
+
assert_equal 2000, @@coll.find().sort(:created_at, :asc).next_document["created_at"].year
|
95
|
+
assert_equal 2004, @@coll.find().sort(:created_at, :desc).next_document["created_at"].year
|
96
|
+
|
97
|
+
assert_equal 2000, @@coll.find().sort([:created_at, :asc]).next_document["created_at"].year
|
98
|
+
assert_equal 2004, @@coll.find().sort([:created_at, :desc]).next_document["created_at"].year
|
99
|
+
|
100
|
+
assert_equal 2000, @@coll.find().sort([[:created_at, :asc]]).next_document["created_at"].year
|
101
|
+
assert_equal 2004, @@coll.find().sort([[:created_at, :desc]]).next_document["created_at"].year
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_sort_min_max_keys
|
105
|
+
@@coll.remove
|
106
|
+
@@coll.insert({"n" => 1000000})
|
107
|
+
@@coll.insert({"n" => -1000000})
|
108
|
+
@@coll.insert({"n" => MaxKey.new})
|
109
|
+
@@coll.insert({"n" => MinKey.new})
|
110
|
+
|
111
|
+
results = @@coll.find.sort([:n, :asc]).to_a
|
112
|
+
|
113
|
+
assert_equal MinKey.new, results[0]['n']
|
114
|
+
assert_equal -1000000, results[1]['n']
|
115
|
+
assert_equal 1000000, results[2]['n']
|
116
|
+
assert_equal MaxKey.new, results[3]['n']
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_id_range_queries
|
120
|
+
@@coll.remove
|
121
|
+
|
122
|
+
t1 = Time.now
|
123
|
+
t1_id = ObjectID.from_time(t1)
|
124
|
+
@@coll.save({:t => 't1'})
|
125
|
+
@@coll.save({:t => 't1'})
|
126
|
+
@@coll.save({:t => 't1'})
|
127
|
+
sleep(2)
|
128
|
+
t2 = Time.now
|
129
|
+
t2_id = ObjectID.from_time(t2)
|
130
|
+
@@coll.save({:t => 't2'})
|
131
|
+
@@coll.save({:t => 't2'})
|
132
|
+
@@coll.save({:t => 't2'})
|
133
|
+
|
134
|
+
assert_equal 3, @@coll.find({'_id' => {'$gt' => t1_id}, '_id' => {'$lt' => t2_id}}).count
|
135
|
+
@@coll.find({'_id' => {'$gt' => t2_id}}).each do |doc|
|
136
|
+
assert_equal 't2', doc['t']
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_limit
|
141
|
+
@@coll.remove
|
142
|
+
|
143
|
+
10.times do |i|
|
144
|
+
@@coll.save("x" => i)
|
145
|
+
end
|
146
|
+
assert_equal 10, @@coll.find().count()
|
147
|
+
|
148
|
+
results = @@coll.find().limit(5).to_a
|
149
|
+
assert_equal 5, results.length
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_limit_exceptions
|
153
|
+
assert_raise ArgumentError do
|
154
|
+
cursor = @@coll.find().limit('not-an-integer')
|
155
|
+
end
|
156
|
+
|
157
|
+
cursor = @@coll.find()
|
158
|
+
firstResult = cursor.next_document
|
159
|
+
assert_raise InvalidOperation, "Cannot modify the query once it has been run or closed." do
|
160
|
+
cursor.limit(1)
|
161
|
+
end
|
162
|
+
|
163
|
+
cursor = @@coll.find()
|
164
|
+
cursor.close
|
165
|
+
assert_raise InvalidOperation, "Cannot modify the query once it has been run or closed." do
|
166
|
+
cursor.limit(1)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_skip
|
171
|
+
@@coll.remove
|
172
|
+
|
173
|
+
10.times do |i|
|
174
|
+
@@coll.save("x" => i)
|
175
|
+
end
|
176
|
+
assert_equal 10, @@coll.find().count()
|
177
|
+
|
178
|
+
all_results = @@coll.find().to_a
|
179
|
+
skip_results = @@coll.find().skip(2).to_a
|
180
|
+
assert_equal 10, all_results.length
|
181
|
+
assert_equal 8, skip_results.length
|
182
|
+
|
183
|
+
assert_equal all_results.slice(2...10), skip_results
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_skip_exceptions
|
187
|
+
assert_raise ArgumentError do
|
188
|
+
cursor = @@coll.find().skip('not-an-integer')
|
189
|
+
end
|
190
|
+
|
191
|
+
cursor = @@coll.find()
|
192
|
+
firstResult = cursor.next_document
|
193
|
+
assert_raise InvalidOperation, "Cannot modify the query once it has been run or closed." do
|
194
|
+
cursor.skip(1)
|
195
|
+
end
|
196
|
+
|
197
|
+
cursor = @@coll.find()
|
198
|
+
cursor.close
|
199
|
+
assert_raise InvalidOperation, "Cannot modify the query once it has been run or closed." do
|
200
|
+
cursor.skip(1)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
def test_limit_skip_chaining
|
205
|
+
@@coll.remove
|
206
|
+
10.times do |i|
|
207
|
+
@@coll.save("x" => i)
|
208
|
+
end
|
209
|
+
|
210
|
+
all_results = @@coll.find().to_a
|
211
|
+
limited_skip_results = @@coll.find().limit(5).skip(3).to_a
|
212
|
+
|
213
|
+
assert_equal all_results.slice(3...8), limited_skip_results
|
214
|
+
end
|
215
|
+
|
216
|
+
def test_close_no_query_sent
|
217
|
+
begin
|
218
|
+
cursor = @@coll.find('a' => 1)
|
219
|
+
cursor.close
|
220
|
+
assert cursor.closed?
|
221
|
+
rescue => ex
|
222
|
+
fail ex.to_s
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
def test_refill_via_get_more
|
227
|
+
assert_equal 1, @@coll.count
|
228
|
+
1000.times { |i|
|
229
|
+
assert_equal 1 + i, @@coll.count
|
230
|
+
@@coll.insert('a' => i)
|
231
|
+
}
|
232
|
+
|
233
|
+
assert_equal 1001, @@coll.count
|
234
|
+
count = 0
|
235
|
+
@@coll.find.each { |obj|
|
236
|
+
count += obj['a']
|
237
|
+
}
|
238
|
+
assert_equal 1001, @@coll.count
|
239
|
+
|
240
|
+
# do the same thing again for debugging
|
241
|
+
assert_equal 1001, @@coll.count
|
242
|
+
count2 = 0
|
243
|
+
@@coll.find.each { |obj|
|
244
|
+
count2 += obj['a']
|
245
|
+
}
|
246
|
+
assert_equal 1001, @@coll.count
|
247
|
+
|
248
|
+
assert_equal count, count2
|
249
|
+
assert_equal 499501, count
|
250
|
+
end
|
251
|
+
|
252
|
+
def test_refill_via_get_more_alt_coll
|
253
|
+
coll = @@db.collection('test-alt-coll')
|
254
|
+
coll.remove
|
255
|
+
coll.insert('a' => 1) # collection not created until it's used
|
256
|
+
assert_equal 1, coll.count
|
257
|
+
|
258
|
+
1000.times { |i|
|
259
|
+
assert_equal 1 + i, coll.count
|
260
|
+
coll.insert('a' => i)
|
261
|
+
}
|
262
|
+
|
263
|
+
assert_equal 1001, coll.count
|
264
|
+
count = 0
|
265
|
+
coll.find.each { |obj|
|
266
|
+
count += obj['a']
|
267
|
+
}
|
268
|
+
assert_equal 1001, coll.count
|
269
|
+
|
270
|
+
# do the same thing again for debugging
|
271
|
+
assert_equal 1001, coll.count
|
272
|
+
count2 = 0
|
273
|
+
coll.find.each { |obj|
|
274
|
+
count2 += obj['a']
|
275
|
+
}
|
276
|
+
assert_equal 1001, coll.count
|
277
|
+
|
278
|
+
assert_equal count, count2
|
279
|
+
assert_equal 499501, count
|
280
|
+
end
|
281
|
+
|
282
|
+
def test_close_after_query_sent
|
283
|
+
begin
|
284
|
+
cursor = @@coll.find('a' => 1)
|
285
|
+
cursor.next_document
|
286
|
+
cursor.close
|
287
|
+
assert cursor.closed?
|
288
|
+
rescue => ex
|
289
|
+
fail ex.to_s
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
def test_kill_cursors
|
294
|
+
@@coll.drop
|
295
|
+
|
296
|
+
client_cursors = @@db.command("cursorInfo" => 1)["clientCursors_size"]
|
297
|
+
by_location = @@db.command("cursorInfo" => 1)["byLocation_size"]
|
298
|
+
|
299
|
+
10000.times do |i|
|
300
|
+
@@coll.insert("i" => i)
|
301
|
+
end
|
302
|
+
|
303
|
+
assert_equal(client_cursors,
|
304
|
+
@@db.command("cursorInfo" => 1)["clientCursors_size"])
|
305
|
+
assert_equal(by_location,
|
306
|
+
@@db.command("cursorInfo" => 1)["byLocation_size"])
|
307
|
+
|
308
|
+
10.times do |i|
|
309
|
+
@@coll.find_one()
|
310
|
+
end
|
311
|
+
|
312
|
+
assert_equal(client_cursors,
|
313
|
+
@@db.command("cursorInfo" => 1)["clientCursors_size"])
|
314
|
+
assert_equal(by_location,
|
315
|
+
@@db.command("cursorInfo" => 1)["byLocation_size"])
|
316
|
+
|
317
|
+
10.times do |i|
|
318
|
+
a = @@coll.find()
|
319
|
+
a.next_document
|
320
|
+
a.close()
|
321
|
+
end
|
322
|
+
|
323
|
+
assert_equal(client_cursors,
|
324
|
+
@@db.command("cursorInfo" => 1)["clientCursors_size"])
|
325
|
+
assert_equal(by_location,
|
326
|
+
@@db.command("cursorInfo" => 1)["byLocation_size"])
|
327
|
+
|
328
|
+
a = @@coll.find()
|
329
|
+
a.next_document
|
330
|
+
|
331
|
+
assert_not_equal(client_cursors,
|
332
|
+
@@db.command("cursorInfo" => 1)["clientCursors_size"])
|
333
|
+
assert_not_equal(by_location,
|
334
|
+
@@db.command("cursorInfo" => 1)["byLocation_size"])
|
335
|
+
|
336
|
+
a.close()
|
337
|
+
|
338
|
+
assert_equal(client_cursors,
|
339
|
+
@@db.command("cursorInfo" => 1)["clientCursors_size"])
|
340
|
+
assert_equal(by_location,
|
341
|
+
@@db.command("cursorInfo" => 1)["byLocation_size"])
|
342
|
+
|
343
|
+
a = @@coll.find({}, :limit => 10).next_document
|
344
|
+
|
345
|
+
assert_equal(client_cursors,
|
346
|
+
@@db.command("cursorInfo" => 1)["clientCursors_size"])
|
347
|
+
assert_equal(by_location,
|
348
|
+
@@db.command("cursorInfo" => 1)["byLocation_size"])
|
349
|
+
|
350
|
+
@@coll.find() do |cursor|
|
351
|
+
cursor.next_document
|
352
|
+
end
|
353
|
+
|
354
|
+
assert_equal(client_cursors,
|
355
|
+
@@db.command("cursorInfo" => 1)["clientCursors_size"])
|
356
|
+
assert_equal(by_location,
|
357
|
+
@@db.command("cursorInfo" => 1)["byLocation_size"])
|
358
|
+
|
359
|
+
@@coll.find() { |cursor|
|
360
|
+
cursor.next_document
|
361
|
+
}
|
362
|
+
|
363
|
+
assert_equal(client_cursors,
|
364
|
+
@@db.command("cursorInfo" => 1)["clientCursors_size"])
|
365
|
+
assert_equal(by_location,
|
366
|
+
@@db.command("cursorInfo" => 1)["byLocation_size"])
|
367
|
+
end
|
368
|
+
|
369
|
+
def test_count_with_fields
|
370
|
+
@@coll.remove
|
371
|
+
@@coll.save("x" => 1)
|
372
|
+
|
373
|
+
if @@version < "1.1.3"
|
374
|
+
assert_equal(0, @@coll.find({}, :fields => ["a"]).count())
|
375
|
+
else
|
376
|
+
assert_equal(1, @@coll.find({}, :fields => ["a"]).count())
|
377
|
+
end
|
378
|
+
end
|
379
|
+
end
|