bson 4.15.0-java → 5.0.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +94 -10
  3. data/Rakefile +68 -39
  4. data/lib/bson/active_support.rb +1 -0
  5. data/lib/bson/array.rb +57 -31
  6. data/lib/bson/big_decimal.rb +16 -6
  7. data/lib/bson/binary.rb +255 -128
  8. data/lib/bson/boolean.rb +1 -0
  9. data/lib/bson/code.rb +9 -11
  10. data/lib/bson/code_with_scope.rb +8 -10
  11. data/lib/bson/config.rb +1 -27
  12. data/lib/bson/date.rb +2 -1
  13. data/lib/bson/date_time.rb +2 -1
  14. data/lib/bson/db_pointer.rb +11 -12
  15. data/lib/bson/dbref.rb +11 -9
  16. data/lib/bson/decimal128/builder.rb +10 -9
  17. data/lib/bson/decimal128.rb +24 -110
  18. data/lib/bson/document.rb +1 -0
  19. data/lib/bson/environment.rb +1 -0
  20. data/lib/bson/error/bson_decode_error.rb +11 -0
  21. data/lib/bson/error/ext_json_parse_error.rb +11 -0
  22. data/lib/bson/error/illegal_key.rb +23 -0
  23. data/lib/bson/error/invalid_binary_type.rb +37 -0
  24. data/lib/bson/error/invalid_dbref_argument.rb +12 -0
  25. data/lib/bson/error/invalid_decimal128_argument.rb +25 -0
  26. data/lib/bson/error/invalid_decimal128_range.rb +27 -0
  27. data/lib/bson/error/invalid_decimal128_string.rb +26 -0
  28. data/lib/bson/error/invalid_key.rb +24 -0
  29. data/lib/bson/error/invalid_object_id.rb +11 -0
  30. data/lib/bson/error/invalid_regexp_pattern.rb +13 -0
  31. data/lib/bson/error/unrepresentable_precision.rb +19 -0
  32. data/lib/bson/error/unserializable_class.rb +13 -0
  33. data/lib/bson/error/unsupported_binary_subtype.rb +12 -0
  34. data/lib/bson/error/unsupported_type.rb +11 -0
  35. data/lib/bson/error.rb +16 -28
  36. data/lib/bson/ext_json.rb +1 -0
  37. data/lib/bson/false_class.rb +2 -1
  38. data/lib/bson/float.rb +2 -1
  39. data/lib/bson/hash.rb +127 -72
  40. data/lib/bson/int32.rb +16 -4
  41. data/lib/bson/int64.rb +16 -4
  42. data/lib/bson/integer.rb +3 -4
  43. data/lib/bson/json.rb +1 -0
  44. data/lib/bson/max_key.rb +7 -9
  45. data/lib/bson/min_key.rb +7 -9
  46. data/lib/bson/nil_class.rb +1 -0
  47. data/lib/bson/object.rb +5 -25
  48. data/lib/bson/object_id.rb +83 -119
  49. data/lib/bson/open_struct.rb +3 -2
  50. data/lib/bson/regexp.rb +35 -64
  51. data/lib/bson/registry.rb +2 -6
  52. data/lib/bson/specialized.rb +2 -1
  53. data/lib/bson/string.rb +4 -27
  54. data/lib/bson/symbol.rb +22 -19
  55. data/lib/bson/time.rb +2 -1
  56. data/lib/bson/time_with_zone.rb +13 -1
  57. data/lib/bson/timestamp.rb +2 -1
  58. data/lib/bson/true_class.rb +2 -1
  59. data/lib/bson/undefined.rb +14 -0
  60. data/lib/bson/version.rb +3 -1
  61. data/lib/bson-ruby.jar +0 -0
  62. data/lib/bson.rb +3 -2
  63. data/spec/bson/array_spec.rb +19 -60
  64. data/spec/bson/big_decimal_spec.rb +16 -4
  65. data/spec/bson/binary_spec.rb +83 -74
  66. data/spec/bson/binary_uuid_spec.rb +1 -0
  67. data/spec/bson/boolean_spec.rb +1 -0
  68. data/spec/bson/byte_buffer_read_spec.rb +1 -0
  69. data/spec/bson/byte_buffer_spec.rb +1 -0
  70. data/spec/bson/byte_buffer_write_spec.rb +1 -0
  71. data/spec/bson/code_spec.rb +5 -3
  72. data/spec/bson/code_with_scope_spec.rb +5 -3
  73. data/spec/bson/config_spec.rb +1 -35
  74. data/spec/bson/date_spec.rb +1 -0
  75. data/spec/bson/date_time_spec.rb +1 -0
  76. data/spec/bson/dbref_legacy_spec.rb +20 -3
  77. data/spec/bson/dbref_spec.rb +9 -9
  78. data/spec/bson/decimal128_spec.rb +40 -20
  79. data/spec/bson/document_as_spec.rb +1 -0
  80. data/spec/bson/document_spec.rb +1 -1
  81. data/spec/bson/ext_json_parse_spec.rb +1 -0
  82. data/spec/bson/false_class_spec.rb +8 -0
  83. data/spec/bson/float_spec.rb +8 -3
  84. data/spec/bson/hash_as_spec.rb +1 -0
  85. data/spec/bson/hash_spec.rb +87 -75
  86. data/spec/bson/int32_spec.rb +21 -6
  87. data/spec/bson/int64_spec.rb +21 -6
  88. data/spec/bson/integer_spec.rb +45 -13
  89. data/spec/bson/json_spec.rb +1 -0
  90. data/spec/bson/max_key_spec.rb +5 -3
  91. data/spec/bson/min_key_spec.rb +5 -3
  92. data/spec/bson/nil_class_spec.rb +1 -0
  93. data/spec/bson/object_id_spec.rb +57 -4
  94. data/spec/bson/object_spec.rb +2 -1
  95. data/spec/bson/open_struct_spec.rb +14 -71
  96. data/spec/bson/raw_spec.rb +9 -15
  97. data/spec/bson/regexp_spec.rb +4 -3
  98. data/spec/bson/registry_spec.rb +2 -1
  99. data/spec/bson/string_spec.rb +13 -38
  100. data/spec/bson/symbol_raw_spec.rb +25 -0
  101. data/spec/bson/symbol_spec.rb +15 -18
  102. data/spec/bson/time_spec.rb +1 -0
  103. data/spec/bson/time_with_zone_spec.rb +1 -0
  104. data/spec/bson/timestamp_spec.rb +1 -0
  105. data/spec/bson/true_class_spec.rb +8 -0
  106. data/spec/bson/undefined_spec.rb +27 -0
  107. data/spec/bson_spec.rb +1 -0
  108. data/spec/runners/common_driver.rb +6 -5
  109. data/spec/runners/corpus.rb +6 -0
  110. data/spec/runners/corpus_legacy.rb +1 -0
  111. data/spec/spec_helper.rb +1 -0
  112. data/spec/spec_tests/common_driver_spec.rb +9 -4
  113. data/spec/spec_tests/corpus_legacy_spec.rb +1 -0
  114. data/spec/spec_tests/corpus_spec.rb +13 -3
  115. data/spec/spec_tests/data/corpus/binary.json +5 -0
  116. data/spec/spec_tests/data/corpus/code.json +13 -13
  117. data/spec/spec_tests/data/corpus/decimal128-4.json +48 -0
  118. data/spec/spec_tests/data/corpus/decimal128-6.json +12 -0
  119. data/spec/spec_tests/data/corpus/decimal128-7.json +4 -0
  120. data/spec/spec_tests/data/corpus/document.json +20 -0
  121. data/spec/spec_tests/data/corpus/symbol.json +7 -7
  122. data/spec/spec_tests/data/corpus/top.json +18 -3
  123. data/spec/support/shared_examples.rb +28 -5
  124. data/spec/support/spec_config.rb +1 -0
  125. data/spec/support/utils.rb +49 -1
  126. metadata +112 -161
  127. checksums.yaml.gz.sig +0 -0
  128. data/spec/shared/LICENSE +0 -20
  129. data/spec/shared/bin/get-mongodb-download-url +0 -17
  130. data/spec/shared/bin/s3-copy +0 -45
  131. data/spec/shared/bin/s3-upload +0 -69
  132. data/spec/shared/lib/mrss/child_process_helper.rb +0 -80
  133. data/spec/shared/lib/mrss/cluster_config.rb +0 -231
  134. data/spec/shared/lib/mrss/constraints.rb +0 -386
  135. data/spec/shared/lib/mrss/docker_runner.rb +0 -271
  136. data/spec/shared/lib/mrss/event_subscriber.rb +0 -200
  137. data/spec/shared/lib/mrss/lite_constraints.rb +0 -191
  138. data/spec/shared/lib/mrss/server_version_registry.rb +0 -120
  139. data/spec/shared/lib/mrss/spec_organizer.rb +0 -179
  140. data/spec/shared/lib/mrss/utils.rb +0 -15
  141. data/spec/shared/share/Dockerfile.erb +0 -338
  142. data/spec/shared/share/haproxy-1.conf +0 -16
  143. data/spec/shared/share/haproxy-2.conf +0 -17
  144. data/spec/shared/shlib/distro.sh +0 -74
  145. data/spec/shared/shlib/server.sh +0 -367
  146. data/spec/shared/shlib/set_env.sh +0 -131
  147. data.tar.gz.sig +0 -1
  148. metadata.gz.sig +0 -2
@@ -1,231 +0,0 @@
1
- # frozen_string_literal: true
2
- # encoding: utf-8
3
-
4
- # ClusterConfig requires ClientRegistry class provided by the host project.
5
-
6
- require 'singleton'
7
-
8
- module Mrss
9
- class ClusterConfig
10
- include Singleton
11
- include RSpec::Core::Pending
12
-
13
- def single_server?
14
- determine_cluster_config
15
- @single_server
16
- end
17
-
18
- def sharded_ish?
19
- determine_cluster_config
20
- @topology == :sharded || @topology == :load_balanced
21
- end
22
-
23
- def replica_set_name
24
- determine_cluster_config
25
- @replica_set_name
26
- end
27
-
28
- def server_version
29
- determine_cluster_config
30
- @server_version
31
- end
32
-
33
- def enterprise?
34
- determine_cluster_config
35
- @enterprise
36
- end
37
-
38
- def short_server_version
39
- server_version.split('.')[0..1].join('.')
40
- end
41
-
42
- def fcv
43
- determine_cluster_config
44
- @fcv
45
- end
46
-
47
- # Per https://jira.mongodb.org/browse/SERVER-39052, working with FCV
48
- # in sharded topologies is annoying. Also, FCV doesn't exist in servers
49
- # less than 3.4. This method returns FCV on 3.4+ servers when in single
50
- # or RS topologies, and otherwise returns the major.minor server version.
51
- def fcv_ish
52
- if server_version.nil?
53
- raise "Deployment server version not known - check that connection to deployment succeeded"
54
- end
55
-
56
- if server_version >= '3.4' && !sharded_ish?
57
- fcv
58
- else
59
- if short_server_version == '4.1'
60
- '4.2'
61
- else
62
- short_server_version
63
- end
64
- end
65
- end
66
-
67
- # @return [ Mongo::Address ] The address of the primary in the deployment.
68
- def primary_address
69
- determine_cluster_config
70
- @primary_address
71
- end
72
-
73
- def primary_address_str
74
- determine_cluster_config
75
- @primary_address.seed
76
- end
77
-
78
- def primary_address_host
79
- both = primary_address_str
80
- both.split(':').first
81
- end
82
-
83
- def primary_address_port
84
- both = primary_address_str
85
- both.split(':')[1] || 27017
86
- end
87
-
88
- def primary_description
89
- determine_cluster_config
90
- @primary_description
91
- end
92
-
93
- def server_parameters
94
- determine_cluster_config
95
- @server_parameters
96
- end
97
-
98
- # Try running a command on the admin database to see if the mongod was
99
- # started with auth.
100
- def auth_enabled?
101
- if @auth_enabled.nil?
102
- @auth_enabled = begin
103
- basic_client.use(:admin).command(getCmdLineOpts: 1).first["argv"].include?("--auth")
104
- rescue => e
105
- e.message =~ /(not authorized)|(unauthorized)|(no users authenticated)|(requires authentication)/
106
- end
107
- end
108
- @auth_enabled
109
- end
110
-
111
- def topology
112
- determine_cluster_config
113
- @topology
114
- end
115
-
116
- def storage_engine
117
- @storage_engine ||= begin
118
- # 2.6 does not have wired tiger
119
- if short_server_version == '2.6'
120
- :mmapv1
121
- else
122
- client = ClientRegistry.instance.global_client('root_authorized')
123
- if sharded_ish?
124
- shards = client.use(:admin).command(listShards: 1).first
125
- if shards['shards'].empty?
126
- raise 'Shards are empty'
127
- end
128
- shard = shards['shards'].first
129
- address_str = shard['host'].sub(/^.*\//, '').sub(/,.*/, '')
130
- client = ClusterTools.instance.direct_client(address_str,
131
- SpecConfig.instance.test_options.merge(SpecConfig.instance.auth_options).merge(connect: :direct))
132
- end
133
- rv = client.use(:admin).command(serverStatus: 1).first
134
- rv = rv['storageEngine']['name']
135
- rv_map = {
136
- 'wiredTiger' => :wired_tiger,
137
- 'mmapv1' => :mmapv1,
138
- }
139
- rv_map[rv] || rv
140
- end
141
- end
142
- end
143
-
144
- # This method returns an alternate address for connecting to the configured
145
- # deployment. For example, if the replica set is configured with nodes at
146
- # of localhost:27017 and so on, this method will return 127.0.0.:27017.
147
- #
148
- # Note that the "alternate" refers to replica set configuration, not the
149
- # addresses specified in test suite configuration. If the deployment topology
150
- # is not a replica set, "alternate" refers to test suite configuration as
151
- # this is the only configuration available.
152
- def alternate_address
153
- @alternate_address ||= begin
154
- address = primary_address_host
155
- str = case address
156
- when '127.0.0.1'
157
- 'localhost'
158
- when /^(\d+\.){3}\d+$/
159
- skip 'This test requires a hostname or 127.0.0.1 as address'
160
- else
161
- # We don't know if mongod is listening on ipv4 or ipv6, in principle.
162
- # Our tests use ipv4, so hardcode that for now.
163
- # To support both we need to try both addresses which will make this
164
- # test more complicated.
165
- #
166
- # JRuby chokes on primary_address_port as the port (e.g. 27017).
167
- # Since the port does not actually matter, use a common port like 80.
168
- resolved_address = Addrinfo.getaddrinfo(address, 80, Socket::PF_INET).first.ip_address
169
- if resolved_address.include?(':')
170
- "[#{resolved_address}]"
171
- else
172
- resolved_address
173
- end
174
- end + ":#{primary_address_port}"
175
- Mongo::Address.new(str)
176
- end
177
- end
178
-
179
- private
180
-
181
- def determine_cluster_config
182
- return if @primary_address
183
-
184
- # Run all commands to figure out the cluster configuration from the same
185
- # client. This is somewhat wasteful when running a single test, but reduces
186
- # test runtime for the suite overall because all commands are sent on the
187
- # same connection rather than each command connecting to the cluster by
188
- # itself.
189
- client = ClientRegistry.instance.global_client('root_authorized')
190
-
191
- primary = client.cluster.next_primary
192
- @primary_address = primary.address
193
- @primary_description = primary.description
194
- @replica_set_name = client.cluster.topology.replica_set_name
195
-
196
- @topology ||= begin
197
- topology = client.cluster.topology.class.name.sub(/.*::/, '')
198
- topology = topology.gsub(/([A-Z])/) { |match| '_' + match.downcase }.sub(/^_/, '')
199
- if topology =~ /^replica_set/
200
- topology = 'replica_set'
201
- end
202
- topology.to_sym
203
- end
204
-
205
- @single_server = client.cluster.servers_list.length == 1
206
-
207
- build_info = client.database.command(buildInfo: 1).first
208
-
209
- @server_version = build_info['version']
210
- @enterprise = build_info['modules'] && build_info['modules'].include?('enterprise')
211
-
212
- @server_parameters = begin
213
- client.use(:admin).command(getParameter: '*').first
214
- rescue => e
215
- STDERR.puts("WARNING: Failed to obtain server parameters: #{e.class}: #{e.message}")
216
- {}
217
- end
218
-
219
- if !sharded_ish? && short_server_version >= '3.4'
220
- rv = @server_parameters['featureCompatibilityVersion']
221
- @fcv = rv['version'] || rv
222
- end
223
- end
224
-
225
- def basic_client
226
- # Do not cache the result here so that if the client gets closed,
227
- # client registry reconnects it in subsequent tests
228
- ClientRegistry.instance.global_client('basic')
229
- end
230
- end
231
- end
@@ -1,386 +0,0 @@
1
- # frozen_string_literal: true
2
- # encoding: utf-8
3
-
4
- module Mrss
5
- module Constraints
6
- def min_server_version(version)
7
- unless version =~ /\A\d+\.\d+\z/
8
- raise ArgumentError, "Version can only be major.minor: #{version}"
9
- end
10
-
11
- before(:all) do
12
- if version > ClusterConfig.instance.server_version
13
- skip "Server version #{version} or higher required, we have #{ClusterConfig.instance.server_version}"
14
- end
15
- end
16
- end
17
-
18
- def max_server_version(version)
19
- unless version =~ /\A\d+\.\d+\z/
20
- raise ArgumentError, "Version can only be major.minor: #{version}"
21
- end
22
-
23
- before(:all) do
24
- if version < ClusterConfig.instance.short_server_version
25
- skip "Server version #{version} or lower required, we have #{ClusterConfig.instance.server_version}"
26
- end
27
- end
28
- end
29
-
30
- def min_server_fcv(version)
31
- unless version =~ /\A\d+\.\d+\z/
32
- raise ArgumentError, "FCV can only be major.minor: #{version}"
33
- end
34
-
35
- before(:all) do
36
- unless ClusterConfig.instance.fcv_ish >= version
37
- skip "FCV #{version} or higher required, we have #{ClusterConfig.instance.fcv_ish} (server #{ClusterConfig.instance.server_version})"
38
- end
39
- end
40
- end
41
-
42
- def max_server_fcv(version)
43
- unless version =~ /\A\d+\.\d+\z/
44
- raise ArgumentError, "Version can only be major.minor: #{version}"
45
- end
46
-
47
- before(:all) do
48
- if version < ClusterConfig.instance.fcv_ish
49
- skip "FCV #{version} or lower required, we have #{ClusterConfig.instance.fcv_ish} (server #{ClusterConfig.instance.server_version})"
50
- end
51
- end
52
- end
53
-
54
- def require_topology(*topologies)
55
- invalid_topologies = topologies - [:single, :replica_set, :sharded, :load_balanced]
56
-
57
- unless invalid_topologies.empty?
58
- raise ArgumentError, "Invalid topologies requested: #{invalid_topologies.join(', ')}"
59
- end
60
-
61
- before(:all) do
62
- unless topologies.include?(topology = ClusterConfig.instance.topology)
63
- skip "Topology #{topologies.join(' or ')} required, we have #{topology}"
64
- end
65
- end
66
- end
67
-
68
- def max_example_run_time(timeout)
69
- around do |example|
70
- TimeoutInterrupt.timeout(timeout, TimeoutInterrupt::Error.new("Test execution terminated after #{timeout} seconds")) do
71
- example.run
72
- end
73
- end
74
- end
75
-
76
- def require_transaction_support
77
- before(:all) do
78
- case ClusterConfig.instance.topology
79
- when :single
80
- skip 'Transactions tests require a replica set (4.0+) or a sharded cluster (4.2+)'
81
- when :replica_set
82
- unless ClusterConfig.instance.server_version >= '4.0'
83
- skip 'Transactions tests in a replica set topology require server 4.0+'
84
- end
85
- when :sharded, :load_balanced
86
- unless ClusterConfig.instance.server_version >= '4.2'
87
- skip 'Transactions tests in a sharded cluster topology require server 4.2+'
88
- end
89
- else
90
- raise NotImplementedError
91
- end
92
- end
93
- end
94
-
95
- # Fail command fail point was added to mongod in 4.0 and to mongos in 4.2.
96
- def require_fail_command
97
- require_transaction_support
98
- end
99
-
100
- def require_tls
101
- before(:all) do
102
- unless SpecConfig.instance.ssl?
103
- skip "SSL not enabled"
104
- end
105
- end
106
- end
107
-
108
- def require_no_tls
109
- before(:all) do
110
- if SpecConfig.instance.ssl?
111
- skip "SSL enabled"
112
- end
113
- end
114
- end
115
-
116
- def require_retry_writes
117
- before(:all) do
118
- unless SpecConfig.instance.retry_writes?
119
- skip "Retry writes is disabled"
120
- end
121
- end
122
- end
123
-
124
- def require_no_retry_writes
125
- before(:all) do
126
- if SpecConfig.instance.retry_writes?
127
- skip "Retry writes is enabled"
128
- end
129
- end
130
- end
131
-
132
- def require_compression
133
- before(:all) do
134
- if SpecConfig.instance.compressors.nil?
135
- skip "Compression is not enabled"
136
- end
137
- end
138
- end
139
-
140
- def require_zlib_compression
141
- before(:all) do
142
- compressors = SpecConfig.instance.compressors
143
- unless compressors && compressors.include?('zlib')
144
- skip "Zlib compression is not enabled"
145
- end
146
- end
147
- end
148
-
149
- def require_snappy_compression
150
- before(:all) do
151
- compressors = SpecConfig.instance.compressors
152
- unless compressors && compressors.include?('snappy')
153
- skip "Snappy compression is not enabled"
154
- end
155
- end
156
- end
157
-
158
- def require_no_snappy_compression
159
- before(:all) do
160
- compressors = SpecConfig.instance.compressors
161
- if compressors && compressors.include?('snappy')
162
- skip "Snappy compression is enabled"
163
- end
164
- end
165
- end
166
-
167
- def require_zstd_compression
168
- before(:all) do
169
- compressors = SpecConfig.instance.compressors
170
- unless compressors && compressors.include?('zstd')
171
- skip "Zstd compression is not enabled"
172
- end
173
- end
174
- end
175
-
176
- def require_no_zstd_compression
177
- before(:all) do
178
- compressors = SpecConfig.instance.compressors
179
- if compressors && compressors.include?('zstd')
180
- skip "Zstd compression is enabled"
181
- end
182
- end
183
- end
184
-
185
- def require_no_compression
186
- before(:all) do
187
- if SpecConfig.instance.compressors
188
- skip "Compression is enabled"
189
- end
190
- end
191
- end
192
-
193
- def ruby_version_gte(version)
194
- before(:all) do
195
- if RUBY_VERSION < version
196
- skip "Ruby version #{version} or higher required"
197
- end
198
- end
199
- end
200
-
201
- def ruby_version_lt(version)
202
- before(:all) do
203
- if RUBY_VERSION >= version
204
- skip "Ruby version less than #{version} required"
205
- end
206
- end
207
- end
208
-
209
- def require_auth(*values)
210
- before(:all) do
211
- if values.any?
212
- unless values.include?(ENV['AUTH'])
213
- msg = values.map { |v| "AUTH=#{v}" }.join(' or ')
214
- skip "This test requires #{msg}"
215
- end
216
- else
217
- unless ENV['AUTH'] == 'auth' || SpecConfig.instance.user || ClusterConfig.instance.auth_enabled?
218
- skip "Auth required"
219
- end
220
- end
221
- end
222
- end
223
-
224
- def require_no_auth
225
- before(:all) do
226
- auth = ENV.fetch('AUTH', '')
227
- if (!auth.empty? && auth != 'noauth') || SpecConfig.instance.user || ClusterConfig.instance.auth_enabled?
228
- skip "Auth not allowed"
229
- end
230
- end
231
- end
232
-
233
- def require_x509_auth
234
- before(:all) do
235
- unless SpecConfig.instance.x509_auth?
236
- skip "X.509 auth required"
237
- end
238
- end
239
- end
240
-
241
- def require_no_external_user
242
- before(:all) do
243
- if SpecConfig.instance.external_user?
244
- skip "External user configurations are not compatible with this test"
245
- end
246
- end
247
- end
248
-
249
- # Can the driver specify a write concern that won't be overridden?
250
- # (mongos 4.0+ overrides the write concern)
251
- def require_set_write_concern
252
- before(:all) do
253
- if %i(sharded load_balanced).include?(ClusterConfig.instance.topology) &&
254
- ClusterConfig.instance.short_server_version >= '4.0'
255
- then
256
- skip "mongos 4.0+ overrides write concern"
257
- end
258
- end
259
- end
260
-
261
- def require_multi_mongos
262
- before(:all) do
263
- if ClusterConfig.instance.topology == :sharded && SpecConfig.instance.addresses.length == 1
264
- skip 'Test requires a minimum of two mongoses if run in sharded topology'
265
- end
266
-
267
- if ClusterConfig.instance.topology == :load_balanced && SpecConfig.instance.single_mongos?
268
- skip 'Test requires a minimum of two mongoses if run in load-balanced topology'
269
- end
270
- end
271
- end
272
-
273
- # In sharded topology operations are distributed to the mongoses.
274
- # When we set fail points, the fail point may be set on one mongos and
275
- # operation may be executed on another mongos, causing failures.
276
- # Tests that are not setting targeted fail points should utilize this
277
- # method to restrict themselves to single mongos.
278
- #
279
- # In load-balanced topology, the same problem can happen when there is
280
- # more than one mongos behind the load balancer.
281
- def require_no_multi_mongos
282
- before(:all) do
283
- if ClusterConfig.instance.topology == :sharded && SpecConfig.instance.addresses.length > 1
284
- skip 'Test requires a single mongos if run in sharded topology'
285
- end
286
- if ClusterConfig.instance.topology == :load_balanced && !SpecConfig.instance.single_mongos?
287
- skip 'Test requires a single mongos, as indicated by SINGLE_MONGOS=1 environment variable, if run in load-balanced topology'
288
- end
289
- end
290
- end
291
-
292
- alias :require_no_multi_shard :require_no_multi_mongos
293
-
294
- def require_wired_tiger
295
- before(:all) do
296
- # Storage detection fails for serverless instances. However, it is safe to
297
- # assume that a serverless instance uses WiredTiger Storage Engine.
298
- if !SpecConfig.instance.serverless? && ClusterConfig.instance.storage_engine != :wired_tiger
299
- skip 'Test requires WiredTiger storage engine'
300
- end
301
- end
302
- end
303
-
304
- def require_wired_tiger_on_36
305
- before(:all) do
306
- if ClusterConfig.instance.short_server_version >= '3.6'
307
- # Storage detection fails for serverless instances. However, it is safe to
308
- # assume that a serverless instance uses WiredTiger Storage Engine.
309
- if !SpecConfig.instance.serverless? && ClusterConfig.instance.storage_engine != :wired_tiger
310
- skip 'Test requires WiredTiger storage engine on 3.6+ servers'
311
- end
312
- end
313
- end
314
- end
315
-
316
- def require_mmapv1
317
- before(:all) do
318
- if SpecConfig.instance.serverless? || ClusterConfig.instance.storage_engine != :mmapv1
319
- skip 'Test requires MMAPv1 storage engine'
320
- end
321
- end
322
- end
323
-
324
- def require_enterprise
325
- before(:all) do
326
- unless ClusterConfig.instance.enterprise?
327
- skip 'Test requires enterprise build of MongoDB'
328
- end
329
- end
330
- end
331
-
332
- # Integration tests for SRV polling require internet connectivity to
333
- # look up SRV records and a sharded cluster configured on default port on
334
- # localhost (localhost:27017, localhost:27018).
335
- def require_default_port_deployment
336
- # Because the DNS records at test1.test.build.10gen.cc point to
337
- # localhost:27017 & localhost:27018, the test suite must have been
338
- # configured to use these addresses
339
- before(:all) do
340
- have_default_port = SpecConfig.instance.addresses.any? do |address|
341
- %w(127.0.0.1 127.0.0.1:27017 localhost localhost:27017).include?(address)
342
- end
343
- unless have_default_port
344
- skip 'This test requires the test suite to be configured for localhost:27017'
345
- end
346
- end
347
- end
348
-
349
- # Some tests perform assertions on what the driver is logging.
350
- # Some test configurations, for example OCSP with unknown response,
351
- # produce warnings due to optional checks failing.
352
- # This constraint skips tests that issue logging assertions on configurations
353
- # that may produce non-test-originated log entries.
354
- def require_warning_clean
355
- before(:all) do
356
- if ENV['OCSP_STATUS'] == 'unknown'
357
- skip 'Unknown OCSP status is not global warning-clean'
358
- end
359
- end
360
- end
361
-
362
- def require_required_api_version
363
- before(:all) do
364
- unless ENV['API_VERSION_REQUIRED'] == '1'
365
- skip 'Set API_VERSION_REQUIRED=1 to run this test'
366
- end
367
- end
368
- end
369
-
370
- def require_no_required_api_version
371
- before(:all) do
372
- if ENV['API_VERSION_REQUIRED'] == '1'
373
- skip 'Cannot have API_VERSION_REQUIRED=1 to run this test'
374
- end
375
- end
376
- end
377
-
378
- def require_unix_socket
379
- before(:all) do
380
- if ENV['TOPOLOGY'] == 'load-balanced'
381
- skip 'Load balancer does not listen on Unix sockets'
382
- end
383
- end
384
- end
385
- end
386
- end