mongo 1.6.2 → 1.6.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. data/README.md +44 -22
  2. data/Rakefile +17 -4
  3. data/docs/GridFS.md +2 -2
  4. data/docs/HISTORY.md +15 -1
  5. data/docs/RELEASES.md +4 -4
  6. data/docs/TUTORIAL.md +12 -0
  7. data/docs/WRITE_CONCERN.md +1 -1
  8. data/lib/mongo/collection.rb +1 -1
  9. data/lib/mongo/connection.rb +35 -47
  10. data/lib/mongo/cursor.rb +10 -9
  11. data/lib/mongo/db.rb +1 -1
  12. data/lib/mongo/gridfs/grid_ext.rb +4 -4
  13. data/lib/mongo/gridfs/grid_file_system.rb +3 -3
  14. data/lib/mongo/gridfs/grid_io.rb +1 -1
  15. data/lib/mongo/networking.rb +5 -0
  16. data/lib/mongo/repl_set_connection.rb +47 -21
  17. data/lib/mongo/util/conversions.rb +23 -0
  18. data/lib/mongo/util/logging.rb +13 -18
  19. data/lib/mongo/util/node.rb +1 -5
  20. data/lib/mongo/util/pool.rb +0 -1
  21. data/lib/mongo/util/ssl_socket.rb +3 -1
  22. data/lib/mongo/util/support.rb +1 -0
  23. data/lib/mongo/util/tcp_socket.rb +15 -32
  24. data/lib/mongo/util/uri_parser.rb +100 -35
  25. data/lib/mongo/version.rb +1 -1
  26. data/test/auxillary/1.4_features.rb +1 -1
  27. data/test/auxillary/authentication_test.rb +1 -1
  28. data/test/auxillary/autoreconnect_test.rb +1 -1
  29. data/test/auxillary/fork_test.rb +1 -1
  30. data/test/auxillary/repl_set_auth_test.rb +1 -1
  31. data/test/auxillary/slave_connection_test.rb +1 -1
  32. data/test/auxillary/threaded_authentication_test.rb +1 -1
  33. data/test/bson/binary_test.rb +1 -1
  34. data/test/bson/bson_test.rb +8 -1
  35. data/test/bson/byte_buffer_test.rb +1 -1
  36. data/test/bson/hash_with_indifferent_access_test.rb +1 -1
  37. data/test/bson/json_test.rb +1 -1
  38. data/test/bson/object_id_test.rb +11 -1
  39. data/test/bson/ordered_hash_test.rb +1 -1
  40. data/test/bson/timestamp_test.rb +1 -1
  41. data/test/collection_test.rb +1 -1
  42. data/test/connection_test.rb +25 -1
  43. data/test/conversions_test.rb +1 -1
  44. data/test/cursor_fail_test.rb +1 -1
  45. data/test/cursor_message_test.rb +1 -1
  46. data/test/cursor_test.rb +1 -1
  47. data/test/db_api_test.rb +57 -3
  48. data/test/db_connection_test.rb +1 -1
  49. data/test/db_test.rb +1 -1
  50. data/test/grid_file_system_test.rb +1 -1
  51. data/test/grid_io_test.rb +30 -1
  52. data/test/grid_test.rb +1 -1
  53. data/test/pool_test.rb +1 -1
  54. data/test/replica_sets/basic_test.rb +10 -0
  55. data/test/replica_sets/connect_test.rb +45 -0
  56. data/test/replica_sets/read_preference_test.rb +2 -1
  57. data/test/replica_sets/refresh_with_threads_test.rb +2 -0
  58. data/test/replica_sets/rs_test_helper.rb +1 -1
  59. data/test/safe_test.rb +1 -1
  60. data/test/support_test.rb +1 -1
  61. data/test/threading/threading_with_large_pool_test.rb +1 -1
  62. data/test/threading_test.rb +1 -1
  63. data/test/timeout_test.rb +1 -1
  64. data/test/tools/repl_set_manager.rb +1 -0
  65. data/test/unit/collection_test.rb +1 -1
  66. data/test/unit/connection_test.rb +89 -1
  67. data/test/unit/cursor_test.rb +1 -1
  68. data/test/unit/db_test.rb +1 -1
  69. data/test/unit/grid_test.rb +1 -1
  70. data/test/unit/node_test.rb +1 -1
  71. data/test/unit/pool_manager_test.rb +1 -1
  72. data/test/unit/pool_test.rb +1 -1
  73. data/test/unit/read_test.rb +1 -1
  74. data/test/unit/safe_test.rb +1 -1
  75. data/test/uri_test.rb +25 -5
  76. metadata +5 -5
@@ -42,7 +42,7 @@ class ReadPreferenceTest < Test::Unit::TestCase
42
42
  @rs.add_arbiter
43
43
  @rs.remove_secondary_node
44
44
 
45
- @conn = ReplSetConnection.new(build_seeds(2), :read => :secondary_only)
45
+ @conn = ReplSetConnection.new(build_seeds(3), :read => :secondary_only)
46
46
 
47
47
  @db = @conn.db(MONGO_TEST_DB)
48
48
  @coll = @db.collection("test-sets")
@@ -108,6 +108,7 @@ class ReadPreferenceTest < Test::Unit::TestCase
108
108
  @coll.save({:a => 50}, :safe => {:w => 2, :wtimeout => 10000})
109
109
  end
110
110
  @rs.restart_killed_nodes
111
+ sleep(1)
111
112
  @coll.save({:a => 50}, :safe => {:w => 2, :wtimeout => 10000})
112
113
  assert_equal 4, @coll.find.to_a.length
113
114
  end
@@ -49,6 +49,8 @@ class ReplicaSetRefreshWithThreadsTest < Test::Unit::TestCase
49
49
 
50
50
  @rs.add_node
51
51
  threads.each {|t| t.join }
52
+
53
+ sleep(1)
52
54
 
53
55
  @conn['admin'].command({:ismaster => 1})
54
56
 
@@ -1,5 +1,5 @@
1
1
  $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- require './test/test_helper'
2
+ require File.expand_path("../../test_helper", __FILE__)
3
3
  require './test/tools/repl_set_manager'
4
4
 
5
5
  class Test::Unit::TestCase
@@ -1,4 +1,4 @@
1
- require './test/test_helper'
1
+ require File.expand_path("../test_helper", __FILE__)
2
2
  include Mongo
3
3
 
4
4
  class SafeTest < Test::Unit::TestCase
@@ -1,4 +1,4 @@
1
- require './test/test_helper'
1
+ require File.expand_path("../test_helper", __FILE__)
2
2
 
3
3
  class SupportTest < Test::Unit::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require './test/test_helper'
1
+ require File.expand_path("../../test_helper", __FILE__)
2
2
 
3
3
  # Essentialy the same as test_threading.rb but with an expanded pool for
4
4
  # testing multiple connections.
@@ -1,4 +1,4 @@
1
- require './test/test_helper'
1
+ require File.expand_path("../test_helper", __FILE__)
2
2
 
3
3
  class TestThreading < Test::Unit::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require './test/test_helper'
1
+ require File.expand_path("../test_helper", __FILE__)
2
2
 
3
3
  class TestTimeout < Test::Unit::TestCase
4
4
  def test_op_timeout
@@ -152,6 +152,7 @@ class ReplSetManager
152
152
  end
153
153
 
154
154
  con.close
155
+ ensure_up
155
156
 
156
157
  return secondary
157
158
  end
@@ -1,4 +1,4 @@
1
- require './test/test_helper'
1
+ require File.expand_path("../../test_helper", __FILE__)
2
2
 
3
3
  class CollectionTest < Test::Unit::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require './test/test_helper'
1
+ require File.expand_path("../../test_helper", __FILE__)
2
2
  include Mongo
3
3
 
4
4
  class ConnectionTest < Test::Unit::TestCase
@@ -130,5 +130,93 @@ class ConnectionTest < Test::Unit::TestCase
130
130
  end
131
131
  end
132
132
  end
133
+
134
+ context "initializing with ENV['MONGODB_URI']" do
135
+ setup do
136
+ @old_mongodb_uri = ENV['MONGODB_URI']
137
+ end
138
+
139
+ teardown do
140
+ ENV['MONGODB_URI'] = @old_mongodb_uri
141
+ end
142
+
143
+ should "parse a simple uri" do
144
+ ENV['MONGODB_URI'] = "mongodb://localhost?connect=false"
145
+ @conn = Connection.new
146
+ assert_equal ['localhost', 27017], @conn.host_to_try
147
+ end
148
+
149
+ should "allow a complex host names" do
150
+ host_name = "foo.bar-12345.org"
151
+ ENV['MONGODB_URI'] = "mongodb://#{host_name}?connect=false"
152
+ @conn = Connection.new
153
+ assert_equal [host_name, 27017], @conn.host_to_try
154
+ end
155
+
156
+ should "allow db without username and password" do
157
+ host_name = "foo.bar-12345.org"
158
+ ENV['MONGODB_URI'] = "mongodb://#{host_name}/foo?connect=false"
159
+ @conn = Connection.new
160
+ assert_equal [host_name, 27017], @conn.host_to_try
161
+ end
162
+
163
+ should "set safe options on connection" do
164
+ host_name = "localhost"
165
+ opts = "safe=true&w=2&wtimeoutMS=1000&fsync=true&journal=true&connect=false"
166
+ ENV['MONGODB_URI'] = "mongodb://#{host_name}/foo?#{opts}"
167
+ @conn = Connection.new
168
+ assert_equal({:w => 2, :wtimeout => 1000, :fsync => true, :j => true}, @conn.safe)
169
+ end
170
+
171
+ should "set timeout options on connection" do
172
+ host_name = "localhost"
173
+ opts = "connectTimeoutMS=1000&socketTimeoutMS=5000&connect=false"
174
+ ENV['MONGODB_URI'] = "mongodb://#{host_name}/foo?#{opts}"
175
+ @conn = Connection.new
176
+ assert_equal 1, @conn.connect_timeout
177
+ assert_equal 5, @conn.op_timeout
178
+ end
179
+
180
+ should "parse a uri with a hyphen & underscore in the username or password" do
181
+ ENV['MONGODB_URI'] = "mongodb://hyphen-user_name:p-s_s@localhost:27017/db?connect=false"
182
+ @conn = Connection.new
183
+ assert_equal ['localhost', 27017], @conn.host_to_try
184
+ auth_hash = { 'db_name' => 'db', 'username' => 'hyphen-user_name', "password" => 'p-s_s' }
185
+ assert_equal auth_hash, @conn.auths[0]
186
+ end
187
+
188
+ should "attempt to connect" do
189
+ TCPSocket.stubs(:new).returns(new_mock_socket)
190
+ ENV['MONGODB_URI'] = "mongodb://localhost?connect=false" # connect=false ??
191
+ @conn = Connection.new
192
+
193
+ admin_db = new_mock_db
194
+ admin_db.expects(:command).returns({'ok' => 1, 'ismaster' => 1})
195
+ @conn.expects(:[]).with('admin').returns(admin_db)
196
+ @conn.connect
197
+ end
198
+
199
+ should "raise an error on invalid uris" do
200
+ ENV['MONGODB_URI'] = "mongo://localhost"
201
+ assert_raise MongoArgumentError do
202
+ Connection.new
203
+ end
204
+
205
+ ENV['MONGODB_URI'] = "mongodb://localhost:abc"
206
+ assert_raise MongoArgumentError do
207
+ Connection.new
208
+ end
209
+ end
210
+
211
+ should "require all of username, if password and db are specified" do
212
+ ENV['MONGODB_URI'] = "mongodb://kyle:jones@localhost/db?connect=false"
213
+ assert Connection.new
214
+
215
+ ENV['MONGODB_URI'] = "mongodb://kyle:password@localhost"
216
+ assert_raise MongoArgumentError do
217
+ Connection.new
218
+ end
219
+ end
220
+ end
133
221
  end
134
222
  end
@@ -1,4 +1,4 @@
1
- require './test/test_helper'
1
+ require File.expand_path("../../test_helper", __FILE__)
2
2
 
3
3
  class CursorTest < Test::Unit::TestCase
4
4
  context "Cursor options" do
@@ -1,4 +1,4 @@
1
- require './test/test_helper'
1
+ require File.expand_path("../../test_helper", __FILE__)
2
2
 
3
3
  def insert_message(db, documents)
4
4
  documents = [documents] unless documents.is_a?(Array)
@@ -1,4 +1,4 @@
1
- require './test/test_helper'
1
+ require File.expand_path("../../test_helper", __FILE__)
2
2
 
3
3
  class GridTest < Test::Unit::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require './test/test_helper'
1
+ require File.expand_path("../../test_helper", __FILE__)
2
2
 
3
3
  class NodeTest < Test::Unit::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require './test/test_helper'
1
+ require File.expand_path("../../test_helper", __FILE__)
2
2
  include Mongo
3
3
 
4
4
  class PoolManagerTest < Test::Unit::TestCase
@@ -1,4 +1,4 @@
1
- require './test/test_helper'
1
+ require File.expand_path("../../test_helper", __FILE__)
2
2
  include Mongo
3
3
 
4
4
  class PoolTest < Test::Unit::TestCase
@@ -1,4 +1,4 @@
1
- require './test/test_helper'
1
+ require File.expand_path("../../test_helper", __FILE__)
2
2
 
3
3
  class ReadTest < Test::Unit::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require './test/test_helper'
1
+ require File.expand_path("../../test_helper", __FILE__)
2
2
 
3
3
  class SafeTest < Test::Unit::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require './test/test_helper'
1
+ require File.expand_path("../test_helper", __FILE__)
2
2
 
3
3
  class URITest < Test::Unit::TestCase
4
4
  include Mongo
@@ -63,9 +63,10 @@ class URITest < Test::Unit::TestCase
63
63
  assert_equal "test", parser.auths[1]["db_name"]
64
64
  end
65
65
 
66
- def test_opts_basic
66
+ def test_opts_with_semincolon_separator
67
67
  parser = Mongo::URIParser.new('mongodb://localhost:27018?connect=direct;slaveok=true;safe=true')
68
68
  assert_equal 'direct', parser.connect
69
+ assert parser.direct?
69
70
  assert parser.slaveok
70
71
  assert parser.safe
71
72
  end
@@ -73,10 +74,25 @@ class URITest < Test::Unit::TestCase
73
74
  def test_opts_with_amp_separator
74
75
  parser = Mongo::URIParser.new('mongodb://localhost:27018?connect=direct&slaveok=true&safe=true')
75
76
  assert_equal 'direct', parser.connect
77
+ assert parser.direct?
76
78
  assert parser.slaveok
77
79
  assert parser.safe
78
80
  end
79
81
 
82
+ def test_opts_with_uri_encoded_stuff
83
+ parser = Mongo::URIParser.new('mongodb://localhost:27018?connect=%64%69%72%65%63%74&slaveok=%74%72%75%65&safe=true')
84
+ assert_equal 'direct', parser.connect
85
+ assert parser.direct?
86
+ assert parser.slaveok
87
+ assert parser.safe
88
+ end
89
+
90
+ def test_opts_made_invalid_by_mixed_separators
91
+ assert_raise_error MongoArgumentError, "must not mix URL separators ; and &" do
92
+ Mongo::URIParser.new('mongodb://localhost:27018?replicaset=foo;bar&slaveok=true&safe=true')
93
+ end
94
+ end
95
+
80
96
  def test_opts_safe
81
97
  parser = Mongo::URIParser.new('mongodb://localhost:27018?safe=true;w=2;journal=true;fsync=true;wtimeoutMS=200')
82
98
  assert parser.safe
@@ -93,12 +109,16 @@ class URITest < Test::Unit::TestCase
93
109
  end
94
110
 
95
111
  def test_opts_replica_set
96
- assert_raise_error MongoArgumentError, "specify that connect=replicaset" do
97
- Mongo::URIParser.new('mongodb://localhost:27018?replicaset=foo')
98
- end
99
112
  parser = Mongo::URIParser.new('mongodb://localhost:27018?connect=replicaset;replicaset=foo')
100
113
  assert_equal 'foo', parser.replicaset
101
114
  assert_equal 'replicaset', parser.connect
115
+ assert parser.replicaset?
116
+ end
117
+
118
+ def test_opts_conflicting_replica_set
119
+ assert_raise_error MongoArgumentError, "connect=direct conflicts with setting a replicaset name" do
120
+ Mongo::URIParser.new('mongodb://localhost:27018?connect=direct;replicaset=foo')
121
+ end
102
122
  end
103
123
 
104
124
  def test_case_insensitivity
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.2
4
+ version: 1.6.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2012-04-05 00:00:00.000000000 Z
15
+ date: 2012-06-06 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: bson
@@ -21,7 +21,7 @@ dependencies:
21
21
  requirements:
22
22
  - - ~>
23
23
  - !ruby/object:Gem::Version
24
- version: 1.6.2
24
+ version: 1.6.4
25
25
  type: :runtime
26
26
  prerelease: false
27
27
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  requirements:
30
30
  - - ~>
31
31
  - !ruby/object:Gem::Version
32
- version: 1.6.2
32
+ version: 1.6.4
33
33
  description: A Ruby driver for MongoDB. For more information about Mongo, see http://www.mongodb.org.
34
34
  email: mongodb-dev@googlegroups.com
35
35
  executables:
@@ -165,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
165
  version: '0'
166
166
  requirements: []
167
167
  rubyforge_project:
168
- rubygems_version: 1.8.21
168
+ rubygems_version: 1.8.24
169
169
  signing_key:
170
170
  specification_version: 3
171
171
  summary: Ruby driver for MongoDB