mongo 1.8.6 → 1.12.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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/LICENSE +1 -1
- data/README.md +114 -282
- data/Rakefile +18 -4
- data/VERSION +1 -1
- data/bin/mongo_console +27 -5
- data/lib/mongo/bulk_write_collection_view.rb +387 -0
- data/lib/mongo/collection.rb +283 -222
- data/lib/mongo/collection_writer.rb +364 -0
- data/lib/mongo/{util → connection}/node.rb +58 -6
- data/lib/mongo/{util → connection}/pool.rb +61 -37
- data/lib/mongo/{util → connection}/pool_manager.rb +72 -22
- data/lib/mongo/{util → connection}/sharding_pool_manager.rb +13 -0
- data/lib/mongo/connection/socket/socket_util.rb +37 -0
- data/lib/mongo/connection/socket/ssl_socket.rb +95 -0
- data/lib/mongo/connection/socket/tcp_socket.rb +87 -0
- data/lib/mongo/connection/socket/unix_socket.rb +39 -0
- data/lib/mongo/connection/socket.rb +18 -0
- data/lib/mongo/connection.rb +19 -0
- data/lib/mongo/cursor.rb +183 -57
- data/lib/mongo/db.rb +302 -138
- data/lib/mongo/exception.rb +145 -0
- data/lib/mongo/functional/authentication.rb +455 -0
- data/lib/mongo/{util → functional}/logging.rb +23 -7
- data/lib/mongo/functional/read_preference.rb +183 -0
- data/lib/mongo/functional/scram.rb +556 -0
- data/lib/mongo/functional/uri_parser.rb +409 -0
- data/lib/mongo/{util → functional}/write_concern.rb +21 -9
- data/lib/mongo/functional.rb +20 -0
- data/lib/mongo/gridfs/grid.rb +19 -8
- data/lib/mongo/gridfs/grid_ext.rb +14 -0
- data/lib/mongo/gridfs/grid_file_system.rb +17 -4
- data/lib/mongo/gridfs/grid_io.rb +21 -9
- data/lib/mongo/gridfs.rb +18 -0
- data/lib/mongo/legacy.rb +76 -7
- data/lib/mongo/mongo_client.rb +246 -206
- data/lib/mongo/mongo_replica_set_client.rb +65 -15
- data/lib/mongo/mongo_sharded_client.rb +18 -3
- data/lib/mongo/networking.rb +47 -18
- data/lib/mongo/{util → utils}/conversions.rb +18 -3
- data/lib/mongo/{util → utils}/core_ext.rb +15 -32
- data/lib/mongo/{util → utils}/server_version.rb +15 -0
- data/lib/mongo/{util → utils}/support.rb +22 -55
- data/lib/mongo/utils/thread_local_variable_manager.rb +25 -0
- data/lib/mongo/utils.rb +19 -0
- data/lib/mongo.rb +44 -26
- data/mongo.gemspec +2 -2
- data/test/functional/authentication_test.rb +31 -10
- data/test/functional/bulk_api_stress_test.rb +133 -0
- data/test/functional/bulk_write_collection_view_test.rb +1198 -0
- data/test/functional/client_test.rb +627 -0
- data/test/functional/collection_test.rb +1419 -654
- data/test/functional/collection_writer_test.rb +83 -0
- data/test/functional/conversions_test.rb +46 -2
- data/test/functional/cursor_fail_test.rb +17 -9
- data/test/functional/cursor_message_test.rb +28 -15
- data/test/functional/cursor_test.rb +300 -165
- data/test/functional/db_api_test.rb +294 -264
- data/test/functional/db_connection_test.rb +15 -3
- data/test/functional/db_test.rb +165 -99
- data/test/functional/grid_file_system_test.rb +124 -112
- data/test/functional/grid_io_test.rb +17 -3
- data/test/functional/grid_test.rb +16 -2
- data/test/functional/pool_test.rb +99 -10
- data/test/functional/safe_test.rb +18 -4
- data/test/functional/ssl_test.rb +29 -0
- data/test/functional/support_test.rb +14 -0
- data/test/functional/timeout_test.rb +27 -27
- data/test/functional/uri_test.rb +268 -22
- data/test/functional/write_concern_test.rb +19 -5
- data/test/helpers/general.rb +50 -0
- data/test/helpers/test_unit.rb +476 -0
- data/test/replica_set/authentication_test.rb +28 -11
- data/test/replica_set/basic_test.rb +79 -23
- data/test/replica_set/client_test.rb +253 -124
- data/test/replica_set/connection_test.rb +59 -37
- data/test/replica_set/count_test.rb +18 -2
- data/test/replica_set/cursor_test.rb +30 -8
- data/test/replica_set/insert_test.rb +109 -2
- data/test/replica_set/max_values_test.rb +85 -10
- data/test/replica_set/pinning_test.rb +66 -2
- data/test/replica_set/query_test.rb +17 -3
- data/test/replica_set/read_preference_test.rb +115 -96
- data/test/replica_set/refresh_test.rb +59 -9
- data/test/replica_set/replication_ack_test.rb +32 -11
- data/test/replica_set/ssl_test.rb +32 -0
- data/test/sharded_cluster/basic_test.rb +73 -25
- data/test/shared/authentication/basic_auth_shared.rb +260 -0
- data/test/shared/authentication/bulk_api_auth_shared.rb +249 -0
- data/test/shared/authentication/gssapi_shared.rb +176 -0
- data/test/shared/authentication/sasl_plain_shared.rb +96 -0
- data/test/shared/authentication/scram_shared.rb +92 -0
- data/test/shared/ssl_shared.rb +235 -0
- data/test/test_helper.rb +47 -196
- data/test/threading/basic_test.rb +42 -2
- data/test/tools/mongo_config.rb +175 -35
- data/test/tools/mongo_config_test.rb +15 -1
- data/test/unit/client_test.rb +186 -57
- data/test/unit/collection_test.rb +44 -54
- data/test/unit/connection_test.rb +160 -71
- data/test/unit/cursor_test.rb +37 -3
- data/test/unit/db_test.rb +38 -14
- data/test/unit/grid_test.rb +15 -1
- data/test/unit/mongo_sharded_client_test.rb +30 -14
- data/test/unit/node_test.rb +16 -1
- data/test/unit/pool_manager_test.rb +21 -4
- data/test/unit/read_pref_test.rb +386 -1
- data/test/unit/read_test.rb +27 -13
- data/test/unit/safe_test.rb +22 -8
- data/test/unit/sharding_pool_manager_test.rb +25 -4
- data/test/unit/write_concern_test.rb +23 -9
- data.tar.gz.sig +0 -0
- metadata +80 -54
- metadata.gz.sig +0 -0
- data/lib/mongo/exceptions.rb +0 -65
- data/lib/mongo/util/read_preference.rb +0 -112
- data/lib/mongo/util/socket_util.rb +0 -20
- data/lib/mongo/util/ssl_socket.rb +0 -51
- data/lib/mongo/util/tcp_socket.rb +0 -62
- data/lib/mongo/util/thread_local_variable_manager.rb +0 -11
- data/lib/mongo/util/unix_socket.rb +0 -23
- data/lib/mongo/util/uri_parser.rb +0 -337
- data/test/functional/connection_test.rb +0 -449
- data/test/functional/threading_test.rb +0 -95
- data/test/replica_set/complex_connect_test.rb +0 -64
- data/test/shared/authentication.rb +0 -66
- data/test/unit/pool_test.rb +0 -9
- data/test/unit/util_test.rb +0 -55
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# Copyright (C) 2009-2013 MongoDB, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
1
15
|
require 'test_helper'
|
|
2
16
|
|
|
3
17
|
class ReplicaSetCursorTest < Test::Unit::TestCase
|
|
@@ -51,15 +65,17 @@ class ReplicaSetCursorTest < Test::Unit::TestCase
|
|
|
51
65
|
def setup_client(read=:primary)
|
|
52
66
|
route_read ||= read
|
|
53
67
|
# Setup ReplicaSet Connection
|
|
54
|
-
@client = MongoReplicaSetClient.new(@rs.repl_set_seeds, :read => read)
|
|
68
|
+
@client = MongoReplicaSetClient.new(@rs.repl_set_seeds, :read => read, :op_timeout => TEST_OP_TIMEOUT)
|
|
69
|
+
authenticate_client(@client)
|
|
55
70
|
|
|
56
|
-
@db = @client.db(
|
|
71
|
+
@db = @client.db(TEST_DB)
|
|
57
72
|
@db.drop_collection("cursor_tests")
|
|
58
73
|
@coll = @db.collection("cursor_tests")
|
|
59
74
|
insert_docs
|
|
60
75
|
|
|
61
76
|
# Setup Direct Connections
|
|
62
77
|
@primary = Mongo::MongoClient.new(*@client.manager.primary)
|
|
78
|
+
authenticate_client(@primary)
|
|
63
79
|
end
|
|
64
80
|
|
|
65
81
|
def insert_docs
|
|
@@ -79,6 +95,7 @@ class ReplicaSetCursorTest < Test::Unit::TestCase
|
|
|
79
95
|
pool = cursor.instance_variable_get(:@pool)
|
|
80
96
|
cursor.close
|
|
81
97
|
@read = Mongo::MongoClient.new(pool.host, pool.port, :slave_ok => true)
|
|
98
|
+
authenticate_client(@read)
|
|
82
99
|
tag
|
|
83
100
|
rescue Mongo::ConnectionFailure
|
|
84
101
|
false
|
|
@@ -93,24 +110,26 @@ class ReplicaSetCursorTest < Test::Unit::TestCase
|
|
|
93
110
|
read_opts[:comment] = object_id
|
|
94
111
|
|
|
95
112
|
# set profiling level to 2 on client and member to which the query will be routed
|
|
96
|
-
@client.db(
|
|
113
|
+
@client.db(TEST_DB).profiling_level = :all
|
|
97
114
|
@client.secondaries.each do |node|
|
|
98
115
|
node = Mongo::MongoClient.new(node[0], node[1], :slave_ok => true)
|
|
99
|
-
node
|
|
116
|
+
authenticate_client(node)
|
|
117
|
+
node.db(TEST_DB).profiling_level = :all
|
|
100
118
|
end
|
|
101
119
|
|
|
102
120
|
@cursor = @coll.find({}, read_opts)
|
|
103
121
|
@cursor.next
|
|
104
122
|
|
|
105
123
|
# on client and other members set profiling level to 0
|
|
106
|
-
@client.db(
|
|
124
|
+
@client.db(TEST_DB).profiling_level = :off
|
|
107
125
|
@client.secondaries.each do |node|
|
|
108
126
|
node = Mongo::MongoClient.new(node[0], node[1], :slave_ok => true)
|
|
109
|
-
node
|
|
127
|
+
authenticate_client(node)
|
|
128
|
+
node.db(TEST_DB).profiling_level = :off
|
|
110
129
|
end
|
|
111
130
|
# do a query on system.profile of the reader to see if it was used for the query
|
|
112
|
-
profiled_queries = @read.db(
|
|
113
|
-
'ns' => "#{
|
|
131
|
+
profiled_queries = @read.db(TEST_DB).collection('system.profile').find({
|
|
132
|
+
'ns' => "#{TEST_DB}.cursor_tests", "query.$comment" => object_id })
|
|
114
133
|
|
|
115
134
|
assert_equal 1, profiled_queries.count
|
|
116
135
|
end
|
|
@@ -118,6 +137,7 @@ class ReplicaSetCursorTest < Test::Unit::TestCase
|
|
|
118
137
|
# batch from send_initial_query is 101 documents
|
|
119
138
|
# check that you get n_docs back from the query, with the same port
|
|
120
139
|
def cursor_get_more_test(read=:primary)
|
|
140
|
+
return if subject_to_server_4754?(@client)
|
|
121
141
|
set_read_client_and_tag(read)
|
|
122
142
|
10.times do
|
|
123
143
|
# assert that the query went to the correct member
|
|
@@ -138,6 +158,7 @@ class ReplicaSetCursorTest < Test::Unit::TestCase
|
|
|
138
158
|
|
|
139
159
|
# batch from get_more can be huge, so close after send_initial_query
|
|
140
160
|
def kill_cursor_test(read=:primary)
|
|
161
|
+
return if subject_to_server_4754?(@client)
|
|
141
162
|
set_read_client_and_tag(read)
|
|
142
163
|
10.times do
|
|
143
164
|
# assert that the query went to the correct member
|
|
@@ -157,6 +178,7 @@ class ReplicaSetCursorTest < Test::Unit::TestCase
|
|
|
157
178
|
end
|
|
158
179
|
|
|
159
180
|
def assert_cursors_on_members(read=:primary)
|
|
181
|
+
return if subject_to_server_4754?(@client)
|
|
160
182
|
set_read_client_and_tag(read)
|
|
161
183
|
# assert that the query went to the correct member
|
|
162
184
|
route_query(read)
|
|
@@ -1,11 +1,26 @@
|
|
|
1
|
+
# Copyright (C) 2009-2013 MongoDB, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
1
15
|
require 'test_helper'
|
|
2
16
|
|
|
3
17
|
class ReplicaSetInsertTest < Test::Unit::TestCase
|
|
4
18
|
|
|
5
19
|
def setup
|
|
6
20
|
ensure_cluster(:rs)
|
|
7
|
-
@client = MongoReplicaSetClient.
|
|
8
|
-
@
|
|
21
|
+
@client = MongoReplicaSetClient.from_uri(@uri, :op_timeout => TEST_OP_TIMEOUT)
|
|
22
|
+
@version = @client.server_version
|
|
23
|
+
@db = @client.db(TEST_DB)
|
|
9
24
|
@db.drop_collection("test-sets")
|
|
10
25
|
@coll = @db.collection("test-sets")
|
|
11
26
|
end
|
|
@@ -47,4 +62,96 @@ class ReplicaSetInsertTest < Test::Unit::TestCase
|
|
|
47
62
|
end
|
|
48
63
|
end
|
|
49
64
|
|
|
65
|
+
context "Bulk API CollectionView" do
|
|
66
|
+
setup do
|
|
67
|
+
setup
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
should "handle error with deferred write concern error - spec Merging Results" do
|
|
71
|
+
if @client.wire_version_feature?(MongoClient::MONGODB_3_0)
|
|
72
|
+
@coll.remove
|
|
73
|
+
@coll.ensure_index(BSON::OrderedHash[:a, Mongo::ASCENDING], {:unique => true})
|
|
74
|
+
bulk = @coll.initialize_ordered_bulk_op
|
|
75
|
+
bulk.insert({:a => 1})
|
|
76
|
+
bulk.find({:a => 2}).upsert.update({'$set' => {:a => 2}})
|
|
77
|
+
bulk.insert({:a => 1})
|
|
78
|
+
secondary = MongoClient.new(@rs.secondaries.first.host, @rs.secondaries.first.port)
|
|
79
|
+
cmd = BSON::OrderedHash[:configureFailPoint, 'rsSyncApplyStop', :mode, 'alwaysOn']
|
|
80
|
+
secondary['admin'].command(cmd)
|
|
81
|
+
ex = assert_raise BulkWriteError do
|
|
82
|
+
bulk.execute({:w => @rs.servers.size, :wtimeout => 1})
|
|
83
|
+
end
|
|
84
|
+
cmd = BSON::OrderedHash[:configureFailPoint, 'rsSyncApplyStop', :mode, 'off']
|
|
85
|
+
secondary['admin'].command(cmd)
|
|
86
|
+
else
|
|
87
|
+
with_write_commands_and_operations(@db.connection) do |wire_version|
|
|
88
|
+
@coll.remove
|
|
89
|
+
@coll.ensure_index(BSON::OrderedHash[:a, Mongo::ASCENDING], {:unique => true})
|
|
90
|
+
bulk = @coll.initialize_ordered_bulk_op
|
|
91
|
+
bulk.insert({:a => 1})
|
|
92
|
+
bulk.find({:a => 2}).upsert.update({'$set' => {:a => 2}})
|
|
93
|
+
bulk.insert({:a => 1})
|
|
94
|
+
ex = assert_raise BulkWriteError do
|
|
95
|
+
bulk.execute({:w => 5, :wtimeout => 1})
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
result = ex.result
|
|
100
|
+
assert_match_document(
|
|
101
|
+
{
|
|
102
|
+
"ok" => 1,
|
|
103
|
+
"n" => 2,
|
|
104
|
+
"writeErrors" => [
|
|
105
|
+
{
|
|
106
|
+
"index" => 2,
|
|
107
|
+
"code" => 11000,
|
|
108
|
+
"errmsg" => /duplicate key error/,
|
|
109
|
+
}
|
|
110
|
+
],
|
|
111
|
+
"writeConcernError" => [
|
|
112
|
+
{
|
|
113
|
+
"errmsg" => /waiting for replication timed out|timed out waiting for slaves|timeout/,
|
|
114
|
+
"code" => 64,
|
|
115
|
+
"errInfo" => {"wtimeout" => true},
|
|
116
|
+
"index" => 0
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
"errmsg" => /waiting for replication timed out|timed out waiting for slaves|timeout/,
|
|
120
|
+
"code" => 64,
|
|
121
|
+
"errInfo" => {"wtimeout" => true},
|
|
122
|
+
"index" => 1
|
|
123
|
+
}
|
|
124
|
+
],
|
|
125
|
+
"code" => 65,
|
|
126
|
+
"errmsg" => "batch item errors occurred",
|
|
127
|
+
"nInserted" => 1
|
|
128
|
+
}, result)
|
|
129
|
+
assert_equal 2, @coll.find.to_a.size
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
should "handle unordered errors with deferred write concern error - spec Merging Results" do # TODO - spec review
|
|
133
|
+
with_write_commands_and_operations(@db.connection) do |wire_version|
|
|
134
|
+
@coll.remove
|
|
135
|
+
@coll.ensure_index(BSON::OrderedHash[:a, Mongo::ASCENDING], {:unique => true})
|
|
136
|
+
bulk = @coll.initialize_unordered_bulk_op
|
|
137
|
+
bulk.insert({:a => 1})
|
|
138
|
+
bulk.find({:a => 2}).upsert.update({'$set' => {:a => 1}})
|
|
139
|
+
bulk.insert({:a => 3})
|
|
140
|
+
ex = assert_raise BulkWriteError do
|
|
141
|
+
bulk.execute({:w => 5, :wtimeout => 1})
|
|
142
|
+
end
|
|
143
|
+
result = ex.result # unordered varies, don't use assert_bulk_exception
|
|
144
|
+
assert_equal(1, result["ok"], "wire_version:#{wire_version}")
|
|
145
|
+
assert_equal(2, result["n"], "wire_version:#{wire_version}")
|
|
146
|
+
assert(result["nInserted"] >= 1, "wire_version:#{wire_version}")
|
|
147
|
+
assert_equal(65, result["code"], "wire_version:#{wire_version}")
|
|
148
|
+
assert_equal("batch item errors occurred", result["errmsg"], "wire_version:#{wire_version}")
|
|
149
|
+
assert(result["writeErrors"].size >= 1, "wire_version:#{wire_version}")
|
|
150
|
+
assert(result["writeConcernError"].size >= 1, "wire_version:#{wire_version}") if wire_version >= 2
|
|
151
|
+
assert(@coll.size >= 1, "wire_version:#{wire_version}")
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
end
|
|
156
|
+
|
|
50
157
|
end
|
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# Copyright (C) 2009-2013 MongoDB, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
1
15
|
require 'test_helper'
|
|
2
16
|
|
|
3
17
|
class MaxValuesTest < Test::Unit::TestCase
|
|
@@ -6,7 +20,7 @@ class MaxValuesTest < Test::Unit::TestCase
|
|
|
6
20
|
|
|
7
21
|
def setup
|
|
8
22
|
ensure_cluster(:rs)
|
|
9
|
-
@client = MongoReplicaSetClient.
|
|
23
|
+
@client = MongoReplicaSetClient.from_uri(@uri, :op_timeout => TEST_OP_TIMEOUT)
|
|
10
24
|
@db = new_mock_db
|
|
11
25
|
@client.stubs(:[]).returns(@db)
|
|
12
26
|
@ismaster = {
|
|
@@ -15,25 +29,31 @@ class MaxValuesTest < Test::Unit::TestCase
|
|
|
15
29
|
}
|
|
16
30
|
end
|
|
17
31
|
|
|
18
|
-
def
|
|
19
|
-
assert @client.max_message_size
|
|
32
|
+
def test_initial_max_and_min_values
|
|
20
33
|
assert @client.max_bson_size
|
|
34
|
+
assert @client.max_message_size
|
|
35
|
+
assert @client.max_wire_version
|
|
36
|
+
assert @client.min_wire_version
|
|
21
37
|
end
|
|
22
38
|
|
|
23
|
-
def
|
|
39
|
+
def test_updated_max_and_min_sizes_after_node_config_change
|
|
24
40
|
@db.stubs(:command).returns(
|
|
25
41
|
@ismaster.merge({'ismaster' => true}),
|
|
26
42
|
@ismaster.merge({'secondary' => true, 'maxMessageSizeBytes' => 1024 * MESSAGE_SIZE_FACTOR}),
|
|
27
|
-
@ismaster.merge({'secondary' => true, 'maxBsonObjectSize' => 1024})
|
|
43
|
+
@ismaster.merge({'secondary' => true, 'maxBsonObjectSize' => 1024}),
|
|
44
|
+
@ismaster.merge({'secondary' => true, 'maxWireVersion' => 0}),
|
|
45
|
+
@ismaster.merge({'secondary' => true, 'minWireVersion' => 0})
|
|
28
46
|
)
|
|
29
47
|
@client.local_manager.stubs(:refresh_required?).returns(true)
|
|
30
48
|
@client.refresh
|
|
31
49
|
|
|
32
50
|
assert_equal 1024, @client.max_bson_size
|
|
33
51
|
assert_equal 1024 * MESSAGE_SIZE_FACTOR, @client.max_message_size
|
|
52
|
+
assert_equal 0, @client.max_wire_version
|
|
53
|
+
assert_equal 0, @client.min_wire_version
|
|
34
54
|
end
|
|
35
55
|
|
|
36
|
-
def
|
|
56
|
+
def test_no_values_in_config
|
|
37
57
|
@db.stubs(:command).returns(
|
|
38
58
|
@ismaster.merge({'ismaster' => true}),
|
|
39
59
|
@ismaster.merge({'secondary' => true}),
|
|
@@ -44,6 +64,8 @@ class MaxValuesTest < Test::Unit::TestCase
|
|
|
44
64
|
|
|
45
65
|
assert_equal DEFAULT_MAX_BSON_SIZE, @client.max_bson_size
|
|
46
66
|
assert_equal DEFAULT_MAX_BSON_SIZE * MESSAGE_SIZE_FACTOR, @client.max_message_size
|
|
67
|
+
assert_equal 0, @client.max_wire_version
|
|
68
|
+
assert_equal 0, @client.min_wire_version
|
|
47
69
|
end
|
|
48
70
|
|
|
49
71
|
def test_only_bson_size_in_config
|
|
@@ -57,20 +79,73 @@ class MaxValuesTest < Test::Unit::TestCase
|
|
|
57
79
|
|
|
58
80
|
assert_equal 1024, @client.max_bson_size
|
|
59
81
|
assert_equal 1024 * MESSAGE_SIZE_FACTOR, @client.max_message_size
|
|
82
|
+
assert_equal 0, @client.max_wire_version
|
|
83
|
+
assert_equal 0, @client.min_wire_version
|
|
60
84
|
end
|
|
61
85
|
|
|
62
|
-
def
|
|
86
|
+
def test_values_in_config
|
|
87
|
+
#ismaster is called three times on the first node
|
|
63
88
|
@db.stubs(:command).returns(
|
|
64
|
-
@ismaster.merge({'ismaster' => true, 'maxMessageSizeBytes' => 1024 * 2 * MESSAGE_SIZE_FACTOR,
|
|
65
|
-
|
|
66
|
-
@ismaster.merge({'
|
|
89
|
+
@ismaster.merge({'ismaster' => true, 'maxMessageSizeBytes' => 1024 * 2 * MESSAGE_SIZE_FACTOR,
|
|
90
|
+
'maxBsonObjectSize' => 1024, 'maxWireVersion' => 2, 'minWireVersion' => 1}),
|
|
91
|
+
@ismaster.merge({'ismaster' => true, 'maxMessageSizeBytes' => 1024 * 2 * MESSAGE_SIZE_FACTOR,
|
|
92
|
+
'maxBsonObjectSize' => 1024, 'maxWireVersion' => 2, 'minWireVersion' => 1}),
|
|
93
|
+
@ismaster.merge({'ismaster' => true, 'maxMessageSizeBytes' => 1024 * 2 * MESSAGE_SIZE_FACTOR,
|
|
94
|
+
'maxBsonObjectSize' => 1024, 'maxWireVersion' => 2, 'minWireVersion' => 1}),
|
|
95
|
+
@ismaster.merge({'secondary' => true, 'maxMessageSizeBytes' => 1024 * 2 * MESSAGE_SIZE_FACTOR,
|
|
96
|
+
'maxBsonObjectSize' => 1024, 'maxWireVersion' => 2, 'minWireVersion' => 0}),
|
|
97
|
+
@ismaster.merge({'secondary' => true, 'maxMessageSizeBytes' => 1024 * 2 * MESSAGE_SIZE_FACTOR,
|
|
98
|
+
'maxBsonObjectSize' => 1024, 'maxWireVersion' => 1, 'minWireVersion' => 0})
|
|
67
99
|
)
|
|
68
100
|
@client.local_manager.stubs(:refresh_required?).returns(true)
|
|
69
101
|
@client.refresh
|
|
70
102
|
|
|
71
103
|
assert_equal 1024, @client.max_bson_size
|
|
72
104
|
assert_equal 1024 * 2 * MESSAGE_SIZE_FACTOR, @client.max_message_size
|
|
105
|
+
assert_equal 1, @client.max_wire_version # minimum of all max_wire_version
|
|
106
|
+
assert_equal 1, @client.min_wire_version # maximum of all min_wire_version
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def test_wire_version_not_in_range
|
|
110
|
+
min_wire_version, max_wire_version = [Mongo::MongoClient::MIN_WIRE_VERSION-1, Mongo::MongoClient::MIN_WIRE_VERSION-1]
|
|
111
|
+
#ismaster is called three times on the first node
|
|
112
|
+
@db.stubs(:command).returns(
|
|
113
|
+
@ismaster.merge({'ismaster' => true, 'maxWireVersion' => max_wire_version, 'minWireVersion' => min_wire_version}),
|
|
114
|
+
@ismaster.merge({'ismaster' => true, 'maxWireVersion' => max_wire_version, 'minWireVersion' => min_wire_version}),
|
|
115
|
+
@ismaster.merge({'ismaster' => true, 'maxWireVersion' => max_wire_version, 'minWireVersion' => min_wire_version}),
|
|
116
|
+
@ismaster.merge({'secondary' => true, 'maxWireVersion' => max_wire_version, 'minWireVersion' => min_wire_version}),
|
|
117
|
+
@ismaster.merge({'secondary' => true, 'maxWireVersion' => max_wire_version, 'minWireVersion' => min_wire_version})
|
|
118
|
+
)
|
|
119
|
+
@client.local_manager.stubs(:refresh_required?).returns(true)
|
|
120
|
+
assert_raises Mongo::ConnectionFailure do
|
|
121
|
+
@client.refresh
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def test_use_write_command
|
|
126
|
+
with_write_commands(@client) do
|
|
127
|
+
assert_true @client.use_write_command?({:w => 1})
|
|
128
|
+
assert_false @client.use_write_command?({:w => 0})
|
|
129
|
+
end
|
|
130
|
+
with_write_operations(@client) do
|
|
131
|
+
assert_false @client.use_write_command?({:w => 1})
|
|
132
|
+
assert_false @client.use_write_command?({:w => 0})
|
|
133
|
+
end
|
|
134
|
+
@client.local_manager.primary_pool.node.expects(:wire_version_feature?).at_least_once.returns(true)
|
|
135
|
+
assert_true @client.use_write_command?({:w => 1})
|
|
136
|
+
assert_false @client.use_write_command?({:w => 0})
|
|
73
137
|
end
|
|
74
138
|
|
|
139
|
+
def test_max_write_batch_size
|
|
140
|
+
assert_equal Mongo::MongoClient::DEFAULT_MAX_WRITE_BATCH_SIZE, @client.max_write_batch_size
|
|
141
|
+
@client.local_manager.primary_pool.node.stubs(:max_write_batch_size).returns(999)
|
|
142
|
+
assert_equal 999, @client.max_write_batch_size
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def test_max_write_batch_size_no_manager
|
|
146
|
+
# Simulate no local manager being set yet - RUBY-759
|
|
147
|
+
@client.stubs(:local_manager).returns(nil)
|
|
148
|
+
assert_equal Mongo::MongoClient::DEFAULT_MAX_WRITE_BATCH_SIZE, @client.max_write_batch_size
|
|
149
|
+
end
|
|
75
150
|
end
|
|
76
151
|
|
|
@@ -1,10 +1,24 @@
|
|
|
1
|
+
# Copyright (C) 2009-2013 MongoDB, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
1
15
|
require 'test_helper'
|
|
2
16
|
|
|
3
17
|
class ReplicaSetPinningTest < Test::Unit::TestCase
|
|
4
18
|
def setup
|
|
5
19
|
ensure_cluster(:rs)
|
|
6
|
-
@client = MongoReplicaSetClient.
|
|
7
|
-
@db = @client.db(
|
|
20
|
+
@client = MongoReplicaSetClient.from_uri(@uri, :op_timeout => TEST_OP_TIMEOUT)
|
|
21
|
+
@db = @client.db(TEST_DB)
|
|
8
22
|
@coll = @db.collection("test-sets")
|
|
9
23
|
@coll.insert({:a => 1})
|
|
10
24
|
end
|
|
@@ -38,4 +52,54 @@ class ReplicaSetPinningTest < Test::Unit::TestCase
|
|
|
38
52
|
end
|
|
39
53
|
threads.each(&:join)
|
|
40
54
|
end
|
|
55
|
+
|
|
56
|
+
def test_aggregation_cursor_pinning
|
|
57
|
+
return unless @client.server_version >= '2.5.1'
|
|
58
|
+
@coll.drop
|
|
59
|
+
|
|
60
|
+
[10, 1000].each do |size|
|
|
61
|
+
@coll.drop
|
|
62
|
+
size.times {|i| @coll.insert({ :_id => i }) }
|
|
63
|
+
expected_sum = size.times.reduce(:+)
|
|
64
|
+
|
|
65
|
+
cursor = @coll.aggregate(
|
|
66
|
+
[{ :$project => {:_id => '$_id'}} ],
|
|
67
|
+
:cursor => { :batchSize => 1 }
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
assert_equal Mongo::Cursor, cursor.class
|
|
71
|
+
|
|
72
|
+
cursor_sum = cursor.reduce(0) do |sum, doc|
|
|
73
|
+
sum += doc['_id']
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
assert_equal expected_sum, cursor_sum
|
|
77
|
+
end
|
|
78
|
+
@coll.drop
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def test_parallel_scan_pinning
|
|
82
|
+
return unless @client.server_version >= '2.5.5'
|
|
83
|
+
@coll.drop
|
|
84
|
+
|
|
85
|
+
8000.times { |i| @coll.insert({ :_id => i }) }
|
|
86
|
+
|
|
87
|
+
lock = Mutex.new
|
|
88
|
+
doc_ids = Set.new
|
|
89
|
+
threads = []
|
|
90
|
+
cursors = @coll.parallel_scan(3)
|
|
91
|
+
cursors.each_with_index do |cursor, i|
|
|
92
|
+
threads << Thread.new do
|
|
93
|
+
docs = cursor.to_a
|
|
94
|
+
lock.synchronize do
|
|
95
|
+
docs.each do |doc|
|
|
96
|
+
doc_ids << doc['_id']
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
threads.each(&:join)
|
|
102
|
+
assert_equal 8000, doc_ids.count
|
|
103
|
+
@coll.drop
|
|
104
|
+
end
|
|
41
105
|
end
|
|
@@ -1,17 +1,31 @@
|
|
|
1
|
+
# Copyright (C) 2009-2013 MongoDB, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
1
15
|
require 'test_helper'
|
|
2
16
|
|
|
3
17
|
class ReplicaSetQueryTest < Test::Unit::TestCase
|
|
4
18
|
|
|
5
19
|
def setup
|
|
6
20
|
ensure_cluster(:rs)
|
|
7
|
-
@client = MongoReplicaSetClient.
|
|
8
|
-
@db = @client.db(
|
|
21
|
+
@client = MongoReplicaSetClient.from_uri(@uri, :op_timeout => TEST_OP_TIMEOUT)
|
|
22
|
+
@db = @client.db(TEST_DB)
|
|
9
23
|
@db.drop_collection("test-sets")
|
|
10
24
|
@coll = @db.collection("test-sets")
|
|
11
25
|
end
|
|
12
26
|
|
|
13
27
|
def teardown
|
|
14
|
-
@client.close if @
|
|
28
|
+
@client.close if @client
|
|
15
29
|
end
|
|
16
30
|
|
|
17
31
|
def test_query
|