mongo 2.2.1 → 2.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +1 -0
  4. data/lib/mongo/bson.rb +1 -1
  5. data/lib/mongo/cluster/topology/replica_set.rb +21 -4
  6. data/lib/mongo/collection/view/readable.rb +0 -1
  7. data/lib/mongo/error/operation_failure.rb +3 -1
  8. data/lib/mongo/grid/file.rb +14 -11
  9. data/lib/mongo/grid/file/chunk.rb +12 -10
  10. data/lib/mongo/grid/fs_bucket.rb +2 -2
  11. data/lib/mongo/grid/stream/read.rb +1 -1
  12. data/lib/mongo/grid/stream/write.rb +5 -5
  13. data/lib/mongo/options/mapper.rb +17 -0
  14. data/lib/mongo/protocol/message.rb +1 -1
  15. data/lib/mongo/server/connection.rb +3 -25
  16. data/lib/mongo/server/description.rb +19 -2
  17. data/lib/mongo/version.rb +1 -1
  18. data/lib/mongo/write_concern/normalizable.rb +2 -1
  19. data/spec/mongo/client_spec.rb +1 -1
  20. data/spec/mongo/collection/view/readable_spec.rb +18 -0
  21. data/spec/mongo/grid/file/chunk_spec.rb +1 -0
  22. data/spec/mongo/grid/file_spec.rb +25 -6
  23. data/spec/mongo/grid/stream/write_spec.rb +11 -0
  24. data/spec/mongo/protocol/reply_spec.rb +13 -0
  25. data/spec/mongo/server/connection_spec.rb +4 -4
  26. data/spec/mongo/write_concern_spec.rb +15 -0
  27. data/spec/support/command_monitoring.rb +3 -0
  28. data/spec/support/sdam/rs/equal_electionids.yml +4 -0
  29. data/spec/support/sdam/rs/new_primary_new_electionid.yml +7 -1
  30. data/spec/support/sdam/rs/new_primary_new_setversion.yml +101 -0
  31. data/spec/support/sdam/rs/null_election_id.yml +8 -1
  32. data/spec/support/sdam/rs/primary_disconnect_electionid.yml +37 -1
  33. data/spec/support/sdam/rs/primary_disconnect_setversion.yml +160 -0
  34. data/spec/support/sdam/rs/set_version_without_electionid.yml +69 -0
  35. data/spec/support/sdam/rs/setversion_without_electionid.yml +69 -0
  36. data/spec/support/sdam/rs/use_setversion_without_electionid.yml +99 -0
  37. metadata +36 -5
  38. metadata.gz.sig +1 -0
  39. data/lib/csasl/csasl.bundle +0 -0
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'stringio'
2
3
 
3
4
  describe Mongo::Grid::File::Chunk do
4
5
 
@@ -57,13 +57,13 @@ describe Mongo::Grid::File do
57
57
  described_class.new(data, :filename => 'test.txt')
58
58
  end
59
59
 
60
- it 'sets the data' do
61
- expect(file.data).to eq(data)
62
- end
63
-
64
60
  it 'creates the chunks' do
65
61
  expect(file.chunks.size).to eq(4)
66
62
  end
63
+
64
+ it 'returns data' do
65
+ expect(file.data).to eq(data)
66
+ end
67
67
  end
68
68
 
69
69
  context 'when data is a ruby file' do
@@ -80,12 +80,31 @@ describe Mongo::Grid::File do
80
80
  described_class.new(data, :filename => File.basename(ruby_file.path))
81
81
  end
82
82
 
83
- it 'sets the data' do
83
+ it 'creates the chunks' do
84
+ expect(file.chunks.size).to eq(4)
85
+ end
86
+
87
+ it 'returns data' do
84
88
  expect(file.data).to eq(data)
85
89
  end
90
+ end
91
+
92
+ context 'when data is an IO object' do
93
+
94
+ let(:io) do
95
+ StringIO.new('testing')
96
+ end
97
+
98
+ let(:file) do
99
+ described_class.new(io, filename: "test.txt")
100
+ end
86
101
 
87
102
  it 'creates the chunks' do
88
- expect(file.chunks.size).to eq(4)
103
+ expect(file.chunks).not_to be_empty
104
+ end
105
+
106
+ it 'returns data' do
107
+ expect(file.data).to eq 'testing'
89
108
  end
90
109
  end
91
110
 
@@ -66,6 +66,17 @@ describe Mongo::Grid::FSBucket::Stream::Write do
66
66
  end
67
67
  end
68
68
 
69
+ context 'when the fs does not have a write concern' do
70
+
71
+ let(:fs) do
72
+ authorized_client.with(write: nil).database.fs
73
+ end
74
+
75
+ it 'uses the write concern default at the operation level' do
76
+ expect(stream.write(file).closed?).to eq(false)
77
+ end
78
+ end
79
+
69
80
  context 'when provided options' do
70
81
 
71
82
  context 'when provided a write option' do
@@ -97,6 +97,19 @@ describe Mongo::Protocol::Reply do
97
97
  end
98
98
  end
99
99
 
100
+ context 'when the max message size is nil' do
101
+
102
+ let(:reply) { described_class.deserialize(io, nil) }
103
+
104
+ let(:length) { Mongo::Protocol::Message::MAX_MESSAGE_SIZE + 1 }
105
+
106
+ it 'uses the default max message size for comparison' do
107
+ expect {
108
+ reply
109
+ }.to raise_error(Mongo::Error::MaxMessageSize)
110
+ end
111
+ end
112
+
100
113
  describe 'response flags' do
101
114
 
102
115
  context 'no flags' do
@@ -140,8 +140,8 @@ describe Mongo::Server::Connection do
140
140
  connection.connect!
141
141
  end
142
142
 
143
- it 'sets the connection as authenticated' do
144
- expect(connection).to be_authenticated
143
+ it 'sets the connection as connected' do
144
+ expect(connection).to be_connected
145
145
  end
146
146
  end
147
147
  end
@@ -433,8 +433,8 @@ describe Mongo::Server::Connection do
433
433
  )
434
434
  end
435
435
 
436
- it 'sets the authentication strategy for the connection' do
437
- expect(connection.authenticator.user).to eq(user)
436
+ it 'sets the auth options' do
437
+ expect(connection.options[:user]).to eq(user.name)
438
438
  end
439
439
  end
440
440
  end
@@ -122,5 +122,20 @@ describe Mongo::WriteConcern do
122
122
  expect(Mongo::WriteConcern.get(options).options).to eq(options)
123
123
  end
124
124
  end
125
+
126
+ context 'when w is a symbol' do
127
+
128
+ let(:options) do
129
+ { w: :majority, journal: true }
130
+ end
131
+
132
+ it 'returns an Acknowledged write concern object' do
133
+ expect(Mongo::WriteConcern.get(options)).to be_a(Mongo::WriteConcern::Acknowledged)
134
+ end
135
+
136
+ it 'sets w to a string' do
137
+ expect(Mongo::WriteConcern.get(options).options[:w]).to eq('majority')
138
+ end
139
+ end
125
140
  end
126
141
  end
@@ -129,6 +129,9 @@ module Mongo
129
129
  #
130
130
  # @since 2.1.0
131
131
  def hash_matches?(actual, expected)
132
+ if expected['writeConcern']
133
+ expected['writeConcern'] = Options::Mapper.transform_keys_to_symbols(expected['writeConcern'])
134
+ end
132
135
  if expected.keys.first == '$numberLong'
133
136
  converted = expected.values.first.to_i
134
137
  (actual == converted) || actual >= 0
@@ -12,6 +12,7 @@ phases: [
12
12
  ismaster: true,
13
13
  hosts: ["a:27017", "b:27017"],
14
14
  setName: "rs",
15
+ setVersion: 1,
15
16
  electionId: {"$oid": "000000000000000000000001"}
16
17
  }],
17
18
  ["b:27017", {
@@ -19,6 +20,7 @@ phases: [
19
20
  ismaster: true,
20
21
  hosts: ["a:27017", "b:27017"],
21
22
  setName: "rs",
23
+ setVersion: 1,
22
24
  electionId: {"$oid": "000000000000000000000001"}
23
25
  }]
24
26
  ],
@@ -29,11 +31,13 @@ phases: [
29
31
  "a:27017": {
30
32
  type: "Unknown",
31
33
  setName: ,
34
+ setVersion: ,
32
35
  electionId:
33
36
  },
34
37
  "b:27017": {
35
38
  type: "RSPrimary",
36
39
  setName: "rs",
40
+ setVersion: 1,
37
41
  electionId: {"$oid": "000000000000000000000001"}
38
42
  }
39
43
  },
@@ -1,4 +1,4 @@
1
- description: "New primary with greater electionId"
1
+ description: "New primary with greater setVersion and electionId"
2
2
 
3
3
  uri: "mongodb://a/?replicaSet=rs"
4
4
 
@@ -12,6 +12,7 @@ phases: [
12
12
  ismaster: true,
13
13
  hosts: ["a:27017", "b:27017"],
14
14
  setName: "rs",
15
+ setVersion: 1,
15
16
  electionId: {"$oid": "000000000000000000000001"}
16
17
  }]
17
18
  ],
@@ -21,6 +22,7 @@ phases: [
21
22
  "a:27017": {
22
23
  type: "RSPrimary",
23
24
  setName: "rs",
25
+ setVersion: 1,
24
26
  electionId: {"$oid": "000000000000000000000001"}
25
27
  },
26
28
  "b:27017": {
@@ -42,6 +44,7 @@ phases: [
42
44
  ismaster: true,
43
45
  hosts: ["a:27017", "b:27017"],
44
46
  setName: "rs",
47
+ setVersion: 1,
45
48
  electionId: {"$oid": "000000000000000000000002"}
46
49
  }]
47
50
  ],
@@ -56,6 +59,7 @@ phases: [
56
59
  "b:27017": {
57
60
  type: "RSPrimary",
58
61
  setName: "rs",
62
+ setVersion: 1,
59
63
  electionId: {"$oid": "000000000000000000000002"}
60
64
  }
61
65
  },
@@ -72,6 +76,7 @@ phases: [
72
76
  ismaster: true,
73
77
  hosts: ["a:27017", "b:27017"],
74
78
  setName: "rs",
79
+ setVersion: 1,
75
80
  electionId: {"$oid": "000000000000000000000001"}
76
81
  }]
77
82
  ],
@@ -85,6 +90,7 @@ phases: [
85
90
  "b:27017": {
86
91
  type: "RSPrimary",
87
92
  setName: "rs",
93
+ setVersion: 1,
88
94
  electionId: {"$oid": "000000000000000000000002"}
89
95
  }
90
96
  },
@@ -0,0 +1,101 @@
1
+ description: "New primary with greater setVersion"
2
+
3
+ uri: "mongodb://a/?replicaSet=rs"
4
+
5
+ phases: [
6
+
7
+ # Primary A is discovered and tells us about B.
8
+ {
9
+ responses: [
10
+ ["a:27017", {
11
+ ok: 1,
12
+ ismaster: true,
13
+ hosts: ["a:27017", "b:27017"],
14
+ setName: "rs",
15
+ setVersion: 1,
16
+ electionId: {"$oid": "000000000000000000000001"}
17
+ }]
18
+ ],
19
+
20
+ outcome: {
21
+ servers: {
22
+ "a:27017": {
23
+ type: "RSPrimary",
24
+ setName: "rs",
25
+ setVersion: 1,
26
+ electionId: {"$oid": "000000000000000000000001"}
27
+ },
28
+ "b:27017": {
29
+ type: "Unknown",
30
+ setName: ,
31
+ electionId:
32
+ }
33
+ },
34
+ topologyType: "ReplicaSetWithPrimary",
35
+ setName: "rs",
36
+ }
37
+ },
38
+
39
+ # RS is reconfigured and B is elected.
40
+ {
41
+ responses: [
42
+ ["b:27017", {
43
+ ok: 1,
44
+ ismaster: true,
45
+ hosts: ["a:27017", "b:27017"],
46
+ setName: "rs",
47
+ setVersion: 2,
48
+ electionId: {"$oid": "000000000000000000000001"}
49
+ }]
50
+ ],
51
+
52
+ outcome: {
53
+ servers: {
54
+ "a:27017": {
55
+ type: "Unknown",
56
+ setName: ,
57
+ electionId:
58
+ },
59
+ "b:27017": {
60
+ type: "RSPrimary",
61
+ setName: "rs",
62
+ setVersion: 2,
63
+ electionId: {"$oid": "000000000000000000000001"}
64
+ }
65
+ },
66
+ topologyType: "ReplicaSetWithPrimary",
67
+ setName: "rs",
68
+ }
69
+ },
70
+
71
+ # A still claims to be primary but it's ignored.
72
+ {
73
+ responses: [
74
+ ["a:27017", {
75
+ ok: 1,
76
+ ismaster: true,
77
+ hosts: ["a:27017", "b:27017"],
78
+ setName: "rs",
79
+ setVersion: 1,
80
+ electionId: {"$oid": "000000000000000000000001"}
81
+ }]
82
+ ],
83
+ outcome: {
84
+ servers: {
85
+ "a:27017": {
86
+ type: "Unknown",
87
+ setName: ,
88
+ electionId:
89
+ },
90
+ "b:27017": {
91
+ type: "RSPrimary",
92
+ setName: "rs",
93
+ setVersion: 2,
94
+ electionId: {"$oid": "000000000000000000000002"}
95
+ }
96
+ },
97
+ topologyType: "ReplicaSetWithPrimary",
98
+ setName: "rs",
99
+ }
100
+ }
101
+ ]
@@ -11,6 +11,7 @@ phases: [
11
11
  ok: 1,
12
12
  ismaster: true,
13
13
  hosts: ["a:27017", "b:27017", "c:27017"],
14
+ setVersion: 1,
14
15
  setName: "rs"
15
16
  }]
16
17
  ],
@@ -20,6 +21,7 @@ phases: [
20
21
  "a:27017": {
21
22
  type: "RSPrimary",
22
23
  setName: "rs",
24
+ setVersion: 1,
23
25
  electionId:
24
26
  },
25
27
  "b:27017": {
@@ -46,6 +48,7 @@ phases: [
46
48
  ismaster: true,
47
49
  hosts: ["a:27017", "b:27017", "c:27017"],
48
50
  setName: "rs",
51
+ setVersion: 1,
49
52
  electionId: {"$oid": "000000000000000000000002"}
50
53
  }]
51
54
  ],
@@ -60,6 +63,7 @@ phases: [
60
63
  "b:27017": {
61
64
  type: "RSPrimary",
62
65
  setName: "rs",
66
+ setVersion: 1,
63
67
  electionId: {"$oid": "000000000000000000000002"}
64
68
  },
65
69
  "c:27017": {
@@ -80,6 +84,7 @@ phases: [
80
84
  ok: 1,
81
85
  ismaster: true,
82
86
  hosts: ["a:27017", "b:27017", "c:27017"],
87
+ setVersion: 1,
83
88
  setName: "rs"
84
89
  }]
85
90
  ],
@@ -88,6 +93,7 @@ phases: [
88
93
  "a:27017": {
89
94
  type: "RSPrimary",
90
95
  setName: "rs",
96
+ setVersion: 1,
91
97
  electionId:
92
98
  },
93
99
  "b:27017": {
@@ -106,7 +112,7 @@ phases: [
106
112
  }
107
113
  },
108
114
 
109
- # But we remember A's electionId, so when we finally hear from C
115
+ # But we remember B's electionId, so when we finally hear from C
110
116
  # claiming it is primary, we ignore it due to its outdated electionId
111
117
  {
112
118
  responses: [
@@ -115,6 +121,7 @@ phases: [
115
121
  ismaster: true,
116
122
  hosts: ["a:27017", "b:27017", "c:27017"],
117
123
  setName: "rs",
124
+ setVersion: 1,
118
125
  electionId: {"$oid": "000000000000000000000001"}
119
126
  }]
120
127
  ],
@@ -1,4 +1,4 @@
1
- description: "Disconnected from primary, reject stale primary"
1
+ description: "Disconnected from primary, reject primary with stale electionId"
2
2
 
3
3
  uri: "mongodb://a/?replicaSet=rs"
4
4
 
@@ -12,6 +12,7 @@ phases: [
12
12
  ismaster: true,
13
13
  hosts: ["a:27017", "b:27017"],
14
14
  setName: "rs",
15
+ setVersion: 1,
15
16
  electionId: {"$oid": "000000000000000000000001"}
16
17
  }],
17
18
  ["b:27017", {
@@ -19,6 +20,7 @@ phases: [
19
20
  ismaster: true,
20
21
  hosts: ["a:27017", "b:27017"],
21
22
  setName: "rs",
23
+ setVersion: 1,
22
24
  electionId: {"$oid": "000000000000000000000002"}
23
25
  }]
24
26
  ],
@@ -33,6 +35,7 @@ phases: [
33
35
  "b:27017": {
34
36
  type: "RSPrimary",
35
37
  setName: "rs",
38
+ setVersion: 1,
36
39
  electionId: {"$oid": "000000000000000000000002"}
37
40
  }
38
41
  },
@@ -72,6 +75,7 @@ phases: [
72
75
  ismaster: true,
73
76
  hosts: ["a:27017", "b:27017"],
74
77
  setName: "rs",
78
+ setVersion: 1,
75
79
  electionId: {"$oid": "000000000000000000000001"}
76
80
  }]
77
81
  ],
@@ -101,6 +105,7 @@ phases: [
101
105
  ismaster: true,
102
106
  hosts: ["a:27017", "b:27017"],
103
107
  setName: "rs",
108
+ setVersion: 1,
104
109
  electionId: {"$oid": "000000000000000000000003"}
105
110
  }]
106
111
  ],
@@ -109,6 +114,7 @@ phases: [
109
114
  "a:27017": {
110
115
  type: "RSPrimary",
111
116
  setName: "rs",
117
+ setVersion: 1,
112
118
  electionId: {"$oid": "000000000000000000000003"}
113
119
  },
114
120
  "b:27017": {
@@ -120,5 +126,35 @@ phases: [
120
126
  topologyType: "ReplicaSetWithPrimary",
121
127
  setName: "rs",
122
128
  }
129
+ },
130
+
131
+ # B comes back as secondary.
132
+ {
133
+ responses: [
134
+ ["b:27017", {
135
+ ok: 1,
136
+ ismaster: false,
137
+ secondary: true,
138
+ hosts: ["a:27017", "b:27017"],
139
+ setName: "rs",
140
+ setVersion: 2
141
+ }]
142
+ ],
143
+ outcome: {
144
+ servers: {
145
+ "a:27017": {
146
+ type: "RSPrimary",
147
+ setName: "rs",
148
+ setVersion: 1,
149
+ electionId: {"$oid": "000000000000000000000002"}
150
+ },
151
+ "b:27017": {
152
+ type: "RSSecondary",
153
+ setName: "rs"
154
+ }
155
+ },
156
+ topologyType: "ReplicaSetWithPrimary",
157
+ setName: "rs",
158
+ }
123
159
  }
124
160
  ]