mongo 1.1.4 → 1.1.5
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.
- data/Rakefile +50 -69
- data/docs/CREDITS.md +4 -0
- data/docs/HISTORY.md +9 -0
- data/docs/REPLICA_SETS.md +8 -10
- data/lib/mongo.rb +3 -1
- data/lib/mongo/collection.rb +2 -1
- data/lib/mongo/connection.rb +146 -314
- data/lib/mongo/db.rb +6 -2
- data/lib/mongo/gridfs/grid.rb +1 -1
- data/lib/mongo/gridfs/grid_io.rb +29 -5
- data/lib/mongo/repl_set_connection.rb +290 -0
- data/lib/mongo/util/pool.rb +6 -8
- data/lib/mongo/util/uri_parser.rb +71 -0
- data/mongo.gemspec +1 -2
- data/test/collection_test.rb +9 -7
- data/test/connection_test.rb +0 -6
- data/test/grid_file_system_test.rb +2 -2
- data/test/grid_io_test.rb +33 -1
- data/test/grid_test.rb +36 -6
- data/test/replica_sets/connect_test.rb +59 -21
- data/test/replica_sets/count_test.rb +9 -7
- data/test/replica_sets/insert_test.rb +11 -9
- data/test/replica_sets/pooled_insert_test.rb +12 -13
- data/test/replica_sets/query_secondaries.rb +48 -8
- data/test/replica_sets/query_test.rb +10 -9
- data/test/replica_sets/replication_ack_test.rb +15 -22
- data/test/replica_sets/rs_test_helper.rb +29 -0
- data/test/test_helper.rb +13 -20
- data/test/threading/{test_threading_large_pool.rb → threading_with_large_pool_test.rb} +1 -1
- data/test/tools/repl_set_manager.rb +241 -0
- data/test/tools/test.rb +13 -0
- data/test/unit/connection_test.rb +3 -85
- data/test/unit/repl_set_connection_test.rb +82 -0
- metadata +19 -21
- data/test/replica_pairs/count_test.rb +0 -34
- data/test/replica_pairs/insert_test.rb +0 -50
- data/test/replica_pairs/pooled_insert_test.rb +0 -54
- data/test/replica_pairs/query_test.rb +0 -39
- data/test/replica_sets/node_type_test.rb +0 -42
- data/test/rs.rb +0 -24
data/test/tools/test.rb
ADDED
@@ -41,103 +41,21 @@ class ConnectionTest < Test::Unit::TestCase
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
context "connecting to a replica set" do
|
45
|
-
setup do
|
46
|
-
TCPSocket.stubs(:new).returns(new_mock_socket('localhost', 27017))
|
47
|
-
@conn = Connection.multi([['localhost', 27017]], :connect => false, :read_secondary => true)
|
48
|
-
|
49
|
-
admin_db = new_mock_db
|
50
|
-
@hosts = ['localhost:27018', 'localhost:27019', 'localhost:27020']
|
51
|
-
|
52
|
-
admin_db.stubs(:command).returns({'ok' => 1, 'ismaster' => 1, 'hosts' => @hosts}).
|
53
|
-
then.returns({'ok' => 1, 'ismaster' => 0, 'hosts' => @hosts, 'secondary' => 1}).
|
54
|
-
then.returns({'ok' => 1, 'ismaster' => 0, 'hosts' => @hosts, 'secondary' => 1}).
|
55
|
-
then.returns({'ok' => 1, 'ismaster' => 0, 'arbiterOnly' => 1})
|
56
|
-
|
57
|
-
@conn.stubs(:[]).with('admin').returns(admin_db)
|
58
|
-
@conn.connect
|
59
|
-
end
|
60
|
-
|
61
|
-
should "store the hosts returned from the ismaster command" do
|
62
|
-
assert_equal 'localhost', @conn.primary_pool.host
|
63
|
-
assert_equal 27017, @conn.primary_pool.port
|
64
|
-
|
65
|
-
assert_equal 'localhost', @conn.secondary_pools[0].host
|
66
|
-
assert_equal 27018, @conn.secondary_pools[0].port
|
67
|
-
|
68
|
-
assert_equal 'localhost', @conn.secondary_pools[1].host
|
69
|
-
assert_equal 27019, @conn.secondary_pools[1].port
|
70
|
-
|
71
|
-
assert_equal 2, @conn.secondary_pools.length
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
context "connecting to a replica set and providing seed nodes" do
|
76
|
-
setup do
|
77
|
-
TCPSocket.stubs(:new).returns(new_mock_socket)
|
78
|
-
@conn = Connection.multi([['localhost', 27017], ['localhost', 27019]], :connect => false)
|
79
|
-
|
80
|
-
admin_db = new_mock_db
|
81
|
-
@hosts = ['localhost:27017', 'localhost:27018', 'localhost:27019']
|
82
|
-
admin_db.stubs(:command).returns({'ok' => 1, 'ismaster' => 1, 'hosts' => @hosts})
|
83
|
-
@conn.stubs(:[]).with('admin').returns(admin_db)
|
84
|
-
@conn.connect
|
85
|
-
end
|
86
|
-
|
87
|
-
should "not store any hosts redundantly" do
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
context "initializing a paired connection" do
|
92
|
-
should "require left and right nodes" do
|
93
|
-
assert_raise MongoArgumentError do
|
94
|
-
Connection.multi(['localhost', 27018], :connect => false)
|
95
|
-
end
|
96
|
-
|
97
|
-
assert_raise MongoArgumentError do
|
98
|
-
Connection.multi(['localhost', 27018], :connect => false)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
should "store both nodes" do
|
103
|
-
@conn = Connection.multi([['localhost', 27017], ['localhost', 27018]], :connect => false)
|
104
|
-
|
105
|
-
assert_equal ['localhost', 27017], @conn.nodes[0]
|
106
|
-
assert_equal ['localhost', 27018], @conn.nodes[1]
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
44
|
context "initializing with a mongodb uri" do
|
111
45
|
should "parse a simple uri" do
|
112
46
|
@conn = Connection.from_uri("mongodb://localhost", :connect => false)
|
113
|
-
assert_equal ['localhost', 27017], @conn.
|
47
|
+
assert_equal ['localhost', 27017], @conn.host_to_try
|
114
48
|
end
|
115
49
|
|
116
50
|
should "allow a complex host names" do
|
117
51
|
host_name = "foo.bar-12345.org"
|
118
52
|
@conn = Connection.from_uri("mongodb://#{host_name}", :connect => false)
|
119
|
-
assert_equal [host_name, 27017], @conn.
|
120
|
-
end
|
121
|
-
|
122
|
-
should "parse a uri specifying multiple nodes" do
|
123
|
-
@conn = Connection.from_uri("mongodb://localhost:27017,mydb.com:27018", :connect => false)
|
124
|
-
assert_equal ['localhost', 27017], @conn.nodes[0]
|
125
|
-
assert_equal ['mydb.com', 27018], @conn.nodes[1]
|
126
|
-
end
|
127
|
-
|
128
|
-
should "parse a uri specifying multiple nodes with auth" do
|
129
|
-
@conn = Connection.from_uri("mongodb://kyle:s3cr3t@localhost:27017/app,mickey:m0u5e@mydb.com:27018/dsny", :connect => false)
|
130
|
-
assert_equal ['localhost', 27017], @conn.nodes[0]
|
131
|
-
assert_equal ['mydb.com', 27018], @conn.nodes[1]
|
132
|
-
auth_hash = {'username' => 'kyle', 'password' => 's3cr3t', 'db_name' => 'app'}
|
133
|
-
assert_equal auth_hash, @conn.auths[0]
|
134
|
-
auth_hash = {'username' => 'mickey', 'password' => 'm0u5e', 'db_name' => 'dsny'}
|
135
|
-
assert_equal auth_hash, @conn.auths[1]
|
53
|
+
assert_equal [host_name, 27017], @conn.host_to_try
|
136
54
|
end
|
137
55
|
|
138
56
|
should "parse a uri with a hyphen & underscore in the username or password" do
|
139
57
|
@conn = Connection.from_uri("mongodb://hyphen-user_name:p-s_s@localhost:27017/db", :connect => false)
|
140
|
-
assert_equal ['localhost', 27017], @conn.
|
58
|
+
assert_equal ['localhost', 27017], @conn.host_to_try
|
141
59
|
auth_hash = { 'db_name' => 'db', 'username' => 'hyphen-user_name', "password" => 'p-s_s' }
|
142
60
|
assert_equal auth_hash, @conn.auths[0]
|
143
61
|
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require './test/test_helper'
|
2
|
+
include Mongo
|
3
|
+
|
4
|
+
class ReplSetConnectionTest < Test::Unit::TestCase
|
5
|
+
context "Initialization: " do
|
6
|
+
setup do
|
7
|
+
def new_mock_socket(host='localhost', port=27017)
|
8
|
+
socket = Object.new
|
9
|
+
socket.stubs(:setsockopt).with(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
10
|
+
socket.stubs(:close)
|
11
|
+
socket
|
12
|
+
end
|
13
|
+
|
14
|
+
def new_mock_db
|
15
|
+
db = Object.new
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "connecting to a replica set" do
|
20
|
+
setup do
|
21
|
+
TCPSocket.stubs(:new).returns(new_mock_socket('localhost', 27017))
|
22
|
+
@conn = ReplSetConnection.new(['localhost', 27017], :connect => false, :read_secondary => true)
|
23
|
+
|
24
|
+
admin_db = new_mock_db
|
25
|
+
@hosts = ['localhost:27018', 'localhost:27019', 'localhost:27020']
|
26
|
+
|
27
|
+
admin_db.stubs(:command).returns({'ok' => 1, 'ismaster' => 1, 'hosts' => @hosts}).
|
28
|
+
then.returns({'ok' => 1, 'ismaster' => 0, 'hosts' => @hosts, 'secondary' => 1}).
|
29
|
+
then.returns({'ok' => 1, 'ismaster' => 0, 'hosts' => @hosts, 'secondary' => 1}).
|
30
|
+
then.returns({'ok' => 1, 'ismaster' => 0, 'arbiterOnly' => 1})
|
31
|
+
|
32
|
+
@conn.stubs(:[]).with('admin').returns(admin_db)
|
33
|
+
@conn.connect
|
34
|
+
end
|
35
|
+
|
36
|
+
should "store the hosts returned from the ismaster command" do
|
37
|
+
assert_equal 'localhost', @conn.primary_pool.host
|
38
|
+
assert_equal 27017, @conn.primary_pool.port
|
39
|
+
|
40
|
+
assert_equal 'localhost', @conn.secondary_pools[0].host
|
41
|
+
assert_equal 27018, @conn.secondary_pools[0].port
|
42
|
+
|
43
|
+
assert_equal 'localhost', @conn.secondary_pools[1].host
|
44
|
+
assert_equal 27019, @conn.secondary_pools[1].port
|
45
|
+
|
46
|
+
assert_equal 2, @conn.secondary_pools.length
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "connecting to a replica set and providing seed nodes" do
|
51
|
+
setup do
|
52
|
+
TCPSocket.stubs(:new).returns(new_mock_socket)
|
53
|
+
@conn = ReplSetConnection.new(['localhost', 27017], ['localhost', 27019], :connect => false)
|
54
|
+
|
55
|
+
admin_db = new_mock_db
|
56
|
+
@hosts = ['localhost:27017', 'localhost:27018', 'localhost:27019']
|
57
|
+
admin_db.stubs(:command).returns({'ok' => 1, 'ismaster' => 1, 'hosts' => @hosts})
|
58
|
+
@conn.stubs(:[]).with('admin').returns(admin_db)
|
59
|
+
@conn.connect
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context "initializing with a mongodb uri" do
|
64
|
+
|
65
|
+
should "parse a uri specifying multiple nodes" do
|
66
|
+
@conn = Connection.from_uri("mongodb://localhost:27017,mydb.com:27018", :connect => false)
|
67
|
+
assert_equal ['localhost', 27017], @conn.nodes[0]
|
68
|
+
assert_equal ['mydb.com', 27018], @conn.nodes[1]
|
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
|
+
end
|
81
|
+
end
|
82
|
+
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:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 1.1.
|
9
|
+
- 5
|
10
|
+
version: 1.1.5
|
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-
|
20
|
+
date: 2010-12-15 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:
|
31
|
+
hash: 25
|
32
32
|
segments:
|
33
33
|
- 1
|
34
34
|
- 1
|
35
|
-
-
|
36
|
-
version: 1.1.
|
35
|
+
- 5
|
36
|
+
version: 1.1.5
|
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.
|
@@ -54,6 +54,7 @@ files:
|
|
54
54
|
- lib/mongo/collection.rb
|
55
55
|
- lib/mongo/exceptions.rb
|
56
56
|
- lib/mongo/connection.rb
|
57
|
+
- lib/mongo/repl_set_connection.rb
|
57
58
|
- lib/mongo/gridfs/grid_io.rb
|
58
59
|
- lib/mongo/gridfs/grid_file_system.rb
|
59
60
|
- lib/mongo/gridfs/grid.rb
|
@@ -64,6 +65,7 @@ files:
|
|
64
65
|
- lib/mongo/util/pool.rb
|
65
66
|
- lib/mongo/util/core_ext.rb
|
66
67
|
- lib/mongo/util/server_version.rb
|
68
|
+
- lib/mongo/util/uri_parser.rb
|
67
69
|
- lib/mongo/db.rb
|
68
70
|
- docs/HISTORY.md
|
69
71
|
- docs/TUTORIAL.md
|
@@ -76,6 +78,7 @@ files:
|
|
76
78
|
- bin/mongo_console
|
77
79
|
- test/grid_file_system_test.rb
|
78
80
|
- test/unit/db_test.rb
|
81
|
+
- test/unit/repl_set_connection_test.rb
|
79
82
|
- test/unit/collection_test.rb
|
80
83
|
- test/unit/cursor_test.rb
|
81
84
|
- test/unit/grid_test.rb
|
@@ -84,7 +87,6 @@ files:
|
|
84
87
|
- test/unit/safe_test.rb
|
85
88
|
- test/db_test.rb
|
86
89
|
- test/collection_test.rb
|
87
|
-
- test/rs.rb
|
88
90
|
- test/cursor_test.rb
|
89
91
|
- test/grid_test.rb
|
90
92
|
- test/db_api_test.rb
|
@@ -95,8 +97,10 @@ files:
|
|
95
97
|
- test/conversions_test.rb
|
96
98
|
- test/connection_test.rb
|
97
99
|
- test/cursor_message_test.rb
|
100
|
+
- test/tools/test.rb
|
101
|
+
- test/tools/repl_set_manager.rb
|
98
102
|
- test/cursor_fail_test.rb
|
99
|
-
- test/threading/
|
103
|
+
- test/threading/threading_with_large_pool_test.rb
|
100
104
|
- test/test_helper.rb
|
101
105
|
- test/grid_io_test.rb
|
102
106
|
- test/bson/byte_buffer_test.rb
|
@@ -109,20 +113,16 @@ files:
|
|
109
113
|
- test/support/keys.rb
|
110
114
|
- test/support/hash_with_indifferent_access.rb
|
111
115
|
- test/db_connection_test.rb
|
116
|
+
- test/replica_sets/rs_test_helper.rb
|
112
117
|
- test/replica_sets/pooled_insert_test.rb
|
113
118
|
- test/replica_sets/count_test.rb
|
114
119
|
- test/replica_sets/replication_ack_test.rb
|
115
120
|
- test/replica_sets/query_secondaries.rb
|
116
121
|
- test/replica_sets/query_test.rb
|
117
|
-
- test/replica_sets/node_type_test.rb
|
118
122
|
- test/replica_sets/insert_test.rb
|
119
123
|
- test/replica_sets/connect_test.rb
|
120
124
|
- test/safe_test.rb
|
121
125
|
- test/support_test.rb
|
122
|
-
- test/replica_pairs/pooled_insert_test.rb
|
123
|
-
- test/replica_pairs/count_test.rb
|
124
|
-
- test/replica_pairs/query_test.rb
|
125
|
-
- test/replica_pairs/insert_test.rb
|
126
126
|
- test/threading_test.rb
|
127
127
|
has_rdoc: true
|
128
128
|
homepage: http://www.mongodb.org
|
@@ -163,6 +163,7 @@ summary: Ruby driver for the MongoDB
|
|
163
163
|
test_files:
|
164
164
|
- test/grid_file_system_test.rb
|
165
165
|
- test/unit/db_test.rb
|
166
|
+
- test/unit/repl_set_connection_test.rb
|
166
167
|
- test/unit/collection_test.rb
|
167
168
|
- test/unit/cursor_test.rb
|
168
169
|
- test/unit/grid_test.rb
|
@@ -171,7 +172,6 @@ test_files:
|
|
171
172
|
- test/unit/safe_test.rb
|
172
173
|
- test/db_test.rb
|
173
174
|
- test/collection_test.rb
|
174
|
-
- test/rs.rb
|
175
175
|
- test/cursor_test.rb
|
176
176
|
- test/grid_test.rb
|
177
177
|
- test/db_api_test.rb
|
@@ -182,8 +182,10 @@ test_files:
|
|
182
182
|
- test/conversions_test.rb
|
183
183
|
- test/connection_test.rb
|
184
184
|
- test/cursor_message_test.rb
|
185
|
+
- test/tools/test.rb
|
186
|
+
- test/tools/repl_set_manager.rb
|
185
187
|
- test/cursor_fail_test.rb
|
186
|
-
- test/threading/
|
188
|
+
- test/threading/threading_with_large_pool_test.rb
|
187
189
|
- test/test_helper.rb
|
188
190
|
- test/grid_io_test.rb
|
189
191
|
- test/bson/byte_buffer_test.rb
|
@@ -196,18 +198,14 @@ test_files:
|
|
196
198
|
- test/support/keys.rb
|
197
199
|
- test/support/hash_with_indifferent_access.rb
|
198
200
|
- test/db_connection_test.rb
|
201
|
+
- test/replica_sets/rs_test_helper.rb
|
199
202
|
- test/replica_sets/pooled_insert_test.rb
|
200
203
|
- test/replica_sets/count_test.rb
|
201
204
|
- test/replica_sets/replication_ack_test.rb
|
202
205
|
- test/replica_sets/query_secondaries.rb
|
203
206
|
- test/replica_sets/query_test.rb
|
204
|
-
- test/replica_sets/node_type_test.rb
|
205
207
|
- test/replica_sets/insert_test.rb
|
206
208
|
- test/replica_sets/connect_test.rb
|
207
209
|
- test/safe_test.rb
|
208
210
|
- test/support_test.rb
|
209
|
-
- test/replica_pairs/pooled_insert_test.rb
|
210
|
-
- test/replica_pairs/count_test.rb
|
211
|
-
- test/replica_pairs/query_test.rb
|
212
|
-
- test/replica_pairs/insert_test.rb
|
213
211
|
- test/threading_test.rb
|
@@ -1,34 +0,0 @@
|
|
1
|
-
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
-
require 'mongo'
|
3
|
-
require 'test/unit'
|
4
|
-
require './test/test_helper'
|
5
|
-
|
6
|
-
# NOTE: this test should be run only if a replica pair is running.
|
7
|
-
class ReplicaPairCountTest < Test::Unit::TestCase
|
8
|
-
include Mongo
|
9
|
-
|
10
|
-
def setup
|
11
|
-
@conn = Mongo::Connection.new({:left => ["localhost", 27017], :right => ["localhost", 27018]}, nil)
|
12
|
-
@db = @conn.db('mongo-ruby-test')
|
13
|
-
@db.drop_collection("test-pairs")
|
14
|
-
@coll = @db.collection("test-pairs")
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_correct_count_after_insertion_reconnect
|
18
|
-
@coll.insert({:a => 20}, :safe => true)
|
19
|
-
assert_equal 1, @coll.count
|
20
|
-
|
21
|
-
# Sleep to allow resync
|
22
|
-
sleep(3)
|
23
|
-
|
24
|
-
puts "Please disconnect the current master."
|
25
|
-
gets
|
26
|
-
|
27
|
-
rescue_connection_failure do
|
28
|
-
@coll.insert({:a => 30}, :safe => true)
|
29
|
-
end
|
30
|
-
@coll.insert({:a => 40}, :safe => true)
|
31
|
-
assert_equal 3, @coll.count, "Second count failed"
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
-
require 'mongo'
|
3
|
-
require 'test/unit'
|
4
|
-
require './test/test_helper'
|
5
|
-
|
6
|
-
# NOTE: this test should be run only if a replica pair is running.
|
7
|
-
class ReplicaPairInsertTest < Test::Unit::TestCase
|
8
|
-
include Mongo
|
9
|
-
|
10
|
-
def setup
|
11
|
-
@conn = Mongo::Connection.new({:left => ["localhost", 27017], :right => ["localhost", 27018]}, nil)
|
12
|
-
@db = @conn.db('mongo-ruby-test')
|
13
|
-
@db.drop_collection("test-pairs")
|
14
|
-
@coll = @db.collection("test-pairs")
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_insert
|
18
|
-
@coll.save({:a => 20}, :safe => true)
|
19
|
-
puts "Please disconnect the current master."
|
20
|
-
gets
|
21
|
-
|
22
|
-
rescue_connection_failure do
|
23
|
-
@coll.save({:a => 30}, :safe => true)
|
24
|
-
end
|
25
|
-
|
26
|
-
@coll.save({:a => 40}, :safe => true)
|
27
|
-
@coll.save({:a => 50}, :safe => true)
|
28
|
-
@coll.save({:a => 60}, :safe => true)
|
29
|
-
@coll.save({:a => 70}, :safe => true)
|
30
|
-
|
31
|
-
puts "Please reconnect the old master to make sure that the new master " +
|
32
|
-
"has synced with the previous master. Note: this may have happened already."
|
33
|
-
gets
|
34
|
-
results = []
|
35
|
-
|
36
|
-
rescue_connection_failure do
|
37
|
-
@coll.find.each {|r| results << r}
|
38
|
-
[20, 30, 40, 50, 60, 70].each do |a|
|
39
|
-
assert results.any? {|r| r['a'] == a}, "Could not find record for a => #{a}"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
@coll.save({:a => 80}, :safe => true)
|
44
|
-
@coll.find.each {|r| results << r}
|
45
|
-
[20, 30, 40, 50, 60, 70, 80].each do |a|
|
46
|
-
assert results.any? {|r| r['a'] == a}, "Could not find record for a => #{a} on second find"
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
-
require 'mongo'
|
3
|
-
require 'test/unit'
|
4
|
-
require './test/test_helper'
|
5
|
-
|
6
|
-
# NOTE: this test should be run only if a replica pair is running.
|
7
|
-
class ReplicaPairPooledInsertTest < Test::Unit::TestCase
|
8
|
-
include Mongo
|
9
|
-
|
10
|
-
def setup
|
11
|
-
@conn = Mongo::Connection.new({:left => ["localhost", 27017], :right => ["localhost", 27018]}, nil, :pool_size => 10, :timeout => 5)
|
12
|
-
@db = @conn.db('mongo-ruby-test')
|
13
|
-
@db.drop_collection("test-pairs")
|
14
|
-
@coll = @db.collection("test-pairs")
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_insert
|
18
|
-
expected_results = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
19
|
-
@coll.save({:a => -1}, :safe => true)
|
20
|
-
puts "Please disconnect the current master."
|
21
|
-
gets
|
22
|
-
|
23
|
-
threads = []
|
24
|
-
10.times do |i|
|
25
|
-
threads[i] = Thread.new do
|
26
|
-
rescue_connection_failure do
|
27
|
-
@coll.save({:a => i}, :safe => true)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
puts "Please reconnect the old master to make sure that the new master " +
|
33
|
-
"has synced with the previous master. Note: this may have happened already." +
|
34
|
-
"Note also that when connection with multiple threads, you may need to wait a few seconds" +
|
35
|
-
"after restarting the old master so that all the data has had a chance to sync." +
|
36
|
-
"This is a case of eventual consistency."
|
37
|
-
gets
|
38
|
-
results = []
|
39
|
-
|
40
|
-
rescue_connection_failure do
|
41
|
-
@coll.find.each {|r| results << r}
|
42
|
-
expected_results.each do |a|
|
43
|
-
assert results.any? {|r| r['a'] == a}, "Could not find record for a => #{a}"
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
@coll.save({:a => 10}, :safe => true)
|
48
|
-
@coll.find.each {|r| results << r}
|
49
|
-
(expected_results + [10]).each do |a|
|
50
|
-
assert results.any? {|r| r['a'] == a}, "Could not find record for a => #{a} on second find"
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|