Skip to content

Commit 0bdc165

Browse files
committed
CSHARP-1362: Code review changes.
1 parent 297517a commit 0bdc165

File tree

5 files changed

+33
-81
lines changed

5 files changed

+33
-81
lines changed

src/MongoDB.Driver.Core.Tests/Core/Operations/AsyncCursorTests.cs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ public void constructor_should_initialize_instance()
5555
var serializer = BsonDocumentSerializer.Instance;
5656
var messageEncoderSettings = new MessageEncoderSettings();
5757
var maxTime = TimeSpan.FromSeconds(1);
58-
var slaveOk = true;
5958

6059
var result = new AsyncCursor<BsonDocument>(
6160
channelSource,
@@ -67,8 +66,7 @@ public void constructor_should_initialize_instance()
6766
limit,
6867
serializer,
6968
messageEncoderSettings,
70-
maxTime,
71-
slaveOk);
69+
maxTime);
7270

7371
var reflector = new Reflector(result);
7472
reflector.BatchSize.Should().Be(batchSize);
@@ -84,7 +82,6 @@ public void constructor_should_initialize_instance()
8482
reflector.MessageEncoderSettings.Should().BeEquivalentTo(messageEncoderSettings);
8583
reflector.Query.Should().Be(query);
8684
reflector.Serializer.Should().Be(serializer);
87-
reflector.SlaveOk.Should().Be(slaveOk);
8885
}
8986

9087
[Test]
@@ -193,8 +190,7 @@ private AsyncCursor<BsonDocument> CreateSubject(
193190
Optional<long> cursorId = default(Optional<long>),
194191
Optional<int?> batchSize = default(Optional<int?>),
195192
Optional<int?> limit = default(Optional<int?>),
196-
Optional<TimeSpan?> maxTime = default(Optional<TimeSpan?>),
197-
Optional<bool> slaveOk = default(Optional<bool>))
193+
Optional<TimeSpan?> maxTime = default(Optional<TimeSpan?>))
198194
{
199195
return new AsyncCursor<BsonDocument>(
200196
channelSource.WithDefault(Substitute.For<IChannelSource>()),
@@ -206,8 +202,7 @@ private AsyncCursor<BsonDocument> CreateSubject(
206202
limit.WithDefault(null),
207203
serializer.WithDefault(BsonDocumentSerializer.Instance),
208204
new MessageEncoderSettings(),
209-
maxTime.WithDefault(null),
210-
slaveOk.WithDefault(false));
205+
maxTime.WithDefault(null));
211206
}
212207

213208
// nested types
@@ -340,15 +335,6 @@ public IBsonSerializer<BsonDocument> Serializer
340335
}
341336
}
342337

343-
public bool SlaveOk
344-
{
345-
get
346-
{
347-
var fieldInfo = _instance.GetType().GetField("_slaveOk", BindingFlags.NonPublic | BindingFlags.Instance);
348-
return (bool)fieldInfo.GetValue(_instance);
349-
}
350-
}
351-
352338
// public methods
353339
public BsonDocument CreateGetMoreCommand()
354340
{

src/MongoDB.Driver.Core.Tests/Core/Operations/FindCommandOperationTests.cs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public void CreateCommand_should_return_expected_result()
165165

166166
var result = reflector.CreateCommand(serverDescription, null);
167167

168-
result.Should().Be($"{{ find : \"{_collectionNamespace.CollectionName}\" }}");
168+
result.Should().Be($"{{ find : '{_collectionNamespace.CollectionName}' }}");
169169
}
170170

171171
[Test]
@@ -180,7 +180,7 @@ public void CreateCommand_should_return_expected_result_when_allowPartialResults
180180

181181
var result = reflector.CreateCommand(serverDescription, null);
182182

183-
result.Should().Be($"{{ find : \"{_collectionNamespace.CollectionName}\", allowPartialResults : {(value ? "true" : "false")} }}");
183+
result.Should().Be($"{{ find : '{_collectionNamespace.CollectionName}', allowPartialResults : {(value ? "true" : "false")} }}");
184184
}
185185

186186
[Test]
@@ -195,7 +195,7 @@ public void CreateCommand_should_return_expected_result_when_comment_is_provided
195195

196196
var result = reflector.CreateCommand(serverDescription, null);
197197

198-
result.Should().Be($"{{ find : \"{_collectionNamespace.CollectionName}\", comment : \"{value}\" }}");
198+
result.Should().Be($"{{ find : '{_collectionNamespace.CollectionName}', comment : '{value}' }}");
199199
}
200200

201201
[TestCase(CursorType.Tailable, "")]
@@ -209,7 +209,7 @@ public void CreateCommand_should_return_expected_result_when_cursor_is_tailableA
209209

210210
var result = reflector.CreateCommand(serverDescription, null);
211211

212-
result.Should().Be($"{{ find : \"{_collectionNamespace.CollectionName}\", tailable : true{awaitJson} }}");
212+
result.Should().Be($"{{ find : '{_collectionNamespace.CollectionName}', tailable : true{awaitJson} }}");
213213
}
214214

215215
[Test]
@@ -224,7 +224,7 @@ public void CreateCommand_should_return_expected_result_when_filter_is_provided(
224224

225225
var result = reflector.CreateCommand(serverDescription, null);
226226

227-
result.Should().Be($"{{ find : \"{_collectionNamespace.CollectionName}\", filter : {json} }}");
227+
result.Should().Be($"{{ find : '{_collectionNamespace.CollectionName}', filter : {json} }}");
228228
}
229229

230230
[Test]
@@ -239,12 +239,12 @@ public void CreateCommand_should_return_expected_result_when_firstBatchSize_is_p
239239

240240
var result = reflector.CreateCommand(serverDescription, null);
241241

242-
result.Should().Be($"{{ find : \"{_collectionNamespace.CollectionName}\", batchSize : {value} }}");
242+
result.Should().Be($"{{ find : '{_collectionNamespace.CollectionName}', batchSize : {value} }}");
243243
}
244244

245245
[Test]
246246
public void CreateCommand_should_return_expected_result_when_hint_is_provided(
247-
[Values("{ value : \"b_1\" }", "{ value : { b : 1 } }")]
247+
[Values("{ value : 'b_1' }", "{ value : { b : 1 } }")]
248248
string json)
249249
{
250250
var subject = new FindCommandOperation<BsonDocument>(_collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings);
@@ -254,7 +254,7 @@ public void CreateCommand_should_return_expected_result_when_hint_is_provided(
254254

255255
var result = reflector.CreateCommand(serverDescription, null);
256256

257-
result.Should().Be($"{{ find : \"{_collectionNamespace.CollectionName}\", hint : {subject.Hint.ToJson()} }}");
257+
result.Should().Be($"{{ find : '{_collectionNamespace.CollectionName}', hint : {subject.Hint.ToJson()} }}");
258258
}
259259

260260
[TestCase(-1, ", limit : 1, singleBatch : true")]
@@ -270,7 +270,7 @@ public void CreateCommand_should_return_expected_result_when_limit_is_provided(i
270270

271271
var result = reflector.CreateCommand(serverDescription, null);
272272

273-
result.Should().Be($"{{ find : \"{_collectionNamespace.CollectionName}\"{json} }}");
273+
result.Should().Be($"{{ find : '{_collectionNamespace.CollectionName}'{json} }}");
274274
}
275275

276276
[Test]
@@ -285,7 +285,7 @@ public void CreateCommand_should_return_expected_result_when_max_is_provided(
285285

286286
var result = reflector.CreateCommand(serverDescription, null);
287287

288-
result.Should().Be($"{{ find : \"{_collectionNamespace.CollectionName}\", max : {json} }}");
288+
result.Should().Be($"{{ find : '{_collectionNamespace.CollectionName}', max : {json} }}");
289289
}
290290

291291
[Test]
@@ -300,7 +300,7 @@ public void CreateCommand_should_return_expected_result_when_maxScan_is_provided
300300

301301
var result = reflector.CreateCommand(serverDescription, null);
302302

303-
result.Should().Be($"{{ find : \"{_collectionNamespace.CollectionName}\", maxScan : {value} }}");
303+
result.Should().Be($"{{ find : '{_collectionNamespace.CollectionName}', maxScan : {value} }}");
304304
}
305305

306306
[Test]
@@ -315,7 +315,7 @@ public void CreateCommand_should_return_expected_result_when_maxTime_is_provided
315315

316316
var result = reflector.CreateCommand(serverDescription, null);
317317

318-
result.Should().Be($"{{ find : \"{_collectionNamespace.CollectionName}\", maxTimeMS : {value * 1000} }}");
318+
result.Should().Be($"{{ find : '{_collectionNamespace.CollectionName}', maxTimeMS : {value * 1000} }}");
319319
}
320320

321321
[Test]
@@ -330,7 +330,7 @@ public void CreateCommand_should_return_expected_result_when_min_is_provided(
330330

331331
var result = reflector.CreateCommand(serverDescription, null);
332332

333-
result.Should().Be($"{{ find : \"{_collectionNamespace.CollectionName}\", min : {json} }}");
333+
result.Should().Be($"{{ find : '{_collectionNamespace.CollectionName}', min : {json} }}");
334334
}
335335

336336
[Test]
@@ -345,7 +345,7 @@ public void CreateCommand_should_return_expected_result_when_noCursorTimeout_is_
345345

346346
var result = reflector.CreateCommand(serverDescription, null);
347347

348-
result.Should().Be($"{{ find : \"{_collectionNamespace.CollectionName}\", noCursorTimeout : {(value ? "true" : "false")} }}");
348+
result.Should().Be($"{{ find : '{_collectionNamespace.CollectionName}', noCursorTimeout : {(value ? "true" : "false")} }}");
349349
}
350350

351351
[Test]
@@ -360,7 +360,7 @@ public void CreateCommand_should_return_expected_result_when_oplogReplay_is_prov
360360

361361
var result = reflector.CreateCommand(serverDescription, null);
362362

363-
result.Should().Be($"{{ find : \"{_collectionNamespace.CollectionName}\", oplogReplay : {(value ? "true" : "false")} }}");
363+
result.Should().Be($"{{ find : '{_collectionNamespace.CollectionName}', oplogReplay : {(value ? "true" : "false")} }}");
364364
}
365365

366366
[Test]
@@ -375,7 +375,7 @@ public void CreateCommand_should_return_expected_result_when_projection_is_provi
375375

376376
var result = reflector.CreateCommand(serverDescription, null);
377377

378-
result.Should().Be($"{{ find : \"{_collectionNamespace.CollectionName}\", projection : {json} }}");
378+
result.Should().Be($"{{ find : '{_collectionNamespace.CollectionName}', projection : {json} }}");
379379
}
380380

381381
[Test]
@@ -390,7 +390,7 @@ public void CreateCommand_should_return_expected_result_when_readConcern_is_prov
390390

391391
var result = reflector.CreateCommand(serverDescription, null);
392392

393-
result.Should().Be($"{{ find : \"{_collectionNamespace.CollectionName}\", readConcern : {value} }}");
393+
result.Should().Be($"{{ find : '{_collectionNamespace.CollectionName}', readConcern : {value} }}");
394394
}
395395

396396
[Test]
@@ -407,7 +407,7 @@ public void CreateCommand_should_return_expected_result_when_readPreference_is_p
407407

408408
var mode = value.ToString();
409409
var camelCaseMode = char.ToLower(mode[0]) + mode.Substring(1);
410-
result.Should().Be($"{{ find : \"{_collectionNamespace.CollectionName}\", readPreference : {{ mode : \"{camelCaseMode}\" }} }}");
410+
result.Should().Be($"{{ find : '{_collectionNamespace.CollectionName}', readPreference : {{ mode : '{camelCaseMode}' }} }}");
411411
}
412412

413413
[Test]
@@ -422,7 +422,7 @@ public void CreateCommand_should_return_expected_result_when_returnKey_is_provid
422422

423423
var result = reflector.CreateCommand(serverDescription, null);
424424

425-
result.Should().Be($"{{ find : \"{_collectionNamespace.CollectionName}\", returnKey : {(value ? "true" : "false")} }}");
425+
result.Should().Be($"{{ find : '{_collectionNamespace.CollectionName}', returnKey : {(value ? "true" : "false")} }}");
426426
}
427427

428428
[Test]
@@ -437,7 +437,7 @@ public void CreateCommand_should_return_expected_result_when_showRecordId_is_pro
437437

438438
var result = reflector.CreateCommand(serverDescription, null);
439439

440-
result.Should().Be($"{{ find : \"{_collectionNamespace.CollectionName}\", showRecordId : {(value ? "true" : "false")} }}");
440+
result.Should().Be($"{{ find : '{_collectionNamespace.CollectionName}', showRecordId : {(value ? "true" : "false")} }}");
441441
}
442442

443443
[Test]
@@ -452,7 +452,7 @@ public void CreateCommand_should_return_expected_result_when_singleBatch_is_prov
452452

453453
var result = reflector.CreateCommand(serverDescription, null);
454454

455-
result.Should().Be($"{{ find : \"{_collectionNamespace.CollectionName}\", singleBatch : {(value ? "true" : "false")} }}");
455+
result.Should().Be($"{{ find : '{_collectionNamespace.CollectionName}', singleBatch : {(value ? "true" : "false")} }}");
456456
}
457457

458458
[Test]
@@ -467,7 +467,7 @@ public void CreateCommand_should_return_expected_result_when_skip_is_provided(
467467

468468
var result = reflector.CreateCommand(serverDescription, null);
469469

470-
result.Should().Be($"{{ find : \"{_collectionNamespace.CollectionName}\", skip : {value} }}");
470+
result.Should().Be($"{{ find : '{_collectionNamespace.CollectionName}', skip : {value} }}");
471471
}
472472

473473
[Test]
@@ -482,7 +482,7 @@ public void CreateCommand_should_return_expected_result_when_snapshot_is_provide
482482

483483
var result = reflector.CreateCommand(serverDescription, null);
484484

485-
result.Should().Be($"{{ find : \"{_collectionNamespace.CollectionName}\", snapshot : {(value ? "true" : "false")} }}");
485+
result.Should().Be($"{{ find : '{_collectionNamespace.CollectionName}', snapshot : {(value ? "true" : "false")} }}");
486486
}
487487

488488
[Test]
@@ -497,7 +497,7 @@ public void CreateCommand_should_return_expected_result_when_sort_is_provided(
497497

498498
var result = reflector.CreateCommand(serverDescription, null);
499499

500-
result.Should().Be($"{{ find : \"{_collectionNamespace.CollectionName}\", sort : {json} }}");
500+
result.Should().Be($"{{ find : '{_collectionNamespace.CollectionName}', sort : {json} }}");
501501
}
502502

503503
[Test]
@@ -612,7 +612,7 @@ public void FirstBatchSize_set_should_throw_when_value_is_invalid(
612612

613613
[Test]
614614
public void Hint_get_and_set_should_work(
615-
[Values(null, "{ value : \"b_1\" }", "{ value : { b : 1 } }")]
615+
[Values(null, "{ value : 'b_1' }", "{ value : { b : 1 } }")]
616616
string json)
617617
{
618618
var subject = new FindCommandOperation<BsonDocument>(_collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings);

src/MongoDB.Driver.Core/Core/Operations/AsyncCursor.cs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ public class AsyncCursor<TDocument> : IAsyncCursor<TDocument>
5858
private readonly long? _operationId;
5959
private readonly BsonDocument _query;
6060
private readonly IBsonSerializer<TDocument> _serializer;
61-
private bool _slaveOk;
6261

6362
// constructors
6463
/// <summary>
@@ -74,7 +73,6 @@ public class AsyncCursor<TDocument> : IAsyncCursor<TDocument>
7473
/// <param name="serializer">The serializer.</param>
7574
/// <param name="messageEncoderSettings">The message encoder settings.</param>
7675
/// <param name="maxTime">The maxTime for each batch.</param>
77-
/// <param name="slaveOk">The slaveOk value (for getMore commands)</param>
7876
public AsyncCursor(
7977
IChannelSource channelSource,
8078
CollectionNamespace collectionNamespace,
@@ -85,8 +83,7 @@ public AsyncCursor(
8583
int? limit,
8684
IBsonSerializer<TDocument> serializer,
8785
MessageEncoderSettings messageEncoderSettings,
88-
TimeSpan? maxTime = null,
89-
bool slaveOk = false)
86+
TimeSpan? maxTime = null)
9087
{
9188
_operationId = EventContext.OperationId;
9289
_channelSource = channelSource;
@@ -99,7 +96,6 @@ public AsyncCursor(
9996
_serializer = Ensure.IsNotNull(serializer, nameof(serializer));
10097
_messageEncoderSettings = messageEncoderSettings;
10198
_maxTime = maxTime;
102-
_slaveOk = slaveOk;
10399

104100
if (_limit > 0 && _firstBatch.Count > _limit)
105101
{
@@ -156,21 +152,11 @@ private CursorBatch<TDocument> CreateCursorBatch(BsonDocument result)
156152

157153
private BsonDocument CreateGetMoreCommand()
158154
{
159-
var getMoreBatchSize = _batchSize;
160-
if (_limit > 0)
161-
{
162-
getMoreBatchSize = _limit.Value - _count;
163-
if (_batchSize > 0 && getMoreBatchSize.Value > _batchSize.Value)
164-
{
165-
getMoreBatchSize = _batchSize.Value;
166-
}
167-
}
168-
169155
var command = new BsonDocument
170156
{
171157
{ "getMore", _cursorId },
172158
{ "collection", _collectionNamespace.CollectionName },
173-
{ "batchSize", () => getMoreBatchSize.Value, getMoreBatchSize > 0 },
159+
{ "batchSize", () => _batchSize.Value, _batchSize > 0 },
174160
{ "maxTimeMS", () => _maxTime.Value.TotalMilliseconds, _maxTime.HasValue }
175161
};
176162

@@ -184,7 +170,7 @@ private CursorBatch<TDocument> ExecuteGetMoreCommand(IChannelHandle channel, Can
184170
_collectionNamespace.DatabaseNamespace,
185171
command,
186172
NoOpElementNameValidator.Instance,
187-
_slaveOk,
173+
false, // slaveOk
188174
__getMoreCommandResultSerializer,
189175
_messageEncoderSettings,
190176
cancellationToken);
@@ -199,7 +185,7 @@ private async Task<CursorBatch<TDocument>> ExecuteGetMoreCommandAsync(IChannelHa
199185
_collectionNamespace.DatabaseNamespace,
200186
command,
201187
NoOpElementNameValidator.Instance,
202-
_slaveOk,
188+
false, // slaveOk
203189
__getMoreCommandResultSerializer,
204190
_messageEncoderSettings,
205191
cancellationToken).ConfigureAwait(false);

src/MongoDB.Driver.Core/Core/Operations/FindCommandOperation.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,7 @@ private AsyncCursor<TDocument> CreateCursor(IChannelSourceHandle channelSource,
435435
_limit < 0 ? Math.Abs(_limit.Value) : _limit,
436436
_resultSerializer,
437437
_messageEncoderSettings,
438-
null, // maxTime
439-
slaveOk);
438+
null); // maxTime
440439
}
441440

442441
private CursorBatch<TDocument> CreateCursorBatch(BsonDocument result)

0 commit comments

Comments
 (0)