Skip to content

Commit b0a2bdc

Browse files
committed
Add the ability to mock BatchGet and MultiTableBatchGet operations (#3407)
1 parent c4e2519 commit b0a2bdc

File tree

10 files changed

+384
-293
lines changed

10 files changed

+384
-293
lines changed

sdk/src/Services/DynamoDBv2/Custom/DataModel/BatchGet.cs

Lines changed: 141 additions & 164 deletions
Large diffs are not rendered by default.

sdk/src/Services/DynamoDBv2/Custom/DataModel/Context.cs

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -209,50 +209,28 @@ public void Dispose()
209209

210210
#region BatchGet
211211

212-
/// <summary>
213-
/// Creates a strongly-typed BatchGet object, allowing
214-
/// a batch-get operation against DynamoDB.
215-
/// </summary>
216-
/// <typeparam name="T">Type of objects to get</typeparam>
217-
/// <returns>Empty strongly-typed BatchGet object</returns>
218-
public BatchGet<T> CreateBatchGet<T>()
212+
/// <inheritdoc/>
213+
public IBatchGet<T> CreateBatchGet<T>()
219214
{
220215
return CreateBatchGet<T>((BatchGetConfig)null);
221216
}
222217

223-
/// <summary>
224-
/// Creates a strongly-typed BatchGet object, allowing
225-
/// a batch-get operation against DynamoDB.
226-
/// </summary>
227-
/// <typeparam name="T">Type of objects to get</typeparam>
228-
/// <param name="operationConfig">Config object which can be used to override that table used.</param>
229-
/// <returns>Empty strongly-typed BatchGet object</returns>
218+
/// <inheritdoc/>
230219
[Obsolete("Use the CreateBatchGet overload that takes BatchGetConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to BatchGet.")]
231-
public BatchGet<T> CreateBatchGet<T>(DynamoDBOperationConfig operationConfig)
220+
public IBatchGet<T> CreateBatchGet<T>(DynamoDBOperationConfig operationConfig)
232221
{
233222
DynamoDBFlatConfig config = new DynamoDBFlatConfig(operationConfig, this.Config);
234223
return new BatchGet<T>(this, config);
235224
}
236225

237-
/// <summary>
238-
/// Creates a strongly-typed BatchGet object, allowing
239-
/// a batch-get operation against DynamoDB.
240-
/// </summary>
241-
/// <typeparam name="T">Type of objects to get</typeparam>
242-
/// <param name="batchGetConfig">Config object that can be used to override properties on the table's context for this request</param>
243-
/// <returns>Empty strongly-typed BatchGet object</returns>
244-
public BatchGet<T> CreateBatchGet<T>(BatchGetConfig batchGetConfig)
226+
/// <inheritdoc/>
227+
public IBatchGet<T> CreateBatchGet<T>(BatchGetConfig batchGetConfig)
245228
{
246229
return new BatchGet<T>(this, new DynamoDBFlatConfig(batchGetConfig?.ToDynamoDBOperationConfig(), Config));
247230
}
248231

249-
/// <summary>
250-
/// Creates a MultiTableBatchGet object, composed of multiple
251-
/// individual BatchGet objects.
252-
/// </summary>
253-
/// <param name="batches">Individual BatchGet objects</param>
254-
/// <returns>Composite MultiTableBatchGet object</returns>
255-
public MultiTableBatchGet CreateMultiTableBatchGet(params BatchGet[] batches)
232+
/// <inheritdoc/>
233+
public IMultiTableBatchGet CreateMultiTableBatchGet(params IBatchGet[] batches)
256234
{
257235
return new MultiTableBatchGet(batches);
258236
}

sdk/src/Services/DynamoDBv2/Custom/DataModel/IDynamoDBContext.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
using System.Collections.Generic;
1818

1919
using Amazon.DynamoDBv2.DocumentModel;
20-
using Amazon.DynamoDBv2.Model;
2120

2221
namespace Amazon.DynamoDBv2.DataModel
2322
{
@@ -154,34 +153,34 @@ public partial interface IDynamoDBContext : IDisposable
154153
/// </summary>
155154
/// <typeparam name="T">Type of objects to get</typeparam>
156155
/// <returns>Empty strongly-typed BatchGet object</returns>
157-
BatchGet<T> CreateBatchGet<T>();
156+
IBatchGet<T> CreateBatchGet<T>();
158157

159158
/// <summary>
160159
/// Creates a strongly-typed BatchGet object, allowing
161160
/// a batch-get operation against DynamoDB.
162161
/// </summary>
163162
/// <typeparam name="T">Type of objects to get</typeparam>
164163
/// <param name="operationConfig">Config object which can be used to override that table used.</param>
165-
/// <returns>Empty strongly-typed BatchGet object</returns>
164+
/// <returns>A BatchGet object using this context's configuration, which can be used to prepare and execute a BatchGet request</returns>
166165
[Obsolete("Use the CreateBatchGet overload that takes BatchGetConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to BatchGet.")]
167-
BatchGet<T> CreateBatchGet<T>(DynamoDBOperationConfig operationConfig = null);
166+
IBatchGet<T> CreateBatchGet<T>(DynamoDBOperationConfig operationConfig = null);
168167

169168
/// <summary>
170169
/// Creates a strongly-typed BatchGet object, allowing
171170
/// a batch-get operation against DynamoDB.
172171
/// </summary>
173172
/// <typeparam name="T">Type of objects to get</typeparam>
174173
/// <param name="batchGetConfig">Config object that can be used to override properties on the table's context for this request</param>
175-
/// <returns>Empty strongly-typed BatchGet object</returns>
176-
public BatchGet<T> CreateBatchGet<T>(BatchGetConfig batchGetConfig);
174+
/// <returns>A BatchGet object based on the provided <see cref="BatchGetConfig"/>, which can be used to prepare and execute a BatchGet request</returns>
175+
IBatchGet<T> CreateBatchGet<T>(BatchGetConfig batchGetConfig);
177176

178177
/// <summary>
179178
/// Creates a MultiTableBatchGet object, composed of multiple
180179
/// individual BatchGet objects.
181180
/// </summary>
182181
/// <param name="batches">Individual BatchGet objects</param>
183-
/// <returns>Composite MultiTableBatchGet object</returns>
184-
MultiTableBatchGet CreateMultiTableBatchGet(params BatchGet[] batches);
182+
/// <returns>A MultiTableBatchGet object using this context's configuration, which can be used to prepare and execute a MultiTableBatchGet request</returns>
183+
IMultiTableBatchGet CreateMultiTableBatchGet(params IBatchGet[] batches);
185184

186185
#endregion
187186

sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/BatchGet.Async.cs

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,60 +14,55 @@
1414
*/
1515
#pragma warning disable 1574
1616

17-
using System;
18-
using System.Collections;
19-
using System.Collections.Generic;
20-
using System.Reflection;
21-
using Amazon.DynamoDBv2.Model;
22-
using Amazon.DynamoDBv2.DocumentModel;
2317
using System.Threading;
2418
using System.Threading.Tasks;
25-
using Amazon.Runtime.Internal;
2619

2720
namespace Amazon.DynamoDBv2.DataModel
2821
{
29-
/// <summary>
30-
/// Represents a non-generic object for retrieving a batch of items
31-
/// from a single DynamoDB table
32-
/// </summary>
33-
public abstract partial class BatchGet
22+
public partial interface IBatchGet
3423
{
35-
#region Public methods
36-
3724
/// <summary>
3825
/// Executes a server call to batch-get the items requested.
3926
/// </summary>
4027
/// <param name="cancellationToken">Token which can be used to cancel the task.</param>
4128
///
4229
/// <returns>A Task that can be used to poll or wait for results, or both.</returns>
43-
public Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken))
30+
Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken));
31+
}
32+
33+
public abstract partial class BatchGet
34+
{
35+
/// <inheritdoc/>
36+
public abstract Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken));
37+
}
38+
39+
public partial class BatchGet<T> : BatchGet, IBatchGet<T>
40+
{
41+
/// <inheritdoc/>
42+
public override Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken))
4443
{
4544
return ExecuteHelperAsync(cancellationToken);
4645
}
47-
48-
#endregion
4946
}
5047

51-
/// <summary>
52-
/// Class for retrieving a batch of items from multiple DynamoDB tables,
53-
/// using multiple strongly-typed BatchGet objects
54-
/// </summary>
55-
public partial class MultiTableBatchGet
48+
public partial interface IMultiTableBatchGet
5649
{
57-
#region Public methods
58-
5950
/// <summary>
6051
/// Executes a multi-table batch request against all configured batches.
6152
/// Results are stored in the respective BatchGet objects.
6253
/// </summary>
6354
/// <param name="cancellationToken">Token which can be used to cancel the task.</param>
6455
///
6556
/// <returns>A Task that can be used to poll or wait for results, or both.</returns>
57+
Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken));
58+
}
59+
60+
public partial class MultiTableBatchGet : IMultiTableBatchGet
61+
{
62+
/// <inheritdoc/>
6663
public Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken))
6764
{
6865
return ExecuteHelperAsync(cancellationToken);
6966
}
70-
71-
#endregion
7267
}
7368
}

sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/Context.Async.cs

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@
1616

1717
using System;
1818
using System.Collections.Generic;
19-
using System.Linq;
2019
using System.Threading;
2120
using System.Threading.Tasks;
2221
using Amazon.DynamoDBv2.DocumentModel;
23-
using Amazon.DynamoDBv2.Model;
24-
using Amazon.Runtime.Internal;
2522

2623
namespace Amazon.DynamoDBv2.DataModel
2724
{
@@ -197,31 +194,14 @@ public Task DeleteAsync<T>(object hashKey, object rangeKey, DeleteConfig deleteC
197194

198195
#region BatchGet async
199196

200-
/// <summary>
201-
/// Issues a batch-get request with multiple batches.
202-
///
203-
/// Results are stored in the individual batches.
204-
/// </summary>
205-
/// <param name="batches">
206-
/// Configured BatchGet objects
207-
/// </param>
208-
public Task ExecuteBatchGetAsync(params BatchGet[] batches)
197+
/// <inheritdoc/>
198+
public Task ExecuteBatchGetAsync(params IBatchGet[] batches)
209199
{
210200
return ExecuteBatchGetAsync(batches, default(CancellationToken));
211201
}
212202

213-
/// <summary>
214-
/// Issues a batch-get request with multiple batches.
215-
///
216-
/// Results are stored in the individual batches.
217-
/// </summary>
218-
/// <param name="batches">
219-
/// Configured BatchGet objects
220-
/// </param>
221-
/// <param name="cancellationToken">
222-
/// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
223-
/// </param>
224-
public Task ExecuteBatchGetAsync(BatchGet[] batches, CancellationToken cancellationToken = default(CancellationToken))
203+
/// <inheritdoc/>
204+
public Task ExecuteBatchGetAsync(IBatchGet[] batches, CancellationToken cancellationToken = default(CancellationToken))
225205
{
226206
MultiTableBatchGet superBatch = new MultiTableBatchGet(batches);
227207
return superBatch.ExecuteAsync(cancellationToken);

sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/IDynamoDBContext.Async.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,17 @@ partial interface IDynamoDBContext
407407

408408
#region BatchGet async
409409

410+
/// <summary>
411+
/// Issues a batch-get request with multiple batches.
412+
///
413+
/// Results are stored in the individual batches.
414+
/// </summary>
415+
/// <param name="batches">
416+
/// Configured BatchGet objects
417+
/// </param>
418+
/// <returns>A Task that can be used to poll or wait for results, or both.</returns>
419+
Task ExecuteBatchGetAsync(params IBatchGet[] batches);
420+
410421
/// <summary>
411422
/// Issues a batch-get request with multiple batches.
412423
///
@@ -417,7 +428,7 @@ partial interface IDynamoDBContext
417428
/// </param>
418429
/// <param name="cancellationToken">Token which can be used to cancel the task.</param>
419430
/// <returns>A Task that can be used to poll or wait for results, or both.</returns>
420-
Task ExecuteBatchGetAsync(BatchGet[] batches, CancellationToken cancellationToken = default(CancellationToken));
431+
Task ExecuteBatchGetAsync(IBatchGet[] batches, CancellationToken cancellationToken = default(CancellationToken));
421432

422433
#endregion
423434

sdk/src/Services/DynamoDBv2/Custom/DataModel/_bcl/BatchGet.Sync.cs

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,51 +13,46 @@
1313
* permissions and limitations under the License.
1414
*/
1515

16-
using System;
17-
using System.Collections;
18-
using System.Collections.Generic;
19-
using System.Reflection;
20-
using Amazon.DynamoDBv2.Model;
21-
using Amazon.DynamoDBv2.DocumentModel;
22-
2316
namespace Amazon.DynamoDBv2.DataModel
2417
{
25-
/// <summary>
26-
/// Represents a non-generic object for retrieving a batch of items
27-
/// from a single DynamoDB table
28-
/// </summary>
29-
public abstract partial class BatchGet
18+
public partial interface IBatchGet
3019
{
31-
#region Public methods
32-
3320
/// <summary>
3421
/// Executes a server call to batch-get the items requested.
3522
/// </summary>
36-
public void Execute()
23+
void Execute();
24+
}
25+
26+
public abstract partial class BatchGet
27+
{
28+
/// <inheritdoc/>
29+
public abstract void Execute();
30+
}
31+
32+
public partial class BatchGet<T> : BatchGet, IBatchGet<T>
33+
{
34+
/// <inheritdoc/>
35+
public override void Execute()
3736
{
3837
ExecuteHelper();
3938
}
40-
41-
#endregion
4239
}
4340

44-
/// <summary>
45-
/// Class for retrieving a batch of items from multiple DynamoDB tables,
46-
/// using multiple strongly-typed BatchGet objects
47-
/// </summary>
48-
public partial class MultiTableBatchGet
41+
public partial interface IMultiTableBatchGet
4942
{
50-
#region Public methods
51-
5243
/// <summary>
5344
/// Executes a multi-table batch request against all configured batches.
5445
/// Results are stored in the respective BatchGet objects.
5546
/// </summary>
47+
void Execute();
48+
}
49+
50+
public partial class MultiTableBatchGet : IMultiTableBatchGet
51+
{
52+
/// <inheritdoc/>/>
5653
public void Execute()
5754
{
5855
ExecuteHelper();
5956
}
60-
61-
#endregion
6257
}
6358
}

sdk/src/Services/DynamoDBv2/Custom/DataModel/_bcl/Context.Sync.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@
1515

1616
using System;
1717
using System.Collections.Generic;
18-
using System.Linq;
1918

2019
using Amazon.DynamoDBv2.DocumentModel;
21-
using Amazon.DynamoDBv2.Model;
2220

2321
namespace Amazon.DynamoDBv2.DataModel
2422
{
@@ -171,15 +169,8 @@ public void Delete<T>(object hashKey, object rangeKey, DeleteConfig deleteConfig
171169
#endregion
172170

173171
#region BatchGet
174-
/// <summary>
175-
/// Issues a batch-get request with multiple batches.
176-
///
177-
/// Results are stored in the individual batches.
178-
/// </summary>
179-
/// <param name="batches">
180-
/// Configured BatchGet objects
181-
/// </param>
182-
public void ExecuteBatchGet(params BatchGet[] batches)
172+
/// <inheritdoc/>
173+
public void ExecuteBatchGet(params IBatchGet[] batches)
183174
{
184175
MultiTableBatchGet superBatch = new MultiTableBatchGet(batches);
185176
superBatch.Execute();

sdk/src/Services/DynamoDBv2/Custom/DataModel/_bcl/IDynamoDBContext.Sync.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313
* permissions and limitations under the License.
1414
*/
1515

16-
using System;
1716
using System.Collections.Generic;
1817

1918
using Amazon.DynamoDBv2.DocumentModel;
20-
using Amazon.DynamoDBv2.Model;
2119

2220
namespace Amazon.DynamoDBv2.DataModel
2321
{
@@ -364,7 +362,7 @@ partial interface IDynamoDBContext
364362
/// <param name="batches">
365363
/// Configured BatchGet objects
366364
/// </param>
367-
void ExecuteBatchGet(params BatchGet[] batches);
365+
void ExecuteBatchGet(params IBatchGet[] batches);
368366

369367
#endregion
370368

0 commit comments

Comments
 (0)