mongo 2.13.3 → 2.14.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (197) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/lib/mongo/address/ipv4.rb +1 -1
  4. data/lib/mongo/address/ipv6.rb +1 -1
  5. data/lib/mongo/address.rb +1 -1
  6. data/lib/mongo/bulk_write.rb +17 -0
  7. data/lib/mongo/caching_cursor.rb +74 -0
  8. data/lib/mongo/client.rb +47 -8
  9. data/lib/mongo/cluster/topology/single.rb +1 -1
  10. data/lib/mongo/cluster.rb +3 -3
  11. data/lib/mongo/collection/view/aggregation.rb +25 -4
  12. data/lib/mongo/collection/view/builder/find_command.rb +38 -18
  13. data/lib/mongo/collection/view/explainable.rb +27 -8
  14. data/lib/mongo/collection/view/iterable.rb +72 -12
  15. data/lib/mongo/collection/view/readable.rb +12 -2
  16. data/lib/mongo/collection/view/writable.rb +15 -1
  17. data/lib/mongo/collection/view.rb +24 -20
  18. data/lib/mongo/collection.rb +26 -2
  19. data/lib/mongo/crypt/encryption_io.rb +6 -6
  20. data/lib/mongo/cursor.rb +1 -0
  21. data/lib/mongo/database/view.rb +1 -1
  22. data/lib/mongo/database.rb +8 -14
  23. data/lib/mongo/error/invalid_read_concern.rb +28 -0
  24. data/lib/mongo/error/server_certificate_revoked.rb +22 -0
  25. data/lib/mongo/error/unsupported_option.rb +14 -12
  26. data/lib/mongo/error.rb +2 -0
  27. data/lib/mongo/grid/fs_bucket.rb +37 -37
  28. data/lib/mongo/lint.rb +2 -1
  29. data/lib/mongo/logger.rb +3 -3
  30. data/lib/mongo/operation/aggregate/result.rb +9 -8
  31. data/lib/mongo/operation/collections_info/command.rb +0 -5
  32. data/lib/mongo/operation/collections_info/result.rb +3 -16
  33. data/lib/mongo/operation/delete/bulk_result.rb +2 -0
  34. data/lib/mongo/operation/delete/result.rb +3 -0
  35. data/lib/mongo/operation/explain/command.rb +4 -0
  36. data/lib/mongo/operation/explain/legacy.rb +4 -0
  37. data/lib/mongo/operation/explain/op_msg.rb +6 -0
  38. data/lib/mongo/operation/explain/result.rb +3 -0
  39. data/lib/mongo/operation/find/legacy/result.rb +2 -0
  40. data/lib/mongo/operation/find/result.rb +3 -0
  41. data/lib/mongo/operation/get_more/result.rb +3 -0
  42. data/lib/mongo/operation/indexes/result.rb +5 -0
  43. data/lib/mongo/operation/insert/bulk_result.rb +5 -0
  44. data/lib/mongo/operation/insert/result.rb +5 -0
  45. data/lib/mongo/operation/list_collections/result.rb +5 -0
  46. data/lib/mongo/operation/map_reduce/result.rb +10 -0
  47. data/lib/mongo/operation/parallel_scan/command.rb +2 -1
  48. data/lib/mongo/operation/parallel_scan/result.rb +4 -0
  49. data/lib/mongo/operation/result.rb +35 -6
  50. data/lib/mongo/operation/shared/bypass_document_validation.rb +1 -0
  51. data/lib/mongo/operation/shared/causal_consistency_supported.rb +1 -0
  52. data/lib/mongo/operation/shared/collections_info_or_list_collections.rb +2 -0
  53. data/lib/mongo/operation/shared/executable.rb +1 -0
  54. data/lib/mongo/operation/shared/idable.rb +2 -1
  55. data/lib/mongo/operation/shared/limited.rb +1 -0
  56. data/lib/mongo/operation/shared/object_id_generator.rb +1 -0
  57. data/lib/mongo/operation/shared/read_preference_supported.rb +36 -38
  58. data/lib/mongo/operation/shared/result/aggregatable.rb +1 -0
  59. data/lib/mongo/operation/shared/sessions_supported.rb +3 -3
  60. data/lib/mongo/operation/shared/specifiable.rb +1 -0
  61. data/lib/mongo/operation/shared/write.rb +1 -0
  62. data/lib/mongo/operation/shared/write_concern_supported.rb +1 -0
  63. data/lib/mongo/operation/update/legacy/result.rb +7 -0
  64. data/lib/mongo/operation/update/result.rb +8 -0
  65. data/lib/mongo/operation/users_info/result.rb +3 -0
  66. data/lib/mongo/operation.rb +2 -0
  67. data/lib/mongo/protocol/msg.rb +2 -2
  68. data/lib/mongo/protocol/query.rb +11 -11
  69. data/lib/mongo/query_cache.rb +242 -0
  70. data/lib/mongo/retryable.rb +8 -1
  71. data/lib/mongo/server/connection_common.rb +2 -2
  72. data/lib/mongo/server/connection_pool.rb +3 -0
  73. data/lib/mongo/server/monitor/connection.rb +3 -3
  74. data/lib/mongo/server/monitor.rb +1 -1
  75. data/lib/mongo/server/pending_connection.rb +2 -2
  76. data/lib/mongo/server/push_monitor.rb +1 -1
  77. data/lib/mongo/server.rb +5 -1
  78. data/lib/mongo/server_selector/base.rb +5 -1
  79. data/lib/mongo/server_selector/secondary_preferred.rb +7 -2
  80. data/lib/mongo/session.rb +3 -0
  81. data/lib/mongo/socket/ocsp_cache.rb +97 -0
  82. data/lib/mongo/socket/ocsp_verifier.rb +368 -0
  83. data/lib/mongo/socket/ssl.rb +45 -24
  84. data/lib/mongo/socket.rb +6 -4
  85. data/lib/mongo/srv/monitor.rb +7 -13
  86. data/lib/mongo/srv/resolver.rb +14 -10
  87. data/lib/mongo/timeout.rb +2 -0
  88. data/lib/mongo/uri/options_mapper.rb +582 -0
  89. data/lib/mongo/uri/srv_protocol.rb +3 -2
  90. data/lib/mongo/uri.rb +21 -390
  91. data/lib/mongo/utils.rb +12 -1
  92. data/lib/mongo/version.rb +1 -1
  93. data/lib/mongo.rb +9 -0
  94. data/spec/NOTES.aws-auth.md +12 -7
  95. data/spec/README.md +56 -1
  96. data/spec/integration/bson_symbol_spec.rb +2 -4
  97. data/spec/integration/bulk_write_spec.rb +48 -0
  98. data/spec/integration/client_authentication_options_spec.rb +55 -28
  99. data/spec/integration/connection_pool_populator_spec.rb +3 -1
  100. data/spec/integration/cursor_reaping_spec.rb +53 -17
  101. data/spec/integration/ocsp_connectivity_spec.rb +26 -0
  102. data/spec/integration/ocsp_verifier_cache_spec.rb +188 -0
  103. data/spec/integration/ocsp_verifier_spec.rb +334 -0
  104. data/spec/integration/query_cache_spec.rb +1045 -0
  105. data/spec/integration/query_cache_transactions_spec.rb +179 -0
  106. data/spec/integration/retryable_writes/retryable_writes_40_and_newer_spec.rb +1 -0
  107. data/spec/integration/retryable_writes/shared/performs_legacy_retries.rb +2 -0
  108. data/spec/integration/sdam_error_handling_spec.rb +69 -18
  109. data/spec/integration/sdam_events_spec.rb +7 -8
  110. data/spec/integration/server_selection_spec.rb +36 -0
  111. data/spec/integration/srv_monitoring_spec.rb +38 -3
  112. data/spec/integration/srv_spec.rb +56 -0
  113. data/spec/lite_spec_helper.rb +4 -2
  114. data/spec/mongo/address_spec.rb +1 -1
  115. data/spec/mongo/caching_cursor_spec.rb +70 -0
  116. data/spec/mongo/client_construction_spec.rb +54 -1
  117. data/spec/mongo/client_encryption_spec.rb +10 -16
  118. data/spec/mongo/client_spec.rb +40 -0
  119. data/spec/mongo/cluster/topology/single_spec.rb +14 -5
  120. data/spec/mongo/cluster_spec.rb +3 -0
  121. data/spec/mongo/collection/view/explainable_spec.rb +87 -4
  122. data/spec/mongo/collection/view/map_reduce_spec.rb +2 -0
  123. data/spec/mongo/collection_spec.rb +60 -0
  124. data/spec/mongo/crypt/auto_decryption_context_spec.rb +1 -1
  125. data/spec/mongo/crypt/auto_encryption_context_spec.rb +1 -1
  126. data/spec/mongo/crypt/data_key_context_spec.rb +1 -1
  127. data/spec/mongo/crypt/explicit_decryption_context_spec.rb +1 -1
  128. data/spec/mongo/crypt/explicit_encryption_context_spec.rb +1 -1
  129. data/spec/mongo/database_spec.rb +44 -64
  130. data/spec/mongo/error/no_server_available_spec.rb +1 -1
  131. data/spec/mongo/index/view_spec.rb +2 -4
  132. data/spec/mongo/logger_spec.rb +13 -11
  133. data/spec/mongo/operation/read_preference_legacy_spec.rb +19 -9
  134. data/spec/mongo/operation/read_preference_op_msg_spec.rb +3 -3
  135. data/spec/mongo/query_cache_spec.rb +279 -0
  136. data/spec/mongo/server/app_metadata_shared.rb +7 -33
  137. data/spec/mongo/server/connection_pool_spec.rb +7 -3
  138. data/spec/mongo/server/connection_spec.rb +14 -7
  139. data/spec/mongo/server_selector/secondary_preferred_spec.rb +6 -6
  140. data/spec/mongo/socket/ssl_spec.rb +1 -1
  141. data/spec/mongo/socket_spec.rb +1 -1
  142. data/spec/mongo/uri/srv_protocol_spec.rb +64 -33
  143. data/spec/mongo/uri_option_parsing_spec.rb +11 -11
  144. data/spec/mongo/uri_spec.rb +68 -41
  145. data/spec/mongo/utils_spec.rb +39 -0
  146. data/spec/runners/auth.rb +3 -0
  147. data/spec/runners/connection_string.rb +35 -124
  148. data/spec/runners/transactions/operation.rb +2 -13
  149. data/spec/spec_tests/cmap_spec.rb +7 -3
  150. data/spec/spec_tests/data/change_streams/change-streams-errors.yml +0 -1
  151. data/spec/spec_tests/data/change_streams/change-streams.yml +0 -1
  152. data/spec/spec_tests/data/cmap/pool-checkout-connection.yml +6 -2
  153. data/spec/spec_tests/data/cmap/pool-create-min-size.yml +3 -0
  154. data/spec/spec_tests/data/connection_string/valid-warnings.yml +24 -0
  155. data/spec/spec_tests/data/sdam_monitoring/discovered_standalone.yml +1 -3
  156. data/spec/spec_tests/data/sdam_monitoring/standalone.yml +2 -2
  157. data/spec/spec_tests/data/sdam_monitoring/standalone_repeated.yml +2 -2
  158. data/spec/spec_tests/data/sdam_monitoring/standalone_suppress_equal_description_changes.yml +2 -2
  159. data/spec/spec_tests/data/sdam_monitoring/standalone_to_rs_with_me_mismatch.yml +2 -2
  160. data/spec/spec_tests/data/uri_options/auth-options.yml +25 -0
  161. data/spec/spec_tests/data/uri_options/compression-options.yml +6 -3
  162. data/spec/spec_tests/data/uri_options/read-preference-options.yml +24 -0
  163. data/spec/spec_tests/data/uri_options/ruby-connection-options.yml +1 -0
  164. data/spec/spec_tests/data/uri_options/tls-options.yml +160 -4
  165. data/spec/spec_tests/dns_seedlist_discovery_spec.rb +9 -1
  166. data/spec/spec_tests/uri_options_spec.rb +31 -33
  167. data/spec/support/certificates/atlas-ocsp-ca.crt +28 -0
  168. data/spec/support/certificates/atlas-ocsp.crt +41 -0
  169. data/spec/support/client_registry.rb +4 -8
  170. data/spec/support/client_registry_macros.rb +4 -4
  171. data/spec/support/common_shortcuts.rb +45 -0
  172. data/spec/support/constraints.rb +23 -0
  173. data/spec/support/lite_constraints.rb +24 -0
  174. data/spec/support/matchers.rb +16 -0
  175. data/spec/support/ocsp +1 -0
  176. data/spec/support/session_registry.rb +52 -0
  177. data/spec/support/spec_config.rb +22 -12
  178. data/spec/support/spec_setup.rb +38 -48
  179. data/spec/support/utils.rb +19 -1
  180. data.tar.gz.sig +1 -3
  181. metadata +938 -933
  182. metadata.gz.sig +0 -0
  183. data/spec/integration/secondary_reads_spec.rb +0 -102
  184. data/spec/shared/LICENSE +0 -20
  185. data/spec/shared/bin/get-mongodb-download-url +0 -17
  186. data/spec/shared/lib/mrss/child_process_helper.rb +0 -80
  187. data/spec/shared/lib/mrss/cluster_config.rb +0 -221
  188. data/spec/shared/lib/mrss/constraints.rb +0 -346
  189. data/spec/shared/lib/mrss/docker_runner.rb +0 -265
  190. data/spec/shared/lib/mrss/lite_constraints.rb +0 -191
  191. data/spec/shared/lib/mrss/server_version_registry.rb +0 -115
  192. data/spec/shared/lib/mrss/spec_organizer.rb +0 -152
  193. data/spec/shared/lib/mrss/utils.rb +0 -15
  194. data/spec/shared/share/Dockerfile.erb +0 -231
  195. data/spec/shared/shlib/distro.sh +0 -73
  196. data/spec/shared/shlib/server.sh +0 -290
  197. data/spec/shared/shlib/set_env.sh +0 -128
metadata.gz.sig CHANGED
Binary file
@@ -1,102 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Secondary reads' do
4
- before do
5
- root_authorized_client.use('sr')['secondary_reads'].drop
6
- root_authorized_client.use('sr')['secondary_reads'].insert_one(test: 1)
7
- end
8
-
9
- shared_examples 'performs reads as per read preference' do
10
-
11
- %i(primary primary_preferred).each do |mode|
12
-
13
- context mode.inspect do
14
-
15
- let(:client) do
16
- root_authorized_client.with(read: {mode: mode}).use('sr')
17
- end
18
-
19
- it 'reads from primary' do
20
- start_stats = get_read_counters
21
-
22
- 30.times do
23
- client['secondary_reads'].find.to_a
24
- end
25
-
26
- end_stats = get_read_counters
27
-
28
- end_stats[:secondary].should be_within(10).of(start_stats[:secondary])
29
- end_stats[:primary].should >= start_stats[:primary] + 30
30
- end
31
- end
32
- end
33
-
34
- %i(secondary secondary_preferred).each do |mode|
35
-
36
- context mode.inspect do
37
- let(:client) do
38
- root_authorized_client.with(read: {mode: mode}).use('sr')
39
- end
40
-
41
- it 'reads from secondaries' do
42
- start_stats = get_read_counters
43
-
44
- 30.times do
45
- client['secondary_reads'].find.to_a
46
- end
47
-
48
- end_stats = get_read_counters
49
-
50
- end_stats[:primary].should be_within(10).of(start_stats[:primary])
51
- end_stats[:secondary].should >= start_stats[:secondary] + 30
52
- end
53
- end
54
- end
55
- end
56
-
57
- context 'replica set' do
58
- require_topology :replica_set
59
-
60
- include_examples 'performs reads as per read preference'
61
- end
62
-
63
- context 'sharded cluster' do
64
- require_topology :sharded
65
-
66
- include_examples 'performs reads as per read preference'
67
- end
68
-
69
- def get_read_counters
70
- client = ClientRegistry.instance.global_client('root_authorized')
71
- addresses = []
72
- if client.cluster.sharded?
73
- doc = client.use('admin').command(listShards: 1).documents.first
74
- doc['shards'].each do |shard|
75
- addresses += shard['host'].split('/').last.split(',')
76
- end
77
- else
78
- client.cluster.servers.each do |server|
79
- next unless server.primary? || server.secondary?
80
- addresses << server.address.seed
81
- end
82
- end
83
- stats = Hash.new(0)
84
- addresses.each do |address|
85
- ClientRegistry.instance.new_local_client(
86
- [address],
87
- SpecConfig.instance.all_test_options.merge(connect: :direct),
88
- ) do |c|
89
- server = c.cluster.servers.first
90
- next unless server.primary? || server.secondary?
91
- stat = c.command(serverStatus: 1).documents.first
92
- queries = stat['opcounters']['query']
93
- if server.primary?
94
- stats[:primary] += queries
95
- else
96
- stats[:secondary] += queries
97
- end
98
- end
99
- end
100
- stats
101
- end
102
- end
data/spec/shared/LICENSE DELETED
@@ -1,20 +0,0 @@
1
- Copyright (c) 2020 MongoDB, Inc.
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,17 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- desired_version, arch = ARGV
4
- if arch.nil?
5
- STDERR.puts "Usage: get-mongodb-download-url desired-version arch"
6
- exit 1
7
- end
8
-
9
- $: << File.join(File.dirname(__FILE__), '../lib')
10
- require 'mrss/server_version_registry'
11
-
12
- begin
13
- puts Mrss::ServerVersionRegistry.new(desired_version, arch).download_url
14
- rescue Mrss::ServerVersionRegistry::Error => exc
15
- STDERR.puts "Error: #{exc}"
16
- exit 2
17
- end
@@ -1,80 +0,0 @@
1
- # frozen_string_literal: true
2
- # encoding: utf-8
3
-
4
- autoload :ChildProcess, 'childprocess'
5
- autoload :Tempfile, 'tempfile'
6
-
7
- module Mrss
8
- module ChildProcessHelper
9
- class SpawnError < StandardError; end
10
-
11
- module_function def call(cmd, env: nil, cwd: nil)
12
- process = ChildProcess.new(*cmd)
13
- process.io.inherit!
14
- if cwd
15
- process.cwd = cwd
16
- end
17
- if env
18
- env.each do |k, v|
19
- process.environment[k.to_s] = v
20
- end
21
- end
22
- process.start
23
- process.wait
24
- process
25
- end
26
-
27
- module_function def check_call(cmd, env: nil, cwd: nil)
28
- process = call(cmd, env: env, cwd: cwd)
29
- unless process.exit_code == 0
30
- raise SpawnError, "Failed to execute: #{cmd}"
31
- end
32
- end
33
-
34
- module_function def get_output(cmd, env: nil, cwd: nil)
35
- process = ChildProcess.new(*cmd)
36
- process.io.inherit!
37
- if cwd
38
- process.cwd = cwd
39
- end
40
- if env
41
- env.each do |k, v|
42
- process.environment[k.to_s] = v
43
- end
44
- end
45
-
46
- output = ''
47
- r, w = IO.pipe
48
-
49
- begin
50
- process.io.stdout = w
51
- process.start
52
- w.close
53
-
54
- thread = Thread.new do
55
- begin
56
- loop do
57
- output << r.readpartial(16384)
58
- end
59
- rescue EOFError
60
- end
61
- end
62
-
63
- process.wait
64
- thread.join
65
- ensure
66
- r.close
67
- end
68
-
69
- [process, output]
70
- end
71
-
72
- module_function def check_output(*args)
73
- process, output = get_output(*args)
74
- unless process.exit_code == 0
75
- raise SpawnError,"Failed to execute: #{args}"
76
- end
77
- output
78
- end
79
- end
80
- end
@@ -1,221 +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 replica_set_name
19
- determine_cluster_config
20
- @replica_set_name
21
- end
22
-
23
- def server_version
24
- determine_cluster_config
25
- @server_version
26
- end
27
-
28
- def enterprise?
29
- determine_cluster_config
30
- @enterprise
31
- end
32
-
33
- def short_server_version
34
- server_version.split('.')[0..1].join('.')
35
- end
36
-
37
- def fcv
38
- determine_cluster_config
39
- @fcv
40
- end
41
-
42
- # Per https://jira.mongodb.org/browse/SERVER-39052, working with FCV
43
- # in sharded topologies is annoying. Also, FCV doesn't exist in servers
44
- # less than 3.4. This method returns FCV on 3.4+ servers when in single
45
- # or RS topologies, and otherwise returns the major.minor server version.
46
- def fcv_ish
47
- if server_version.nil?
48
- raise "Deployment server version not known - check that connection to deployment succeeded"
49
- end
50
-
51
- if server_version >= '3.4' && topology != :sharded
52
- fcv
53
- else
54
- if short_server_version == '4.1'
55
- '4.2'
56
- else
57
- short_server_version
58
- end
59
- end
60
- end
61
-
62
- # @return [ Mongo::Address ] The address of the primary in the deployment.
63
- def primary_address
64
- determine_cluster_config
65
- @primary_address
66
- end
67
-
68
- def primary_address_str
69
- determine_cluster_config
70
- @primary_address.seed
71
- end
72
-
73
- def primary_address_host
74
- both = primary_address_str
75
- both.split(':').first
76
- end
77
-
78
- def primary_address_port
79
- both = primary_address_str
80
- both.split(':')[1] || 27017
81
- end
82
-
83
- def primary_description
84
- determine_cluster_config
85
- @primary_description
86
- end
87
-
88
- def server_parameters
89
- determine_cluster_config
90
- @server_parameters
91
- end
92
-
93
- # Try running a command on the admin database to see if the mongod was
94
- # started with auth.
95
- def auth_enabled?
96
- if @auth_enabled.nil?
97
- @auth_enabled = begin
98
- basic_client.use(:admin).command(getCmdLineOpts: 1).first["argv"].include?("--auth")
99
- rescue => e
100
- e.message =~ /(not authorized)|(unauthorized)|(no users authenticated)|(requires authentication)/
101
- end
102
- end
103
- @auth_enabled
104
- end
105
-
106
- def topology
107
- determine_cluster_config
108
- @topology
109
- end
110
-
111
- def storage_engine
112
- @storage_engine ||= begin
113
- # 2.6 does not have wired tiger
114
- if short_server_version == '2.6'
115
- :mmapv1
116
- else
117
- client = ClientRegistry.instance.global_client('root_authorized')
118
- if topology == :sharded
119
- shards = client.use(:admin).command(listShards: 1).first
120
- if shards['shards'].empty?
121
- raise 'Shards are empty'
122
- end
123
- shard = shards['shards'].first
124
- address_str = shard['host'].sub(/^.*\//, '').sub(/,.*/, '')
125
- client = ClusterTools.instance.direct_client(address_str,
126
- SpecConfig.instance.test_options.merge(SpecConfig.instance.auth_options).merge(connect: :direct))
127
- end
128
- rv = client.use(:admin).command(serverStatus: 1).first
129
- rv = rv['storageEngine']['name']
130
- rv_map = {
131
- 'wiredTiger' => :wired_tiger,
132
- 'mmapv1' => :mmapv1,
133
- }
134
- rv_map[rv] || rv
135
- end
136
- end
137
- end
138
-
139
- # This method returns an alternate address for connecting to the configured
140
- # deployment. For example, if the replica set is configured with nodes at
141
- # of localhost:27017 and so on, this method will return 127.0.0.:27017.
142
- #
143
- # Note that the "alternate" refers to replica set configuration, not the
144
- # addresses specified in test suite configuration. If the deployment topology
145
- # is not a replica set, "alternate" refers to test suite configuration as
146
- # this is the only configuration available.
147
- def alternate_address
148
- @alternate_address ||= begin
149
- address = primary_address_host
150
- str = case address
151
- when '127.0.0.1'
152
- 'localhost'
153
- when /^(\d+\.){3}\d+$/
154
- skip 'This test requires a hostname or 127.0.0.1 as address'
155
- else
156
- # We don't know if mongod is listening on ipv4 or ipv6, in principle.
157
- # Our tests use ipv4, so hardcode that for now.
158
- # To support both we need to try both addresses which will make this
159
- # test more complicated.
160
- #
161
- # JRuby chokes on primary_address_port as the port (e.g. 27017).
162
- # Since the port does not actually matter, use a common port like 80.
163
- resolved_address = Addrinfo.getaddrinfo(address, 80, Socket::PF_INET).first.ip_address
164
- if resolved_address.include?(':')
165
- "[#{resolved_address}]"
166
- else
167
- resolved_address
168
- end
169
- end + ":#{primary_address_port}"
170
- Mongo::Address.new(str)
171
- end
172
- end
173
-
174
- private
175
-
176
- def determine_cluster_config
177
- return if @primary_address
178
-
179
- # Run all commands to figure out the cluster configuration from the same
180
- # client. This is somewhat wasteful when running a single test, but reduces
181
- # test runtime for the suite overall because all commands are sent on the
182
- # same connection rather than each command connecting to the cluster by
183
- # itself.
184
- client = ClientRegistry.instance.global_client('root_authorized')
185
-
186
- primary = client.cluster.next_primary
187
- @primary_address = primary.address
188
- @primary_description = primary.description
189
- @replica_set_name = client.cluster.topology.replica_set_name
190
-
191
- @topology ||= begin
192
- topology = client.cluster.topology.class.name.sub(/.*::/, '')
193
- topology = topology.gsub(/([A-Z])/) { |match| '_' + match.downcase }.sub(/^_/, '')
194
- if topology =~ /^replica_set/
195
- topology = 'replica_set'
196
- end
197
- topology.to_sym
198
- end
199
-
200
- @single_server = client.cluster.servers_list.length == 1
201
-
202
- build_info = client.database.command(buildInfo: 1).first
203
-
204
- @server_version = build_info['version']
205
- @enterprise = build_info['modules'] && build_info['modules'].include?('enterprise')
206
-
207
- @server_parameters = client.use(:admin).command(getParameter: '*').first
208
-
209
- if @topology != :sharded && short_server_version >= '3.4'
210
- rv = @server_parameters['featureCompatibilityVersion']
211
- @fcv = rv['version'] || rv
212
- end
213
- end
214
-
215
- def basic_client
216
- # Do not cache the result here so that if the client gets closed,
217
- # client registry reconnects it in subsequent tests
218
- ClientRegistry.instance.global_client('basic')
219
- end
220
- end
221
- end