mongo 1.1.5 → 1.2.rc0

Sign up to get free protection for your applications and to get access to all the features.
@@ -165,6 +165,41 @@ class TestConnection < Test::Unit::TestCase
165
165
  assert unlocked, "mongod failed to unlock"
166
166
  end
167
167
 
168
+ def test_max_bson_size_value
169
+ conn = standard_connection
170
+ if conn.server_version > "1.6"
171
+ assert_equal conn['admin'].command({:ismaster => 1})['maxBsonObjectSize'], conn.max_bson_size
172
+ end
173
+
174
+ conn.connect
175
+ assert_equal BSON::BSON_CODER.max_bson_size, conn.max_bson_size
176
+ doc = {'n' => 'a' * (BSON_CODER.max_bson_size - 11)}
177
+ assert_raise InvalidDocument do
178
+ assert BSON::BSON_CODER.serialize(doc)
179
+ end
180
+
181
+ limit = 7 * 1024 * 1024
182
+ conn.stubs(:max_bson_size).returns(limit)
183
+ conn.connect
184
+ assert_equal limit, conn.max_bson_size
185
+ assert_equal limit, BSON::BSON_CODER.max_bson_size
186
+ doc = {'n' => 'a' * ((limit) - 11)}
187
+ assert_raise_error InvalidDocument, "limited to #{limit}" do
188
+ assert BSON::BSON_CODER.serialize(doc)
189
+ end
190
+ end
191
+
192
+ def test_max_bson_size_with_old_mongod
193
+ conn = standard_connection(:connect => false)
194
+
195
+ admin_db = Object.new
196
+ admin_db.expects(:command).returns({'ok' => 1, 'ismaster' => 1}).twice
197
+ conn.expects(:[]).with('admin').returns(admin_db).twice
198
+
199
+ conn.connect
200
+ assert_equal Mongo::DEFAULT_MAX_BSON_SIZE, BSON::BSON_CODER.max_bson_size
201
+ end
202
+
168
203
  context "Saved authentications" do
169
204
  setup do
170
205
  @conn = standard_connection
@@ -16,8 +16,8 @@ class ConnectTest < Test::Unit::TestCase
16
16
 
17
17
  def test_connect_with_deprecated_multi
18
18
  @conn = Connection.multi([[RS.host, RS.ports[0]], [RS.host, RS.ports[1]]], :name => RS.name)
19
- assert @conn.connected?
20
19
  assert @conn.is_a?(ReplSetConnection)
20
+ assert @conn.connected?
21
21
  end
22
22
 
23
23
  def test_connect_bad_name
@@ -31,6 +31,7 @@ class ConnectTest < Test::Unit::TestCase
31
31
  @conn = ReplSetConnection.new([RS.host, RS.ports[0]], [RS.host, RS.ports[1]],
32
32
  [RS.host, RS.ports[2]], :name => RS.name)
33
33
  assert @conn.connected?
34
+ assert @conn.read_primary?
34
35
 
35
36
  assert_equal RS.primary, @conn.primary
36
37
  assert_equal RS.secondaries.sort, @conn.secondaries.sort
@@ -0,0 +1,32 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require './test/replica_sets/rs_test_helper'
3
+
4
+ # NOTE: This test expects a replica set of three nodes to be running on RS.host,
5
+ # on ports TEST_PORT, RS.ports[1], and TEST + 2.
6
+ class ConnectionStringTest < Test::Unit::TestCase
7
+ include Mongo
8
+
9
+ def setup
10
+ RS.restart_killed_nodes
11
+ end
12
+
13
+ def teardown
14
+ RS.restart_killed_nodes
15
+ end
16
+
17
+ def test_connect_with_connection_string
18
+ @conn = Connection.from_uri("mongodb://#{RS.host}:#{RS.ports[0]},#{RS.host}:#{RS.ports[1]}?replicaset=#{RS.name}")
19
+ assert @conn.is_a?(ReplSetConnection)
20
+ assert @conn.connected?
21
+ end
22
+
23
+ def test_connect_with_full_connection_string
24
+ @conn = Connection.from_uri("mongodb://#{RS.host}:#{RS.ports[0]},#{RS.host}:#{RS.ports[1]}?replicaset=#{RS.name};safe=true;w=2;fsync=true;slaveok=true")
25
+ assert @conn.is_a?(ReplSetConnection)
26
+ assert @conn.connected?
27
+ assert_equal 2, @conn.safe[:w]
28
+ assert @conn.safe[:fsync]
29
+ assert @conn.read_pool
30
+ end
31
+
32
+ end
@@ -16,6 +16,10 @@ class ReplicaSetQuerySecondariesTest < Test::Unit::TestCase
16
16
  RS.restart_killed_nodes
17
17
  end
18
18
 
19
+ def test_read_primary
20
+ assert !@conn.read_primary?
21
+ end
22
+
19
23
  def test_con
20
24
  assert @conn.primary_pool, "No primary pool!"
21
25
  assert @conn.read_pool, "No read pool!"
@@ -13,6 +13,8 @@ class ReplicaSetAckTest < Test::Unit::TestCase
13
13
  @slave1 = Connection.new(@conn.secondary_pools[0].host,
14
14
  @conn.secondary_pools[0].port, :slave_ok => true)
15
15
 
16
+ assert !@slave1.read_primary?
17
+
16
18
  @db = @conn.db(MONGO_TEST_DB)
17
19
  @db.drop_collection("test-sets")
18
20
  @col = @db.collection("test-sets")
@@ -12,17 +12,15 @@ class Test::Unit::TestCase
12
12
  # Generic code for rescuing connection failures and retrying operations.
13
13
  # This could be combined with some timeout functionality.
14
14
  def rescue_connection_failure(max_retries=60)
15
- success = false
16
- tries = 0
17
- while !success && tries < max_retries
18
- begin
19
- yield
20
- success = true
21
- rescue Mongo::ConnectionFailure
22
- puts "Rescue attempt #{tries}\n"
23
- tries += 1
24
- sleep(1)
25
- end
15
+ retries = 0
16
+ begin
17
+ yield
18
+ rescue Mongo::ConnectionFailure => ex
19
+ puts "Rescue attempt #{retries}"
20
+ retries += 1
21
+ raise ex if retries > max_retries
22
+ sleep(1)
23
+ retry
26
24
  end
27
25
  end
28
26
 
@@ -113,7 +113,6 @@ class CollectionTest < Test::Unit::TestCase
113
113
 
114
114
  @coll.ensure_index [["x", Mongo::DESCENDING]]
115
115
  @coll.ensure_index [["x", Mongo::DESCENDING]]
116
-
117
116
  end
118
117
 
119
118
  should "call generate_indexes for each key when calling ensure_indexes" do
@@ -22,8 +22,8 @@ class ConnectionTest < Test::Unit::TestCase
22
22
  TCPSocket.stubs(:new).returns(new_mock_socket)
23
23
 
24
24
  admin_db = new_mock_db
25
- admin_db.expects(:command).returns({'ok' => 1, 'ismaster' => 1})
26
- @conn.expects(:[]).with('admin').returns(admin_db)
25
+ admin_db.expects(:command).returns({'ok' => 1, 'ismaster' => 1}).twice
26
+ @conn.expects(:[]).with('admin').returns(admin_db).twice
27
27
  @conn.connect
28
28
  end
29
29
 
@@ -65,8 +65,8 @@ class ConnectionTest < Test::Unit::TestCase
65
65
  @conn = Connection.from_uri("mongodb://localhost", :connect => false)
66
66
 
67
67
  admin_db = new_mock_db
68
- admin_db.expects(:command).returns({'ok' => 1, 'ismaster' => 1})
69
- @conn.expects(:[]).with('admin').returns(admin_db)
68
+ admin_db.expects(:command).returns({'ok' => 1, 'ismaster' => 1}).twice
69
+ @conn.expects(:[]).with('admin').returns(admin_db).twice
70
70
  @conn.expects(:apply_saved_authentication)
71
71
  @conn.connect
72
72
  end
@@ -67,16 +67,6 @@ class ReplSetConnectionTest < Test::Unit::TestCase
67
67
  assert_equal ['localhost', 27017], @conn.nodes[0]
68
68
  assert_equal ['mydb.com', 27018], @conn.nodes[1]
69
69
  end
70
-
71
- should "parse a uri specifying multiple nodes with auth" do
72
- @conn = Connection.from_uri("mongodb://kyle:s3cr3t@localhost:27017/app,mickey:m0u5e@mydb.com:27018/dsny", :connect => false)
73
- assert_equal ['localhost', 27017], @conn.nodes[0]
74
- assert_equal ['mydb.com', 27018], @conn.nodes[1]
75
- auth_hash = {'username' => 'kyle', 'password' => 's3cr3t', 'db_name' => 'app'}
76
- assert_equal auth_hash, @conn.auths[0]
77
- auth_hash = {'username' => 'mickey', 'password' => 'm0u5e', 'db_name' => 'dsny'}
78
- assert_equal auth_hash, @conn.auths[1]
79
- end
80
70
  end
81
71
  end
82
72
  end
@@ -40,7 +40,7 @@ class SafeTest < Test::Unit::TestCase
40
40
  col = @db['bar']
41
41
  assert_equal @safe_value, col.safe
42
42
 
43
- col = Collection.new(@db, 'bar')
43
+ col = Collection.new('bar', @db)
44
44
  assert_equal @safe_value, col.safe
45
45
  end
46
46
 
@@ -48,7 +48,7 @@ class SafeTest < Test::Unit::TestCase
48
48
  col = @db.collection('bar', :safe => false)
49
49
  assert_equal false, col.safe
50
50
 
51
- col = Collection.new(@db, 'bar', :safe => false)
51
+ col = Collection.new('bar', @db, :safe => false)
52
52
  assert_equal false, col.safe
53
53
  end
54
54
  end
data/test/uri_test.rb ADDED
@@ -0,0 +1,75 @@
1
+ require './test/test_helper'
2
+
3
+ class TestThreading < Test::Unit::TestCase
4
+ include Mongo
5
+
6
+ def test_uri_without_port
7
+ parser = Mongo::URIParser.new('mongodb://localhost')
8
+ assert_equal 1, parser.nodes.length
9
+ assert_equal 'localhost', parser.nodes[0][0]
10
+ assert_equal 27017, parser.nodes[0][1]
11
+ end
12
+
13
+ def test_basic_uri
14
+ parser = Mongo::URIParser.new('mongodb://localhost:27018')
15
+ assert_equal 1, parser.nodes.length
16
+ assert_equal 'localhost', parser.nodes[0][0]
17
+ assert_equal 27018, parser.nodes[0][1]
18
+ end
19
+
20
+ def test_multiple_uris
21
+ parser = Mongo::URIParser.new('mongodb://a.example.com:27018,b.example.com')
22
+ assert_equal 2, parser.nodes.length
23
+ assert_equal 'a.example.com', parser.nodes[0][0]
24
+ assert_equal 27018, parser.nodes[0][1]
25
+ assert_equal 'b.example.com', parser.nodes[1][0]
26
+ assert_equal 27017, parser.nodes[1][1]
27
+ end
28
+
29
+ def test_multiple_uris_with_auths
30
+ parser = Mongo::URIParser.new('mongodb://bob:secret@a.example.com:27018/test,joe:secret2@b.example.com/test2')
31
+ assert_equal 2, parser.nodes.length
32
+ assert_equal 'a.example.com', parser.nodes[0][0]
33
+ assert_equal 27018, parser.nodes[0][1]
34
+ assert_equal 'b.example.com', parser.nodes[1][0]
35
+ assert_equal 27017, parser.nodes[1][1]
36
+ assert_equal 2, parser.auths.length
37
+ assert_equal "bob", parser.auths[0]["username"]
38
+ assert_equal "secret", parser.auths[0]["password"]
39
+ assert_equal "test", parser.auths[0]["db_name"]
40
+ assert_equal "joe", parser.auths[1]["username"]
41
+ assert_equal "secret2", parser.auths[1]["password"]
42
+ assert_equal "test2", parser.auths[1]["db_name"]
43
+ end
44
+
45
+ def test_opts_basic
46
+ parser = Mongo::URIParser.new('mongodb://localhost:27018?connect=direct;slaveok=true;safe=true')
47
+ assert_equal 'direct', parser.connect
48
+ assert parser.slaveok
49
+ assert parser.safe
50
+ end
51
+
52
+ def test_opts_with_amp_separator
53
+ parser = Mongo::URIParser.new('mongodb://localhost:27018?connect=direct&slaveok=true&safe=true')
54
+ assert_equal 'direct', parser.connect
55
+ assert parser.slaveok
56
+ assert parser.safe
57
+ end
58
+
59
+ def test_opts_safe
60
+ parser = Mongo::URIParser.new('mongodb://localhost:27018?safe=true;w=2;wtimeout=200;fsync=true')
61
+ assert parser.safe
62
+ assert_equal 2, parser.w
63
+ assert_equal 200, parser.wtimeout
64
+ assert parser.fsync
65
+ end
66
+
67
+ def test_opts_replica_set
68
+ assert_raise_error MongoArgumentError, "specify that connect=replicaset" do
69
+ Mongo::URIParser.new('mongodb://localhost:27018?replicaset=foo')
70
+ end
71
+ parser = Mongo::URIParser.new('mongodb://localhost:27018?connect=replicaset;replicaset=foo')
72
+ assert_equal 'foo', parser.replicaset
73
+ assert_equal 'replicaset', parser.connect
74
+ end
75
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease: false
4
+ hash: 977940448
5
+ prerelease: true
6
6
  segments:
7
7
  - 1
8
- - 1
9
- - 5
10
- version: 1.1.5
8
+ - 2
9
+ - rc0
10
+ version: 1.2.rc0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jim Menard
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-12-15 00:00:00 -05:00
20
+ date: 2011-01-05 00:00:00 -05:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -28,12 +28,12 @@ dependencies:
28
28
  requirements:
29
29
  - - ">="
30
30
  - !ruby/object:Gem::Version
31
- hash: 25
31
+ hash: 977940448
32
32
  segments:
33
33
  - 1
34
- - 1
35
- - 5
36
- version: 1.1.5
34
+ - 2
35
+ - rc0
36
+ version: 1.2.rc0
37
37
  type: :runtime
38
38
  version_requirements: *id001
39
39
  description: A Ruby driver for MongoDB. For more information about Mongo, see http://www.mongodb.org.
@@ -96,6 +96,7 @@ files:
96
96
  - test/auxillary/1.4_features.rb
97
97
  - test/conversions_test.rb
98
98
  - test/connection_test.rb
99
+ - test/uri_test.rb
99
100
  - test/cursor_message_test.rb
100
101
  - test/tools/test.rb
101
102
  - test/tools/repl_set_manager.rb
@@ -119,6 +120,7 @@ files:
119
120
  - test/replica_sets/replication_ack_test.rb
120
121
  - test/replica_sets/query_secondaries.rb
121
122
  - test/replica_sets/query_test.rb
123
+ - test/replica_sets/connection_string_test.rb
122
124
  - test/replica_sets/insert_test.rb
123
125
  - test/replica_sets/connect_test.rb
124
126
  - test/safe_test.rb
@@ -147,12 +149,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
149
  required_rubygems_version: !ruby/object:Gem::Requirement
148
150
  none: false
149
151
  requirements:
150
- - - ">="
152
+ - - ">"
151
153
  - !ruby/object:Gem::Version
152
- hash: 3
154
+ hash: 25
153
155
  segments:
154
- - 0
155
- version: "0"
156
+ - 1
157
+ - 3
158
+ - 1
159
+ version: 1.3.1
156
160
  requirements: []
157
161
 
158
162
  rubyforge_project:
@@ -181,6 +185,7 @@ test_files:
181
185
  - test/auxillary/1.4_features.rb
182
186
  - test/conversions_test.rb
183
187
  - test/connection_test.rb
188
+ - test/uri_test.rb
184
189
  - test/cursor_message_test.rb
185
190
  - test/tools/test.rb
186
191
  - test/tools/repl_set_manager.rb
@@ -204,6 +209,7 @@ test_files:
204
209
  - test/replica_sets/replication_ack_test.rb
205
210
  - test/replica_sets/query_secondaries.rb
206
211
  - test/replica_sets/query_test.rb
212
+ - test/replica_sets/connection_string_test.rb
207
213
  - test/replica_sets/insert_test.rb
208
214
  - test/replica_sets/connect_test.rb
209
215
  - test/safe_test.rb