mongo 2.0.6 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +5 -2
- data/lib/mongo/address/ipv4.rb +6 -1
- data/lib/mongo/address/unix.rb +2 -2
- data/lib/mongo/address.rb +18 -10
- data/lib/mongo/auth/cr/conversation.rb +1 -1
- data/lib/mongo/auth/ldap/conversation.rb +7 -3
- data/lib/mongo/auth/scram/conversation.rb +9 -3
- data/lib/mongo/auth/user/view.rb +23 -2
- data/lib/mongo/auth/x509/conversation.rb +1 -1
- data/lib/mongo/bulk_write/combineable.rb +51 -0
- data/lib/mongo/bulk_write/ordered_combiner.rb +55 -0
- data/lib/mongo/bulk_write/result.rb +191 -0
- data/lib/mongo/bulk_write/result_combiner.rb +117 -0
- data/lib/mongo/bulk_write/transformable.rb +132 -0
- data/lib/mongo/bulk_write/unordered_combiner.rb +52 -0
- data/lib/mongo/bulk_write/validatable.rb +62 -0
- data/lib/mongo/bulk_write.rb +159 -23
- data/lib/mongo/client.rb +52 -16
- data/lib/mongo/cluster/topology/replica_set.rb +27 -9
- data/lib/mongo/cluster/topology/sharded.rb +1 -1
- data/lib/mongo/cluster/topology/unknown.rb +5 -2
- data/lib/mongo/cluster.rb +42 -7
- data/lib/mongo/collection/view/aggregation.rb +48 -9
- data/lib/mongo/collection/view/immutable.rb +6 -6
- data/lib/mongo/collection/view/iterable.rb +18 -4
- data/lib/mongo/collection/view/map_reduce.rb +58 -17
- data/lib/mongo/collection/view/readable.rb +173 -42
- data/lib/mongo/collection/view/writable.rb +37 -23
- data/lib/mongo/collection/view.rb +2 -2
- data/lib/mongo/collection.rb +370 -33
- data/lib/mongo/cursor.rb +15 -3
- data/lib/mongo/database/view.rb +5 -4
- data/lib/mongo/database.rb +14 -4
- data/lib/mongo/dbref.rb +113 -0
- data/lib/mongo/error/closed_stream.rb +34 -0
- data/lib/mongo/error/extra_file_chunk.rb +34 -0
- data/lib/mongo/error/{invalid_uri_option.rb → file_not_found.rb} +11 -12
- data/lib/mongo/error/invalid_file.rb +2 -2
- data/lib/mongo/error/invalid_file_revision.rb +37 -0
- data/lib/mongo/error/invalid_uri.rb +5 -4
- data/lib/mongo/error/missing_file_chunk.rb +38 -0
- data/lib/mongo/error/operation_failure.rb +1 -1
- data/lib/mongo/error/parser.rb +1 -1
- data/lib/mongo/error/unchangeable_collection_option.rb +38 -0
- data/lib/mongo/error/unexpected_chunk_length.rb +39 -0
- data/lib/mongo/error.rb +13 -2
- data/lib/mongo/event/description_changed.rb +1 -1
- data/lib/mongo/grid/file/chunk.rb +6 -6
- data/lib/mongo/grid/file/{metadata.rb → info.rb} +41 -39
- data/lib/mongo/grid/file.rb +13 -10
- data/lib/mongo/grid/fs_bucket.rb +448 -0
- data/lib/mongo/grid/stream/read.rb +208 -0
- data/lib/mongo/grid/stream/write.rb +187 -0
- data/lib/mongo/grid/stream.rb +64 -0
- data/lib/mongo/grid.rb +2 -1
- data/lib/mongo/index/view.rb +3 -3
- data/lib/mongo/index.rb +5 -0
- data/lib/mongo/loggable.rb +34 -57
- data/lib/mongo/logger.rb +16 -78
- data/lib/mongo/monitoring/command_log_subscriber.rb +112 -0
- data/lib/mongo/monitoring/event/command_failed.rb +96 -0
- data/lib/mongo/monitoring/event/command_started.rb +89 -0
- data/lib/mongo/monitoring/event/command_succeeded.rb +118 -0
- data/lib/mongo/monitoring/event/secure.rb +58 -0
- data/lib/mongo/monitoring/event.rb +18 -0
- data/lib/mongo/monitoring/publishable.rb +106 -0
- data/lib/mongo/monitoring.rb +195 -0
- data/lib/mongo/operation/{aggregate.rb → commands/aggregate.rb} +3 -41
- data/lib/mongo/operation/commands/collections_info/result.rb +39 -0
- data/lib/mongo/operation/commands/collections_info.rb +68 -0
- data/lib/mongo/operation/{command.rb → commands/command.rb} +2 -18
- data/lib/mongo/operation/commands/indexes.rb +70 -0
- data/lib/mongo/operation/commands/list_collections/result.rb +112 -0
- data/lib/mongo/operation/commands/list_collections.rb +54 -0
- data/lib/mongo/operation/commands/list_indexes/result.rb +116 -0
- data/lib/mongo/operation/commands/list_indexes.rb +56 -0
- data/lib/mongo/operation/{map_reduce → commands/map_reduce}/result.rb +1 -1
- data/lib/mongo/operation/{map_reduce.rb → commands/map_reduce.rb} +3 -41
- data/lib/mongo/operation/commands/parallel_scan/result.rb +72 -0
- data/lib/mongo/operation/commands/parallel_scan.rb +56 -0
- data/lib/mongo/operation/commands/user_query.rb +69 -0
- data/lib/mongo/{bulk_write/ordered_bulk_write.rb → operation/commands/users_info/result.rb} +18 -30
- data/lib/mongo/operation/commands/users_info.rb +53 -0
- data/lib/mongo/operation/commands.rb +24 -0
- data/lib/mongo/operation/executable.rb +4 -68
- data/lib/mongo/operation/kill_cursors.rb +3 -3
- data/lib/mongo/operation/read/get_more.rb +2 -22
- data/lib/mongo/{bulk_write/unordered_bulk_write.rb → operation/read/query/result.rb} +20 -26
- data/lib/mongo/operation/read/query.rb +4 -21
- data/lib/mongo/operation/read.rb +0 -4
- data/lib/mongo/operation/{read_preferrable.rb → read_preference.rb} +3 -2
- data/lib/mongo/operation/result.rb +13 -1
- data/lib/mongo/operation/specifiable.rb +42 -0
- data/lib/mongo/operation/write/bulk/bulkable.rb +82 -0
- data/lib/mongo/operation/write/bulk/delete/result.rb +74 -0
- data/lib/mongo/operation/write/bulk/delete.rb +71 -0
- data/lib/mongo/operation/write/bulk/insert/result.rb +129 -0
- data/lib/mongo/operation/write/bulk/insert.rb +96 -0
- data/lib/mongo/operation/write/bulk/legacy_mergable.rb +87 -0
- data/lib/mongo/operation/write/bulk/mergable.rb +71 -0
- data/lib/mongo/operation/write/bulk/update/result.rb +174 -0
- data/lib/mongo/operation/write/bulk/update.rb +81 -0
- data/lib/mongo/operation/write/bulk.rb +6 -3
- data/lib/mongo/operation/write/command/create_index.rb +0 -1
- data/lib/mongo/operation/write/command/create_user.rb +0 -1
- data/lib/mongo/operation/write/command/delete.rb +0 -1
- data/lib/mongo/operation/write/command/drop_index.rb +0 -1
- data/lib/mongo/operation/write/command/insert.rb +0 -1
- data/lib/mongo/operation/write/command/remove_user.rb +0 -1
- data/lib/mongo/operation/write/command/update.rb +0 -1
- data/lib/mongo/operation/write/command/update_user.rb +0 -1
- data/lib/mongo/operation/write/command/writable.rb +13 -18
- data/lib/mongo/operation/write/create_index.rb +4 -27
- data/lib/mongo/operation/write/create_user.rb +4 -30
- data/lib/mongo/operation/write/delete.rb +6 -29
- data/lib/mongo/operation/write/drop_index.rb +3 -3
- data/lib/mongo/operation/write/gle.rb +48 -0
- data/lib/mongo/operation/write/idable.rb +5 -0
- data/lib/mongo/operation/write/insert.rb +2 -24
- data/lib/mongo/operation/write/remove_user.rb +4 -27
- data/lib/mongo/operation/write/update.rb +13 -36
- data/lib/mongo/operation/write/update_user.rb +4 -30
- data/lib/mongo/operation/write/write_command_enabled.rb +53 -0
- data/lib/mongo/operation/write.rb +2 -0
- data/lib/mongo/operation.rb +32 -4
- data/lib/mongo/options/mapper.rb +4 -2
- data/lib/mongo/options/redacted.rb +156 -0
- data/lib/mongo/options.rb +1 -0
- data/lib/mongo/protocol/delete.rb +75 -15
- data/lib/mongo/protocol/get_more.rb +65 -13
- data/lib/mongo/protocol/insert.rb +85 -13
- data/lib/mongo/protocol/kill_cursors.rb +59 -14
- data/lib/mongo/protocol/message.rb +12 -12
- data/lib/mongo/protocol/query.rb +163 -37
- data/lib/mongo/protocol/reply.rb +103 -0
- data/lib/mongo/protocol/serializers.rb +1 -1
- data/lib/mongo/protocol/update.rb +82 -14
- data/lib/mongo/retryable.rb +83 -0
- data/lib/mongo/server/connectable.rb +21 -25
- data/lib/mongo/server/connection.rb +75 -4
- data/lib/mongo/server/connection_pool/queue.rb +15 -0
- data/lib/mongo/server/connection_pool.rb +12 -0
- data/lib/mongo/server/description/features.rb +2 -1
- data/lib/mongo/server/description.rb +52 -1
- data/lib/mongo/server/monitor/connection.rb +26 -2
- data/lib/mongo/server/monitor.rb +19 -3
- data/lib/mongo/server.rb +39 -5
- data/lib/mongo/server_selector/selectable.rb +40 -31
- data/lib/mongo/server_selector.rb +19 -10
- data/lib/mongo/socket/ssl.rb +28 -16
- data/lib/mongo/socket/tcp.rb +3 -3
- data/lib/mongo/socket/unix.rb +5 -8
- data/lib/mongo/socket.rb +11 -4
- data/lib/mongo/uri.rb +248 -137
- data/lib/mongo/version.rb +1 -1
- data/lib/mongo.rb +5 -3
- data/spec/mongo/address/unix_spec.rb +1 -1
- data/spec/mongo/address_spec.rb +25 -0
- data/spec/mongo/auth/cr_spec.rb +9 -1
- data/spec/mongo/auth/ldap/conversation_spec.rb +43 -0
- data/spec/mongo/auth/ldap_spec.rb +9 -1
- data/spec/mongo/auth/scram_spec.rb +9 -1
- data/spec/mongo/auth/user/view_spec.rb +26 -1
- data/spec/mongo/auth/x509_spec.rb +9 -1
- data/spec/mongo/bulk_write/ordered_combiner_spec.rb +271 -0
- data/spec/mongo/bulk_write/unordered_combiner_spec.rb +239 -0
- data/spec/mongo/bulk_write_spec.rb +428 -0
- data/spec/mongo/client_spec.rb +167 -17
- data/spec/mongo/cluster/topology/replica_set_spec.rb +18 -9
- data/spec/mongo/cluster/topology/sharded_spec.rb +11 -3
- data/spec/mongo/cluster/topology/single_spec.rb +12 -4
- data/spec/mongo/cluster_spec.rb +55 -10
- data/spec/mongo/collection/view/aggregation_spec.rb +188 -1
- data/spec/mongo/collection/view/explainable_spec.rb +1 -1
- data/spec/mongo/collection/view/immutable_spec.rb +103 -0
- data/spec/mongo/collection/view/map_reduce_spec.rb +99 -4
- data/spec/mongo/collection/view/readable_spec.rb +238 -6
- data/spec/mongo/collection/view/writable_spec.rb +4 -4
- data/spec/mongo/collection/view_spec.rb +459 -71
- data/spec/mongo/collection_spec.rb +1291 -9
- data/spec/mongo/command_monitoring_spec.rb +51 -0
- data/spec/mongo/connection_string_spec.rb +115 -0
- data/spec/mongo/crud_spec.rb +2 -2
- data/spec/mongo/cursor_spec.rb +3 -3
- data/spec/mongo/database_spec.rb +47 -11
- data/spec/mongo/dbref_spec.rb +149 -0
- data/spec/mongo/grid/file/chunk_spec.rb +5 -5
- data/spec/mongo/grid/file/{metadata_spec.rb → info_spec.rb} +29 -17
- data/spec/mongo/grid/file_spec.rb +8 -8
- data/spec/mongo/grid/fs_bucket_spec.rb +1020 -0
- data/spec/mongo/grid/stream/read_spec.rb +275 -0
- data/spec/mongo/grid/stream/write_spec.rb +440 -0
- data/spec/mongo/grid/stream_spec.rb +48 -0
- data/spec/mongo/gridfs_spec.rb +50 -0
- data/spec/mongo/logger_spec.rb +0 -40
- data/spec/mongo/monitoring/command_log_subscriber_spec.rb +76 -0
- data/spec/mongo/monitoring/event/command_started_spec.rb +26 -0
- data/spec/mongo/monitoring/event/command_succeeded_spec.rb +26 -0
- data/spec/mongo/monitoring/event/secure_spec.rb +57 -0
- data/spec/mongo/monitoring_spec.rb +168 -0
- data/spec/mongo/operation/commands/aggregate_spec.rb +69 -0
- data/spec/mongo/operation/{read → commands}/collections_info_spec.rb +1 -1
- data/spec/mongo/operation/{command_spec.rb → commands/command_spec.rb} +0 -18
- data/spec/mongo/operation/{read → commands}/indexes_spec.rb +1 -1
- data/spec/mongo/operation/{map_reduce_spec.rb → commands/map_reduce_spec.rb} +1 -19
- data/spec/mongo/operation/kill_cursors_spec.rb +1 -17
- data/spec/mongo/operation/read/get_more_spec.rb +0 -16
- data/spec/mongo/operation/read/query_spec.rb +19 -16
- data/spec/mongo/operation/{read_preferrable_spec.rb → read_preference_spec.rb} +11 -11
- data/spec/mongo/operation/write/bulk/{bulk_delete_spec.rb → delete_spec.rb} +18 -29
- data/spec/mongo/operation/write/bulk/{bulk_insert_spec.rb → insert_spec.rb} +3 -14
- data/spec/mongo/operation/write/bulk/{bulk_update_spec.rb → update_spec.rb} +8 -19
- data/spec/mongo/operation/write/command/delete_spec.rb +0 -16
- data/spec/mongo/operation/write/command/insert_spec.rb +0 -16
- data/spec/mongo/operation/write/command/update_spec.rb +0 -16
- data/spec/mongo/operation/write/delete_spec.rb +4 -4
- data/spec/mongo/operation/write/insert_spec.rb +2 -13
- data/spec/mongo/operation/write/update_spec.rb +7 -7
- data/spec/mongo/options/redacted_spec.rb +350 -0
- data/spec/mongo/protocol/kill_cursors_spec.rb +5 -3
- data/spec/mongo/protocol/query_spec.rb +15 -30
- data/spec/mongo/retryable_spec.rb +147 -0
- data/spec/mongo/server/connection_pool/queue_spec.rb +16 -0
- data/spec/mongo/server/connection_pool_spec.rb +50 -6
- data/spec/mongo/server/connection_spec.rb +49 -4
- data/spec/mongo/server/description_spec.rb +49 -3
- data/spec/mongo/server/monitor_spec.rb +51 -0
- data/spec/mongo/server_discovery_and_monitoring_spec.rb +32 -59
- data/spec/mongo/server_selection_rtt_spec.rb +37 -57
- data/spec/mongo/server_selection_spec.rb +19 -9
- data/spec/mongo/server_selector/nearest_spec.rb +35 -27
- data/spec/mongo/server_selector/primary_preferred_spec.rb +32 -30
- data/spec/mongo/server_selector/primary_spec.rb +21 -14
- data/spec/mongo/server_selector/secondary_preferred_spec.rb +28 -26
- data/spec/mongo/server_selector/secondary_spec.rb +24 -22
- data/spec/mongo/server_selector_spec.rb +87 -24
- data/spec/mongo/server_spec.rb +94 -8
- data/spec/mongo/socket/ssl_spec.rb +123 -13
- data/spec/mongo/socket/unix_spec.rb +52 -0
- data/spec/mongo/uri_spec.rb +295 -67
- data/spec/spec_helper.rb +40 -24
- data/spec/support/authorization.rb +23 -9
- data/spec/support/certificates/client.pem +4 -4
- data/spec/support/command_monitoring/bulkWrite.yml +73 -0
- data/spec/support/command_monitoring/command.yml +42 -0
- data/spec/support/command_monitoring/deleteMany.yml +55 -0
- data/spec/support/command_monitoring/deleteOne.yml +55 -0
- data/spec/support/command_monitoring/find.yml +219 -0
- data/spec/support/command_monitoring/insertMany.yml +81 -0
- data/spec/support/command_monitoring/insertOne.yml +51 -0
- data/spec/support/command_monitoring/updateMany.yml +67 -0
- data/spec/support/command_monitoring/updateOne.yml +95 -0
- data/spec/support/command_monitoring.rb +365 -0
- data/spec/support/connection_string.rb +228 -0
- data/spec/support/connection_string_tests/invalid-uris.yml +193 -0
- data/spec/support/connection_string_tests/valid-auth.yml +256 -0
- data/spec/support/connection_string_tests/valid-host_identifiers.yml +121 -0
- data/spec/support/connection_string_tests/valid-options.yml +30 -0
- data/spec/support/connection_string_tests/valid-unix_socket-absolute.yml +197 -0
- data/spec/support/connection_string_tests/valid-unix_socket-relative.yml +213 -0
- data/spec/support/connection_string_tests/valid-warnings.yml +55 -0
- data/spec/support/crud/read.rb +22 -19
- data/spec/support/crud/write.rb +58 -27
- data/spec/support/crud.rb +10 -2
- data/spec/support/gridfs.rb +637 -0
- data/spec/support/gridfs_tests/delete.yml +157 -0
- data/spec/support/gridfs_tests/download.yml +210 -0
- data/spec/support/gridfs_tests/download_by_name.yml +113 -0
- data/spec/support/gridfs_tests/upload.yml +158 -0
- data/spec/support/matchers.rb +1 -1
- data/spec/support/sdam/rs/equal_electionids.yml +44 -0
- data/spec/support/sdam/rs/new_primary_new_electionid.yml +95 -0
- data/spec/support/sdam/rs/null_election_id.yml +144 -0
- data/spec/support/sdam/rs/primary_disconnect_electionid.yml +124 -0
- data/spec/support/sdam/rs/primary_mismatched_me.yml +37 -0
- data/spec/support/sdam/rs/primary_to_no_primary_mismatched_me.yml +75 -0
- data/spec/support/sdam/rs/secondary_mismatched_me.yml +37 -0
- data/spec/support/sdam/sharded/mongos_disconnect.yml +104 -0
- data/spec/support/sdam/single/direct_connection_rsarbiter.yml +1 -1
- data/spec/support/sdam/single/direct_connection_rsprimary.yml +1 -1
- data/spec/support/sdam/single/direct_connection_rssecondary.yml +1 -1
- data/spec/support/sdam/single/direct_connection_slave.yml +1 -1
- data/spec/support/sdam/single/direct_connection_standalone.yml +1 -1
- data/spec/support/sdam/single/not_ok_response.yml +0 -1
- data/spec/support/server_discovery_and_monitoring.rb +22 -3
- data/spec/support/server_selection.rb +3 -1
- data/spec/support/shared/bulk_write.rb +218 -22
- data/spec/support/shared/server_selector.rb +80 -14
- data.tar.gz.sig +0 -0
- metadata +188 -59
- metadata.gz.sig +0 -0
- data/lib/mongo/bulk_write/bulk_writable.rb +0 -196
- data/lib/mongo/bulk_write/deletable.rb +0 -56
- data/lib/mongo/bulk_write/insertable.rb +0 -48
- data/lib/mongo/bulk_write/replacable.rb +0 -57
- data/lib/mongo/bulk_write/updatable.rb +0 -68
- data/lib/mongo/grid/fs.rb +0 -149
- data/lib/mongo/operation/list_collections/result.rb +0 -114
- data/lib/mongo/operation/list_indexes/result.rb +0 -118
- data/lib/mongo/operation/read/collections_info.rb +0 -68
- data/lib/mongo/operation/read/indexes.rb +0 -69
- data/lib/mongo/operation/read/list_collections.rb +0 -76
- data/lib/mongo/operation/read/list_indexes.rb +0 -78
- data/lib/mongo/operation/write/bulk/bulk_delete/result.rb +0 -75
- data/lib/mongo/operation/write/bulk/bulk_delete.rb +0 -145
- data/lib/mongo/operation/write/bulk/bulk_insert/result.rb +0 -130
- data/lib/mongo/operation/write/bulk/bulk_insert.rb +0 -132
- data/lib/mongo/operation/write/bulk/bulk_mergable.rb +0 -67
- data/lib/mongo/operation/write/bulk/bulk_update/result.rb +0 -162
- data/lib/mongo/operation/write/bulk/bulk_update.rb +0 -154
- data/lib/mongo/operation/write/bulk/legacy_bulk_mergable.rb +0 -83
- data/spec/mongo/bulk/bulk_write_spec.rb +0 -262
- data/spec/mongo/grid/fs_spec.rb +0 -160
- data/spec/mongo/loggable_spec.rb +0 -63
- data/spec/mongo/operation/aggregate_spec.rb +0 -127
- /data/lib/mongo/operation/{aggregate → commands/aggregate}/result.rb +0 -0
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
def runnable?(file)
|
4
|
+
!write_command_enabled? && (file.include?('bulkWrite') || file.include?('insert'))
|
5
|
+
end
|
6
|
+
|
7
|
+
describe 'Command Monitoring Events' do
|
8
|
+
|
9
|
+
COMMAND_MONITORING_TESTS.each do |file|
|
10
|
+
|
11
|
+
spec = Mongo::CommandMonitoring::Spec.new(file)
|
12
|
+
|
13
|
+
spec.tests.each do |test|
|
14
|
+
|
15
|
+
context(test.description) do
|
16
|
+
|
17
|
+
let(:subscriber) do
|
18
|
+
Mongo::CommandMonitoring::TestSubscriber.new
|
19
|
+
end
|
20
|
+
|
21
|
+
let(:monitoring) do
|
22
|
+
authorized_client.instance_variable_get(:@monitoring)
|
23
|
+
end
|
24
|
+
|
25
|
+
before do
|
26
|
+
authorized_collection.find.delete_many
|
27
|
+
authorized_client.subscribe(Mongo::Monitoring::COMMAND, subscriber)
|
28
|
+
end
|
29
|
+
|
30
|
+
after do
|
31
|
+
monitoring.subscribers[Mongo::Monitoring::COMMAND].delete(subscriber)
|
32
|
+
authorized_collection.find.delete_many
|
33
|
+
end
|
34
|
+
|
35
|
+
test.expectations.each do |expectation|
|
36
|
+
|
37
|
+
it "generates a #{expectation.event_name} for #{expectation.command_name}", unless: runnable?(file) do
|
38
|
+
begin
|
39
|
+
test.run(authorized_collection)
|
40
|
+
event = subscriber.send(expectation.event_type)[expectation.command_name]
|
41
|
+
expect(event).to send(expectation.matcher, expectation)
|
42
|
+
rescue Mongo::Error::OperationFailure, Mongo::Error::BulkWriteError => e
|
43
|
+
event = subscriber.send(expectation.event_type)[expectation.command_name]
|
44
|
+
expect(event).to send(expectation.matcher, expectation)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'ConnectionString' do
|
4
|
+
include Mongo::ConnectionString
|
5
|
+
|
6
|
+
CONNECTION_STRING_TESTS.each do |file|
|
7
|
+
|
8
|
+
spec = Mongo::ConnectionString::Spec.new(file)
|
9
|
+
|
10
|
+
context(spec.description) do
|
11
|
+
|
12
|
+
before(:all) do
|
13
|
+
|
14
|
+
module Mongo
|
15
|
+
class Address
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
alias :original_initialize_resolver! :initialize_resolver!
|
20
|
+
def initialize_resolver!(timeout, ssl_options)
|
21
|
+
family = (host == 'localhost') ? ::Socket::AF_INET : ::Socket::AF_UNSPEC
|
22
|
+
info = ::Socket.getaddrinfo(host, nil, family, ::Socket::SOCK_STREAM)
|
23
|
+
FAMILY_MAP[info.first[4]].new(info[3], port, host)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class Server
|
28
|
+
|
29
|
+
# The constructor keeps the same API, but does not instantiate a
|
30
|
+
# monitor and run it.
|
31
|
+
alias :original_initialize :initialize
|
32
|
+
def initialize(address, cluster, monitoring, event_listeners, options = {})
|
33
|
+
@address = address
|
34
|
+
@cluster = cluster
|
35
|
+
@monitoring = monitoring
|
36
|
+
@options = options.freeze
|
37
|
+
@monitor = Monitor.new(address, event_listeners, options)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Disconnect simply needs to return true since we have no monitor and
|
41
|
+
# no connection.
|
42
|
+
alias :original_disconnect! :disconnect!
|
43
|
+
def disconnect!; true; end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
after(:all) do
|
49
|
+
|
50
|
+
module Mongo
|
51
|
+
# Return the implementations to their originals for the other
|
52
|
+
# tests in the suite.
|
53
|
+
class Address
|
54
|
+
alias :initialize_resolver! :original_initialize_resolver!
|
55
|
+
remove_method(:original_initialize_resolver!)
|
56
|
+
end
|
57
|
+
|
58
|
+
class Server
|
59
|
+
alias :initialize :original_initialize
|
60
|
+
remove_method(:original_initialize)
|
61
|
+
|
62
|
+
alias :disconnect! :original_disconnect!
|
63
|
+
remove_method(:original_disconnect!)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
spec.tests.each_with_index do |test, index|
|
69
|
+
|
70
|
+
context "when a #{test.description} is provided" do
|
71
|
+
|
72
|
+
|
73
|
+
context 'when the uri is invalid', unless: test.valid? do
|
74
|
+
|
75
|
+
it 'raises an error' do
|
76
|
+
expect{
|
77
|
+
test.uri
|
78
|
+
}.to raise_exception(Mongo::Error::InvalidURI)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'when the uri should warn', if: test.warn? do
|
83
|
+
|
84
|
+
before do
|
85
|
+
expect(Mongo::Logger.logger).to receive(:warn)
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'warns' do
|
89
|
+
expect(test.client).to be_a(Mongo::Client)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'when the uri is valid', if: test.valid? do
|
94
|
+
|
95
|
+
it 'does not raise an exception' do
|
96
|
+
expect(test.uri).to be_a(Mongo::URI)
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'creates a client with the correct hosts' do
|
100
|
+
expect(test.client).to have_hosts(test)
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'creates a client with the correct authentication properties' do
|
104
|
+
expect(test.client).to match_auth(test)
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'creates a client with the correct options' do
|
108
|
+
expect(test.client).to match_options(test)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
data/spec/mongo/crud_spec.rb
CHANGED
@@ -13,11 +13,11 @@ describe 'CRUD' do
|
|
13
13
|
context(test.description) do
|
14
14
|
|
15
15
|
before(:each) do
|
16
|
-
authorized_collection.
|
16
|
+
authorized_collection.delete_many
|
17
17
|
end
|
18
18
|
|
19
19
|
after(:each) do
|
20
|
-
authorized_collection.
|
20
|
+
authorized_collection.delete_many
|
21
21
|
end
|
22
22
|
|
23
23
|
let(:results) do
|
data/spec/mongo/cursor_spec.rb
CHANGED
@@ -33,7 +33,7 @@ describe Mongo::Cursor do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
after do
|
36
|
-
authorized_collection.
|
36
|
+
authorized_collection.delete_many
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'returns the correct amount' do
|
@@ -58,7 +58,7 @@ describe Mongo::Cursor do
|
|
58
58
|
end
|
59
59
|
|
60
60
|
after do
|
61
|
-
authorized_collection.
|
61
|
+
authorized_collection.delete_many
|
62
62
|
end
|
63
63
|
|
64
64
|
it 'returns the correct amount' do
|
@@ -84,7 +84,7 @@ describe Mongo::Cursor do
|
|
84
84
|
end
|
85
85
|
|
86
86
|
after do
|
87
|
-
authorized_collection.
|
87
|
+
authorized_collection.delete_many
|
88
88
|
end
|
89
89
|
|
90
90
|
context 'when a limit is provided' do
|
data/spec/mongo/database_spec.rb
CHANGED
@@ -93,6 +93,26 @@ describe Mongo::Database do
|
|
93
93
|
expect(database.collection_names(batch_size: 1).to_a).to include('users')
|
94
94
|
end
|
95
95
|
end
|
96
|
+
|
97
|
+
context 'when there are more collections than the initial batch size' do
|
98
|
+
|
99
|
+
before do
|
100
|
+
200.times do |i|
|
101
|
+
database["#{i}_dalmatians"].create
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
after do
|
106
|
+
200.times do |i|
|
107
|
+
database["#{i}_dalmatians"].drop
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'returns all collections' do
|
112
|
+
expect(database.collection_names.select { |c| c =~ /dalmatians/}.size).to eq(200)
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
96
116
|
end
|
97
117
|
|
98
118
|
describe '#list_collections' do
|
@@ -195,7 +215,7 @@ describe Mongo::Database do
|
|
195
215
|
end
|
196
216
|
|
197
217
|
let(:client) do
|
198
|
-
authorized_client.with(server_selection_timeout:
|
218
|
+
authorized_client.with(server_selection_timeout: 0.1)
|
199
219
|
end
|
200
220
|
|
201
221
|
let(:database) do
|
@@ -278,7 +298,7 @@ describe Mongo::Database do
|
|
278
298
|
shared_context 'a GridFS database' do
|
279
299
|
|
280
300
|
it 'returns a Grid::FS for the db' do
|
281
|
-
expect(fs).to be_a(Mongo::Grid::
|
301
|
+
expect(fs).to be_a(Mongo::Grid::FSBucket)
|
282
302
|
end
|
283
303
|
|
284
304
|
context 'when operating on the fs' do
|
@@ -292,8 +312,8 @@ describe Mongo::Database do
|
|
292
312
|
end
|
293
313
|
|
294
314
|
after do
|
295
|
-
fs.files_collection.
|
296
|
-
fs.chunks_collection.
|
315
|
+
fs.files_collection.delete_many
|
316
|
+
fs.chunks_collection.delete_many
|
297
317
|
end
|
298
318
|
|
299
319
|
let(:from_db) do
|
@@ -301,7 +321,7 @@ describe Mongo::Database do
|
|
301
321
|
end
|
302
322
|
|
303
323
|
it 'returns the assembled file from the db' do
|
304
|
-
expect(from_db.filename).to eq(file.
|
324
|
+
expect(from_db.filename).to eq(file.info.filename)
|
305
325
|
end
|
306
326
|
end
|
307
327
|
end
|
@@ -317,15 +337,31 @@ describe Mongo::Database do
|
|
317
337
|
|
318
338
|
context 'when a custom prefix is provided' do
|
319
339
|
|
320
|
-
|
321
|
-
|
322
|
-
|
340
|
+
context 'when the option is fs_name' do
|
341
|
+
|
342
|
+
let(:fs) do
|
343
|
+
database.fs(:fs_name => 'grid')
|
344
|
+
end
|
323
345
|
|
324
|
-
|
325
|
-
|
346
|
+
it 'sets the custom prefix' do
|
347
|
+
expect(fs.prefix).to eq('grid')
|
348
|
+
end
|
349
|
+
|
350
|
+
it_behaves_like 'a GridFS database'
|
326
351
|
end
|
327
352
|
|
328
|
-
|
353
|
+
context 'when the option is bucket_name' do
|
354
|
+
|
355
|
+
let(:fs) do
|
356
|
+
database.fs(:bucket_name => 'grid')
|
357
|
+
end
|
358
|
+
|
359
|
+
it 'sets the custom prefix' do
|
360
|
+
expect(fs.prefix).to eq('grid')
|
361
|
+
end
|
362
|
+
|
363
|
+
it_behaves_like 'a GridFS database'
|
364
|
+
end
|
329
365
|
end
|
330
366
|
end
|
331
367
|
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
describe Mongo::DBRef do
|
5
|
+
|
6
|
+
let(:object_id) do
|
7
|
+
BSON::ObjectId.new
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#as_json' do
|
11
|
+
|
12
|
+
context 'when the database is not provided' do
|
13
|
+
|
14
|
+
let(:dbref) do
|
15
|
+
described_class.new('users', object_id)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'returns the json document without database' do
|
19
|
+
expect(dbref.as_json).to eq({ '$ref' => 'users', '$id' => object_id })
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'when the database is provided' do
|
24
|
+
|
25
|
+
let(:dbref) do
|
26
|
+
described_class.new('users', object_id, 'database')
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'returns the json document with database' do
|
30
|
+
expect(dbref.as_json).to eq({
|
31
|
+
'$ref' => 'users',
|
32
|
+
'$id' => object_id,
|
33
|
+
'$db' => 'database'
|
34
|
+
})
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#initialize' do
|
40
|
+
|
41
|
+
let(:dbref) do
|
42
|
+
described_class.new('users', object_id)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'sets the collection' do
|
46
|
+
expect(dbref.collection).to eq('users')
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'sets the id' do
|
50
|
+
expect(dbref.id).to eq(object_id)
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'when a database is provided' do
|
54
|
+
|
55
|
+
let(:dbref) do
|
56
|
+
described_class.new('users', object_id, 'db')
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'sets the database' do
|
60
|
+
expect(dbref.database).to eq('db')
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe '#to_bson' do
|
66
|
+
|
67
|
+
let(:dbref) do
|
68
|
+
described_class.new('users', object_id, 'database')
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'converts the underlying document to bson' do
|
72
|
+
expect(dbref.to_bson).to eq(dbref.as_json.to_bson)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '#to_json' do
|
77
|
+
|
78
|
+
context 'when the database is not provided' do
|
79
|
+
|
80
|
+
let(:dbref) do
|
81
|
+
described_class.new('users', object_id)
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'returns the json document without database' do
|
85
|
+
expect(dbref.to_json).to eq("{\"$ref\":\"users\",\"$id\":#{object_id.to_json}}")
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'when the database is provided' do
|
90
|
+
|
91
|
+
let(:dbref) do
|
92
|
+
described_class.new('users', object_id, 'database')
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'returns the json document with database' do
|
96
|
+
expect(dbref.to_json).to eq("{\"$ref\":\"users\",\"$id\":#{object_id.to_json},\"$db\":\"database\"}")
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe '#from_bson' do
|
102
|
+
|
103
|
+
let(:bson) do
|
104
|
+
StringIO.new(dbref.to_bson)
|
105
|
+
end
|
106
|
+
|
107
|
+
let(:decoded) do
|
108
|
+
BSON::Document.from_bson(bson)
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'when a database exists' do
|
112
|
+
|
113
|
+
let(:dbref) do
|
114
|
+
described_class.new('users', object_id, 'database')
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'decodes the ref' do
|
118
|
+
expect(decoded.collection).to eq('users')
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'decodes the id' do
|
122
|
+
expect(decoded.id).to eq(object_id)
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'decodes the database' do
|
126
|
+
expect(decoded.database).to eq('database')
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
context 'when no database exists' do
|
131
|
+
|
132
|
+
let(:dbref) do
|
133
|
+
described_class.new('users', object_id)
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'decodes the ref' do
|
137
|
+
expect(decoded.collection).to eq('users')
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'decodes the id' do
|
141
|
+
expect(decoded.id).to eq(object_id)
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'sets the database to nil' do
|
145
|
+
expect(decoded.database).to be_nil
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
@@ -10,8 +10,8 @@ describe Mongo::Grid::File::Chunk do
|
|
10
10
|
BSON::ObjectId.new
|
11
11
|
end
|
12
12
|
|
13
|
-
let(:
|
14
|
-
Mongo::Grid::File::
|
13
|
+
let(:file_info) do
|
14
|
+
Mongo::Grid::File::Info.new(:files_id => file_id)
|
15
15
|
end
|
16
16
|
|
17
17
|
describe '#==' do
|
@@ -72,7 +72,7 @@ describe Mongo::Grid::File::Chunk do
|
|
72
72
|
end
|
73
73
|
|
74
74
|
let(:chunks) do
|
75
|
-
described_class.split(raw_data,
|
75
|
+
described_class.split(raw_data, file_info)
|
76
76
|
end
|
77
77
|
|
78
78
|
it 'returns the chunks assembled into the raw data' do
|
@@ -157,7 +157,7 @@ describe Mongo::Grid::File::Chunk do
|
|
157
157
|
end
|
158
158
|
|
159
159
|
let(:chunks) do
|
160
|
-
described_class.split(raw_data,
|
160
|
+
described_class.split(raw_data, file_info)
|
161
161
|
end
|
162
162
|
|
163
163
|
let(:chunk) do
|
@@ -204,7 +204,7 @@ describe Mongo::Grid::File::Chunk do
|
|
204
204
|
end
|
205
205
|
|
206
206
|
let(:chunks) do
|
207
|
-
described_class.split(raw_data,
|
207
|
+
described_class.split(raw_data, file_info)
|
208
208
|
end
|
209
209
|
|
210
210
|
it 'returns the correct number of chunks' do
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Mongo::Grid::File::
|
3
|
+
describe Mongo::Grid::File::Info do
|
4
4
|
|
5
5
|
describe '#==' do
|
6
6
|
|
@@ -8,23 +8,23 @@ describe Mongo::Grid::File::Metadata do
|
|
8
8
|
Time.now.utc
|
9
9
|
end
|
10
10
|
|
11
|
-
let(:
|
11
|
+
let(:info) do
|
12
12
|
described_class.new(:filename => 'test.txt', :length => 7, :uploadDate => upload_date)
|
13
13
|
end
|
14
14
|
|
15
|
-
context 'when the other is not
|
15
|
+
context 'when the other is not a file info object' do
|
16
16
|
|
17
17
|
it 'returns false' do
|
18
|
-
expect(
|
18
|
+
expect(info).to_not eq('test')
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
context 'when the other object is
|
22
|
+
context 'when the other object is file info object' do
|
23
23
|
|
24
24
|
context 'when the documents are equal' do
|
25
25
|
|
26
26
|
it 'returns true' do
|
27
|
-
expect(
|
27
|
+
expect(info).to eq(info)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -35,7 +35,7 @@ describe Mongo::Grid::File::Metadata do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'returns false' do
|
38
|
-
expect(
|
38
|
+
expect(info).to_not eq(other)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
@@ -45,48 +45,60 @@ describe Mongo::Grid::File::Metadata do
|
|
45
45
|
|
46
46
|
context 'when provided only a filename and length' do
|
47
47
|
|
48
|
-
let(:
|
48
|
+
let(:info) do
|
49
49
|
described_class.new(:filename => 'test.txt', :length => 7)
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'sets the default id' do
|
53
|
-
expect(
|
53
|
+
expect(info.id).to be_a(BSON::ObjectId)
|
54
54
|
end
|
55
55
|
|
56
56
|
it 'sets the upload date' do
|
57
|
-
expect(
|
57
|
+
expect(info.upload_date).to be_a(Time)
|
58
58
|
end
|
59
59
|
|
60
60
|
it 'sets the chunk size' do
|
61
|
-
expect(
|
61
|
+
expect(info.chunk_size).to eq(Mongo::Grid::File::Chunk::DEFAULT_SIZE)
|
62
62
|
end
|
63
63
|
|
64
64
|
it 'sets the content type' do
|
65
|
-
expect(
|
65
|
+
expect(info.content_type).to eq(Mongo::Grid::File::Info::DEFAULT_CONTENT_TYPE)
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
70
|
describe '#inspect' do
|
71
71
|
|
72
|
-
let(:
|
72
|
+
let(:info) do
|
73
73
|
described_class.new(:filename => 'test.txt', :length => 7)
|
74
74
|
end
|
75
75
|
|
76
76
|
it 'includes the chunk size' do
|
77
|
-
expect(
|
77
|
+
expect(info.inspect).to include(info.chunk_size.to_s)
|
78
78
|
end
|
79
79
|
|
80
80
|
it 'includes the filename' do
|
81
|
-
expect(
|
81
|
+
expect(info.inspect).to include(info.filename)
|
82
82
|
end
|
83
83
|
|
84
84
|
it 'includes the md5' do
|
85
|
-
expect(
|
85
|
+
expect(info.inspect).to include(info.md5.to_s)
|
86
86
|
end
|
87
87
|
|
88
88
|
it 'includes the id' do
|
89
|
-
expect(
|
89
|
+
expect(info.inspect).to include(info.id.to_s)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'when there are extra options' do
|
94
|
+
|
95
|
+
let(:info) do
|
96
|
+
described_class.new(:filename => 'test.txt', :extra_field => 'extra')
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'does not include them in the document written to the database' do
|
100
|
+
expect(info.document['extra_field']).to be_nil
|
101
|
+
expect(info.document[:extra_field]).to be_nil
|
90
102
|
end
|
91
103
|
end
|
92
104
|
end
|
@@ -51,7 +51,7 @@ describe Mongo::Grid::File do
|
|
51
51
|
(1..data_size).each{ |i| data << '1' }
|
52
52
|
end
|
53
53
|
|
54
|
-
context 'when provided data and
|
54
|
+
context 'when provided data and file information' do
|
55
55
|
|
56
56
|
let(:file) do
|
57
57
|
described_class.new(data, :filename => 'test.txt')
|
@@ -118,31 +118,31 @@ describe Mongo::Grid::File do
|
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
121
|
-
context 'when provided chunks and
|
121
|
+
context 'when provided chunks and file information' do
|
122
122
|
|
123
123
|
let(:file_id) do
|
124
124
|
BSON::ObjectId.new
|
125
125
|
end
|
126
126
|
|
127
|
-
let(:
|
127
|
+
let(:info) do
|
128
128
|
BSON::Document.new(
|
129
129
|
:_id => file_id,
|
130
130
|
:uploadDate => Time.now.utc,
|
131
131
|
:filename => 'test.txt',
|
132
132
|
:chunkSize => Mongo::Grid::File::Chunk::DEFAULT_SIZE,
|
133
133
|
:length => data.length,
|
134
|
-
:contentType => Mongo::Grid::File::
|
134
|
+
:contentType => Mongo::Grid::File::Info::DEFAULT_CONTENT_TYPE
|
135
135
|
)
|
136
136
|
end
|
137
137
|
|
138
138
|
let(:chunks) do
|
139
139
|
Mongo::Grid::File::Chunk.split(
|
140
|
-
data, Mongo::Grid::File::
|
140
|
+
data, Mongo::Grid::File::Info.new(info)
|
141
141
|
).map{ |chunk| chunk.document }
|
142
142
|
end
|
143
143
|
|
144
144
|
let(:file) do
|
145
|
-
described_class.new(chunks,
|
145
|
+
described_class.new(chunks, info)
|
146
146
|
end
|
147
147
|
|
148
148
|
it 'sets the chunks' do
|
@@ -153,8 +153,8 @@ describe Mongo::Grid::File do
|
|
153
153
|
expect(file.data).to eq(data)
|
154
154
|
end
|
155
155
|
|
156
|
-
it 'sets the
|
157
|
-
expect(file.
|
156
|
+
it 'sets the file information' do
|
157
|
+
expect(file.info.id).to eq(info[:_id])
|
158
158
|
end
|
159
159
|
end
|
160
160
|
end
|