mongo 2.4.0.rc0 → 2.4.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +1 -2
  4. data/lib/mongo/bulk_write/validatable.rb +3 -1
  5. data/lib/mongo/client.rb +30 -3
  6. data/lib/mongo/cluster/app_metadata.rb +7 -2
  7. data/lib/mongo/collection.rb +3 -1
  8. data/lib/mongo/collection/view.rb +3 -1
  9. data/lib/mongo/collection/view/aggregation.rb +3 -1
  10. data/lib/mongo/collection/view/builder/find_command.rb +20 -5
  11. data/lib/mongo/collection/view/map_reduce.rb +3 -1
  12. data/lib/mongo/collection/view/writable.rb +12 -2
  13. data/lib/mongo/cursor/builder/get_more_command.rb +3 -2
  14. data/lib/mongo/error/closed_stream.rb +1 -1
  15. data/lib/mongo/error/invalid_server_preference.rb +1 -1
  16. data/lib/mongo/index/view.rb +3 -1
  17. data/lib/mongo/operation/write/bulk/mergable.rb +1 -1
  18. data/lib/mongo/operation/write/create_index.rb +1 -1
  19. data/lib/mongo/operation/write/delete.rb +1 -1
  20. data/lib/mongo/operation/write/update.rb +1 -1
  21. data/lib/mongo/protocol/delete.rb +4 -1
  22. data/lib/mongo/protocol/get_more.rb +4 -1
  23. data/lib/mongo/protocol/insert.rb +7 -3
  24. data/lib/mongo/protocol/kill_cursors.rb +4 -1
  25. data/lib/mongo/protocol/message.rb +5 -1
  26. data/lib/mongo/protocol/query.rb +11 -4
  27. data/lib/mongo/protocol/update.rb +4 -1
  28. data/lib/mongo/server/connectable.rb +8 -2
  29. data/lib/mongo/server/connection_pool.rb +3 -1
  30. data/lib/mongo/server/monitor.rb +1 -0
  31. data/lib/mongo/socket.rb +16 -8
  32. data/lib/mongo/socket/ssl.rb +24 -9
  33. data/lib/mongo/uri.rb +6 -6
  34. data/lib/mongo/version.rb +1 -1
  35. data/mongo.gemspec +1 -1
  36. data/spec/mongo/bulk_write_spec.rb +117 -0
  37. data/spec/mongo/collection/view/aggregation_spec.rb +26 -0
  38. data/spec/mongo/collection/view/builder/find_command_spec.rb +244 -2
  39. data/spec/mongo/collection/view/map_reduce_spec.rb +13 -0
  40. data/spec/mongo/collection/view/readable_spec.rb +26 -0
  41. data/spec/mongo/collection/view/writable_spec.rb +104 -0
  42. data/spec/mongo/collection/view_spec.rb +13 -0
  43. data/spec/mongo/collection_spec.rb +226 -7
  44. data/spec/mongo/crud_spec.rb +5 -5
  45. data/spec/mongo/index/view_spec.rb +53 -0
  46. data/spec/mongo/server/connection_spec.rb +45 -26
  47. data/spec/mongo/socket/ssl_spec.rb +358 -22
  48. data/spec/spec_helper.rb +4 -0
  49. data/spec/support/authorization.rb +3 -3
  50. data/spec/support/certificates/client_cert.pem +21 -0
  51. data/spec/support/certificates/client_key.pem +28 -0
  52. data/spec/support/certificates/client_key_encrypted.pem +30 -0
  53. data/spec/support/crud.rb +67 -22
  54. data/spec/support/crud/read.rb +18 -36
  55. data/spec/support/crud/write.rb +0 -44
  56. data/spec/support/crud_tests/read/aggregate-collation.yml +17 -0
  57. data/spec/support/crud_tests/read/aggregate-out.yml +28 -0
  58. data/spec/support/crud_tests/read/aggregate.yml +1 -35
  59. data/spec/support/crud_tests/read/count-collation.yml +15 -0
  60. data/spec/support/crud_tests/read/count.yml +3 -15
  61. data/spec/support/crud_tests/read/distinct-collation.yml +17 -0
  62. data/spec/support/crud_tests/read/distinct.yml +1 -14
  63. data/spec/support/crud_tests/read/find-collation.yml +15 -0
  64. data/spec/support/crud_tests/read/find.yml +1 -12
  65. data/spec/support/crud_tests/write/deleteMany-collation.yml +22 -0
  66. data/spec/support/crud_tests/write/deleteMany.yml +1 -23
  67. data/spec/support/crud_tests/write/deleteOne-collation.yml +22 -0
  68. data/spec/support/crud_tests/write/deleteOne.yml +1 -21
  69. data/spec/support/crud_tests/write/findOneAndDelete-collation.yml +23 -0
  70. data/spec/support/crud_tests/write/findOneAndDelete.yml +2 -28
  71. data/spec/support/crud_tests/write/findOneAndReplace-collation.yml +24 -0
  72. data/spec/support/crud_tests/write/findOneAndReplace-upsert.yml +47 -0
  73. data/spec/support/crud_tests/write/findOneAndReplace.yml +13 -53
  74. data/spec/support/crud_tests/write/findOneAndUpdate-collation.yml +27 -0
  75. data/spec/support/crud_tests/write/findOneAndUpdate.yml +8 -51
  76. data/spec/support/crud_tests/write/insertMany.yml +1 -2
  77. data/spec/support/crud_tests/write/insertOne.yml +1 -2
  78. data/spec/support/crud_tests/write/replaceOne-collation.yml +23 -0
  79. data/spec/support/crud_tests/write/replaceOne-upsert.yml +48 -0
  80. data/spec/support/crud_tests/write/replaceOne.yml +11 -45
  81. data/spec/support/crud_tests/write/updateMany-collation.yml +27 -0
  82. data/spec/support/crud_tests/write/updateMany.yml +10 -42
  83. data/spec/support/crud_tests/write/updateOne-collation.yml +24 -0
  84. data/spec/support/crud_tests/write/updateOne.yml +7 -33
  85. data/spec/support/sdam/rs/new_primary_new_setversion.yml +1 -1
  86. data/spec/support/sdam/rs/null_election_id.yml +1 -0
  87. data/spec/support/sdam/rs/primary_disconnect_electionid.yml +2 -3
  88. data/spec/support/sdam/rs/primary_disconnect_setversion.yml +1 -2
  89. data/spec/support/sdam/single/direct_connection_rsarbiter.yml +1 -1
  90. data/spec/support/sdam/single/direct_connection_rsprimary.yml +1 -1
  91. data/spec/support/sdam/single/direct_connection_rssecondary.yml +1 -1
  92. metadata +40 -4
  93. metadata.gz.sig +0 -0
@@ -15,6 +15,10 @@ CLIENT_PEM = "#{SSL_CERTS_DIR}/client.pem"
15
15
  CLIENT_PASSWORD_PEM = "#{SSL_CERTS_DIR}/password_protected.pem"
16
16
  CA_PEM = "#{SSL_CERTS_DIR}/ca.pem"
17
17
  CRL_PEM = "#{SSL_CERTS_DIR}/crl.pem"
18
+ CLIENT_KEY_PEM = "#{SSL_CERTS_DIR}/client_key.pem"
19
+ CLIENT_CERT_PEM = "#{SSL_CERTS_DIR}/client_cert.pem"
20
+ CLIENT_KEY_ENCRYPTED_PEM = "#{SSL_CERTS_DIR}/client_key_encrypted.pem"
21
+ CLIENT_KEY_PASSPHRASE = "passphrase"
18
22
 
19
23
  require 'mongo'
20
24
 
@@ -51,8 +51,8 @@ SSL = ENV['SSL_ENABLED'] == 'true'
51
51
  SSL_OPTIONS = {
52
52
  ssl: SSL,
53
53
  ssl_verify: false,
54
- ssl_cert: CLIENT_PEM,
55
- ssl_key: CLIENT_PEM
54
+ ssl_cert: CLIENT_CERT_PEM,
55
+ ssl_key: CLIENT_KEY_PEM
56
56
  }
57
57
 
58
58
  # Base test options.
@@ -61,7 +61,7 @@ SSL_OPTIONS = {
61
61
  BASE_OPTIONS = {
62
62
  max_pool_size: 1,
63
63
  write: WRITE_CONCERN,
64
- heartbeat_frequency: 5,
64
+ heartbeat_frequency: 20,
65
65
  max_read_retries: 5
66
66
  }
67
67
 
@@ -0,0 +1,21 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDdjCCAt+gAwIBAgIBBzANBgkqhkiG9w0BAQUFADCBkjELMAkGA1UEBhMCVVMx
3
+ ETAPBgNVBAgMCE5ldyBZb3JrMRYwFAYDVQQHDA1OZXcgWW9yayBDaXR5MQ4wDAYD
4
+ VQQKDAUxMEdlbjEPMA0GA1UECwwGS2VybmVsMRowGAYDVQQDDBFNeSBDZXJ0IEF1
5
+ dGhvcml0eTEbMBkGCSqGSIb3DQEJARYMcm9vdEBsYXphcnVzMB4XDTEzMDgyMzE0
6
+ NTUzMloXDTQxMDEwNzE0NTUzMlowbjELMAkGA1UEBhMCVVMxETAPBgNVBAgMCE5l
7
+ dyBZb3JrMRYwFAYDVQQHDA1OZXcgWW9yayBDaXR5MQ4wDAYDVQQKDAUxMEdlbjET
8
+ MBEGA1UECwwKa2VybmVsdXNlcjEPMA0GA1UEAwwGY2xpZW50MIIBIjANBgkqhkiG
9
+ 9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuhZC1Is9XopnnqfAzUqcnP2VuYO/9M8DjC7b
10
+ qcE1WID24umHKITj0J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PyxuzENLo1tGYvjH0Rfvzjfkvali2Tfk3kjha0GhTw7CH7U3L
29
+ 5rb5GQj16tDX/Oqa2DluESH3tzDJ7Rgdwda0Dk3iceVEsSHArt6TOz/qa+Ycm/EC
30
+ -----END RSA PRIVATE KEY-----
@@ -23,11 +23,18 @@
23
23
  # @since 2.0.0
24
24
  RSpec::Matchers.define :match_collection_data do |test|
25
25
 
26
- match do |actual|
26
+ match do
27
27
  test.compare_collection_data
28
28
  end
29
29
  end
30
30
 
31
+ RSpec::Matchers.define :match_operation_result do |test|
32
+
33
+ match do |actual|
34
+ test.compare_operation_result(actual)
35
+ end
36
+ end
37
+
31
38
  require 'support/crud/read'
32
39
  require 'support/crud/write'
33
40
 
@@ -59,6 +66,31 @@ module Mongo
59
66
  @description = File.basename(file)
60
67
  @data = @spec['data']
61
68
  @crud_tests = @spec['tests']
69
+ @min_server_version = @spec['minServerVersion']
70
+ @max_server_version = @spec['maxServerVersion']
71
+ end
72
+
73
+
74
+ # Whether the test can be run on a given server version.
75
+ #
76
+ # @example Can the test run on this server version?
77
+ # spec.server_version_satisfied?(client)
78
+ #
79
+ # @param [ Mongo::Client ] client The client to check.
80
+ #
81
+ # @return [ true, false ] Whether the test can be run on the given
82
+ # server version.
83
+ #
84
+ # @since 2.4.0
85
+ def server_version_satisfied?(client)
86
+ case @min_server_version
87
+ when '2.6'
88
+ client.cluster.servers.first.features.write_command_enabled?
89
+ when '3.4'
90
+ client.cluster.servers.first.features.collation_enabled?
91
+ else
92
+ true
93
+ end
62
94
  end
63
95
 
64
96
  # Get a list of CRUDTests for each test definition.
@@ -146,6 +178,8 @@ module Mongo
146
178
  def compare_collection_data
147
179
  if actual_collection_data.nil?
148
180
  outcome_collection_data.nil?
181
+ elsif actual_collection_data.empty?
182
+ outcome_collection_data.empty?
149
183
  else
150
184
  actual_collection_data.all? do |doc|
151
185
  outcome_collection_data.include?(doc)
@@ -153,41 +187,52 @@ module Mongo
153
187
  end
154
188
  end
155
189
 
156
- # Whether this test requires server version >= 2.6 for its results to match
157
- # the expected results.
190
+ # Compare the actual operation result to the expected operation result.
158
191
  #
159
- # @example If this test requires >= 2.6.
160
- # test.requires_2_6?(collection)
192
+ # @example Compare the existing and expected operation results.
193
+ # test.compare_operation_result(actual_results)
161
194
  #
162
- # @param [ true, false ] If write commands are enabled on the server.
163
- # @param [ Collection ] The collection the test is run on.
195
+ # @params [ Object ] actual The actual test results.
164
196
  #
165
- # @return [ true, false ] Whether the test requires server >= 2.6.
197
+ # @return [ true, false ] The result of comparing the expected and actual operation result.
166
198
  #
167
- # @since 2.0.0
168
- def requires_2_6?(write_command_enabled, collection)
169
- !write_command_enabled && @operation.requires_2_6?(collection)
199
+ # @since 2.4.0
200
+ def compare_operation_result(actual)
201
+ if actual.is_a?(Array)
202
+ actual.empty? || @outcome['result'].each_with_index do |expected, i|
203
+ compare_result(expected, actual[i])
204
+ end
205
+ else
206
+ compare_result(@outcome['result'], actual)
207
+ end
170
208
  end
171
209
 
172
- # Whether this operation requires a certain server version to be run.
210
+ # The expected data in the collection as an outcome after running this test.
173
211
  #
174
- # @example Determine whether this operation requires a certain server feature.
175
- # operation.feature_enabled?(collection)
212
+ # @example Get the outcome collection data
213
+ # test.outcome_collection_data
176
214
  #
177
- # @param [ Collection ] collection The collection the operation
178
- # should be executed on.
179
- #
180
- # @return [ true, false ] Whether this operation requires a certain server version.
215
+ # @return [ Array<Hash> ] The list of documents expected to be in the collection
216
+ # after running this test.
181
217
  #
182
218
  # @since 2.4.0
183
- def feature_enabled?(collection)
184
- @operation.feature_enabled?(collection)
219
+ def outcome_collection_data
220
+ @outcome['collection']['data'] if @outcome['collection']
185
221
  end
186
222
 
187
223
  private
188
224
 
189
- def outcome_collection_data
190
- @outcome['collection']['data'] if @outcome['collection']
225
+ def compare_result(expected, actual)
226
+ case expected
227
+ when nil
228
+ actual.nil?
229
+ when Hash
230
+ actual.each do |k, v|
231
+ expected[k] == v
232
+ end
233
+ when Integer
234
+ expected == actual
235
+ end
191
236
  end
192
237
 
193
238
  def actual_collection_data
@@ -32,6 +32,16 @@ module Mongo
32
32
  :collation => 'collation'
33
33
  }
34
34
 
35
+ # Map of read preference mode names to their equivalent Ruby-formatted symbols.
36
+ #
37
+ # @since 2.4.0
38
+ READ_PREFERENCE_MAP = { 'primary' => :primary,
39
+ 'secondary' => :secondary,
40
+ 'primaryPreferred' => :primary_preferred,
41
+ 'secondaryPreferred' => :secondary_preferred,
42
+ 'nearest' => :nearest
43
+ }
44
+
35
45
  # The operation name.
36
46
  #
37
47
  # @return [ String ] name The operation name.
@@ -76,41 +86,6 @@ module Mongo
76
86
  pipeline.find {|op| op.keys.include?('$out') })
77
87
  end
78
88
 
79
- # Whether the operation requires server version >= 2.6 for its results to
80
- # match expected results.
81
- #
82
- # @example Whether the operation requires >= 2.6 for its results to match.
83
- # operation.requires_2_6?(collection)
84
- #
85
- # @param [ Collection ] collection The collection the operation is executed on.
86
- #
87
- # @return [ true, false ] If the operation requires 2.6 for its results to match.
88
- #
89
- # @since 2.0.0
90
- def requires_2_6?(collection)
91
- name == 'aggregate' && pipeline.find {|op| op.keys.include?('$out') }
92
- end
93
-
94
- # Whether this operation requires a certain server version to be run.
95
- #
96
- # @example Determine whether this operation requires a certain server feature.
97
- # operation.feature_enabled?(collection)
98
- #
99
- # @param [ Collection ] collection The collection the operation
100
- # should be executed on.
101
- #
102
- # @return [ true, false ] Whether this operation requires a certain server version.
103
- #
104
- # @since 2.4.0
105
- def feature_enabled?(collection)
106
- if collation
107
- return $mongo_client.cluster.servers.first.features.collation_enabled?
108
- elsif requires_2_6?(collection)
109
- return $mongo_client.cluster.servers.first.features.write_command_enabled?
110
- end
111
- true
112
- end
113
-
114
89
  private
115
90
 
116
91
  def count(collection)
@@ -130,7 +105,8 @@ module Mongo
130
105
  end
131
106
 
132
107
  def find(collection)
133
- collection.find(filter, options.merge(modifiers: BSON::Document.new(modifiers) || {})).to_a
108
+ opts = modifiers ? options.merge(modifiers: BSON::Document.new(modifiers)) : options
109
+ (read_preference ? collection.with(read: read_preference) : collection).find(filter, opts).to_a
134
110
  end
135
111
 
136
112
  def options
@@ -166,6 +142,12 @@ module Mongo
166
142
  def arguments
167
143
  @spec['arguments']
168
144
  end
145
+
146
+ def read_preference
147
+ if @spec['read_preference'] && @spec['read_preference']['mode']
148
+ { mode: READ_PREFERENCE_MAP[@spec['read_preference']['mode']] }
149
+ end
150
+ end
169
151
  end
170
152
  end
171
153
  end
@@ -51,14 +51,6 @@ module Mongo
51
51
  :collation => 'collation'
52
52
  }
53
53
 
54
- # Operations that need a check if results on < 2.6 will match.
55
- #
56
- # @since 2.0.0
57
- REQUIRES_2_6 = ['findOneAndReplace',
58
- 'updateMany',
59
- 'updateOne',
60
- 'replaceOne']
61
-
62
54
  # The operation name.
63
55
  #
64
56
  # @return [ String ] name The operation name.
@@ -98,42 +90,6 @@ module Mongo
98
90
  send(OPERATIONS[name], collection)
99
91
  end
100
92
 
101
- # Whether this operation requires >= 2.6 to be tested.
102
- #
103
- # @example Determine whether this operation requires >= 2.6.
104
- # operation.requires_2_6?(collection)
105
- #
106
- # @param [ Collection ] collection The collection the operation
107
- # should be executed on.
108
- #
109
- # @return [ true, false ] Whether this operation requires 2.6
110
- # to be tested.
111
- #
112
- # @since 2.0.0
113
- def requires_2_6?(collection)
114
- REQUIRES_2_6.include?(name) && upsert
115
- end
116
-
117
- # Whether this operation requires a certain server version to be run.
118
- #
119
- # @example Determine whether this operation requires a certain server feature.
120
- # operation.feature_enabled?(collection)
121
- #
122
- # @param [ Collection ] collection The collection the operation
123
- # should be executed on.
124
- #
125
- # @return [ true, false ] Whether this operation requires a certain server version.
126
- #
127
- # @since 2.4.0
128
- def feature_enabled?(collection)
129
- if collation
130
- return $mongo_client.cluster.servers.first.features.collation_enabled?
131
- elsif requires_2_6?(collection)
132
- return $mongo_client.cluster.servers.first.features.write_command_enabled?
133
- end
134
- true
135
- end
136
-
137
93
  private
138
94
 
139
95
  def bulk_write(collection)
@@ -0,0 +1,17 @@
1
+ data:
2
+ - {_id: 1, x: 'ping'}
3
+ minServerVersion: '3.4'
4
+
5
+ tests:
6
+ -
7
+ description: "Aggregate with collation"
8
+ operation:
9
+ name: aggregate
10
+ arguments:
11
+ pipeline:
12
+ - $match:
13
+ x: 'PING'
14
+ collation: { locale: 'en_US', strength: 2 } # https://docs.mongodb.com/master/reference/collation/#collation-document
15
+ outcome:
16
+ result:
17
+ - {_id: 1, x: 'ping'}
@@ -0,0 +1,28 @@
1
+ data:
2
+ - {_id: 1, x: 11}
3
+ - {_id: 2, x: 22}
4
+ - {_id: 3, x: 33}
5
+ minServerVersion: '2.6'
6
+
7
+ tests:
8
+ -
9
+ description: "Aggregate with $out"
10
+ operation:
11
+ name: aggregate
12
+ arguments:
13
+ pipeline:
14
+ - $sort: {x: 1}
15
+ - $match:
16
+ _id: {$gt: 1}
17
+ - $out: "other_test_collection"
18
+ batchSize: 2
19
+
20
+ outcome:
21
+ result:
22
+ - {_id: 2, x: 22}
23
+ - {_id: 3, x: 33}
24
+ collection:
25
+ name: "other_test_collection"
26
+ data:
27
+ - {_id: 2, x: 22}
28
+ - {_id: 3, x: 33}
@@ -2,7 +2,6 @@ data:
2
2
  - {_id: 1, x: 11}
3
3
  - {_id: 2, x: 22}
4
4
  - {_id: 3, x: 33}
5
- - {_id: 4, x: 'ping'}
6
5
 
7
6
  tests:
8
7
  -
@@ -13,43 +12,10 @@ tests:
13
12
  pipeline:
14
13
  - $sort: {x: 1}
15
14
  - $match:
16
- _id: {$gt: 1, $lt: 4}
15
+ _id: {$gt: 1}
17
16
  batchSize: 2
18
17
 
19
18
  outcome:
20
19
  result:
21
20
  - {_id: 2, x: 22}
22
21
  - {_id: 3, x: 33}
23
- -
24
- description: "Aggregate with $out"
25
- operation:
26
- name: aggregate
27
- arguments:
28
- pipeline:
29
- - $sort: {x: 1}
30
- - $match:
31
- _id: {$gt: 1, $lt: 4}
32
- - $out: "other_test_collection"
33
- batchSize: 2
34
-
35
- outcome:
36
- result:
37
- - {_id: 2, x: 22}
38
- - {_id: 3, x: 33}
39
- collection:
40
- name: "other_test_collection"
41
- data:
42
- - {_id: 2, x: 22}
43
- - {_id: 3, x: 33}
44
- -
45
- description: "Aggregate with collation"
46
- operation:
47
- name: aggregate
48
- arguments:
49
- pipeline:
50
- - $match:
51
- x: 'PING'
52
- collation: { locale: 'en_US', strength: 2 }
53
- outcome:
54
- result:
55
- - {_id: 4, x: 'ping'}