mongo 1.4.0 → 1.5.0.rc0

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.
Files changed (49) hide show
  1. data/docs/HISTORY.md +15 -0
  2. data/docs/REPLICA_SETS.md +19 -7
  3. data/lib/mongo.rb +1 -0
  4. data/lib/mongo/collection.rb +1 -1
  5. data/lib/mongo/connection.rb +29 -351
  6. data/lib/mongo/cursor.rb +88 -6
  7. data/lib/mongo/gridfs/grid.rb +4 -2
  8. data/lib/mongo/gridfs/grid_file_system.rb +4 -2
  9. data/lib/mongo/networking.rb +345 -0
  10. data/lib/mongo/repl_set_connection.rb +236 -191
  11. data/lib/mongo/util/core_ext.rb +45 -0
  12. data/lib/mongo/util/logging.rb +5 -0
  13. data/lib/mongo/util/node.rb +6 -4
  14. data/lib/mongo/util/pool.rb +73 -26
  15. data/lib/mongo/util/pool_manager.rb +100 -30
  16. data/lib/mongo/util/uri_parser.rb +29 -21
  17. data/lib/mongo/version.rb +1 -1
  18. data/test/bson/binary_test.rb +6 -8
  19. data/test/bson/bson_test.rb +1 -0
  20. data/test/bson/ordered_hash_test.rb +2 -0
  21. data/test/bson/test_helper.rb +0 -17
  22. data/test/collection_test.rb +22 -0
  23. data/test/connection_test.rb +1 -1
  24. data/test/cursor_test.rb +3 -3
  25. data/test/load/thin/load.rb +4 -7
  26. data/test/replica_sets/basic_test.rb +46 -0
  27. data/test/replica_sets/connect_test.rb +35 -58
  28. data/test/replica_sets/count_test.rb +15 -6
  29. data/test/replica_sets/insert_test.rb +6 -7
  30. data/test/replica_sets/query_test.rb +4 -6
  31. data/test/replica_sets/read_preference_test.rb +112 -8
  32. data/test/replica_sets/refresh_test.rb +66 -36
  33. data/test/replica_sets/refresh_with_threads_test.rb +55 -0
  34. data/test/replica_sets/replication_ack_test.rb +3 -6
  35. data/test/replica_sets/rs_test_helper.rb +12 -6
  36. data/test/replica_sets/threading_test.rb +111 -0
  37. data/test/test_helper.rb +9 -2
  38. data/test/threading_test.rb +14 -6
  39. data/test/tools/repl_set_manager.rb +55 -40
  40. data/test/unit/collection_test.rb +2 -1
  41. data/test/unit/connection_test.rb +8 -8
  42. data/test/unit/grid_test.rb +4 -2
  43. data/test/unit/pool_manager_test.rb +1 -0
  44. data/test/unit/read_test.rb +17 -5
  45. data/test/uri_test.rb +9 -4
  46. metadata +13 -28
  47. data/test/replica_sets/connection_string_test.rb +0 -29
  48. data/test/replica_sets/pooled_insert_test.rb +0 -58
  49. data/test/replica_sets/query_secondaries.rb +0 -109
@@ -10,7 +10,7 @@ class ReadTest < Test::Unit::TestCase
10
10
 
11
11
  end
12
12
 
13
- context "Read mode on connection: " do
13
+ context "Read mode on replica set connection: " do
14
14
  setup do
15
15
  @read_preference = :secondary
16
16
  @con = Mongo::ReplSetConnection.new(['localhost', 27017], :read => @read_preference, :connect => false)
@@ -71,19 +71,31 @@ class ReadTest < Test::Unit::TestCase
71
71
  end
72
72
 
73
73
  should "use default value on query" do
74
+ @cursor = @col.find({:a => 1})
75
+ sock = mock()
76
+ read_pool = stub(:checkin => true)
77
+ @con.stubs(:read_pool).returns(read_pool)
78
+ primary_pool = stub(:checkin => true)
79
+ @con.stubs(:primary_pool).returns(primary_pool)
80
+ @con.expects(:checkout_reader).returns(sock)
74
81
  @con.expects(:receive_message).with do |o, m, l, s, c, r|
75
- r == :secondary
82
+ r == nil
76
83
  end.returns([[], 0, 0])
77
84
 
78
- @col.find_one({:a => 1})
85
+ @cursor.next
79
86
  end
80
87
 
81
88
  should "allow override default value on query" do
89
+ @cursor = @col.find({:a => 1}, :read => :primary)
90
+ sock = mock()
91
+ primary_pool = stub(:checkin => true)
92
+ @con.stubs(:primary_pool).returns(primary_pool)
93
+ @con.expects(:checkout_writer).returns(sock)
82
94
  @con.expects(:receive_message).with do |o, m, l, s, c, r|
83
- r == :primary
95
+ r == nil
84
96
  end.returns([[], 0, 0])
85
97
 
86
- @col.find_one({:a => 1}, :read => :primary)
98
+ @cursor.next
87
99
  end
88
100
 
89
101
  should "allow override alternate value on query" do
@@ -36,6 +36,11 @@ class TestThreading < Test::Unit::TestCase
36
36
  assert_equal "s-_3#%R.t", parser.auths[0]["password"]
37
37
  end
38
38
 
39
+ def test_complex_usernames
40
+ parser = Mongo::URIParser.new('mongodb://b:ob:secret.word@a.example.com:27018/test')
41
+ assert_equal "b:ob", parser.auths[0]["username"]
42
+ end
43
+
39
44
  def test_passwords_contain_no_commas
40
45
  assert_raise MongoArgumentError do
41
46
  Mongo::URIParser.new('mongodb://bob:a,b@a.example.com:27018/test')
@@ -43,7 +48,7 @@ class TestThreading < Test::Unit::TestCase
43
48
  end
44
49
 
45
50
  def test_multiple_uris_with_auths
46
- parser = Mongo::URIParser.new('mongodb://bob:secret@a.example.com:27018/test,joe:secret2@b.example.com/test2')
51
+ parser = Mongo::URIParser.new('mongodb://bob:secret@a.example.com:27018,b.example.com/test')
47
52
  assert_equal 2, parser.nodes.length
48
53
  assert_equal 'a.example.com', parser.nodes[0][0]
49
54
  assert_equal 27018, parser.nodes[0][1]
@@ -53,9 +58,9 @@ class TestThreading < Test::Unit::TestCase
53
58
  assert_equal "bob", parser.auths[0]["username"]
54
59
  assert_equal "secret", parser.auths[0]["password"]
55
60
  assert_equal "test", parser.auths[0]["db_name"]
56
- assert_equal "joe", parser.auths[1]["username"]
57
- assert_equal "secret2", parser.auths[1]["password"]
58
- assert_equal "test2", parser.auths[1]["db_name"]
61
+ assert_equal "bob", parser.auths[1]["username"]
62
+ assert_equal "secret", parser.auths[1]["password"]
63
+ assert_equal "test", parser.auths[1]["db_name"]
59
64
  end
60
65
 
61
66
  def test_opts_basic
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
5
- prerelease:
6
- segments:
7
- - 1
8
- - 4
9
- - 0
10
- version: 1.4.0
4
+ prerelease: 6
5
+ version: 1.5.0.rc0
11
6
  platform: ruby
12
7
  authors:
13
8
  - Jim Menard
@@ -17,7 +12,7 @@ autorequire:
17
12
  bindir: bin
18
13
  cert_chain: []
19
14
 
20
- date: 2011-09-20 00:00:00 -04:00
15
+ date: 2011-11-18 00:00:00 -05:00
21
16
  default_executable:
22
17
  dependencies:
23
18
  - !ruby/object:Gem::Dependency
@@ -28,12 +23,7 @@ dependencies:
28
23
  requirements:
29
24
  - - "="
30
25
  - !ruby/object:Gem::Version
31
- hash: 7
32
- segments:
33
- - 1
34
- - 4
35
- - 0
36
- version: 1.4.0
26
+ version: 1.5.0.rc0
37
27
  type: :runtime
38
28
  version_requirements: *id001
39
29
  description: A Ruby driver for MongoDB. For more information about Mongo, see http://www.mongodb.org.
@@ -60,6 +50,7 @@ files:
60
50
  - lib/mongo/gridfs/grid_file_system.rb
61
51
  - lib/mongo/gridfs/grid_io.rb
62
52
  - lib/mongo/gridfs/grid_io_fix.rb
53
+ - lib/mongo/networking.rb
63
54
  - lib/mongo/repl_set_connection.rb
64
55
  - lib/mongo/util/conversions.rb
65
56
  - lib/mongo/util/core_ext.rb
@@ -116,17 +107,17 @@ files:
116
107
  - test/load/thin/load.rb
117
108
  - test/load/unicorn/load.rb
118
109
  - test/pool_test.rb
110
+ - test/replica_sets/basic_test.rb
119
111
  - test/replica_sets/connect_test.rb
120
- - test/replica_sets/connection_string_test.rb
121
112
  - test/replica_sets/count_test.rb
122
113
  - test/replica_sets/insert_test.rb
123
- - test/replica_sets/pooled_insert_test.rb
124
- - test/replica_sets/query_secondaries.rb
125
114
  - test/replica_sets/query_test.rb
126
115
  - test/replica_sets/read_preference_test.rb
127
116
  - test/replica_sets/refresh_test.rb
117
+ - test/replica_sets/refresh_with_threads_test.rb
128
118
  - test/replica_sets/replication_ack_test.rb
129
119
  - test/replica_sets/rs_test_helper.rb
120
+ - test/replica_sets/threading_test.rb
130
121
  - test/safe_test.rb
131
122
  - test/support/hash_with_indifferent_access.rb
132
123
  - test/support/keys.rb
@@ -164,19 +155,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
164
155
  requirements:
165
156
  - - ">="
166
157
  - !ruby/object:Gem::Version
167
- hash: 3
168
- segments:
169
- - 0
170
158
  version: "0"
171
159
  required_rubygems_version: !ruby/object:Gem::Requirement
172
160
  none: false
173
161
  requirements:
174
- - - ">="
162
+ - - ">"
175
163
  - !ruby/object:Gem::Version
176
- hash: 3
177
- segments:
178
- - 0
179
- version: "0"
164
+ version: 1.3.1
180
165
  requirements: []
181
166
 
182
167
  rubyforge_project:
@@ -217,17 +202,17 @@ test_files:
217
202
  - test/load/thin/load.rb
218
203
  - test/load/unicorn/load.rb
219
204
  - test/pool_test.rb
205
+ - test/replica_sets/basic_test.rb
220
206
  - test/replica_sets/connect_test.rb
221
- - test/replica_sets/connection_string_test.rb
222
207
  - test/replica_sets/count_test.rb
223
208
  - test/replica_sets/insert_test.rb
224
- - test/replica_sets/pooled_insert_test.rb
225
- - test/replica_sets/query_secondaries.rb
226
209
  - test/replica_sets/query_test.rb
227
210
  - test/replica_sets/read_preference_test.rb
228
211
  - test/replica_sets/refresh_test.rb
212
+ - test/replica_sets/refresh_with_threads_test.rb
229
213
  - test/replica_sets/replication_ack_test.rb
230
214
  - test/replica_sets/rs_test_helper.rb
215
+ - test/replica_sets/threading_test.rb
231
216
  - test/safe_test.rb
232
217
  - test/support/hash_with_indifferent_access.rb
233
218
  - test/support/keys.rb
@@ -1,29 +0,0 @@
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 teardown
10
- RS.restart_killed_nodes
11
- @conn.close if @conn
12
- end
13
-
14
- def test_connect_with_connection_string
15
- @conn = Connection.from_uri("mongodb://#{RS.host}:#{RS.ports[0]},#{RS.host}:#{RS.ports[1]}?replicaset=#{RS.name}")
16
- assert @conn.is_a?(ReplSetConnection)
17
- assert @conn.connected?
18
- end
19
-
20
- def test_connect_with_full_connection_string
21
- @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")
22
- assert @conn.is_a?(ReplSetConnection)
23
- assert @conn.connected?
24
- assert_equal 2, @conn.safe[:w]
25
- assert @conn.safe[:fsync]
26
- assert @conn.read_pool
27
- end
28
-
29
- end
@@ -1,58 +0,0 @@
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
5
- # on the local host.
6
- class ReplicaSetPooledInsertTest < Test::Unit::TestCase
7
- include Mongo
8
-
9
- def setup
10
- @conn = ReplSetConnection.new([RS.host, RS.ports[0]], [RS.host, RS.ports[1]],
11
- [RS.host, RS.ports[2]], :pool_size => 5, :timeout => 5)
12
- @db = @conn.db(MONGO_TEST_DB)
13
- @db.drop_collection("test-sets")
14
- @coll = @db.collection("test-sets")
15
- end
16
-
17
- def teardown
18
- RS.restart_killed_nodes
19
- @conn.close if @conn
20
- end
21
-
22
- def test_insert
23
- expected_results = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
24
- @coll.save({:a => -1}, :safe => true)
25
-
26
- RS.kill_primary
27
-
28
- threads = []
29
- 10.times do |i|
30
- threads[i] = Thread.new do
31
- rescue_connection_failure do
32
- @coll.save({:a => i}, :safe => true)
33
- end
34
- end
35
- end
36
-
37
- threads.each {|t| t.join}
38
-
39
- # Restart the old master and wait for sync
40
- RS.restart_killed_nodes
41
- sleep(1)
42
- results = []
43
-
44
- rescue_connection_failure do
45
- @coll.find.each {|r| results << r}
46
- expected_results.each do |a|
47
- assert results.any? {|r| r['a'] == a}, "Could not find record for a => #{a}"
48
- end
49
- end
50
-
51
- @coll.save({:a => 10}, :safe => true)
52
- @coll.find.each {|r| results << r}
53
- (expected_results + [10]).each do |a|
54
- assert results.any? {|r| r['a'] == a}, "Could not find record for a => #{a} on second find"
55
- end
56
- end
57
-
58
- end
@@ -1,109 +0,0 @@
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
5
- # on the local host.
6
- class ReplicaSetQuerySecondariesTest < Test::Unit::TestCase
7
- include Mongo
8
-
9
- def setup
10
- @conn = ReplSetConnection.new([RS.host, RS.ports[0]], :read => :secondary)
11
- @db = @conn.db(MONGO_TEST_DB)
12
- @db.drop_collection("test-sets")
13
- end
14
-
15
- def teardown
16
- RS.restart_killed_nodes
17
- @conn.close if @conn
18
- end
19
-
20
- def test_read_primary
21
- rescue_connection_failure do
22
- assert !@conn.read_primary?
23
- assert !@conn.primary?
24
- end
25
- end
26
-
27
- def test_con
28
- assert @conn.primary_pool, "No primary pool!"
29
- assert @conn.read_pool, "No read pool!"
30
- assert @conn.primary_pool.port != @conn.read_pool.port,
31
- "Primary port and read port at the same!"
32
- end
33
-
34
- def test_query_secondaries
35
- @coll = @db.collection("test-sets", :safe => {:w => 3, :wtimeout => 20000})
36
- @coll.save({:a => 20})
37
- @coll.save({:a => 30})
38
- @coll.save({:a => 40})
39
- results = []
40
- @coll.find.each {|r| results << r["a"]}
41
- assert results.include?(20)
42
- assert results.include?(30)
43
- assert results.include?(40)
44
-
45
- RS.kill_primary
46
-
47
- results = []
48
- rescue_connection_failure do
49
- @coll.find.each {|r| results << r}
50
- [20, 30, 40].each do |a|
51
- assert results.any? {|r| r['a'] == a}, "Could not find record for a => #{a}"
52
- end
53
- end
54
- end
55
-
56
- def test_kill_primary
57
- @coll = @db.collection("test-sets", :safe => {:w => 3, :wtimeout => 10000})
58
- @coll.save({:a => 20})
59
- @coll.save({:a => 30})
60
- assert_equal 2, @coll.find.to_a.length
61
-
62
- # Should still be able to read immediately after killing master node
63
- RS.kill_primary
64
- assert_equal 2, @coll.find.to_a.length
65
- rescue_connection_failure do
66
- @coll.save({:a => 50}, :safe => {:w => 2, :wtimeout => 10000})
67
- end
68
- RS.restart_killed_nodes
69
- @coll.save({:a => 50}, :safe => {:w => 2, :wtimeout => 10000})
70
- assert_equal 4, @coll.find.to_a.length
71
- end
72
-
73
- def test_kill_secondary
74
- @coll = @db.collection("test-sets", {:safe => {:w => 3, :wtimeout => 20000}})
75
- @coll.save({:a => 20})
76
- @coll.save({:a => 30})
77
- assert_equal 2, @coll.find.to_a.length
78
-
79
- read_node = RS.get_node_from_port(@conn.read_pool.port)
80
- RS.kill(read_node)
81
-
82
- # Should fail immediately on next read
83
- old_read_pool_port = @conn.read_pool.port
84
- assert_raise ConnectionFailure do
85
- @coll.find.to_a.length
86
- end
87
-
88
- # Should eventually reconnect and be able to read
89
- rescue_connection_failure do
90
- length = @coll.find.to_a.length
91
- assert_equal 2, length
92
- end
93
- new_read_pool_port = @conn.read_pool.port
94
- assert old_read_pool_port != new_read_pool_port
95
- end
96
-
97
- def test_write_lots_of_data
98
- @coll = @db.collection("test-sets", {:safe => {:w => 2}})
99
-
100
- 6000.times do |n|
101
- @coll.save({:a => n})
102
- end
103
-
104
- cursor = @coll.find()
105
- cursor.next
106
- cursor.close
107
- end
108
-
109
- end