Skip to content

Commit 7aba53b

Browse files
TryPause -> PauseIfRunning (Azure#36246)
* TryPause -> PauseIfRunning * exportapi
1 parent 7996ad1 commit 7aba53b

File tree

9 files changed

+40
-53
lines changed

9 files changed

+40
-53
lines changed

sdk/storage/Azure.Storage.DataMovement/api/Azure.Storage.DataMovement.net6.0.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ internal DataTransfer() { }
88
public Azure.Storage.DataMovement.StorageTransferStatus TransferStatus { get { throw null; } }
99
public System.Threading.Tasks.Task AwaitCompletion(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
1010
public void EnsureCompleted(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { }
11-
public System.Threading.Tasks.Task<bool> TryPauseAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
11+
public System.Threading.Tasks.Task PauseIfRunningAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
1212
}
1313
[System.FlagsAttribute]
1414
public enum ErrorHandlingOptions
@@ -117,11 +117,11 @@ public partial class TransferManager : System.IAsyncDisposable
117117
{
118118
protected TransferManager() { }
119119
public TransferManager(Azure.Storage.DataMovement.TransferManagerOptions options = null) { }
120+
public virtual System.Threading.Tasks.Task PauseTransferIfRunningAsync(Azure.Storage.DataMovement.DataTransfer transfer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
121+
public virtual System.Threading.Tasks.Task PauseTransferIfRunningAsync(string transferId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
120122
public virtual System.Threading.Tasks.Task<Azure.Storage.DataMovement.DataTransfer> StartTransferAsync(Azure.Storage.DataMovement.StorageResource sourceResource, Azure.Storage.DataMovement.StorageResource destinationResource, Azure.Storage.DataMovement.Models.TransferOptions transferOptions = null) { throw null; }
121123
public virtual System.Threading.Tasks.Task<Azure.Storage.DataMovement.DataTransfer> StartTransferAsync(Azure.Storage.DataMovement.StorageResourceContainer sourceResource, Azure.Storage.DataMovement.StorageResourceContainer destinationResource, Azure.Storage.DataMovement.Models.TransferOptions transferOptions = null) { throw null; }
122124
System.Threading.Tasks.ValueTask System.IAsyncDisposable.DisposeAsync() { throw null; }
123-
public virtual System.Threading.Tasks.Task<bool> TryPauseTransferAsync(Azure.Storage.DataMovement.DataTransfer transfer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
124-
public virtual System.Threading.Tasks.Task<bool> TryPauseTransferAsync(string transferId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
125125
}
126126
public partial class TransferManagerOptions
127127
{

sdk/storage/Azure.Storage.DataMovement/api/Azure.Storage.DataMovement.netstandard2.0.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ internal DataTransfer() { }
88
public Azure.Storage.DataMovement.StorageTransferStatus TransferStatus { get { throw null; } }
99
public System.Threading.Tasks.Task AwaitCompletion(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
1010
public void EnsureCompleted(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { }
11-
public System.Threading.Tasks.Task<bool> TryPauseAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
11+
public System.Threading.Tasks.Task PauseIfRunningAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
1212
}
1313
[System.FlagsAttribute]
1414
public enum ErrorHandlingOptions
@@ -117,11 +117,11 @@ public partial class TransferManager : System.IAsyncDisposable
117117
{
118118
protected TransferManager() { }
119119
public TransferManager(Azure.Storage.DataMovement.TransferManagerOptions options = null) { }
120+
public virtual System.Threading.Tasks.Task PauseTransferIfRunningAsync(Azure.Storage.DataMovement.DataTransfer transfer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
121+
public virtual System.Threading.Tasks.Task PauseTransferIfRunningAsync(string transferId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
120122
public virtual System.Threading.Tasks.Task<Azure.Storage.DataMovement.DataTransfer> StartTransferAsync(Azure.Storage.DataMovement.StorageResource sourceResource, Azure.Storage.DataMovement.StorageResource destinationResource, Azure.Storage.DataMovement.Models.TransferOptions transferOptions = null) { throw null; }
121123
public virtual System.Threading.Tasks.Task<Azure.Storage.DataMovement.DataTransfer> StartTransferAsync(Azure.Storage.DataMovement.StorageResourceContainer sourceResource, Azure.Storage.DataMovement.StorageResourceContainer destinationResource, Azure.Storage.DataMovement.Models.TransferOptions transferOptions = null) { throw null; }
122124
System.Threading.Tasks.ValueTask System.IAsyncDisposable.DisposeAsync() { throw null; }
123-
public virtual System.Threading.Tasks.Task<bool> TryPauseTransferAsync(Azure.Storage.DataMovement.DataTransfer transfer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
124-
public virtual System.Threading.Tasks.Task<bool> TryPauseTransferAsync(string transferId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
125125
}
126126
public partial class TransferManagerOptions
127127
{

sdk/storage/Azure.Storage.DataMovement/api/Azure.Storage.DataMovement.netstandard2.1.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ internal DataTransfer() { }
88
public Azure.Storage.DataMovement.StorageTransferStatus TransferStatus { get { throw null; } }
99
public System.Threading.Tasks.Task AwaitCompletion(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
1010
public void EnsureCompleted(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { }
11-
public System.Threading.Tasks.Task<bool> TryPauseAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
11+
public System.Threading.Tasks.Task PauseIfRunningAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
1212
}
1313
[System.FlagsAttribute]
1414
public enum ErrorHandlingOptions
@@ -117,11 +117,11 @@ public partial class TransferManager : System.IAsyncDisposable
117117
{
118118
protected TransferManager() { }
119119
public TransferManager(Azure.Storage.DataMovement.TransferManagerOptions options = null) { }
120+
public virtual System.Threading.Tasks.Task PauseTransferIfRunningAsync(Azure.Storage.DataMovement.DataTransfer transfer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
121+
public virtual System.Threading.Tasks.Task PauseTransferIfRunningAsync(string transferId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
120122
public virtual System.Threading.Tasks.Task<Azure.Storage.DataMovement.DataTransfer> StartTransferAsync(Azure.Storage.DataMovement.StorageResource sourceResource, Azure.Storage.DataMovement.StorageResource destinationResource, Azure.Storage.DataMovement.Models.TransferOptions transferOptions = null) { throw null; }
121123
public virtual System.Threading.Tasks.Task<Azure.Storage.DataMovement.DataTransfer> StartTransferAsync(Azure.Storage.DataMovement.StorageResourceContainer sourceResource, Azure.Storage.DataMovement.StorageResourceContainer destinationResource, Azure.Storage.DataMovement.Models.TransferOptions transferOptions = null) { throw null; }
122124
System.Threading.Tasks.ValueTask System.IAsyncDisposable.DisposeAsync() { throw null; }
123-
public virtual System.Threading.Tasks.Task<bool> TryPauseTransferAsync(Azure.Storage.DataMovement.DataTransfer transfer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
124-
public virtual System.Threading.Tasks.Task<bool> TryPauseTransferAsync(string transferId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
125125
}
126126
public partial class TransferManagerOptions
127127
{

sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransfer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ public async Task AwaitCompletion(CancellationToken cancellationToken = default)
9191
///
9292
/// Will return true if the pause has taken place.
9393
/// </returns>
94-
public Task<bool> TryPauseAsync(CancellationToken cancellationToken = default)
94+
public async Task PauseIfRunningAsync(CancellationToken cancellationToken = default)
9595
{
96-
return _state.TryPauseAsync(cancellationToken);
96+
await _state.PauseIfRunningAsync(cancellationToken).ConfigureAwait(false);
9797
}
9898
}
9999
}

sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransferState.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33

44
using System;
5+
using System.Collections.Generic;
56
using System.Threading;
67
using System.Threading.Tasks;
78
using Azure.Core;
@@ -172,14 +173,14 @@ public void UpdateTransferBytes(long transferredBytes)
172173
}
173174
}
174175

175-
public async Task<bool> TryPauseAsync(CancellationToken cancellationToken)
176+
public async Task PauseIfRunningAsync(CancellationToken cancellationToken)
176177
{
177178
if (StorageTransferStatus.Paused == _status ||
178179
StorageTransferStatus.Completed == _status ||
179180
StorageTransferStatus.CompletedWithSkippedTransfers == _status ||
180181
StorageTransferStatus.CompletedWithFailedTransfers == _status)
181182
{
182-
return false;
183+
return;
183184
}
184185
CancellationHelper.ThrowIfCancellationRequested(cancellationToken);
185186
// Call the inner cancellation token to stop the transfer job
@@ -188,9 +189,7 @@ public async Task<bool> TryPauseAsync(CancellationToken cancellationToken)
188189
{
189190
// Wait until full pause has completed.
190191
await CompletionSource.Task.AwaitWithCancellation(cancellationToken);
191-
return true;
192192
}
193-
return false;
194193
}
195194

196195
internal bool TriggerCancellation()

sdk/storage/Azure.Storage.DataMovement/src/Shared/TransferManager.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ private async Task NotifyOfPendingJobChunkProcessing()
232232
/// Return true once the transfer has been successfully paused or false if the transfer
233233
/// was already completed.
234234
/// </returns>
235-
public virtual Task<bool> TryPauseTransferAsync(DataTransfer transfer, CancellationToken cancellationToken = default)
236-
=> TryPauseTransferAsync(transfer.Id, cancellationToken);
235+
public virtual Task PauseTransferIfRunningAsync(DataTransfer transfer, CancellationToken cancellationToken = default)
236+
=> PauseTransferIfRunningAsync(transfer.Id, cancellationToken);
237237

238238
/// <summary>
239239
/// Attempts to pause the transfer of the respective id.
@@ -247,17 +247,14 @@ public virtual Task<bool> TryPauseTransferAsync(DataTransfer transfer, Cancellat
247247
/// Return true once the transfer has been successfully paused or false if the transfer
248248
/// was already completed.
249249
/// </returns>
250-
public virtual Task<bool> TryPauseTransferAsync(string transferId, CancellationToken cancellationToken = default)
250+
public virtual async Task PauseTransferIfRunningAsync(string transferId, CancellationToken cancellationToken = default)
251251
{
252252
Argument.AssertNotNullOrEmpty(transferId, nameof(transferId));
253-
if (_dataTransfers.TryGetValue(transferId, out DataTransfer transfer))
253+
if (!_dataTransfers.TryGetValue(transferId, out DataTransfer transfer))
254254
{
255-
return transfer.TryPauseAsync(cancellationToken: cancellationToken);
256-
}
257-
else
258-
{
259-
throw Errors.InvalidTransferId(nameof(TryPauseTransferAsync), transferId);
255+
throw Errors.InvalidTransferId(nameof(PauseTransferIfRunningAsync), transferId);
260256
}
257+
await transfer.PauseIfRunningAsync(cancellationToken: cancellationToken).ConfigureAwait(false);
261258
}
262259

263260
/// <summary>

sdk/storage/Azure.Storage.DataMovement/src/StorageTransferStatus.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public enum StorageTransferStatus
3131
InProgress = 2,
3232

3333
/// <summary>
34-
/// The Job has been paused. When transfer is paused (e.g. see <see cref="TransferManager.TryPauseTransferAsync(string, System.Threading.CancellationToken)"/>) during the transfer,
34+
/// The Job has been paused. When transfer is paused (e.g. see <see cref="TransferManager.PauseTransferIfRunningAsync(string, System.Threading.CancellationToken)"/>) during the transfer,
3535
/// this will be the value.
3636
///
3737
/// This status is a resumable state, only

sdk/storage/Azure.Storage.DataMovement/tests/DataTransferTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public async Task TryPauseAsync()
9595
{
9696
DataTransfer transfer = new DataTransfer(StorageTransferStatus.InProgress);
9797

98-
Task<bool> pauseTask = transfer.TryPauseAsync();
98+
Task pauseTask = transfer.PauseIfRunningAsync();
9999

100100
Assert.AreEqual(StorageTransferStatus.PauseInProgress, transfer.TransferStatus);
101101

@@ -104,9 +104,9 @@ public async Task TryPauseAsync()
104104
Assert.Fail("Unable to set the transfer status internally to the DataTransfer.");
105105
}
106106

107-
bool pauseResult = await pauseTask;
107+
await pauseTask;
108108

109-
Assert.IsTrue(pauseResult);
109+
Assert.AreEqual(StorageTransferStatus.Paused, transfer.TransferStatus);
110110
Assert.IsFalse(transfer.HasCompleted);
111111
}
112112

@@ -119,9 +119,9 @@ public async Task TryPauseAsync_AlreadyPaused(StorageTransferStatus status)
119119
{
120120
DataTransfer transfer = new DataTransfer(status);
121121

122-
bool pauseResult = await transfer.TryPauseAsync();
123-
124-
Assert.IsFalse(pauseResult);
122+
Assert.AreEqual(status, transfer.TransferStatus);
123+
await transfer.PauseIfRunningAsync();
124+
Assert.AreEqual(status, transfer.TransferStatus);
125125
}
126126

127127
[Test]
@@ -132,7 +132,7 @@ public async Task TryPauseAsync_CancellationToken()
132132

133133
try
134134
{
135-
await transfer.TryPauseAsync(cancellationTokenSource.Token);
135+
await transfer.PauseIfRunningAsync(cancellationTokenSource.Token);
136136
}
137137
catch (OperationCanceledException exception)
138138
{

0 commit comments

Comments
 (0)