mongo 1.7.1 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/{LICENSE.txt → LICENSE} +0 -0
- data/README.md +124 -111
- data/Rakefile +9 -325
- data/VERSION +1 -0
- data/bin/mongo_console +4 -4
- data/examples/admin.rb +43 -0
- data/examples/capped.rb +22 -0
- data/examples/cursor.rb +48 -0
- data/examples/gridfs.rb +44 -0
- data/examples/index_test.rb +126 -0
- data/examples/info.rb +31 -0
- data/examples/queries.rb +74 -0
- data/examples/replica_set.rb +26 -0
- data/examples/simple.rb +25 -0
- data/examples/strict.rb +35 -0
- data/examples/types.rb +36 -0
- data/{test/load → examples/web}/thin/load.rb +3 -1
- data/{test/load → examples/web}/unicorn/load.rb +5 -3
- data/lib/mongo.rb +8 -10
- data/lib/mongo/collection.rb +134 -114
- data/lib/mongo/cursor.rb +21 -14
- data/lib/mongo/db.rb +30 -28
- data/lib/mongo/exceptions.rb +1 -1
- data/lib/mongo/gridfs/grid.rb +8 -7
- data/lib/mongo/gridfs/grid_ext.rb +1 -1
- data/lib/mongo/gridfs/grid_file_system.rb +6 -5
- data/lib/mongo/gridfs/grid_io.rb +22 -19
- data/lib/mongo/legacy.rb +82 -0
- data/lib/mongo/{connection.rb → mongo_client.rb} +82 -61
- data/lib/mongo/{repl_set_connection.rb → mongo_replica_set_client.rb} +54 -39
- data/lib/mongo/{sharded_connection.rb → mongo_sharded_client.rb} +9 -9
- data/lib/mongo/networking.rb +25 -20
- data/lib/mongo/util/conversions.rb +1 -1
- data/lib/mongo/util/core_ext.rb +1 -1
- data/lib/mongo/util/logging.rb +20 -4
- data/lib/mongo/util/node.rb +16 -16
- data/lib/mongo/util/pool.rb +56 -27
- data/lib/mongo/util/pool_manager.rb +28 -27
- data/lib/mongo/util/server_version.rb +1 -1
- data/lib/mongo/util/sharding_pool_manager.rb +8 -8
- data/lib/mongo/util/ssl_socket.rb +1 -5
- data/lib/mongo/util/support.rb +24 -8
- data/lib/mongo/util/tcp_socket.rb +0 -4
- data/lib/mongo/util/uri_parser.rb +54 -38
- data/lib/mongo/util/write_concern.rb +67 -0
- data/mongo.gemspec +21 -32
- data/test/auxillary/{1.4_features.rb → 1.4_feature_test.rb} +4 -5
- data/test/auxillary/authentication_test.rb +18 -20
- data/test/auxillary/autoreconnect_test.rb +3 -5
- data/test/auxillary/fork_test.rb +5 -7
- data/test/auxillary/repl_set_auth_test.rb +13 -15
- data/test/auxillary/slave_connection_test.rb +8 -7
- data/test/auxillary/threaded_authentication_test.rb +15 -17
- data/test/bson/binary_test.rb +1 -1
- data/test/bson/bson_test.rb +60 -36
- data/test/bson/byte_buffer_test.rb +1 -1
- data/test/bson/hash_with_indifferent_access_test.rb +2 -2
- data/test/bson/json_test.rb +1 -2
- data/test/bson/object_id_test.rb +1 -2
- data/test/bson/ordered_hash_test.rb +1 -1
- data/test/bson/timestamp_test.rb +1 -1
- data/test/{collection_test.rb → functional/collection_test.rb} +57 -57
- data/test/{connection_test.rb → functional/connection_test.rb} +75 -89
- data/test/{conversions_test.rb → functional/conversions_test.rb} +1 -1
- data/test/{cursor_fail_test.rb → functional/cursor_fail_test.rb} +3 -29
- data/test/{cursor_message_test.rb → functional/cursor_message_test.rb} +1 -1
- data/test/{cursor_test.rb → functional/cursor_test.rb} +5 -1
- data/test/{db_api_test.rb → functional/db_api_test.rb} +8 -9
- data/test/{db_connection_test.rb → functional/db_connection_test.rb} +3 -5
- data/test/{db_test.rb → functional/db_test.rb} +13 -13
- data/test/{grid_file_system_test.rb → functional/grid_file_system_test.rb} +2 -2
- data/test/{grid_io_test.rb → functional/grid_io_test.rb} +6 -6
- data/test/{grid_test.rb → functional/grid_test.rb} +4 -10
- data/test/{pool_test.rb → functional/pool_test.rb} +1 -1
- data/test/functional/safe_test.rb +84 -0
- data/test/{support_test.rb → functional/support_test.rb} +1 -1
- data/test/{threading_test.rb → functional/threading_test.rb} +9 -9
- data/test/{timeout_test.rb → functional/timeout_test.rb} +1 -1
- data/test/{uri_test.rb → functional/uri_test.rb} +1 -1
- data/test/functional/write_concern_test.rb +104 -0
- data/test/replica_set/basic_test.rb +139 -0
- data/test/replica_set/client_test.rb +255 -0
- data/test/replica_set/complex_connect_test.rb +62 -0
- data/test/replica_set/connection_test.rb +255 -0
- data/test/{replica_sets → replica_set}/count_test.rb +17 -14
- data/test/replica_set/cursor_test.rb +75 -0
- data/test/{replica_sets → replica_set}/insert_test.rb +19 -16
- data/test/replica_set/query_test.rb +64 -0
- data/test/replica_set/refresh_test.rb +153 -0
- data/test/{replica_sets → replica_set}/replication_ack_test.rb +21 -17
- data/test/sharded_cluster/basic_test.rb +31 -50
- data/test/support/hash_with_indifferent_access.rb +1 -1
- data/test/test_helper.rb +56 -9
- data/test/threading/threading_with_large_pool_test.rb +8 -8
- data/test/tools/mongo_config.rb +270 -58
- data/test/tools/mongo_config_test.rb +146 -0
- data/test/unit/client_test.rb +230 -0
- data/test/unit/collection_test.rb +45 -32
- data/test/unit/connection_test.rb +82 -74
- data/test/unit/cursor_test.rb +14 -6
- data/test/unit/db_test.rb +8 -8
- data/test/unit/grid_test.rb +11 -11
- data/test/unit/node_test.rb +24 -24
- data/test/unit/pool_manager_test.rb +13 -13
- data/test/unit/pool_test.rb +1 -1
- data/test/unit/read_test.rb +21 -26
- data/test/unit/safe_test.rb +52 -33
- data/test/unit/util_test.rb +55 -0
- data/test/unit/write_concern_test.rb +161 -0
- metadata +158 -171
- data/docs/CREDITS.md +0 -123
- data/docs/FAQ.md +0 -116
- data/docs/GRID_FS.md +0 -158
- data/docs/HISTORY.md +0 -392
- data/docs/READ_PREFERENCE.md +0 -99
- data/docs/RELEASES.md +0 -54
- data/docs/REPLICA_SETS.md +0 -113
- data/docs/TAILABLE_CURSORS.md +0 -51
- data/docs/TUTORIAL.md +0 -356
- data/docs/WRITE_CONCERN.md +0 -31
- data/lib/mongo/gridfs/grid_io_fix.rb +0 -38
- data/lib/mongo/version.rb +0 -3
- data/test/bson/test_helper.rb +0 -30
- data/test/replica_sets/basic_test.rb +0 -119
- data/test/replica_sets/complex_connect_test.rb +0 -57
- data/test/replica_sets/complex_read_preference_test.rb +0 -237
- data/test/replica_sets/connect_test.rb +0 -156
- data/test/replica_sets/cursor_test.rb +0 -70
- data/test/replica_sets/pooled_insert_test.rb +0 -57
- data/test/replica_sets/query_test.rb +0 -50
- data/test/replica_sets/read_preference_test.rb +0 -234
- data/test/replica_sets/refresh_test.rb +0 -156
- data/test/replica_sets/refresh_with_threads_test.rb +0 -60
- data/test/replica_sets/rs_test_helper.rb +0 -39
- data/test/safe_test.rb +0 -68
- data/test/sharded_cluster/mongo_config_test.rb +0 -126
- data/test/sharded_cluster/sc_test_helper.rb +0 -39
- data/test/tools/repl_set_manager.rb +0 -418
@@ -1,132 +1,140 @@
|
|
1
|
-
require
|
2
|
-
include Mongo
|
1
|
+
require 'test_helper'
|
3
2
|
|
4
3
|
class ConnectionTest < Test::Unit::TestCase
|
5
|
-
context "
|
4
|
+
context "Mongo::MongoClient intialization " do
|
6
5
|
context "given a single node" do
|
7
6
|
setup do
|
8
|
-
@
|
7
|
+
@connection = Mongo::Connection.new('localhost', 27017, :safe => true, :connect => false)
|
9
8
|
TCPSocket.stubs(:new).returns(new_mock_socket)
|
10
9
|
|
11
10
|
admin_db = new_mock_db
|
12
11
|
admin_db.expects(:command).returns({'ok' => 1, 'ismaster' => 1})
|
13
|
-
@
|
14
|
-
@
|
12
|
+
@connection.expects(:[]).with('admin').returns(admin_db)
|
13
|
+
@connection.connect
|
14
|
+
end
|
15
|
+
|
16
|
+
should "set safe mode true" do
|
17
|
+
assert_equal true, @connection.safe
|
15
18
|
end
|
16
19
|
|
17
20
|
should "set localhost and port to master" do
|
18
|
-
assert_equal 'localhost', @
|
19
|
-
assert_equal 27017, @
|
21
|
+
assert_equal 'localhost', @connection.primary_pool.host
|
22
|
+
assert_equal 27017, @connection.primary_pool.port
|
20
23
|
end
|
21
24
|
|
22
25
|
should "set connection pool to 1" do
|
23
|
-
assert_equal 1, @
|
26
|
+
assert_equal 1, @connection.primary_pool.size
|
24
27
|
end
|
25
28
|
|
26
29
|
should "default slave_ok to false" do
|
27
|
-
assert !@
|
30
|
+
assert !@connection.slave_ok?
|
31
|
+
end
|
32
|
+
|
33
|
+
should "raise exception for invalid host or port" do
|
34
|
+
assert_raise MongoArgumentError do
|
35
|
+
Mongo::Connection.new(:safe => true)
|
36
|
+
end
|
37
|
+
assert_raise MongoArgumentError do
|
38
|
+
Mongo::Connection.new('localhost', :safe => true)
|
39
|
+
end
|
28
40
|
end
|
29
41
|
|
30
42
|
should "warn if invalid options are specified" do
|
31
|
-
|
43
|
+
connection = Mongo::Connection.allocate
|
32
44
|
opts = {:connect => false}
|
33
45
|
|
34
|
-
ReplSetConnection::REPL_SET_OPTS.each do |opt|
|
35
|
-
|
46
|
+
Mongo::ReplSetConnection::REPL_SET_OPTS.each do |opt|
|
47
|
+
connection.expects(:warn).with("#{opt} is not a valid option for #{connection.class}")
|
36
48
|
opts[opt] = true
|
37
49
|
end
|
38
50
|
|
39
51
|
args = ['localhost', 27017, opts]
|
40
|
-
|
52
|
+
connection.send(:initialize, *args)
|
41
53
|
end
|
42
54
|
|
43
55
|
context "given a replica set" do
|
44
|
-
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
args = [['localhost:27017'], opts]
|
60
|
-
conn.send(:initialize, *args)
|
61
|
-
end
|
56
|
+
|
57
|
+
# should "warn if invalid options are specified" do
|
58
|
+
# connection = Mongo::ReplSetConnection.allocate
|
59
|
+
# opts = {:connect => false}
|
60
|
+
|
61
|
+
# # Mongo::Connection::CLIENT_ONLY_OPTS.each do |opt|
|
62
|
+
# connection.expects(:warn).with("#{:slave_ok} is not a valid option for #{connection.class}")
|
63
|
+
# opts[:slave_ok] = true
|
64
|
+
# # end
|
65
|
+
|
66
|
+
# args = [['localhost:27017'], opts]
|
67
|
+
# connection.send(:initialize, *args)
|
68
|
+
# end
|
69
|
+
|
62
70
|
end
|
63
71
|
end
|
64
72
|
|
65
73
|
context "initializing with a mongodb uri" do
|
66
74
|
should "parse a simple uri" do
|
67
|
-
@
|
68
|
-
assert_equal ['localhost', 27017], @
|
75
|
+
@connection = Mongo::Connection.from_uri("mongodb://localhost", :connect => false)
|
76
|
+
assert_equal ['localhost', 27017], @connection.host_to_try
|
69
77
|
end
|
70
78
|
|
71
79
|
should "allow a complex host names" do
|
72
80
|
host_name = "foo.bar-12345.org"
|
73
|
-
@
|
74
|
-
assert_equal [host_name, 27017], @
|
81
|
+
@connection = Mongo::Connection.from_uri("mongodb://#{host_name}", :connect => false)
|
82
|
+
assert_equal [host_name, 27017], @connection.host_to_try
|
75
83
|
end
|
76
84
|
|
77
85
|
should "allow db without username and password" do
|
78
86
|
host_name = "foo.bar-12345.org"
|
79
|
-
@
|
80
|
-
assert_equal [host_name, 27017], @
|
87
|
+
@connection = Mongo::Connection.from_uri("mongodb://#{host_name}/foo", :connect => false)
|
88
|
+
assert_equal [host_name, 27017], @connection.host_to_try
|
81
89
|
end
|
82
90
|
|
83
91
|
should "set safe options on connection" do
|
84
92
|
host_name = "localhost"
|
85
93
|
opts = "safe=true&w=2&wtimeoutMS=1000&fsync=true&journal=true"
|
86
|
-
@
|
87
|
-
assert_equal({:w => 2, :wtimeout => 1000, :fsync => true, :j => true}, @
|
94
|
+
@connection = Mongo::Connection.from_uri("mongodb://#{host_name}/foo?#{opts}", :connect => false)
|
95
|
+
assert_equal({:w => 2, :wtimeout => 1000, :fsync => true, :j => true}, @connection.write_concern)
|
88
96
|
end
|
89
97
|
|
90
98
|
should "set timeout options on connection" do
|
91
99
|
host_name = "localhost"
|
92
100
|
opts = "connectTimeoutMS=1000&socketTimeoutMS=5000"
|
93
|
-
@
|
94
|
-
assert_equal 1, @
|
95
|
-
assert_equal 5, @
|
101
|
+
@connection = Mongo::Connection.from_uri("mongodb://#{host_name}/foo?#{opts}", :connect => false)
|
102
|
+
assert_equal 1, @connection.connect_timeout
|
103
|
+
assert_equal 5, @connection.op_timeout
|
96
104
|
end
|
97
105
|
|
98
106
|
should "parse a uri with a hyphen & underscore in the username or password" do
|
99
|
-
@
|
100
|
-
assert_equal ['localhost', 27017], @
|
107
|
+
@connection = Mongo::Connection.from_uri("mongodb://hyphen-user_name:p-s_s@localhost:27017/db", :connect => false)
|
108
|
+
assert_equal ['localhost', 27017], @connection.host_to_try
|
101
109
|
auth_hash = { 'db_name' => 'db', 'username' => 'hyphen-user_name', "password" => 'p-s_s' }
|
102
|
-
assert_equal auth_hash, @
|
110
|
+
assert_equal auth_hash, @connection.auths[0]
|
103
111
|
end
|
104
112
|
|
105
113
|
should "attempt to connect" do
|
106
114
|
TCPSocket.stubs(:new).returns(new_mock_socket)
|
107
|
-
@
|
115
|
+
@connection = Mongo::Connection.from_uri("mongodb://localhost", :connect => false)
|
108
116
|
|
109
117
|
admin_db = new_mock_db
|
110
118
|
admin_db.expects(:command).returns({'ok' => 1, 'ismaster' => 1})
|
111
|
-
@
|
112
|
-
@
|
119
|
+
@connection.expects(:[]).with('admin').returns(admin_db)
|
120
|
+
@connection.connect
|
113
121
|
end
|
114
122
|
|
115
123
|
should "raise an error on invalid uris" do
|
116
124
|
assert_raise MongoArgumentError do
|
117
|
-
Connection.from_uri("mongo://localhost", :connect => false)
|
125
|
+
Mongo::Connection.from_uri("mongo://localhost", :connect => false)
|
118
126
|
end
|
119
127
|
|
120
128
|
assert_raise MongoArgumentError do
|
121
|
-
Connection.from_uri("mongodb://localhost:abc", :connect => false)
|
129
|
+
Mongo::Connection.from_uri("mongodb://localhost:abc", :connect => false)
|
122
130
|
end
|
123
131
|
end
|
124
132
|
|
125
133
|
should "require all of username, if password and db are specified" do
|
126
|
-
assert Connection.from_uri("mongodb://kyle:jones@localhost/db", :connect => false)
|
134
|
+
assert Mongo::Connection.from_uri("mongodb://kyle:jones@localhost/db", :connect => false)
|
127
135
|
|
128
136
|
assert_raise MongoArgumentError do
|
129
|
-
Connection.from_uri("mongodb://kyle:password@localhost", :connect => false)
|
137
|
+
Mongo::Connection.from_uri("mongodb://kyle:password@localhost", :connect => false)
|
130
138
|
end
|
131
139
|
end
|
132
140
|
end
|
@@ -142,79 +150,79 @@ class ConnectionTest < Test::Unit::TestCase
|
|
142
150
|
|
143
151
|
should "parse a simple uri" do
|
144
152
|
ENV['MONGODB_URI'] = "mongodb://localhost?connect=false"
|
145
|
-
@
|
146
|
-
assert_equal ['localhost', 27017], @
|
153
|
+
@connection = Mongo::Connection.new
|
154
|
+
assert_equal ['localhost', 27017], @connection.host_to_try
|
147
155
|
end
|
148
156
|
|
149
157
|
should "allow a complex host names" do
|
150
158
|
host_name = "foo.bar-12345.org"
|
151
159
|
ENV['MONGODB_URI'] = "mongodb://#{host_name}?connect=false"
|
152
|
-
@
|
153
|
-
assert_equal [host_name, 27017], @
|
160
|
+
@connection = Mongo::Connection.new
|
161
|
+
assert_equal [host_name, 27017], @connection.host_to_try
|
154
162
|
end
|
155
163
|
|
156
164
|
should "allow db without username and password" do
|
157
165
|
host_name = "foo.bar-12345.org"
|
158
166
|
ENV['MONGODB_URI'] = "mongodb://#{host_name}/foo?connect=false"
|
159
|
-
@
|
160
|
-
assert_equal [host_name, 27017], @
|
167
|
+
@connection = Mongo::Connection.new
|
168
|
+
assert_equal [host_name, 27017], @connection.host_to_try
|
161
169
|
end
|
162
170
|
|
163
171
|
should "set safe options on connection" do
|
164
172
|
host_name = "localhost"
|
165
173
|
opts = "safe=true&w=2&wtimeoutMS=1000&fsync=true&journal=true&connect=false"
|
166
174
|
ENV['MONGODB_URI'] = "mongodb://#{host_name}/foo?#{opts}"
|
167
|
-
@
|
168
|
-
assert_equal({:w => 2, :wtimeout => 1000, :fsync => true, :j => true}, @
|
175
|
+
@connection = Mongo::Connection.new
|
176
|
+
assert_equal({:w => 2, :wtimeout => 1000, :fsync => true, :j => true}, @connection.safe)
|
169
177
|
end
|
170
178
|
|
171
179
|
should "set timeout options on connection" do
|
172
180
|
host_name = "localhost"
|
173
181
|
opts = "connectTimeoutMS=1000&socketTimeoutMS=5000&connect=false"
|
174
182
|
ENV['MONGODB_URI'] = "mongodb://#{host_name}/foo?#{opts}"
|
175
|
-
@
|
176
|
-
assert_equal 1, @
|
177
|
-
assert_equal 5, @
|
183
|
+
@connection = Mongo::Connection.new
|
184
|
+
assert_equal 1, @connection.connect_timeout
|
185
|
+
assert_equal 5, @connection.op_timeout
|
178
186
|
end
|
179
187
|
|
180
188
|
should "parse a uri with a hyphen & underscore in the username or password" do
|
181
189
|
ENV['MONGODB_URI'] = "mongodb://hyphen-user_name:p-s_s@localhost:27017/db?connect=false"
|
182
|
-
@
|
183
|
-
assert_equal ['localhost', 27017], @
|
190
|
+
@connection = Mongo::Connection.new
|
191
|
+
assert_equal ['localhost', 27017], @connection.host_to_try
|
184
192
|
auth_hash = { 'db_name' => 'db', 'username' => 'hyphen-user_name', "password" => 'p-s_s' }
|
185
|
-
assert_equal auth_hash, @
|
193
|
+
assert_equal auth_hash, @connection.auths[0]
|
186
194
|
end
|
187
195
|
|
188
196
|
should "attempt to connect" do
|
189
197
|
TCPSocket.stubs(:new).returns(new_mock_socket)
|
190
198
|
ENV['MONGODB_URI'] = "mongodb://localhost?connect=false" # connect=false ??
|
191
|
-
@
|
199
|
+
@connection = Mongo::Connection.new
|
192
200
|
|
193
201
|
admin_db = new_mock_db
|
194
202
|
admin_db.expects(:command).returns({'ok' => 1, 'ismaster' => 1})
|
195
|
-
@
|
196
|
-
@
|
203
|
+
@connection.expects(:[]).with('admin').returns(admin_db)
|
204
|
+
@connection.connect
|
197
205
|
end
|
198
206
|
|
199
207
|
should "raise an error on invalid uris" do
|
200
208
|
ENV['MONGODB_URI'] = "mongo://localhost"
|
201
209
|
assert_raise MongoArgumentError do
|
202
|
-
Connection.new
|
210
|
+
Mongo::Connection.new
|
203
211
|
end
|
204
212
|
|
205
213
|
ENV['MONGODB_URI'] = "mongodb://localhost:abc"
|
206
214
|
assert_raise MongoArgumentError do
|
207
|
-
Connection.new
|
215
|
+
Mongo::Connection.new
|
208
216
|
end
|
209
217
|
end
|
210
218
|
|
211
219
|
should "require all of username, if password and db are specified" do
|
212
220
|
ENV['MONGODB_URI'] = "mongodb://kyle:jones@localhost/db?connect=false"
|
213
|
-
assert Connection.new
|
221
|
+
assert Mongo::Connection.new
|
214
222
|
|
215
223
|
ENV['MONGODB_URI'] = "mongodb://kyle:password@localhost"
|
216
224
|
assert_raise MongoArgumentError do
|
217
|
-
Connection.new
|
225
|
+
Mongo::Connection.new
|
218
226
|
end
|
219
227
|
end
|
220
228
|
end
|
data/test/unit/cursor_test.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
require
|
1
|
+
require 'test_helper'
|
2
2
|
|
3
3
|
class CursorTest < Test::Unit::TestCase
|
4
4
|
context "Cursor options" do
|
5
5
|
setup do
|
6
6
|
@logger = mock()
|
7
7
|
@logger.stubs(:debug)
|
8
|
-
@connection = stub(:class =>
|
8
|
+
@connection = stub(:class => MongoClient, :logger => @logger,
|
9
9
|
:slave_ok? => false, :read_preference => :primary, :log_duration => false,
|
10
10
|
:tag_sets => {}, :acceptable_latency => 10)
|
11
11
|
@db = stub(:name => "testing", :slave_ok? => false,
|
@@ -78,23 +78,31 @@ class CursorTest < Test::Unit::TestCase
|
|
78
78
|
assert_equal "name", @cursor.query_options_hash[:hint]
|
79
79
|
end
|
80
80
|
|
81
|
+
should "set comment" do
|
82
|
+
assert_nil @cursor.comment
|
83
|
+
|
84
|
+
@cursor = Cursor.new(@collection, :comment => "comment")
|
85
|
+
assert_equal "comment", @cursor.comment
|
86
|
+
assert_equal "comment", @cursor.query_options_hash[:comment]
|
87
|
+
end
|
88
|
+
|
81
89
|
should "cache full collection name" do
|
82
90
|
assert_equal "testing.items", @cursor.full_collection_name
|
83
91
|
end
|
84
|
-
|
92
|
+
|
85
93
|
should "raise error when batch_size is 1" do
|
86
94
|
e = assert_raise ArgumentError do
|
87
95
|
@cursor.batch_size(1)
|
88
96
|
end
|
89
97
|
assert_equal "Invalid value for batch_size 1; must be 0 or > 1.", e.message
|
90
98
|
end
|
91
|
-
|
99
|
+
|
92
100
|
should "use the limit for batch size when it's smaller than the specified batch_size" do
|
93
101
|
@cursor.limit(99)
|
94
102
|
@cursor.batch_size(100)
|
95
103
|
assert_equal 99, @cursor.batch_size
|
96
104
|
end
|
97
|
-
|
105
|
+
|
98
106
|
should "use the specified batch_size" do
|
99
107
|
@cursor.batch_size(100)
|
100
108
|
assert_equal 100, @cursor.batch_size
|
@@ -105,7 +113,7 @@ class CursorTest < Test::Unit::TestCase
|
|
105
113
|
setup do
|
106
114
|
@logger = mock()
|
107
115
|
@logger.stubs(:debug)
|
108
|
-
@connection = stub(:class =>
|
116
|
+
@connection = stub(:class => MongoClient, :logger => @logger, :slave_ok? => false,
|
109
117
|
:log_duration => false, :tag_sets =>{}, :acceptable_latency => 10)
|
110
118
|
@db = stub(:slave_ok? => true, :name => "testing", :connection => @connection,
|
111
119
|
:tag_sets => {}, :acceptable_latency => 10)
|
data/test/unit/db_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'test_helper'
|
2
2
|
|
3
3
|
def insert_message(db, documents)
|
4
4
|
documents = [documents] unless documents.is_a?(Array)
|
@@ -13,12 +13,12 @@ class DBTest < Test::Unit::TestCase
|
|
13
13
|
context "DBTest: " do
|
14
14
|
context "DB commands" do
|
15
15
|
setup do
|
16
|
-
@
|
17
|
-
@
|
18
|
-
@
|
19
|
-
@
|
20
|
-
@
|
21
|
-
@db
|
16
|
+
@client = stub()
|
17
|
+
@client.stubs(:write_concern).returns({})
|
18
|
+
@client.stubs(:read_preference)
|
19
|
+
@client.stubs(:tag_sets)
|
20
|
+
@client.stubs(:acceptable_latency)
|
21
|
+
@db = DB.new("testing", @client)
|
22
22
|
@db.stubs(:safe)
|
23
23
|
@db.stubs(:read_preference)
|
24
24
|
@db.stubs(:tag_sets)
|
@@ -61,7 +61,7 @@ class DBTest < Test::Unit::TestCase
|
|
61
61
|
|
62
62
|
should "raise an error if logging out fails" do
|
63
63
|
@db.expects(:command).returns({})
|
64
|
-
@
|
64
|
+
@client.expects(:pool_size).returns(1)
|
65
65
|
assert_raise Mongo::MongoDBError do
|
66
66
|
@db.logout
|
67
67
|
end
|
data/test/unit/grid_test.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
require
|
1
|
+
require 'test_helper'
|
2
2
|
|
3
3
|
class GridTest < Test::Unit::TestCase
|
4
4
|
|
5
5
|
context "GridFS: " do
|
6
6
|
setup do
|
7
|
-
@
|
8
|
-
@
|
9
|
-
@
|
10
|
-
@
|
11
|
-
@
|
12
|
-
@db = DB.new("testing", @
|
7
|
+
@client = stub()
|
8
|
+
@client.stubs(:write_concern).returns({})
|
9
|
+
@client.stubs(:read_preference)
|
10
|
+
@client.stubs(:tag_sets)
|
11
|
+
@client.stubs(:acceptable_latency)
|
12
|
+
@db = DB.new("testing", @client)
|
13
13
|
@files = mock()
|
14
14
|
@chunks = mock()
|
15
15
|
|
@@ -21,8 +21,8 @@ class GridTest < Test::Unit::TestCase
|
|
21
21
|
|
22
22
|
context "Grid classe with standard connections" do
|
23
23
|
setup do
|
24
|
-
@
|
25
|
-
@
|
24
|
+
@client.expects(:class).returns(MongoClient)
|
25
|
+
@client.expects(:read_primary?).returns(true)
|
26
26
|
end
|
27
27
|
|
28
28
|
should "create indexes for Grid" do
|
@@ -39,8 +39,8 @@ class GridTest < Test::Unit::TestCase
|
|
39
39
|
|
40
40
|
context "Grid classes with slave connection" do
|
41
41
|
setup do
|
42
|
-
@
|
43
|
-
@
|
42
|
+
@client.expects(:class).twice.returns(MongoClient)
|
43
|
+
@client.expects(:read_primary?).returns(false)
|
44
44
|
end
|
45
45
|
|
46
46
|
should "not create indexes for Grid" do
|
data/test/unit/node_test.rb
CHANGED
@@ -1,74 +1,74 @@
|
|
1
|
-
require
|
1
|
+
require 'test_helper'
|
2
2
|
|
3
3
|
class NodeTest < Test::Unit::TestCase
|
4
4
|
|
5
5
|
def setup
|
6
|
-
@
|
6
|
+
@client = stub()
|
7
7
|
end
|
8
8
|
|
9
9
|
should "refuse to connect to node without 'hosts' key" do
|
10
10
|
tcp = mock()
|
11
|
-
node = Node.new(@
|
11
|
+
node = Node.new(@client, ['localhost', 27017])
|
12
12
|
tcp.stubs(:new).returns(new_mock_socket)
|
13
|
-
@
|
13
|
+
@client.stubs(:socket_class).returns(tcp)
|
14
14
|
|
15
15
|
admin_db = new_mock_db
|
16
16
|
admin_db.stubs(:command).returns({'ok' => 1, 'ismaster' => 1})
|
17
|
-
@
|
18
|
-
@
|
19
|
-
@
|
20
|
-
@
|
17
|
+
@client.stubs(:[]).with('admin').returns(admin_db)
|
18
|
+
@client.stubs(:op_timeout).returns(nil)
|
19
|
+
@client.stubs(:connect_timeout).returns(nil)
|
20
|
+
@client.expects(:log)
|
21
21
|
|
22
22
|
assert node.connect
|
23
23
|
node.set_config
|
24
24
|
end
|
25
25
|
|
26
26
|
should "load a node from an array" do
|
27
|
-
node = Node.new(@
|
27
|
+
node = Node.new(@client, ['power.level.com', 9001])
|
28
28
|
assert_equal 'power.level.com', node.host
|
29
29
|
assert_equal 9001, node.port
|
30
30
|
assert_equal 'power.level.com:9001', node.address
|
31
31
|
end
|
32
32
|
|
33
33
|
should "should default the port for an array" do
|
34
|
-
node = Node.new(@
|
34
|
+
node = Node.new(@client, ['power.level.com'])
|
35
35
|
assert_equal 'power.level.com', node.host
|
36
|
-
assert_equal
|
37
|
-
assert_equal "power.level.com:#{
|
36
|
+
assert_equal MongoClient::DEFAULT_PORT, node.port
|
37
|
+
assert_equal "power.level.com:#{MongoClient::DEFAULT_PORT}", node.address
|
38
38
|
end
|
39
39
|
|
40
40
|
should "load a node from a string" do
|
41
|
-
node = Node.new(@
|
41
|
+
node = Node.new(@client, 'localhost:1234')
|
42
42
|
assert_equal 'localhost', node.host
|
43
43
|
assert_equal 1234, node.port
|
44
44
|
assert_equal 'localhost:1234', node.address
|
45
45
|
end
|
46
46
|
|
47
47
|
should "should default the port for a string" do
|
48
|
-
node = Node.new(@
|
48
|
+
node = Node.new(@client, '192.168.0.1')
|
49
49
|
assert_equal '192.168.0.1', node.host
|
50
|
-
assert_equal
|
51
|
-
assert_equal "192.168.0.1:#{
|
50
|
+
assert_equal MongoClient::DEFAULT_PORT, node.port
|
51
|
+
assert_equal "192.168.0.1:#{MongoClient::DEFAULT_PORT}", node.address
|
52
52
|
end
|
53
53
|
|
54
54
|
should "two nodes with the same address should be equal" do
|
55
|
-
assert_equal Node.new(@
|
56
|
-
Node.new(@
|
55
|
+
assert_equal Node.new(@client, '192.168.0.1'),
|
56
|
+
Node.new(@client, ['192.168.0.1', MongoClient::DEFAULT_PORT])
|
57
57
|
end
|
58
58
|
|
59
59
|
should "two nodes with the same address should have the same hash" do
|
60
|
-
assert_equal Node.new(@
|
61
|
-
Node.new(@
|
60
|
+
assert_equal Node.new(@client, '192.168.0.1').hash,
|
61
|
+
Node.new(@client, ['192.168.0.1', MongoClient::DEFAULT_PORT]).hash
|
62
62
|
end
|
63
63
|
|
64
64
|
should "two nodes with different addresses should not be equal" do
|
65
|
-
assert_not_equal Node.new(@
|
66
|
-
Node.new(@
|
65
|
+
assert_not_equal Node.new(@client, '192.168.0.2'),
|
66
|
+
Node.new(@client, ['192.168.0.1', MongoClient::DEFAULT_PORT])
|
67
67
|
end
|
68
68
|
|
69
69
|
should "two nodes with the same address should have the same hash negate" do
|
70
|
-
assert_not_equal Node.new(@
|
71
|
-
Node.new(@
|
70
|
+
assert_not_equal Node.new(@client, '192.168.0.1').hash,
|
71
|
+
Node.new(@client, '1239.33.4.2393:29949').hash
|
72
72
|
end
|
73
73
|
|
74
74
|
end
|