mongo 2.11.1 → 2.11.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +2 -1
  3. data.tar.gz.sig +2 -1
  4. data/Rakefile +24 -0
  5. data/lib/mongo/address.rb +53 -37
  6. data/lib/mongo/auth.rb +30 -10
  7. data/lib/mongo/auth/cr.rb +1 -0
  8. data/lib/mongo/auth/cr/conversation.rb +13 -13
  9. data/lib/mongo/auth/ldap.rb +2 -1
  10. data/lib/mongo/auth/ldap/conversation.rb +9 -12
  11. data/lib/mongo/auth/scram.rb +1 -0
  12. data/lib/mongo/auth/scram/conversation.rb +36 -27
  13. data/lib/mongo/auth/user.rb +7 -1
  14. data/lib/mongo/auth/x509.rb +2 -1
  15. data/lib/mongo/auth/x509/conversation.rb +9 -9
  16. data/lib/mongo/bulk_write/transformable.rb +3 -3
  17. data/lib/mongo/client.rb +17 -6
  18. data/lib/mongo/cluster.rb +67 -49
  19. data/lib/mongo/cluster/sdam_flow.rb +87 -3
  20. data/lib/mongo/collection/view/readable.rb +3 -1
  21. data/lib/mongo/collection/view/writable.rb +3 -3
  22. data/lib/mongo/cursor/builder/kill_cursors_command.rb +8 -1
  23. data/lib/mongo/cursor/builder/op_kill_cursors.rb +8 -1
  24. data/lib/mongo/database.rb +1 -1
  25. data/lib/mongo/grid/file.rb +5 -0
  26. data/lib/mongo/grid/file/chunk.rb +2 -0
  27. data/lib/mongo/grid/fs_bucket.rb +15 -13
  28. data/lib/mongo/grid/stream/write.rb +9 -3
  29. data/lib/mongo/protocol/serializers.rb +12 -2
  30. data/lib/mongo/server.rb +13 -6
  31. data/lib/mongo/server/connection.rb +15 -8
  32. data/lib/mongo/server/connection_base.rb +7 -4
  33. data/lib/mongo/server/description.rb +34 -21
  34. data/lib/mongo/server/monitor.rb +1 -1
  35. data/lib/mongo/server/monitor/connection.rb +2 -3
  36. data/lib/mongo/session.rb +10 -10
  37. data/lib/mongo/socket.rb +10 -1
  38. data/lib/mongo/uri.rb +1 -1
  39. data/lib/mongo/version.rb +1 -1
  40. data/mongo.gemspec +1 -1
  41. data/spec/README.md +13 -0
  42. data/spec/integration/auth_spec.rb +27 -8
  43. data/spec/integration/bson_symbol_spec.rb +34 -0
  44. data/spec/integration/client_construction_spec.rb +14 -0
  45. data/spec/integration/client_options_spec.rb +5 -5
  46. data/spec/integration/connection_spec.rb +57 -9
  47. data/spec/integration/crud_spec.rb +45 -0
  48. data/spec/integration/cursor_reaping_spec.rb +2 -1
  49. data/spec/integration/grid_fs_bucket_spec.rb +48 -0
  50. data/spec/integration/retryable_errors_spec.rb +2 -2
  51. data/spec/integration/zlib_compression_spec.rb +25 -0
  52. data/spec/lite_spec_helper.rb +1 -0
  53. data/spec/mongo/address_spec.rb +19 -13
  54. data/spec/mongo/auth/ldap/conversation_spec.rb +1 -1
  55. data/spec/mongo/auth/scram/conversation_spec.rb +25 -14
  56. data/spec/mongo/auth/user/view_spec.rb +39 -7
  57. data/spec/mongo/auth/user_spec.rb +12 -0
  58. data/spec/mongo/auth/x509/conversation_spec.rb +1 -1
  59. data/spec/mongo/bulk_write_spec.rb +2 -2
  60. data/spec/mongo/client_construction_spec.rb +3 -22
  61. data/spec/mongo/cluster_spec.rb +57 -0
  62. data/spec/mongo/collection/view/map_reduce_spec.rb +1 -1
  63. data/spec/mongo/collection_spec.rb +26 -2
  64. data/spec/mongo/cursor/builder/op_kill_cursors_spec.rb +56 -0
  65. data/spec/mongo/server/connection_spec.rb +76 -8
  66. data/spec/mongo/server/monitor/connection_spec.rb +14 -7
  67. data/spec/mongo/socket/ssl_spec.rb +132 -98
  68. data/spec/mongo/socket/tcp_spec.rb +1 -9
  69. data/spec/mongo/uri_spec.rb +1 -1
  70. data/spec/runners/sdam/verifier.rb +6 -3
  71. data/spec/spec_tests/data/sdam/rs/primary_address_change.yml +29 -0
  72. data/spec/spec_tests/data/sdam/rs/primary_mismatched_me.yml +27 -23
  73. data/spec/spec_tests/data/sdam/rs/primary_to_no_primary_mismatched_me.yml +56 -79
  74. data/spec/spec_tests/data/sdam/sharded/primary_address_change.yml +21 -0
  75. data/spec/spec_tests/data/sdam/sharded/primary_mismatched_me.yml +22 -0
  76. data/spec/spec_tests/data/sdam/single/primary_address_change.yml +24 -0
  77. data/spec/spec_tests/data/sdam/single/primary_mismatched_me.yml +25 -0
  78. data/spec/spec_tests/data/sdam_monitoring/replica_set_with_me_mismatch.yml +159 -0
  79. data/spec/spec_tests/data/sdam_monitoring/{replica_set_other_seed.yml → replica_set_with_primary_change.yml} +97 -101
  80. data/spec/spec_tests/data/sdam_monitoring/replica_set_with_primary_removal.yml +22 -18
  81. data/spec/spec_tests/data/sdam_monitoring/standalone_to_rs_with_me_mismatch.yml +90 -0
  82. data/spec/support/cluster_config.rb +36 -0
  83. data/spec/support/cluster_tools.rb +5 -3
  84. data/spec/support/command_monitoring.rb +1 -1
  85. data/spec/support/constraints.rb +18 -18
  86. data/spec/support/lite_constraints.rb +8 -0
  87. data/spec/support/server_discovery_and_monitoring.rb +2 -0
  88. data/spec/support/spec_config.rb +3 -3
  89. data/spec/support/utils.rb +11 -1
  90. metadata +661 -637
  91. metadata.gz.sig +0 -0
@@ -1,16 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Mongo::Socket::TCP do
4
- require_no_tls
5
-
6
- let(:address) { default_address }
7
-
8
- let!(:resolver) do
9
- address.send(:create_resolver, {})
10
- end
11
-
12
4
  let(:socket) do
13
- resolver.socket(5, {})
5
+ described_class.new('127.0.0.1', SpecConfig.instance.any_port, 5, Socket::AF_INET)
14
6
  end
15
7
 
16
8
  describe '#address' do
@@ -352,7 +352,7 @@ describe Mongo::URI do
352
352
  let(:servers) { '%2Ftmp%2Fmongodb-27017.sock' }
353
353
 
354
354
  it 'returns an array with the parsed server' do
355
- expect(uri.servers).to eq([URI.unescape(servers)])
355
+ expect(uri.servers).to eq([URI::DEFAULT_PARSER.unescape(servers)])
356
356
  end
357
357
  end
358
358
 
@@ -37,10 +37,13 @@ module Sdam
37
37
  verify_description_matches(server, desc)
38
38
  end
39
39
 
40
+ # Verify actual topology has no servers not also present in the
41
+ # expected topology description.
42
+ expected_addresses = expected['servers'].map do |server|
43
+ server['address']
44
+ end
40
45
  actual.server_descriptions.keys.each do |address_str|
41
- expect(
42
- expected['servers'].any? { |server| server['address'] == address_str }
43
- ).to be true
46
+ expect(expected_addresses).to include(address_str)
44
47
  end
45
48
  end
46
49
 
@@ -0,0 +1,29 @@
1
+ description: Primary whose address differs from client address but no me mismatch
2
+ uri: mongodb://localhost:27017/?replicaSet=rs
3
+ phases:
4
+ -
5
+ responses:
6
+ -
7
+ - localhost:27017
8
+ - hosts:
9
+ - a:27017
10
+ - b:27017
11
+ ismaster: true
12
+ ok: 1
13
+ setName: rs
14
+ minWireVersion: 0
15
+ maxWireVersion: 6
16
+ outcome:
17
+ # Both of the hosts in the primary description are added to the topology.
18
+ # Existing server (localhost:27017) is removed from topology because
19
+ # its address is not in the list of hosts returned by the primary.
20
+ servers:
21
+ a:27017:
22
+ setName:
23
+ type: Unknown
24
+ b:27017:
25
+ setName:
26
+ type: Unknown
27
+ setName: rs
28
+ topologyType: ReplicaSetNoPrimary
29
+ logicalSessionTimeoutMinutes:
@@ -1,26 +1,30 @@
1
1
  description: Primary mismatched me
2
+ uri: mongodb://localhost:27017/?replicaSet=rs
2
3
  phases:
3
- - outcome:
4
- servers:
5
- 'a:27017':
6
- setName: null
7
- type: Unknown
8
- 'b:27017':
9
- setName: null
10
- type: Unknown
4
+ -
5
+ responses:
6
+ -
7
+ - localhost:27017
8
+ - me: a:27017
9
+ hosts:
10
+ - a:27017
11
+ - b:27017
12
+ ismaster: true
13
+ ok: 1
11
14
  setName: rs
12
- topologyType: ReplicaSetNoPrimary
13
- logicalSessionTimeoutMinutes: null
14
- responses:
15
- - - 'localhost:27017'
16
- - me: 'a:27017'
17
- hosts:
18
- - 'a:27017'
19
- - 'b:27017'
20
- ismaster: true
21
- ok: 1
22
- setName: rs
23
- minWireVersion: 0
24
- maxWireVersion: 6
25
- uri: 'mongodb://localhost:27017/?replicaSet=rs'
26
-
15
+ minWireVersion: 0
16
+ maxWireVersion: 6
17
+ outcome:
18
+ # Both of the hosts in the primary description are added to the topology.
19
+ # Existing server (localhost:27017) is removed from topology because
20
+ # its address is not in the list of hosts returned by the primary.
21
+ servers:
22
+ a:27017:
23
+ setName:
24
+ type: Unknown
25
+ b:27017:
26
+ setName:
27
+ type: Unknown
28
+ setName: rs
29
+ topologyType: ReplicaSetNoPrimary
30
+ logicalSessionTimeoutMinutes:
@@ -1,79 +1,56 @@
1
- description: "Primary to no primary with mismatched me"
2
-
3
- uri: "mongodb://a/?replicaSet=rs"
4
-
5
- phases: [
6
-
7
- {
8
- responses: [
9
-
10
- ["a:27017", {
11
-
12
- ok: 1,
13
- ismaster: true,
14
- hosts: ["a:27017", "b:27017"],
15
- me: "a:27017",
16
- setName: "rs",
17
- minWireVersion: 0,
18
- maxWireVersion: 6
19
- }]
20
- ],
21
-
22
- outcome: {
23
-
24
- servers: {
25
-
26
- "a:27017": {
27
-
28
- type: "RSPrimary",
29
- setName: "rs"
30
- },
31
-
32
- "b:27017": {
33
-
34
- type: "Unknown",
35
- setName:
36
- }
37
- },
38
- topologyType: "ReplicaSetWithPrimary",
39
- logicalSessionTimeoutMinutes: null,
40
- setName: "rs"
41
- }
42
- },
43
- {
44
- responses: [
45
-
46
- ["a:27017", {
47
-
48
- ok: 1,
49
- ismaster: true,
50
- hosts: ["c:27017", "d:27017"],
51
- me : "c:27017",
52
- setName: "rs",
53
- minWireVersion: 0,
54
- maxWireVersion: 6
55
- }]
56
- ],
57
-
58
- outcome: {
59
-
60
- servers: {
61
-
62
- "c:27017": {
63
-
64
- type: "Unknown",
65
- setName:
66
- },
67
-
68
- "d:27017": {
69
-
70
- type: "Unknown",
71
- setName:
72
- }
73
- },
74
- topologyType: "ReplicaSetNoPrimary",
75
- logicalSessionTimeoutMinutes: null,
76
- setName: "rs"
77
- }
78
- }
79
- ]
1
+ description: Primary to no primary with mismatched me
2
+ uri: mongodb://a/?replicaSet=rs
3
+
4
+ phases:
5
+ -
6
+ responses:
7
+ -
8
+ - a:27017
9
+ - ok: 1
10
+ ismaster: true
11
+ hosts:
12
+ - a:27017
13
+ - b:27017
14
+ me: a:27017
15
+ setName: rs
16
+ minWireVersion: 0
17
+ maxWireVersion: 6
18
+ outcome:
19
+ servers:
20
+ a:27017:
21
+ type: RSPrimary
22
+ setName: rs
23
+ b:27017:
24
+ type: Unknown
25
+ setName:
26
+ topologyType: ReplicaSetWithPrimary
27
+ logicalSessionTimeoutMinutes:
28
+ setName: rs
29
+
30
+ -
31
+ responses:
32
+ -
33
+ - a:27017
34
+ - ok: 1
35
+ ismaster: true
36
+ hosts:
37
+ - c:27017
38
+ - d:27017
39
+ me: c:27017
40
+ setName: rs
41
+ minWireVersion: 0
42
+ maxWireVersion: 6
43
+ outcome:
44
+ # Hosts from primary description (c:27017 and d:27017) added to the topoolgy.
45
+ # Hosts not in primary description (a:27017 and b:27017) are removed from
46
+ # the topology.
47
+ servers:
48
+ c:27017:
49
+ type: Unknown
50
+ setName:
51
+ d:27017:
52
+ type: Unknown
53
+ setName:
54
+ topologyType: ReplicaSetNoPrimary
55
+ logicalSessionTimeoutMinutes:
56
+ setName: rs
@@ -0,0 +1,21 @@
1
+ description: RS Primary whose address differs from client address but no me mismatch
2
+ uri: mongodb://localhost:27017/?connect=sharded
3
+ phases:
4
+ -
5
+ responses:
6
+ -
7
+ - localhost:27017
8
+ - hosts:
9
+ - a:27017
10
+ - b:27017
11
+ ismaster: true
12
+ ok: 1
13
+ setName: rs
14
+ minWireVersion: 0
15
+ maxWireVersion: 6
16
+ outcome:
17
+ # Since the server is of the wrong type, it is removed from the topology.
18
+ servers:
19
+ {}
20
+ topologyType: Sharded
21
+ logicalSessionTimeoutMinutes:
@@ -0,0 +1,22 @@
1
+ description: RS Primary w/mismatched me
2
+ uri: mongodb://localhost:27017/?connect=sharded
3
+ phases:
4
+ -
5
+ responses:
6
+ -
7
+ - localhost:27017
8
+ - me: a:27017
9
+ hosts:
10
+ - a:27017
11
+ - b:27017
12
+ ismaster: true
13
+ ok: 1
14
+ setName: rs
15
+ minWireVersion: 0
16
+ maxWireVersion: 6
17
+ outcome:
18
+ # Since the server is of the wrong type, it is removed from the topology.
19
+ servers:
20
+ {}
21
+ topologyType: Sharded
22
+ logicalSessionTimeoutMinutes:
@@ -0,0 +1,24 @@
1
+ description: RS Primary whose address differs from client address but no me mismatch
2
+ uri: mongodb://localhost:27017/?connect=direct
3
+ phases:
4
+ -
5
+ responses:
6
+ -
7
+ - localhost:27017
8
+ - hosts:
9
+ - a:27017
10
+ - b:27017
11
+ ismaster: true
12
+ ok: 1
13
+ setName: rs
14
+ minWireVersion: 0
15
+ maxWireVersion: 6
16
+ outcome:
17
+ # In Single topology the server type is preserved. In this case the
18
+ # connection is to a RS primary.
19
+ servers:
20
+ localhost:27017:
21
+ type: RSPrimary
22
+ setName: rs
23
+ topologyType: Single
24
+ logicalSessionTimeoutMinutes:
@@ -0,0 +1,25 @@
1
+ description: RS Primary w/mismatched me
2
+ uri: mongodb://localhost:27017/?connect=direct
3
+ phases:
4
+ -
5
+ responses:
6
+ -
7
+ - localhost:27017
8
+ - me: a:27017
9
+ hosts:
10
+ - a:27017
11
+ - b:27017
12
+ ismaster: true
13
+ ok: 1
14
+ setName: rs
15
+ minWireVersion: 0
16
+ maxWireVersion: 6
17
+ outcome:
18
+ # In Single topology the server type is preserved. In this case the
19
+ # connection is to a RS primary.
20
+ servers:
21
+ localhost:27017:
22
+ type: RSPrimary
23
+ setName: rs
24
+ topologyType: Single
25
+ logicalSessionTimeoutMinutes:
@@ -0,0 +1,159 @@
1
+ description: "Monitoring a topology that is a replica set with a me mismatch in first response"
2
+ uri: "mongodb://a,b/"
3
+ phases:
4
+ -
5
+ responses: []
6
+ outcome:
7
+ events:
8
+ -
9
+ topology_opening_event:
10
+ topologyId: "42"
11
+ -
12
+ topology_description_changed_event:
13
+ topologyId: "42"
14
+ previousDescription:
15
+ topologyType: "Unknown"
16
+ servers: []
17
+ newDescription:
18
+ topologyType: "Unknown"
19
+ servers:
20
+ -
21
+ address: "a:27017"
22
+ arbiters: []
23
+ hosts: []
24
+ passives: []
25
+ type: "Unknown"
26
+ -
27
+ address: "b:27017"
28
+ arbiters: []
29
+ hosts: []
30
+ passives: []
31
+ type: "Unknown"
32
+ -
33
+ server_opening_event:
34
+ topologyId: "42"
35
+ address: "a:27017"
36
+ -
37
+ server_opening_event:
38
+ topologyId: "42"
39
+ address: "b:27017"
40
+ # phase 1 - server is a primary with mismatched me
41
+ -
42
+ responses:
43
+ -
44
+ - "a:27017"
45
+ -
46
+ ok: 1
47
+ ismaster: true
48
+ setName: "rs"
49
+ setVersion: 1
50
+ me: "aa:27017"
51
+ primary: "aa:27017"
52
+ hosts:
53
+ - "aa:27017"
54
+ minWireVersion: 0
55
+ maxWireVersion: 4
56
+ outcome:
57
+ events:
58
+ # TODO see about having the opening event precede the closing event.
59
+ -
60
+ server_closed_event:
61
+ topologyId: "42"
62
+ address: "a:27017"
63
+ -
64
+ server_closed_event:
65
+ topologyId: "42"
66
+ address: "b:27017"
67
+ -
68
+ server_opening_event:
69
+ topologyId: "42"
70
+ address: "aa:27017"
71
+ -
72
+ topology_description_changed_event:
73
+ topologyId: "42"
74
+ previousDescription:
75
+ topologyType: "Unknown"
76
+ servers:
77
+ -
78
+ address: "a:27017"
79
+ arbiters: []
80
+ hosts: []
81
+ passives: []
82
+ -
83
+ address: "b:27017"
84
+ arbiters: []
85
+ hosts: []
86
+ passives: []
87
+ newDescription:
88
+ topologyType: "ReplicaSetNoPrimary"
89
+ setName: rs
90
+ servers:
91
+ -
92
+ address: "aa:27017"
93
+ arbiters: []
94
+ hosts: []
95
+ passives: []
96
+
97
+ # phaes 2 - response from new primary from new address
98
+ -
99
+ responses:
100
+ -
101
+ - "aa:27017"
102
+ -
103
+ ok: 1
104
+ ismaster: true
105
+ setName: "rs"
106
+ setVersion: 1
107
+ primary: "aa:27017"
108
+ me: "aa:27017"
109
+ hosts:
110
+ - "aa:27017"
111
+ minWireVersion: 0
112
+ maxWireVersion: 4
113
+ outcome:
114
+ events:
115
+ -
116
+ server_description_changed_event:
117
+ topologyId: "42"
118
+ address: "aa:27017"
119
+ previousDescription:
120
+ address: "aa:27017"
121
+ arbiters: []
122
+ hosts: []
123
+ passives: []
124
+ type: "Unknown"
125
+ newDescription:
126
+ address: "aa:27017"
127
+ arbiters: []
128
+ hosts:
129
+ - "aa:27017"
130
+ passives: []
131
+ primary: "aa:27017"
132
+ setName: "rs"
133
+ type: "RSPrimary"
134
+ -
135
+ topology_description_changed_event:
136
+ topologyId: "42"
137
+ previousDescription:
138
+ topologyType: "ReplicaSetNoPrimary"
139
+ setName: rs
140
+ servers:
141
+ -
142
+ address: "aa:27017"
143
+ arbiters: []
144
+ hosts: []
145
+ passives: []
146
+ type: "Unknown"
147
+ newDescription:
148
+ topologyType: "ReplicaSetWithPrimary"
149
+ setName: "rs"
150
+ servers:
151
+ -
152
+ address: "aa:27017"
153
+ arbiters: []
154
+ hosts:
155
+ - "aa:27017"
156
+ passives: []
157
+ primary: "aa:27017"
158
+ setName: "rs"
159
+ type: "RSPrimary"