mongo 1.3.0 → 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 +7 -0
- checksums.yaml.gz.sig +0 -0
- data/{LICENSE.txt → LICENSE} +1 -1
- data/README.md +122 -271
- data/Rakefile +25 -209
- data/VERSION +1 -0
- data/bin/mongo_console +31 -9
- data/lib/mongo/bulk_write_collection_view.rb +387 -0
- data/lib/mongo/collection.rb +576 -269
- data/lib/mongo/collection_writer.rb +364 -0
- data/lib/mongo/connection/node.rb +249 -0
- data/lib/mongo/connection/pool.rb +340 -0
- data/lib/mongo/connection/pool_manager.rb +320 -0
- data/lib/mongo/connection/sharding_pool_manager.rb +67 -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 +7 -875
- data/lib/mongo/cursor.rb +403 -117
- data/lib/mongo/db.rb +444 -243
- data/lib/mongo/exception.rb +145 -0
- data/lib/mongo/functional/authentication.rb +455 -0
- data/lib/mongo/functional/logging.rb +85 -0
- 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/functional/write_concern.rb +66 -0
- data/lib/mongo/functional.rb +20 -0
- data/lib/mongo/gridfs/grid.rb +30 -24
- data/lib/mongo/gridfs/grid_ext.rb +6 -10
- data/lib/mongo/gridfs/grid_file_system.rb +38 -20
- data/lib/mongo/gridfs/grid_io.rb +84 -75
- data/lib/mongo/gridfs.rb +18 -0
- data/lib/mongo/legacy.rb +140 -0
- data/lib/mongo/mongo_client.rb +697 -0
- data/lib/mongo/mongo_replica_set_client.rb +535 -0
- data/lib/mongo/mongo_sharded_client.rb +159 -0
- data/lib/mongo/networking.rb +372 -0
- data/lib/mongo/{util → utils}/conversions.rb +29 -8
- data/lib/mongo/{util → utils}/core_ext.rb +28 -18
- data/lib/mongo/{util → utils}/server_version.rb +4 -6
- data/lib/mongo/{util → utils}/support.rb +29 -31
- data/lib/mongo/utils/thread_local_variable_manager.rb +25 -0
- data/lib/mongo/utils.rb +19 -0
- data/lib/mongo.rb +51 -50
- data/mongo.gemspec +29 -32
- data/test/functional/authentication_test.rb +39 -0
- 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 +2175 -0
- data/test/functional/collection_writer_test.rb +83 -0
- data/test/{conversions_test.rb → functional/conversions_test.rb} +47 -3
- data/test/functional/cursor_fail_test.rb +57 -0
- data/test/functional/cursor_message_test.rb +56 -0
- data/test/functional/cursor_test.rb +683 -0
- data/test/functional/db_api_test.rb +835 -0
- data/test/functional/db_connection_test.rb +25 -0
- data/test/functional/db_test.rb +348 -0
- data/test/functional/grid_file_system_test.rb +285 -0
- data/test/{grid_io_test.rb → functional/grid_io_test.rb} +72 -11
- data/test/{grid_test.rb → functional/grid_test.rb} +88 -15
- data/test/functional/pool_test.rb +136 -0
- data/test/functional/safe_test.rb +98 -0
- data/test/functional/ssl_test.rb +29 -0
- data/test/functional/support_test.rb +62 -0
- data/test/functional/timeout_test.rb +60 -0
- data/test/functional/uri_test.rb +446 -0
- data/test/functional/write_concern_test.rb +118 -0
- data/test/helpers/general.rb +50 -0
- data/test/helpers/test_unit.rb +476 -0
- data/test/replica_set/authentication_test.rb +37 -0
- data/test/replica_set/basic_test.rb +189 -0
- data/test/replica_set/client_test.rb +393 -0
- data/test/replica_set/connection_test.rb +138 -0
- data/test/replica_set/count_test.rb +66 -0
- data/test/replica_set/cursor_test.rb +220 -0
- data/test/replica_set/insert_test.rb +157 -0
- data/test/replica_set/max_values_test.rb +151 -0
- data/test/replica_set/pinning_test.rb +105 -0
- data/test/replica_set/query_test.rb +73 -0
- data/test/replica_set/read_preference_test.rb +219 -0
- data/test/replica_set/refresh_test.rb +211 -0
- data/test/replica_set/replication_ack_test.rb +95 -0
- data/test/replica_set/ssl_test.rb +32 -0
- data/test/sharded_cluster/basic_test.rb +203 -0
- 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 +53 -94
- data/test/threading/basic_test.rb +120 -0
- data/test/tools/mongo_config.rb +708 -0
- data/test/tools/mongo_config_test.rb +160 -0
- data/test/unit/client_test.rb +381 -0
- data/test/unit/collection_test.rb +89 -53
- data/test/unit/connection_test.rb +282 -32
- data/test/unit/cursor_test.rb +206 -8
- data/test/unit/db_test.rb +55 -13
- data/test/unit/grid_test.rb +43 -16
- data/test/unit/mongo_sharded_client_test.rb +48 -0
- data/test/unit/node_test.rb +93 -0
- data/test/unit/pool_manager_test.rb +111 -0
- data/test/unit/read_pref_test.rb +406 -0
- data/test/unit/read_test.rb +159 -0
- data/test/unit/safe_test.rb +69 -36
- data/test/unit/sharding_pool_manager_test.rb +84 -0
- data/test/unit/write_concern_test.rb +175 -0
- data.tar.gz.sig +3 -0
- metadata +227 -216
- metadata.gz.sig +0 -0
- data/docs/CREDITS.md +0 -123
- data/docs/FAQ.md +0 -116
- data/docs/GridFS.md +0 -158
- data/docs/HISTORY.md +0 -244
- data/docs/RELEASES.md +0 -33
- data/docs/REPLICA_SETS.md +0 -72
- data/docs/TUTORIAL.md +0 -247
- data/docs/WRITE_CONCERN.md +0 -28
- data/lib/mongo/exceptions.rb +0 -71
- data/lib/mongo/gridfs/grid_io_fix.rb +0 -38
- data/lib/mongo/repl_set_connection.rb +0 -342
- data/lib/mongo/test.rb +0 -20
- data/lib/mongo/util/pool.rb +0 -177
- data/lib/mongo/util/uri_parser.rb +0 -185
- data/test/async/collection_test.rb +0 -224
- data/test/async/connection_test.rb +0 -24
- data/test/async/cursor_test.rb +0 -162
- data/test/async/worker_pool_test.rb +0 -99
- data/test/auxillary/1.4_features.rb +0 -166
- data/test/auxillary/authentication_test.rb +0 -68
- data/test/auxillary/autoreconnect_test.rb +0 -41
- data/test/auxillary/fork_test.rb +0 -30
- data/test/auxillary/repl_set_auth_test.rb +0 -58
- data/test/auxillary/slave_connection_test.rb +0 -36
- data/test/auxillary/threaded_authentication_test.rb +0 -101
- data/test/bson/binary_test.rb +0 -15
- data/test/bson/bson_test.rb +0 -649
- data/test/bson/byte_buffer_test.rb +0 -208
- data/test/bson/hash_with_indifferent_access_test.rb +0 -38
- data/test/bson/json_test.rb +0 -17
- data/test/bson/object_id_test.rb +0 -154
- data/test/bson/ordered_hash_test.rb +0 -204
- data/test/bson/timestamp_test.rb +0 -24
- data/test/collection_test.rb +0 -910
- data/test/connection_test.rb +0 -309
- data/test/cursor_fail_test.rb +0 -75
- data/test/cursor_message_test.rb +0 -43
- data/test/cursor_test.rb +0 -483
- data/test/db_api_test.rb +0 -726
- data/test/db_connection_test.rb +0 -15
- data/test/db_test.rb +0 -287
- data/test/grid_file_system_test.rb +0 -243
- data/test/load/resque/load.rb +0 -21
- data/test/load/resque/processor.rb +0 -26
- data/test/load/thin/load.rb +0 -24
- data/test/load/unicorn/load.rb +0 -23
- data/test/load/unicorn/unicorn.rb +0 -29
- data/test/replica_sets/connect_test.rb +0 -94
- data/test/replica_sets/connection_string_test.rb +0 -32
- data/test/replica_sets/count_test.rb +0 -35
- data/test/replica_sets/insert_test.rb +0 -53
- data/test/replica_sets/pooled_insert_test.rb +0 -55
- data/test/replica_sets/query_secondaries.rb +0 -96
- data/test/replica_sets/query_test.rb +0 -51
- data/test/replica_sets/replication_ack_test.rb +0 -66
- data/test/replica_sets/rs_test_helper.rb +0 -27
- data/test/safe_test.rb +0 -68
- data/test/support/hash_with_indifferent_access.rb +0 -186
- data/test/support/keys.rb +0 -45
- data/test/support_test.rb +0 -18
- data/test/threading/threading_with_large_pool_test.rb +0 -90
- data/test/threading_test.rb +0 -87
- data/test/tools/auth_repl_set_manager.rb +0 -14
- data/test/tools/load.rb +0 -58
- data/test/tools/repl_set_manager.rb +0 -266
- data/test/tools/sharding_manager.rb +0 -202
- data/test/tools/test.rb +0 -4
- data/test/unit/pool_test.rb +0 -9
- data/test/unit/repl_set_connection_test.rb +0 -59
- data/test/uri_test.rb +0 -91
@@ -0,0 +1,83 @@
|
|
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
|
+
|
15
|
+
require 'test_helper'
|
16
|
+
|
17
|
+
module Mongo
|
18
|
+
class Collection
|
19
|
+
public :batch_write
|
20
|
+
end
|
21
|
+
class CollectionWriter
|
22
|
+
public :sort_by_first_sym, :ordered_group_by_first
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class CollectionWriterTest < Test::Unit::TestCase
|
27
|
+
|
28
|
+
DATABASE_NAME = 'ruby_test_collection_writer'
|
29
|
+
COLLECTION_NAME = 'test'
|
30
|
+
|
31
|
+
def default_setup
|
32
|
+
@client = MongoClient.from_uri(TEST_URI)
|
33
|
+
@db = @client[DATABASE_NAME]
|
34
|
+
@collection = @db[COLLECTION_NAME]
|
35
|
+
@collection.drop
|
36
|
+
end
|
37
|
+
|
38
|
+
context "Bulk API Execute" do
|
39
|
+
setup do
|
40
|
+
default_setup
|
41
|
+
end
|
42
|
+
|
43
|
+
should "sort_by_first_sym for grouping unordered ops" do
|
44
|
+
pairs = [
|
45
|
+
[:insert, {:n => 0}],
|
46
|
+
[:update, {:n => 1}], [:update, {:n => 2}],
|
47
|
+
[:delete, {:n => 3}],
|
48
|
+
[:insert, {:n => 5}], [:insert, {:n => 6}], [:insert, {:n => 7}],
|
49
|
+
[:update, {:n => 8}],
|
50
|
+
[:delete, {:n => 9}], [:delete, {:n => 10}]
|
51
|
+
]
|
52
|
+
result = @collection.command_writer.sort_by_first_sym(pairs)
|
53
|
+
expected = [
|
54
|
+
:delete, :delete, :delete,
|
55
|
+
:insert, :insert, :insert, :insert,
|
56
|
+
:update, :update, :update
|
57
|
+
]
|
58
|
+
assert_equal expected, result.collect{|first, rest| first}
|
59
|
+
end
|
60
|
+
|
61
|
+
should "calculate ordered_group_by_first" do
|
62
|
+
pairs = [
|
63
|
+
[:insert, {:n => 0}],
|
64
|
+
[:update, {:n => 1}], [:update, {:n => 2}],
|
65
|
+
[:delete, {:n => 3}],
|
66
|
+
[:insert, {:n => 5}], [:insert, {:n => 6}], [:insert, {:n => 7}],
|
67
|
+
[:update, {:n => 8}],
|
68
|
+
[:delete, {:n => 9}], [:delete, {:n => 10}]
|
69
|
+
]
|
70
|
+
result = @collection.command_writer.ordered_group_by_first(pairs)
|
71
|
+
expected = [
|
72
|
+
[:insert, [{:n => 0}]],
|
73
|
+
[:update, [{:n => 1}, {:n => 2}]],
|
74
|
+
[:delete, [{:n => 3}]],
|
75
|
+
[:insert, [{:n => 5}, {:n => 6}, {:n => 7}]],
|
76
|
+
[:update, [{:n => 8}]],
|
77
|
+
[:delete, [{:n => 9}, {:n => 10}]]
|
78
|
+
]
|
79
|
+
assert_equal expected, result
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
@@ -1,6 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
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
|
+
|
15
|
+
require 'test_helper'
|
4
16
|
|
5
17
|
class ConversionsTest < Test::Unit::TestCase
|
6
18
|
include Mongo::Conversions
|
@@ -15,6 +27,34 @@ class ConversionsTest < Test::Unit::TestCase
|
|
15
27
|
assert_equal({ "field1" => 1, "field2" => -1 }, params)
|
16
28
|
end
|
17
29
|
|
30
|
+
def test_array_as_sort_parameters_with_array_of_key_and_hash
|
31
|
+
params = array_as_sort_parameters(["score", {"$meta" => "textScore"}])
|
32
|
+
assert_equal({"score" => {"$meta" => "textScore"}}, params)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_array_as_sort_parameters_with_array_of_key_and_hashes
|
36
|
+
params = array_as_sort_parameters([["field1", :asc],["score", {"$meta" => "textScore"}]])
|
37
|
+
assert_equal({"field1" => 1, "score" => {"$meta" => "textScore"}}, params)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_hash_as_sort_parameters_with_string
|
41
|
+
sort = BSON::OrderedHash["field", "asc"]
|
42
|
+
params = hash_as_sort_parameters(sort)
|
43
|
+
assert_equal({"field" => 1}, params)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_hash_as_sort_parameters_with_hash
|
47
|
+
sort = BSON::OrderedHash["score", {"$meta" => "textScore"}]
|
48
|
+
params = hash_as_sort_parameters(sort)
|
49
|
+
assert_equal({"score" => {"$meta" => "textScore"}}, params)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_hash_as_sort_parameters_with_hash_and_string
|
53
|
+
sort = BSON::OrderedHash["score", {"$meta" => "textScore"}, "field", "asc"]
|
54
|
+
params = hash_as_sort_parameters(sort)
|
55
|
+
assert_equal({ "score" => {"$meta" => "textScore"}, "field" => 1 }, params)
|
56
|
+
end
|
57
|
+
|
18
58
|
def test_string_as_sort_parameters_with_string
|
19
59
|
params = string_as_sort_parameters("field")
|
20
60
|
assert_equal({ "field" => 1 }, params)
|
@@ -110,6 +150,10 @@ class ConversionsTest < Test::Unit::TestCase
|
|
110
150
|
assert_equal(-1, sort_value(:DESC))
|
111
151
|
end
|
112
152
|
|
153
|
+
def test_sort_value_when_value_is_hash
|
154
|
+
assert_equal({"$meta" => "textScore"}, sort_value("$meta" => "textScore"))
|
155
|
+
end
|
156
|
+
|
113
157
|
def test_sort_value_when_value_is_invalid
|
114
158
|
assert_raise Mongo::InvalidSortValueError do
|
115
159
|
sort_value(2)
|
@@ -0,0 +1,57 @@
|
|
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
|
+
|
15
|
+
require 'test_helper'
|
16
|
+
require 'logger'
|
17
|
+
|
18
|
+
class CursorFailTest < Test::Unit::TestCase
|
19
|
+
|
20
|
+
include Mongo
|
21
|
+
|
22
|
+
def setup
|
23
|
+
@connection = standard_connection
|
24
|
+
@db = @connection[TEST_DB]
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_refill_via_get_more_alt_coll
|
28
|
+
coll = @db.collection('test-alt-coll')
|
29
|
+
coll.remove
|
30
|
+
coll.insert('a' => 1) # collection not created until it's used
|
31
|
+
assert_equal 1, coll.count
|
32
|
+
|
33
|
+
1000.times { |i|
|
34
|
+
assert_equal 1 + i, coll.count
|
35
|
+
coll.insert('a' => i)
|
36
|
+
}
|
37
|
+
|
38
|
+
assert_equal 1001, coll.count
|
39
|
+
count = 0
|
40
|
+
coll.find.each { |obj|
|
41
|
+
count += obj['a']
|
42
|
+
}
|
43
|
+
assert_equal 1001, coll.count
|
44
|
+
|
45
|
+
# do the same thing again for debugging
|
46
|
+
assert_equal 1001, coll.count
|
47
|
+
count2 = 0
|
48
|
+
coll.find.each { |obj|
|
49
|
+
count2 += obj['a']
|
50
|
+
}
|
51
|
+
assert_equal 1001, coll.count
|
52
|
+
|
53
|
+
assert_equal count, count2
|
54
|
+
assert_equal 499501, count
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,56 @@
|
|
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
|
+
|
15
|
+
require 'test_helper'
|
16
|
+
require 'logger'
|
17
|
+
|
18
|
+
class CursorMessageTest < Test::Unit::TestCase
|
19
|
+
|
20
|
+
include Mongo
|
21
|
+
|
22
|
+
def setup
|
23
|
+
@connection = standard_connection
|
24
|
+
@db = @connection.db(TEST_DB)
|
25
|
+
@coll = @db.collection('test')
|
26
|
+
@version = @connection.server_version
|
27
|
+
@coll.remove
|
28
|
+
@coll.insert('a' => 1) # collection not created until it's used
|
29
|
+
@coll_full_name = "#{TEST_DB}.test"
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_valid_batch_sizes
|
33
|
+
assert_raise ArgumentError do
|
34
|
+
@coll.find({}, :batch_size => 1, :limit => 5)
|
35
|
+
end
|
36
|
+
|
37
|
+
assert_raise ArgumentError do
|
38
|
+
@coll.find({}, :batch_size => -1, :limit => 5)
|
39
|
+
end
|
40
|
+
|
41
|
+
assert @coll.find({}, :batch_size => 0, :limit => 5)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_batch_size
|
45
|
+
@coll.remove
|
46
|
+
200.times do |n|
|
47
|
+
@coll.insert({:a => n})
|
48
|
+
end
|
49
|
+
|
50
|
+
list = @coll.find({}, :batch_size => 2, :limit => 6).to_a
|
51
|
+
assert_equal 6, list.length
|
52
|
+
|
53
|
+
list = @coll.find({}, :batch_size => 100, :limit => 101).to_a
|
54
|
+
assert_equal 101, list.length
|
55
|
+
end
|
56
|
+
end
|