mongo 2.0.6 → 2.1.0.beta
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 +0 -0
- data.tar.gz.sig +0 -0
- data/lib/mongo.rb +2 -0
- data/lib/mongo/bulk_write.rb +1 -0
- data/lib/mongo/bulk_write/bulk_writable.rb +87 -31
- data/lib/mongo/bulk_write/deletable.rb +8 -7
- data/lib/mongo/bulk_write/insertable.rb +4 -3
- data/lib/mongo/bulk_write/ordered_bulk_write.rb +6 -6
- data/lib/mongo/bulk_write/replacable.rb +4 -3
- data/lib/mongo/bulk_write/result.rb +138 -0
- data/lib/mongo/bulk_write/unordered_bulk_write.rb +5 -8
- data/lib/mongo/bulk_write/updatable.rb +8 -7
- data/lib/mongo/client.rb +36 -4
- data/lib/mongo/cluster.rb +39 -4
- data/lib/mongo/cluster/topology/replica_set.rb +20 -4
- data/lib/mongo/cluster/topology/sharded.rb +1 -1
- data/lib/mongo/collection.rb +282 -29
- data/lib/mongo/collection/view/aggregation.rb +32 -4
- data/lib/mongo/collection/view/iterable.rb +2 -1
- data/lib/mongo/collection/view/map_reduce.rb +3 -1
- data/lib/mongo/collection/view/readable.rb +89 -14
- data/lib/mongo/collection/view/writable.rb +11 -5
- data/lib/mongo/cursor.rb +11 -3
- data/lib/mongo/dbref.rb +113 -0
- data/lib/mongo/error.rb +6 -2
- data/lib/mongo/error/parser.rb +1 -1
- data/lib/mongo/event/description_changed.rb +1 -1
- data/lib/mongo/grid/file.rb +1 -1
- data/lib/mongo/grid/fs.rb +2 -5
- data/lib/mongo/monitoring.rb +199 -0
- data/lib/mongo/monitoring/command_log_subscriber.rb +88 -0
- data/lib/mongo/monitoring/event.rb +17 -0
- data/lib/mongo/monitoring/event/command_failed.rb +96 -0
- data/lib/mongo/monitoring/event/command_started.rb +88 -0
- data/lib/mongo/monitoring/event/command_succeeded.rb +96 -0
- data/lib/mongo/monitoring/publishable.rb +96 -0
- data/lib/mongo/operation.rb +1 -0
- data/lib/mongo/operation/executable.rb +1 -1
- data/lib/mongo/operation/parallel_scan.rb +76 -0
- data/lib/mongo/operation/parallel_scan/result.rb +72 -0
- data/lib/mongo/operation/specifiable.rb +18 -0
- data/lib/mongo/operation/write/bulk/bulk_delete.rb +1 -1
- data/lib/mongo/operation/write/bulk/bulk_insert.rb +1 -1
- data/lib/mongo/operation/write/bulk/bulk_mergable.rb +2 -2
- data/lib/mongo/operation/write/bulk/bulk_update.rb +1 -1
- data/lib/mongo/operation/write/bulk/bulk_update/result.rb +13 -1
- data/lib/mongo/protocol/delete.rb +8 -13
- data/lib/mongo/protocol/get_more.rb +13 -13
- data/lib/mongo/protocol/insert.rb +8 -13
- data/lib/mongo/protocol/kill_cursors.rb +7 -11
- data/lib/mongo/protocol/query.rb +58 -20
- data/lib/mongo/protocol/reply.rb +12 -0
- data/lib/mongo/protocol/update.rb +13 -14
- data/lib/mongo/server.rb +23 -2
- data/lib/mongo/server/connectable.rb +0 -22
- data/lib/mongo/server/connection.rb +29 -0
- data/lib/mongo/server/description.rb +23 -1
- data/lib/mongo/server/monitor.rb +17 -1
- data/lib/mongo/server/monitor/connection.rb +24 -0
- data/lib/mongo/socket/ssl.rb +28 -16
- data/lib/mongo/socket/tcp.rb +1 -1
- data/lib/mongo/socket/unix.rb +1 -1
- data/lib/mongo/uri.rb +12 -5
- data/lib/mongo/version.rb +1 -1
- data/spec/mongo/auth/cr_spec.rb +9 -1
- data/spec/mongo/auth/ldap_spec.rb +9 -1
- data/spec/mongo/auth/scram_spec.rb +9 -1
- data/spec/mongo/auth/x509_spec.rb +9 -1
- data/spec/mongo/{bulk/bulk_write_spec.rb → bulk_write_spec.rb} +15 -15
- data/spec/mongo/client_spec.rb +42 -0
- data/spec/mongo/cluster/topology/replica_set_spec.rb +16 -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 +123 -1
- data/spec/mongo/collection/view/explainable_spec.rb +1 -1
- data/spec/mongo/collection/view/map_reduce_spec.rb +1 -1
- data/spec/mongo/collection/view/readable_spec.rb +251 -6
- data/spec/mongo/collection/view/writable_spec.rb +4 -4
- data/spec/mongo/collection/view_spec.rb +233 -71
- data/spec/mongo/collection_spec.rb +905 -9
- data/spec/mongo/crud_spec.rb +2 -2
- data/spec/mongo/cursor_spec.rb +3 -3
- data/spec/mongo/dbref_spec.rb +149 -0
- data/spec/mongo/monitoring_spec.rb +168 -0
- data/spec/mongo/operation/map_reduce_spec.rb +1 -1
- data/spec/mongo/operation/write/bulk/bulk_delete_spec.rb +1 -1
- data/spec/mongo/operation/write/bulk/bulk_insert_spec.rb +2 -2
- data/spec/mongo/operation/write/bulk/bulk_update_spec.rb +1 -1
- data/spec/mongo/operation/write/delete_spec.rb +1 -1
- data/spec/mongo/operation/write/insert_spec.rb +2 -2
- data/spec/mongo/operation/write/update_spec.rb +1 -1
- data/spec/mongo/protocol/query_spec.rb +0 -29
- data/spec/mongo/server/connection_pool_spec.rb +18 -6
- data/spec/mongo/server/connection_spec.rb +12 -4
- data/spec/mongo/server/description_spec.rb +7 -3
- data/spec/mongo/server/monitor_spec.rb +30 -0
- data/spec/mongo/server_discovery_and_monitoring_spec.rb +11 -4
- data/spec/mongo/server_selection_spec.rb +14 -6
- data/spec/mongo/server_spec.rb +27 -8
- data/spec/mongo/socket/ssl_spec.rb +94 -8
- data/spec/mongo/uri_spec.rb +25 -9
- data/spec/spec_helper.rb +29 -20
- data/spec/support/authorization.rb +19 -4
- data/spec/support/certificates/client.pem +4 -4
- data/spec/support/crud/read.rb +9 -10
- data/spec/support/crud/write.rb +24 -20
- data/spec/support/sdam/rs/equal_electionids.yml +45 -0
- data/spec/support/sdam/rs/new_primary_new_electionid.yml +98 -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/sharded/mongos_disconnect.yml +104 -0
- data/spec/support/server_discovery_and_monitoring.rb +19 -2
- data/spec/support/shared/bulk_write.rb +26 -22
- data/spec/support/shared/server_selector.rb +2 -1
- metadata +31 -7
- metadata.gz.sig +0 -0
- data/lib/mongo/error/invalid_uri_option.rb +0 -38
@@ -19,7 +19,6 @@ module Mongo
|
|
19
19
|
#
|
20
20
|
# @since 2.0.0
|
21
21
|
module Connectable
|
22
|
-
include Loggable
|
23
22
|
|
24
23
|
# The default time in seconds to timeout a connection attempt.
|
25
24
|
#
|
@@ -47,27 +46,6 @@ module Mongo
|
|
47
46
|
!!@socket && @socket.alive?
|
48
47
|
end
|
49
48
|
|
50
|
-
# Dispatch the provided messages to the connection. If the last message
|
51
|
-
# requires a response a reply will be returned.
|
52
|
-
#
|
53
|
-
# @example Dispatch the messages.
|
54
|
-
# connection.dispatch([ insert, command ])
|
55
|
-
#
|
56
|
-
# @note This method is named dispatch since 'send' is a core Ruby method on
|
57
|
-
# all objects.
|
58
|
-
#
|
59
|
-
# @param [ Array<Message> ] messages The messages to dispatch.
|
60
|
-
#
|
61
|
-
# @return [ Protocol::Reply ] The reply if needed.
|
62
|
-
#
|
63
|
-
# @since 2.0.0
|
64
|
-
def dispatch(messages)
|
65
|
-
log_debug(messages) do |msgs|
|
66
|
-
write(msgs)
|
67
|
-
msgs.last.replyable? ? read : nil
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
49
|
# Get the connection timeout.
|
72
50
|
#
|
73
51
|
# @example Get the connection timeout.
|
@@ -20,6 +20,7 @@ module Mongo
|
|
20
20
|
# @since 2.0.0
|
21
21
|
class Connection
|
22
22
|
include Connectable
|
23
|
+
include Monitoring::Publishable
|
23
24
|
extend Forwardable
|
24
25
|
|
25
26
|
# @return [ Mongo::Auth::CR, Mongo::Auth::X509, Mongo::Auth:LDAP, Mongo::Auth::SCRAM ]
|
@@ -88,17 +89,45 @@ module Mongo
|
|
88
89
|
true
|
89
90
|
end
|
90
91
|
|
92
|
+
# Dispatch the provided messages to the connection. If the last message
|
93
|
+
# requires a response a reply will be returned.
|
94
|
+
#
|
95
|
+
# @example Dispatch the messages.
|
96
|
+
# connection.dispatch([ insert, command ])
|
97
|
+
#
|
98
|
+
# @note This method is named dispatch since 'send' is a core Ruby method on
|
99
|
+
# all objects.
|
100
|
+
#
|
101
|
+
# @param [ Array<Message> ] messages The messages to dispatch.
|
102
|
+
# @param [ Integer ] operation_id The operation id to link messages.
|
103
|
+
#
|
104
|
+
# @return [ Protocol::Reply ] The reply if needed.
|
105
|
+
#
|
106
|
+
# @since 2.0.0
|
107
|
+
def dispatch(messages, operation_id = nil)
|
108
|
+
publish_command(messages, operation_id || Monitoring.next_operation_id) do |msgs|
|
109
|
+
write(msgs)
|
110
|
+
msgs.last.replyable? ? read : nil
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
91
114
|
# Initialize a new socket connection from the client to the server.
|
92
115
|
#
|
116
|
+
# @api private
|
117
|
+
#
|
93
118
|
# @example Create the connection.
|
94
119
|
# Connection.new(server)
|
95
120
|
#
|
121
|
+
# @note Connection must never be directly instantiated outside of a
|
122
|
+
# Server.
|
123
|
+
#
|
96
124
|
# @param [ Mongo::Server ] server The server the connection is for.
|
97
125
|
# @param [ Hash ] options The connection options.
|
98
126
|
#
|
99
127
|
# @since 2.0.0
|
100
128
|
def initialize(server, options = {})
|
101
129
|
@address = server.address
|
130
|
+
@monitoring = server.monitoring
|
102
131
|
@options = options.freeze
|
103
132
|
@server = server
|
104
133
|
@ssl_options = options.reject { |k, v| !k.to_s.start_with?('ssl') }
|
@@ -124,10 +124,20 @@ module Mongo
|
|
124
124
|
# @since 2.0.0
|
125
125
|
TAGS = 'tags'.freeze
|
126
126
|
|
127
|
+
# Constant for reading electionID info from config.
|
128
|
+
#
|
129
|
+
# @since 2.1.0
|
130
|
+
ELECTION_ID = 'electionId'.freeze
|
131
|
+
|
132
|
+
# Constant for reading localTime info from config.
|
133
|
+
#
|
134
|
+
# @since 2.1.0
|
135
|
+
LOCAL_TIME = 'localTime'.freeze
|
136
|
+
|
127
137
|
# Fields to exclude when comparing two descriptions.
|
128
138
|
#
|
129
139
|
# @since 2.0.6
|
130
|
-
EXCLUDE_FOR_COMPARISON = [
|
140
|
+
EXCLUDE_FOR_COMPARISON = [ LOCAL_TIME, ELECTION_ID ]
|
131
141
|
|
132
142
|
# @return [ Address ] address The server's address.
|
133
143
|
attr_reader :address
|
@@ -304,6 +314,18 @@ module Mongo
|
|
304
314
|
config[TAGS] || {}
|
305
315
|
end
|
306
316
|
|
317
|
+
# Get the electionId from the config.
|
318
|
+
#
|
319
|
+
# @example Get the electionId.
|
320
|
+
# description.election_id
|
321
|
+
#
|
322
|
+
# @return [ BSON::ObjectId ] The election id.
|
323
|
+
#
|
324
|
+
# @since 2.1.0
|
325
|
+
def election_id
|
326
|
+
config[ELECTION_ID]
|
327
|
+
end
|
328
|
+
|
307
329
|
# Is the server a mongos?
|
308
330
|
#
|
309
331
|
# @example Is the server a mongos?
|
data/lib/mongo/server/monitor.rb
CHANGED
@@ -91,9 +91,13 @@ module Mongo
|
|
91
91
|
|
92
92
|
# Create the new server monitor.
|
93
93
|
#
|
94
|
+
# @api private
|
95
|
+
#
|
94
96
|
# @example Create the server monitor.
|
95
97
|
# Mongo::Server::Monitor.new(address, listeners)
|
96
98
|
#
|
99
|
+
# @note Monitor must never be directly instantiated outside of a Server.
|
100
|
+
#
|
97
101
|
# @param [ Address ] address The address to monitor.
|
98
102
|
# @param [ Event::Listeners ] listeners The event listeners.
|
99
103
|
# @param [ Hash ] options The options.
|
@@ -112,7 +116,7 @@ module Mongo
|
|
112
116
|
# server.
|
113
117
|
#
|
114
118
|
# @example Run the monitor.
|
115
|
-
#
|
119
|
+
# monitor.run
|
116
120
|
#
|
117
121
|
# @return [ Thread ] The thread the monitor runs on.
|
118
122
|
#
|
@@ -139,6 +143,18 @@ module Mongo
|
|
139
143
|
@thread.kill && @thread.stop?
|
140
144
|
end
|
141
145
|
|
146
|
+
# Restarts the server monitor unless the current thread is alive.
|
147
|
+
#
|
148
|
+
# @example Restart the monitor.
|
149
|
+
# monitor.restart!
|
150
|
+
#
|
151
|
+
# @return [ Thread ] The thread the monitor runs on.
|
152
|
+
#
|
153
|
+
# @since 2.1.0
|
154
|
+
def restart!
|
155
|
+
@thread.alive? ? @thread : run!
|
156
|
+
end
|
157
|
+
|
142
158
|
private
|
143
159
|
|
144
160
|
def average_round_trip_time(start)
|
@@ -60,11 +60,35 @@ module Mongo
|
|
60
60
|
true
|
61
61
|
end
|
62
62
|
|
63
|
+
# Dispatch the provided messages to the connection. If the last message
|
64
|
+
# requires a response a reply will be returned.
|
65
|
+
#
|
66
|
+
# @example Dispatch the messages.
|
67
|
+
# connection.dispatch([ insert, command ])
|
68
|
+
#
|
69
|
+
# @note This method is named dispatch since 'send' is a core Ruby method on
|
70
|
+
# all objects.
|
71
|
+
#
|
72
|
+
# @param [ Array<Message> ] messages The messages to dispatch.
|
73
|
+
#
|
74
|
+
# @return [ Protocol::Reply ] The reply if needed.
|
75
|
+
#
|
76
|
+
# @since 2.0.0
|
77
|
+
def dispatch(messages)
|
78
|
+
write(messages)
|
79
|
+
messages.last.replyable? ? read : nil
|
80
|
+
end
|
81
|
+
|
63
82
|
# Initialize a new socket connection from the client to the server.
|
64
83
|
#
|
84
|
+
# @api private
|
85
|
+
#
|
65
86
|
# @example Create the connection.
|
66
87
|
# Connection.new(address)
|
67
88
|
#
|
89
|
+
# @note Connection must never be directly instantiated outside of a
|
90
|
+
# Monitor.
|
91
|
+
#
|
68
92
|
# @param [ Mongo::Address ] address The address the connection is for.
|
69
93
|
# @param [ Hash ] options The connection options.
|
70
94
|
#
|
data/lib/mongo/socket/ssl.rb
CHANGED
@@ -54,10 +54,10 @@ module Mongo
|
|
54
54
|
# @since 2.0.0
|
55
55
|
def connect!
|
56
56
|
Timeout.timeout(timeout, Error::SocketTimeoutError) do
|
57
|
-
@tcp_socket.connect(::Socket.pack_sockaddr_in(port, host))
|
57
|
+
handle_errors { @tcp_socket.connect(::Socket.pack_sockaddr_in(port, host)) }
|
58
58
|
@socket = OpenSSL::SSL::SSLSocket.new(@tcp_socket, context)
|
59
59
|
@socket.sync_close = true
|
60
|
-
@socket.connect
|
60
|
+
handle_errors { @socket.connect }
|
61
61
|
verify_certificate!(@socket)
|
62
62
|
self
|
63
63
|
end
|
@@ -100,22 +100,34 @@ module Mongo
|
|
100
100
|
|
101
101
|
def create_context(options)
|
102
102
|
context = OpenSSL::SSL::SSLContext.new
|
103
|
-
if options[:ssl_cert]
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
103
|
+
set_cert(context, options) if options[:ssl_cert]
|
104
|
+
set_key(context, options) if options[:ssl_key]
|
105
|
+
set_cert_verification(context, options) unless options[:ssl_verify] == false
|
106
|
+
context
|
107
|
+
end
|
108
|
+
|
109
|
+
def set_cert(context, options)
|
110
|
+
context.cert = OpenSSL::X509::Certificate.new(File.open(options[:ssl_cert]))
|
111
|
+
end
|
112
|
+
|
113
|
+
def set_key(context, options)
|
114
|
+
if options[:ssl_key_pass_phrase]
|
115
|
+
context.key = OpenSSL::PKey::RSA.new(File.open(options[:ssl_key]),
|
116
|
+
options[:ssl_key_pass_phrase])
|
117
|
+
else
|
118
|
+
context.key = OpenSSL::PKey::RSA.new(File.open(options[:ssl_key]))
|
113
119
|
end
|
114
|
-
|
115
|
-
|
116
|
-
|
120
|
+
end
|
121
|
+
|
122
|
+
def set_cert_verification(context, options)
|
123
|
+
context.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
124
|
+
cert_store = OpenSSL::X509::Store.new
|
125
|
+
if options[:ssl_ca_cert]
|
126
|
+
cert_store.add_file(options[:ssl_ca_cert])
|
127
|
+
else
|
128
|
+
cert_store.set_default_paths
|
117
129
|
end
|
118
|
-
context
|
130
|
+
context.cert_store = cert_store
|
119
131
|
end
|
120
132
|
|
121
133
|
def verify_certificate!(socket)
|
data/lib/mongo/socket/tcp.rb
CHANGED
@@ -43,7 +43,7 @@ module Mongo
|
|
43
43
|
def connect!
|
44
44
|
Timeout.timeout(timeout, Error::SocketTimeoutError) do
|
45
45
|
socket.setsockopt(IPPROTO_TCP, TCP_NODELAY, 1)
|
46
|
-
socket.connect(::Socket.pack_sockaddr_in(port, host))
|
46
|
+
handle_errors { socket.connect(::Socket.pack_sockaddr_in(port, host)) }
|
47
47
|
self
|
48
48
|
end
|
49
49
|
end
|
data/lib/mongo/socket/unix.rb
CHANGED
data/lib/mongo/uri.rb
CHANGED
@@ -27,6 +27,7 @@ module Mongo
|
|
27
27
|
#
|
28
28
|
# @since 2.0.0
|
29
29
|
class URI
|
30
|
+
include Loggable
|
30
31
|
|
31
32
|
# Scheme Regex: non-capturing, matches scheme.
|
32
33
|
#
|
@@ -69,7 +70,7 @@ module Mongo
|
|
69
70
|
# @since 2.0.0
|
70
71
|
DATABASE = %r{(?:/([^/\.\ "*<>:\|\?]*))?}.freeze
|
71
72
|
|
72
|
-
# Option Regex:
|
73
|
+
# Option Regex: only matches the ampersand separator and does
|
73
74
|
# not allow for semicolon to be used to separate options.
|
74
75
|
#
|
75
76
|
# @since 2.0.0
|
@@ -123,7 +124,8 @@ module Mongo
|
|
123
124
|
#
|
124
125
|
# @since 2.0.0
|
125
126
|
def initialize(string)
|
126
|
-
@
|
127
|
+
@string = string
|
128
|
+
@match = @string.match(URI)
|
127
129
|
raise Error::InvalidURI.new(string) unless @match
|
128
130
|
end
|
129
131
|
|
@@ -210,8 +212,13 @@ module Mongo
|
|
210
212
|
parsed_options.split('&').reduce({}) do |options, option|
|
211
213
|
key, value = option.split('=')
|
212
214
|
strategy = OPTION_MAP[key]
|
213
|
-
|
214
|
-
|
215
|
+
if strategy.nil?
|
216
|
+
log_warn([
|
217
|
+
"Unsupported URI option '#{key}' on URI '#{@string}'. It will be ignored."
|
218
|
+
])
|
219
|
+
else
|
220
|
+
add_option(strategy, value, options)
|
221
|
+
end
|
215
222
|
options
|
216
223
|
end
|
217
224
|
end
|
@@ -243,7 +250,7 @@ module Mongo
|
|
243
250
|
|
244
251
|
# Write Options
|
245
252
|
option 'w', :w, :group => :write
|
246
|
-
option '
|
253
|
+
option 'journal', :j, :group => :write
|
247
254
|
option 'fsync', :fsync, :group => :write
|
248
255
|
option 'wtimeoutMS', :timeout, :group => :write
|
249
256
|
|
data/lib/mongo/version.rb
CHANGED
data/spec/mongo/auth/cr_spec.rb
CHANGED
@@ -6,8 +6,16 @@ describe Mongo::Auth::CR do
|
|
6
6
|
Mongo::Address.new(DEFAULT_ADDRESS)
|
7
7
|
end
|
8
8
|
|
9
|
+
let(:monitoring) do
|
10
|
+
Mongo::Monitoring.new
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:listeners) do
|
14
|
+
Mongo::Event::Listeners.new
|
15
|
+
end
|
16
|
+
|
9
17
|
let(:server) do
|
10
|
-
Mongo::Server.new(address, double('cluster'),
|
18
|
+
Mongo::Server.new(address, double('cluster'), monitoring, listeners, TEST_OPTIONS)
|
11
19
|
end
|
12
20
|
|
13
21
|
let(:connection) do
|
@@ -6,8 +6,16 @@ describe Mongo::Auth::LDAP do
|
|
6
6
|
Mongo::Address.new(DEFAULT_ADDRESS)
|
7
7
|
end
|
8
8
|
|
9
|
+
let(:monitoring) do
|
10
|
+
Mongo::Monitoring.new
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:listeners) do
|
14
|
+
Mongo::Event::Listeners.new
|
15
|
+
end
|
16
|
+
|
9
17
|
let(:server) do
|
10
|
-
Mongo::Server.new(address, double('cluster'),
|
18
|
+
Mongo::Server.new(address, double('cluster'), monitoring, listeners, TEST_OPTIONS)
|
11
19
|
end
|
12
20
|
|
13
21
|
let(:connection) do
|
@@ -6,8 +6,16 @@ describe Mongo::Auth::SCRAM do
|
|
6
6
|
Mongo::Address.new(DEFAULT_ADDRESS)
|
7
7
|
end
|
8
8
|
|
9
|
+
let(:monitoring) do
|
10
|
+
Mongo::Monitoring.new
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:listeners) do
|
14
|
+
Mongo::Event::Listeners.new
|
15
|
+
end
|
16
|
+
|
9
17
|
let(:server) do
|
10
|
-
Mongo::Server.new(address, double('cluster'),
|
18
|
+
Mongo::Server.new(address, double('cluster'), monitoring, listeners, TEST_OPTIONS)
|
11
19
|
end
|
12
20
|
|
13
21
|
let(:connection) do
|
@@ -6,8 +6,16 @@ describe Mongo::Auth::X509 do
|
|
6
6
|
Mongo::Address.new(DEFAULT_ADDRESS)
|
7
7
|
end
|
8
8
|
|
9
|
+
let(:monitoring) do
|
10
|
+
Mongo::Monitoring.new
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:listeners) do
|
14
|
+
Mongo::Event::Listeners.new
|
15
|
+
end
|
16
|
+
|
9
17
|
let(:server) do
|
10
|
-
Mongo::Server.new(address, double('cluster'),
|
18
|
+
Mongo::Server.new(address, double('cluster'), monitoring, listeners, TEST_OPTIONS)
|
11
19
|
end
|
12
20
|
|
13
21
|
let(:connection) do
|
@@ -3,11 +3,11 @@ require 'spec_helper'
|
|
3
3
|
describe Mongo::BulkWrite do
|
4
4
|
|
5
5
|
before do
|
6
|
-
authorized_collection.
|
6
|
+
authorized_collection.delete_many
|
7
7
|
end
|
8
8
|
|
9
9
|
after do
|
10
|
-
authorized_collection.
|
10
|
+
authorized_collection.delete_many
|
11
11
|
end
|
12
12
|
|
13
13
|
let(:bulk) do
|
@@ -59,13 +59,13 @@ describe Mongo::BulkWrite do
|
|
59
59
|
let(:options) do
|
60
60
|
{ ordered: true }
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
it_behaves_like 'a bulk write object'
|
64
|
-
|
64
|
+
|
65
65
|
context 'when the batch requires splitting' do
|
66
|
-
|
66
|
+
|
67
67
|
context 'when the operations are the same type' do
|
68
|
-
|
68
|
+
|
69
69
|
let(:error) do
|
70
70
|
begin
|
71
71
|
bulk.execute
|
@@ -73,7 +73,7 @@ describe Mongo::BulkWrite do
|
|
73
73
|
ex
|
74
74
|
end
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
let(:operations) do
|
78
78
|
[].tap do |ops|
|
79
79
|
3000.times do |i|
|
@@ -83,13 +83,13 @@ describe Mongo::BulkWrite do
|
|
83
83
|
ops << { insert_one: { _id: 3001 } }
|
84
84
|
end
|
85
85
|
end
|
86
|
-
|
86
|
+
|
87
87
|
it 'raises a BulkWriteError' do
|
88
88
|
expect(error).to be_a(Mongo::Error::BulkWriteError)
|
89
89
|
end
|
90
90
|
|
91
91
|
it 'halts execution after first error and reports correct index' do
|
92
|
-
expect(error.result[
|
92
|
+
expect(error.result[Mongo::Error::WRITE_ERRORS].first['index']).to eq(3000)
|
93
93
|
expect(authorized_collection.find.count).to eq(3000)
|
94
94
|
end
|
95
95
|
end
|
@@ -120,7 +120,7 @@ describe Mongo::BulkWrite do
|
|
120
120
|
end
|
121
121
|
|
122
122
|
it 'halts execution after first error and reports correct index' do
|
123
|
-
expect(error.result[
|
123
|
+
expect(error.result[Mongo::Error::WRITE_ERRORS].first['index']).to eq(2001)
|
124
124
|
expect(authorized_collection.find.count).to eq(1999)
|
125
125
|
end
|
126
126
|
end
|
@@ -134,7 +134,7 @@ describe Mongo::BulkWrite do
|
|
134
134
|
ex
|
135
135
|
end
|
136
136
|
end
|
137
|
-
|
137
|
+
|
138
138
|
let(:operations) do
|
139
139
|
[].tap do |ops|
|
140
140
|
6.times do |i|
|
@@ -144,11 +144,11 @@ describe Mongo::BulkWrite do
|
|
144
144
|
ops << { insert_one: { _id: 100 } }
|
145
145
|
end
|
146
146
|
end
|
147
|
-
|
147
|
+
|
148
148
|
it 'raises a BulkWriteError error' do
|
149
149
|
expect(error).to be_a(Mongo::Error::BulkWriteError)
|
150
150
|
end
|
151
|
-
|
151
|
+
|
152
152
|
it 'splits messages into multiple messages' do
|
153
153
|
error
|
154
154
|
expect(authorized_collection.find.count).to eq(6)
|
@@ -192,7 +192,7 @@ describe Mongo::BulkWrite do
|
|
192
192
|
end
|
193
193
|
|
194
194
|
it 'does not halt execution after first error' do
|
195
|
-
expect(error.result[
|
195
|
+
expect(error.result[Mongo::Error::WRITE_ERRORS].first['index']).to eq(3000)
|
196
196
|
expect(authorized_collection.find.count).to eq(3001)
|
197
197
|
end
|
198
198
|
end
|
@@ -223,7 +223,7 @@ describe Mongo::BulkWrite do
|
|
223
223
|
end
|
224
224
|
|
225
225
|
it 'does not halt execution after first error' do
|
226
|
-
expect(error.result[
|
226
|
+
expect(error.result[Mongo::Error::WRITE_ERRORS].first['index']).to eq(2001)
|
227
227
|
expect(authorized_collection.find.count).to eq(2000)
|
228
228
|
end
|
229
229
|
end
|