Skip to content

Commit

Permalink
Add the ability to mock BatchGet and MultiTableBatchGet operations (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
96malhar authored Aug 6, 2024
1 parent ad8c25d commit 96b5be0
Show file tree
Hide file tree
Showing 10 changed files with 384 additions and 293 deletions.
305 changes: 141 additions & 164 deletions sdk/src/Services/DynamoDBv2/Custom/DataModel/BatchGet.cs

Large diffs are not rendered by default.

38 changes: 8 additions & 30 deletions sdk/src/Services/DynamoDBv2/Custom/DataModel/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,50 +209,28 @@ public void Dispose()

#region BatchGet

/// <summary>
/// Creates a strongly-typed BatchGet object, allowing
/// a batch-get operation against DynamoDB.
/// </summary>
/// <typeparam name="T">Type of objects to get</typeparam>
/// <returns>Empty strongly-typed BatchGet object</returns>
public BatchGet<T> CreateBatchGet<T>()
/// <inheritdoc/>
public IBatchGet<T> CreateBatchGet<T>()
{
return CreateBatchGet<T>((BatchGetConfig)null);
}

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

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

/// <summary>
/// Creates a MultiTableBatchGet object, composed of multiple
/// individual BatchGet objects.
/// </summary>
/// <param name="batches">Individual BatchGet objects</param>
/// <returns>Composite MultiTableBatchGet object</returns>
public MultiTableBatchGet CreateMultiTableBatchGet(params BatchGet[] batches)
/// <inheritdoc/>
public IMultiTableBatchGet CreateMultiTableBatchGet(params IBatchGet[] batches)
{
return new MultiTableBatchGet(batches);
}
Expand Down
15 changes: 7 additions & 8 deletions sdk/src/Services/DynamoDBv2/Custom/DataModel/IDynamoDBContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
using System.Collections.Generic;

using Amazon.DynamoDBv2.DocumentModel;
using Amazon.DynamoDBv2.Model;

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

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

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

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

#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,60 +14,55 @@
*/
#pragma warning disable 1574

using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using Amazon.DynamoDBv2.Model;
using Amazon.DynamoDBv2.DocumentModel;
using System.Threading;
using System.Threading.Tasks;
using Amazon.Runtime.Internal;

namespace Amazon.DynamoDBv2.DataModel
{
/// <summary>
/// Represents a non-generic object for retrieving a batch of items
/// from a single DynamoDB table
/// </summary>
public abstract partial class BatchGet
public partial interface IBatchGet
{
#region Public methods

/// <summary>
/// Executes a server call to batch-get the items requested.
/// </summary>
/// <param name="cancellationToken">Token which can be used to cancel the task.</param>
///
/// <returns>A Task that can be used to poll or wait for results, or both.</returns>
public Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken))
Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken));
}

public abstract partial class BatchGet
{
/// <inheritdoc/>
public abstract Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken));
}

public partial class BatchGet<T> : BatchGet, IBatchGet<T>
{
/// <inheritdoc/>
public override Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken))
{
return ExecuteHelperAsync(cancellationToken);
}

#endregion
}

/// <summary>
/// Class for retrieving a batch of items from multiple DynamoDB tables,
/// using multiple strongly-typed BatchGet objects
/// </summary>
public partial class MultiTableBatchGet
public partial interface IMultiTableBatchGet
{
#region Public methods

/// <summary>
/// Executes a multi-table batch request against all configured batches.
/// Results are stored in the respective BatchGet objects.
/// </summary>
/// <param name="cancellationToken">Token which can be used to cancel the task.</param>
///
/// <returns>A Task that can be used to poll or wait for results, or both.</returns>
Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken));
}

public partial class MultiTableBatchGet : IMultiTableBatchGet
{
/// <inheritdoc/>
public Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken))
{
return ExecuteHelperAsync(cancellationToken);
}

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Amazon.DynamoDBv2.DocumentModel;
using Amazon.DynamoDBv2.Model;
using Amazon.Runtime.Internal;

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

#region BatchGet async

/// <summary>
/// Issues a batch-get request with multiple batches.
///
/// Results are stored in the individual batches.
/// </summary>
/// <param name="batches">
/// Configured BatchGet objects
/// </param>
public Task ExecuteBatchGetAsync(params BatchGet[] batches)
/// <inheritdoc/>
public Task ExecuteBatchGetAsync(params IBatchGet[] batches)
{
return ExecuteBatchGetAsync(batches, default(CancellationToken));
}

/// <summary>
/// Issues a batch-get request with multiple batches.
///
/// Results are stored in the individual batches.
/// </summary>
/// <param name="batches">
/// Configured BatchGet objects
/// </param>
/// <param name="cancellationToken">
/// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
/// </param>
public Task ExecuteBatchGetAsync(BatchGet[] batches, CancellationToken cancellationToken = default(CancellationToken))
/// <inheritdoc/>
public Task ExecuteBatchGetAsync(IBatchGet[] batches, CancellationToken cancellationToken = default(CancellationToken))
{
MultiTableBatchGet superBatch = new MultiTableBatchGet(batches);
return superBatch.ExecuteAsync(cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,17 @@ partial interface IDynamoDBContext

#region BatchGet async

/// <summary>
/// Issues a batch-get request with multiple batches.
///
/// Results are stored in the individual batches.
/// </summary>
/// <param name="batches">
/// Configured BatchGet objects
/// </param>
/// <returns>A Task that can be used to poll or wait for results, or both.</returns>
Task ExecuteBatchGetAsync(params IBatchGet[] batches);

/// <summary>
/// Issues a batch-get request with multiple batches.
///
Expand All @@ -397,7 +408,7 @@ partial interface IDynamoDBContext
/// </param>
/// <param name="cancellationToken">Token which can be used to cancel the task.</param>
/// <returns>A Task that can be used to poll or wait for results, or both.</returns>
Task ExecuteBatchGetAsync(BatchGet[] batches, CancellationToken cancellationToken = default(CancellationToken));
Task ExecuteBatchGetAsync(IBatchGet[] batches, CancellationToken cancellationToken = default(CancellationToken));

#endregion

Expand Down
47 changes: 21 additions & 26 deletions sdk/src/Services/DynamoDBv2/Custom/DataModel/_bcl/BatchGet.Sync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,51 +13,46 @@
* permissions and limitations under the License.
*/

using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using Amazon.DynamoDBv2.Model;
using Amazon.DynamoDBv2.DocumentModel;

namespace Amazon.DynamoDBv2.DataModel
{
/// <summary>
/// Represents a non-generic object for retrieving a batch of items
/// from a single DynamoDB table
/// </summary>
public abstract partial class BatchGet
public partial interface IBatchGet
{
#region Public methods

/// <summary>
/// Executes a server call to batch-get the items requested.
/// </summary>
public void Execute()
void Execute();
}

public abstract partial class BatchGet
{
/// <inheritdoc/>
public abstract void Execute();
}

public partial class BatchGet<T> : BatchGet, IBatchGet<T>
{
/// <inheritdoc/>
public override void Execute()
{
ExecuteHelper();
}

#endregion
}

/// <summary>
/// Class for retrieving a batch of items from multiple DynamoDB tables,
/// using multiple strongly-typed BatchGet objects
/// </summary>
public partial class MultiTableBatchGet
public partial interface IMultiTableBatchGet
{
#region Public methods

/// <summary>
/// Executes a multi-table batch request against all configured batches.
/// Results are stored in the respective BatchGet objects.
/// </summary>
void Execute();
}

public partial class MultiTableBatchGet : IMultiTableBatchGet
{
/// <inheritdoc/>/>
public void Execute()
{
ExecuteHelper();
}

#endregion
}
}
13 changes: 2 additions & 11 deletions sdk/src/Services/DynamoDBv2/Custom/DataModel/_bcl/Context.Sync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@

using System;
using System.Collections.Generic;
using System.Linq;

using Amazon.DynamoDBv2.DocumentModel;
using Amazon.DynamoDBv2.Model;

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

#region BatchGet
/// <summary>
/// Issues a batch-get request with multiple batches.
///
/// Results are stored in the individual batches.
/// </summary>
/// <param name="batches">
/// Configured BatchGet objects
/// </param>
public void ExecuteBatchGet(params BatchGet[] batches)
/// <inheritdoc/>
public void ExecuteBatchGet(params IBatchGet[] batches)
{
MultiTableBatchGet superBatch = new MultiTableBatchGet(batches);
superBatch.Execute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
* permissions and limitations under the License.
*/

using System;
using System.Collections.Generic;

using Amazon.DynamoDBv2.DocumentModel;
using Amazon.DynamoDBv2.Model;

namespace Amazon.DynamoDBv2.DataModel
{
Expand Down Expand Up @@ -341,7 +339,7 @@ partial interface IDynamoDBContext
/// <param name="batches">
/// Configured BatchGet objects
/// </param>
void ExecuteBatchGet(params BatchGet[] batches);
void ExecuteBatchGet(params IBatchGet[] batches);

#endregion

Expand Down
Loading

0 comments on commit 96b5be0

Please sign in to comment.