Skip to content

Commit 8339bc0

Browse files
CSHARP-3672: LB support integration testing. (#560)
CSHARP-3672: LB support integration testing.
1 parent 2b163f6 commit 8339bc0

39 files changed

+1275
-131
lines changed

src/MongoDB.Driver.Core/Core/Misc/Ensure.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,22 @@ public static T IsNotNull<T>(T value, string paramName) where T : class
224224
return value;
225225
}
226226

227+
/// <summary>
228+
/// Ensures that the value of a parameter is not null.
229+
/// </summary>
230+
/// <typeparam name="T">Type type of the value.</typeparam>
231+
/// <param name="value">The value of the parameter.</param>
232+
/// <param name="paramName">The name of the parameter.</param>
233+
/// <returns>The value of the parameter.</returns>
234+
public static Nullable<T> HasValue<T>(Nullable<T> value, string paramName) where T : struct
235+
{
236+
if (!value.HasValue)
237+
{
238+
throw new ArgumentException("The Nullable parameter must have a value.", paramName);
239+
}
240+
return value;
241+
}
242+
227243
/// <summary>
228244
/// Ensures that the value of a parameter is not null or empty.
229245
/// </summary>

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ namespace MongoDB.Driver.Core.Operations
3333
public class ListCollectionsOperation : IReadOperation<IAsyncCursor<BsonDocument>>
3434
{
3535
// fields
36+
private int? _batchSize;
3637
private BsonDocument _filter;
3738
private readonly DatabaseNamespace _databaseNamespace;
3839
private readonly MessageEncoderSettings _messageEncoderSettings;
@@ -54,6 +55,18 @@ public ListCollectionsOperation(
5455
}
5556

5657
// properties
58+
/// <summary>
59+
/// Gets or sets the batch size.
60+
/// </summary>
61+
/// <value>
62+
/// The batch size.
63+
/// </value>
64+
public int? BatchSize
65+
{
66+
get => _batchSize;
67+
set => _batchSize = value;
68+
}
69+
5770
/// <summary>
5871
/// Gets or sets the filter.
5972
/// </summary>
@@ -146,6 +159,7 @@ private IExecutableInRetryableReadContext<IAsyncCursor<BsonDocument>> CreateOper
146159
{
147160
return new ListCollectionsUsingCommandOperation(_databaseNamespace, _messageEncoderSettings)
148161
{
162+
BatchSize = _batchSize,
149163
Filter = _filter,
150164
NameOnly = _nameOnly,
151165
RetryRequested = _retryRequested // might be overridden by retryable read context
@@ -155,6 +169,7 @@ private IExecutableInRetryableReadContext<IAsyncCursor<BsonDocument>> CreateOper
155169
{
156170
return new ListCollectionsUsingQueryOperation(_databaseNamespace, _messageEncoderSettings)
157171
{
172+
BatchSize = _batchSize,
158173
Filter = _filter,
159174
RetryRequested = _retryRequested // might be overridden by retryable read context
160175
};

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ namespace MongoDB.Driver.Core.Operations
3131
public class ListCollectionsUsingCommandOperation : IReadOperation<IAsyncCursor<BsonDocument>>, IExecutableInRetryableReadContext<IAsyncCursor<BsonDocument>>
3232
{
3333
// fields
34+
private int? _batchSize;
3435
private BsonDocument _filter;
3536
private readonly DatabaseNamespace _databaseNamespace;
3637
private readonly MessageEncoderSettings _messageEncoderSettings;
@@ -52,6 +53,18 @@ public ListCollectionsUsingCommandOperation(
5253
}
5354

5455
// properties
56+
/// <summary>
57+
/// Gets or sets the batch size.
58+
/// </summary>
59+
/// <value>
60+
/// The batch size.
61+
/// </value>
62+
public int? BatchSize
63+
{
64+
get => _batchSize;
65+
set => _batchSize = value;
66+
}
67+
5568
/// <summary>
5669
/// Gets or sets the filter.
5770
/// </summary>
@@ -166,7 +179,8 @@ private ReadCommandOperation<BsonDocument> CreateOperation()
166179
{
167180
{ "listCollections", 1 },
168181
{ "filter", _filter, _filter != null },
169-
{ "nameOnly", () => _nameOnly.Value, _nameOnly.HasValue }
182+
{ "nameOnly", () => _nameOnly.Value, _nameOnly.HasValue },
183+
{ "cursor", () => new BsonDocument("batchSize", _batchSize.Value), _batchSize.HasValue }
170184
};
171185
return new ReadCommandOperation<BsonDocument>(_databaseNamespace, command, BsonDocumentSerializer.Instance, _messageEncoderSettings)
172186
{
@@ -184,7 +198,7 @@ private IAsyncCursor<BsonDocument> CreateCursor(IChannelSourceHandle channelSour
184198
command,
185199
cursorDocument["firstBatch"].AsBsonArray.OfType<BsonDocument>().ToList(),
186200
cursorDocument["id"].ToInt64(),
187-
0,
201+
batchSize: _batchSize ?? 0,
188202
0,
189203
BsonDocumentSerializer.Instance,
190204
_messageEncoderSettings);

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ namespace MongoDB.Driver.Core.Operations
3333
public class ListCollectionsUsingQueryOperation : IReadOperation<IAsyncCursor<BsonDocument>>, IExecutableInRetryableReadContext<IAsyncCursor<BsonDocument>>
3434
{
3535
// fields
36+
private int? _batchSize;
3637
private BsonDocument _filter;
3738
private readonly DatabaseNamespace _databaseNamespace;
3839
private readonly MessageEncoderSettings _messageEncoderSettings;
@@ -53,6 +54,18 @@ public ListCollectionsUsingQueryOperation(
5354
}
5455

5556
// properties
57+
/// <summary>
58+
/// Gets or sets the batch size.
59+
/// </summary>
60+
/// <value>
61+
/// The batch size.
62+
/// </value>
63+
public int? BatchSize
64+
{
65+
get => _batchSize;
66+
set => _batchSize = value;
67+
}
68+
5669
/// <summary>
5770
/// Gets or sets the filter.
5871
/// </summary>
@@ -166,6 +179,7 @@ private FindOperation<BsonDocument> CreateOperation()
166179

167180
return new FindOperation<BsonDocument>(_databaseNamespace.SystemNamespacesCollection, BsonDocumentSerializer.Instance, _messageEncoderSettings)
168181
{
182+
BatchSize = _batchSize,
169183
Filter = filter,
170184
RetryRequested = _retryRequested
171185
};

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ namespace MongoDB.Driver.Core.Operations
2929
public class ListIndexesOperation : IReadOperation<IAsyncCursor<BsonDocument>>
3030
{
3131
// fields
32+
private int? _batchSize;
3233
private readonly CollectionNamespace _collectionNamespace;
3334
private readonly MessageEncoderSettings _messageEncoderSettings;
3435
private bool _retryRequested;
@@ -48,6 +49,18 @@ public ListIndexesOperation(
4849
}
4950

5051
// properties
52+
/// <summary>
53+
/// Gets or sets the batch size.
54+
/// </summary>
55+
/// <value>
56+
/// The batch size.
57+
/// </value>
58+
public int? BatchSize
59+
{
60+
get => _batchSize;
61+
set => _batchSize = value;
62+
}
63+
5164
/// <summary>
5265
/// Gets the collection namespace.
5366
/// </summary>
@@ -116,12 +129,16 @@ private IExecutableInRetryableReadContext<IAsyncCursor<BsonDocument>> CreateOper
116129
{
117130
return new ListIndexesUsingCommandOperation(_collectionNamespace, _messageEncoderSettings)
118131
{
132+
BatchSize = _batchSize,
119133
RetryRequested = _retryRequested // might be overridden by retryable read context
120134
};
121135
}
122136
else
123137
{
124-
return new ListIndexesUsingQueryOperation(_collectionNamespace, _messageEncoderSettings);
138+
return new ListIndexesUsingQueryOperation(_collectionNamespace, _messageEncoderSettings)
139+
{
140+
BatchSize = _batchSize
141+
};
125142
}
126143
}
127144
}

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ namespace MongoDB.Driver.Core.Operations
3333
public class ListIndexesUsingCommandOperation : IReadOperation<IAsyncCursor<BsonDocument>>, IExecutableInRetryableReadContext<IAsyncCursor<BsonDocument>>
3434
{
3535
// fields
36+
private int? _batchSize;
3637
private readonly CollectionNamespace _collectionNamespace;
3738
private readonly MessageEncoderSettings _messageEncoderSettings;
3839
private bool _retryRequested;
@@ -52,6 +53,18 @@ public ListIndexesUsingCommandOperation(
5253
}
5354

5455
// properties
56+
/// <summary>
57+
/// Gets or sets the batch size.
58+
/// </summary>
59+
/// <value>
60+
/// The batch size.
61+
/// </value>
62+
public int? BatchSize
63+
{
64+
get => _batchSize;
65+
set => _batchSize = value;
66+
}
67+
5568
/// <summary>
5669
/// Gets the collection namespace.
5770
/// </summary>
@@ -153,7 +166,11 @@ public async Task<IAsyncCursor<BsonDocument>> ExecuteAsync(RetryableReadContext
153166
private ReadCommandOperation<BsonDocument> CreateOperation()
154167
{
155168
var databaseNamespace = _collectionNamespace.DatabaseNamespace;
156-
var command = new BsonDocument("listIndexes", _collectionNamespace.CollectionName);
169+
var command = new BsonDocument
170+
{
171+
{ "listIndexes", _collectionNamespace.CollectionName },
172+
{ "cursor", () => new BsonDocument("batchSize", _batchSize.Value), _batchSize.HasValue }
173+
};
157174
return new ReadCommandOperation<BsonDocument>(databaseNamespace, command, BsonDocumentSerializer.Instance, _messageEncoderSettings)
158175
{
159176
RetryRequested = _retryRequested // might be overridden by retryable read context
@@ -170,7 +187,7 @@ private IAsyncCursor<BsonDocument> CreateCursor(IChannelSourceHandle channelSour
170187
command,
171188
cursorDocument["firstBatch"].AsBsonArray.OfType<BsonDocument>().ToList(),
172189
cursorDocument["id"].ToInt64(),
173-
0,
190+
batchSize: _batchSize ?? 0,
174191
0,
175192
BsonDocumentSerializer.Instance,
176193
_messageEncoderSettings);

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
* limitations under the License.
1414
*/
1515

16-
using System;
17-
using System.Collections.Generic;
18-
using System.Linq;
1916
using System.Threading;
2017
using System.Threading.Tasks;
2118
using MongoDB.Bson;
@@ -32,6 +29,7 @@ namespace MongoDB.Driver.Core.Operations
3229
public class ListIndexesUsingQueryOperation : IReadOperation<IAsyncCursor<BsonDocument>>, IExecutableInRetryableReadContext<IAsyncCursor<BsonDocument>>
3330
{
3431
// fields
32+
private int? _batchSize;
3533
private readonly CollectionNamespace _collectionNamespace;
3634
private readonly MessageEncoderSettings _messageEncoderSettings;
3735

@@ -50,6 +48,18 @@ public ListIndexesUsingQueryOperation(
5048
}
5149

5250
// properties
51+
/// <summary>
52+
/// Gets or sets the batch size.
53+
/// </summary>
54+
/// <value>
55+
/// The batch size.
56+
/// </value>
57+
public int? BatchSize
58+
{
59+
get => _batchSize;
60+
set => _batchSize = value;
61+
}
62+
5363
/// <summary>
5464
/// Gets the collection namespace.
5565
/// </summary>
@@ -120,6 +130,7 @@ private FindOperation<BsonDocument> CreateOperation()
120130
var filter = new BsonDocument("ns", _collectionNamespace.FullName);
121131
return new FindOperation<BsonDocument>(systemIndexesCollection, BsonDocumentSerializer.Instance, _messageEncoderSettings)
122132
{
133+
BatchSize = _batchSize,
123134
Filter = filter,
124135
RetryRequested = false
125136
};

src/MongoDB.Driver/IMongoIndexManager.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,14 @@ Task<string> CreateOneAsync(
405405
/// <returns>A cursor.</returns>
406406
IAsyncCursor<BsonDocument> List(CancellationToken cancellationToken = default(CancellationToken));
407407

408+
/// <summary>
409+
/// Lists the indexes.
410+
/// </summary>
411+
/// <param name="options">The options.</param>
412+
/// <param name="cancellationToken">The cancellation token.</param>
413+
/// <returns>A cursor.</returns>
414+
IAsyncCursor<BsonDocument> List(ListIndexesOptions options, CancellationToken cancellationToken = default(CancellationToken));
415+
408416
/// <summary>
409417
/// Lists the indexes.
410418
/// </summary>
@@ -415,13 +423,32 @@ Task<string> CreateOneAsync(
415423
/// </returns>
416424
IAsyncCursor<BsonDocument> List(IClientSessionHandle session, CancellationToken cancellationToken = default(CancellationToken));
417425

426+
/// <summary>
427+
/// Lists the indexes.
428+
/// </summary>
429+
/// <param name="session">The session.</param>
430+
/// <param name="options">The options.</param>
431+
/// <param name="cancellationToken">The cancellation token.</param>
432+
/// <returns>
433+
/// A cursor.
434+
/// </returns>
435+
IAsyncCursor<BsonDocument> List(IClientSessionHandle session, ListIndexesOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
436+
418437
/// <summary>
419438
/// Lists the indexes.
420439
/// </summary>
421440
/// <param name="cancellationToken">The cancellation token.</param>
422441
/// <returns>A Task whose result is a cursor.</returns>
423442
Task<IAsyncCursor<BsonDocument>> ListAsync(CancellationToken cancellationToken = default(CancellationToken));
424443

444+
/// <summary>
445+
/// Lists the indexes.
446+
/// </summary>
447+
/// <param name="options">The options.</param>
448+
/// <param name="cancellationToken">The cancellation token.</param>
449+
/// <returns>A Task whose result is a cursor.</returns>
450+
Task<IAsyncCursor<BsonDocument>> ListAsync(ListIndexesOptions options, CancellationToken cancellationToken = default(CancellationToken));
451+
425452
/// <summary>
426453
/// Lists the indexes.
427454
/// </summary>
@@ -431,5 +458,16 @@ Task<string> CreateOneAsync(
431458
/// A Task whose result is a cursor.
432459
/// </returns>
433460
Task<IAsyncCursor<BsonDocument>> ListAsync(IClientSessionHandle session, CancellationToken cancellationToken = default(CancellationToken));
461+
462+
/// <summary>
463+
/// Lists the indexes.
464+
/// </summary>
465+
/// <param name="session">The session.</param>
466+
/// <param name="options">The options.</param>
467+
/// <param name="cancellationToken">The cancellation token.</param>
468+
/// <returns>
469+
/// A Task whose result is a cursor.
470+
/// </returns>
471+
Task<IAsyncCursor<BsonDocument>> ListAsync(IClientSessionHandle session, ListIndexesOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
434472
}
435473
}

src/MongoDB.Driver/ListCollectionsOptions.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515

1616
using MongoDB.Bson;
17+
1718
namespace MongoDB.Driver
1819
{
1920
/// <summary>
@@ -22,9 +23,19 @@ namespace MongoDB.Driver
2223
public sealed class ListCollectionsOptions
2324
{
2425
// fields
26+
private int? _batchSize;
2527
private FilterDefinition<BsonDocument> _filter;
2628

2729
// properties
30+
/// <summary>
31+
/// Gets or sets the batch size.
32+
/// </summary>
33+
public int? BatchSize
34+
{
35+
get { return _batchSize; }
36+
set { _batchSize = value; }
37+
}
38+
2839
/// <summary>
2940
/// Gets or sets the filter.
3041
/// </summary>

0 commit comments

Comments
 (0)