-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Transfermanager public constructor calls DI * testing and minor changes move delegate out of class for easier typing. privatize some fields testing transfer manager item transfer with mocked dependencies. * container test * usings * rename test * address nitpicks * fix
- Loading branch information
1 parent
f328c76
commit 70567f2
Showing
7 changed files
with
557 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
sdk/storage/Azure.Storage.DataMovement/tests/Models/StepProcessor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Azure.Storage.DataMovement.Tests | ||
{ | ||
/// <summary> | ||
/// Processor that only processes items one by one from | ||
/// its queue only when invoked for each item. | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
internal class StepProcessor<T> : IProcessor<T> | ||
{ | ||
private readonly Queue<T> _queue = new(); | ||
|
||
public int ItemsInQueue => _queue.Count; | ||
|
||
/// <inheritdoc/> | ||
public ProcessAsync<T> Process { get; set; } | ||
|
||
/// <inheritdoc/> | ||
public ValueTask QueueAsync(T item, CancellationToken cancellationToken = default) | ||
{ | ||
_queue.Enqueue(item); | ||
return new(Task.CompletedTask); | ||
} | ||
|
||
/// <summary> | ||
/// Attmpts to read an item from internal queue, then completes | ||
/// a call to <see cref="Process"/> on it. | ||
/// </summary> | ||
/// <returns> | ||
/// Whether or not an item was successfully read from the queue. | ||
/// </returns> | ||
public async ValueTask<bool> TryStepAsync(CancellationToken cancellationToken = default) | ||
{ | ||
if (_queue.Count > 0) | ||
{ | ||
await Process?.Invoke(_queue.Dequeue(), cancellationToken); | ||
return true; | ||
} | ||
else | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
public async ValueTask<int> StepMany(int maxSteps, CancellationToken cancellationToken = default) | ||
{ | ||
int steps = 0; | ||
while (steps < maxSteps && await TryStepAsync(cancellationToken)) | ||
{ | ||
steps++; | ||
} | ||
return steps; | ||
} | ||
|
||
public async ValueTask<int> StepAll(CancellationToken cancellationToken = default) | ||
{ | ||
int steps = 0; | ||
while (await TryStepAsync(cancellationToken)) | ||
{ | ||
steps++; | ||
} | ||
return steps; | ||
} | ||
|
||
public void Dispose() | ||
{ } | ||
} | ||
} |
Oops, something went wrong.