From b1d0eaf83e6e2945926500730b99b6b6e4a59d92 Mon Sep 17 00:00:00 2001 From: Amanda Nguyen Date: Wed, 9 Aug 2023 13:03:56 -0700 Subject: [PATCH 01/13] WIP --- .../samples/Sample01b_HelloWorldAsync.cs | 4 +- .../src/DataTransferStatus.cs | 111 ++++++++++++------ .../src/JobPartInternal.cs | 32 ++--- .../src/ServiceToServiceJobPart.cs | 4 +- .../src/ServiceToServiceTransferJob.cs | 2 +- .../src/Shared/DataTransferState.cs | 22 ++-- .../src/Shared/TransferManager.cs | 4 +- .../src/StreamToUriJobPart.cs | 4 +- .../src/StreamToUriTransferJob.cs | 2 +- .../src/TransferJobInternal.cs | 81 ++++++------- .../src/UriToStreamJobPart.cs | 2 +- .../src/UriToStreamTransferJob.cs | 2 +- .../tests/DataTransferTests.cs | 32 ++--- .../tests/GetTransfersTests.cs | 58 ++++----- .../tests/LocalTransferCheckpointerTests.cs | 10 +- .../tests/PauseResumeTransferTests.cs | 32 ++--- .../tests/ProgressHandlerTests.cs | 4 +- .../StartTransferDownloadDirectoryTests.cs | 18 +-- .../tests/StartTransferDownloadTests.cs | 28 ++--- .../StartTransferSyncCopyDirectoryTests.cs | 18 +-- .../tests/StartTransferSyncCopyTests.cs | 22 ++-- .../StartTransferUploadDirectoryTests.cs | 16 +-- .../tests/StartTransferUploadTests.cs | 28 ++--- .../tests/TestEventsRaised.cs | 30 ++--- 24 files changed, 303 insertions(+), 263 deletions(-) diff --git a/sdk/storage/Azure.Storage.DataMovement.Blobs/samples/Sample01b_HelloWorldAsync.cs b/sdk/storage/Azure.Storage.DataMovement.Blobs/samples/Sample01b_HelloWorldAsync.cs index b9cb32ed9e0a6..0722f36d6fa3b 100644 --- a/sdk/storage/Azure.Storage.DataMovement.Blobs/samples/Sample01b_HelloWorldAsync.cs +++ b/sdk/storage/Azure.Storage.DataMovement.Blobs/samples/Sample01b_HelloWorldAsync.cs @@ -527,7 +527,7 @@ public async Task UploadDirectory_EventHandler_SasAsync() DataTransferOptions transferOptions = new DataTransferOptions(); transferOptions.TransferStatusChanged += (TransferStatusEventArgs args) => { - if (args.StorageTransferStatus == DataTransferStatus.Completed) + if (args.StorageTransferStatus == DataTransferStatus.TransferState.Completed) { using (StreamWriter logStream = File.AppendText(logFile)) { @@ -713,7 +713,7 @@ public async Task CopySingle_ConnectionStringAsync() #endregion Assert.IsTrue(await destinationAppendBlobClient.ExistsAsync()); - Assert.AreEqual(dataTransfer.TransferStatus, DataTransferStatus.Completed); + Assert.AreEqual(dataTransfer.TransferStatus, DataTransferStatus.TransferState.Completed); } finally { diff --git a/sdk/storage/Azure.Storage.DataMovement/src/DataTransferStatus.cs b/sdk/storage/Azure.Storage.DataMovement/src/DataTransferStatus.cs index 0a56b039e54e2..dba488eda0cd6 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/DataTransferStatus.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/DataTransferStatus.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using System.Runtime.CompilerServices; using System.Threading; namespace Azure.Storage.DataMovement @@ -8,59 +9,103 @@ namespace Azure.Storage.DataMovement /// /// Defines the status of the Transfer Job. /// - public enum DataTransferStatus + public class DataTransferStatus { /// - /// Default value. - /// Equivalent to . + /// Defines the types of the state a transfer can have. /// - None = 0, + public enum TransferState + { + /// + /// Default value. + /// + None, - /// - /// The Job has been queued up but has not yet begun any transfers. - /// Equivalent to . - /// - Queued = 1, + /// + /// The transfer has been queued up but has not yet started. + /// + Queued, - /// - /// The Job has started, but has not yet completed. - /// Equivalent to . - /// - InProgress = 2, + /// + /// The transfer has started, but has not yet completed. + /// + InProgress, + + /// + /// The transfer has started and is in the process of being paused. + /// + /// Transfer can be stopped if + /// or is called. + /// + Pausing, // (Used to be PauseInProgress) + + /// + /// The transfer has started and is in the process of being stopped. + /// + /// Transfer can be stopped if is + /// enabled in the . + /// + Stopping, // (Used to be CancellationInProgress) + + /// + /// The transfer has been paused. When transfer is paused + /// (e.g. see ) + /// during the transfer, this will be the value. + /// + Paused, + + /// + /// The transfer has come to a completed state. If the transfer has started and + /// has fully stopped will also come to this state. + /// + Completed + } /// - /// The Job has been paused. When transfer is paused (e.g. see ) during the transfer, - /// this will be the value. + /// Represents if transfer has any failure items. /// - /// This status is a resumable state, only - /// transfers that failed will be retried when - /// with the respective transfer ID to resume. + /// If set to `true`, the transfer has at least one failure item. + /// If set to `false`, the transfer currently has no failures. /// - Paused = 3, + public bool HasFailureItems { get; internal set; } /// - /// The Job has completed successfully with no failures or skips. + /// Represents if transfer has any skipped items. + /// + /// If set to `true`, the transfer has at least one item it has skipped. + /// If set to `false`, the transfer currently has no items that has been skipped. + /// + /// It's possible to never have any items skipped if + /// is not enabled in the . /// - Completed = 4, + public bool HasSkippedItems { get; internal set; } /// - /// The Job has been completed with at least one skipped transfer. + /// Defines the state of the transfer. /// - CompletedWithSkippedTransfers = 5, + public TransferState State { get; internal set; } /// - /// The Job has been completed with at least one failed transfer. + /// Constructor to set the initial state to with no failures or skipped items. /// - CompletedWithFailedTransfers = 6, + protected internal DataTransferStatus() + { + State = TransferState.Queued; + HasFailureItems = false; + HasSkippedItems = false; + } /// - /// A pause was called on the transfer job and is in progress. + /// Constructor to have a custom state, failure state, and skipped state. /// - PauseInProgress = 7, + protected internal DataTransferStatus(TransferState state, bool hasFailureItems, bool hasSkippedItems) + { + State = state; + HasFailureItems = hasFailureItems; + HasSkippedItems = hasSkippedItems; + } - /// - /// A pause was called on the transfer job and is in progress. - /// - CancellationInProgress = 8, - }; + internal bool IsCompletedWithFailedItems => State.Equals(TransferState.Completed) && HasFailureItems; + internal bool IsCompletedWithSkippedItems => State.Equals(TransferState.Completed) && HasSkippedItems; + } } diff --git a/sdk/storage/Azure.Storage.DataMovement/src/JobPartInternal.cs b/sdk/storage/Azure.Storage.DataMovement/src/JobPartInternal.cs index 92e532488fadd..bc8638d6c6e69 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/JobPartInternal.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/JobPartInternal.cs @@ -259,23 +259,23 @@ await QueueChunk( /// /// Triggers the cancellation for the Job Part. /// - /// If the status is set to - /// and any chunks is still processing to be cancelled is will be set to - /// until the chunks finish then it will be set to . + /// If the status is set to + /// and any chunks is still processing to be cancelled is will be set to + /// until the chunks finish then it will be set to . /// - /// If the status is set to + /// If the status is set to /// and any chunks is still processing to be cancelled is will be set to - /// until the chunks finish then it will be set to . + /// until the chunks finish then it will be set to . /// /// The task to wait until the cancellation has been triggered. internal async Task TriggerCancellationAsync() { // Set the status to Pause/CancellationInProgress - if (DataTransferStatus.PauseInProgress == _dataTransfer.TransferStatus) + if (DataTransferStatus.TransferState.Pausing == _dataTransfer.TransferStatus) { // It's possible that the status hasn't propagated down to the job part // status yet here since we pause from the data transfer object. - await OnTransferStatusChanged(DataTransferStatus.PauseInProgress).ConfigureAwait(false); + await OnTransferStatusChanged(DataTransferStatus.TransferState.Pausing).ConfigureAwait(false); } else { @@ -294,7 +294,7 @@ internal async Task OnTransferStatusChanged(DataTransferStatus transferStatus) bool statusChanged = false; lock (_statusLock) { - if (transferStatus != DataTransferStatus.None + if (transferStatus != DataTransferStatus.TransferState.None && JobPartStatus != transferStatus) { statusChanged = true; @@ -308,20 +308,20 @@ internal async Task OnTransferStatusChanged(DataTransferStatus transferStatus) { _progressTracker.IncrementInProgressFiles(); } - else if (transferStatus == DataTransferStatus.Completed) + else if (transferStatus == DataTransferStatus.TransferState.Completed) { _progressTracker.IncrementCompletedFiles(); } - else if (transferStatus == DataTransferStatus.CompletedWithSkippedTransfers) + else if (transferStatus == DataTransferStatus.TransferState.CompletedWithSkippedTransfers) { _progressTracker.IncrementSkippedFiles(); } - else if (transferStatus == DataTransferStatus.CompletedWithFailedTransfers) + else if (transferStatus == DataTransferStatus.TransferState.CompletedWithFailedTransfers) { _progressTracker.IncrementFailedFiles(); } - if (JobPartStatus == DataTransferStatus.Completed) + if (JobPartStatus == DataTransferStatus.TransferState.Completed) { await InvokeSingleCompletedArg().ConfigureAwait(false); } @@ -390,7 +390,7 @@ await TransferSkippedEventHandler.RaiseAsync( ClientDiagnostics) .ConfigureAwait(false); } - await OnTransferStatusChanged(DataTransferStatus.CompletedWithSkippedTransfers).ConfigureAwait(false); + await OnTransferStatusChanged(DataTransferStatus.TransferState.CompletedWithSkippedTransfers).ConfigureAwait(false); } /// @@ -567,13 +567,13 @@ internal async Task CheckAndUpdateCancellationStatusAsync() { if (_chunkTasks.All((Task task) => (task.IsCompleted))) { - if (JobPartStatus == DataTransferStatus.PauseInProgress) + if (JobPartStatus == DataTransferStatus.TransferState.Pausing) { - await OnTransferStatusChanged(DataTransferStatus.Paused).ConfigureAwait(false); + await OnTransferStatusChanged(DataTransferStatus.TransferState.Paused).ConfigureAwait(false); } else if (JobPartStatus == DataTransferStatus.CancellationInProgress) { - await OnTransferStatusChanged(DataTransferStatus.CompletedWithFailedTransfers).ConfigureAwait(false); + await OnTransferStatusChanged(DataTransferStatus.TransferState.CompletedWithFailedTransfers).ConfigureAwait(false); } } } diff --git a/sdk/storage/Azure.Storage.DataMovement/src/ServiceToServiceJobPart.cs b/sdk/storage/Azure.Storage.DataMovement/src/ServiceToServiceJobPart.cs index 277a045fe6e30..a998b3a3f84d3 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/ServiceToServiceJobPart.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/ServiceToServiceJobPart.cs @@ -211,7 +211,7 @@ await _destinationResource.CopyFromUriAsync( cancellationToken: _cancellationToken).ConfigureAwait(false); ReportBytesWritten(completeLength); - await OnTransferStatusChanged(DataTransferStatus.Completed).ConfigureAwait(false); + await OnTransferStatusChanged(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); } catch (RequestFailedException exception) when (_createMode == StorageResourceCreationPreference.SkipIfExists @@ -307,7 +307,7 @@ await _destinationResource.CompleteTransferAsync( await DisposeHandlers().ConfigureAwait(false); // Set completion status to completed - await OnTransferStatusChanged(DataTransferStatus.Completed).ConfigureAwait(false); + await OnTransferStatusChanged(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); } catch (Exception ex) { diff --git a/sdk/storage/Azure.Storage.DataMovement/src/ServiceToServiceTransferJob.cs b/sdk/storage/Azure.Storage.DataMovement/src/ServiceToServiceTransferJob.cs index ea5af0ae23746..2e9e4b664459a 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/ServiceToServiceTransferJob.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/ServiceToServiceTransferJob.cs @@ -108,7 +108,7 @@ public override async IAsyncEnumerable ProcessJobToJobPartAsync bool isFinalPartFound = false; foreach (JobPartInternal part in _jobParts) { - if (part.JobPartStatus != DataTransferStatus.Completed) + if (part.JobPartStatus != DataTransferStatus.TransferState.Completed) { part.JobPartStatus = DataTransferStatus.Queued; yield return part; diff --git a/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransferState.cs b/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransferState.cs index d96830068f369..55d2ef5478605 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransferState.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransferState.cs @@ -38,9 +38,9 @@ public DataTransferState( CompletionSource = new TaskCompletionSource( _status, TaskCreationOptions.RunContinuationsAsynchronously); - if (DataTransferStatus.Completed == status || - DataTransferStatus.CompletedWithSkippedTransfers == status || - DataTransferStatus.CompletedWithFailedTransfers == status) + if (DataTransferStatus.TransferState.Completed == status || + DataTransferStatus.TransferState.CompletedWithSkippedTransfers == status || + DataTransferStatus.TransferState.CompletedWithFailedTransfers == status) { CompletionSource.TrySetResult(status); } @@ -62,9 +62,9 @@ internal set { } public bool HasCompleted { get { - return (DataTransferStatus.Completed == _status || - DataTransferStatus.CompletedWithSkippedTransfers == _status || - DataTransferStatus.CompletedWithFailedTransfers == _status); + return (DataTransferStatus.TransferState.Completed == _status || + DataTransferStatus.TransferState.CompletedWithSkippedTransfers == _status || + DataTransferStatus.TransferState.CompletedWithFailedTransfers == _status); } internal set { } } @@ -102,10 +102,10 @@ public bool TrySetTransferStatus(DataTransferStatus status) if (_status != status) { _status = status; - if (DataTransferStatus.Paused == status || - DataTransferStatus.Completed == status || - DataTransferStatus.CompletedWithSkippedTransfers == status || - DataTransferStatus.CompletedWithFailedTransfers == status) + if (DataTransferStatus.TransferState.Paused == status || + DataTransferStatus.TransferState.Completed == status || + DataTransferStatus.TransferState.CompletedWithSkippedTransfers == status || + DataTransferStatus.TransferState.CompletedWithFailedTransfers == status) { // If the _completionSource has been cancelled or the exception // has been set, we don't need to check if TrySetResult returns false @@ -129,7 +129,7 @@ public async Task PauseIfRunningAsync(CancellationToken cancellationToken) } CancellationHelper.ThrowIfCancellationRequested(cancellationToken); // Call the inner cancellation token to stop the transfer job - TrySetTransferStatus(DataTransferStatus.PauseInProgress); + TrySetTransferStatus(DataTransferStatus.TransferState.Pausing); if (TriggerCancellation()) { // Wait until full pause has completed. diff --git a/sdk/storage/Azure.Storage.DataMovement/src/Shared/TransferManager.cs b/sdk/storage/Azure.Storage.DataMovement/src/Shared/TransferManager.cs index 3bff5e88f7f5c..f261457a343f2 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/Shared/TransferManager.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/Shared/TransferManager.cs @@ -257,7 +257,7 @@ public virtual async Task PauseTransferIfRunningAsync(string transferId, Cancell /// If specified, the returned list of transfers will have only have the transfers /// of which match the status specified. /// - /// If not specified or specified to , + /// If not specified or specified to , /// all transfers will be returned regardless of status. /// /// @@ -300,7 +300,7 @@ public virtual async IAsyncEnumerable GetResumableTransf _cancellationToken).ConfigureAwait(false); // Transfers marked as fully completed are not resumable - if (jobStatus == DataTransferStatus.Completed) + if (jobStatus.State == DataTransferStatus.TransferState.Completed) { continue; } diff --git a/sdk/storage/Azure.Storage.DataMovement/src/StreamToUriJobPart.cs b/sdk/storage/Azure.Storage.DataMovement/src/StreamToUriJobPart.cs index 31dd0358f7f36..5d8d174f50b47 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/StreamToUriJobPart.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/StreamToUriJobPart.cs @@ -250,7 +250,7 @@ await _destinationResource.CopyFromStreamAsync( ReportBytesWritten(blockSize); // Set completion status to completed - await OnTransferStatusChanged(DataTransferStatus.Completed).ConfigureAwait(false); + await OnTransferStatusChanged(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); } else { @@ -395,7 +395,7 @@ await _destinationResource.CompleteTransferAsync( await DisposeHandlers().ConfigureAwait(false); // Set completion status to completed - await OnTransferStatusChanged(DataTransferStatus.Completed).ConfigureAwait(false); + await OnTransferStatusChanged(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); } private async Task QueueStageBlockRequests(List<(long Offset, long Size)> rangeList, long completeLength) diff --git a/sdk/storage/Azure.Storage.DataMovement/src/StreamToUriTransferJob.cs b/sdk/storage/Azure.Storage.DataMovement/src/StreamToUriTransferJob.cs index 429e7478bfef5..cc1d0fab68e5d 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/StreamToUriTransferJob.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/StreamToUriTransferJob.cs @@ -106,7 +106,7 @@ public override async IAsyncEnumerable ProcessJobToJobPartAsync bool isFinalPartFound = false; foreach (JobPartInternal part in _jobParts) { - if (part.JobPartStatus != DataTransferStatus.Completed) + if (part.JobPartStatus != DataTransferStatus.TransferState.Completed) { part.JobPartStatus = DataTransferStatus.Queued; yield return part; diff --git a/sdk/storage/Azure.Storage.DataMovement/src/TransferJobInternal.cs b/sdk/storage/Azure.Storage.DataMovement/src/TransferJobInternal.cs index 935aeeaa66666..a94e92876ae6b 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/TransferJobInternal.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/TransferJobInternal.cs @@ -273,13 +273,13 @@ public void DisposeHandlers() /// /// Triggers the cancellation for the Job Part. /// - /// If the status is set to - /// and any chunks is still processing to be cancelled is will be set to - /// until the chunks finish then it will be set to . + /// If the status is set to + /// and any chunks is still processing to be cancelled is will be set to + /// until the chunks finish then it will be set to . /// - /// If the status is set to + /// If the status is set to /// and any chunks is still processing to be cancelled is will be set to - /// until the chunks finish then it will be set to . + /// until the chunks finish then it will be set to . /// /// The task to wait until the cancellation has been triggered. public async Task TriggerJobCancellationAsync() @@ -336,39 +336,38 @@ public async Task JobPartEvent(TransferStatusEventArgs args) DataTransferStatus jobStatus = _dataTransfer._state.GetTransferStatus(); // Keep track of paused, failed, and skipped which we will use to determine final job status - if (jobPartStatus == DataTransferStatus.Paused) + // Since this is each Job Part coming in, the state of skipped or failed is mutually exclusive. + if (jobPartStatus.State == DataTransferStatus.TransferState.Paused) { _jobPartPaused = true; } - else if (jobPartStatus == DataTransferStatus.CompletedWithFailedTransfers) + else if (jobPartStatus.State == DataTransferStatus.TransferState.Completed + && jobPartStatus.HasFailureItems) { _jobPartFailed = true; } - else if (jobPartStatus == DataTransferStatus.CompletedWithSkippedTransfers) + else if (jobPartStatus.State == DataTransferStatus.TransferState.Completed + && jobPartStatus.HasSkippedItems) { _jobPartSkipped = true; } // Cancel the entire job if one job part fails and StopOnFailure is set if (_errorMode == DataTransferErrorMode.StopOnAnyFailure && - jobPartStatus == DataTransferStatus.CompletedWithFailedTransfers && - jobStatus != DataTransferStatus.CancellationInProgress && - jobStatus != DataTransferStatus.CompletedWithFailedTransfers && - jobStatus != DataTransferStatus.CompletedWithSkippedTransfers && - jobStatus != DataTransferStatus.Completed) + jobPartStatus.IsCompletedWithFailedItems && + jobStatus.State != DataTransferStatus.TransferState.Stopping && + jobStatus.State != DataTransferStatus.TransferState.Completed) { await TriggerJobCancellationAsync().ConfigureAwait(false); jobStatus = _dataTransfer._state.GetTransferStatus(); } - if ((jobPartStatus == DataTransferStatus.Paused || - jobPartStatus == DataTransferStatus.Completed || - jobPartStatus == DataTransferStatus.CompletedWithSkippedTransfers || - jobPartStatus == DataTransferStatus.CompletedWithFailedTransfers) - && (jobStatus == DataTransferStatus.Queued || - jobStatus == DataTransferStatus.InProgress || - jobStatus == DataTransferStatus.PauseInProgress || - jobStatus == DataTransferStatus.CancellationInProgress)) + if ((jobPartStatus.State == DataTransferStatus.TransferState.Paused || + jobPartStatus.State == DataTransferStatus.TransferState.Completed) + && (jobStatus.State == DataTransferStatus.TransferState.Queued || + jobStatus.State == DataTransferStatus.TransferState.InProgress || + jobStatus.State == DataTransferStatus.TransferState.Pausing || + jobStatus.State == DataTransferStatus.TransferState.Stopping)) { Interlocked.Decrement(ref _pendingJobParts); @@ -389,10 +388,8 @@ public async Task OnJobStatusChangedAsync(DataTransferStatus status) if (statusChanged) { // If we are in a final state, dispose the JobPartEvent handlers - if (status == DataTransferStatus.Completed || - status == DataTransferStatus.CompletedWithSkippedTransfers || - status == DataTransferStatus.CompletedWithFailedTransfers || - status == DataTransferStatus.Paused) + if (status.State == DataTransferStatus.TransferState.Completed || + status.State == DataTransferStatus.TransferState.Paused) { DisposeHandlers(); } @@ -439,24 +436,22 @@ internal async Task OnEnumerationComplete() { // If there were no job parts enumerated and we haven't already aborted/completed the job. if (_jobParts.Count == 0 && - _dataTransfer.TransferStatus != DataTransferStatus.Paused && - _dataTransfer.TransferStatus != DataTransferStatus.CompletedWithSkippedTransfers && - _dataTransfer.TransferStatus != DataTransferStatus.CompletedWithFailedTransfers && - _dataTransfer.TransferStatus != DataTransferStatus.Completed) + _dataTransfer.TransferStatus.State != DataTransferStatus.TransferState.Paused && + _dataTransfer.TransferStatus.State != DataTransferStatus.TransferState.Completed) { - if (_dataTransfer.TransferStatus == DataTransferStatus.PauseInProgress) + if (_dataTransfer.TransferStatus.State == DataTransferStatus.TransferState.Pausing) { // If we paused before we were able to list, set the status properly. - await OnJobStatusChangedAsync(DataTransferStatus.Paused).ConfigureAwait(false); + await OnJobStatusChangedAsync(DataTransferStatus.TransferState.Paused).ConfigureAwait(false); } else if (_dataTransfer.TransferStatus == DataTransferStatus.CancellationInProgress) { // If we aborted before we were able to list, set the status properly. - await OnJobStatusChangedAsync(DataTransferStatus.CompletedWithFailedTransfers).ConfigureAwait(false); + await OnJobStatusChangedAsync(DataTransferStatus.TransferState.CompletedWithFailedTransfers).ConfigureAwait(false); } else { - await OnJobStatusChangedAsync(DataTransferStatus.Completed).ConfigureAwait(false); + await OnJobStatusChangedAsync(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); } } await CheckAndUpdateStatusAsync().ConfigureAwait(false); @@ -468,13 +463,13 @@ internal async Task CheckAndUpdateStatusAsync() // This is in the case that we weren't able to begin listing any job parts yet. if (_jobParts.Count == 0) { - if (_dataTransfer.TransferStatus == DataTransferStatus.PauseInProgress) + if (_dataTransfer.TransferStatus == DataTransferStatus.TransferState.Pausing) { - await OnJobStatusChangedAsync(DataTransferStatus.Paused).ConfigureAwait(false); + await OnJobStatusChangedAsync(DataTransferStatus.TransferState.Paused).ConfigureAwait(false); } else if (_dataTransfer.TransferStatus == DataTransferStatus.CancellationInProgress) { - await OnJobStatusChangedAsync(DataTransferStatus.CompletedWithFailedTransfers).ConfigureAwait(false); + await OnJobStatusChangedAsync(DataTransferStatus.TransferState.CompletedWithFailedTransfers).ConfigureAwait(false); } return; } @@ -484,19 +479,19 @@ internal async Task CheckAndUpdateStatusAsync() { if (_jobPartPaused) { - await OnJobStatusChangedAsync(DataTransferStatus.Paused).ConfigureAwait(false); + await OnJobStatusChangedAsync(DataTransferStatus.TransferState.Paused).ConfigureAwait(false); } else if (_jobPartFailed) { - await OnJobStatusChangedAsync(DataTransferStatus.CompletedWithFailedTransfers).ConfigureAwait(false); + await OnJobStatusChangedAsync(DataTransferStatus.TransferState.CompletedWithFailedTransfers).ConfigureAwait(false); } else if (_jobPartSkipped) { - await OnJobStatusChangedAsync(DataTransferStatus.CompletedWithSkippedTransfers).ConfigureAwait(false); + await OnJobStatusChangedAsync(DataTransferStatus.TransferState.CompletedWithSkippedTransfers).ConfigureAwait(false); } else { - await OnJobStatusChangedAsync(DataTransferStatus.Completed).ConfigureAwait(false); + await OnJobStatusChangedAsync(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); } } } @@ -507,9 +502,9 @@ public void AppendJobPart(JobPartInternal jobPart) // Job parts can come from resuming a transfer and therefore may already be complete DataTransferStatus status = jobPart.JobPartStatus; - if (status != DataTransferStatus.CompletedWithSkippedTransfers && - status != DataTransferStatus.CompletedWithFailedTransfers && - status != DataTransferStatus.Completed) + if (status != DataTransferStatus.TransferState.CompletedWithSkippedTransfers && + status != DataTransferStatus.TransferState.CompletedWithFailedTransfers && + status != DataTransferStatus.TransferState.Completed) { Interlocked.Increment(ref _pendingJobParts); } diff --git a/sdk/storage/Azure.Storage.DataMovement/src/UriToStreamJobPart.cs b/sdk/storage/Azure.Storage.DataMovement/src/UriToStreamJobPart.cs index 30258ce5f67ee..5abf9c2401f3e 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/UriToStreamJobPart.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/UriToStreamJobPart.cs @@ -340,7 +340,7 @@ await _destinationResource.CompleteTransferAsync( await DisposeHandlers().ConfigureAwait(false); // Update the transfer status - await OnTransferStatusChanged(DataTransferStatus.Completed).ConfigureAwait(false); + await OnTransferStatusChanged(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); } catch (Exception ex) { diff --git a/sdk/storage/Azure.Storage.DataMovement/src/UriToStreamTransferJob.cs b/sdk/storage/Azure.Storage.DataMovement/src/UriToStreamTransferJob.cs index 88cc9bccab057..4aae089a43ddb 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/UriToStreamTransferJob.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/UriToStreamTransferJob.cs @@ -106,7 +106,7 @@ public override async IAsyncEnumerable ProcessJobToJobPartAsync bool isFinalPartFound = false; foreach (JobPartInternal part in _jobParts) { - if (part.JobPartStatus != DataTransferStatus.Completed) + if (part.JobPartStatus != DataTransferStatus.TransferState.Completed) { part.JobPartStatus = DataTransferStatus.Queued; yield return part; diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/DataTransferTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/DataTransferTests.cs index 879586d0c8b6d..fc9d2904a4b01 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/DataTransferTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/DataTransferTests.cs @@ -30,12 +30,12 @@ public void Ctor_Default() } [Test] - [TestCase(DataTransferStatus.None)] + [TestCase(DataTransferStatus.TransferState.None)] [TestCase(DataTransferStatus.Queued)] [TestCase(DataTransferStatus.InProgress)] - [TestCase(DataTransferStatus.PauseInProgress)] + [TestCase(DataTransferStatus.TransferState.Pausing)] [TestCase(DataTransferStatus.CancellationInProgress)] - [TestCase(DataTransferStatus.Paused)] + [TestCase(DataTransferStatus.TransferState.Paused)] public void HasCompleted_False(DataTransferStatus status) { // Arrange @@ -55,9 +55,9 @@ public void HasCompleted_False(DataTransferStatus status) } [Test] - [TestCase(DataTransferStatus.Completed)] - [TestCase(DataTransferStatus.CompletedWithSkippedTransfers)] - [TestCase(DataTransferStatus.CompletedWithFailedTransfers)] + [TestCase(DataTransferStatus.TransferState.Completed)] + [TestCase(DataTransferStatus.TransferState.CompletedWithSkippedTransfers)] + [TestCase(DataTransferStatus.TransferState.CompletedWithFailedTransfers)] public void HasCompleted_True(DataTransferStatus status) { // Arrange @@ -86,7 +86,7 @@ public void EnsureCompleted() DataTransfer transfer = new DataTransfer( id: transferId, transferManager: transferManager, - status: DataTransferStatus.Completed); + status: DataTransferStatus.TransferState.Completed); // Act transfer.WaitForCompletion(); @@ -125,7 +125,7 @@ public async Task AwaitCompletion() DataTransfer transfer = new DataTransfer( id: transferId, transferManager: transferManager, - status: DataTransferStatus.Completed); + status: DataTransferStatus.TransferState.Completed); // Act await transfer.WaitForCompletionAsync(); @@ -167,25 +167,25 @@ public async Task TryPauseAsync() // Act Task pauseTask = transfer.PauseAsync(); - Assert.AreEqual(DataTransferStatus.PauseInProgress, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Pausing, transfer.TransferStatus); // Assert - if (!transfer._state.TrySetTransferStatus(DataTransferStatus.Paused)) + if (!transfer._state.TrySetTransferStatus(DataTransferStatus.TransferState.Paused)) { Assert.Fail("Unable to set the transfer status internally to the DataTransfer."); } await pauseTask; - Assert.AreEqual(DataTransferStatus.Paused, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus); Assert.IsFalse(transfer.HasCompleted); } [Test] - [TestCase(DataTransferStatus.Paused)] - [TestCase(DataTransferStatus.Completed)] - [TestCase(DataTransferStatus.CompletedWithSkippedTransfers)] - [TestCase(DataTransferStatus.CompletedWithFailedTransfers)] + [TestCase(DataTransferStatus.TransferState.Paused)] + [TestCase(DataTransferStatus.TransferState.Completed)] + [TestCase(DataTransferStatus.TransferState.CompletedWithSkippedTransfers)] + [TestCase(DataTransferStatus.TransferState.CompletedWithFailedTransfers)] public async Task TryPauseAsync_AlreadyPaused(DataTransferStatus status) { // Arrange @@ -221,7 +221,7 @@ public async Task TryPauseAsync_CancellationToken() { Assert.AreEqual(exception.Message, "The operation was canceled."); } - Assert.AreEqual(DataTransferStatus.PauseInProgress, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Pausing, transfer.TransferStatus); Assert.IsFalse(transfer.HasCompleted); } } diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/GetTransfersTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/GetTransfersTests.cs index 06939c2fd71f1..85bde680184a3 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/GetTransfersTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/GetTransfersTests.cs @@ -85,9 +85,9 @@ public async Task GetTransfers_Populated() [Test] [TestCase(DataTransferStatus.Queued)] [TestCase(DataTransferStatus.InProgress)] - [TestCase(DataTransferStatus.Paused)] - [TestCase(DataTransferStatus.Completed)] - [TestCase(DataTransferStatus.CompletedWithFailedTransfers)] + [TestCase(DataTransferStatus.TransferState.Paused)] + [TestCase(DataTransferStatus.TransferState.Completed)] + [TestCase(DataTransferStatus.TransferState.CompletedWithFailedTransfers)] public async Task GetTransfers_Filtered(DataTransferStatus status) { using DisposingLocalDirectory testDirectory = DisposingLocalDirectory.GetTestDirectory(); @@ -100,13 +100,13 @@ public async Task GetTransfers_Filtered(DataTransferStatus status) GetNewDataTransfer(DataTransferStatus.Queued), GetNewDataTransfer(DataTransferStatus.InProgress), GetNewDataTransfer(DataTransferStatus.InProgress), - GetNewDataTransfer(DataTransferStatus.Paused), - GetNewDataTransfer(DataTransferStatus.Paused), - GetNewDataTransfer(DataTransferStatus.CompletedWithFailedTransfers), - GetNewDataTransfer(DataTransferStatus.CompletedWithFailedTransfers), - GetNewDataTransfer(DataTransferStatus.CompletedWithFailedTransfers), - GetNewDataTransfer(DataTransferStatus.Completed), - GetNewDataTransfer(DataTransferStatus.Completed), + GetNewDataTransfer(DataTransferStatus.TransferState.Paused), + GetNewDataTransfer(DataTransferStatus.TransferState.Paused), + GetNewDataTransfer(DataTransferStatus.TransferState.CompletedWithFailedTransfers), + GetNewDataTransfer(DataTransferStatus.TransferState.CompletedWithFailedTransfers), + GetNewDataTransfer(DataTransferStatus.TransferState.CompletedWithFailedTransfers), + GetNewDataTransfer(DataTransferStatus.TransferState.Completed), + GetNewDataTransfer(DataTransferStatus.TransferState.Completed), }; TransferManagerFactory factory = new TransferManagerFactory(GetDefaultManagerOptions(testDirectory.DirectoryPath)); @@ -133,14 +133,14 @@ public async Task GetTransfers_FilterMultipleStatuses() GetNewDataTransfer(DataTransferStatus.Queued), GetNewDataTransfer(DataTransferStatus.InProgress), GetNewDataTransfer(DataTransferStatus.InProgress), - GetNewDataTransfer(DataTransferStatus.Paused), - GetNewDataTransfer(DataTransferStatus.Paused), - GetNewDataTransfer(DataTransferStatus.CompletedWithFailedTransfers), - GetNewDataTransfer(DataTransferStatus.CompletedWithFailedTransfers), - GetNewDataTransfer(DataTransferStatus.CompletedWithFailedTransfers), - GetNewDataTransfer(DataTransferStatus.Completed), - GetNewDataTransfer(DataTransferStatus.Completed), - GetNewDataTransfer(DataTransferStatus.CompletedWithSkippedTransfers) + GetNewDataTransfer(DataTransferStatus.TransferState.Paused), + GetNewDataTransfer(DataTransferStatus.TransferState.Paused), + GetNewDataTransfer(DataTransferStatus.TransferState.CompletedWithFailedTransfers), + GetNewDataTransfer(DataTransferStatus.TransferState.CompletedWithFailedTransfers), + GetNewDataTransfer(DataTransferStatus.TransferState.CompletedWithFailedTransfers), + GetNewDataTransfer(DataTransferStatus.TransferState.Completed), + GetNewDataTransfer(DataTransferStatus.TransferState.Completed), + GetNewDataTransfer(DataTransferStatus.TransferState.CompletedWithSkippedTransfers) }; TransferManagerFactory factory = new TransferManagerFactory(GetDefaultManagerOptions(testDirectory.DirectoryPath)); @@ -148,9 +148,9 @@ public async Task GetTransfers_FilterMultipleStatuses() // Act DataTransferStatus[] statuses = new DataTransferStatus[] { - DataTransferStatus.Completed, - DataTransferStatus.CompletedWithFailedTransfers, - DataTransferStatus.CompletedWithSkippedTransfers }; + DataTransferStatus.TransferState.Completed, + DataTransferStatus.TransferState.CompletedWithFailedTransfers, + DataTransferStatus.TransferState.CompletedWithSkippedTransfers }; IList result = await manager.GetTransfersAsync(statuses).ToListAsync(); // Assert @@ -170,13 +170,13 @@ public async Task GetTransfers_Filtered_Empty() GetNewDataTransfer(DataTransferStatus.Queued), GetNewDataTransfer(DataTransferStatus.InProgress), GetNewDataTransfer(DataTransferStatus.InProgress), - GetNewDataTransfer(DataTransferStatus.Paused), - GetNewDataTransfer(DataTransferStatus.Paused), - GetNewDataTransfer(DataTransferStatus.CompletedWithFailedTransfers), - GetNewDataTransfer(DataTransferStatus.CompletedWithFailedTransfers), - GetNewDataTransfer(DataTransferStatus.CompletedWithFailedTransfers), - GetNewDataTransfer(DataTransferStatus.Completed), - GetNewDataTransfer(DataTransferStatus.Completed), + GetNewDataTransfer(DataTransferStatus.TransferState.Paused), + GetNewDataTransfer(DataTransferStatus.TransferState.Paused), + GetNewDataTransfer(DataTransferStatus.TransferState.CompletedWithFailedTransfers), + GetNewDataTransfer(DataTransferStatus.TransferState.CompletedWithFailedTransfers), + GetNewDataTransfer(DataTransferStatus.TransferState.CompletedWithFailedTransfers), + GetNewDataTransfer(DataTransferStatus.TransferState.Completed), + GetNewDataTransfer(DataTransferStatus.TransferState.Completed), }; TransferManagerFactory factory = new TransferManagerFactory(GetDefaultManagerOptions(testDirectory.DirectoryPath)); @@ -274,7 +274,7 @@ public async Task GetResumableTransfers_IgnoresCompleted() test.DirectoryPath, transferId1, 3 /* jobPartCount */, - DataTransferStatus.Completed); + DataTransferStatus.TransferState.Completed); string transferId2 = Guid.NewGuid().ToString(); factory.CreateStubJobPartPlanFilesAsync( diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/LocalTransferCheckpointerTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/LocalTransferCheckpointerTests.cs index 3c74cb43e158e..61dc12d9b82e7 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/LocalTransferCheckpointerTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/LocalTransferCheckpointerTests.cs @@ -906,7 +906,7 @@ public async Task SetJobTransferStatusAsync() string transferId = GetNewTransferId(); int partNumber = 0; int chunksTotal = 1; - DataTransferStatus newStatus = DataTransferStatus.Completed; + DataTransferStatus newStatus = DataTransferStatus.TransferState.Completed; JobPartPlanHeader header = CheckpointerTesting.CreateDefaultJobPartHeader( transferId: transferId, partNumber: partNumber); @@ -948,7 +948,7 @@ public async Task SetJobTransferStatusAsync_MultipleParts() // Arrange string transferId = GetNewTransferId(); int chunksTotal = 1; - DataTransferStatus newStatus = DataTransferStatus.Completed; + DataTransferStatus newStatus = DataTransferStatus.TransferState.Completed; JobPartPlanHeader header1 = CheckpointerTesting.CreateDefaultJobPartHeader( transferId: transferId, partNumber: 0); @@ -1057,7 +1057,7 @@ public void SetJobTransferStatusAsync_Error() // Arrange string transferId = GetNewTransferId(); int partNumber = 0; - DataTransferStatus newStatus = DataTransferStatus.Completed; + DataTransferStatus newStatus = DataTransferStatus.TransferState.Completed; JobPartPlanHeader header = CheckpointerTesting.CreateDefaultJobPartHeader( transferId: transferId, partNumber: partNumber); @@ -1079,7 +1079,7 @@ public async Task SetJobPartTransferStatusAsync() int partNumber = 0; int chunksTotal = 1; // originally the default is set to Queued - DataTransferStatus newStatus = DataTransferStatus.Completed; + DataTransferStatus newStatus = DataTransferStatus.TransferState.Completed; JobPartPlanHeader header = CheckpointerTesting.CreateDefaultJobPartHeader( transferId: transferId, partNumber: partNumber); @@ -1122,7 +1122,7 @@ public void SetJobPartTransferStatusAsync_Error() string transferId = GetNewTransferId(); int partNumber = 0; // originally the default is set to Queued - DataTransferStatus newStatus = DataTransferStatus.Completed; + DataTransferStatus newStatus = DataTransferStatus.TransferState.Completed; JobPartPlanHeader header = CheckpointerTesting.CreateDefaultJobPartHeader( transferId: transferId, partNumber: partNumber); diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/PauseResumeTransferTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/PauseResumeTransferTests.cs index ac86813f8634f..2f85b5004a987 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/PauseResumeTransferTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/PauseResumeTransferTests.cs @@ -254,7 +254,7 @@ public async Task TryPauseTransferAsync_Id(TransferDirection transferType) // Assert await testEventsRaised.AssertPausedCheck(); - Assert.AreEqual(DataTransferStatus.Paused, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus); // Check if Job Plan File exists in checkpointer path. JobPartPlanFileName fileName = new JobPartPlanFileName( @@ -302,7 +302,7 @@ public async Task TryPauseTransferAsync_DataTransfer(TransferDirection transferT // Assert await testEventsRaised.AssertPausedCheck(); - Assert.AreEqual(DataTransferStatus.Paused, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus); // Check if Job Plan File exists in checkpointer path. JobPartPlanFileName fileName = new JobPartPlanFileName( @@ -366,12 +366,12 @@ public async Task TryPauseTransferAsync_AlreadyPaused(TransferDirection transfer // Assert await testEventsRaised.AssertPausedCheck(); - Assert.AreEqual(DataTransferStatus.Paused, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus); CancellationTokenSource cancellationTokenSource2 = new CancellationTokenSource(TimeSpan.FromSeconds(10)); await transferManager.PauseTransferIfRunningAsync(transfer.Id, cancellationTokenSource2.Token); - Assert.AreEqual(DataTransferStatus.Paused, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus); // Check if Job Plan File exists in checkpointer path. JobPartPlanFileName fileName = new JobPartPlanFileName( @@ -426,7 +426,7 @@ public async Task PauseThenResumeTransferAsync(TransferDirection transferType) await transferManager.PauseTransferIfRunningAsync(transfer.Id, cancellationTokenSource.Token); // Assert - Confirm we've paused - Assert.AreEqual(DataTransferStatus.Paused, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus); await testEventsRaised.AssertPausedCheck(); // Act - Resume Job @@ -443,7 +443,7 @@ public async Task PauseThenResumeTransferAsync(TransferDirection transferType) // Assert await testEventRaised2.AssertSingleCompletedCheck(); - Assert.AreEqual(DataTransferStatus.Completed, resumeTransfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, resumeTransfer.TransferStatus); Assert.IsTrue(resumeTransfer.HasCompleted); // Verify transfer @@ -498,7 +498,7 @@ public async Task ResumeTransferAsync(TransferDirection transferType) await transferManager.PauseTransferIfRunningAsync(transfer.Id, cancellationTokenSource.Token); // Assert - Confirm we've paused - Assert.AreEqual(DataTransferStatus.Paused, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus); await testEventsRaised.AssertPausedCheck(); // Act - Resume Job @@ -515,7 +515,7 @@ public async Task ResumeTransferAsync(TransferDirection transferType) // Assert await testEventRaised2.AssertSingleCompletedCheck(); - Assert.AreEqual(DataTransferStatus.Completed, resumeTransfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, resumeTransfer.TransferStatus); Assert.IsTrue(resumeTransfer.HasCompleted); // Verify transfer @@ -705,7 +705,7 @@ public async Task TryPauseTransferAsync_Id_Directory(TransferDirection transferT // Assert await testEventsRaised.AssertPausedCheck(); - Assert.AreEqual(DataTransferStatus.Paused, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus); } [Ignore("https://github.com/Azure/azure-sdk-for-net/issues/35439")] @@ -750,7 +750,7 @@ public async Task TryPauseTransferAsync_DataTransfer_Directory(TransferDirection // Assert await testEventsRaised.AssertPausedCheck(); - Assert.AreEqual(DataTransferStatus.Paused, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus); } [Ignore("https://github.com/Azure/azure-sdk-for-net/issues/35439")] @@ -795,13 +795,13 @@ public async Task TryPauseTransferAsync_AlreadyPaused_Directory(TransferDirectio // Assert await testEventsRaised.AssertPausedCheck(); - Assert.AreEqual(DataTransferStatus.Paused, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus); CancellationTokenSource cancellationTokenSource2 = new CancellationTokenSource(TimeSpan.FromSeconds(10)); await transferManager.PauseTransferIfRunningAsync(transfer.Id, cancellationTokenSource2.Token); await testEventsRaised.AssertPausedCheck(); - Assert.AreEqual(DataTransferStatus.Paused, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus); } [Ignore("https://github.com/Azure/azure-sdk-for-net/issues/35439")] @@ -852,7 +852,7 @@ public async Task PauseThenResumeTransferAsync_Directory(TransferDirection trans await transferManager.PauseTransferIfRunningAsync(transfer.Id, cancellationTokenSource.Token); // Assert - Confirm we've paused - Assert.AreEqual(DataTransferStatus.Paused, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus); await testEventsRaised.AssertPausedCheck(); // Act - Resume Job @@ -869,7 +869,7 @@ public async Task PauseThenResumeTransferAsync_Directory(TransferDirection trans // Assert await testEventRaised2.AssertContainerCompletedCheck(partCount); - Assert.AreEqual(DataTransferStatus.Completed, resumeTransfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, resumeTransfer.TransferStatus); Assert.IsTrue(resumeTransfer.HasCompleted); // Verify transfer @@ -929,7 +929,7 @@ public async Task ResumeTransferAsync_Directory(TransferDirection transferType) await transferManager.PauseTransferIfRunningAsync(transfer.Id, cancellationTokenSource.Token); // Assert - Confirm we've paused - Assert.AreEqual(DataTransferStatus.Paused, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus); await testEventsRaised.AssertPausedCheck(); // Act - Resume Job @@ -946,7 +946,7 @@ public async Task ResumeTransferAsync_Directory(TransferDirection transferType) // Assert await testEventsRaised2.AssertContainerCompletedCheck(partCount); - Assert.AreEqual(DataTransferStatus.Completed, resumeTransfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, resumeTransfer.TransferStatus); Assert.IsTrue(resumeTransfer.HasCompleted); // Verify transfer diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/ProgressHandlerTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/ProgressHandlerTests.cs index a2bea0c44de33..149808a9dd463 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/ProgressHandlerTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/ProgressHandlerTests.cs @@ -344,7 +344,7 @@ public async Task ProgressHandler_PauseResume(int delayInMs) // Pause transfer CancellationTokenSource tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30)); await transferManager.PauseTransferIfRunningAsync(transfer.Id, tokenSource.Token); - Assert.AreEqual(DataTransferStatus.Paused, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus); // Record the current number of progress updates to use during assertions int pause = progressHandler.Updates.Count; @@ -360,7 +360,7 @@ public async Task ProgressHandler_PauseResume(int delayInMs) await resumeTransfer.WaitForCompletionAsync(tokenSource.Token); // Assert - Assert.AreEqual(DataTransferStatus.Completed, resumeTransfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, resumeTransfer.TransferStatus); ProgressHandlerAsserts.AssertFileProgress(progressHandler.Updates, 5, pauseIndexes: pause); ProgressHandlerAsserts.AssertBytesTransferred(progressHandler.Updates, _expectedBytesTransferred); } diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferDownloadDirectoryTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferDownloadDirectoryTests.cs index e3c7b3212169e..cf2f8f3720a29 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferDownloadDirectoryTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferDownloadDirectoryTests.cs @@ -75,7 +75,7 @@ private async Task DownloadBlobDirectoryAndVerify( await testEventsRaised.AssertContainerCompletedCheck(sourceFiles.Count); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); // List all files in source blob folder path List blobNames = new List(); @@ -221,7 +221,7 @@ public async Task DownloadDirectoryAsync_Empty() await transfer.WaitForCompletionAsync(cancellationTokenSource.Token); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); List localItemsAfterDownload = Directory.GetFiles(destinationFolder, "*", SearchOption.AllDirectories).ToList(); @@ -515,7 +515,7 @@ public async Task StartTransfer_AwaitCompletion() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); await testEventsRaised.AssertContainerCompletedCheck(4); } @@ -551,7 +551,7 @@ public async Task StartTransfer_AwaitCompletion_Failed() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("Cannot overwrite file.")); await testEventsRaised.AssertContainerCompletedWithFailedCheck(1); } @@ -589,7 +589,7 @@ public async Task StartTransfer_AwaitCompletion_Skipped() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithSkippedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithSkippedTransfers, transfer.TransferStatus); await testEventsRaised.AssertContainerCompletedWithSkippedCheck(1); } @@ -619,7 +619,7 @@ public async Task StartTransfer_EnsureCompleted() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); await testEventsRaised.AssertContainerCompletedCheck(4); } @@ -655,7 +655,7 @@ public async Task StartTransfer_EnsureCompleted_Failed() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("Cannot overwrite file.")); await testEventsRaised.AssertContainerCompletedWithFailedCheck(1); } @@ -693,7 +693,7 @@ public async Task StartTransfer_EnsureCompleted_Skipped() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithSkippedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithSkippedTransfers, transfer.TransferStatus); await testEventsRaised.AssertContainerCompletedWithSkippedCheck(1); } @@ -732,7 +732,7 @@ public async Task StartTransfer_EnsureCompleted_Failed_SmallChunks() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("Cannot overwrite file.")); await testEventsRaised.AssertContainerCompletedWithFailedCheck(1); } diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferDownloadTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferDownloadTests.cs index ee0478b07accf..6d58d377656bf 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferDownloadTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferDownloadTests.cs @@ -117,7 +117,7 @@ private async Task DownloadBlockBlobsAndVerify( options[i].TransferStatusChanged += (TransferStatusEventArgs args) => { // Assert - if (args.StorageTransferStatus == DataTransferStatus.Completed) + if (args.StorageTransferStatus == DataTransferStatus.TransferState.Completed) { completed = true; } @@ -169,7 +169,7 @@ private async Task DownloadBlockBlobsAndVerify( // Verify Download await downloadedBlobInfo[i].EventsRaised.AssertSingleCompletedCheck(); - Assert.AreEqual(DataTransferStatus.Completed, downloadedBlobInfo[i].DataTransfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, downloadedBlobInfo[i].DataTransfer.TransferStatus); CheckDownloadFile(downloadedBlobInfo[i].SourceLocalPath, downloadedBlobInfo[i].DestinationLocalPath); }; } @@ -285,7 +285,7 @@ public async Task BlockBlobToLocal_Skip_Exists() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithSkippedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithSkippedTransfers, transfer.TransferStatus); Assert.IsTrue(skippedSeen); FileInfo destFileInfo = new FileInfo(destFile); Assert.IsTrue(destFileInfo.Length == 0); @@ -327,7 +327,7 @@ public async Task BlockBlobToLocal_Failure_Exists() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); await testEventsRaised.AssertSingleFailedCheck(); FileInfo destFileInfo = new FileInfo(destFile); Assert.IsTrue(destFileInfo.Length == 0); @@ -692,7 +692,7 @@ public async Task AppendBlobToLocal_Skip_Exists() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithSkippedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithSkippedTransfers, transfer.TransferStatus); await testEventsRaised.AssertSingleSkippedCheck(); FileInfo destFileInfo = new FileInfo(destFile); Assert.IsTrue(destFileInfo.Length == 0); @@ -735,7 +735,7 @@ public async Task AppendBlobToLocal_Failure_Exists() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); await testEventsRaised.AssertSingleFailedCheck(); FileInfo destFileInfo = new FileInfo(destFile); Assert.IsTrue(destFileInfo.Length == 0); @@ -1152,7 +1152,7 @@ public async Task PageBlobToLocal_Skip_Exists() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithSkippedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithSkippedTransfers, transfer.TransferStatus); await testEventsRaised.AssertSingleSkippedCheck(); FileInfo destFileInfo = new FileInfo(destFile); Assert.IsTrue(destFileInfo.Length == 0); @@ -1195,7 +1195,7 @@ public async Task PageBlobToLocal_Failure_Exists() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); await testEventsRaised.AssertSingleFailedCheck(); FileInfo destFileInfo = new FileInfo(destFile); Assert.IsTrue(destFileInfo.Length == 0); @@ -1415,7 +1415,7 @@ public async Task StartTransfer_AwaitCompletion() failureTransferHolder.AssertUnexpectedFailureCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); } [RecordedTest] @@ -1446,7 +1446,7 @@ public async Task StartTransfer_AwaitCompletion_Failed() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); await testEventRaised.AssertSingleFailedCheck(); Assert.AreEqual(1, testEventRaised.FailedEvents.Count); Assert.IsTrue(testEventRaised.FailedEvents.First().Exception.Message.Contains("Cannot overwrite file.")); @@ -1481,7 +1481,7 @@ public async Task StartTransfer_AwaitCompletion_Skipped() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithSkippedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithSkippedTransfers, transfer.TransferStatus); await testEventRaised.AssertSingleSkippedCheck(); } @@ -1514,7 +1514,7 @@ public async Task StartTransfer_EnsureCompleted() testEventRaised.AssertUnexpectedFailureCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); } [RecordedTest] @@ -1545,7 +1545,7 @@ public async Task StartTransfer_EnsureCompleted_Failed() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); await testEventsRaised.AssertSingleFailedCheck(); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("Cannot overwrite file.")); } @@ -1580,7 +1580,7 @@ public async Task StartTransfer_EnsureCompleted_Skipped() await testEventsRaised.AssertSingleSkippedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithSkippedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithSkippedTransfers, transfer.TransferStatus); } #endregion } diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferSyncCopyDirectoryTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferSyncCopyDirectoryTests.cs index 56e367a2cd120..83e3fddb7445b 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferSyncCopyDirectoryTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferSyncCopyDirectoryTests.cs @@ -78,7 +78,7 @@ private async Task CopyBlobDirectoryAndVerify( await testEventFailed.AssertContainerCompletedCheck(sourceFiles.Count); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); // List all files in source blob folder path List sourceblobNames = new List(); @@ -245,7 +245,7 @@ public async Task BlockBlobDirectoryToDirectory_EmptyFolder() CancellationTokenSource tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30)); await transfer.WaitForCompletionAsync(tokenSource.Token); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); // Assert List blobs = ((List)await test.Container.GetBlobsAsync().ToListAsync()) @@ -586,7 +586,7 @@ public async Task StartTransfer_AwaitCompletion() testEventsRaised.AssertUnexpectedFailureCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); } [Test] @@ -616,7 +616,7 @@ public async Task StartTransfer_AwaitCompletion_Failed() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); await testEventsRaised.AssertContainerCompletedWithFailedCheck(1); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); } @@ -649,7 +649,7 @@ public async Task StartTransfer_AwaitCompletion_Skipped() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithSkippedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithSkippedTransfers, transfer.TransferStatus); await testEventsRaised.AssertContainerCompletedWithSkippedCheck(1); } @@ -674,7 +674,7 @@ public async Task StartTransfer_EnsureCompleted() testEventsRaised.AssertUnexpectedFailureCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); } [Test] @@ -704,7 +704,7 @@ public async Task StartTransfer_EnsureCompleted_Failed() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); await testEventsRaised.AssertContainerCompletedWithFailedCheck(1); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); } @@ -738,7 +738,7 @@ public async Task StartTransfer_EnsureCompleted_Skipped() testEventsRaised.AssertUnexpectedFailureCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithSkippedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithSkippedTransfers, transfer.TransferStatus); } [Test] @@ -773,7 +773,7 @@ public async Task StartTransfer_EnsureCompleted_Failed_SmallChunks() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); await testEventsRaised.AssertContainerCompletedWithFailedCheck(1); } diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferSyncCopyTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferSyncCopyTests.cs index 307dd7c781de0..e073882432966 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferSyncCopyTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferSyncCopyTests.cs @@ -165,7 +165,7 @@ private async Task CopyBlockBlobsAndVerify( CancellationTokenSource tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(waitTimeInSec)); await copyBlobInfo[i].DataTransfer.WaitForCompletionAsync(tokenSource.Token); Assert.IsTrue(copyBlobInfo[i].DataTransfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.Completed, copyBlobInfo[i].DataTransfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, copyBlobInfo[i].DataTransfer.TransferStatus); // Verify Copy - using original source File and Copying the destination await copyBlobInfo[i].testEventsRaised.AssertSingleCompletedCheck(); @@ -385,7 +385,7 @@ public async Task BlockBlobToBlockBlob_Skip_Exists() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithSkippedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithSkippedTransfers, transfer.TransferStatus); await testEventsRaised.AssertSingleSkippedCheck(); Assert.IsTrue(await destinationClient.ExistsAsync()); // Verify Upload - That we skipped over and didn't reupload something new. @@ -437,7 +437,7 @@ public async Task BlockBlobToBlockBlob_Failure_Exists() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); Assert.IsTrue(await destinationClient.ExistsAsync()); await testEventsRaised.AssertSingleFailedCheck(); Assert.NotNull(testEventsRaised.FailedEvents.First().Exception, "Excepted failure: Overwrite failure was supposed to be raised during the test"); @@ -526,7 +526,7 @@ public async Task AppendBlobToAppendBlob_Error() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); await testEventsRaised.AssertSingleFailedCheck(); Assert.NotNull(testEventsRaised.FailedEvents.First().Exception, "Excepted failure: Failure was supposed to be raised during the test"); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); @@ -579,7 +579,7 @@ public async Task PageBlobToPageBlob_Error() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); await testEventsRaised.AssertSingleFailedCheck(); Assert.NotNull(testEventsRaised.FailedEvents.First().Exception, "Excepted failure: Failure was supposed to be raised during the test"); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); @@ -649,7 +649,7 @@ public async Task StartTransfer_AwaitCompletion() await testEventsRaised.AssertSingleCompletedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); } [RecordedTest] @@ -678,7 +678,7 @@ public async Task StartTransfer_AwaitCompletion_Failed() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); await testEventsRaised.AssertSingleFailedCheck(); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); } @@ -711,7 +711,7 @@ public async Task StartTransfer_AwaitCompletion_Skipped() await testEventsRaised.AssertSingleSkippedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithSkippedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithSkippedTransfers, transfer.TransferStatus); } [RecordedTest] @@ -734,7 +734,7 @@ public async Task StartTransfer_EnsureCompleted() await testEventsRaised.AssertSingleCompletedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); } [RecordedTest] @@ -764,7 +764,7 @@ public async Task StartTransfer_EnsureCompleted_Failed() await testEventsRaised.AssertSingleFailedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); } @@ -796,7 +796,7 @@ public async Task StartTransfer_EnsureCompleted_Skipped() await testEventsRaised.AssertSingleSkippedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithSkippedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithSkippedTransfers, transfer.TransferStatus); } #endregion } diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferUploadDirectoryTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferUploadDirectoryTests.cs index 3f0c961d57b2c..543f5cdbcfed8 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferUploadDirectoryTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferUploadDirectoryTests.cs @@ -71,7 +71,7 @@ private async Task UploadBlobDirectoryAndVerify( await testEventsRaised.AssertContainerCompletedCheck(files.Count); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); // Assert - Check Response List blobs = ((List)await destinationContainer.GetBlobsAsync(prefix: destinationPrefix).ToListAsync()) @@ -734,7 +734,7 @@ public async Task StartTransfer_AwaitCompletion() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); await testEventsRaised.AssertContainerCompletedCheck(4); } @@ -768,7 +768,7 @@ public async Task StartTransfer_AwaitCompletion_Failed() await testEventsRaised.AssertContainerCompletedWithFailedCheck(1); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); } @@ -803,7 +803,7 @@ public async Task StartTransfer_AwaitCompletion_Skipped() await testEventsRaised.AssertContainerCompletedWithSkippedCheck(1); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithSkippedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithSkippedTransfers, transfer.TransferStatus); } [Test] @@ -832,7 +832,7 @@ public async Task StartTransfer_EnsureCompleted() await testEventsRaised.AssertContainerCompletedCheck(4); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); } [Test] @@ -865,7 +865,7 @@ public async Task StartTransfer_EnsureCompleted_Failed() await testEventsRaised.AssertContainerCompletedWithFailedCheck(1); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); } @@ -900,7 +900,7 @@ public async Task StartTransfer_EnsureCompleted_Skipped() await testEventsRaised.AssertContainerCompletedWithSkippedCheck(1); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithSkippedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithSkippedTransfers, transfer.TransferStatus); } [Test] @@ -935,7 +935,7 @@ public async Task StartTransfer_EnsureCompleted_Failed_SmallChunks() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); await testEventsRaised.AssertContainerCompletedWithFailedCheck(1); } diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferUploadTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferUploadTests.cs index b25ac03a1414e..b83d62dcaae37 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferUploadTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferUploadTests.cs @@ -302,7 +302,7 @@ public async Task LocalToBlockBlob_Skip_Exists() await testEventsRaised.AssertSingleSkippedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithSkippedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithSkippedTransfers, transfer.TransferStatus); Assert.IsTrue(await destinationClient.ExistsAsync()); // Verify Upload - That we skipped over and didn't reupload something new. using (FileStream fileStream = File.OpenRead(originalSourceFile)) @@ -349,7 +349,7 @@ public async Task LocalToBlockBlob_Failure_Exists() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); Assert.IsTrue(await destinationClient.ExistsAsync()); await testEventRaised.AssertSingleFailedCheck(); Assert.NotNull(testEventRaised.FailedEvents.First().Exception, "Excepted failure: Overwrite failure was supposed to be raised during the test"); @@ -578,7 +578,7 @@ private async Task UploadPageBlobsAndVerify( CancellationTokenSource tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(waitTimeInSec)); await uploadedBlobInfo[i].DataTransfer.WaitForCompletionAsync(tokenSource.Token); Assert.IsTrue(uploadedBlobInfo[i].DataTransfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.Completed, uploadedBlobInfo[i].DataTransfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, uploadedBlobInfo[i].DataTransfer.TransferStatus); // Verify Upload await uploadedBlobInfo[i].EventsRaised.AssertSingleCompletedCheck(); @@ -692,7 +692,7 @@ public async Task LocalToPageBlob_Skip_Exists() await testEventsRaised.AssertSingleSkippedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithSkippedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithSkippedTransfers, transfer.TransferStatus); Assert.IsTrue(await destinationClient.ExistsAsync()); // Verify Upload - That we skipped over and didn't reupload something new. using (FileStream fileStream = File.OpenRead(originalSourceFile)) @@ -739,7 +739,7 @@ public async Task LocalToPageBlob_Failure_Exists() await testEventsRaised.AssertSingleFailedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); Assert.IsTrue(await destinationClient.ExistsAsync()); Assert.NotNull(testEventsRaised.FailedEvents.First().Exception, "Excepted failure: Overwrite failure was supposed to be raised during the test"); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("The specified blob already exists.")); @@ -997,7 +997,7 @@ private async Task UploadAppendBlobsAndVerify( CancellationTokenSource tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(waitTimeInSec)); await uploadedBlobInfo[i].DataTransfer.WaitForCompletionAsync(tokenSource.Token); Assert.IsTrue(uploadedBlobInfo[i].DataTransfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.Completed, uploadedBlobInfo[i].DataTransfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, uploadedBlobInfo[i].DataTransfer.TransferStatus); // Verify Upload await uploadedBlobInfo[i].EventsRaised.AssertSingleCompletedCheck(); @@ -1133,7 +1133,7 @@ public async Task LocalToAppendBlob_Skip_Exists() await testEventsRaised.AssertSingleSkippedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithSkippedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithSkippedTransfers, transfer.TransferStatus); Assert.IsTrue(await destinationClient.ExistsAsync()); // Verify Upload - That we skipped over and didn't reupload something new. using (FileStream fileStream = File.OpenRead(originalSourceFile)) @@ -1180,7 +1180,7 @@ public async Task LocalToAppendBlob_Failure_Exists() await testEventsRaised.AssertSingleFailedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); Assert.IsTrue(await destinationClient.ExistsAsync()); Assert.NotNull(testEventsRaised.FailedEvents.First().Exception, "Excepted failure: Overwrite failure was supposed to be raised during the test"); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("The specified blob already exists.")); @@ -1411,7 +1411,7 @@ public async Task StartTransfer_AwaitCompletion() await testEventsRaised.AssertSingleCompletedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); } [RecordedTest] @@ -1441,7 +1441,7 @@ public async Task StartTransfer_AwaitCompletion_Failed() await testEventsRaised.AssertSingleFailedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); } @@ -1473,7 +1473,7 @@ public async Task StartTransfer_AwaitCompletion_Skipped() await testEventsRaised.AssertSingleSkippedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithSkippedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithSkippedTransfers, transfer.TransferStatus); } [RecordedTest] @@ -1496,7 +1496,7 @@ public async Task StartTransfer_EnsureCompleted() await testEventsRaised.AssertSingleCompletedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); } [RecordedTest] @@ -1526,7 +1526,7 @@ public async Task StartTransfer_EnsureCompleted_Failed() await testEventsRaised.AssertSingleFailedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); } @@ -1558,7 +1558,7 @@ public async Task StartTransfer_EnsureCompleted_Skipped() await testEventsRaised.AssertSingleSkippedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.CompletedWithSkippedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithSkippedTransfers, transfer.TransferStatus); } #endregion diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/TestEventsRaised.cs b/sdk/storage/Azure.Storage.DataMovement/tests/TestEventsRaised.cs index 15e47868ca365..16bef0f7eef3d 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/TestEventsRaised.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/TestEventsRaised.cs @@ -116,7 +116,7 @@ public void AssertUnexpectedFailureCheck() /// /// This asserts that the expected events occurred during a single transfer that is expected - /// to have a at the end without any skips + /// to have a at the end without any skips /// or failures. /// public async Task AssertSingleCompletedCheck() @@ -129,13 +129,13 @@ public async Task AssertSingleCompletedCheck() CollectionAssert.AreEqual( new DataTransferStatus[] { DataTransferStatus.InProgress, - DataTransferStatus.Completed }, + DataTransferStatus.TransferState.Completed }, StatusEvents.Select(e => e.StorageTransferStatus)); } /// /// This asserts that the expected events occurred during a single transfer that is expected - /// to have a at the end without any + /// to have a at the end without any /// or failures. /// public async Task AssertSingleSkippedCheck() @@ -150,13 +150,13 @@ public async Task AssertSingleSkippedCheck() CollectionAssert.AreEqual( new DataTransferStatus[] { DataTransferStatus.InProgress, - DataTransferStatus.CompletedWithSkippedTransfers }, + DataTransferStatus.TransferState.CompletedWithSkippedTransfers }, StatusEvents.Select(e => e.StorageTransferStatus)); } /// /// This asserts that the expected events occurred during a single transfer that is expected - /// to have a at the end without any skips. + /// to have a at the end without any skips. /// public async Task AssertSingleFailedCheck() { @@ -172,13 +172,13 @@ public async Task AssertSingleFailedCheck() new DataTransferStatus[] { DataTransferStatus.InProgress, DataTransferStatus.CancellationInProgress, - DataTransferStatus.CompletedWithFailedTransfers }, + DataTransferStatus.TransferState.CompletedWithFailedTransfers }, StatusEvents.Select(e => e.StorageTransferStatus)); } /// /// This asserts that the expected events occurred during a container transfer that is expected - /// to have a at the end without any skips + /// to have a at the end without any skips /// or failures. /// /// @@ -194,13 +194,13 @@ public async Task AssertContainerCompletedCheck(int transferCount) CollectionAssert.AreEqual( new DataTransferStatus[] { DataTransferStatus.InProgress, - DataTransferStatus.Completed }, + DataTransferStatus.TransferState.Completed }, StatusEvents.Select(e => e.StorageTransferStatus)); } /// /// This asserts that the expected events occurred during a container transfer that is expected - /// to have a at the end without any skips. + /// to have a at the end without any skips. /// Assuming was set. /// /// @@ -225,13 +225,13 @@ public async Task AssertContainerCompletedWithFailedCheck(int expectedFailureCou new DataTransferStatus[] { DataTransferStatus.InProgress, DataTransferStatus.CancellationInProgress, - DataTransferStatus.CompletedWithFailedTransfers }, + DataTransferStatus.TransferState.CompletedWithFailedTransfers }, StatusEvents.Select(e => e.StorageTransferStatus)); } /// /// This asserts that the expected events occurred during a container transfer that is expected - /// to have a at the end without any skips. + /// to have a at the end without any skips. /// Assuming was set. /// /// @@ -255,13 +255,13 @@ public async Task AssertContainerCompletedWithFailedCheckContinue(int expectedFa CollectionAssert.AreEqual( new DataTransferStatus[] { DataTransferStatus.InProgress, - DataTransferStatus.CompletedWithFailedTransfers }, + DataTransferStatus.TransferState.CompletedWithFailedTransfers }, StatusEvents.Select(e => e.StorageTransferStatus)); } /// /// This asserts that the expected events occurred during a container transfer that is expected - /// to have a at the end without any failures. + /// to have a at the end without any failures. /// /// /// Expected amount of skipped single transfers to occur within the container transfers. @@ -275,7 +275,7 @@ public async Task AssertContainerCompletedWithSkippedCheck(int expectedSkipCount CollectionAssert.AreEqual( new DataTransferStatus[] { DataTransferStatus.InProgress, - DataTransferStatus.CompletedWithSkippedTransfers }, + DataTransferStatus.TransferState.CompletedWithSkippedTransfers }, StatusEvents.Select(e => e.StorageTransferStatus)); } @@ -288,7 +288,7 @@ public async Task AssertPausedCheck() CollectionAssert.AreEqual( new DataTransferStatus[] { DataTransferStatus.InProgress, - DataTransferStatus.Paused }, + DataTransferStatus.TransferState.Paused }, StatusEvents.Select(e => e.StorageTransferStatus)); } From a2ab1b341df832de0a1bd2f30aa9a41e5409fb14 Mon Sep 17 00:00:00 2001 From: Amanda Nguyen Date: Wed, 16 Aug 2023 15:09:45 -0700 Subject: [PATCH 02/13] WIP --- .../samples/Sample01b_HelloWorldAsync.cs | 2 +- .../src/DataTransferStatus.cs | 40 ++++++----- .../src/JobPartInternal.cs | 69 +++++++++---------- .../src/ServiceToServiceJobPart.cs | 4 +- .../src/Shared/DataMovementConstants.cs | 16 ++++- .../src/Shared/JobPlan/JobPartPlanHeader.cs | 50 +++++++++++--- .../src/Shared/LocalTransferCheckpointer.cs | 2 +- .../src/Shared/TransferCheckpointer.cs | 6 +- .../src/Shared/TransferManager.cs | 6 +- .../src/StreamToUriJobPart.cs | 4 +- .../src/TransferJobInternal.cs | 2 +- .../src/UriToStreamJobPart.cs | 2 +- .../tests/Shared/CheckpointerTesting.cs | 2 +- 13 files changed, 125 insertions(+), 80 deletions(-) diff --git a/sdk/storage/Azure.Storage.DataMovement.Blobs/samples/Sample01b_HelloWorldAsync.cs b/sdk/storage/Azure.Storage.DataMovement.Blobs/samples/Sample01b_HelloWorldAsync.cs index 0722f36d6fa3b..63b020d10f6fe 100644 --- a/sdk/storage/Azure.Storage.DataMovement.Blobs/samples/Sample01b_HelloWorldAsync.cs +++ b/sdk/storage/Azure.Storage.DataMovement.Blobs/samples/Sample01b_HelloWorldAsync.cs @@ -527,7 +527,7 @@ public async Task UploadDirectory_EventHandler_SasAsync() DataTransferOptions transferOptions = new DataTransferOptions(); transferOptions.TransferStatusChanged += (TransferStatusEventArgs args) => { - if (args.StorageTransferStatus == DataTransferStatus.TransferState.Completed) + if (args.StorageTransferStatus.HasCompletedSuccessfully) { using (StreamWriter logStream = File.AppendText(logFile)) { diff --git a/sdk/storage/Azure.Storage.DataMovement/src/DataTransferStatus.cs b/sdk/storage/Azure.Storage.DataMovement/src/DataTransferStatus.cs index dba488eda0cd6..5be76968ecd2d 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/DataTransferStatus.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/DataTransferStatus.cs @@ -19,17 +19,17 @@ public enum TransferState /// /// Default value. /// - None, + None = 0, /// /// The transfer has been queued up but has not yet started. /// - Queued, + Queued = 1, /// /// The transfer has started, but has not yet completed. /// - InProgress, + InProgress = 2, /// /// The transfer has started and is in the process of being paused. @@ -37,7 +37,7 @@ public enum TransferState /// Transfer can be stopped if /// or is called. /// - Pausing, // (Used to be PauseInProgress) + Pausing = 3, /// /// The transfer has started and is in the process of being stopped. @@ -45,29 +45,42 @@ public enum TransferState /// Transfer can be stopped if is /// enabled in the . /// - Stopping, // (Used to be CancellationInProgress) + Stopping = 4, /// /// The transfer has been paused. When transfer is paused /// (e.g. see ) /// during the transfer, this will be the value. /// - Paused, + Paused = 5, /// /// The transfer has come to a completed state. If the transfer has started and /// has fully stopped will also come to this state. /// - Completed + Completed = 6 } + /// + /// Defines the state of the transfer. + /// + public TransferState State { get; internal set; } + + /// + /// Represents if the transfer has completed successfully without any failure or skipped items. + /// + public bool HasCompletedSuccessfully => + (State == TransferState.Completed) && + !HasFailedItems && + !HasSkippedItems; + /// /// Represents if transfer has any failure items. /// /// If set to `true`, the transfer has at least one failure item. /// If set to `false`, the transfer currently has no failures. /// - public bool HasFailureItems { get; internal set; } + public bool HasFailedItems { get; internal set; } /// /// Represents if transfer has any skipped items. @@ -80,18 +93,13 @@ public enum TransferState /// public bool HasSkippedItems { get; internal set; } - /// - /// Defines the state of the transfer. - /// - public TransferState State { get; internal set; } - /// /// Constructor to set the initial state to with no failures or skipped items. /// protected internal DataTransferStatus() { State = TransferState.Queued; - HasFailureItems = false; + HasFailedItems = false; HasSkippedItems = false; } @@ -101,11 +109,11 @@ protected internal DataTransferStatus() protected internal DataTransferStatus(TransferState state, bool hasFailureItems, bool hasSkippedItems) { State = state; - HasFailureItems = hasFailureItems; + HasFailedItems = hasFailureItems; HasSkippedItems = hasSkippedItems; } - internal bool IsCompletedWithFailedItems => State.Equals(TransferState.Completed) && HasFailureItems; + internal bool IsCompletedWithFailedItems => State.Equals(TransferState.Completed) && HasFailedItems; internal bool IsCompletedWithSkippedItems => State.Equals(TransferState.Completed) && HasSkippedItems; } } diff --git a/sdk/storage/Azure.Storage.DataMovement/src/JobPartInternal.cs b/sdk/storage/Azure.Storage.DataMovement/src/JobPartInternal.cs index bc8638d6c6e69..891b864d6065f 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/JobPartInternal.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/JobPartInternal.cs @@ -169,12 +169,12 @@ internal JobPartInternal( SyncAsyncEventHandler singleTransferEventHandler, ClientDiagnostics clientDiagnostics, CancellationToken cancellationToken, - DataTransferStatus jobPartStatus = DataTransferStatus.Queued, + DataTransferStatus jobPartStatus = default, long? length = default) { Argument.AssertNotNull(clientDiagnostics, nameof(clientDiagnostics)); - JobPartStatus = jobPartStatus; + JobPartStatus = jobPartStatus != default ? jobPartStatus : new DataTransferStatus(); PartNumber = partNumber; _dataTransfer = dataTransfer; _sourceResource = sourceResource; @@ -263,24 +263,25 @@ await QueueChunk( /// and any chunks is still processing to be cancelled is will be set to /// until the chunks finish then it will be set to . /// - /// If the status is set to - /// and any chunks is still processing to be cancelled is will be set to - /// until the chunks finish then it will be set to . + /// If the part status is set to but has + /// + /// and any chunks is still processing to be cancelled is will be set to + /// until the chunks finish then it will be set to . /// /// The task to wait until the cancellation has been triggered. internal async Task TriggerCancellationAsync() { // Set the status to Pause/CancellationInProgress - if (DataTransferStatus.TransferState.Pausing == _dataTransfer.TransferStatus) + if (DataTransferStatus.TransferState.Pausing == _dataTransfer.TransferStatus.State) { // It's possible that the status hasn't propagated down to the job part // status yet here since we pause from the data transfer object. - await OnTransferStatusChanged(DataTransferStatus.TransferState.Pausing).ConfigureAwait(false); + await OnTransferStateChanged(DataTransferStatus.TransferState.Pausing).ConfigureAwait(false); } else { // It's a cancellation if a pause wasn't called. - await OnTransferStatusChanged(DataTransferStatus.CancellationInProgress).ConfigureAwait(false); + await OnTransferStateChanged(DataTransferStatus.TransferState.Stopping).ConfigureAwait(false); } await CleanupAbortedJobPartAsync().ConfigureAwait(false); } @@ -288,52 +289,41 @@ internal async Task TriggerCancellationAsync() /// /// To change all transfer statues at the same time /// - /// - internal async Task OnTransferStatusChanged(DataTransferStatus transferStatus) + /// + internal async Task OnTransferStateChanged(DataTransferStatus.TransferState transferState) { bool statusChanged = false; lock (_statusLock) { - if (transferStatus != DataTransferStatus.TransferState.None - && JobPartStatus != transferStatus) + if (transferState != DataTransferStatus.TransferState.None + && JobPartStatus.State != transferState) { statusChanged = true; - JobPartStatus = transferStatus; + JobPartStatus.State = transferState; } } if (statusChanged) { // Progress tracking, do before invoking the event below - if (transferStatus == DataTransferStatus.InProgress) + if (transferState == DataTransferStatus.TransferState.InProgress) { _progressTracker.IncrementInProgressFiles(); } - else if (transferStatus == DataTransferStatus.TransferState.Completed) - { - _progressTracker.IncrementCompletedFiles(); - } - else if (transferStatus == DataTransferStatus.TransferState.CompletedWithSkippedTransfers) - { - _progressTracker.IncrementSkippedFiles(); - } - else if (transferStatus == DataTransferStatus.TransferState.CompletedWithFailedTransfers) - { - _progressTracker.IncrementFailedFiles(); - } - if (JobPartStatus == DataTransferStatus.TransferState.Completed) + if (JobPartStatus.HasCompletedSuccessfully) { + _progressTracker.IncrementCompletedFiles(); await InvokeSingleCompletedArg().ConfigureAwait(false); } // Set the status in the checkpointer - await SetCheckpointerStatus(transferStatus).ConfigureAwait(false); + await SetCheckpointerState(transferState).ConfigureAwait(false); // TODO: change to RaiseAsync await PartTransferStatusEventHandler.RaiseAsync( new TransferStatusEventArgs( _dataTransfer.Id, - transferStatus, + JobPartStatus, false, _cancellationToken), nameof(JobPartInternal), @@ -390,7 +380,8 @@ await TransferSkippedEventHandler.RaiseAsync( ClientDiagnostics) .ConfigureAwait(false); } - await OnTransferStatusChanged(DataTransferStatus.TransferState.CompletedWithSkippedTransfers).ConfigureAwait(false); + _progressTracker.IncrementSkippedFiles(); + await OnTransferStateChanged(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); } /// @@ -418,6 +409,7 @@ await TransferFailedEventHandler.RaiseAsync( ClientDiagnostics) .ConfigureAwait(false); } + _progressTracker.IncrementFailedFiles(); } // Trigger job cancellation if the failed handler is enabled await TriggerCancellationAsync().ConfigureAwait(false); @@ -452,7 +444,7 @@ public async virtual Task CleanupAbortedJobPartAsync() public async virtual Task AddJobPartToCheckpointerAsync(int chunksTotal, bool isFinalPart) { JobPartPlanHeader header = this.ToJobPartPlanHeader( - jobStatus: DataTransferStatus.InProgress, + jobStatus: DataTransferStatus.TransferState.InProgress, isFinalPart: isFinalPart); using (Stream stream = new MemoryStream()) { @@ -466,12 +458,12 @@ await _checkpointer.AddNewJobPartAsync( } } - internal async virtual Task SetCheckpointerStatus(DataTransferStatus status) + internal async virtual Task SetCheckpointerState(DataTransferStatus.TransferState state) { - await _checkpointer.SetJobPartTransferStatusAsync( + await _checkpointer.SetJobPartTransferStateAsync( transferId: _dataTransfer.Id, partNumber: PartNumber, - status: status).ConfigureAwait(false); + state: state).ConfigureAwait(false); } internal long CalculateBlockSize(long length) @@ -567,13 +559,14 @@ internal async Task CheckAndUpdateCancellationStatusAsync() { if (_chunkTasks.All((Task task) => (task.IsCompleted))) { - if (JobPartStatus == DataTransferStatus.TransferState.Pausing) + if (JobPartStatus.State == DataTransferStatus.TransferState.Pausing) { - await OnTransferStatusChanged(DataTransferStatus.TransferState.Paused).ConfigureAwait(false); + await OnTransferStateChanged(DataTransferStatus.TransferState.Paused).ConfigureAwait(false); } - else if (JobPartStatus == DataTransferStatus.CancellationInProgress) + else if (JobPartStatus.State == DataTransferStatus.TransferState.Stopping) { - await OnTransferStatusChanged(DataTransferStatus.TransferState.CompletedWithFailedTransfers).ConfigureAwait(false); + _progressTracker.IncrementFailedFiles(); + await OnTransferStateChanged(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); } } } diff --git a/sdk/storage/Azure.Storage.DataMovement/src/ServiceToServiceJobPart.cs b/sdk/storage/Azure.Storage.DataMovement/src/ServiceToServiceJobPart.cs index a998b3a3f84d3..4cf371791919c 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/ServiceToServiceJobPart.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/ServiceToServiceJobPart.cs @@ -211,7 +211,7 @@ await _destinationResource.CopyFromUriAsync( cancellationToken: _cancellationToken).ConfigureAwait(false); ReportBytesWritten(completeLength); - await OnTransferStatusChanged(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); + await OnTransferStateChanged(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); } catch (RequestFailedException exception) when (_createMode == StorageResourceCreationPreference.SkipIfExists @@ -307,7 +307,7 @@ await _destinationResource.CompleteTransferAsync( await DisposeHandlers().ConfigureAwait(false); // Set completion status to completed - await OnTransferStatusChanged(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); + await OnTransferStateChanged(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); } catch (Exception ex) { diff --git a/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataMovementConstants.cs b/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataMovementConstants.cs index 016f459eecaec..24515f2f5ad08 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataMovementConstants.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataMovementConstants.cs @@ -217,11 +217,21 @@ internal static class PlanFile /// Index: 49021 internal const int RehydratePriorityTypeIndex = PermanentDeleteOptionIndex + OneByte; /// Index: 49022 - internal const int AtomicJobStatusIndex = RehydratePriorityTypeIndex + OneByte; + internal const int AtomicJobStatusStateIndex = RehydratePriorityTypeIndex + OneByte; /// Index: 49023 - internal const int AtomicPartStatusIndex = AtomicJobStatusIndex + OneByte; + internal const int AtomicJobStatusHasFailedIndex = AtomicJobStatusStateIndex + OneByte; + /// Index: 49024 + internal const int AtomicJobStatusHasSkippedIndex = AtomicJobStatusHasFailedIndex + OneByte; + /// Index: 49025 + internal const int AtomicPartStatusStateIndex = AtomicJobStatusHasSkippedIndex + OneByte; + /// Index: 49026 + internal const int AtomicPartStatusHasFailedIndex = AtomicPartStatusStateIndex + OneByte; + /// Index: 49027 + internal const int AtomicPartStatusHasSkippedIndex = AtomicPartStatusHasFailedIndex + OneByte; + /// Index: 49028 + internal const int AtomicPartStatusIndex = AtomicPartStatusHasSkippedIndex + OneByte; /// - /// Size of the JobPart Header: 49024 + /// Size of the JobPart Header: 49029 /// internal const int JobPartHeaderSizeInBytes = AtomicPartStatusIndex + OneByte; } diff --git a/sdk/storage/Azure.Storage.DataMovement/src/Shared/JobPlan/JobPartPlanHeader.cs b/sdk/storage/Azure.Storage.DataMovement/src/Shared/JobPlan/JobPartPlanHeader.cs index b9a822ae348bd..1863c6e1bc977 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/Shared/JobPlan/JobPartPlanHeader.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/Shared/JobPlan/JobPartPlanHeader.cs @@ -574,11 +574,23 @@ public void Serialize(Stream stream) // RehydratePriorityType writer.Write((byte)RehydratePriorityType); - // AtomicJobStatus - writer.Write((byte)AtomicJobStatus); + // AtomicJobStatus.State + writer.Write((byte)AtomicJobStatus.State); - // AtomicPartStatus - writer.Write((byte)AtomicPartStatus); + // AtomicJobStatus.HasFailedItems + writer.Write(Convert.ToByte(AtomicJobStatus.HasFailedItems)); + + // AtomicJobStatus.HasSkippedItems + writer.Write(Convert.ToByte(AtomicJobStatus.HasSkippedItems)); + + // AtomicPartStatus.State + writer.Write((byte)AtomicPartStatus.State); + + // AtomicPartStatus.HasFailedItems + writer.Write(Convert.ToByte(AtomicPartStatus.HasFailedItems)); + + // AtomicPartStatus.HasSkippedItems + writer.Write(Convert.ToByte(AtomicPartStatus.HasSkippedItems)); } public static JobPartPlanHeader Deserialize(Stream stream) @@ -820,13 +832,35 @@ public static JobPartPlanHeader Deserialize(Stream stream) byte rehydratePriorityTypeByte = reader.ReadByte(); JobPartPlanRehydratePriorityType rehydratePriorityType = (JobPartPlanRehydratePriorityType)rehydratePriorityTypeByte; - // AtomicJobStatus + // AtomicJobStatus.State byte atomicJobStatusByte = reader.ReadByte(); - DataTransferStatus atomicJobStatus = (DataTransferStatus)atomicJobStatusByte; + DataTransferStatus.TransferState jobStatusState = (DataTransferStatus.TransferState)atomicJobStatusByte; + + // AtomicJobStatus.HasFailedItems + bool jobStatusHasFailed = Convert.ToBoolean(reader.ReadByte()); - // AtomicPartStatus + // AtomicJobStatus.HasSkippedItems + bool jobStatusHasSkipped = Convert.ToBoolean(reader.ReadByte()); + + // AtomicPartStatus.State byte atomicPartStatusByte = reader.ReadByte(); - DataTransferStatus atomicPartStatus = (DataTransferStatus)atomicPartStatusByte; + DataTransferStatus.TransferState partStatusState = (DataTransferStatus.TransferState)atomicPartStatusByte; + + // AtomicPartStatus.HasFailedItems + bool partStatusHasFailed = Convert.ToBoolean(reader.ReadByte()); + + // AtomicPartStatus.HasSkippedItems + bool partStatusHasSkipped = Convert.ToBoolean(reader.ReadByte()); + + DataTransferStatus atomicJobStatus = new DataTransferStatus( + jobStatusState, + jobStatusHasFailed, + jobStatusHasSkipped); + + DataTransferStatus atomicPartStatus = new DataTransferStatus( + partStatusState, + partStatusHasFailed, + partStatusHasSkipped); JobPartPlanDestinationBlob dstBlobData = new JobPartPlanDestinationBlob( blobType: blobType, diff --git a/sdk/storage/Azure.Storage.DataMovement/src/Shared/LocalTransferCheckpointer.cs b/sdk/storage/Azure.Storage.DataMovement/src/Shared/LocalTransferCheckpointer.cs index ae7a5c992c2c5..29e16b7837060 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/Shared/LocalTransferCheckpointer.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/Shared/LocalTransferCheckpointer.cs @@ -306,7 +306,7 @@ public override async Task SetJobTransferStatusAsync( CancellationToken cancellationToken = default) { long length = DataMovementConstants.PlanFile.OneByte; - int offset = DataMovementConstants.PlanFile.AtomicJobStatusIndex; + int offset = DataMovementConstants.PlanFile.AtomicJobStatusStateIndex; CancellationHelper.ThrowIfCancellationRequested(cancellationToken); if (_transferStates.TryGetValue(transferId, out Dictionary jobPartFiles)) diff --git a/sdk/storage/Azure.Storage.DataMovement/src/Shared/TransferCheckpointer.cs b/sdk/storage/Azure.Storage.DataMovement/src/Shared/TransferCheckpointer.cs index ebd52aa5c4cad..2f444faed23f3 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/Shared/TransferCheckpointer.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/Shared/TransferCheckpointer.cs @@ -143,15 +143,15 @@ public abstract Task SetJobTransferStatusAsync( /// /// The transfer ID. /// The job part number. - /// The of the job part. + /// The of the job part. /// /// Optional to propagate /// notifications that the operation should be canceled. /// - public abstract Task SetJobPartTransferStatusAsync( + public abstract Task SetJobPartTransferStateAsync( string transferId, int partNumber, - DataTransferStatus status, + DataTransferStatus.TransferState state, CancellationToken cancellationToken = default); /// diff --git a/sdk/storage/Azure.Storage.DataMovement/src/Shared/TransferManager.cs b/sdk/storage/Azure.Storage.DataMovement/src/Shared/TransferManager.cs index f261457a343f2..c9b8949e5e60a 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/Shared/TransferManager.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/Shared/TransferManager.cs @@ -294,13 +294,13 @@ public virtual async IAsyncEnumerable GetResumableTransf List storedTransfers = await _checkpointer.GetStoredTransfersAsync().ConfigureAwait(false); foreach (string transferId in storedTransfers) { - DataTransferStatus jobStatus = (DataTransferStatus) await _checkpointer.GetByteValue( + DataTransferStatus.TransferState jobStatus = (DataTransferStatus.TransferState) await _checkpointer.GetByteValue( transferId, - DataMovementConstants.PlanFile.AtomicJobStatusIndex, + DataMovementConstants.PlanFile.AtomicJobStatusStateIndex, _cancellationToken).ConfigureAwait(false); // Transfers marked as fully completed are not resumable - if (jobStatus.State == DataTransferStatus.TransferState.Completed) + if (jobStatus == DataTransferStatus.TransferState.Completed) { continue; } diff --git a/sdk/storage/Azure.Storage.DataMovement/src/StreamToUriJobPart.cs b/sdk/storage/Azure.Storage.DataMovement/src/StreamToUriJobPart.cs index 5d8d174f50b47..e178c22218aec 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/StreamToUriJobPart.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/StreamToUriJobPart.cs @@ -250,7 +250,7 @@ await _destinationResource.CopyFromStreamAsync( ReportBytesWritten(blockSize); // Set completion status to completed - await OnTransferStatusChanged(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); + await OnTransferStateChanged(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); } else { @@ -395,7 +395,7 @@ await _destinationResource.CompleteTransferAsync( await DisposeHandlers().ConfigureAwait(false); // Set completion status to completed - await OnTransferStatusChanged(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); + await OnTransferStateChanged(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); } private async Task QueueStageBlockRequests(List<(long Offset, long Size)> rangeList, long completeLength) diff --git a/sdk/storage/Azure.Storage.DataMovement/src/TransferJobInternal.cs b/sdk/storage/Azure.Storage.DataMovement/src/TransferJobInternal.cs index c5d57d3d080dd..c3764159f5c6d 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/TransferJobInternal.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/TransferJobInternal.cs @@ -342,7 +342,7 @@ public async Task JobPartEvent(TransferStatusEventArgs args) _jobPartPaused = true; } else if (jobPartStatus.State == DataTransferStatus.TransferState.Completed - && jobPartStatus.HasFailureItems) + && jobPartStatus.HasFailedItems) { _jobPartFailed = true; } diff --git a/sdk/storage/Azure.Storage.DataMovement/src/UriToStreamJobPart.cs b/sdk/storage/Azure.Storage.DataMovement/src/UriToStreamJobPart.cs index 5abf9c2401f3e..1e30b4abf801c 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/UriToStreamJobPart.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/UriToStreamJobPart.cs @@ -340,7 +340,7 @@ await _destinationResource.CompleteTransferAsync( await DisposeHandlers().ConfigureAwait(false); // Update the transfer status - await OnTransferStatusChanged(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); + await OnTransferStateChanged(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); } catch (Exception ex) { diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/Shared/CheckpointerTesting.cs b/sdk/storage/Azure.Storage.DataMovement/tests/Shared/CheckpointerTesting.cs index 0e28efccc35d2..f9392be248ff3 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/Shared/CheckpointerTesting.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/Shared/CheckpointerTesting.cs @@ -43,7 +43,7 @@ internal static readonly DateTimeOffset DefaultStartTime internal const JobPartDeleteSnapshotsOption DefaultDeleteSnapshotsOption = JobPartDeleteSnapshotsOption.None; internal const JobPartPermanentDeleteOption DefaultPermanentDeleteOption = JobPartPermanentDeleteOption.None; internal const JobPartPlanRehydratePriorityType DefaultRehydratePriorityType = JobPartPlanRehydratePriorityType.None; - internal const DataTransferStatus DefaultJobStatus = DataTransferStatus.Queued; + internal const DataTransferStatus DefaultJobStatus = new DataTransferStatus(); internal const DataTransferStatus DefaultPartStatus = DataTransferStatus.Queued; internal static JobPartPlanHeader CreateDefaultJobPartHeader( From a0f761a2f481d76db30a12228200331116c765c2 Mon Sep 17 00:00:00 2001 From: amnguye Date: Mon, 21 Aug 2023 10:02:36 -0700 Subject: [PATCH 03/13] WIP --- .../src/DataTransferStatus.cs | 63 ++++++++ .../src/JobPartInternal.cs | 76 +++++++--- .../src/ServiceToServiceJobPart.cs | 10 +- .../src/Shared/DataTransfer.cs | 2 +- .../src/Shared/DataTransferState.cs | 54 +++---- .../src/Shared/LocalTransferCheckpointer.cs | 20 ++- .../src/Shared/TransferCheckpointer.cs | 4 +- .../src/StreamToUriJobPart.cs | 8 +- .../src/TransferJobInternal.cs | 136 +++++++----------- .../src/UriToStreamJobPart.cs | 10 +- .../Azure.Storage.DataMovement.Tests.csproj | 2 +- .../tests/DataTransferTests.cs | 2 +- 12 files changed, 222 insertions(+), 165 deletions(-) diff --git a/sdk/storage/Azure.Storage.DataMovement/src/DataTransferStatus.cs b/sdk/storage/Azure.Storage.DataMovement/src/DataTransferStatus.cs index 5be76968ecd2d..4d9de1895faf5 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/DataTransferStatus.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/DataTransferStatus.cs @@ -11,6 +11,10 @@ namespace Azure.Storage.DataMovement /// public class DataTransferStatus { + private object _stateLock = new object(); + private object _hasSkippedLock = new object(); + private object _hasFailedLock = new object(); + /// /// Defines the types of the state a transfer can have. /// @@ -115,5 +119,64 @@ protected internal DataTransferStatus(TransferState state, bool hasFailureItems, internal bool IsCompletedWithFailedItems => State.Equals(TransferState.Completed) && HasFailedItems; internal bool IsCompletedWithSkippedItems => State.Equals(TransferState.Completed) && HasSkippedItems; + + /// + /// Accordingly update the to true. If already set to true, nothing will happen. + /// + /// This should only be triggered when a failed item has been seen. + /// + /// True if was updated. False otherwise. + internal bool OnFailedItem() + { + lock (_hasFailedLock) + { + if (!HasFailedItems) + { + HasFailedItems = true; + return true; + } + } + return false; + } + + /// + /// Accordingly update the to true. If already set to true, nothing will happen. + /// + /// This should only be triggered when a skipped item has been seen. + /// + /// /// True if was updated. False otherwise. + internal bool OnSkippedItem() + { + lock (_hasSkippedLock) + { + if (!HasSkippedItems) + { + HasSkippedItems = true; + return true; + } + } + return false; + } + + /// + /// Accordingly update the . If the current State is the same as the parameter, + /// then nothing will happen. + /// + /// This should only be triggered when the state updates. + /// + /// True if was updated. False otherwise. + internal bool OnTransferStateChange(TransferState state) + { + lock (_stateLock) + { + if (state != TransferState.None && + State != state) + { + State = state; + return true; + } + } + return false; + } } } diff --git a/sdk/storage/Azure.Storage.DataMovement/src/JobPartInternal.cs b/sdk/storage/Azure.Storage.DataMovement/src/JobPartInternal.cs index 891b864d6065f..d5fdd0845bee8 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/JobPartInternal.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/JobPartInternal.cs @@ -96,7 +96,6 @@ internal abstract class JobPartInternal /// The current status of each job part. /// public DataTransferStatus JobPartStatus { get; set; } - private object _statusLock = new object(); /// /// Optional. If the length is known, we log it instead of doing a GetProperties call on the @@ -174,6 +173,7 @@ internal JobPartInternal( { Argument.AssertNotNull(clientDiagnostics, nameof(clientDiagnostics)); + // if defualt is passed, the job part status will be queued JobPartStatus = jobPartStatus != default ? jobPartStatus : new DataTransferStatus(); PartNumber = partNumber; _dataTransfer = dataTransfer; @@ -241,7 +241,7 @@ await QueueChunk( { await Task.Run(chunkTask).ConfigureAwait(false); chunkCompleted.SetResult(true); - await CheckAndUpdateCancellationStatusAsync().ConfigureAwait(false); + await CheckAndUpdateCancellationStateAsync().ConfigureAwait(false); } catch (Exception ex) { @@ -276,12 +276,12 @@ internal async Task TriggerCancellationAsync() { // It's possible that the status hasn't propagated down to the job part // status yet here since we pause from the data transfer object. - await OnTransferStateChanged(DataTransferStatus.TransferState.Pausing).ConfigureAwait(false); + await OnTransferStateChangedAsync(DataTransferStatus.TransferState.Pausing).ConfigureAwait(false); } else { // It's a cancellation if a pause wasn't called. - await OnTransferStateChanged(DataTransferStatus.TransferState.Stopping).ConfigureAwait(false); + await OnTransferStateChangedAsync(DataTransferStatus.TransferState.Stopping).ConfigureAwait(false); } await CleanupAbortedJobPartAsync().ConfigureAwait(false); } @@ -290,19 +290,9 @@ internal async Task TriggerCancellationAsync() /// To change all transfer statues at the same time /// /// - internal async Task OnTransferStateChanged(DataTransferStatus.TransferState transferState) + internal async Task OnTransferStateChangedAsync(DataTransferStatus.TransferState transferState) { - bool statusChanged = false; - lock (_statusLock) - { - if (transferState != DataTransferStatus.TransferState.None - && JobPartStatus.State != transferState) - { - statusChanged = true; - JobPartStatus.State = transferState; - } - } - if (statusChanged) + if (JobPartStatus.OnTransferStateChange(transferState)) { // Progress tracking, do before invoking the event below if (transferState == DataTransferStatus.TransferState.InProgress) @@ -319,7 +309,6 @@ internal async Task OnTransferStateChanged(DataTransferStatus.TransferState tran // Set the status in the checkpointer await SetCheckpointerState(transferState).ConfigureAwait(false); - // TODO: change to RaiseAsync await PartTransferStatusEventHandler.RaiseAsync( new TransferStatusEventArgs( _dataTransfer.Id, @@ -333,6 +322,44 @@ await PartTransferStatusEventHandler.RaiseAsync( } } + internal async Task OnTransferFailedAsync() + { + // Update the JobPartStatus. If was already updated (e.g. there was a failed item before) + // then don't raise the PartTransferStatusEventHandler + if (JobPartStatus.OnFailedItem()) + { + await PartTransferStatusEventHandler.RaiseAsync( + new TransferStatusEventArgs( + _dataTransfer.Id, + JobPartStatus, + false, + _cancellationToken), + nameof(JobPartInternal), + nameof(PartTransferStatusEventHandler), + ClientDiagnostics) + .ConfigureAwait(false); + } + } + + internal async Task OnTransferSkippedAsync() + { + // Update the JobPartStatus. If was already updated (e.g. there was a failed item before) + // then don't raise the PartTransferStatusEventHandler + if (JobPartStatus.OnSkippedItem()) + { + await PartTransferStatusEventHandler.RaiseAsync( + new TransferStatusEventArgs( + _dataTransfer.Id, + JobPartStatus, + false, + _cancellationToken), + nameof(JobPartInternal), + nameof(PartTransferStatusEventHandler), + ClientDiagnostics) + .ConfigureAwait(false); + } + } + /// /// To change all transfer statues at the same time /// @@ -381,7 +408,9 @@ await TransferSkippedEventHandler.RaiseAsync( .ConfigureAwait(false); } _progressTracker.IncrementSkippedFiles(); - await OnTransferStateChanged(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); + await OnTransferSkippedAsync().ConfigureAwait(false); + //TODO: figure out why we set the Completed state here and not just wait for all the chunks to finish + //await OnTransferStateChangedAsync(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); } /// @@ -412,8 +441,9 @@ await TransferFailedEventHandler.RaiseAsync( _progressTracker.IncrementFailedFiles(); } // Trigger job cancellation if the failed handler is enabled + await OnTransferFailedAsync().ConfigureAwait(false); await TriggerCancellationAsync().ConfigureAwait(false); - await CheckAndUpdateCancellationStatusAsync().ConfigureAwait(false); + await CheckAndUpdateCancellationStateAsync().ConfigureAwait(false); } /// @@ -444,7 +474,7 @@ public async virtual Task CleanupAbortedJobPartAsync() public async virtual Task AddJobPartToCheckpointerAsync(int chunksTotal, bool isFinalPart) { JobPartPlanHeader header = this.ToJobPartPlanHeader( - jobStatus: DataTransferStatus.TransferState.InProgress, + jobStatus: JobPartStatus, isFinalPart: isFinalPart); using (Stream stream = new MemoryStream()) { @@ -555,18 +585,18 @@ internal static long ParseRangeTotalLength(string range) } } - internal async Task CheckAndUpdateCancellationStatusAsync() + internal async Task CheckAndUpdateCancellationStateAsync() { if (_chunkTasks.All((Task task) => (task.IsCompleted))) { if (JobPartStatus.State == DataTransferStatus.TransferState.Pausing) { - await OnTransferStateChanged(DataTransferStatus.TransferState.Paused).ConfigureAwait(false); + await OnTransferStateChangedAsync(DataTransferStatus.TransferState.Paused).ConfigureAwait(false); } else if (JobPartStatus.State == DataTransferStatus.TransferState.Stopping) { _progressTracker.IncrementFailedFiles(); - await OnTransferStateChanged(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); + await OnTransferStateChangedAsync(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); } } } diff --git a/sdk/storage/Azure.Storage.DataMovement/src/ServiceToServiceJobPart.cs b/sdk/storage/Azure.Storage.DataMovement/src/ServiceToServiceJobPart.cs index 4cf371791919c..b61cf2a029cf6 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/ServiceToServiceJobPart.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/ServiceToServiceJobPart.cs @@ -55,7 +55,7 @@ private ServiceToServiceJobPart( StorageResourceItem sourceResource, StorageResourceItem destinationResource, bool isFinalPart, - DataTransferStatus jobPartStatus = DataTransferStatus.Queued, + DataTransferStatus jobPartStatus = default, long? length = default) : base(dataTransfer: job._dataTransfer, partNumber: partNumber, @@ -128,7 +128,7 @@ public static async Task CreateJobPartAsync( public override async Task ProcessPartToChunkAsync() { - await OnTransferStatusChanged(DataTransferStatus.InProgress).ConfigureAwait(false); + await OnTransferStateChangedAsync(DataTransferStatus.TransferState.InProgress).ConfigureAwait(false); // Attempt to get the length, it's possible the file could // not be accessible (or does not exist). @@ -193,7 +193,7 @@ await PutBlockFromUri( } else { - await CheckAndUpdateCancellationStatusAsync().ConfigureAwait(false); + await CheckAndUpdateCancellationStateAsync().ConfigureAwait(false); } } @@ -211,7 +211,7 @@ await _destinationResource.CopyFromUriAsync( cancellationToken: _cancellationToken).ConfigureAwait(false); ReportBytesWritten(completeLength); - await OnTransferStateChanged(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); + await OnTransferStateChangedAsync(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); } catch (RequestFailedException exception) when (_createMode == StorageResourceCreationPreference.SkipIfExists @@ -307,7 +307,7 @@ await _destinationResource.CompleteTransferAsync( await DisposeHandlers().ConfigureAwait(false); // Set completion status to completed - await OnTransferStateChanged(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); + await OnTransferStateChangedAsync(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); } catch (Exception ex) { diff --git a/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransfer.cs b/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransfer.cs index f1f6becbe1bca..657e20e019097 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransfer.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransfer.cs @@ -54,7 +54,7 @@ internal DataTransfer() internal DataTransfer( string id, TransferManager transferManager, - DataTransferStatus status = DataTransferStatus.Queued) + DataTransferStatus status = default) { Argument.AssertNotNullOrEmpty(id, nameof(id)); Argument.AssertNotNull(transferManager, nameof(transferManager)); diff --git a/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransferState.cs b/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransferState.cs index 55d2ef5478605..393ea2149cc81 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransferState.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransferState.cs @@ -14,7 +14,6 @@ namespace Azure.Storage.DataMovement /// internal class DataTransferState { - private readonly object _statusLock = new object(); private string _id; private DataTransferStatus _status; @@ -31,16 +30,14 @@ internal class DataTransferState /// The Transfer Status of the Transfer. See . public DataTransferState( string id = default, - DataTransferStatus status = DataTransferStatus.Queued) + DataTransferStatus status = default) { _id = string.IsNullOrEmpty(id) ? Guid.NewGuid().ToString() : id; _status = status; CompletionSource = new TaskCompletionSource( _status, TaskCreationOptions.RunContinuationsAsynchronously); - if (DataTransferStatus.TransferState.Completed == status || - DataTransferStatus.TransferState.CompletedWithSkippedTransfers == status || - DataTransferStatus.TransferState.CompletedWithFailedTransfers == status) + if (DataTransferStatus.TransferState.Completed == status.State) { CompletionSource.TrySetResult(status); } @@ -62,9 +59,9 @@ internal set { } public bool HasCompleted { get { - return (DataTransferStatus.TransferState.Completed == _status || - DataTransferStatus.TransferState.CompletedWithSkippedTransfers == _status || - DataTransferStatus.TransferState.CompletedWithFailedTransfers == _status); + // TODO: look to whether before a paused state was considered completed.. + return (DataTransferStatus.TransferState.Completed == _status.State || + DataTransferStatus.TransferState.Paused == _status.State); } internal set { } } @@ -84,42 +81,37 @@ public void SetId(string id) /// public DataTransferStatus GetTransferStatus() { - lock (_statusLock) - { - return _status; - } + return _status; } /// /// Sets the completion status /// - /// + /// /// Returns whether or not the status has been changed/set - public bool TrySetTransferStatus(DataTransferStatus status) + public bool TrySetTransferState(DataTransferStatus.TransferState state) { - lock (_statusLock) + if (_status.OnTransferStateChange(state)) { - if (_status != status) + if (DataTransferStatus.TransferState.Completed == _status.State || + DataTransferStatus.TransferState.Paused == _status.State) { - _status = status; - if (DataTransferStatus.TransferState.Paused == status || - DataTransferStatus.TransferState.Completed == status || - DataTransferStatus.TransferState.CompletedWithSkippedTransfers == status || - DataTransferStatus.TransferState.CompletedWithFailedTransfers == status) - { - // If the _completionSource has been cancelled or the exception - // has been set, we don't need to check if TrySetResult returns false - // because it's acceptable to cancel or have an error occur before then. - CompletionSource.TrySetResult(status); - } - return true; + // If the _completionSource has been cancelled or the exception + // has been set, we don't need to check if TrySetResult returns false + // because it's acceptable to cancel or have an error occur before then. + CompletionSource.TrySetResult(_status); } - return false; + return true; } + return false; } + public bool TryOnFailedItemsState() => _status.OnFailedItem(); + + public bool TryOnSkippedItemsState() => _status.OnSkippedItem(); + internal bool CanPause() - => _status == DataTransferStatus.InProgress; + => DataTransferStatus.TransferState.InProgress == _status.State; public async Task PauseIfRunningAsync(CancellationToken cancellationToken) { @@ -129,7 +121,7 @@ public async Task PauseIfRunningAsync(CancellationToken cancellationToken) } CancellationHelper.ThrowIfCancellationRequested(cancellationToken); // Call the inner cancellation token to stop the transfer job - TrySetTransferStatus(DataTransferStatus.TransferState.Pausing); + TrySetTransferState(DataTransferStatus.TransferState.Pausing); if (TriggerCancellation()) { // Wait until full pause has completed. diff --git a/sdk/storage/Azure.Storage.DataMovement/src/Shared/LocalTransferCheckpointer.cs b/sdk/storage/Azure.Storage.DataMovement/src/Shared/LocalTransferCheckpointer.cs index 29e16b7837060..e90ea724af984 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/Shared/LocalTransferCheckpointer.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/Shared/LocalTransferCheckpointer.cs @@ -305,7 +305,7 @@ public override async Task SetJobTransferStatusAsync( DataTransferStatus status, CancellationToken cancellationToken = default) { - long length = DataMovementConstants.PlanFile.OneByte; + long length = DataMovementConstants.PlanFile.OneByte * 3; int offset = DataMovementConstants.PlanFile.AtomicJobStatusStateIndex; CancellationHelper.ThrowIfCancellationRequested(cancellationToken); @@ -326,7 +326,13 @@ public override async Task SetJobTransferStatusAsync( { accessor.Write( position: 0, - value: (byte)status); + value: (byte)status.State); + accessor.Write( + position: 1, + value: status.HasFailedItems); + accessor.Write( + position: 2, + value: status.HasSkippedItems); // to flush to the underlying file that supports the mmf accessor.Flush(); } @@ -348,7 +354,7 @@ public override async Task SetJobPartTransferStatusAsync( DataTransferStatus status, CancellationToken cancellationToken = default) { - long length = DataMovementConstants.PlanFile.OneByte; + long length = DataMovementConstants.PlanFile.OneByte * 3; int offset = DataMovementConstants.PlanFile.AtomicPartStatusIndex; CancellationHelper.ThrowIfCancellationRequested(cancellationToken); @@ -369,7 +375,13 @@ public override async Task SetJobPartTransferStatusAsync( { accessor.Write( position: 0, - value: (byte)status); + value: (byte)status.State); + accessor.Write( + position: 1, + value: status.HasFailedItems); + accessor.Write( + position: 2, + value: status.HasSkippedItems); // to flush to the underlying file that supports the mmf accessor.Flush(); } diff --git a/sdk/storage/Azure.Storage.DataMovement/src/Shared/TransferCheckpointer.cs b/sdk/storage/Azure.Storage.DataMovement/src/Shared/TransferCheckpointer.cs index 2f444faed23f3..8a359c1b4940b 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/Shared/TransferCheckpointer.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/Shared/TransferCheckpointer.cs @@ -148,10 +148,10 @@ public abstract Task SetJobTransferStatusAsync( /// Optional to propagate /// notifications that the operation should be canceled. /// - public abstract Task SetJobPartTransferStateAsync( + public abstract Task SetJobPartTransferStatusAsync( string transferId, int partNumber, - DataTransferStatus.TransferState state, + DataTransferStatus state, CancellationToken cancellationToken = default); /// diff --git a/sdk/storage/Azure.Storage.DataMovement/src/StreamToUriJobPart.cs b/sdk/storage/Azure.Storage.DataMovement/src/StreamToUriJobPart.cs index e178c22218aec..2339b10589386 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/StreamToUriJobPart.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/StreamToUriJobPart.cs @@ -58,7 +58,7 @@ private StreamToUriJobPart( StorageResourceItem sourceResource, StorageResourceItem destinationResource, bool isFinalPart, - DataTransferStatus jobPartStatus = DataTransferStatus.Queued, + DataTransferStatus jobPartStatus = default, long? length = default) : base(dataTransfer: job._dataTransfer, partNumber: partNumber, @@ -142,7 +142,7 @@ public override async Task ProcessPartToChunkAsync() // Attempt to get the length, it's possible the file could // not be accesible (or does not exist). string operationName = $"{nameof(TransferManager.StartTransferAsync)}"; - await OnTransferStatusChanged(DataTransferStatus.InProgress).ConfigureAwait(false); + await OnTransferStateChangedAsync(DataTransferStatus.TransferState.InProgress).ConfigureAwait(false); long? fileLength = default; try { @@ -250,7 +250,7 @@ await _destinationResource.CopyFromStreamAsync( ReportBytesWritten(blockSize); // Set completion status to completed - await OnTransferStateChanged(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); + await OnTransferStateChangedAsync(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); } else { @@ -395,7 +395,7 @@ await _destinationResource.CompleteTransferAsync( await DisposeHandlers().ConfigureAwait(false); // Set completion status to completed - await OnTransferStateChanged(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); + await OnTransferStateChangedAsync(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); } private async Task QueueStageBlockRequests(List<(long Offset, long Size)> rangeList, long completeLength) diff --git a/sdk/storage/Azure.Storage.DataMovement/src/TransferJobInternal.cs b/sdk/storage/Azure.Storage.DataMovement/src/TransferJobInternal.cs index c3764159f5c6d..902f466233d21 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/TransferJobInternal.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/TransferJobInternal.cs @@ -87,14 +87,6 @@ internal abstract class TransferJobInternal : IDisposable /// internal StorageResourceCreationPreference _creationPreference; - private object _statusLock = new object(); - - /// - /// To help set the job status when all job parts have completed. - /// - internal bool _hasFailures; - internal bool _hasSkipped; - /// /// Considering if there's more than one job part, the transfer status will need to be set to /// completed all job parts have been set to completed. @@ -136,8 +128,6 @@ internal abstract class TransferJobInternal : IDisposable internal bool _enumerationComplete; private int _pendingJobParts; private bool _jobPartPaused; - private bool _jobPartFailed; - private bool _jobPartSkipped; public CancellationToken _cancellationToken { get; internal set; } @@ -164,13 +154,11 @@ private TransferJobInternal( Argument.AssertNotNull(clientDiagnostics, nameof(clientDiagnostics)); _dataTransfer = dataTransfer ?? throw Errors.ArgumentNull(nameof(dataTransfer)); - _dataTransfer._state.TrySetTransferStatus(DataTransferStatus.Queued); + _dataTransfer.TransferStatus.OnTransferStateChange(DataTransferStatus.TransferState.Queued); _errorMode = errorHandling; _checkpointer = checkPointer; _creationPreference = creationPreference; QueueChunkTask = queueChunkTask; - _hasFailures = false; - _hasSkipped = false; _arrayPool = arrayPool; _jobParts = new List(); _enumerationComplete = false; @@ -273,20 +261,14 @@ public void DisposeHandlers() /// /// Triggers the cancellation for the Job Part. /// - /// If the status is set to - /// and any chunks is still processing to be cancelled is will be set to - /// until the chunks finish then it will be set to . - /// - /// If the status is set to - /// and any chunks is still processing to be cancelled is will be set to - /// until the chunks finish then it will be set to . + /// If the cancellation token was called to cancelled, change the status to Stopping. /// /// The task to wait until the cancellation has been triggered. public async Task TriggerJobCancellationAsync() { if (!_dataTransfer._state.CancellationTokenSource.IsCancellationRequested) { - await OnJobStatusChangedAsync(DataTransferStatus.CancellationInProgress).ConfigureAwait(false); + await OnJobStateChangedAsync(DataTransferStatus.TransferState.Stopping).ConfigureAwait(false); _dataTransfer._state.TriggerCancellation(); } } @@ -316,6 +298,10 @@ await TransferFailedEventHandler.RaiseAsync( ClientDiagnostics) .ConfigureAwait(false); } + if (_dataTransfer._state.TryOnFailedItemsState()) + { + + } } // Trigger job cancellation if the failed handler is enabled await TriggerJobCancellationAsync().ConfigureAwait(false); @@ -341,20 +327,24 @@ public async Task JobPartEvent(TransferStatusEventArgs args) { _jobPartPaused = true; } - else if (jobPartStatus.State == DataTransferStatus.TransferState.Completed - && jobPartStatus.HasFailedItems) + else if (jobPartStatus.HasFailedItems) { - _jobPartFailed = true; + if (_dataTransfer._state.TryOnFailedItemsState()) + { + await SetCheckpointerStatus().ConfigureAwait(false); + } } - else if (jobPartStatus.State == DataTransferStatus.TransferState.Completed - && jobPartStatus.HasSkippedItems) + else if (jobPartStatus.HasSkippedItems) { - _jobPartSkipped = true; + if (_dataTransfer._state.TryOnSkippedItemsState()) + { + await SetCheckpointerStatus().ConfigureAwait(false); + } } // Cancel the entire job if one job part fails and StopOnFailure is set if (_errorMode == DataTransferErrorMode.StopOnAnyFailure && - jobPartStatus.IsCompletedWithFailedItems && + jobPartStatus.HasFailedItems && jobStatus.State != DataTransferStatus.TransferState.Stopping && jobStatus.State != DataTransferStatus.TransferState.Completed) { @@ -378,58 +368,43 @@ public async Task JobPartEvent(TransferStatusEventArgs args) } } - public async Task OnJobStatusChangedAsync(DataTransferStatus status) + public async Task OnJobStateChangedAsync(DataTransferStatus.TransferState state) { - bool statusChanged = false; - lock (_statusLock) - { - statusChanged = _dataTransfer._state.TrySetTransferStatus(status); - } - if (statusChanged) + if (_dataTransfer._state.TrySetTransferState(state)) { // If we are in a final state, dispose the JobPartEvent handlers - if (status.State == DataTransferStatus.TransferState.Completed || - status.State == DataTransferStatus.TransferState.Paused) + if (state == DataTransferStatus.TransferState.Completed || + state == DataTransferStatus.TransferState.Paused) { DisposeHandlers(); } - if (TransferStatusEventHandler != null) - { - await TransferStatusEventHandler.RaiseAsync( - new TransferStatusEventArgs( - transferId: _dataTransfer.Id, - transferStatus: status, - isRunningSynchronously: false, - cancellationToken: _cancellationToken), - nameof(TransferJobInternal), - nameof(TransferStatusEventHandler), - ClientDiagnostics).ConfigureAwait(false); - } - await SetCheckpointerStatus(status).ConfigureAwait(false); + await OnJobPartStatusChangedAsync().ConfigureAwait(false); + await SetCheckpointerStatus().ConfigureAwait(false); } } - public async Task OnJobPartStatusChangedAsync(DataTransferStatus status) + public async Task OnJobPartStatusChangedAsync() { - //TODO: change to RaiseAsync after implementing ClientDiagnostics for TransferManager - await JobPartStatusEvents.RaiseAsync( - new TransferStatusEventArgs( - transferId: _dataTransfer.Id, - transferStatus: status, - isRunningSynchronously: false, - cancellationToken: _cancellationToken), - nameof(TransferJobInternal), - nameof(JobPartStatusEvents), - ClientDiagnostics) - .ConfigureAwait(false); + if (TransferStatusEventHandler != null) + { + await TransferStatusEventHandler.RaiseAsync( + new TransferStatusEventArgs( + transferId: _dataTransfer.Id, + transferStatus: _dataTransfer.TransferStatus, + isRunningSynchronously: false, + cancellationToken: _cancellationToken), + nameof(TransferJobInternal), + nameof(TransferStatusEventHandler), + ClientDiagnostics).ConfigureAwait(false); + } } - internal async virtual Task SetCheckpointerStatus(DataTransferStatus status) + internal async virtual Task SetCheckpointerStatus() { await _checkpointer.SetJobTransferStatusAsync( transferId: _dataTransfer.Id, - status: status).ConfigureAwait(false); + status: _dataTransfer.TransferStatus).ConfigureAwait(false); } internal async Task OnEnumerationComplete() @@ -442,16 +417,11 @@ internal async Task OnEnumerationComplete() if (_dataTransfer.TransferStatus.State == DataTransferStatus.TransferState.Pausing) { // If we paused before we were able to list, set the status properly. - await OnJobStatusChangedAsync(DataTransferStatus.TransferState.Paused).ConfigureAwait(false); - } - else if (_dataTransfer.TransferStatus == DataTransferStatus.CancellationInProgress) - { - // If we aborted before we were able to list, set the status properly. - await OnJobStatusChangedAsync(DataTransferStatus.TransferState.CompletedWithFailedTransfers).ConfigureAwait(false); + await OnJobStateChangedAsync(DataTransferStatus.TransferState.Paused).ConfigureAwait(false); } else { - await OnJobStatusChangedAsync(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); + await OnJobStateChangedAsync(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); } } await CheckAndUpdateStatusAsync().ConfigureAwait(false); @@ -463,13 +433,13 @@ internal async Task CheckAndUpdateStatusAsync() // This is in the case that we weren't able to begin listing any job parts yet. if (_jobParts.Count == 0) { - if (_dataTransfer.TransferStatus == DataTransferStatus.TransferState.Pausing) + if (_dataTransfer.TransferStatus.State == DataTransferStatus.TransferState.Pausing) { - await OnJobStatusChangedAsync(DataTransferStatus.TransferState.Paused).ConfigureAwait(false); + await OnJobStateChangedAsync(DataTransferStatus.TransferState.Paused).ConfigureAwait(false); } - else if (_dataTransfer.TransferStatus == DataTransferStatus.CancellationInProgress) + else if (_dataTransfer.TransferStatus.State == DataTransferStatus.TransferState.Stopping) { - await OnJobStatusChangedAsync(DataTransferStatus.TransferState.CompletedWithFailedTransfers).ConfigureAwait(false); + await OnJobStateChangedAsync(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); } return; } @@ -479,19 +449,11 @@ internal async Task CheckAndUpdateStatusAsync() { if (_jobPartPaused) { - await OnJobStatusChangedAsync(DataTransferStatus.TransferState.Paused).ConfigureAwait(false); - } - else if (_jobPartFailed) - { - await OnJobStatusChangedAsync(DataTransferStatus.TransferState.CompletedWithFailedTransfers).ConfigureAwait(false); - } - else if (_jobPartSkipped) - { - await OnJobStatusChangedAsync(DataTransferStatus.TransferState.CompletedWithSkippedTransfers).ConfigureAwait(false); + await OnJobStateChangedAsync(DataTransferStatus.TransferState.Paused).ConfigureAwait(false); } else { - await OnJobStatusChangedAsync(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); + await OnJobStateChangedAsync(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); } } } @@ -502,9 +464,7 @@ public void AppendJobPart(JobPartInternal jobPart) // Job parts can come from resuming a transfer and therefore may already be complete DataTransferStatus status = jobPart.JobPartStatus; - if (status != DataTransferStatus.TransferState.CompletedWithSkippedTransfers && - status != DataTransferStatus.TransferState.CompletedWithFailedTransfers && - status != DataTransferStatus.TransferState.Completed) + if (status.State != DataTransferStatus.TransferState.Completed) { Interlocked.Increment(ref _pendingJobParts); } diff --git a/sdk/storage/Azure.Storage.DataMovement/src/UriToStreamJobPart.cs b/sdk/storage/Azure.Storage.DataMovement/src/UriToStreamJobPart.cs index 1e30b4abf801c..5da5e72bbeccf 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/UriToStreamJobPart.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/UriToStreamJobPart.cs @@ -58,7 +58,7 @@ private UriToStreamJobPart( StorageResourceItem sourceResource, StorageResourceItem destinationResource, bool isFinalPart, - DataTransferStatus jobPartStatus = DataTransferStatus.Queued, + DataTransferStatus jobPartStatus = default, long? length = default) : base(dataTransfer: job._dataTransfer, partNumber: partNumber, @@ -147,7 +147,7 @@ public override async Task ProcessPartToChunkAsync() { // we can default the length to 0 because we know the destination is local and // does not require a length to be created. - await OnTransferStatusChanged(DataTransferStatus.InProgress).ConfigureAwait(false); + await OnTransferStateChangedAsync(DataTransferStatus.TransferState.InProgress).ConfigureAwait(false); try { @@ -247,7 +247,7 @@ await DownloadStreamingInternal(range: httpRange).ConfigureAwait(false)) } else { - await CheckAndUpdateCancellationStatusAsync().ConfigureAwait(false); + await CheckAndUpdateCancellationStateAsync().ConfigureAwait(false); } } catch (Exception ex) @@ -340,7 +340,7 @@ await _destinationResource.CompleteTransferAsync( await DisposeHandlers().ConfigureAwait(false); // Update the transfer status - await OnTransferStateChanged(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); + await OnTransferStateChangedAsync(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); } catch (Exception ex) { @@ -512,7 +512,7 @@ await QueueChunkToChannelAsync( } else { - await CheckAndUpdateCancellationStatusAsync().ConfigureAwait(false); + await CheckAndUpdateCancellationStateAsync().ConfigureAwait(false); } } } diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/Azure.Storage.DataMovement.Tests.csproj b/sdk/storage/Azure.Storage.DataMovement/tests/Azure.Storage.DataMovement.Tests.csproj index 92cc0c5061113..0a0b4177ce289 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/Azure.Storage.DataMovement.Tests.csproj +++ b/sdk/storage/Azure.Storage.DataMovement/tests/Azure.Storage.DataMovement.Tests.csproj @@ -1,6 +1,6 @@  - $(RequiredTargetFrameworks) + $(RequiredTargetFrameworks);net6.0 Microsoft Azure.Storage.DataMovement client library tests BlobDataMovementSDK;$(DefineConstants) false diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/DataTransferTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/DataTransferTests.cs index fc9d2904a4b01..5bf896bdc20a8 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/DataTransferTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/DataTransferTests.cs @@ -170,7 +170,7 @@ public async Task TryPauseAsync() Assert.AreEqual(DataTransferStatus.TransferState.Pausing, transfer.TransferStatus); // Assert - if (!transfer._state.TrySetTransferStatus(DataTransferStatus.TransferState.Paused)) + if (!transfer._state.TrySetTransferState(DataTransferStatus.TransferState.Paused)) { Assert.Fail("Unable to set the transfer status internally to the DataTransfer."); } From 04e6d4663f0df8beee245deef980d4f4e0b34e5b Mon Sep 17 00:00:00 2001 From: Amanda Nguyen Date: Mon, 21 Aug 2023 13:15:52 -0700 Subject: [PATCH 04/13] WIP --- .../Azure.Storage.DataMovement/src/JobPartInternal.cs | 8 ++++---- .../src/ServiceToServiceTransferJob.cs | 6 +++--- .../src/StreamToUriTransferJob.cs | 6 +++--- .../Azure.Storage.DataMovement/src/TransferJobInternal.cs | 7 +------ .../src/UriToStreamTransferJob.cs | 6 +++--- 5 files changed, 14 insertions(+), 19 deletions(-) diff --git a/sdk/storage/Azure.Storage.DataMovement/src/JobPartInternal.cs b/sdk/storage/Azure.Storage.DataMovement/src/JobPartInternal.cs index d5fdd0845bee8..8b013720c15db 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/JobPartInternal.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/JobPartInternal.cs @@ -307,7 +307,7 @@ internal async Task OnTransferStateChangedAsync(DataTransferStatus.TransferState } // Set the status in the checkpointer - await SetCheckpointerState(transferState).ConfigureAwait(false); + await SetCheckpointerStatus().ConfigureAwait(false); await PartTransferStatusEventHandler.RaiseAsync( new TransferStatusEventArgs( @@ -488,12 +488,12 @@ await _checkpointer.AddNewJobPartAsync( } } - internal async virtual Task SetCheckpointerState(DataTransferStatus.TransferState state) + internal async virtual Task SetCheckpointerStatus() { - await _checkpointer.SetJobPartTransferStateAsync( + await _checkpointer.SetJobPartTransferStatusAsync( transferId: _dataTransfer.Id, partNumber: PartNumber, - state: state).ConfigureAwait(false); + state: JobPartStatus).ConfigureAwait(false); } internal long CalculateBlockSize(long length) diff --git a/sdk/storage/Azure.Storage.DataMovement/src/ServiceToServiceTransferJob.cs b/sdk/storage/Azure.Storage.DataMovement/src/ServiceToServiceTransferJob.cs index 2e9e4b664459a..f80afcb85046f 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/ServiceToServiceTransferJob.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/ServiceToServiceTransferJob.cs @@ -69,7 +69,7 @@ internal ServiceToServiceTransferJob( /// An IEnumerable that contains the job parts public override async IAsyncEnumerable ProcessJobToJobPartAsync() { - await OnJobStatusChangedAsync(DataTransferStatus.InProgress).ConfigureAwait(false); + await OnJobStateChangedAsync(DataTransferStatus.TransferState.InProgress).ConfigureAwait(false); int partNumber = 0; if (_jobParts.Count == 0) @@ -108,9 +108,9 @@ public override async IAsyncEnumerable ProcessJobToJobPartAsync bool isFinalPartFound = false; foreach (JobPartInternal part in _jobParts) { - if (part.JobPartStatus != DataTransferStatus.TransferState.Completed) + if (!part.JobPartStatus.HasCompletedSuccessfully) { - part.JobPartStatus = DataTransferStatus.Queued; + part.JobPartStatus.OnTransferStateChange(DataTransferStatus.TransferState.Queued); yield return part; if (part.IsFinalPart) diff --git a/sdk/storage/Azure.Storage.DataMovement/src/StreamToUriTransferJob.cs b/sdk/storage/Azure.Storage.DataMovement/src/StreamToUriTransferJob.cs index cc1d0fab68e5d..ddb038e81270c 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/StreamToUriTransferJob.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/StreamToUriTransferJob.cs @@ -67,7 +67,7 @@ internal StreamToUriTransferJob( /// An IEnumerable that contains the job parts public override async IAsyncEnumerable ProcessJobToJobPartAsync() { - await OnJobStatusChangedAsync(DataTransferStatus.InProgress).ConfigureAwait(false); + await OnJobStateChangedAsync(DataTransferStatus.TransferState.InProgress).ConfigureAwait(false); int partNumber = 0; if (_jobParts.Count == 0) @@ -106,9 +106,9 @@ public override async IAsyncEnumerable ProcessJobToJobPartAsync bool isFinalPartFound = false; foreach (JobPartInternal part in _jobParts) { - if (part.JobPartStatus != DataTransferStatus.TransferState.Completed) + if (!part.JobPartStatus.HasCompletedSuccessfully) { - part.JobPartStatus = DataTransferStatus.Queued; + part.JobPartStatus.OnTransferStateChange(DataTransferStatus.TransferState.Queued); yield return part; if (part.IsFinalPart) diff --git a/sdk/storage/Azure.Storage.DataMovement/src/TransferJobInternal.cs b/sdk/storage/Azure.Storage.DataMovement/src/TransferJobInternal.cs index 902f466233d21..5148e9131884e 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/TransferJobInternal.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/TransferJobInternal.cs @@ -284,7 +284,6 @@ public async virtual Task InvokeFailedArgAsync(Exception ex) { if (TransferFailedEventHandler != null) { - // TODO: change to RaiseAsync await TransferFailedEventHandler.RaiseAsync( new TransferItemFailedEventArgs( _dataTransfer.Id, @@ -298,12 +297,8 @@ await TransferFailedEventHandler.RaiseAsync( ClientDiagnostics) .ConfigureAwait(false); } - if (_dataTransfer._state.TryOnFailedItemsState()) - { - - } + _dataTransfer._state.TryOnFailedItemsState(); } - // Trigger job cancellation if the failed handler is enabled await TriggerJobCancellationAsync().ConfigureAwait(false); // If we're failing from a Transfer Job point, it means we have aborted the job diff --git a/sdk/storage/Azure.Storage.DataMovement/src/UriToStreamTransferJob.cs b/sdk/storage/Azure.Storage.DataMovement/src/UriToStreamTransferJob.cs index 4aae089a43ddb..d4d1ea9fb6f0c 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/UriToStreamTransferJob.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/UriToStreamTransferJob.cs @@ -67,7 +67,7 @@ internal UriToStreamTransferJob( /// An IEnumerable that contains the job parts public override async IAsyncEnumerable ProcessJobToJobPartAsync() { - await OnJobStatusChangedAsync(DataTransferStatus.InProgress).ConfigureAwait(false); + await OnJobStateChangedAsync(DataTransferStatus.TransferState.InProgress).ConfigureAwait(false); int partNumber = 0; if (_jobParts.Count == 0) @@ -106,9 +106,9 @@ public override async IAsyncEnumerable ProcessJobToJobPartAsync bool isFinalPartFound = false; foreach (JobPartInternal part in _jobParts) { - if (part.JobPartStatus != DataTransferStatus.TransferState.Completed) + if (!part.JobPartStatus.HasCompletedSuccessfully) { - part.JobPartStatus = DataTransferStatus.Queued; + part.JobPartStatus.OnTransferStateChange(DataTransferStatus.TransferState.Queued); yield return part; if (part.IsFinalPart) From a22c375b8afed5c906e357011f543a04a8e5a5ed Mon Sep 17 00:00:00 2001 From: Amanda Nguyen Date: Tue, 22 Aug 2023 10:06:10 -0700 Subject: [PATCH 05/13] WIP - tests updated --- .../samples/Sample01b_HelloWorldAsync.cs | 2 +- .../Azure.Storage.DataMovement.Blobs.csproj | 2 +- .../Azure.Storage.DataMovement/CHANGELOG.md | 1 + .../src/DataTransferStatus.cs | 13 +- .../src/Shared/DataTransferStatusInternal.cs | 15 +++ .../src/Shared/JobPlan/JobPartPlanHeader.cs | 4 +- .../src/Shared/TransferStatusEventArgs.cs | 4 +- .../src/TransferJobInternal.cs | 2 +- .../tests/DataTransferTests.cs | 58 +++++---- .../tests/GetTransfersTests.cs | 121 ++++++++++-------- .../tests/JobPartPlanHeaderTests.cs | 28 +++- .../tests/LocalTransferCheckpointerFactory.cs | 13 +- .../tests/LocalTransferCheckpointerTests.cs | 12 +- .../tests/PauseResumeTransferTests.cs | 4 +- .../tests/Shared/CheckpointerTesting.cs | 10 +- .../StartTransferDownloadDirectoryTests.cs | 15 ++- .../tests/StartTransferDownloadTests.cs | 32 +++-- .../StartTransferSyncCopyDirectoryTests.cs | 15 ++- .../tests/StartTransferSyncCopyTests.cs | 24 ++-- .../StartTransferUploadDirectoryTests.cs | 15 ++- .../tests/StartTransferUploadTests.cs | 32 +++-- .../tests/TestEventsRaised.cs | 66 ++++++---- 22 files changed, 309 insertions(+), 179 deletions(-) create mode 100644 sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransferStatusInternal.cs diff --git a/sdk/storage/Azure.Storage.DataMovement.Blobs/samples/Sample01b_HelloWorldAsync.cs b/sdk/storage/Azure.Storage.DataMovement.Blobs/samples/Sample01b_HelloWorldAsync.cs index 63b020d10f6fe..f765ebb6cd3eb 100644 --- a/sdk/storage/Azure.Storage.DataMovement.Blobs/samples/Sample01b_HelloWorldAsync.cs +++ b/sdk/storage/Azure.Storage.DataMovement.Blobs/samples/Sample01b_HelloWorldAsync.cs @@ -527,7 +527,7 @@ public async Task UploadDirectory_EventHandler_SasAsync() DataTransferOptions transferOptions = new DataTransferOptions(); transferOptions.TransferStatusChanged += (TransferStatusEventArgs args) => { - if (args.StorageTransferStatus.HasCompletedSuccessfully) + if (args.TransferStatus.HasCompletedSuccessfully) { using (StreamWriter logStream = File.AppendText(logFile)) { diff --git a/sdk/storage/Azure.Storage.DataMovement.Blobs/src/Azure.Storage.DataMovement.Blobs.csproj b/sdk/storage/Azure.Storage.DataMovement.Blobs/src/Azure.Storage.DataMovement.Blobs.csproj index a86fbfb8a1b30..38b9b2b134b7a 100644 --- a/sdk/storage/Azure.Storage.DataMovement.Blobs/src/Azure.Storage.DataMovement.Blobs.csproj +++ b/sdk/storage/Azure.Storage.DataMovement.Blobs/src/Azure.Storage.DataMovement.Blobs.csproj @@ -46,6 +46,7 @@ + @@ -53,7 +54,6 @@ - diff --git a/sdk/storage/Azure.Storage.DataMovement/CHANGELOG.md b/sdk/storage/Azure.Storage.DataMovement/CHANGELOG.md index dfcdbbc5ad115..0520d6d2e83e2 100644 --- a/sdk/storage/Azure.Storage.DataMovement/CHANGELOG.md +++ b/sdk/storage/Azure.Storage.DataMovement/CHANGELOG.md @@ -41,6 +41,7 @@ - [BREAKING CHANGE] Renamed `SingleTransferCompletedEventArgs` to `TransferItemCompletedEventArgs` - [BREAKING CHANGE] Renamed `TransferItemFailedEventArgs` to `TransferItemFailedEventArgs` - [BREAKING CHANGE] Renamed `TransferItemSkippedEventArgs` to `TransferItemSkippedEventArgs` +- [BREAKING CHANGE] Renamed `TransferStatusEventArgs.StorageTransferStatus` to `TransferStatus` - [BREAKING CHANGE] Renamed `StorageResourceSingle` to `StorageResourceItem` - [BREAKING CHANGE] Renamed `StorageResourceItem.WriteFromStreamAsync` to `CopyFromStreamAsync` - [BREAKING CHANGE] Renamed `StorageResourceContainer.GetChildStorageResource` to `StorageResourceContainer.GetStorageResourceReference` diff --git a/sdk/storage/Azure.Storage.DataMovement/src/DataTransferStatus.cs b/sdk/storage/Azure.Storage.DataMovement/src/DataTransferStatus.cs index 4d9de1895faf5..d052be5e607c8 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/DataTransferStatus.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/DataTransferStatus.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using System; using System.Runtime.CompilerServices; using System.Threading; @@ -9,7 +10,7 @@ namespace Azure.Storage.DataMovement /// /// Defines the status of the Transfer Job. /// - public class DataTransferStatus + public class DataTransferStatus : IEquatable { private object _stateLock = new object(); private object _hasSkippedLock = new object(); @@ -178,5 +179,15 @@ internal bool OnTransferStateChange(TransferState state) } return false; } + + /// + /// Indicates whether the current object is equal to another object of the same type. + /// + /// An object to compare with this object. + /// Returns true if the current object is equal to the other parameter; otherwise, false. + public bool Equals(DataTransferStatus other) + => State.Equals(other.State) && + HasFailedItems.Equals(other.HasFailedItems) && + HasSkippedItems.Equals(other.HasSkippedItems); } } diff --git a/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransferStatusInternal.cs b/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransferStatusInternal.cs new file mode 100644 index 0000000000000..c7270363d19e3 --- /dev/null +++ b/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransferStatusInternal.cs @@ -0,0 +1,15 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Azure.Storage.DataMovement +{ + internal class DataTransferStatusInternal : DataTransferStatus + { + public DataTransferStatusInternal( + TransferState state, + bool hasFailedItems, + bool hasSkippedItems) + : base(state, hasFailedItems, hasSkippedItems) + { } + } +} diff --git a/sdk/storage/Azure.Storage.DataMovement/src/Shared/JobPlan/JobPartPlanHeader.cs b/sdk/storage/Azure.Storage.DataMovement/src/Shared/JobPlan/JobPartPlanHeader.cs index 1863c6e1bc977..06a43ed1faac4 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/Shared/JobPlan/JobPartPlanHeader.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/Shared/JobPlan/JobPartPlanHeader.cs @@ -852,12 +852,12 @@ public static JobPartPlanHeader Deserialize(Stream stream) // AtomicPartStatus.HasSkippedItems bool partStatusHasSkipped = Convert.ToBoolean(reader.ReadByte()); - DataTransferStatus atomicJobStatus = new DataTransferStatus( + DataTransferStatus atomicJobStatus = new DataTransferStatusInternal( jobStatusState, jobStatusHasFailed, jobStatusHasSkipped); - DataTransferStatus atomicPartStatus = new DataTransferStatus( + DataTransferStatus atomicPartStatus = new DataTransferStatusInternal( partStatusState, partStatusHasFailed, partStatusHasSkipped); diff --git a/sdk/storage/Azure.Storage.DataMovement/src/Shared/TransferStatusEventArgs.cs b/sdk/storage/Azure.Storage.DataMovement/src/Shared/TransferStatusEventArgs.cs index dd534f19803fd..1c6fbeded0d3b 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/Shared/TransferStatusEventArgs.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/Shared/TransferStatusEventArgs.cs @@ -12,7 +12,7 @@ public class TransferStatusEventArgs : DataTransferEventArgs /// /// Gets the of the job. /// - public DataTransferStatus StorageTransferStatus { get; } + public DataTransferStatus TransferStatus { get; } /// /// Initializes a new instance of the . @@ -28,7 +28,7 @@ public TransferStatusEventArgs( CancellationToken cancellationToken) : base (transferId, isRunningSynchronously, cancellationToken) { - StorageTransferStatus = transferStatus; + TransferStatus = transferStatus; } } } diff --git a/sdk/storage/Azure.Storage.DataMovement/src/TransferJobInternal.cs b/sdk/storage/Azure.Storage.DataMovement/src/TransferJobInternal.cs index 5148e9131884e..291889fc2714d 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/TransferJobInternal.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/TransferJobInternal.cs @@ -313,7 +313,7 @@ await TransferFailedEventHandler.RaiseAsync( /// public async Task JobPartEvent(TransferStatusEventArgs args) { - DataTransferStatus jobPartStatus = args.StorageTransferStatus; + DataTransferStatus jobPartStatus = args.TransferStatus; DataTransferStatus jobStatus = _dataTransfer._state.GetTransferStatus(); // Keep track of paused, failed, and skipped which we will use to determine final job status diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/DataTransferTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/DataTransferTests.cs index 5bf896bdc20a8..8d2c8c50b6b2c 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/DataTransferTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/DataTransferTests.cs @@ -12,6 +12,9 @@ namespace Azure.Storage.DataMovement.Tests public class DataTransferTests { private static string GetNewTransferId() => Guid.NewGuid().ToString(); + private static DataTransferStatus QueuedStatus => new DataTransferStatus(DataTransferStatus.TransferState.Queued, false, false); + private static DataTransferStatus InProgressStatus => new DataTransferStatus(DataTransferStatus.TransferState.InProgress, false, false); + private static DataTransferStatus SuccessfulCompletedStatus => new DataTransferStatus(DataTransferStatus.TransferState.Completed, false, false); [Test] public void Ctor_Default() @@ -30,13 +33,14 @@ public void Ctor_Default() } [Test] - [TestCase(DataTransferStatus.TransferState.None)] - [TestCase(DataTransferStatus.Queued)] - [TestCase(DataTransferStatus.InProgress)] - [TestCase(DataTransferStatus.TransferState.Pausing)] - [TestCase(DataTransferStatus.CancellationInProgress)] - [TestCase(DataTransferStatus.TransferState.Paused)] - public void HasCompleted_False(DataTransferStatus status) + [TestCase(DataTransferStatus.TransferState.None, false)] + [TestCase(DataTransferStatus.TransferState.Queued, false)] + [TestCase(DataTransferStatus.TransferState.InProgress, false)] + [TestCase(DataTransferStatus.TransferState.Pausing, false)] + [TestCase(DataTransferStatus.TransferState.Paused, false)] + [TestCase(DataTransferStatus.TransferState.Completed, false)] + [TestCase(DataTransferStatus.TransferState.Completed, true)] + public void HasCompleted_False(DataTransferStatus.TransferState status, bool HasFailures) { // Arrange string transferId = GetNewTransferId(); @@ -46,7 +50,7 @@ public void HasCompleted_False(DataTransferStatus status) DataTransfer transfer = new DataTransfer( id: transferId, transferManager: transferManager, - status: status); + status: new DataTransferStatus(status, HasFailures, false)); // Assert Assert.AreEqual(transferId, transfer.Id); @@ -55,10 +59,14 @@ public void HasCompleted_False(DataTransferStatus status) } [Test] - [TestCase(DataTransferStatus.TransferState.Completed)] - [TestCase(DataTransferStatus.TransferState.CompletedWithSkippedTransfers)] - [TestCase(DataTransferStatus.TransferState.CompletedWithFailedTransfers)] - public void HasCompleted_True(DataTransferStatus status) + [TestCase(DataTransferStatus.TransferState.Completed, false, false)] + [TestCase(DataTransferStatus.TransferState.Completed, false, true)] + [TestCase(DataTransferStatus.TransferState.Completed, true, false)] + [TestCase(DataTransferStatus.TransferState.Completed, true, true)] + public void HasCompleted_True( + DataTransferStatus status, + bool hasFailedItems, + bool hasSkippedItems) { // Arrange string transferId = GetNewTransferId(); @@ -86,7 +94,7 @@ public void EnsureCompleted() DataTransfer transfer = new DataTransfer( id: transferId, transferManager: transferManager, - status: DataTransferStatus.TransferState.Completed); + status: SuccessfulCompletedStatus); // Act transfer.WaitForCompletion(); @@ -106,7 +114,7 @@ public void EnsureCompleted_CancellationToken() DataTransfer transfer = new DataTransfer( id: transferId, transferManager: new(), - status: DataTransferStatus.Queued); + status: QueuedStatus); CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(1)); // Act @@ -125,7 +133,7 @@ public async Task AwaitCompletion() DataTransfer transfer = new DataTransfer( id: transferId, transferManager: transferManager, - status: DataTransferStatus.TransferState.Completed); + status: SuccessfulCompletedStatus); // Act await transfer.WaitForCompletionAsync(); @@ -145,7 +153,7 @@ public void AwaitCompletion_CancellationToken() DataTransfer transfer = new DataTransfer( id: transferId, transferManager: new(), - status: DataTransferStatus.Queued); + status: QueuedStatus); CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(1)); Assert.CatchAsync( @@ -162,7 +170,7 @@ public async Task TryPauseAsync() DataTransfer transfer = new DataTransfer( id: transferId, transferManager: new(), - status: DataTransferStatus.InProgress); + status: InProgressStatus); // Act Task pauseTask = transfer.PauseAsync(); @@ -182,11 +190,15 @@ public async Task TryPauseAsync() } [Test] - [TestCase(DataTransferStatus.TransferState.Paused)] - [TestCase(DataTransferStatus.TransferState.Completed)] - [TestCase(DataTransferStatus.TransferState.CompletedWithSkippedTransfers)] - [TestCase(DataTransferStatus.TransferState.CompletedWithFailedTransfers)] - public async Task TryPauseAsync_AlreadyPaused(DataTransferStatus status) + [TestCase(DataTransferStatus.TransferState.Paused, false, false)] + [TestCase(DataTransferStatus.TransferState.Completed, false, false)] + [TestCase(DataTransferStatus.TransferState.Completed, false, true)] + [TestCase(DataTransferStatus.TransferState.Completed, true, false)] + [TestCase(DataTransferStatus.TransferState.Completed, true, true)] + public async Task TryPauseAsync_AlreadyPaused( + DataTransferStatus status, + bool hasFailedItems, + bool hasSkippedItems) { // Arrange string transferId = GetNewTransferId(); @@ -210,7 +222,7 @@ public async Task TryPauseAsync_CancellationToken() DataTransfer transfer = new DataTransfer( id: transferId, transferManager: new(), - status: DataTransferStatus.InProgress); + status: InProgressStatus); CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(1)); try diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/GetTransfersTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/GetTransfersTests.cs index 85bde680184a3..70b9320f07098 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/GetTransfersTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/GetTransfersTests.cs @@ -14,6 +14,14 @@ namespace Azure.Storage.DataMovement.Tests /// public class GetTransfersTests { + private static DataTransferStatus QueuedStatus => new DataTransferStatus(DataTransferStatus.TransferState.Queued, false, false); + private static DataTransferStatus InProgressStatus => new DataTransferStatus(DataTransferStatus.TransferState.InProgress, false, false); + private static DataTransferStatus PausedStatus => new DataTransferStatus(DataTransferStatus.TransferState.Paused, false, false); + private static DataTransferStatus SuccessfulCompletedStatus => new DataTransferStatus(DataTransferStatus.TransferState.Completed, false, false); + private static DataTransferStatus FailedCompletedStatus => new DataTransferStatus(DataTransferStatus.TransferState.Completed, true, false); + private static DataTransferStatus SkippedCompletedStatus => new DataTransferStatus(DataTransferStatus.TransferState.Completed, true, false); + private static DataTransferStatus FailedSkippedCompletedStatus => new DataTransferStatus(DataTransferStatus.TransferState.Completed, true, false); + private TransferManagerOptions GetDefaultManagerOptions(string checkpointerPath) => new TransferManagerOptions() { @@ -38,7 +46,7 @@ private void AssertListTransfersEquals(IList expected, IList storedTransfers = new List { - GetNewDataTransfer(DataTransferStatus.Queued), - GetNewDataTransfer(DataTransferStatus.Queued), - GetNewDataTransfer(DataTransferStatus.Queued), - GetNewDataTransfer(DataTransferStatus.Queued), - GetNewDataTransfer(DataTransferStatus.InProgress), - GetNewDataTransfer(DataTransferStatus.InProgress), - GetNewDataTransfer(DataTransferStatus.TransferState.Paused), - GetNewDataTransfer(DataTransferStatus.TransferState.Paused), - GetNewDataTransfer(DataTransferStatus.TransferState.CompletedWithFailedTransfers), - GetNewDataTransfer(DataTransferStatus.TransferState.CompletedWithFailedTransfers), - GetNewDataTransfer(DataTransferStatus.TransferState.CompletedWithFailedTransfers), - GetNewDataTransfer(DataTransferStatus.TransferState.Completed), - GetNewDataTransfer(DataTransferStatus.TransferState.Completed), + GetNewDataTransfer(QueuedStatus), + GetNewDataTransfer(QueuedStatus), + GetNewDataTransfer(QueuedStatus), + GetNewDataTransfer(QueuedStatus), + GetNewDataTransfer(InProgressStatus), + GetNewDataTransfer(InProgressStatus), + GetNewDataTransfer(PausedStatus), + GetNewDataTransfer(PausedStatus), + GetNewDataTransfer(FailedCompletedStatus), + GetNewDataTransfer(FailedCompletedStatus), + GetNewDataTransfer(FailedCompletedStatus), + GetNewDataTransfer(SuccessfulCompletedStatus), + GetNewDataTransfer(SuccessfulCompletedStatus), }; TransferManagerFactory factory = new TransferManagerFactory(GetDefaultManagerOptions(testDirectory.DirectoryPath)); @@ -127,20 +138,20 @@ public async Task GetTransfers_FilterMultipleStatuses() // Arrange - Set up transfer manager with multiple transfers List storedTransfers = new List { - GetNewDataTransfer(DataTransferStatus.Queued), - GetNewDataTransfer(DataTransferStatus.Queued), - GetNewDataTransfer(DataTransferStatus.Queued), - GetNewDataTransfer(DataTransferStatus.Queued), - GetNewDataTransfer(DataTransferStatus.InProgress), - GetNewDataTransfer(DataTransferStatus.InProgress), - GetNewDataTransfer(DataTransferStatus.TransferState.Paused), - GetNewDataTransfer(DataTransferStatus.TransferState.Paused), - GetNewDataTransfer(DataTransferStatus.TransferState.CompletedWithFailedTransfers), - GetNewDataTransfer(DataTransferStatus.TransferState.CompletedWithFailedTransfers), - GetNewDataTransfer(DataTransferStatus.TransferState.CompletedWithFailedTransfers), - GetNewDataTransfer(DataTransferStatus.TransferState.Completed), - GetNewDataTransfer(DataTransferStatus.TransferState.Completed), - GetNewDataTransfer(DataTransferStatus.TransferState.CompletedWithSkippedTransfers) + GetNewDataTransfer(QueuedStatus), + GetNewDataTransfer(QueuedStatus), + GetNewDataTransfer(QueuedStatus), + GetNewDataTransfer(QueuedStatus), + GetNewDataTransfer(InProgressStatus), + GetNewDataTransfer(InProgressStatus), + GetNewDataTransfer(PausedStatus), + GetNewDataTransfer(PausedStatus), + GetNewDataTransfer(FailedCompletedStatus), + GetNewDataTransfer(FailedCompletedStatus), + GetNewDataTransfer(FailedCompletedStatus), + GetNewDataTransfer(SuccessfulCompletedStatus), + GetNewDataTransfer(SuccessfulCompletedStatus), + GetNewDataTransfer(SkippedCompletedStatus) }; TransferManagerFactory factory = new TransferManagerFactory(GetDefaultManagerOptions(testDirectory.DirectoryPath)); @@ -148,9 +159,9 @@ public async Task GetTransfers_FilterMultipleStatuses() // Act DataTransferStatus[] statuses = new DataTransferStatus[] { - DataTransferStatus.TransferState.Completed, - DataTransferStatus.TransferState.CompletedWithFailedTransfers, - DataTransferStatus.TransferState.CompletedWithSkippedTransfers }; + SuccessfulCompletedStatus, + FailedCompletedStatus, + SkippedCompletedStatus }; IList result = await manager.GetTransfersAsync(statuses).ToListAsync(); // Assert @@ -164,26 +175,26 @@ public async Task GetTransfers_Filtered_Empty() // Arrange - Set up transfer manager with multiple transfers List storedTransfers = new List { - GetNewDataTransfer(DataTransferStatus.Queued), - GetNewDataTransfer(DataTransferStatus.Queued), - GetNewDataTransfer(DataTransferStatus.Queued), - GetNewDataTransfer(DataTransferStatus.Queued), - GetNewDataTransfer(DataTransferStatus.InProgress), - GetNewDataTransfer(DataTransferStatus.InProgress), - GetNewDataTransfer(DataTransferStatus.TransferState.Paused), - GetNewDataTransfer(DataTransferStatus.TransferState.Paused), - GetNewDataTransfer(DataTransferStatus.TransferState.CompletedWithFailedTransfers), - GetNewDataTransfer(DataTransferStatus.TransferState.CompletedWithFailedTransfers), - GetNewDataTransfer(DataTransferStatus.TransferState.CompletedWithFailedTransfers), - GetNewDataTransfer(DataTransferStatus.TransferState.Completed), - GetNewDataTransfer(DataTransferStatus.TransferState.Completed), + GetNewDataTransfer(QueuedStatus), + GetNewDataTransfer(QueuedStatus), + GetNewDataTransfer(QueuedStatus), + GetNewDataTransfer(QueuedStatus), + GetNewDataTransfer(InProgressStatus), + GetNewDataTransfer(InProgressStatus), + GetNewDataTransfer(PausedStatus), + GetNewDataTransfer(PausedStatus), + GetNewDataTransfer(FailedCompletedStatus), + GetNewDataTransfer(FailedCompletedStatus), + GetNewDataTransfer(FailedCompletedStatus), + GetNewDataTransfer(SuccessfulCompletedStatus), + GetNewDataTransfer(SuccessfulCompletedStatus), }; TransferManagerFactory factory = new TransferManagerFactory(GetDefaultManagerOptions(testDirectory.DirectoryPath)); TransferManager manager = factory.BuildTransferManager(storedTransfers); // Act - With a transfer status not in the above stored transfers - DataTransferStatus[] statuses = new DataTransferStatus[] { DataTransferStatus.CancellationInProgress }; + DataTransferStatus[] statuses = new DataTransferStatus[] { new DataTransferStatus(DataTransferStatus.TransferState.Stopping, true, false) }; IList result = await manager.GetTransfersAsync(statuses).ToListAsync(); // Assert @@ -274,14 +285,14 @@ public async Task GetResumableTransfers_IgnoresCompleted() test.DirectoryPath, transferId1, 3 /* jobPartCount */, - DataTransferStatus.TransferState.Completed); + SuccessfulCompletedStatus); string transferId2 = Guid.NewGuid().ToString(); factory.CreateStubJobPartPlanFilesAsync( test.DirectoryPath, transferId2, 3 /* jobPartCount */, - DataTransferStatus.Queued); + QueuedStatus); // Build TransferManager with the stored transfers TransferManagerOptions options = new TransferManagerOptions() @@ -326,7 +337,7 @@ private void AddTransferFromDataTransferProperties( checkpointerPath, properties.TransferId, numParts, /* jobPartCount */ - DataTransferStatus.InProgress, + InProgressStatus, sourcePaths, destinationPaths, sourceResourceId: properties.SourceTypeId, @@ -338,7 +349,7 @@ private void AddTransferFromDataTransferProperties( checkpointerPath, properties.TransferId, 1, /* jobPartCount */ - DataTransferStatus.InProgress, + InProgressStatus, new List { properties.SourcePath }, new List { properties.DestinationPath }, sourceResourceId: properties.SourceTypeId, diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/JobPartPlanHeaderTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/JobPartPlanHeaderTests.cs index 427f88efe84ac..efabca14fe4cd 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/JobPartPlanHeaderTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/JobPartPlanHeaderTests.cs @@ -395,13 +395,29 @@ public async Task Serialize() await stream.ReadAsync(rehydratePriorityTypeBuffer, 0, oneByte); Assert.AreEqual((byte)DefaultRehydratePriorityType, rehydratePriorityTypeBuffer[0]); - byte[] atomicJobStatusBuffer = new byte[oneByte]; - await stream.ReadAsync(atomicJobStatusBuffer, 0, oneByte); - Assert.AreEqual((byte)DefaultJobStatus, atomicJobStatusBuffer[0]); + byte[] atomicJobStateBuffer = new byte[oneByte]; + await stream.ReadAsync(atomicJobStateBuffer, 0, oneByte); + Assert.AreEqual((byte)DefaultJobStatus.State, atomicJobStateBuffer[0]); - byte[] atomicPartStatusBuffer = new byte[oneByte]; - await stream.ReadAsync(atomicPartStatusBuffer, 0, oneByte); - Assert.AreEqual((byte)DefaultPartStatus, atomicPartStatusBuffer[0]); + byte[] atomicJobHasFailedItemsBuffer = new byte[oneByte]; + await stream.ReadAsync(atomicJobHasFailedItemsBuffer, 0, oneByte); + Assert.AreEqual((byte)DefaultJobStatus.State, atomicJobHasFailedItemsBuffer[0]); + + byte[] atomicJobHasSkippedItemsBuffer = new byte[oneByte]; + await stream.ReadAsync(atomicJobHasSkippedItemsBuffer, 0, oneByte); + Assert.AreEqual((byte)DefaultJobStatus.State, atomicJobHasSkippedItemsBuffer[0]); + + byte[] atomicPartStateBuffer = new byte[oneByte]; + await stream.ReadAsync(atomicPartStateBuffer, 0, oneByte); + Assert.AreEqual((byte)DefaultPartStatus.State, atomicPartStateBuffer[0]); + + byte[] atomiPartHasFailedItemsBuffer = new byte[oneByte]; + await stream.ReadAsync(atomiPartHasFailedItemsBuffer, 0, oneByte); + Assert.AreEqual((byte)DefaultJobStatus.State, atomiPartHasFailedItemsBuffer[0]); + + byte[] atomicPartHasSkippedItemsBuffer = new byte[oneByte]; + await stream.ReadAsync(atomicPartHasSkippedItemsBuffer, 0, oneByte); + Assert.AreEqual((byte)DefaultJobStatus.State, atomicPartHasSkippedItemsBuffer[0]); } } diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/LocalTransferCheckpointerFactory.cs b/sdk/storage/Azure.Storage.DataMovement/tests/LocalTransferCheckpointerFactory.cs index 255123d43b732..571dae599ffd2 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/LocalTransferCheckpointerFactory.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/LocalTransferCheckpointerFactory.cs @@ -43,8 +43,8 @@ internal static readonly DateTimeOffset _testStartTime internal const JobPartDeleteSnapshotsOption _testDeleteSnapshotsOption = JobPartDeleteSnapshotsOption.None; internal const JobPartPermanentDeleteOption _testPermanentDeleteOption = JobPartPermanentDeleteOption.None; internal const JobPartPlanRehydratePriorityType _testRehydratePriorityType = JobPartPlanRehydratePriorityType.None; - internal const DataTransferStatus _testJobStatus = DataTransferStatus.Queued; - internal const DataTransferStatus _testPartStatus = DataTransferStatus.Queued; + internal static readonly DataTransferStatus _testJobStatus = new DataTransferStatusInternal(DataTransferStatus.TransferState.Queued, false, false); + internal static readonly DataTransferStatus _testPartStatus = new DataTransferStatusInternal(DataTransferStatus.TransferState.Queued, false, false); private string _checkpointerPath; @@ -89,12 +89,13 @@ internal void CreateStubJobPartPlanFilesAsync( string checkpointerPath, string transferId, int jobPartCount, - DataTransferStatus status = DataTransferStatus.Queued, + DataTransferStatus status = default, List sourcePaths = default, List destinationPaths = default, string sourceResourceId = "LocalFile", string destinationResourceId = "LocalFile") { + status ??= _testPartStatus; // Populate sourcePaths if not provided if (sourcePaths == default) { @@ -185,9 +186,11 @@ internal JobPartPlanHeader CreateDefaultJobPartHeader( JobPartDeleteSnapshotsOption deleteSnapshotsOption = _testDeleteSnapshotsOption, JobPartPermanentDeleteOption permanentDeleteOption = _testPermanentDeleteOption, JobPartPlanRehydratePriorityType rehydratePriorityType = _testRehydratePriorityType, - DataTransferStatus atomicJobStatus = _testJobStatus, - DataTransferStatus atomicPartStatus = _testPartStatus) + DataTransferStatus atomicJobStatus = default, + DataTransferStatus atomicPartStatus = default) { + atomicJobStatus ??= _testJobStatus; + atomicPartStatus ??= _testPartStatus; if (startTime == default) { startTime = _testStartTime; diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/LocalTransferCheckpointerTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/LocalTransferCheckpointerTests.cs index 61dc12d9b82e7..0b3c5a25efb89 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/LocalTransferCheckpointerTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/LocalTransferCheckpointerTests.cs @@ -14,6 +14,8 @@ namespace Azure.Storage.DataMovement.Tests { public class LocalTransferCheckpointerTests : DataMovementTestBase { + private static DataTransferStatus SuccessfulCompletedStatus => new DataTransferStatus(DataTransferStatus.TransferState.Completed, false, false); + public LocalTransferCheckpointerTests(bool async) : base(async, null) { @@ -906,7 +908,7 @@ public async Task SetJobTransferStatusAsync() string transferId = GetNewTransferId(); int partNumber = 0; int chunksTotal = 1; - DataTransferStatus newStatus = DataTransferStatus.TransferState.Completed; + DataTransferStatus newStatus = SuccessfulCompletedStatus; JobPartPlanHeader header = CheckpointerTesting.CreateDefaultJobPartHeader( transferId: transferId, partNumber: partNumber); @@ -948,7 +950,7 @@ public async Task SetJobTransferStatusAsync_MultipleParts() // Arrange string transferId = GetNewTransferId(); int chunksTotal = 1; - DataTransferStatus newStatus = DataTransferStatus.TransferState.Completed; + DataTransferStatus newStatus = SuccessfulCompletedStatus; JobPartPlanHeader header1 = CheckpointerTesting.CreateDefaultJobPartHeader( transferId: transferId, partNumber: 0); @@ -1057,7 +1059,7 @@ public void SetJobTransferStatusAsync_Error() // Arrange string transferId = GetNewTransferId(); int partNumber = 0; - DataTransferStatus newStatus = DataTransferStatus.TransferState.Completed; + DataTransferStatus newStatus = SuccessfulCompletedStatus; JobPartPlanHeader header = CheckpointerTesting.CreateDefaultJobPartHeader( transferId: transferId, partNumber: partNumber); @@ -1079,7 +1081,7 @@ public async Task SetJobPartTransferStatusAsync() int partNumber = 0; int chunksTotal = 1; // originally the default is set to Queued - DataTransferStatus newStatus = DataTransferStatus.TransferState.Completed; + DataTransferStatus newStatus = SuccessfulCompletedStatus; JobPartPlanHeader header = CheckpointerTesting.CreateDefaultJobPartHeader( transferId: transferId, partNumber: partNumber); @@ -1122,7 +1124,7 @@ public void SetJobPartTransferStatusAsync_Error() string transferId = GetNewTransferId(); int partNumber = 0; // originally the default is set to Queued - DataTransferStatus newStatus = DataTransferStatus.TransferState.Completed; + DataTransferStatus newStatus = SuccessfulCompletedStatus; JobPartPlanHeader header = CheckpointerTesting.CreateDefaultJobPartHeader( transferId: transferId, partNumber: partNumber); diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/PauseResumeTransferTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/PauseResumeTransferTests.cs index 2f85b5004a987..6f04cff2d3c1b 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/PauseResumeTransferTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/PauseResumeTransferTests.cs @@ -964,9 +964,9 @@ public async Task PauseAllTriggersCorrectPauses() List> pausable = new(); List> unpausable = new(); TransferManager manager = new(); - foreach (DataTransferStatus state in Enum.GetValues(typeof(DataTransferStatus)).Cast()) + foreach (DataTransferStatus status in Enum.GetValues(typeof(DataTransferStatus)).Cast()) { - bool canPause = state == DataTransferStatus.InProgress; + bool canPause = status.State == DataTransferStatus.TransferState.InProgress; Mock transfer = new(MockBehavior.Loose) { CallBase = true, diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/Shared/CheckpointerTesting.cs b/sdk/storage/Azure.Storage.DataMovement/tests/Shared/CheckpointerTesting.cs index 0801da3260dde..3762fc1c04336 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/Shared/CheckpointerTesting.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/Shared/CheckpointerTesting.cs @@ -46,8 +46,8 @@ internal static readonly DateTimeOffset DefaultStartTime internal const JobPartDeleteSnapshotsOption DefaultDeleteSnapshotsOption = JobPartDeleteSnapshotsOption.None; internal const JobPartPermanentDeleteOption DefaultPermanentDeleteOption = JobPartPermanentDeleteOption.None; internal const JobPartPlanRehydratePriorityType DefaultRehydratePriorityType = JobPartPlanRehydratePriorityType.None; - internal const DataTransferStatus DefaultJobStatus = new DataTransferStatus(); - internal const DataTransferStatus DefaultPartStatus = DataTransferStatus.Queued; + internal static readonly DataTransferStatus DefaultJobStatus = new DataTransferStatusInternal(DataTransferStatus.TransferState.Queued, false, false); + internal static readonly DataTransferStatus DefaultPartStatus = new DataTransferStatusInternal(DataTransferStatus.TransferState.Queued, false, false); internal static JobPartPlanHeader CreateDefaultJobPartHeader( string version = DataMovementConstants.PlanFile.SchemaVersion, @@ -95,8 +95,8 @@ internal static JobPartPlanHeader CreateDefaultJobPartHeader( JobPartDeleteSnapshotsOption deleteSnapshotsOption = DefaultDeleteSnapshotsOption, JobPartPermanentDeleteOption permanentDeleteOption = DefaultPermanentDeleteOption, JobPartPlanRehydratePriorityType rehydratePriorityType = DefaultRehydratePriorityType, - DataTransferStatus atomicJobStatus = DefaultJobStatus, - DataTransferStatus atomicPartStatus = DefaultPartStatus) + DataTransferStatus atomicJobStatus = default, + DataTransferStatus atomicPartStatus = default) { if (startTime == default) { @@ -108,6 +108,8 @@ internal static JobPartPlanHeader CreateDefaultJobPartHeader( } metadata ??= DataProvider.BuildMetadata(); blobTags ??= DataProvider.BuildTags(); + atomicJobStatus ??= DefaultJobStatus; + atomicPartStatus ??= DefaultPartStatus; JobPartPlanDestinationBlob dstBlobData = new JobPartPlanDestinationBlob( blobType: blobType, diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferDownloadDirectoryTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferDownloadDirectoryTests.cs index cf2f8f3720a29..fbcaf8be5fd5e 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferDownloadDirectoryTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferDownloadDirectoryTests.cs @@ -551,7 +551,8 @@ public async Task StartTransfer_AwaitCompletion_Failed() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("Cannot overwrite file.")); await testEventsRaised.AssertContainerCompletedWithFailedCheck(1); } @@ -589,7 +590,8 @@ public async Task StartTransfer_AwaitCompletion_Skipped() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithSkippedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); await testEventsRaised.AssertContainerCompletedWithSkippedCheck(1); } @@ -655,7 +657,8 @@ public async Task StartTransfer_EnsureCompleted_Failed() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("Cannot overwrite file.")); await testEventsRaised.AssertContainerCompletedWithFailedCheck(1); } @@ -693,7 +696,8 @@ public async Task StartTransfer_EnsureCompleted_Skipped() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithSkippedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); await testEventsRaised.AssertContainerCompletedWithSkippedCheck(1); } @@ -732,7 +736,8 @@ public async Task StartTransfer_EnsureCompleted_Failed_SmallChunks() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("Cannot overwrite file.")); await testEventsRaised.AssertContainerCompletedWithFailedCheck(1); } diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferDownloadTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferDownloadTests.cs index 6d58d377656bf..7ae7c5f97783c 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferDownloadTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferDownloadTests.cs @@ -117,7 +117,7 @@ private async Task DownloadBlockBlobsAndVerify( options[i].TransferStatusChanged += (TransferStatusEventArgs args) => { // Assert - if (args.StorageTransferStatus == DataTransferStatus.TransferState.Completed) + if (args.TransferStatus.HasCompletedSuccessfully) { completed = true; } @@ -285,7 +285,8 @@ public async Task BlockBlobToLocal_Skip_Exists() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithSkippedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(skippedSeen); FileInfo destFileInfo = new FileInfo(destFile); Assert.IsTrue(destFileInfo.Length == 0); @@ -327,7 +328,8 @@ public async Task BlockBlobToLocal_Failure_Exists() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); await testEventsRaised.AssertSingleFailedCheck(); FileInfo destFileInfo = new FileInfo(destFile); Assert.IsTrue(destFileInfo.Length == 0); @@ -692,7 +694,8 @@ public async Task AppendBlobToLocal_Skip_Exists() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithSkippedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); await testEventsRaised.AssertSingleSkippedCheck(); FileInfo destFileInfo = new FileInfo(destFile); Assert.IsTrue(destFileInfo.Length == 0); @@ -735,7 +738,8 @@ public async Task AppendBlobToLocal_Failure_Exists() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); await testEventsRaised.AssertSingleFailedCheck(); FileInfo destFileInfo = new FileInfo(destFile); Assert.IsTrue(destFileInfo.Length == 0); @@ -1152,7 +1156,8 @@ public async Task PageBlobToLocal_Skip_Exists() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithSkippedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); await testEventsRaised.AssertSingleSkippedCheck(); FileInfo destFileInfo = new FileInfo(destFile); Assert.IsTrue(destFileInfo.Length == 0); @@ -1195,7 +1200,8 @@ public async Task PageBlobToLocal_Failure_Exists() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); await testEventsRaised.AssertSingleFailedCheck(); FileInfo destFileInfo = new FileInfo(destFile); Assert.IsTrue(destFileInfo.Length == 0); @@ -1446,7 +1452,8 @@ public async Task StartTransfer_AwaitCompletion_Failed() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); await testEventRaised.AssertSingleFailedCheck(); Assert.AreEqual(1, testEventRaised.FailedEvents.Count); Assert.IsTrue(testEventRaised.FailedEvents.First().Exception.Message.Contains("Cannot overwrite file.")); @@ -1481,7 +1488,8 @@ public async Task StartTransfer_AwaitCompletion_Skipped() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithSkippedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); await testEventRaised.AssertSingleSkippedCheck(); } @@ -1545,7 +1553,8 @@ public async Task StartTransfer_EnsureCompleted_Failed() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); await testEventsRaised.AssertSingleFailedCheck(); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("Cannot overwrite file.")); } @@ -1580,7 +1589,8 @@ public async Task StartTransfer_EnsureCompleted_Skipped() await testEventsRaised.AssertSingleSkippedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithSkippedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); } #endregion } diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferSyncCopyDirectoryTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferSyncCopyDirectoryTests.cs index 83e3fddb7445b..09b037915f422 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferSyncCopyDirectoryTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferSyncCopyDirectoryTests.cs @@ -616,7 +616,8 @@ public async Task StartTransfer_AwaitCompletion_Failed() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); await testEventsRaised.AssertContainerCompletedWithFailedCheck(1); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); } @@ -649,7 +650,8 @@ public async Task StartTransfer_AwaitCompletion_Skipped() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithSkippedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); await testEventsRaised.AssertContainerCompletedWithSkippedCheck(1); } @@ -704,7 +706,8 @@ public async Task StartTransfer_EnsureCompleted_Failed() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); await testEventsRaised.AssertContainerCompletedWithFailedCheck(1); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); } @@ -738,7 +741,8 @@ public async Task StartTransfer_EnsureCompleted_Skipped() testEventsRaised.AssertUnexpectedFailureCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithSkippedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); } [Test] @@ -773,7 +777,8 @@ public async Task StartTransfer_EnsureCompleted_Failed_SmallChunks() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); await testEventsRaised.AssertContainerCompletedWithFailedCheck(1); } diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferSyncCopyTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferSyncCopyTests.cs index e073882432966..e9f26abfd120f 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferSyncCopyTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferSyncCopyTests.cs @@ -385,7 +385,8 @@ public async Task BlockBlobToBlockBlob_Skip_Exists() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithSkippedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); await testEventsRaised.AssertSingleSkippedCheck(); Assert.IsTrue(await destinationClient.ExistsAsync()); // Verify Upload - That we skipped over and didn't reupload something new. @@ -437,7 +438,8 @@ public async Task BlockBlobToBlockBlob_Failure_Exists() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(await destinationClient.ExistsAsync()); await testEventsRaised.AssertSingleFailedCheck(); Assert.NotNull(testEventsRaised.FailedEvents.First().Exception, "Excepted failure: Overwrite failure was supposed to be raised during the test"); @@ -526,7 +528,8 @@ public async Task AppendBlobToAppendBlob_Error() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); await testEventsRaised.AssertSingleFailedCheck(); Assert.NotNull(testEventsRaised.FailedEvents.First().Exception, "Excepted failure: Failure was supposed to be raised during the test"); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); @@ -579,7 +582,8 @@ public async Task PageBlobToPageBlob_Error() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); await testEventsRaised.AssertSingleFailedCheck(); Assert.NotNull(testEventsRaised.FailedEvents.First().Exception, "Excepted failure: Failure was supposed to be raised during the test"); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); @@ -678,7 +682,8 @@ public async Task StartTransfer_AwaitCompletion_Failed() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); await testEventsRaised.AssertSingleFailedCheck(); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); } @@ -711,7 +716,8 @@ public async Task StartTransfer_AwaitCompletion_Skipped() await testEventsRaised.AssertSingleSkippedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithSkippedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); } [RecordedTest] @@ -764,7 +770,8 @@ public async Task StartTransfer_EnsureCompleted_Failed() await testEventsRaised.AssertSingleFailedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); } @@ -796,7 +803,8 @@ public async Task StartTransfer_EnsureCompleted_Skipped() await testEventsRaised.AssertSingleSkippedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithSkippedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); } #endregion } diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferUploadDirectoryTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferUploadDirectoryTests.cs index 543f5cdbcfed8..28fa8e8f29416 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferUploadDirectoryTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferUploadDirectoryTests.cs @@ -768,7 +768,8 @@ public async Task StartTransfer_AwaitCompletion_Failed() await testEventsRaised.AssertContainerCompletedWithFailedCheck(1); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); } @@ -803,7 +804,8 @@ public async Task StartTransfer_AwaitCompletion_Skipped() await testEventsRaised.AssertContainerCompletedWithSkippedCheck(1); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithSkippedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); } [Test] @@ -865,7 +867,8 @@ public async Task StartTransfer_EnsureCompleted_Failed() await testEventsRaised.AssertContainerCompletedWithFailedCheck(1); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); } @@ -900,7 +903,8 @@ public async Task StartTransfer_EnsureCompleted_Skipped() await testEventsRaised.AssertContainerCompletedWithSkippedCheck(1); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithSkippedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); } [Test] @@ -935,7 +939,8 @@ public async Task StartTransfer_EnsureCompleted_Failed_SmallChunks() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); await testEventsRaised.AssertContainerCompletedWithFailedCheck(1); } diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferUploadTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferUploadTests.cs index b83d62dcaae37..37f26757da58f 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferUploadTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferUploadTests.cs @@ -166,7 +166,7 @@ public async Task LocalToBlockBlob_EventHandler() options.TransferStatusChanged += (TransferStatusEventArgs args) => { // Assert - if (args.StorageTransferStatus == DataTransferStatus.InProgress) + if (args.TransferStatus.State == DataTransferStatus.TransferState.InProgress) { progressSeen = true; } @@ -302,7 +302,8 @@ public async Task LocalToBlockBlob_Skip_Exists() await testEventsRaised.AssertSingleSkippedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithSkippedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); Assert.IsTrue(await destinationClient.ExistsAsync()); // Verify Upload - That we skipped over and didn't reupload something new. using (FileStream fileStream = File.OpenRead(originalSourceFile)) @@ -349,7 +350,8 @@ public async Task LocalToBlockBlob_Failure_Exists() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(await destinationClient.ExistsAsync()); await testEventRaised.AssertSingleFailedCheck(); Assert.NotNull(testEventRaised.FailedEvents.First().Exception, "Excepted failure: Overwrite failure was supposed to be raised during the test"); @@ -692,7 +694,8 @@ public async Task LocalToPageBlob_Skip_Exists() await testEventsRaised.AssertSingleSkippedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithSkippedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); Assert.IsTrue(await destinationClient.ExistsAsync()); // Verify Upload - That we skipped over and didn't reupload something new. using (FileStream fileStream = File.OpenRead(originalSourceFile)) @@ -739,7 +742,8 @@ public async Task LocalToPageBlob_Failure_Exists() await testEventsRaised.AssertSingleFailedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(await destinationClient.ExistsAsync()); Assert.NotNull(testEventsRaised.FailedEvents.First().Exception, "Excepted failure: Overwrite failure was supposed to be raised during the test"); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("The specified blob already exists.")); @@ -1133,7 +1137,8 @@ public async Task LocalToAppendBlob_Skip_Exists() await testEventsRaised.AssertSingleSkippedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithSkippedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); Assert.IsTrue(await destinationClient.ExistsAsync()); // Verify Upload - That we skipped over and didn't reupload something new. using (FileStream fileStream = File.OpenRead(originalSourceFile)) @@ -1180,7 +1185,8 @@ public async Task LocalToAppendBlob_Failure_Exists() await testEventsRaised.AssertSingleFailedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(await destinationClient.ExistsAsync()); Assert.NotNull(testEventsRaised.FailedEvents.First().Exception, "Excepted failure: Overwrite failure was supposed to be raised during the test"); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("The specified blob already exists.")); @@ -1441,7 +1447,8 @@ public async Task StartTransfer_AwaitCompletion_Failed() await testEventsRaised.AssertSingleFailedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); } @@ -1473,7 +1480,8 @@ public async Task StartTransfer_AwaitCompletion_Skipped() await testEventsRaised.AssertSingleSkippedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithSkippedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); } [RecordedTest] @@ -1526,7 +1534,8 @@ public async Task StartTransfer_EnsureCompleted_Failed() await testEventsRaised.AssertSingleFailedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithFailedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); } @@ -1558,7 +1567,8 @@ public async Task StartTransfer_EnsureCompleted_Skipped() await testEventsRaised.AssertSingleSkippedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.CompletedWithSkippedTransfers, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); } #endregion diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/TestEventsRaised.cs b/sdk/storage/Azure.Storage.DataMovement/tests/TestEventsRaised.cs index 16bef0f7eef3d..3502eae6bc5bb 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/TestEventsRaised.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/TestEventsRaised.cs @@ -24,6 +24,14 @@ namespace Azure.Storage.DataMovement.Tests /// internal class TestEventsRaised : IDisposable { + private static readonly DataTransferStatus InProgressStatus = new DataTransferStatus(DataTransferStatus.TransferState.InProgress, false, false); + private static readonly DataTransferStatus InProgressFailedStatus = new DataTransferStatus(DataTransferStatus.TransferState.InProgress, true, false); + private static readonly DataTransferStatus InProgressSkippedStatus = new DataTransferStatus(DataTransferStatus.TransferState.InProgress, false, true); + private static readonly DataTransferStatus StoppingFailedStatus = new DataTransferStatus(DataTransferStatus.TransferState.Stopping, true, false); + private static readonly DataTransferStatus SuccessfulCompletedStatus = new DataTransferStatus(DataTransferStatus.TransferState.Completed, false, false); + private static readonly DataTransferStatus SkippedCompletedStatus = new DataTransferStatus(DataTransferStatus.TransferState.Completed, false, true); + private static readonly DataTransferStatus FailedCompletedStatus = new DataTransferStatus(DataTransferStatus.TransferState.Completed, true, false); + public List FailedEvents { get; internal set; } public List StatusEvents { get; internal set; } public List SkippedEvents { get; internal set; } @@ -128,9 +136,9 @@ public async Task AssertSingleCompletedCheck() await WaitForStatusEventsAsync().ConfigureAwait(false); CollectionAssert.AreEqual( new DataTransferStatus[] { - DataTransferStatus.InProgress, - DataTransferStatus.TransferState.Completed }, - StatusEvents.Select(e => e.StorageTransferStatus)); + InProgressStatus, + SuccessfulCompletedStatus }, + StatusEvents.Select(e => e.TransferStatus)); } /// @@ -149,9 +157,9 @@ public async Task AssertSingleSkippedCheck() await WaitForStatusEventsAsync().ConfigureAwait(false); CollectionAssert.AreEqual( new DataTransferStatus[] { - DataTransferStatus.InProgress, - DataTransferStatus.TransferState.CompletedWithSkippedTransfers }, - StatusEvents.Select(e => e.StorageTransferStatus)); + InProgressStatus, + SkippedCompletedStatus }, + StatusEvents.Select(e => e.TransferStatus)); } /// @@ -170,10 +178,11 @@ public async Task AssertSingleFailedCheck() await WaitForStatusEventsAsync().ConfigureAwait(false); CollectionAssert.AreEqual( new DataTransferStatus[] { - DataTransferStatus.InProgress, - DataTransferStatus.CancellationInProgress, - DataTransferStatus.TransferState.CompletedWithFailedTransfers }, - StatusEvents.Select(e => e.StorageTransferStatus)); + InProgressStatus, + InProgressFailedStatus, + StoppingFailedStatus, + FailedCompletedStatus }, + StatusEvents.Select(e => e.TransferStatus)); } /// @@ -193,9 +202,9 @@ public async Task AssertContainerCompletedCheck(int transferCount) await WaitForStatusEventsAsync().ConfigureAwait(false); CollectionAssert.AreEqual( new DataTransferStatus[] { - DataTransferStatus.InProgress, - DataTransferStatus.TransferState.Completed }, - StatusEvents.Select(e => e.StorageTransferStatus)); + InProgressStatus, + SuccessfulCompletedStatus }, + StatusEvents.Select(e => e.TransferStatus)); } /// @@ -223,10 +232,11 @@ public async Task AssertContainerCompletedWithFailedCheck(int expectedFailureCou await WaitForStatusEventsAsync().ConfigureAwait(false); CollectionAssert.AreEqual( new DataTransferStatus[] { - DataTransferStatus.InProgress, - DataTransferStatus.CancellationInProgress, - DataTransferStatus.TransferState.CompletedWithFailedTransfers }, - StatusEvents.Select(e => e.StorageTransferStatus)); + InProgressStatus, + InProgressFailedStatus, + StoppingFailedStatus, + FailedCompletedStatus }, + StatusEvents.Select(e => e.TransferStatus)); } /// @@ -254,9 +264,11 @@ public async Task AssertContainerCompletedWithFailedCheckContinue(int expectedFa await WaitForStatusEventsAsync().ConfigureAwait(false); CollectionAssert.AreEqual( new DataTransferStatus[] { - DataTransferStatus.InProgress, - DataTransferStatus.TransferState.CompletedWithFailedTransfers }, - StatusEvents.Select(e => e.StorageTransferStatus)); + InProgressStatus, + InProgressFailedStatus, + StoppingFailedStatus, + FailedCompletedStatus }, + StatusEvents.Select(e => e.TransferStatus)); } /// @@ -274,9 +286,10 @@ public async Task AssertContainerCompletedWithSkippedCheck(int expectedSkipCount await WaitForStatusEventsAsync().ConfigureAwait(false); CollectionAssert.AreEqual( new DataTransferStatus[] { - DataTransferStatus.InProgress, - DataTransferStatus.TransferState.CompletedWithSkippedTransfers }, - StatusEvents.Select(e => e.StorageTransferStatus)); + InProgressStatus, + InProgressSkippedStatus, + SkippedCompletedStatus }, + StatusEvents.Select(e => e.TransferStatus)); } public async Task AssertPausedCheck() @@ -287,9 +300,10 @@ public async Task AssertPausedCheck() await WaitForStatusEventsAsync().ConfigureAwait(false); CollectionAssert.AreEqual( new DataTransferStatus[] { - DataTransferStatus.InProgress, - DataTransferStatus.TransferState.Paused }, - StatusEvents.Select(e => e.StorageTransferStatus)); + InProgressStatus, + new DataTransferStatus(DataTransferStatus.TransferState.Pausing, false, false), + new DataTransferStatus(DataTransferStatus.TransferState.Paused, false, false) }, + StatusEvents.Select(e => e.TransferStatus)); } /// From c7ce11ff536964e8ad90ffdd5ad172ae180197e8 Mon Sep 17 00:00:00 2001 From: Amanda Nguyen Date: Fri, 25 Aug 2023 15:33:31 -0700 Subject: [PATCH 06/13] Finished fixing tests with changes --- .../Azure.Storage.DataMovement/CHANGELOG.md | 3 +- .../src/CheckpointerExtensions.cs | 2 +- .../src/DataTransferStatus.cs | 12 +++ .../src/JobPartInternal.cs | 74 ++++++++---------- .../src/Shared/DataMovementConstants.cs | 7 +- .../src/Shared/DataTransfer.cs | 5 +- ...rState.cs => DataTransferInternalState.cs} | 8 +- .../src/Shared/LocalTransferCheckpointer.cs | 2 +- .../src/TransferJobInternal.cs | 2 +- .../tests/DataTransferTests.cs | 28 ++++--- .../tests/GetTransfersTests.cs | 6 +- .../tests/JobPartPlanHeaderTests.cs | 34 ++++++-- .../tests/PauseResumeTransferTests.cs | 36 ++++----- .../Resources/SampleJobPartPlanFile.steVb3 | Bin 0 -> 49032 bytes .../StartTransferDownloadDirectoryTests.cs | 18 ++--- .../tests/StartTransferDownloadTests.cs | 26 +++--- .../StartTransferSyncCopyDirectoryTests.cs | 18 ++--- .../tests/StartTransferSyncCopyTests.cs | 22 +++--- .../StartTransferUploadDirectoryTests.cs | 16 ++-- .../tests/StartTransferUploadTests.cs | 28 +++---- .../tests/TestEventsRaised.cs | 53 ++++++++----- 21 files changed, 220 insertions(+), 180 deletions(-) rename sdk/storage/Azure.Storage.DataMovement/src/Shared/{DataTransferState.cs => DataTransferInternalState.cs} (93%) create mode 100644 sdk/storage/Azure.Storage.DataMovement/tests/Resources/SampleJobPartPlanFile.steVb3 diff --git a/sdk/storage/Azure.Storage.DataMovement/CHANGELOG.md b/sdk/storage/Azure.Storage.DataMovement/CHANGELOG.md index 07c490f7d3323..7130097a95c0c 100644 --- a/sdk/storage/Azure.Storage.DataMovement/CHANGELOG.md +++ b/sdk/storage/Azure.Storage.DataMovement/CHANGELOG.md @@ -50,8 +50,9 @@ - [BREAKING CHANGE] Renamed `ErrorHandlingBehavior` to `DataTransferErrorMode` - [BREAKING CHANGE] Renamed `DataTransferErrorMode.StopOnAnyFailures` to `StopOnAnyFailure` - [BREAKING CHANGE] Renamed `TransferType` to `DataTransferOrder` -- [BREAKING CHANGE] Renamed `DataTransferOrder.Unordered` to `Unordered` +- [BREAKING CHANGE] Renamed `DataTransferOrder.Concurrent` to `Unordered` - [BREAKING CHANGE] Renamed `StorageTransferStatus` to `DataTransferStatus` +- [BREAKING CHANGE] Changed `DataTransferStatus` from `enum` to a `class`. - [BREAKING CHANGE] Renamed `StorageResourceCreateMode` to `StorageResourceCreationPreference`. - [BREAKING CHANGE] Renamed `StorageResourceCreationPreference` values from `Fail` to `FailIfExists`, `Overwrite` to `OverwriteIfExists` and `Skip` to `SkipIfExists`. `None` was removed, use `FailIfExists` instead. - [BREAKING CHANGE] Renamed `DataTransferOptions.CreateMode` to `CreationPreference`. diff --git a/sdk/storage/Azure.Storage.DataMovement/src/CheckpointerExtensions.cs b/sdk/storage/Azure.Storage.DataMovement/src/CheckpointerExtensions.cs index 5b398de8aeb74..5b1f628f24e1e 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/CheckpointerExtensions.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/CheckpointerExtensions.cs @@ -32,7 +32,7 @@ internal static async Task IsResumableAsync( bool hasSkippedItems = Convert.ToBoolean(hasSkippedItemsByte); // Transfers marked as fully completed are not resumable - return transferState.Equals(DataTransferStatus.TransferState.Completed) && !hasFailedItems && !hasSkippedItems; + return transferState != DataTransferStatus.TransferState.Completed || hasFailedItems || hasSkippedItems; } internal static async Task GetDataTransferPropertiesAsync( diff --git a/sdk/storage/Azure.Storage.DataMovement/src/DataTransferStatus.cs b/sdk/storage/Azure.Storage.DataMovement/src/DataTransferStatus.cs index d052be5e607c8..4d57e84fcb2eb 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/DataTransferStatus.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/DataTransferStatus.cs @@ -189,5 +189,17 @@ public bool Equals(DataTransferStatus other) => State.Equals(other.State) && HasFailedItems.Equals(other.HasFailedItems) && HasSkippedItems.Equals(other.HasSkippedItems); + + /// + /// Performs a Deep Copy of the . + /// + /// A deep copy of the respective . + internal DataTransferStatus DeepCopy() + => new DataTransferStatus + { + State = State, + HasFailedItems = HasFailedItems, + HasSkippedItems =HasSkippedItems, + }; } } diff --git a/sdk/storage/Azure.Storage.DataMovement/src/JobPartInternal.cs b/sdk/storage/Azure.Storage.DataMovement/src/JobPartInternal.cs index 8b013720c15db..dea671affdd28 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/JobPartInternal.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/JobPartInternal.cs @@ -322,44 +322,6 @@ await PartTransferStatusEventHandler.RaiseAsync( } } - internal async Task OnTransferFailedAsync() - { - // Update the JobPartStatus. If was already updated (e.g. there was a failed item before) - // then don't raise the PartTransferStatusEventHandler - if (JobPartStatus.OnFailedItem()) - { - await PartTransferStatusEventHandler.RaiseAsync( - new TransferStatusEventArgs( - _dataTransfer.Id, - JobPartStatus, - false, - _cancellationToken), - nameof(JobPartInternal), - nameof(PartTransferStatusEventHandler), - ClientDiagnostics) - .ConfigureAwait(false); - } - } - - internal async Task OnTransferSkippedAsync() - { - // Update the JobPartStatus. If was already updated (e.g. there was a failed item before) - // then don't raise the PartTransferStatusEventHandler - if (JobPartStatus.OnSkippedItem()) - { - await PartTransferStatusEventHandler.RaiseAsync( - new TransferStatusEventArgs( - _dataTransfer.Id, - JobPartStatus, - false, - _cancellationToken), - nameof(JobPartInternal), - nameof(PartTransferStatusEventHandler), - ClientDiagnostics) - .ConfigureAwait(false); - } - } - /// /// To change all transfer statues at the same time /// @@ -408,9 +370,24 @@ await TransferSkippedEventHandler.RaiseAsync( .ConfigureAwait(false); } _progressTracker.IncrementSkippedFiles(); - await OnTransferSkippedAsync().ConfigureAwait(false); + + // Update the JobPartStatus. If was already updated (e.g. there was a failed item before) + // then don't raise the PartTransferStatusEventHandler + if (JobPartStatus.OnSkippedItem()) + { + await PartTransferStatusEventHandler.RaiseAsync( + new TransferStatusEventArgs( + _dataTransfer.Id, + JobPartStatus, + false, + _cancellationToken), + nameof(JobPartInternal), + nameof(PartTransferStatusEventHandler), + ClientDiagnostics) + .ConfigureAwait(false); + } //TODO: figure out why we set the Completed state here and not just wait for all the chunks to finish - //await OnTransferStateChangedAsync(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); + await OnTransferStateChangedAsync(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); } /// @@ -439,9 +416,24 @@ await TransferFailedEventHandler.RaiseAsync( .ConfigureAwait(false); } _progressTracker.IncrementFailedFiles(); + + // Update the JobPartStatus. If was already updated (e.g. there was a failed item before) + // then don't raise the PartTransferStatusEventHandler + if (JobPartStatus.OnFailedItem()) + { + await PartTransferStatusEventHandler.RaiseAsync( + new TransferStatusEventArgs( + _dataTransfer.Id, + JobPartStatus, + false, + _cancellationToken), + nameof(JobPartInternal), + nameof(PartTransferStatusEventHandler), + ClientDiagnostics) + .ConfigureAwait(false); + } } // Trigger job cancellation if the failed handler is enabled - await OnTransferFailedAsync().ConfigureAwait(false); await TriggerCancellationAsync().ConfigureAwait(false); await CheckAndUpdateCancellationStateAsync().ConfigureAwait(false); } diff --git a/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataMovementConstants.cs b/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataMovementConstants.cs index 24515f2f5ad08..12bf1317c96fc 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataMovementConstants.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataMovementConstants.cs @@ -60,7 +60,8 @@ internal static class PlanFile { internal const string SchemaVersion_b1 = "b1"; internal const string SchemaVersion_b2 = "b2"; - internal const string SchemaVersion = SchemaVersion_b2; // TODO: remove b for beta + internal const string SchemaVersion_b3 = "b3"; + internal const string SchemaVersion = SchemaVersion_b3; // TODO: remove b for beta // Job Plan file extension. e.g. the file extension will look like {transferid}--{jobpartNumber}.steV{schemaVersion} internal const string FileExtension = ".steV"; @@ -228,12 +229,10 @@ internal static class PlanFile internal const int AtomicPartStatusHasFailedIndex = AtomicPartStatusStateIndex + OneByte; /// Index: 49027 internal const int AtomicPartStatusHasSkippedIndex = AtomicPartStatusHasFailedIndex + OneByte; - /// Index: 49028 - internal const int AtomicPartStatusIndex = AtomicPartStatusHasSkippedIndex + OneByte; /// /// Size of the JobPart Header: 49029 /// - internal const int JobPartHeaderSizeInBytes = AtomicPartStatusIndex + OneByte; + internal const int JobPartHeaderSizeInBytes = AtomicPartStatusHasSkippedIndex + OneByte; } internal static class ErrorCode diff --git a/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransfer.cs b/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransfer.cs index 657e20e019097..12ab5aac84e94 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransfer.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransfer.cs @@ -36,7 +36,7 @@ public class DataTransfer /// /// Defines the current state of the transfer. /// - internal DataTransferState _state; + internal DataTransferInternalState _state; /// /// For mocking. @@ -58,7 +58,8 @@ internal DataTransfer( { Argument.AssertNotNullOrEmpty(id, nameof(id)); Argument.AssertNotNull(transferManager, nameof(transferManager)); - _state = new DataTransferState(id, status); + status ??= new DataTransferStatus(); + _state = new DataTransferInternalState(id, status); TransferManager = transferManager; } diff --git a/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransferState.cs b/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransferInternalState.cs similarity index 93% rename from sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransferState.cs rename to sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransferInternalState.cs index 393ea2149cc81..eb375f7a7a9e8 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransferState.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransferInternalState.cs @@ -12,7 +12,7 @@ namespace Azure.Storage.DataMovement /// /// Defines the state of the transfer /// - internal class DataTransferState + internal class DataTransferInternalState { private string _id; private DataTransferStatus _status; @@ -28,7 +28,7 @@ internal class DataTransferState /// /// The transfer ID of the transfer object. /// The Transfer Status of the Transfer. See . - public DataTransferState( + public DataTransferInternalState( string id = default, DataTransferStatus status = default) { @@ -59,9 +59,7 @@ internal set { } public bool HasCompleted { get { - // TODO: look to whether before a paused state was considered completed.. - return (DataTransferStatus.TransferState.Completed == _status.State || - DataTransferStatus.TransferState.Paused == _status.State); + return DataTransferStatus.TransferState.Completed == _status.State; } internal set { } } diff --git a/sdk/storage/Azure.Storage.DataMovement/src/Shared/LocalTransferCheckpointer.cs b/sdk/storage/Azure.Storage.DataMovement/src/Shared/LocalTransferCheckpointer.cs index e90ea724af984..d073df59a0950 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/Shared/LocalTransferCheckpointer.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/Shared/LocalTransferCheckpointer.cs @@ -355,7 +355,7 @@ public override async Task SetJobPartTransferStatusAsync( CancellationToken cancellationToken = default) { long length = DataMovementConstants.PlanFile.OneByte * 3; - int offset = DataMovementConstants.PlanFile.AtomicPartStatusIndex; + int offset = DataMovementConstants.PlanFile.AtomicPartStatusStateIndex; CancellationHelper.ThrowIfCancellationRequested(cancellationToken); if (_transferStates.TryGetValue(transferId, out Dictionary jobPartFiles)) diff --git a/sdk/storage/Azure.Storage.DataMovement/src/TransferJobInternal.cs b/sdk/storage/Azure.Storage.DataMovement/src/TransferJobInternal.cs index bf7dc42d319e0..d44318a449513 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/TransferJobInternal.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/TransferJobInternal.cs @@ -386,7 +386,7 @@ public async Task OnJobPartStatusChangedAsync() await TransferStatusEventHandler.RaiseAsync( new TransferStatusEventArgs( transferId: _dataTransfer.Id, - transferStatus: _dataTransfer.TransferStatus, + transferStatus: _dataTransfer.TransferStatus.DeepCopy(), isRunningSynchronously: false, cancellationToken: _cancellationToken), nameof(TransferJobInternal), diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/DataTransferTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/DataTransferTests.cs index 8d2c8c50b6b2c..a4d8b5040608e 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/DataTransferTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/DataTransferTests.cs @@ -38,9 +38,9 @@ public void Ctor_Default() [TestCase(DataTransferStatus.TransferState.InProgress, false)] [TestCase(DataTransferStatus.TransferState.Pausing, false)] [TestCase(DataTransferStatus.TransferState.Paused, false)] - [TestCase(DataTransferStatus.TransferState.Completed, false)] - [TestCase(DataTransferStatus.TransferState.Completed, true)] - public void HasCompleted_False(DataTransferStatus.TransferState status, bool HasFailures) + [TestCase(DataTransferStatus.TransferState.Stopping, false)] + [TestCase(DataTransferStatus.TransferState.Stopping, true)] + public void HasCompleted_False(DataTransferStatus.TransferState status, bool hasFailedItems) { // Arrange string transferId = GetNewTransferId(); @@ -50,7 +50,7 @@ public void HasCompleted_False(DataTransferStatus.TransferState status, bool Has DataTransfer transfer = new DataTransfer( id: transferId, transferManager: transferManager, - status: new DataTransferStatus(status, HasFailures, false)); + status: new DataTransferStatus(status, hasFailedItems, false)); // Assert Assert.AreEqual(transferId, transfer.Id); @@ -64,7 +64,7 @@ public void HasCompleted_False(DataTransferStatus.TransferState status, bool Has [TestCase(DataTransferStatus.TransferState.Completed, true, false)] [TestCase(DataTransferStatus.TransferState.Completed, true, true)] public void HasCompleted_True( - DataTransferStatus status, + DataTransferStatus.TransferState state, bool hasFailedItems, bool hasSkippedItems) { @@ -76,7 +76,7 @@ public void HasCompleted_True( DataTransfer transfer = new DataTransfer( id: transferId, transferManager: transferManager, - status: status); + status: new DataTransferStatus(state, hasFailedItems, hasSkippedItems)); // Assert Assert.AreEqual(transferId, transfer.Id); @@ -175,7 +175,7 @@ public async Task TryPauseAsync() // Act Task pauseTask = transfer.PauseAsync(); - Assert.AreEqual(DataTransferStatus.TransferState.Pausing, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Pausing, transfer.TransferStatus.State); // Assert if (!transfer._state.TrySetTransferState(DataTransferStatus.TransferState.Paused)) @@ -185,7 +185,7 @@ public async Task TryPauseAsync() await pauseTask; - Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus.State); Assert.IsFalse(transfer.HasCompleted); } @@ -196,21 +196,23 @@ public async Task TryPauseAsync() [TestCase(DataTransferStatus.TransferState.Completed, true, false)] [TestCase(DataTransferStatus.TransferState.Completed, true, true)] public async Task TryPauseAsync_AlreadyPaused( - DataTransferStatus status, + DataTransferStatus.TransferState state, bool hasFailedItems, bool hasSkippedItems) { // Arrange string transferId = GetNewTransferId(); + DataTransferStatus originalStatus = new DataTransferStatus(state, hasFailedItems, hasSkippedItems); + DataTransfer transfer = new DataTransfer( id: transferId, transferManager: new(), - status: status); + status: originalStatus); - Assert.AreEqual(status, transfer.TransferStatus); + Assert.AreEqual(originalStatus, transfer.TransferStatus); await transfer.PauseAsync(); - Assert.AreEqual(status, transfer.TransferStatus); + Assert.AreEqual(originalStatus, transfer.TransferStatus); } [Test] @@ -233,7 +235,7 @@ public async Task TryPauseAsync_CancellationToken() { Assert.AreEqual(exception.Message, "The operation was canceled."); } - Assert.AreEqual(DataTransferStatus.TransferState.Pausing, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Pausing, transfer.TransferStatus.State); Assert.IsFalse(transfer.HasCompleted); } } diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/GetTransfersTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/GetTransfersTests.cs index 70b9320f07098..fa6099b86bf93 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/GetTransfersTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/GetTransfersTests.cs @@ -97,7 +97,7 @@ public async Task GetTransfers_Populated() [TestCase(DataTransferStatus.TransferState.Completed, false, false)] [TestCase(DataTransferStatus.TransferState.Completed, true, false)] public async Task GetTransfers_Filtered( - DataTransferStatus status, + DataTransferStatus.TransferState state, bool hasFailedItems, bool hasSkippedItems) { @@ -124,8 +124,8 @@ public async Task GetTransfers_Filtered( TransferManager manager = factory.BuildTransferManager(storedTransfers); // Act - DataTransferStatus[] statuses = new DataTransferStatus[] { status }; - IList result = await manager.GetTransfersAsync(statuses).ToListAsync(); + DataTransferStatus status = new DataTransferStatus(state, hasFailedItems, hasSkippedItems); + IList result = await manager.GetTransfersAsync(status).ToListAsync(); // Assert AssertListTransfersEquals(storedTransfers.Where( d => d.TransferStatus == status).ToList(), result); diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/JobPartPlanHeaderTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/JobPartPlanHeaderTests.cs index efabca14fe4cd..260ca3b166cab 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/JobPartPlanHeaderTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/JobPartPlanHeaderTests.cs @@ -401,11 +401,11 @@ public async Task Serialize() byte[] atomicJobHasFailedItemsBuffer = new byte[oneByte]; await stream.ReadAsync(atomicJobHasFailedItemsBuffer, 0, oneByte); - Assert.AreEqual((byte)DefaultJobStatus.State, atomicJobHasFailedItemsBuffer[0]); + Assert.AreEqual(Convert.ToByte(DefaultJobStatus.HasFailedItems), atomicJobHasFailedItemsBuffer[0]); byte[] atomicJobHasSkippedItemsBuffer = new byte[oneByte]; await stream.ReadAsync(atomicJobHasSkippedItemsBuffer, 0, oneByte); - Assert.AreEqual((byte)DefaultJobStatus.State, atomicJobHasSkippedItemsBuffer[0]); + Assert.AreEqual(Convert.ToByte(DefaultJobStatus.HasSkippedItems), atomicJobHasSkippedItemsBuffer[0]); byte[] atomicPartStateBuffer = new byte[oneByte]; await stream.ReadAsync(atomicPartStateBuffer, 0, oneByte); @@ -413,11 +413,11 @@ public async Task Serialize() byte[] atomiPartHasFailedItemsBuffer = new byte[oneByte]; await stream.ReadAsync(atomiPartHasFailedItemsBuffer, 0, oneByte); - Assert.AreEqual((byte)DefaultJobStatus.State, atomiPartHasFailedItemsBuffer[0]); + Assert.AreEqual(Convert.ToByte(DefaultJobStatus.HasFailedItems), atomiPartHasFailedItemsBuffer[0]); byte[] atomicPartHasSkippedItemsBuffer = new byte[oneByte]; await stream.ReadAsync(atomicPartHasSkippedItemsBuffer, 0, oneByte); - Assert.AreEqual((byte)DefaultJobStatus.State, atomicPartHasSkippedItemsBuffer[0]); + Assert.AreEqual(Convert.ToByte(DefaultJobStatus.HasSkippedItems), atomicPartHasSkippedItemsBuffer[0]); } } @@ -434,7 +434,7 @@ public void Serialize_Error() } [Test] - public void Deserialize() + public void Deserialize() { // Arrange IDictionary metadata = DataProvider.BuildMetadata(); @@ -475,7 +475,21 @@ public void Deserialize_File_Version_b2() using (FileStream stream = File.OpenRead(samplePath)) { // Act / Assert - DeserializeAndVerify(stream, DataMovementConstants.PlanFile.SchemaVersion_b2, DataProvider.BuildMetadata(), DataProvider.BuildTags()); + Assert.Catch( + () => JobPartPlanHeader.Deserialize(stream), + $"The checkpoint file schema version {DataMovementConstants.PlanFile.SchemaVersion_b2} is not supported by this version of the SDK."); + } + } + + [Test] + public void Deserialize_File_Version_b3() + { + // Arrange + string samplePath = Path.Combine("Resources", "SampleJobPartPlanFile.steVb3"); + using (FileStream stream = File.OpenRead(samplePath)) + { + // Act / Assert + DeserializeAndVerify(stream, DataMovementConstants.PlanFile.SchemaVersion_b3, DataProvider.BuildMetadata(), DataProvider.BuildTags()); } } @@ -556,8 +570,12 @@ private void DeserializeAndVerify( Assert.AreEqual(deserializedHeader.DeleteSnapshotsOption, DefaultDeleteSnapshotsOption); Assert.AreEqual(deserializedHeader.PermanentDeleteOption, DefaultPermanentDeleteOption); Assert.AreEqual(deserializedHeader.RehydratePriorityType, DefaultRehydratePriorityType); - Assert.AreEqual(deserializedHeader.AtomicJobStatus, DefaultJobStatus); - Assert.AreEqual(deserializedHeader.AtomicPartStatus, DefaultPartStatus); + Assert.AreEqual(DefaultJobStatus.State, deserializedHeader.AtomicJobStatus.State); + Assert.AreEqual(DefaultJobStatus.HasFailedItems, deserializedHeader.AtomicJobStatus.HasFailedItems); + Assert.AreEqual(DefaultJobStatus.HasSkippedItems, deserializedHeader.AtomicJobStatus.HasSkippedItems); + Assert.AreEqual(DefaultPartStatus.State, deserializedHeader.AtomicPartStatus.State); + Assert.AreEqual(DefaultPartStatus.HasFailedItems, deserializedHeader.AtomicPartStatus.HasFailedItems); + Assert.AreEqual(DefaultPartStatus.HasSkippedItems, deserializedHeader.AtomicPartStatus.HasSkippedItems); } } } diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/PauseResumeTransferTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/PauseResumeTransferTests.cs index 32d501ca3b2cd..1ec89a734661f 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/PauseResumeTransferTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/PauseResumeTransferTests.cs @@ -255,7 +255,7 @@ public async Task TryPauseTransferAsync_Id(TransferDirection transferType) // Assert await testEventsRaised.AssertPausedCheck(); - Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus.State); // Check if Job Plan File exists in checkpointer path. JobPartPlanFileName fileName = new JobPartPlanFileName( @@ -303,7 +303,7 @@ public async Task TryPauseTransferAsync_DataTransfer(TransferDirection transferT // Assert await testEventsRaised.AssertPausedCheck(); - Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus.State); // Check if Job Plan File exists in checkpointer path. JobPartPlanFileName fileName = new JobPartPlanFileName( @@ -367,12 +367,12 @@ public async Task TryPauseTransferAsync_AlreadyPaused(TransferDirection transfer // Assert await testEventsRaised.AssertPausedCheck(); - Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus.State); CancellationTokenSource cancellationTokenSource2 = new CancellationTokenSource(TimeSpan.FromSeconds(10)); await transferManager.PauseTransferIfRunningAsync(transfer.Id, cancellationTokenSource2.Token); - Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus.State); // Check if Job Plan File exists in checkpointer path. JobPartPlanFileName fileName = new JobPartPlanFileName( @@ -428,7 +428,7 @@ public async Task PauseThenResumeTransferAsync(TransferDirection transferType) await transferManager.PauseTransferIfRunningAsync(transfer.Id, cancellationTokenSource.Token); // Assert - Confirm we've paused - Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus.State); await testEventsRaised.AssertPausedCheck(); // Act - Resume Job @@ -443,7 +443,7 @@ public async Task PauseThenResumeTransferAsync(TransferDirection transferType) // Assert await testEventRaised2.AssertSingleCompletedCheck(); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, resumeTransfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, resumeTransfer.TransferStatus.State); Assert.IsTrue(resumeTransfer.HasCompleted); // Verify transfer @@ -499,7 +499,7 @@ public async Task ResumeTransferAsync(TransferDirection transferType) await transferManager.PauseTransferIfRunningAsync(transfer.Id, cancellationTokenSource.Token); // Assert - Confirm we've paused - Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus.State); await testEventsRaised.AssertPausedCheck(); // Act - Resume Job @@ -514,7 +514,7 @@ public async Task ResumeTransferAsync(TransferDirection transferType) // Assert await testEventRaised2.AssertSingleCompletedCheck(); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, resumeTransfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, resumeTransfer.TransferStatus.State); Assert.IsTrue(resumeTransfer.HasCompleted); // Verify transfer @@ -704,7 +704,7 @@ public async Task TryPauseTransferAsync_Id_Directory(TransferDirection transferT // Assert await testEventsRaised.AssertPausedCheck(); - Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus.State); } [Ignore("https://github.com/Azure/azure-sdk-for-net/issues/35439")] @@ -749,7 +749,7 @@ public async Task TryPauseTransferAsync_DataTransfer_Directory(TransferDirection // Assert await testEventsRaised.AssertPausedCheck(); - Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus.State); } [Ignore("https://github.com/Azure/azure-sdk-for-net/issues/35439")] @@ -794,13 +794,13 @@ public async Task TryPauseTransferAsync_AlreadyPaused_Directory(TransferDirectio // Assert await testEventsRaised.AssertPausedCheck(); - Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus.State); CancellationTokenSource cancellationTokenSource2 = new CancellationTokenSource(TimeSpan.FromSeconds(10)); await transferManager.PauseTransferIfRunningAsync(transfer.Id, cancellationTokenSource2.Token); await testEventsRaised.AssertPausedCheck(); - Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus.State); } [Ignore("https://github.com/Azure/azure-sdk-for-net/issues/35439")] @@ -852,7 +852,7 @@ public async Task PauseThenResumeTransferAsync_Directory(TransferDirection trans await transferManager.PauseTransferIfRunningAsync(transfer.Id, cancellationTokenSource.Token); // Assert - Confirm we've paused - Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus.State); await testEventsRaised.AssertPausedCheck(); // Act - Resume Job @@ -867,7 +867,7 @@ public async Task PauseThenResumeTransferAsync_Directory(TransferDirection trans // Assert await testEventRaised2.AssertContainerCompletedCheck(partCount); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, resumeTransfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, resumeTransfer.TransferStatus.State); Assert.IsTrue(resumeTransfer.HasCompleted); // Verify transfer @@ -928,7 +928,7 @@ public async Task ResumeTransferAsync_Directory(TransferDirection transferType) await transferManager.PauseTransferIfRunningAsync(transfer.Id, cancellationTokenSource.Token); // Assert - Confirm we've paused - Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus.State); await testEventsRaised.AssertPausedCheck(); // Act - Resume Job @@ -943,7 +943,7 @@ public async Task ResumeTransferAsync_Directory(TransferDirection transferType) // Assert await testEventsRaised2.AssertContainerCompletedCheck(partCount); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, resumeTransfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, resumeTransfer.TransferStatus.State); Assert.IsTrue(resumeTransfer.HasCompleted); // Verify transfer @@ -961,9 +961,9 @@ public async Task PauseAllTriggersCorrectPauses() List> pausable = new(); List> unpausable = new(); TransferManager manager = new(); - foreach (DataTransferStatus status in Enum.GetValues(typeof(DataTransferStatus)).Cast()) + foreach (DataTransferStatus.TransferState state in Enum.GetValues(typeof(DataTransferStatus.TransferState)).Cast()) { - bool canPause = status.State == DataTransferStatus.TransferState.InProgress; + bool canPause = state == DataTransferStatus.TransferState.InProgress; Mock transfer = new(MockBehavior.Loose) { CallBase = true, diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/Resources/SampleJobPartPlanFile.steVb3 b/sdk/storage/Azure.Storage.DataMovement/tests/Resources/SampleJobPartPlanFile.steVb3 new file mode 100644 index 0000000000000000000000000000000000000000..01f7674be7880e8d558666a98729b56b7987d2cc GIT binary patch literal 49032 zcmeI*KX21O7zf~s1QHbjRUr0CFd%`|Kaf(0B8G@AFjS~zzc|+t;l?3$hJHmp01Mv& zu`xhOs|txB40gIaUaYgvzxVVk*6Ggj@L33<{QmRn!*93p?#u0A%=4_`BNaXD#V3?c{+AV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5;&)d{SH^L2lF|5hii5&;4P2oPvZ;MeOHKjx3WJPDz5S)&u~g+V!~)1*E; zo2HG;je2ovZ2*D^5FkK+0D+bSZiJ)5{k@jL#S$PufB*pkD-u`_`NbSPE8^s29#72B zS0t|t0RjXF5NJ~1{?!|OG_Iy)HTHphlf1GB5FkK+z={O!ggoXSQ+7U6pOwXmswzW( z009C72sAG6G#r;@e;8-I(^SX)DAutzh|_T$i++*nI?Z}V2M2H7_w!h#UgPBj5+Fc; z009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RoK(Ji1J&{HHi6%gR009C7+7np+CwlQ)ygz@&>vVnt blobNames = new List(); @@ -222,7 +222,7 @@ public async Task DownloadDirectoryAsync_Empty() await transfer.WaitForCompletionAsync(cancellationTokenSource.Token); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); List localItemsAfterDownload = Directory.GetFiles(destinationFolder, "*", SearchOption.AllDirectories).ToList(); @@ -516,7 +516,7 @@ public async Task StartTransfer_AwaitCompletion() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); await testEventsRaised.AssertContainerCompletedCheck(4); } @@ -552,7 +552,7 @@ public async Task StartTransfer_AwaitCompletion_Failed() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("Cannot overwrite file.")); await testEventsRaised.AssertContainerCompletedWithFailedCheck(1); @@ -591,7 +591,7 @@ public async Task StartTransfer_AwaitCompletion_Skipped() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); await testEventsRaised.AssertContainerCompletedWithSkippedCheck(1); } @@ -622,7 +622,7 @@ public async Task StartTransfer_EnsureCompleted() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); await testEventsRaised.AssertContainerCompletedCheck(4); } @@ -658,7 +658,7 @@ public async Task StartTransfer_EnsureCompleted_Failed() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("Cannot overwrite file.")); await testEventsRaised.AssertContainerCompletedWithFailedCheck(1); @@ -697,7 +697,7 @@ public async Task StartTransfer_EnsureCompleted_Skipped() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); await testEventsRaised.AssertContainerCompletedWithSkippedCheck(1); } @@ -737,7 +737,7 @@ public async Task StartTransfer_EnsureCompleted_Failed_SmallChunks() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("Cannot overwrite file.")); await testEventsRaised.AssertContainerCompletedWithFailedCheck(1); diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferDownloadTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferDownloadTests.cs index ef2108724f8d1..0b5a02c3fb14a 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferDownloadTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferDownloadTests.cs @@ -170,7 +170,7 @@ private async Task DownloadBlockBlobsAndVerify( // Verify Download await downloadedBlobInfo[i].EventsRaised.AssertSingleCompletedCheck(); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, downloadedBlobInfo[i].DataTransfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, downloadedBlobInfo[i].DataTransfer.TransferStatus.State); CheckDownloadFile(downloadedBlobInfo[i].SourceLocalPath, downloadedBlobInfo[i].DestinationLocalPath); }; } @@ -286,7 +286,7 @@ public async Task BlockBlobToLocal_Skip_Exists() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(skippedSeen); FileInfo destFileInfo = new FileInfo(destFile); @@ -329,7 +329,7 @@ public async Task BlockBlobToLocal_Failure_Exists() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); await testEventsRaised.AssertSingleFailedCheck(); FileInfo destFileInfo = new FileInfo(destFile); @@ -695,7 +695,7 @@ public async Task AppendBlobToLocal_Skip_Exists() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); await testEventsRaised.AssertSingleSkippedCheck(); FileInfo destFileInfo = new FileInfo(destFile); @@ -739,7 +739,7 @@ public async Task AppendBlobToLocal_Failure_Exists() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); await testEventsRaised.AssertSingleFailedCheck(); FileInfo destFileInfo = new FileInfo(destFile); @@ -1156,7 +1156,7 @@ public async Task PageBlobToLocal_Skip_Exists() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); await testEventsRaised.AssertSingleSkippedCheck(); FileInfo destFileInfo = new FileInfo(destFile); @@ -1200,7 +1200,7 @@ public async Task PageBlobToLocal_Failure_Exists() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); await testEventsRaised.AssertSingleFailedCheck(); FileInfo destFileInfo = new FileInfo(destFile); @@ -1421,7 +1421,7 @@ public async Task StartTransfer_AwaitCompletion() failureTransferHolder.AssertUnexpectedFailureCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); } [RecordedTest] @@ -1452,7 +1452,7 @@ public async Task StartTransfer_AwaitCompletion_Failed() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); await testEventRaised.AssertSingleFailedCheck(); Assert.AreEqual(1, testEventRaised.FailedEvents.Count); @@ -1488,7 +1488,7 @@ public async Task StartTransfer_AwaitCompletion_Skipped() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); await testEventRaised.AssertSingleSkippedCheck(); } @@ -1522,7 +1522,7 @@ public async Task StartTransfer_EnsureCompleted() testEventRaised.AssertUnexpectedFailureCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); } [RecordedTest] @@ -1553,7 +1553,7 @@ public async Task StartTransfer_EnsureCompleted_Failed() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); await testEventsRaised.AssertSingleFailedCheck(); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("Cannot overwrite file.")); @@ -1589,7 +1589,7 @@ public async Task StartTransfer_EnsureCompleted_Skipped() await testEventsRaised.AssertSingleSkippedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); } #endregion diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferSyncCopyDirectoryTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferSyncCopyDirectoryTests.cs index 1d041ab7a31c9..5f57e4b5f2653 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferSyncCopyDirectoryTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferSyncCopyDirectoryTests.cs @@ -79,7 +79,7 @@ private async Task CopyBlobDirectoryAndVerify( await testEventFailed.AssertContainerCompletedCheck(sourceFiles.Count); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); // List all files in source blob folder path List sourceblobNames = new List(); @@ -246,7 +246,7 @@ public async Task BlockBlobDirectoryToDirectory_EmptyFolder() CancellationTokenSource tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30)); await transfer.WaitForCompletionAsync(tokenSource.Token); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); // Assert List blobs = ((List)await test.Container.GetBlobsAsync().ToListAsync()) @@ -587,7 +587,7 @@ public async Task StartTransfer_AwaitCompletion() testEventsRaised.AssertUnexpectedFailureCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); } [Test] @@ -617,7 +617,7 @@ public async Task StartTransfer_AwaitCompletion_Failed() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); await testEventsRaised.AssertContainerCompletedWithFailedCheck(1); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); @@ -651,7 +651,7 @@ public async Task StartTransfer_AwaitCompletion_Skipped() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); await testEventsRaised.AssertContainerCompletedWithSkippedCheck(1); } @@ -677,7 +677,7 @@ public async Task StartTransfer_EnsureCompleted() testEventsRaised.AssertUnexpectedFailureCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); } [Test] @@ -707,7 +707,7 @@ public async Task StartTransfer_EnsureCompleted_Failed() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); await testEventsRaised.AssertContainerCompletedWithFailedCheck(1); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); @@ -742,7 +742,7 @@ public async Task StartTransfer_EnsureCompleted_Skipped() testEventsRaised.AssertUnexpectedFailureCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); } @@ -778,7 +778,7 @@ public async Task StartTransfer_EnsureCompleted_Failed_SmallChunks() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); await testEventsRaised.AssertContainerCompletedWithFailedCheck(1); diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferSyncCopyTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferSyncCopyTests.cs index a8c559bb03e9c..fb287d85fa613 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferSyncCopyTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferSyncCopyTests.cs @@ -166,7 +166,7 @@ private async Task CopyBlockBlobsAndVerify( CancellationTokenSource tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(waitTimeInSec)); await copyBlobInfo[i].DataTransfer.WaitForCompletionAsync(tokenSource.Token); Assert.IsTrue(copyBlobInfo[i].DataTransfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, copyBlobInfo[i].DataTransfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, copyBlobInfo[i].DataTransfer.TransferStatus.State); // Verify Copy - using original source File and Copying the destination await copyBlobInfo[i].testEventsRaised.AssertSingleCompletedCheck(); @@ -386,7 +386,7 @@ public async Task BlockBlobToBlockBlob_Skip_Exists() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); await testEventsRaised.AssertSingleSkippedCheck(); Assert.IsTrue(await destinationClient.ExistsAsync()); @@ -439,7 +439,7 @@ public async Task BlockBlobToBlockBlob_Failure_Exists() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(await destinationClient.ExistsAsync()); await testEventsRaised.AssertSingleFailedCheck(); @@ -529,7 +529,7 @@ public async Task AppendBlobToAppendBlob_Error() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); await testEventsRaised.AssertSingleFailedCheck(); Assert.NotNull(testEventsRaised.FailedEvents.First().Exception, "Excepted failure: Failure was supposed to be raised during the test"); @@ -583,7 +583,7 @@ public async Task PageBlobToPageBlob_Error() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); await testEventsRaised.AssertSingleFailedCheck(); Assert.NotNull(testEventsRaised.FailedEvents.First().Exception, "Excepted failure: Failure was supposed to be raised during the test"); @@ -654,7 +654,7 @@ public async Task StartTransfer_AwaitCompletion() await testEventsRaised.AssertSingleCompletedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); } [RecordedTest] @@ -683,7 +683,7 @@ public async Task StartTransfer_AwaitCompletion_Failed() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); await testEventsRaised.AssertSingleFailedCheck(); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); @@ -717,7 +717,7 @@ public async Task StartTransfer_AwaitCompletion_Skipped() await testEventsRaised.AssertSingleSkippedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); } @@ -741,7 +741,7 @@ public async Task StartTransfer_EnsureCompleted() await testEventsRaised.AssertSingleCompletedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); } [RecordedTest] @@ -771,7 +771,7 @@ public async Task StartTransfer_EnsureCompleted_Failed() await testEventsRaised.AssertSingleFailedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); } @@ -804,7 +804,7 @@ public async Task StartTransfer_EnsureCompleted_Skipped() await testEventsRaised.AssertSingleSkippedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); } #endregion diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferUploadDirectoryTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferUploadDirectoryTests.cs index 70fc4c6d27071..824bfb5d1d02e 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferUploadDirectoryTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferUploadDirectoryTests.cs @@ -72,7 +72,7 @@ private async Task UploadBlobDirectoryAndVerify( await testEventsRaised.AssertContainerCompletedCheck(files.Count); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); // Assert - Check Response List blobs = ((List)await destinationContainer.GetBlobsAsync(prefix: destinationPrefix).ToListAsync()) @@ -735,7 +735,7 @@ public async Task StartTransfer_AwaitCompletion() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); await testEventsRaised.AssertContainerCompletedCheck(4); } @@ -769,7 +769,7 @@ public async Task StartTransfer_AwaitCompletion_Failed() await testEventsRaised.AssertContainerCompletedWithFailedCheck(1); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); } @@ -805,7 +805,7 @@ public async Task StartTransfer_AwaitCompletion_Skipped() await testEventsRaised.AssertContainerCompletedWithSkippedCheck(1); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); } @@ -835,7 +835,7 @@ public async Task StartTransfer_EnsureCompleted() await testEventsRaised.AssertContainerCompletedCheck(4); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); } [Test] @@ -868,7 +868,7 @@ public async Task StartTransfer_EnsureCompleted_Failed() await testEventsRaised.AssertContainerCompletedWithFailedCheck(1); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); } @@ -904,7 +904,7 @@ public async Task StartTransfer_EnsureCompleted_Skipped() await testEventsRaised.AssertContainerCompletedWithSkippedCheck(1); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); } @@ -940,7 +940,7 @@ public async Task StartTransfer_EnsureCompleted_Failed_SmallChunks() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); await testEventsRaised.AssertContainerCompletedWithFailedCheck(1); diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferUploadTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferUploadTests.cs index a8f687f98e73b..abe3e5bc589d3 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferUploadTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferUploadTests.cs @@ -303,7 +303,7 @@ public async Task LocalToBlockBlob_Skip_Exists() await testEventsRaised.AssertSingleSkippedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); Assert.IsTrue(await destinationClient.ExistsAsync()); // Verify Upload - That we skipped over and didn't reupload something new. @@ -351,7 +351,7 @@ public async Task LocalToBlockBlob_Failure_Exists() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(await destinationClient.ExistsAsync()); await testEventRaised.AssertSingleFailedCheck(); @@ -581,7 +581,7 @@ private async Task UploadPageBlobsAndVerify( CancellationTokenSource tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(waitTimeInSec)); await uploadedBlobInfo[i].DataTransfer.WaitForCompletionAsync(tokenSource.Token); Assert.IsTrue(uploadedBlobInfo[i].DataTransfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, uploadedBlobInfo[i].DataTransfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, uploadedBlobInfo[i].DataTransfer.TransferStatus.State); // Verify Upload await uploadedBlobInfo[i].EventsRaised.AssertSingleCompletedCheck(); @@ -695,7 +695,7 @@ public async Task LocalToPageBlob_Skip_Exists() await testEventsRaised.AssertSingleSkippedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); Assert.IsTrue(await destinationClient.ExistsAsync()); // Verify Upload - That we skipped over and didn't reupload something new. @@ -743,7 +743,7 @@ public async Task LocalToPageBlob_Failure_Exists() await testEventsRaised.AssertSingleFailedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(await destinationClient.ExistsAsync()); Assert.NotNull(testEventsRaised.FailedEvents.First().Exception, "Excepted failure: Overwrite failure was supposed to be raised during the test"); @@ -1002,7 +1002,7 @@ private async Task UploadAppendBlobsAndVerify( CancellationTokenSource tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(waitTimeInSec)); await uploadedBlobInfo[i].DataTransfer.WaitForCompletionAsync(tokenSource.Token); Assert.IsTrue(uploadedBlobInfo[i].DataTransfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, uploadedBlobInfo[i].DataTransfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, uploadedBlobInfo[i].DataTransfer.TransferStatus.State); // Verify Upload await uploadedBlobInfo[i].EventsRaised.AssertSingleCompletedCheck(); @@ -1138,7 +1138,7 @@ public async Task LocalToAppendBlob_Skip_Exists() await testEventsRaised.AssertSingleSkippedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); Assert.IsTrue(await destinationClient.ExistsAsync()); // Verify Upload - That we skipped over and didn't reupload something new. @@ -1186,7 +1186,7 @@ public async Task LocalToAppendBlob_Failure_Exists() await testEventsRaised.AssertSingleFailedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(await destinationClient.ExistsAsync()); Assert.NotNull(testEventsRaised.FailedEvents.First().Exception, "Excepted failure: Overwrite failure was supposed to be raised during the test"); @@ -1418,7 +1418,7 @@ public async Task StartTransfer_AwaitCompletion() await testEventsRaised.AssertSingleCompletedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); } [RecordedTest] @@ -1448,7 +1448,7 @@ public async Task StartTransfer_AwaitCompletion_Failed() await testEventsRaised.AssertSingleFailedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); } @@ -1481,7 +1481,7 @@ public async Task StartTransfer_AwaitCompletion_Skipped() await testEventsRaised.AssertSingleSkippedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); } @@ -1505,7 +1505,7 @@ public async Task StartTransfer_EnsureCompleted() await testEventsRaised.AssertSingleCompletedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); } [RecordedTest] @@ -1535,7 +1535,7 @@ public async Task StartTransfer_EnsureCompleted_Failed() await testEventsRaised.AssertSingleFailedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); } @@ -1568,7 +1568,7 @@ public async Task StartTransfer_EnsureCompleted_Skipped() await testEventsRaised.AssertSingleSkippedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); } #endregion diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/TestEventsRaised.cs b/sdk/storage/Azure.Storage.DataMovement/tests/TestEventsRaised.cs index 0665982b94704..b5c5158fd98b0 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/TestEventsRaised.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/TestEventsRaised.cs @@ -106,6 +106,25 @@ private Task AppendSingleTransferCompleted(TransferItemCompletedEventArgs args) return Task.CompletedTask; } + private void AssertTransferStatusCollection(DataTransferStatus[] expected, DataTransferStatus[] actual) + { + Assert.AreEqual(expected.Length, actual.Length); + Assert.Multiple(() => + { + for (int i = 0; i < expected.Length; i++) + { + if (!expected[i].Equals(actual[i])) + { + // Compared to individual Assert statements, this makes it clear when running the test, what's failing. + Assert.Fail($"Transfer State Mismatch:" + + $"Expected {nameof(DataTransferStatus.State)}: {expected[i].State}; Actual {nameof(DataTransferStatus.State)}: {actual[i].State}\n" + + $"Expected {nameof(DataTransferStatus.HasFailedItems)}: {expected[i].HasFailedItems}; Actual {nameof(DataTransferStatus.HasFailedItems)}: {actual[i].HasFailedItems}\n" + + $"Expected {nameof(DataTransferStatus.HasSkippedItems)}: {expected[i].HasSkippedItems}; Actual {nameof(DataTransferStatus.HasSkippedItems)}: {actual[i].HasSkippedItems}\n"); + } + } + }); + } + public void AssertUnexpectedFailureCheck() { Assert.Multiple(() => @@ -134,11 +153,11 @@ public async Task AssertSingleCompletedCheck() Assert.IsEmpty(SingleCompletedEvents); await WaitForStatusEventsAsync().ConfigureAwait(false); - CollectionAssert.AreEqual( + AssertTransferStatusCollection( new DataTransferStatus[] { InProgressStatus, SuccessfulCompletedStatus }, - StatusEvents.Select(e => e.TransferStatus)); + StatusEvents.Select(e => e.TransferStatus).ToArray()); } /// @@ -155,11 +174,11 @@ public async Task AssertSingleSkippedCheck() Assert.NotNull(SkippedEvents.First().DestinationResource.Uri); await WaitForStatusEventsAsync().ConfigureAwait(false); - CollectionAssert.AreEqual( + AssertTransferStatusCollection( new DataTransferStatus[] { InProgressStatus, SkippedCompletedStatus }, - StatusEvents.Select(e => e.TransferStatus)); + StatusEvents.Select(e => e.TransferStatus).ToArray()); } /// @@ -176,13 +195,12 @@ public async Task AssertSingleFailedCheck() Assert.NotNull(FailedEvents.First().DestinationResource.Uri); await WaitForStatusEventsAsync().ConfigureAwait(false); - CollectionAssert.AreEqual( + AssertTransferStatusCollection( new DataTransferStatus[] { InProgressStatus, - InProgressFailedStatus, StoppingFailedStatus, FailedCompletedStatus }, - StatusEvents.Select(e => e.TransferStatus)); + StatusEvents.Select(e => e.TransferStatus).ToArray()); } /// @@ -200,11 +218,11 @@ public async Task AssertContainerCompletedCheck(int transferCount) Assert.AreEqual(transferCount, SingleCompletedEvents.Count); await WaitForStatusEventsAsync().ConfigureAwait(false); - CollectionAssert.AreEqual( + AssertTransferStatusCollection( new DataTransferStatus[] { InProgressStatus, SuccessfulCompletedStatus }, - StatusEvents.Select(e => e.TransferStatus)); + StatusEvents.Select(e => e.TransferStatus).ToArray()); } /// @@ -230,13 +248,13 @@ public async Task AssertContainerCompletedWithFailedCheck(int expectedFailureCou Assert.IsEmpty(SkippedEvents); await WaitForStatusEventsAsync().ConfigureAwait(false); - CollectionAssert.AreEqual( + AssertTransferStatusCollection( new DataTransferStatus[] { InProgressStatus, InProgressFailedStatus, StoppingFailedStatus, FailedCompletedStatus }, - StatusEvents.Select(e => e.TransferStatus)); + StatusEvents.Select(e => e.TransferStatus).ToArray()); } /// @@ -262,13 +280,13 @@ public async Task AssertContainerCompletedWithFailedCheckContinue(int expectedFa Assert.IsEmpty(SkippedEvents); await WaitForStatusEventsAsync().ConfigureAwait(false); - CollectionAssert.AreEqual( + AssertTransferStatusCollection( new DataTransferStatus[] { InProgressStatus, InProgressFailedStatus, StoppingFailedStatus, FailedCompletedStatus }, - StatusEvents.Select(e => e.TransferStatus)); + StatusEvents.Select(e => e.TransferStatus).ToArray()); } /// @@ -284,12 +302,12 @@ public async Task AssertContainerCompletedWithSkippedCheck(int expectedSkipCount Assert.AreEqual(expectedSkipCount, SkippedEvents.Count); await WaitForStatusEventsAsync().ConfigureAwait(false); - CollectionAssert.AreEqual( + AssertTransferStatusCollection( new DataTransferStatus[] { InProgressStatus, InProgressSkippedStatus, SkippedCompletedStatus }, - StatusEvents.Select(e => e.TransferStatus)); + StatusEvents.Select(e => e.TransferStatus).ToArray()); } public async Task AssertPausedCheck() @@ -298,12 +316,11 @@ public async Task AssertPausedCheck() Assert.IsEmpty(SkippedEvents); await WaitForStatusEventsAsync().ConfigureAwait(false); - CollectionAssert.AreEqual( + AssertTransferStatusCollection( new DataTransferStatus[] { InProgressStatus, - new DataTransferStatus(DataTransferStatus.TransferState.Pausing, false, false), new DataTransferStatus(DataTransferStatus.TransferState.Paused, false, false) }, - StatusEvents.Select(e => e.TransferStatus)); + StatusEvents.Select(e => e.TransferStatus).ToArray()); } /// From 6a56b4816ad019802e12b8ac4973f5e58e132587 Mon Sep 17 00:00:00 2001 From: Amanda Nguyen Date: Fri, 25 Aug 2023 15:51:26 -0700 Subject: [PATCH 07/13] Cleanup --- .../samples/Sample01b_HelloWorldAsync.cs | 2 +- .../tests/Azure.Storage.DataMovement.Tests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/storage/Azure.Storage.DataMovement.Blobs/samples/Sample01b_HelloWorldAsync.cs b/sdk/storage/Azure.Storage.DataMovement.Blobs/samples/Sample01b_HelloWorldAsync.cs index fed61241a858c..d8cfebf9be7ca 100644 --- a/sdk/storage/Azure.Storage.DataMovement.Blobs/samples/Sample01b_HelloWorldAsync.cs +++ b/sdk/storage/Azure.Storage.DataMovement.Blobs/samples/Sample01b_HelloWorldAsync.cs @@ -659,7 +659,7 @@ public async Task CopySingle_ConnectionStringAsync() #endregion Assert.IsTrue(await destinationAppendBlobClient.ExistsAsync()); - Assert.AreEqual(dataTransfer.TransferStatus, DataTransferStatus.TransferState.Completed); + Assert.AreEqual(DataTransferStatus.TransferState.Completed, dataTransfer.TransferStatus.State); } finally { diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/Azure.Storage.DataMovement.Tests.csproj b/sdk/storage/Azure.Storage.DataMovement/tests/Azure.Storage.DataMovement.Tests.csproj index 23440a6a3e5b8..e0c1ac7910010 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/Azure.Storage.DataMovement.Tests.csproj +++ b/sdk/storage/Azure.Storage.DataMovement/tests/Azure.Storage.DataMovement.Tests.csproj @@ -1,6 +1,6 @@  - $(RequiredTargetFrameworks);net6.0 + $(RequiredTargetFrameworks) Microsoft Azure.Storage.DataMovement client library tests BlobDataMovementSDK;$(DefineConstants) false From 42276f3bbd63e59328d9310c186c087d716512d1 Mon Sep 17 00:00:00 2001 From: Amanda Nguyen Date: Fri, 25 Aug 2023 16:21:17 -0700 Subject: [PATCH 08/13] ExportApi --- .../api/Azure.Storage.DataMovement.net6.0.cs | 32 ++++++++++++------- ...ure.Storage.DataMovement.netstandard2.0.cs | 32 ++++++++++++------- 2 files changed, 40 insertions(+), 24 deletions(-) diff --git a/sdk/storage/Azure.Storage.DataMovement/api/Azure.Storage.DataMovement.net6.0.cs b/sdk/storage/Azure.Storage.DataMovement/api/Azure.Storage.DataMovement.net6.0.cs index f6d72aa6441a4..9d1c9471ee69c 100644 --- a/sdk/storage/Azure.Storage.DataMovement/api/Azure.Storage.DataMovement.net6.0.cs +++ b/sdk/storage/Azure.Storage.DataMovement/api/Azure.Storage.DataMovement.net6.0.cs @@ -70,17 +70,25 @@ protected internal DataTransferProperties() { } public virtual string SourceTypeId { get { throw null; } } public virtual string TransferId { get { throw null; } } } - public enum DataTransferStatus - { - None = 0, - Queued = 1, - InProgress = 2, - Paused = 3, - Completed = 4, - CompletedWithSkippedTransfers = 5, - CompletedWithFailedTransfers = 6, - PauseInProgress = 7, - CancellationInProgress = 8, + public partial class DataTransferStatus : System.IEquatable + { + protected internal DataTransferStatus() { } + protected internal DataTransferStatus(Azure.Storage.DataMovement.DataTransferStatus.TransferState state, bool hasFailureItems, bool hasSkippedItems) { } + public bool HasCompletedSuccessfully { get { throw null; } } + public bool HasFailedItems { get { throw null; } } + public bool HasSkippedItems { get { throw null; } } + public Azure.Storage.DataMovement.DataTransferStatus.TransferState State { get { throw null; } } + public bool Equals(Azure.Storage.DataMovement.DataTransferStatus other) { throw null; } + public enum TransferState + { + None = 0, + Queued = 1, + InProgress = 2, + Pausing = 3, + Stopping = 4, + Paused = 5, + Completed = 6, + } } public partial class LocalDirectoryStorageResourceContainer : Azure.Storage.DataMovement.StorageResourceContainer { @@ -237,6 +245,6 @@ public TransferManagerOptions() { } public partial class TransferStatusEventArgs : Azure.Storage.DataMovement.DataTransferEventArgs { public TransferStatusEventArgs(string transferId, Azure.Storage.DataMovement.DataTransferStatus transferStatus, bool isRunningSynchronously, System.Threading.CancellationToken cancellationToken) : base (default(string), default(bool), default(System.Threading.CancellationToken)) { } - public Azure.Storage.DataMovement.DataTransferStatus StorageTransferStatus { get { throw null; } } + public Azure.Storage.DataMovement.DataTransferStatus TransferStatus { get { throw null; } } } } diff --git a/sdk/storage/Azure.Storage.DataMovement/api/Azure.Storage.DataMovement.netstandard2.0.cs b/sdk/storage/Azure.Storage.DataMovement/api/Azure.Storage.DataMovement.netstandard2.0.cs index f6d72aa6441a4..9d1c9471ee69c 100644 --- a/sdk/storage/Azure.Storage.DataMovement/api/Azure.Storage.DataMovement.netstandard2.0.cs +++ b/sdk/storage/Azure.Storage.DataMovement/api/Azure.Storage.DataMovement.netstandard2.0.cs @@ -70,17 +70,25 @@ protected internal DataTransferProperties() { } public virtual string SourceTypeId { get { throw null; } } public virtual string TransferId { get { throw null; } } } - public enum DataTransferStatus - { - None = 0, - Queued = 1, - InProgress = 2, - Paused = 3, - Completed = 4, - CompletedWithSkippedTransfers = 5, - CompletedWithFailedTransfers = 6, - PauseInProgress = 7, - CancellationInProgress = 8, + public partial class DataTransferStatus : System.IEquatable + { + protected internal DataTransferStatus() { } + protected internal DataTransferStatus(Azure.Storage.DataMovement.DataTransferStatus.TransferState state, bool hasFailureItems, bool hasSkippedItems) { } + public bool HasCompletedSuccessfully { get { throw null; } } + public bool HasFailedItems { get { throw null; } } + public bool HasSkippedItems { get { throw null; } } + public Azure.Storage.DataMovement.DataTransferStatus.TransferState State { get { throw null; } } + public bool Equals(Azure.Storage.DataMovement.DataTransferStatus other) { throw null; } + public enum TransferState + { + None = 0, + Queued = 1, + InProgress = 2, + Pausing = 3, + Stopping = 4, + Paused = 5, + Completed = 6, + } } public partial class LocalDirectoryStorageResourceContainer : Azure.Storage.DataMovement.StorageResourceContainer { @@ -237,6 +245,6 @@ public TransferManagerOptions() { } public partial class TransferStatusEventArgs : Azure.Storage.DataMovement.DataTransferEventArgs { public TransferStatusEventArgs(string transferId, Azure.Storage.DataMovement.DataTransferStatus transferStatus, bool isRunningSynchronously, System.Threading.CancellationToken cancellationToken) : base (default(string), default(bool), default(System.Threading.CancellationToken)) { } - public Azure.Storage.DataMovement.DataTransferStatus StorageTransferStatus { get { throw null; } } + public Azure.Storage.DataMovement.DataTransferStatus TransferStatus { get { throw null; } } } } From 2325ddb964fb7ba1647f9b4eb1a379fff9abe646 Mon Sep 17 00:00:00 2001 From: Amanda Nguyen Date: Tue, 29 Aug 2023 10:15:09 -0700 Subject: [PATCH 09/13] WIP --- .../Azure.Storage.DataMovement/tests/TestEventsRaised.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/TestEventsRaised.cs b/sdk/storage/Azure.Storage.DataMovement/tests/TestEventsRaised.cs index b5c5158fd98b0..9510ad8b8d862 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/TestEventsRaised.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/TestEventsRaised.cs @@ -251,7 +251,6 @@ public async Task AssertContainerCompletedWithFailedCheck(int expectedFailureCou AssertTransferStatusCollection( new DataTransferStatus[] { InProgressStatus, - InProgressFailedStatus, StoppingFailedStatus, FailedCompletedStatus }, StatusEvents.Select(e => e.TransferStatus).ToArray()); @@ -284,7 +283,6 @@ public async Task AssertContainerCompletedWithFailedCheckContinue(int expectedFa new DataTransferStatus[] { InProgressStatus, InProgressFailedStatus, - StoppingFailedStatus, FailedCompletedStatus }, StatusEvents.Select(e => e.TransferStatus).ToArray()); } From 407a88f45d5c7bebd1becb413199467325e1af52 Mon Sep 17 00:00:00 2001 From: Amanda Nguyen Date: Tue, 5 Sep 2023 22:50:12 -0700 Subject: [PATCH 10/13] Fixes to live tests --- sdk/storage/Azure.Storage.DataMovement/src/JobPartInternal.cs | 1 - .../Azure.Storage.DataMovement/src/TransferJobInternal.cs | 3 ++- .../tests/StartTransferUploadDirectoryTests.cs | 2 +- .../Azure.Storage.DataMovement/tests/TestEventsRaised.cs | 3 +++ 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/sdk/storage/Azure.Storage.DataMovement/src/JobPartInternal.cs b/sdk/storage/Azure.Storage.DataMovement/src/JobPartInternal.cs index dea671affdd28..38454f90ae666 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/JobPartInternal.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/JobPartInternal.cs @@ -587,7 +587,6 @@ internal async Task CheckAndUpdateCancellationStateAsync() } else if (JobPartStatus.State == DataTransferStatus.TransferState.Stopping) { - _progressTracker.IncrementFailedFiles(); await OnTransferStateChangedAsync(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); } } diff --git a/sdk/storage/Azure.Storage.DataMovement/src/TransferJobInternal.cs b/sdk/storage/Azure.Storage.DataMovement/src/TransferJobInternal.cs index d44318a449513..3c3a29f05ca97 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/TransferJobInternal.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/TransferJobInternal.cs @@ -297,7 +297,6 @@ await TransferFailedEventHandler.RaiseAsync( ClientDiagnostics) .ConfigureAwait(false); } - _dataTransfer._state.TryOnFailedItemsState(); } await TriggerJobCancellationAsync().ConfigureAwait(false); @@ -327,6 +326,7 @@ public async Task JobPartEvent(TransferStatusEventArgs args) if (_dataTransfer._state.TryOnFailedItemsState()) { await SetCheckpointerStatus().ConfigureAwait(false); + await OnJobPartStatusChangedAsync().ConfigureAwait(false); } } else if (jobPartStatus.HasSkippedItems) @@ -334,6 +334,7 @@ public async Task JobPartEvent(TransferStatusEventArgs args) if (_dataTransfer._state.TryOnSkippedItemsState()) { await SetCheckpointerStatus().ConfigureAwait(false); + await OnJobPartStatusChangedAsync().ConfigureAwait(false); } } diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferUploadDirectoryTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferUploadDirectoryTests.cs index f59b74fdcabcc..892e6d81d8760 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferUploadDirectoryTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferUploadDirectoryTests.cs @@ -942,7 +942,7 @@ public async Task StartTransfer_EnsureCompleted_Failed_SmallChunks() Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); - Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); + Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); await testEventsRaised.AssertContainerCompletedWithFailedCheck(1); } diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/TestEventsRaised.cs b/sdk/storage/Azure.Storage.DataMovement/tests/TestEventsRaised.cs index 9510ad8b8d862..796c910d2fdc5 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/TestEventsRaised.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/TestEventsRaised.cs @@ -177,6 +177,7 @@ public async Task AssertSingleSkippedCheck() AssertTransferStatusCollection( new DataTransferStatus[] { InProgressStatus, + InProgressSkippedStatus, SkippedCompletedStatus }, StatusEvents.Select(e => e.TransferStatus).ToArray()); } @@ -198,6 +199,7 @@ public async Task AssertSingleFailedCheck() AssertTransferStatusCollection( new DataTransferStatus[] { InProgressStatus, + InProgressFailedStatus, StoppingFailedStatus, FailedCompletedStatus }, StatusEvents.Select(e => e.TransferStatus).ToArray()); @@ -251,6 +253,7 @@ public async Task AssertContainerCompletedWithFailedCheck(int expectedFailureCou AssertTransferStatusCollection( new DataTransferStatus[] { InProgressStatus, + InProgressFailedStatus, StoppingFailedStatus, FailedCompletedStatus }, StatusEvents.Select(e => e.TransferStatus).ToArray()); From b2c92cc76f9ce294e063e56b95a430454c9621b8 Mon Sep 17 00:00:00 2001 From: Amanda Nguyen Date: Wed, 6 Sep 2023 13:57:33 -0700 Subject: [PATCH 11/13] PR Comments - part 1 --- .../samples/Sample01b_HelloWorldAsync.cs | 2 +- .../src/CheckpointerExtensions.cs | 4 +- .../src/DataTransferState.cs | 57 ++++++++++++ .../src/DataTransferStatus.cs | 92 ++++--------------- .../src/JobPartInternal.cs | 78 ++++++++-------- .../src/ServiceToServiceJobPart.cs | 6 +- .../src/ServiceToServiceTransferJob.cs | 4 +- .../src/Shared/DataTransferInternalState.cs | 20 ++-- .../src/Shared/DataTransferStatusInternal.cs | 2 +- .../src/Shared/JobPlan/JobPartPlanHeader.cs | 4 +- .../src/Shared/TransferCheckpointer.cs | 4 +- .../src/Shared/TransferManager.cs | 2 +- .../src/StreamToUriJobPart.cs | 6 +- .../src/StreamToUriTransferJob.cs | 4 +- .../src/TransferJobInternal.cs | 60 ++++++------ .../src/UriToStreamJobPart.cs | 4 +- .../src/UriToStreamTransferJob.cs | 4 +- .../tests/DataTransferTests.cs | 52 +++++------ .../tests/GetTransfersTests.cs | 28 +++--- .../tests/LocalTransferCheckpointerFactory.cs | 4 +- .../tests/LocalTransferCheckpointerTests.cs | 2 +- .../tests/PauseResumeTransferTests.cs | 36 ++++---- .../tests/ProgressHandlerTests.cs | 4 +- .../tests/Shared/CheckpointerTesting.cs | 4 +- .../StartTransferDownloadDirectoryTests.cs | 18 ++-- .../tests/StartTransferDownloadTests.cs | 26 +++--- .../StartTransferSyncCopyDirectoryTests.cs | 18 ++-- .../tests/StartTransferSyncCopyTests.cs | 22 ++--- .../StartTransferUploadDirectoryTests.cs | 16 ++-- .../tests/StartTransferUploadTests.cs | 30 +++--- .../tests/TestEventsRaised.cs | 30 +++--- 31 files changed, 321 insertions(+), 322 deletions(-) create mode 100644 sdk/storage/Azure.Storage.DataMovement/src/DataTransferState.cs diff --git a/sdk/storage/Azure.Storage.DataMovement.Blobs/samples/Sample01b_HelloWorldAsync.cs b/sdk/storage/Azure.Storage.DataMovement.Blobs/samples/Sample01b_HelloWorldAsync.cs index d8cfebf9be7ca..d0d59f80e6f5a 100644 --- a/sdk/storage/Azure.Storage.DataMovement.Blobs/samples/Sample01b_HelloWorldAsync.cs +++ b/sdk/storage/Azure.Storage.DataMovement.Blobs/samples/Sample01b_HelloWorldAsync.cs @@ -659,7 +659,7 @@ public async Task CopySingle_ConnectionStringAsync() #endregion Assert.IsTrue(await destinationAppendBlobClient.ExistsAsync()); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, dataTransfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, dataTransfer.TransferStatus.State); } finally { diff --git a/sdk/storage/Azure.Storage.DataMovement/src/CheckpointerExtensions.cs b/sdk/storage/Azure.Storage.DataMovement/src/CheckpointerExtensions.cs index 4633d6df5170f..75ebf0a1c6581 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/CheckpointerExtensions.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/CheckpointerExtensions.cs @@ -14,7 +14,7 @@ internal static async Task IsResumableAsync( string transferId, CancellationToken cancellationToken) { - DataTransferStatus.TransferState transferState = (DataTransferStatus.TransferState) await checkpointer.GetByteValue( + DataTransferState transferState = (DataTransferState) await checkpointer.GetByteValue( transferId, DataMovementConstants.JobPartPlanFile.AtomicJobStatusStateIndex, cancellationToken).ConfigureAwait(false); @@ -32,7 +32,7 @@ internal static async Task IsResumableAsync( bool hasSkippedItems = Convert.ToBoolean(hasSkippedItemsByte); // Transfers marked as fully completed are not resumable - return transferState != DataTransferStatus.TransferState.Completed || hasFailedItems || hasSkippedItems; + return transferState != DataTransferState.Completed || hasFailedItems || hasSkippedItems; } internal static async Task GetDataTransferPropertiesAsync( diff --git a/sdk/storage/Azure.Storage.DataMovement/src/DataTransferState.cs b/sdk/storage/Azure.Storage.DataMovement/src/DataTransferState.cs new file mode 100644 index 0000000000000..1624dbf093ff3 --- /dev/null +++ b/sdk/storage/Azure.Storage.DataMovement/src/DataTransferState.cs @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Threading; + +namespace Azure.Storage.DataMovement +{ + /// + /// Defines the types of the state a transfer can have. + /// + public enum DataTransferState + { + /// + /// Default value. + /// + None = 0, + + /// + /// The transfer has been queued up but has not yet started. + /// + Queued = 1, + + /// + /// The transfer has started, but has not yet completed. + /// + InProgress = 2, + + /// + /// The transfer has started and is in the process of being paused. + /// + /// Transfer can be stopped if + /// or is called. + /// + Pausing = 3, + + /// + /// The transfer has started and is in the process of being stopped. + /// + /// Transfer can be stopped if is + /// enabled in the . + /// + Stopping = 4, + + /// + /// The transfer has been paused. When transfer is paused + /// (e.g. see ) + /// during the transfer, this will be the value. + /// + Paused = 5, + + /// + /// The transfer has come to a completed state. If the transfer has started and + /// has fully stopped will also come to this state. + /// + Completed = 6 + } +} diff --git a/sdk/storage/Azure.Storage.DataMovement/src/DataTransferStatus.cs b/sdk/storage/Azure.Storage.DataMovement/src/DataTransferStatus.cs index 4d57e84fcb2eb..e5805dde041f8 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/DataTransferStatus.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/DataTransferStatus.cs @@ -13,69 +13,17 @@ namespace Azure.Storage.DataMovement public class DataTransferStatus : IEquatable { private object _stateLock = new object(); - private object _hasSkippedLock = new object(); - private object _hasFailedLock = new object(); - - /// - /// Defines the types of the state a transfer can have. - /// - public enum TransferState - { - /// - /// Default value. - /// - None = 0, - - /// - /// The transfer has been queued up but has not yet started. - /// - Queued = 1, - - /// - /// The transfer has started, but has not yet completed. - /// - InProgress = 2, - - /// - /// The transfer has started and is in the process of being paused. - /// - /// Transfer can be stopped if - /// or is called. - /// - Pausing = 3, - - /// - /// The transfer has started and is in the process of being stopped. - /// - /// Transfer can be stopped if is - /// enabled in the . - /// - Stopping = 4, - - /// - /// The transfer has been paused. When transfer is paused - /// (e.g. see ) - /// during the transfer, this will be the value. - /// - Paused = 5, - - /// - /// The transfer has come to a completed state. If the transfer has started and - /// has fully stopped will also come to this state. - /// - Completed = 6 - } /// /// Defines the state of the transfer. /// - public TransferState State { get; internal set; } + public DataTransferState State { get; internal set; } /// /// Represents if the transfer has completed successfully without any failure or skipped items. /// public bool HasCompletedSuccessfully => - (State == TransferState.Completed) && + (State == DataTransferState.Completed) && !HasFailedItems && !HasSkippedItems; @@ -99,11 +47,11 @@ public enum TransferState public bool HasSkippedItems { get; internal set; } /// - /// Constructor to set the initial state to with no failures or skipped items. + /// Constructor to set the initial state to with no failures or skipped items. /// protected internal DataTransferStatus() { - State = TransferState.Queued; + State = DataTransferState.Queued; HasFailedItems = false; HasSkippedItems = false; } @@ -111,15 +59,15 @@ protected internal DataTransferStatus() /// /// Constructor to have a custom state, failure state, and skipped state. /// - protected internal DataTransferStatus(TransferState state, bool hasFailureItems, bool hasSkippedItems) + protected internal DataTransferStatus(DataTransferState state, bool hasFailureItems, bool hasSkippedItems) { State = state; HasFailedItems = hasFailureItems; HasSkippedItems = hasSkippedItems; } - internal bool IsCompletedWithFailedItems => State.Equals(TransferState.Completed) && HasFailedItems; - internal bool IsCompletedWithSkippedItems => State.Equals(TransferState.Completed) && HasSkippedItems; + internal bool IsCompletedWithFailedItems => State.Equals(DataTransferState.Completed) && HasFailedItems; + internal bool IsCompletedWithSkippedItems => State.Equals(DataTransferState.Completed) && HasSkippedItems; /// /// Accordingly update the to true. If already set to true, nothing will happen. @@ -127,15 +75,12 @@ protected internal DataTransferStatus(TransferState state, bool hasFailureItems, /// This should only be triggered when a failed item has been seen. /// /// True if was updated. False otherwise. - internal bool OnFailedItem() + internal bool TrySetFailedItem() { - lock (_hasFailedLock) + if (!HasFailedItems) { - if (!HasFailedItems) - { - HasFailedItems = true; - return true; - } + HasFailedItems = true; + return true; } return false; } @@ -146,15 +91,12 @@ internal bool OnFailedItem() /// This should only be triggered when a skipped item has been seen. /// /// /// True if was updated. False otherwise. - internal bool OnSkippedItem() + internal bool TrySetSkippedItem() { - lock (_hasSkippedLock) + if (!HasSkippedItems) { - if (!HasSkippedItems) - { - HasSkippedItems = true; - return true; - } + HasSkippedItems = true; + return true; } return false; } @@ -166,11 +108,11 @@ internal bool OnSkippedItem() /// This should only be triggered when the state updates. /// /// True if was updated. False otherwise. - internal bool OnTransferStateChange(TransferState state) + internal bool TrySetTransferStateChange(DataTransferState state) { lock (_stateLock) { - if (state != TransferState.None && + if (state != DataTransferState.None && State != state) { State = state; diff --git a/sdk/storage/Azure.Storage.DataMovement/src/JobPartInternal.cs b/sdk/storage/Azure.Storage.DataMovement/src/JobPartInternal.cs index 38454f90ae666..a3714e8e55e50 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/JobPartInternal.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/JobPartInternal.cs @@ -174,7 +174,7 @@ internal JobPartInternal( Argument.AssertNotNull(clientDiagnostics, nameof(clientDiagnostics)); // if defualt is passed, the job part status will be queued - JobPartStatus = jobPartStatus != default ? jobPartStatus : new DataTransferStatus(); + JobPartStatus = jobPartStatus ?? new DataTransferStatus(); PartNumber = partNumber; _dataTransfer = dataTransfer; _sourceResource = sourceResource; @@ -259,29 +259,29 @@ await QueueChunk( /// /// Triggers the cancellation for the Job Part. /// - /// If the status is set to - /// and any chunks is still processing to be cancelled is will be set to - /// until the chunks finish then it will be set to . + /// If the status is set to + /// and any chunks is still processing to be cancelled is will be set to + /// until the chunks finish then it will be set to . /// - /// If the part status is set to but has + /// If the part status is set to but has /// - /// and any chunks is still processing to be cancelled is will be set to - /// until the chunks finish then it will be set to . + /// and any chunks is still processing to be cancelled is will be set to + /// until the chunks finish then it will be set to . /// /// The task to wait until the cancellation has been triggered. internal async Task TriggerCancellationAsync() { // Set the status to Pause/CancellationInProgress - if (DataTransferStatus.TransferState.Pausing == _dataTransfer.TransferStatus.State) + if (DataTransferState.Pausing == _dataTransfer.TransferStatus.State) { // It's possible that the status hasn't propagated down to the job part // status yet here since we pause from the data transfer object. - await OnTransferStateChangedAsync(DataTransferStatus.TransferState.Pausing).ConfigureAwait(false); + await OnTransferStateChangedAsync(DataTransferState.Pausing).ConfigureAwait(false); } else { // It's a cancellation if a pause wasn't called. - await OnTransferStateChangedAsync(DataTransferStatus.TransferState.Stopping).ConfigureAwait(false); + await OnTransferStateChangedAsync(DataTransferState.Stopping).ConfigureAwait(false); } await CleanupAbortedJobPartAsync().ConfigureAwait(false); } @@ -290,12 +290,12 @@ internal async Task TriggerCancellationAsync() /// To change all transfer statues at the same time /// /// - internal async Task OnTransferStateChangedAsync(DataTransferStatus.TransferState transferState) + internal async Task OnTransferStateChangedAsync(DataTransferState transferState) { - if (JobPartStatus.OnTransferStateChange(transferState)) + if (JobPartStatus.TrySetTransferStateChange(transferState)) { // Progress tracking, do before invoking the event below - if (transferState == DataTransferStatus.TransferState.InProgress) + if (transferState == DataTransferState.InProgress) { _progressTracker.IncrementInProgressFiles(); } @@ -373,21 +373,21 @@ await TransferSkippedEventHandler.RaiseAsync( // Update the JobPartStatus. If was already updated (e.g. there was a failed item before) // then don't raise the PartTransferStatusEventHandler - if (JobPartStatus.OnSkippedItem()) + if (JobPartStatus.TrySetSkippedItem()) { await PartTransferStatusEventHandler.RaiseAsync( - new TransferStatusEventArgs( - _dataTransfer.Id, - JobPartStatus, - false, - _cancellationToken), - nameof(JobPartInternal), - nameof(PartTransferStatusEventHandler), - ClientDiagnostics) - .ConfigureAwait(false); + new TransferStatusEventArgs( + _dataTransfer.Id, + JobPartStatus, + false, + _cancellationToken), + nameof(JobPartInternal), + nameof(PartTransferStatusEventHandler), + ClientDiagnostics) + .ConfigureAwait(false); } //TODO: figure out why we set the Completed state here and not just wait for all the chunks to finish - await OnTransferStateChangedAsync(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); + await OnTransferStateChangedAsync(DataTransferState.Completed).ConfigureAwait(false); } /// @@ -419,18 +419,18 @@ await TransferFailedEventHandler.RaiseAsync( // Update the JobPartStatus. If was already updated (e.g. there was a failed item before) // then don't raise the PartTransferStatusEventHandler - if (JobPartStatus.OnFailedItem()) + if (JobPartStatus.TrySetFailedItem()) { await PartTransferStatusEventHandler.RaiseAsync( - new TransferStatusEventArgs( - _dataTransfer.Id, - JobPartStatus, - false, - _cancellationToken), - nameof(JobPartInternal), - nameof(PartTransferStatusEventHandler), - ClientDiagnostics) - .ConfigureAwait(false); + new TransferStatusEventArgs( + _dataTransfer.Id, + JobPartStatus, + false, + _cancellationToken), + nameof(JobPartInternal), + nameof(PartTransferStatusEventHandler), + ClientDiagnostics) + .ConfigureAwait(false); } } // Trigger job cancellation if the failed handler is enabled @@ -485,7 +485,7 @@ internal async virtual Task SetCheckpointerStatus() await _checkpointer.SetJobPartTransferStatusAsync( transferId: _dataTransfer.Id, partNumber: PartNumber, - state: JobPartStatus).ConfigureAwait(false); + status: JobPartStatus).ConfigureAwait(false); } internal long CalculateBlockSize(long length) @@ -581,13 +581,13 @@ internal async Task CheckAndUpdateCancellationStateAsync() { if (_chunkTasks.All((Task task) => (task.IsCompleted))) { - if (JobPartStatus.State == DataTransferStatus.TransferState.Pausing) + if (JobPartStatus.State == DataTransferState.Pausing) { - await OnTransferStateChangedAsync(DataTransferStatus.TransferState.Paused).ConfigureAwait(false); + await OnTransferStateChangedAsync(DataTransferState.Paused).ConfigureAwait(false); } - else if (JobPartStatus.State == DataTransferStatus.TransferState.Stopping) + else if (JobPartStatus.State == DataTransferState.Stopping) { - await OnTransferStateChangedAsync(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); + await OnTransferStateChangedAsync(DataTransferState.Completed).ConfigureAwait(false); } } } diff --git a/sdk/storage/Azure.Storage.DataMovement/src/ServiceToServiceJobPart.cs b/sdk/storage/Azure.Storage.DataMovement/src/ServiceToServiceJobPart.cs index b61cf2a029cf6..f0fce0e2c19fa 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/ServiceToServiceJobPart.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/ServiceToServiceJobPart.cs @@ -128,7 +128,7 @@ public static async Task CreateJobPartAsync( public override async Task ProcessPartToChunkAsync() { - await OnTransferStateChangedAsync(DataTransferStatus.TransferState.InProgress).ConfigureAwait(false); + await OnTransferStateChangedAsync(DataTransferState.InProgress).ConfigureAwait(false); // Attempt to get the length, it's possible the file could // not be accessible (or does not exist). @@ -211,7 +211,7 @@ await _destinationResource.CopyFromUriAsync( cancellationToken: _cancellationToken).ConfigureAwait(false); ReportBytesWritten(completeLength); - await OnTransferStateChangedAsync(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); + await OnTransferStateChangedAsync(DataTransferState.Completed).ConfigureAwait(false); } catch (RequestFailedException exception) when (_createMode == StorageResourceCreationPreference.SkipIfExists @@ -307,7 +307,7 @@ await _destinationResource.CompleteTransferAsync( await DisposeHandlers().ConfigureAwait(false); // Set completion status to completed - await OnTransferStateChangedAsync(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); + await OnTransferStateChangedAsync(DataTransferState.Completed).ConfigureAwait(false); } catch (Exception ex) { diff --git a/sdk/storage/Azure.Storage.DataMovement/src/ServiceToServiceTransferJob.cs b/sdk/storage/Azure.Storage.DataMovement/src/ServiceToServiceTransferJob.cs index 94dedfcc10094..ee6217f4b7e7f 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/ServiceToServiceTransferJob.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/ServiceToServiceTransferJob.cs @@ -69,7 +69,7 @@ internal ServiceToServiceTransferJob( /// An IEnumerable that contains the job parts public override async IAsyncEnumerable ProcessJobToJobPartAsync() { - await OnJobStateChangedAsync(DataTransferStatus.TransferState.InProgress).ConfigureAwait(false); + await OnJobStateChangedAsync(DataTransferState.InProgress).ConfigureAwait(false); int partNumber = 0; if (_jobParts.Count == 0) @@ -110,7 +110,7 @@ public override async IAsyncEnumerable ProcessJobToJobPartAsync { if (!part.JobPartStatus.HasCompletedSuccessfully) { - part.JobPartStatus.OnTransferStateChange(DataTransferStatus.TransferState.Queued); + part.JobPartStatus.TrySetTransferStateChange(DataTransferState.Queued); yield return part; if (part.IsFinalPart) diff --git a/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransferInternalState.cs b/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransferInternalState.cs index eb375f7a7a9e8..2cdc83a106ad8 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransferInternalState.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransferInternalState.cs @@ -37,7 +37,7 @@ public DataTransferInternalState( CompletionSource = new TaskCompletionSource( _status, TaskCreationOptions.RunContinuationsAsynchronously); - if (DataTransferStatus.TransferState.Completed == status.State) + if (DataTransferState.Completed == status.State) { CompletionSource.TrySetResult(status); } @@ -59,7 +59,7 @@ internal set { } public bool HasCompleted { get { - return DataTransferStatus.TransferState.Completed == _status.State; + return DataTransferState.Completed == _status.State; } internal set { } } @@ -87,12 +87,12 @@ public DataTransferStatus GetTransferStatus() /// /// /// Returns whether or not the status has been changed/set - public bool TrySetTransferState(DataTransferStatus.TransferState state) + public bool TrySetTransferState(DataTransferState state) { - if (_status.OnTransferStateChange(state)) + if (_status.TrySetTransferStateChange(state)) { - if (DataTransferStatus.TransferState.Completed == _status.State || - DataTransferStatus.TransferState.Paused == _status.State) + if (DataTransferState.Completed == _status.State || + DataTransferState.Paused == _status.State) { // If the _completionSource has been cancelled or the exception // has been set, we don't need to check if TrySetResult returns false @@ -104,12 +104,12 @@ public bool TrySetTransferState(DataTransferStatus.TransferState state) return false; } - public bool TryOnFailedItemsState() => _status.OnFailedItem(); + public bool TrySetFailedItemsState() => _status.TrySetFailedItem(); - public bool TryOnSkippedItemsState() => _status.OnSkippedItem(); + public bool TrySetSkippedItemsState() => _status.TrySetSkippedItem(); internal bool CanPause() - => DataTransferStatus.TransferState.InProgress == _status.State; + => DataTransferState.InProgress == _status.State; public async Task PauseIfRunningAsync(CancellationToken cancellationToken) { @@ -119,7 +119,7 @@ public async Task PauseIfRunningAsync(CancellationToken cancellationToken) } CancellationHelper.ThrowIfCancellationRequested(cancellationToken); // Call the inner cancellation token to stop the transfer job - TrySetTransferState(DataTransferStatus.TransferState.Pausing); + TrySetTransferState(DataTransferState.Pausing); if (TriggerCancellation()) { // Wait until full pause has completed. diff --git a/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransferStatusInternal.cs b/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransferStatusInternal.cs index c7270363d19e3..ab00ece7466e4 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransferStatusInternal.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransferStatusInternal.cs @@ -6,7 +6,7 @@ namespace Azure.Storage.DataMovement internal class DataTransferStatusInternal : DataTransferStatus { public DataTransferStatusInternal( - TransferState state, + DataTransferState state, bool hasFailedItems, bool hasSkippedItems) : base(state, hasFailedItems, hasSkippedItems) diff --git a/sdk/storage/Azure.Storage.DataMovement/src/Shared/JobPlan/JobPartPlanHeader.cs b/sdk/storage/Azure.Storage.DataMovement/src/Shared/JobPlan/JobPartPlanHeader.cs index d5cfb96fafa68..42e6a0078b50c 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/Shared/JobPlan/JobPartPlanHeader.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/Shared/JobPlan/JobPartPlanHeader.cs @@ -834,7 +834,7 @@ public static JobPartPlanHeader Deserialize(Stream stream) // AtomicJobStatus.State byte atomicJobStatusByte = reader.ReadByte(); - DataTransferStatus.TransferState jobStatusState = (DataTransferStatus.TransferState)atomicJobStatusByte; + DataTransferState jobStatusState = (DataTransferState)atomicJobStatusByte; // AtomicJobStatus.HasFailedItems bool jobStatusHasFailed = Convert.ToBoolean(reader.ReadByte()); @@ -844,7 +844,7 @@ public static JobPartPlanHeader Deserialize(Stream stream) // AtomicPartStatus.State byte atomicPartStatusByte = reader.ReadByte(); - DataTransferStatus.TransferState partStatusState = (DataTransferStatus.TransferState)atomicPartStatusByte; + DataTransferState partStatusState = (DataTransferState)atomicPartStatusByte; // AtomicPartStatus.HasFailedItems bool partStatusHasFailed = Convert.ToBoolean(reader.ReadByte()); diff --git a/sdk/storage/Azure.Storage.DataMovement/src/Shared/TransferCheckpointer.cs b/sdk/storage/Azure.Storage.DataMovement/src/Shared/TransferCheckpointer.cs index 8a359c1b4940b..ebd52aa5c4cad 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/Shared/TransferCheckpointer.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/Shared/TransferCheckpointer.cs @@ -143,7 +143,7 @@ public abstract Task SetJobTransferStatusAsync( /// /// The transfer ID. /// The job part number. - /// The of the job part. + /// The of the job part. /// /// Optional to propagate /// notifications that the operation should be canceled. @@ -151,7 +151,7 @@ public abstract Task SetJobTransferStatusAsync( public abstract Task SetJobPartTransferStatusAsync( string transferId, int partNumber, - DataTransferStatus state, + DataTransferStatus status, CancellationToken cancellationToken = default); /// diff --git a/sdk/storage/Azure.Storage.DataMovement/src/Shared/TransferManager.cs b/sdk/storage/Azure.Storage.DataMovement/src/Shared/TransferManager.cs index 9c5d5adcb66de..f6bb1ebf46353 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/Shared/TransferManager.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/Shared/TransferManager.cs @@ -260,7 +260,7 @@ public virtual async Task PauseTransferIfRunningAsync(string transferId, Cancell /// If specified, the returned list of transfers will have only have the transfers /// of which match the status specified. /// - /// If not specified or specified to , + /// If not specified or specified to , /// all transfers will be returned regardless of status. /// /// diff --git a/sdk/storage/Azure.Storage.DataMovement/src/StreamToUriJobPart.cs b/sdk/storage/Azure.Storage.DataMovement/src/StreamToUriJobPart.cs index 2339b10589386..466e1fec9f6af 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/StreamToUriJobPart.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/StreamToUriJobPart.cs @@ -142,7 +142,7 @@ public override async Task ProcessPartToChunkAsync() // Attempt to get the length, it's possible the file could // not be accesible (or does not exist). string operationName = $"{nameof(TransferManager.StartTransferAsync)}"; - await OnTransferStateChangedAsync(DataTransferStatus.TransferState.InProgress).ConfigureAwait(false); + await OnTransferStateChangedAsync(DataTransferState.InProgress).ConfigureAwait(false); long? fileLength = default; try { @@ -250,7 +250,7 @@ await _destinationResource.CopyFromStreamAsync( ReportBytesWritten(blockSize); // Set completion status to completed - await OnTransferStateChangedAsync(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); + await OnTransferStateChangedAsync(DataTransferState.Completed).ConfigureAwait(false); } else { @@ -395,7 +395,7 @@ await _destinationResource.CompleteTransferAsync( await DisposeHandlers().ConfigureAwait(false); // Set completion status to completed - await OnTransferStateChangedAsync(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); + await OnTransferStateChangedAsync(DataTransferState.Completed).ConfigureAwait(false); } private async Task QueueStageBlockRequests(List<(long Offset, long Size)> rangeList, long completeLength) diff --git a/sdk/storage/Azure.Storage.DataMovement/src/StreamToUriTransferJob.cs b/sdk/storage/Azure.Storage.DataMovement/src/StreamToUriTransferJob.cs index c248d5993a5b6..df37661cdb910 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/StreamToUriTransferJob.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/StreamToUriTransferJob.cs @@ -67,7 +67,7 @@ internal StreamToUriTransferJob( /// An IEnumerable that contains the job parts public override async IAsyncEnumerable ProcessJobToJobPartAsync() { - await OnJobStateChangedAsync(DataTransferStatus.TransferState.InProgress).ConfigureAwait(false); + await OnJobStateChangedAsync(DataTransferState.InProgress).ConfigureAwait(false); int partNumber = 0; if (_jobParts.Count == 0) @@ -108,7 +108,7 @@ public override async IAsyncEnumerable ProcessJobToJobPartAsync { if (!part.JobPartStatus.HasCompletedSuccessfully) { - part.JobPartStatus.OnTransferStateChange(DataTransferStatus.TransferState.Queued); + part.JobPartStatus.TrySetTransferStateChange(DataTransferState.Queued); yield return part; if (part.IsFinalPart) diff --git a/sdk/storage/Azure.Storage.DataMovement/src/TransferJobInternal.cs b/sdk/storage/Azure.Storage.DataMovement/src/TransferJobInternal.cs index 3c3a29f05ca97..c030881e72dea 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/TransferJobInternal.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/TransferJobInternal.cs @@ -154,7 +154,7 @@ private TransferJobInternal( Argument.AssertNotNull(clientDiagnostics, nameof(clientDiagnostics)); _dataTransfer = dataTransfer ?? throw Errors.ArgumentNull(nameof(dataTransfer)); - _dataTransfer.TransferStatus.OnTransferStateChange(DataTransferStatus.TransferState.Queued); + _dataTransfer.TransferStatus.TrySetTransferStateChange(DataTransferState.Queued); _errorMode = errorHandling; _checkpointer = checkPointer; _creationPreference = creationPreference; @@ -268,7 +268,7 @@ public async Task TriggerJobCancellationAsync() { if (!_dataTransfer._state.CancellationTokenSource.IsCancellationRequested) { - await OnJobStateChangedAsync(DataTransferStatus.TransferState.Stopping).ConfigureAwait(false); + await OnJobStateChangedAsync(DataTransferState.Stopping).ConfigureAwait(false); _dataTransfer._state.TriggerCancellation(); } } @@ -313,17 +313,17 @@ await TransferFailedEventHandler.RaiseAsync( public async Task JobPartEvent(TransferStatusEventArgs args) { DataTransferStatus jobPartStatus = args.TransferStatus; - DataTransferStatus jobStatus = _dataTransfer._state.GetTransferStatus(); + DataTransferState jobState = _dataTransfer._state.GetTransferStatus().State; // Keep track of paused, failed, and skipped which we will use to determine final job status // Since this is each Job Part coming in, the state of skipped or failed is mutually exclusive. - if (jobPartStatus.State == DataTransferStatus.TransferState.Paused) + if (jobPartStatus.State == DataTransferState.Paused) { _jobPartPaused = true; } else if (jobPartStatus.HasFailedItems) { - if (_dataTransfer._state.TryOnFailedItemsState()) + if (_dataTransfer._state.TrySetFailedItemsState()) { await SetCheckpointerStatus().ConfigureAwait(false); await OnJobPartStatusChangedAsync().ConfigureAwait(false); @@ -331,7 +331,7 @@ public async Task JobPartEvent(TransferStatusEventArgs args) } else if (jobPartStatus.HasSkippedItems) { - if (_dataTransfer._state.TryOnSkippedItemsState()) + if (_dataTransfer._state.TrySetSkippedItemsState()) { await SetCheckpointerStatus().ConfigureAwait(false); await OnJobPartStatusChangedAsync().ConfigureAwait(false); @@ -341,19 +341,19 @@ public async Task JobPartEvent(TransferStatusEventArgs args) // Cancel the entire job if one job part fails and StopOnFailure is set if (_errorMode == DataTransferErrorMode.StopOnAnyFailure && jobPartStatus.HasFailedItems && - jobStatus.State != DataTransferStatus.TransferState.Stopping && - jobStatus.State != DataTransferStatus.TransferState.Completed) + jobState != DataTransferState.Stopping && + jobState != DataTransferState.Completed) { await TriggerJobCancellationAsync().ConfigureAwait(false); - jobStatus = _dataTransfer._state.GetTransferStatus(); + jobState = _dataTransfer._state.GetTransferStatus().State; } - if ((jobPartStatus.State == DataTransferStatus.TransferState.Paused || - jobPartStatus.State == DataTransferStatus.TransferState.Completed) - && (jobStatus.State == DataTransferStatus.TransferState.Queued || - jobStatus.State == DataTransferStatus.TransferState.InProgress || - jobStatus.State == DataTransferStatus.TransferState.Pausing || - jobStatus.State == DataTransferStatus.TransferState.Stopping)) + if ((jobPartStatus.State == DataTransferState.Paused || + jobPartStatus.State == DataTransferState.Completed) + && (jobState == DataTransferState.Queued || + jobState == DataTransferState.InProgress || + jobState == DataTransferState.Pausing || + jobState == DataTransferState.Stopping)) { Interlocked.Decrement(ref _pendingJobParts); @@ -364,13 +364,13 @@ public async Task JobPartEvent(TransferStatusEventArgs args) } } - public async Task OnJobStateChangedAsync(DataTransferStatus.TransferState state) + public async Task OnJobStateChangedAsync(DataTransferState state) { if (_dataTransfer._state.TrySetTransferState(state)) { // If we are in a final state, dispose the JobPartEvent handlers - if (state == DataTransferStatus.TransferState.Completed || - state == DataTransferStatus.TransferState.Paused) + if (state == DataTransferState.Completed || + state == DataTransferState.Paused) { DisposeHandlers(); } @@ -407,17 +407,17 @@ internal async Task OnEnumerationComplete() { // If there were no job parts enumerated and we haven't already aborted/completed the job. if (_jobParts.Count == 0 && - _dataTransfer.TransferStatus.State != DataTransferStatus.TransferState.Paused && - _dataTransfer.TransferStatus.State != DataTransferStatus.TransferState.Completed) + _dataTransfer.TransferStatus.State != DataTransferState.Paused && + _dataTransfer.TransferStatus.State != DataTransferState.Completed) { - if (_dataTransfer.TransferStatus.State == DataTransferStatus.TransferState.Pausing) + if (_dataTransfer.TransferStatus.State == DataTransferState.Pausing) { // If we paused before we were able to list, set the status properly. - await OnJobStateChangedAsync(DataTransferStatus.TransferState.Paused).ConfigureAwait(false); + await OnJobStateChangedAsync(DataTransferState.Paused).ConfigureAwait(false); } else { - await OnJobStateChangedAsync(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); + await OnJobStateChangedAsync(DataTransferState.Completed).ConfigureAwait(false); } } await CheckAndUpdateStatusAsync().ConfigureAwait(false); @@ -429,13 +429,13 @@ internal async Task CheckAndUpdateStatusAsync() // This is in the case that we weren't able to begin listing any job parts yet. if (_jobParts.Count == 0) { - if (_dataTransfer.TransferStatus.State == DataTransferStatus.TransferState.Pausing) + if (_dataTransfer.TransferStatus.State == DataTransferState.Pausing) { - await OnJobStateChangedAsync(DataTransferStatus.TransferState.Paused).ConfigureAwait(false); + await OnJobStateChangedAsync(DataTransferState.Paused).ConfigureAwait(false); } - else if (_dataTransfer.TransferStatus.State == DataTransferStatus.TransferState.Stopping) + else if (_dataTransfer.TransferStatus.State == DataTransferState.Stopping) { - await OnJobStateChangedAsync(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); + await OnJobStateChangedAsync(DataTransferState.Completed).ConfigureAwait(false); } return; } @@ -445,11 +445,11 @@ internal async Task CheckAndUpdateStatusAsync() { if (_jobPartPaused) { - await OnJobStateChangedAsync(DataTransferStatus.TransferState.Paused).ConfigureAwait(false); + await OnJobStateChangedAsync(DataTransferState.Paused).ConfigureAwait(false); } else { - await OnJobStateChangedAsync(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); + await OnJobStateChangedAsync(DataTransferState.Completed).ConfigureAwait(false); } } } @@ -460,7 +460,7 @@ public void AppendJobPart(JobPartInternal jobPart) // Job parts can come from resuming a transfer and therefore may already be complete DataTransferStatus status = jobPart.JobPartStatus; - if (status.State != DataTransferStatus.TransferState.Completed) + if (status.State != DataTransferState.Completed) { Interlocked.Increment(ref _pendingJobParts); } diff --git a/sdk/storage/Azure.Storage.DataMovement/src/UriToStreamJobPart.cs b/sdk/storage/Azure.Storage.DataMovement/src/UriToStreamJobPart.cs index 5da5e72bbeccf..7e80aed3afa0c 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/UriToStreamJobPart.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/UriToStreamJobPart.cs @@ -147,7 +147,7 @@ public override async Task ProcessPartToChunkAsync() { // we can default the length to 0 because we know the destination is local and // does not require a length to be created. - await OnTransferStateChangedAsync(DataTransferStatus.TransferState.InProgress).ConfigureAwait(false); + await OnTransferStateChangedAsync(DataTransferState.InProgress).ConfigureAwait(false); try { @@ -340,7 +340,7 @@ await _destinationResource.CompleteTransferAsync( await DisposeHandlers().ConfigureAwait(false); // Update the transfer status - await OnTransferStateChangedAsync(DataTransferStatus.TransferState.Completed).ConfigureAwait(false); + await OnTransferStateChangedAsync(DataTransferState.Completed).ConfigureAwait(false); } catch (Exception ex) { diff --git a/sdk/storage/Azure.Storage.DataMovement/src/UriToStreamTransferJob.cs b/sdk/storage/Azure.Storage.DataMovement/src/UriToStreamTransferJob.cs index 5332867ea7c4b..67bcdf915c99c 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/UriToStreamTransferJob.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/UriToStreamTransferJob.cs @@ -67,7 +67,7 @@ internal UriToStreamTransferJob( /// An IEnumerable that contains the job parts public override async IAsyncEnumerable ProcessJobToJobPartAsync() { - await OnJobStateChangedAsync(DataTransferStatus.TransferState.InProgress).ConfigureAwait(false); + await OnJobStateChangedAsync(DataTransferState.InProgress).ConfigureAwait(false); int partNumber = 0; if (_jobParts.Count == 0) @@ -108,7 +108,7 @@ public override async IAsyncEnumerable ProcessJobToJobPartAsync { if (!part.JobPartStatus.HasCompletedSuccessfully) { - part.JobPartStatus.OnTransferStateChange(DataTransferStatus.TransferState.Queued); + part.JobPartStatus.TrySetTransferStateChange(DataTransferState.Queued); yield return part; if (part.IsFinalPart) diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/DataTransferTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/DataTransferTests.cs index a4d8b5040608e..215a5d9617141 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/DataTransferTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/DataTransferTests.cs @@ -12,9 +12,9 @@ namespace Azure.Storage.DataMovement.Tests public class DataTransferTests { private static string GetNewTransferId() => Guid.NewGuid().ToString(); - private static DataTransferStatus QueuedStatus => new DataTransferStatus(DataTransferStatus.TransferState.Queued, false, false); - private static DataTransferStatus InProgressStatus => new DataTransferStatus(DataTransferStatus.TransferState.InProgress, false, false); - private static DataTransferStatus SuccessfulCompletedStatus => new DataTransferStatus(DataTransferStatus.TransferState.Completed, false, false); + private static DataTransferStatus QueuedStatus => new DataTransferStatus(DataTransferState.Queued, false, false); + private static DataTransferStatus InProgressStatus => new DataTransferStatus(DataTransferState.InProgress, false, false); + private static DataTransferStatus SuccessfulCompletedStatus => new DataTransferStatus(DataTransferState.Completed, false, false); [Test] public void Ctor_Default() @@ -33,14 +33,14 @@ public void Ctor_Default() } [Test] - [TestCase(DataTransferStatus.TransferState.None, false)] - [TestCase(DataTransferStatus.TransferState.Queued, false)] - [TestCase(DataTransferStatus.TransferState.InProgress, false)] - [TestCase(DataTransferStatus.TransferState.Pausing, false)] - [TestCase(DataTransferStatus.TransferState.Paused, false)] - [TestCase(DataTransferStatus.TransferState.Stopping, false)] - [TestCase(DataTransferStatus.TransferState.Stopping, true)] - public void HasCompleted_False(DataTransferStatus.TransferState status, bool hasFailedItems) + [TestCase(DataTransferState.None, false)] + [TestCase(DataTransferState.Queued, false)] + [TestCase(DataTransferState.InProgress, false)] + [TestCase(DataTransferState.Pausing, false)] + [TestCase(DataTransferState.Paused, false)] + [TestCase(DataTransferState.Stopping, false)] + [TestCase(DataTransferState.Stopping, true)] + public void HasCompleted_False(DataTransferState status, bool hasFailedItems) { // Arrange string transferId = GetNewTransferId(); @@ -59,12 +59,12 @@ public void HasCompleted_False(DataTransferStatus.TransferState status, bool has } [Test] - [TestCase(DataTransferStatus.TransferState.Completed, false, false)] - [TestCase(DataTransferStatus.TransferState.Completed, false, true)] - [TestCase(DataTransferStatus.TransferState.Completed, true, false)] - [TestCase(DataTransferStatus.TransferState.Completed, true, true)] + [TestCase(DataTransferState.Completed, false, false)] + [TestCase(DataTransferState.Completed, false, true)] + [TestCase(DataTransferState.Completed, true, false)] + [TestCase(DataTransferState.Completed, true, true)] public void HasCompleted_True( - DataTransferStatus.TransferState state, + DataTransferState state, bool hasFailedItems, bool hasSkippedItems) { @@ -175,28 +175,28 @@ public async Task TryPauseAsync() // Act Task pauseTask = transfer.PauseAsync(); - Assert.AreEqual(DataTransferStatus.TransferState.Pausing, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Pausing, transfer.TransferStatus.State); // Assert - if (!transfer._state.TrySetTransferState(DataTransferStatus.TransferState.Paused)) + if (!transfer._state.TrySetTransferState(DataTransferState.Paused)) { Assert.Fail("Unable to set the transfer status internally to the DataTransfer."); } await pauseTask; - Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Paused, transfer.TransferStatus.State); Assert.IsFalse(transfer.HasCompleted); } [Test] - [TestCase(DataTransferStatus.TransferState.Paused, false, false)] - [TestCase(DataTransferStatus.TransferState.Completed, false, false)] - [TestCase(DataTransferStatus.TransferState.Completed, false, true)] - [TestCase(DataTransferStatus.TransferState.Completed, true, false)] - [TestCase(DataTransferStatus.TransferState.Completed, true, true)] + [TestCase(DataTransferState.Paused, false, false)] + [TestCase(DataTransferState.Completed, false, false)] + [TestCase(DataTransferState.Completed, false, true)] + [TestCase(DataTransferState.Completed, true, false)] + [TestCase(DataTransferState.Completed, true, true)] public async Task TryPauseAsync_AlreadyPaused( - DataTransferStatus.TransferState state, + DataTransferState state, bool hasFailedItems, bool hasSkippedItems) { @@ -235,7 +235,7 @@ public async Task TryPauseAsync_CancellationToken() { Assert.AreEqual(exception.Message, "The operation was canceled."); } - Assert.AreEqual(DataTransferStatus.TransferState.Pausing, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Pausing, transfer.TransferStatus.State); Assert.IsFalse(transfer.HasCompleted); } } diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/GetTransfersTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/GetTransfersTests.cs index fa6099b86bf93..8bae1edbd2025 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/GetTransfersTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/GetTransfersTests.cs @@ -14,13 +14,13 @@ namespace Azure.Storage.DataMovement.Tests /// public class GetTransfersTests { - private static DataTransferStatus QueuedStatus => new DataTransferStatus(DataTransferStatus.TransferState.Queued, false, false); - private static DataTransferStatus InProgressStatus => new DataTransferStatus(DataTransferStatus.TransferState.InProgress, false, false); - private static DataTransferStatus PausedStatus => new DataTransferStatus(DataTransferStatus.TransferState.Paused, false, false); - private static DataTransferStatus SuccessfulCompletedStatus => new DataTransferStatus(DataTransferStatus.TransferState.Completed, false, false); - private static DataTransferStatus FailedCompletedStatus => new DataTransferStatus(DataTransferStatus.TransferState.Completed, true, false); - private static DataTransferStatus SkippedCompletedStatus => new DataTransferStatus(DataTransferStatus.TransferState.Completed, true, false); - private static DataTransferStatus FailedSkippedCompletedStatus => new DataTransferStatus(DataTransferStatus.TransferState.Completed, true, false); + private static DataTransferStatus QueuedStatus => new DataTransferStatus(DataTransferState.Queued, false, false); + private static DataTransferStatus InProgressStatus => new DataTransferStatus(DataTransferState.InProgress, false, false); + private static DataTransferStatus PausedStatus => new DataTransferStatus(DataTransferState.Paused, false, false); + private static DataTransferStatus SuccessfulCompletedStatus => new DataTransferStatus(DataTransferState.Completed, false, false); + private static DataTransferStatus FailedCompletedStatus => new DataTransferStatus(DataTransferState.Completed, true, false); + private static DataTransferStatus SkippedCompletedStatus => new DataTransferStatus(DataTransferState.Completed, true, false); + private static DataTransferStatus FailedSkippedCompletedStatus => new DataTransferStatus(DataTransferState.Completed, true, false); private TransferManagerOptions GetDefaultManagerOptions(string checkpointerPath) => new TransferManagerOptions() @@ -91,13 +91,13 @@ public async Task GetTransfers_Populated() } [Test] - [TestCase(DataTransferStatus.TransferState.Queued, false, false)] - [TestCase(DataTransferStatus.TransferState.InProgress, false, false)] - [TestCase(DataTransferStatus.TransferState.Paused, false, false)] - [TestCase(DataTransferStatus.TransferState.Completed, false, false)] - [TestCase(DataTransferStatus.TransferState.Completed, true, false)] + [TestCase(DataTransferState.Queued, false, false)] + [TestCase(DataTransferState.InProgress, false, false)] + [TestCase(DataTransferState.Paused, false, false)] + [TestCase(DataTransferState.Completed, false, false)] + [TestCase(DataTransferState.Completed, true, false)] public async Task GetTransfers_Filtered( - DataTransferStatus.TransferState state, + DataTransferState state, bool hasFailedItems, bool hasSkippedItems) { @@ -194,7 +194,7 @@ public async Task GetTransfers_Filtered_Empty() TransferManager manager = factory.BuildTransferManager(storedTransfers); // Act - With a transfer status not in the above stored transfers - DataTransferStatus[] statuses = new DataTransferStatus[] { new DataTransferStatus(DataTransferStatus.TransferState.Stopping, true, false) }; + DataTransferStatus[] statuses = new DataTransferStatus[] { new DataTransferStatus(DataTransferState.Stopping, true, false) }; IList result = await manager.GetTransfersAsync(statuses).ToListAsync(); // Assert diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/LocalTransferCheckpointerFactory.cs b/sdk/storage/Azure.Storage.DataMovement/tests/LocalTransferCheckpointerFactory.cs index 26453e3e105dc..2f6583895c7fe 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/LocalTransferCheckpointerFactory.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/LocalTransferCheckpointerFactory.cs @@ -43,8 +43,8 @@ internal static readonly DateTimeOffset _testStartTime internal const JobPartDeleteSnapshotsOption _testDeleteSnapshotsOption = JobPartDeleteSnapshotsOption.None; internal const JobPartPermanentDeleteOption _testPermanentDeleteOption = JobPartPermanentDeleteOption.None; internal const JobPartPlanRehydratePriorityType _testRehydratePriorityType = JobPartPlanRehydratePriorityType.None; - internal static readonly DataTransferStatus _testJobStatus = new DataTransferStatusInternal(DataTransferStatus.TransferState.Queued, false, false); - internal static readonly DataTransferStatus _testPartStatus = new DataTransferStatusInternal(DataTransferStatus.TransferState.Queued, false, false); + internal static readonly DataTransferStatus _testJobStatus = new DataTransferStatusInternal(DataTransferState.Queued, false, false); + internal static readonly DataTransferStatus _testPartStatus = new DataTransferStatusInternal(DataTransferState.Queued, false, false); private string _checkpointerPath; diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/LocalTransferCheckpointerTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/LocalTransferCheckpointerTests.cs index c3ac65565647d..3b38efe6f9642 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/LocalTransferCheckpointerTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/LocalTransferCheckpointerTests.cs @@ -14,7 +14,7 @@ namespace Azure.Storage.DataMovement.Tests { public class LocalTransferCheckpointerTests : DataMovementTestBase { - private static DataTransferStatus SuccessfulCompletedStatus => new DataTransferStatus(DataTransferStatus.TransferState.Completed, false, false); + private static DataTransferStatus SuccessfulCompletedStatus => new DataTransferStatus(DataTransferState.Completed, false, false); public LocalTransferCheckpointerTests(bool async) : base(async, null) diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/PauseResumeTransferTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/PauseResumeTransferTests.cs index dc903a97711b4..c474ab1a1a834 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/PauseResumeTransferTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/PauseResumeTransferTests.cs @@ -256,7 +256,7 @@ public async Task TryPauseTransferAsync_Id(TransferDirection transferType) // Assert await testEventsRaised.AssertPausedCheck(); - Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Paused, transfer.TransferStatus.State); // Check if Job Plan File exists in checkpointer path. JobPartPlanFileName fileName = new JobPartPlanFileName( @@ -304,7 +304,7 @@ public async Task TryPauseTransferAsync_DataTransfer(TransferDirection transferT // Assert await testEventsRaised.AssertPausedCheck(); - Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Paused, transfer.TransferStatus.State); // Check if Job Plan File exists in checkpointer path. JobPartPlanFileName fileName = new JobPartPlanFileName( @@ -368,12 +368,12 @@ public async Task TryPauseTransferAsync_AlreadyPaused(TransferDirection transfer // Assert await testEventsRaised.AssertPausedCheck(); - Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Paused, transfer.TransferStatus.State); CancellationTokenSource cancellationTokenSource2 = new CancellationTokenSource(TimeSpan.FromSeconds(10)); await transferManager.PauseTransferIfRunningAsync(transfer.Id, cancellationTokenSource2.Token); - Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Paused, transfer.TransferStatus.State); // Check if Job Plan File exists in checkpointer path. JobPartPlanFileName fileName = new JobPartPlanFileName( @@ -429,7 +429,7 @@ public async Task PauseThenResumeTransferAsync(TransferDirection transferType) await transferManager.PauseTransferIfRunningAsync(transfer.Id, cancellationTokenSource.Token); // Assert - Confirm we've paused - Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Paused, transfer.TransferStatus.State); await testEventsRaised.AssertPausedCheck(); // Act - Resume Job @@ -444,7 +444,7 @@ public async Task PauseThenResumeTransferAsync(TransferDirection transferType) // Assert await testEventRaised2.AssertSingleCompletedCheck(); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, resumeTransfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, resumeTransfer.TransferStatus.State); Assert.IsTrue(resumeTransfer.HasCompleted); // Verify transfer @@ -500,7 +500,7 @@ public async Task ResumeTransferAsync(TransferDirection transferType) await transferManager.PauseTransferIfRunningAsync(transfer.Id, cancellationTokenSource.Token); // Assert - Confirm we've paused - Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Paused, transfer.TransferStatus.State); await testEventsRaised.AssertPausedCheck(); // Act - Resume Job @@ -515,7 +515,7 @@ public async Task ResumeTransferAsync(TransferDirection transferType) // Assert await testEventRaised2.AssertSingleCompletedCheck(); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, resumeTransfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, resumeTransfer.TransferStatus.State); Assert.IsTrue(resumeTransfer.HasCompleted); // Verify transfer @@ -705,7 +705,7 @@ public async Task TryPauseTransferAsync_Id_Directory(TransferDirection transferT // Assert await testEventsRaised.AssertPausedCheck(); - Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Paused, transfer.TransferStatus.State); } [Ignore("https://github.com/Azure/azure-sdk-for-net/issues/35439")] @@ -750,7 +750,7 @@ public async Task TryPauseTransferAsync_DataTransfer_Directory(TransferDirection // Assert await testEventsRaised.AssertPausedCheck(); - Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Paused, transfer.TransferStatus.State); } [Ignore("https://github.com/Azure/azure-sdk-for-net/issues/35439")] @@ -795,13 +795,13 @@ public async Task TryPauseTransferAsync_AlreadyPaused_Directory(TransferDirectio // Assert await testEventsRaised.AssertPausedCheck(); - Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Paused, transfer.TransferStatus.State); CancellationTokenSource cancellationTokenSource2 = new CancellationTokenSource(TimeSpan.FromSeconds(10)); await transferManager.PauseTransferIfRunningAsync(transfer.Id, cancellationTokenSource2.Token); await testEventsRaised.AssertPausedCheck(); - Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Paused, transfer.TransferStatus.State); } [Ignore("https://github.com/Azure/azure-sdk-for-net/issues/35439")] @@ -853,7 +853,7 @@ public async Task PauseThenResumeTransferAsync_Directory(TransferDirection trans await transferManager.PauseTransferIfRunningAsync(transfer.Id, cancellationTokenSource.Token); // Assert - Confirm we've paused - Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Paused, transfer.TransferStatus.State); await testEventsRaised.AssertPausedCheck(); // Act - Resume Job @@ -868,7 +868,7 @@ public async Task PauseThenResumeTransferAsync_Directory(TransferDirection trans // Assert await testEventRaised2.AssertContainerCompletedCheck(partCount); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, resumeTransfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, resumeTransfer.TransferStatus.State); Assert.IsTrue(resumeTransfer.HasCompleted); // Verify transfer @@ -929,7 +929,7 @@ public async Task ResumeTransferAsync_Directory(TransferDirection transferType) await transferManager.PauseTransferIfRunningAsync(transfer.Id, cancellationTokenSource.Token); // Assert - Confirm we've paused - Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Paused, transfer.TransferStatus.State); await testEventsRaised.AssertPausedCheck(); // Act - Resume Job @@ -944,7 +944,7 @@ public async Task ResumeTransferAsync_Directory(TransferDirection transferType) // Assert await testEventsRaised2.AssertContainerCompletedCheck(partCount); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, resumeTransfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, resumeTransfer.TransferStatus.State); Assert.IsTrue(resumeTransfer.HasCompleted); // Verify transfer @@ -962,9 +962,9 @@ public async Task PauseAllTriggersCorrectPauses() List> pausable = new(); List> unpausable = new(); TransferManager manager = new(); - foreach (DataTransferStatus.TransferState state in Enum.GetValues(typeof(DataTransferStatus.TransferState)).Cast()) + foreach (DataTransferState state in Enum.GetValues(typeof(DataTransferState)).Cast()) { - bool canPause = state == DataTransferStatus.TransferState.InProgress; + bool canPause = state == DataTransferState.InProgress; Mock transfer = new(MockBehavior.Loose) { CallBase = true, diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/ProgressHandlerTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/ProgressHandlerTests.cs index a36d1549dcf94..8ca12a5b75d49 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/ProgressHandlerTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/ProgressHandlerTests.cs @@ -339,7 +339,7 @@ public async Task ProgressHandler_PauseResume(int delayInMs) // Pause transfer CancellationTokenSource tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30)); await transferManager.PauseTransferIfRunningAsync(transfer.Id, tokenSource.Token); - Assert.AreEqual(DataTransferStatus.TransferState.Paused, transfer.TransferStatus); + Assert.AreEqual(DataTransferState.Paused, transfer.TransferStatus); // Record the current number of progress updates to use during assertions int pause = progressHandler.Updates.Count; @@ -353,7 +353,7 @@ public async Task ProgressHandler_PauseResume(int delayInMs) await resumeTransfer.WaitForCompletionAsync(tokenSource.Token); // Assert - Assert.AreEqual(DataTransferStatus.TransferState.Completed, resumeTransfer.TransferStatus); + Assert.AreEqual(DataTransferState.Completed, resumeTransfer.TransferStatus); ProgressHandlerAsserts.AssertFileProgress(progressHandler.Updates, 5, pauseIndexes: pause); ProgressHandlerAsserts.AssertBytesTransferred(progressHandler.Updates, _expectedBytesTransferred); } diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/Shared/CheckpointerTesting.cs b/sdk/storage/Azure.Storage.DataMovement/tests/Shared/CheckpointerTesting.cs index f4e809b4fdb06..e6bd02751e3d5 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/Shared/CheckpointerTesting.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/Shared/CheckpointerTesting.cs @@ -52,8 +52,8 @@ internal static readonly DateTimeOffset DefaultStartTime internal const JobPartDeleteSnapshotsOption DefaultDeleteSnapshotsOption = JobPartDeleteSnapshotsOption.None; internal const JobPartPermanentDeleteOption DefaultPermanentDeleteOption = JobPartPermanentDeleteOption.None; internal const JobPartPlanRehydratePriorityType DefaultRehydratePriorityType = JobPartPlanRehydratePriorityType.None; - internal static readonly DataTransferStatus DefaultJobStatus = new DataTransferStatusInternal(DataTransferStatus.TransferState.Queued, false, false); - internal static readonly DataTransferStatus DefaultPartStatus = new DataTransferStatusInternal(DataTransferStatus.TransferState.Queued, false, false); + internal static readonly DataTransferStatus DefaultJobStatus = new DataTransferStatusInternal(DataTransferState.Queued, false, false); + internal static readonly DataTransferStatus DefaultPartStatus = new DataTransferStatusInternal(DataTransferState.Queued, false, false); internal static JobPartPlanHeader CreateDefaultJobPartHeader( string version = DataMovementConstants.JobPartPlanFile.SchemaVersion, diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferDownloadDirectoryTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferDownloadDirectoryTests.cs index a2e00eb11b74d..b122bdd778439 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferDownloadDirectoryTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferDownloadDirectoryTests.cs @@ -77,7 +77,7 @@ private async Task DownloadBlobDirectoryAndVerify( await testEventsRaised.AssertContainerCompletedCheck(sourceFiles.Count); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); // List all files in source blob folder path List blobNames = new List(); @@ -223,7 +223,7 @@ public async Task DownloadDirectoryAsync_Empty() await transfer.WaitForCompletionAsync(cancellationTokenSource.Token); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); List localItemsAfterDownload = Directory.GetFiles(destinationFolder, "*", SearchOption.AllDirectories).ToList(); @@ -517,7 +517,7 @@ public async Task StartTransfer_AwaitCompletion() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); await testEventsRaised.AssertContainerCompletedCheck(4); } @@ -553,7 +553,7 @@ public async Task StartTransfer_AwaitCompletion_Failed() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("Cannot overwrite file.")); await testEventsRaised.AssertContainerCompletedWithFailedCheck(1); @@ -592,7 +592,7 @@ public async Task StartTransfer_AwaitCompletion_Skipped() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); await testEventsRaised.AssertContainerCompletedWithSkippedCheck(1); } @@ -623,7 +623,7 @@ public async Task StartTransfer_EnsureCompleted() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); await testEventsRaised.AssertContainerCompletedCheck(4); } @@ -659,7 +659,7 @@ public async Task StartTransfer_EnsureCompleted_Failed() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("Cannot overwrite file.")); await testEventsRaised.AssertContainerCompletedWithFailedCheck(1); @@ -698,7 +698,7 @@ public async Task StartTransfer_EnsureCompleted_Skipped() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); await testEventsRaised.AssertContainerCompletedWithSkippedCheck(1); } @@ -738,7 +738,7 @@ public async Task StartTransfer_EnsureCompleted_Failed_SmallChunks() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("Cannot overwrite file.")); await testEventsRaised.AssertContainerCompletedWithFailedCheck(1); diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferDownloadTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferDownloadTests.cs index 0045733015fc6..0d42188150cf4 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferDownloadTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferDownloadTests.cs @@ -172,7 +172,7 @@ private async Task DownloadBlockBlobsAndVerify( // Verify Download await downloadedBlobInfo[i].EventsRaised.AssertSingleCompletedCheck(); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, downloadedBlobInfo[i].DataTransfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, downloadedBlobInfo[i].DataTransfer.TransferStatus.State); CheckDownloadFile(downloadedBlobInfo[i].SourceLocalPath, downloadedBlobInfo[i].DestinationLocalPath); }; } @@ -288,7 +288,7 @@ public async Task BlockBlobToLocal_Skip_Exists() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(skippedSeen); FileInfo destFileInfo = new FileInfo(destFile); @@ -331,7 +331,7 @@ public async Task BlockBlobToLocal_Failure_Exists() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); await testEventsRaised.AssertSingleFailedCheck(); FileInfo destFileInfo = new FileInfo(destFile); @@ -697,7 +697,7 @@ public async Task AppendBlobToLocal_Skip_Exists() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); await testEventsRaised.AssertSingleSkippedCheck(); FileInfo destFileInfo = new FileInfo(destFile); @@ -741,7 +741,7 @@ public async Task AppendBlobToLocal_Failure_Exists() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); await testEventsRaised.AssertSingleFailedCheck(); FileInfo destFileInfo = new FileInfo(destFile); @@ -1158,7 +1158,7 @@ public async Task PageBlobToLocal_Skip_Exists() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); await testEventsRaised.AssertSingleSkippedCheck(); FileInfo destFileInfo = new FileInfo(destFile); @@ -1202,7 +1202,7 @@ public async Task PageBlobToLocal_Failure_Exists() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); await testEventsRaised.AssertSingleFailedCheck(); FileInfo destFileInfo = new FileInfo(destFile); @@ -1423,7 +1423,7 @@ public async Task StartTransfer_AwaitCompletion() failureTransferHolder.AssertUnexpectedFailureCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); } [RecordedTest] @@ -1454,7 +1454,7 @@ public async Task StartTransfer_AwaitCompletion_Failed() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); await testEventRaised.AssertSingleFailedCheck(); Assert.AreEqual(1, testEventRaised.FailedEvents.Count); @@ -1490,7 +1490,7 @@ public async Task StartTransfer_AwaitCompletion_Skipped() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); await testEventRaised.AssertSingleSkippedCheck(); } @@ -1524,7 +1524,7 @@ public async Task StartTransfer_EnsureCompleted() testEventRaised.AssertUnexpectedFailureCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); } [RecordedTest] @@ -1555,7 +1555,7 @@ public async Task StartTransfer_EnsureCompleted_Failed() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); await testEventsRaised.AssertSingleFailedCheck(); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("Cannot overwrite file.")); @@ -1591,7 +1591,7 @@ public async Task StartTransfer_EnsureCompleted_Skipped() await testEventsRaised.AssertSingleSkippedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); } #endregion diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferSyncCopyDirectoryTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferSyncCopyDirectoryTests.cs index 8fa050dbde4fe..c14e6686f9d0d 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferSyncCopyDirectoryTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferSyncCopyDirectoryTests.cs @@ -80,7 +80,7 @@ private async Task CopyBlobDirectoryAndVerify( await testEventFailed.AssertContainerCompletedCheck(sourceFiles.Count); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); // List all files in source blob folder path List sourceblobNames = new List(); @@ -247,7 +247,7 @@ public async Task BlockBlobDirectoryToDirectory_EmptyFolder() CancellationTokenSource tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30)); await transfer.WaitForCompletionAsync(tokenSource.Token); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); // Assert List blobs = ((List)await test.Container.GetBlobsAsync().ToListAsync()) @@ -588,7 +588,7 @@ public async Task StartTransfer_AwaitCompletion() testEventsRaised.AssertUnexpectedFailureCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); } [Test] @@ -618,7 +618,7 @@ public async Task StartTransfer_AwaitCompletion_Failed() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); await testEventsRaised.AssertContainerCompletedWithFailedCheck(1); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); @@ -652,7 +652,7 @@ public async Task StartTransfer_AwaitCompletion_Skipped() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); await testEventsRaised.AssertContainerCompletedWithSkippedCheck(1); } @@ -678,7 +678,7 @@ public async Task StartTransfer_EnsureCompleted() testEventsRaised.AssertUnexpectedFailureCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); } [Test] @@ -708,7 +708,7 @@ public async Task StartTransfer_EnsureCompleted_Failed() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); await testEventsRaised.AssertContainerCompletedWithFailedCheck(1); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); @@ -743,7 +743,7 @@ public async Task StartTransfer_EnsureCompleted_Skipped() testEventsRaised.AssertUnexpectedFailureCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); } @@ -779,7 +779,7 @@ public async Task StartTransfer_EnsureCompleted_Failed_SmallChunks() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); await testEventsRaised.AssertContainerCompletedWithFailedCheck(1); diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferSyncCopyTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferSyncCopyTests.cs index 7c56420802408..44f3c8ec09598 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferSyncCopyTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferSyncCopyTests.cs @@ -167,7 +167,7 @@ private async Task CopyBlockBlobsAndVerify( CancellationTokenSource tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(waitTimeInSec)); await copyBlobInfo[i].DataTransfer.WaitForCompletionAsync(tokenSource.Token); Assert.IsTrue(copyBlobInfo[i].DataTransfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, copyBlobInfo[i].DataTransfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, copyBlobInfo[i].DataTransfer.TransferStatus.State); // Verify Copy - using original source File and Copying the destination await copyBlobInfo[i].testEventsRaised.AssertSingleCompletedCheck(); @@ -387,7 +387,7 @@ public async Task BlockBlobToBlockBlob_Skip_Exists() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); await testEventsRaised.AssertSingleSkippedCheck(); Assert.IsTrue(await destinationClient.ExistsAsync()); @@ -440,7 +440,7 @@ public async Task BlockBlobToBlockBlob_Failure_Exists() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(await destinationClient.ExistsAsync()); await testEventsRaised.AssertSingleFailedCheck(); @@ -530,7 +530,7 @@ public async Task AppendBlobToAppendBlob_Error() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); await testEventsRaised.AssertSingleFailedCheck(); Assert.NotNull(testEventsRaised.FailedEvents.First().Exception, "Excepted failure: Failure was supposed to be raised during the test"); @@ -584,7 +584,7 @@ public async Task PageBlobToPageBlob_Error() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); await testEventsRaised.AssertSingleFailedCheck(); Assert.NotNull(testEventsRaised.FailedEvents.First().Exception, "Excepted failure: Failure was supposed to be raised during the test"); @@ -655,7 +655,7 @@ public async Task StartTransfer_AwaitCompletion() await testEventsRaised.AssertSingleCompletedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); } [RecordedTest] @@ -684,7 +684,7 @@ public async Task StartTransfer_AwaitCompletion_Failed() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); await testEventsRaised.AssertSingleFailedCheck(); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); @@ -718,7 +718,7 @@ public async Task StartTransfer_AwaitCompletion_Skipped() await testEventsRaised.AssertSingleSkippedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); } @@ -742,7 +742,7 @@ public async Task StartTransfer_EnsureCompleted() await testEventsRaised.AssertSingleCompletedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); } [RecordedTest] @@ -772,7 +772,7 @@ public async Task StartTransfer_EnsureCompleted_Failed() await testEventsRaised.AssertSingleFailedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); } @@ -805,7 +805,7 @@ public async Task StartTransfer_EnsureCompleted_Skipped() await testEventsRaised.AssertSingleSkippedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); } #endregion diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferUploadDirectoryTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferUploadDirectoryTests.cs index 892e6d81d8760..5862d00dcbbf0 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferUploadDirectoryTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferUploadDirectoryTests.cs @@ -73,7 +73,7 @@ private async Task UploadBlobDirectoryAndVerify( await testEventsRaised.AssertContainerCompletedCheck(files.Count); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); // Assert - Check Response List blobs = ((List)await destinationContainer.GetBlobsAsync(prefix: destinationPrefix).ToListAsync()) @@ -736,7 +736,7 @@ public async Task StartTransfer_AwaitCompletion() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); await testEventsRaised.AssertContainerCompletedCheck(4); } @@ -770,7 +770,7 @@ public async Task StartTransfer_AwaitCompletion_Failed() await testEventsRaised.AssertContainerCompletedWithFailedCheck(1); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); } @@ -806,7 +806,7 @@ public async Task StartTransfer_AwaitCompletion_Skipped() await testEventsRaised.AssertContainerCompletedWithSkippedCheck(1); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); } @@ -836,7 +836,7 @@ public async Task StartTransfer_EnsureCompleted() await testEventsRaised.AssertContainerCompletedCheck(4); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); } [Test] @@ -869,7 +869,7 @@ public async Task StartTransfer_EnsureCompleted_Failed() await testEventsRaised.AssertContainerCompletedWithFailedCheck(1); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); } @@ -905,7 +905,7 @@ public async Task StartTransfer_EnsureCompleted_Skipped() await testEventsRaised.AssertContainerCompletedWithSkippedCheck(1); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); } @@ -941,7 +941,7 @@ public async Task StartTransfer_EnsureCompleted_Failed_SmallChunks() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); await testEventsRaised.AssertContainerCompletedWithFailedCheck(1); diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferUploadTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferUploadTests.cs index fdcbf3033a8f5..f70725104019f 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferUploadTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/StartTransferUploadTests.cs @@ -169,7 +169,7 @@ public async Task LocalToBlockBlob_EventHandler() options.TransferStatusChanged += (TransferStatusEventArgs args) => { // Assert - if (args.TransferStatus.State == DataTransferStatus.TransferState.InProgress) + if (args.TransferStatus.State == DataTransferState.InProgress) { progressSeen = true; } @@ -305,7 +305,7 @@ public async Task LocalToBlockBlob_Skip_Exists() await testEventsRaised.AssertSingleSkippedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); Assert.IsTrue(await destinationClient.ExistsAsync()); // Verify Upload - That we skipped over and didn't reupload something new. @@ -353,7 +353,7 @@ public async Task LocalToBlockBlob_Failure_Exists() // Assert Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(await destinationClient.ExistsAsync()); await testEventRaised.AssertSingleFailedCheck(); @@ -583,7 +583,7 @@ private async Task UploadPageBlobsAndVerify( CancellationTokenSource tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(waitTimeInSec)); await uploadedBlobInfo[i].DataTransfer.WaitForCompletionAsync(tokenSource.Token); Assert.IsTrue(uploadedBlobInfo[i].DataTransfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, uploadedBlobInfo[i].DataTransfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, uploadedBlobInfo[i].DataTransfer.TransferStatus.State); // Verify Upload await uploadedBlobInfo[i].EventsRaised.AssertSingleCompletedCheck(); @@ -697,7 +697,7 @@ public async Task LocalToPageBlob_Skip_Exists() await testEventsRaised.AssertSingleSkippedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); Assert.IsTrue(await destinationClient.ExistsAsync()); // Verify Upload - That we skipped over and didn't reupload something new. @@ -745,7 +745,7 @@ public async Task LocalToPageBlob_Failure_Exists() await testEventsRaised.AssertSingleFailedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(await destinationClient.ExistsAsync()); Assert.NotNull(testEventsRaised.FailedEvents.First().Exception, "Excepted failure: Overwrite failure was supposed to be raised during the test"); @@ -1004,7 +1004,7 @@ private async Task UploadAppendBlobsAndVerify( CancellationTokenSource tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(waitTimeInSec)); await uploadedBlobInfo[i].DataTransfer.WaitForCompletionAsync(tokenSource.Token); Assert.IsTrue(uploadedBlobInfo[i].DataTransfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, uploadedBlobInfo[i].DataTransfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, uploadedBlobInfo[i].DataTransfer.TransferStatus.State); // Verify Upload await uploadedBlobInfo[i].EventsRaised.AssertSingleCompletedCheck(); @@ -1140,7 +1140,7 @@ public async Task LocalToAppendBlob_Skip_Exists() await testEventsRaised.AssertSingleSkippedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); Assert.IsTrue(await destinationClient.ExistsAsync()); // Verify Upload - That we skipped over and didn't reupload something new. @@ -1188,7 +1188,7 @@ public async Task LocalToAppendBlob_Failure_Exists() await testEventsRaised.AssertSingleFailedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(await destinationClient.ExistsAsync()); Assert.NotNull(testEventsRaised.FailedEvents.First().Exception, "Excepted failure: Overwrite failure was supposed to be raised during the test"); @@ -1420,7 +1420,7 @@ public async Task StartTransfer_AwaitCompletion() await testEventsRaised.AssertSingleCompletedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); } [RecordedTest] @@ -1450,7 +1450,7 @@ public async Task StartTransfer_AwaitCompletion_Failed() await testEventsRaised.AssertSingleFailedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); } @@ -1483,7 +1483,7 @@ public async Task StartTransfer_AwaitCompletion_Skipped() await testEventsRaised.AssertSingleSkippedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); } @@ -1507,7 +1507,7 @@ public async Task StartTransfer_EnsureCompleted() await testEventsRaised.AssertSingleCompletedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); } [RecordedTest] @@ -1537,7 +1537,7 @@ public async Task StartTransfer_EnsureCompleted_Failed() await testEventsRaised.AssertSingleFailedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasFailedItems); Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains("BlobAlreadyExists")); } @@ -1570,7 +1570,7 @@ public async Task StartTransfer_EnsureCompleted_Skipped() await testEventsRaised.AssertSingleSkippedCheck(); Assert.NotNull(transfer); Assert.IsTrue(transfer.HasCompleted); - Assert.AreEqual(DataTransferStatus.TransferState.Completed, transfer.TransferStatus.State); + Assert.AreEqual(DataTransferState.Completed, transfer.TransferStatus.State); Assert.AreEqual(true, transfer.TransferStatus.HasSkippedItems); } #endregion diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/TestEventsRaised.cs b/sdk/storage/Azure.Storage.DataMovement/tests/TestEventsRaised.cs index 796c910d2fdc5..6083811727068 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/TestEventsRaised.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/TestEventsRaised.cs @@ -24,13 +24,13 @@ namespace Azure.Storage.DataMovement.Tests /// internal class TestEventsRaised : IDisposable { - private static readonly DataTransferStatus InProgressStatus = new DataTransferStatus(DataTransferStatus.TransferState.InProgress, false, false); - private static readonly DataTransferStatus InProgressFailedStatus = new DataTransferStatus(DataTransferStatus.TransferState.InProgress, true, false); - private static readonly DataTransferStatus InProgressSkippedStatus = new DataTransferStatus(DataTransferStatus.TransferState.InProgress, false, true); - private static readonly DataTransferStatus StoppingFailedStatus = new DataTransferStatus(DataTransferStatus.TransferState.Stopping, true, false); - private static readonly DataTransferStatus SuccessfulCompletedStatus = new DataTransferStatus(DataTransferStatus.TransferState.Completed, false, false); - private static readonly DataTransferStatus SkippedCompletedStatus = new DataTransferStatus(DataTransferStatus.TransferState.Completed, false, true); - private static readonly DataTransferStatus FailedCompletedStatus = new DataTransferStatus(DataTransferStatus.TransferState.Completed, true, false); + private static readonly DataTransferStatus InProgressStatus = new DataTransferStatus(DataTransferState.InProgress, false, false); + private static readonly DataTransferStatus InProgressFailedStatus = new DataTransferStatus(DataTransferState.InProgress, true, false); + private static readonly DataTransferStatus InProgressSkippedStatus = new DataTransferStatus(DataTransferState.InProgress, false, true); + private static readonly DataTransferStatus StoppingFailedStatus = new DataTransferStatus(DataTransferState.Stopping, true, false); + private static readonly DataTransferStatus SuccessfulCompletedStatus = new DataTransferStatus(DataTransferState.Completed, false, false); + private static readonly DataTransferStatus SkippedCompletedStatus = new DataTransferStatus(DataTransferState.Completed, false, true); + private static readonly DataTransferStatus FailedCompletedStatus = new DataTransferStatus(DataTransferState.Completed, true, false); public List FailedEvents { get; internal set; } public List StatusEvents { get; internal set; } @@ -143,7 +143,7 @@ public void AssertUnexpectedFailureCheck() /// /// This asserts that the expected events occurred during a single transfer that is expected - /// to have a at the end without any skips + /// to have a at the end without any skips /// or failures. /// public async Task AssertSingleCompletedCheck() @@ -162,7 +162,7 @@ public async Task AssertSingleCompletedCheck() /// /// This asserts that the expected events occurred during a single transfer that is expected - /// to have a at the end without any + /// to have a at the end without any /// or failures. /// public async Task AssertSingleSkippedCheck() @@ -184,7 +184,7 @@ public async Task AssertSingleSkippedCheck() /// /// This asserts that the expected events occurred during a single transfer that is expected - /// to have a at the end without any skips. + /// to have a at the end without any skips. /// public async Task AssertSingleFailedCheck() { @@ -207,7 +207,7 @@ public async Task AssertSingleFailedCheck() /// /// This asserts that the expected events occurred during a container transfer that is expected - /// to have a at the end without any skips + /// to have a at the end without any skips /// or failures. /// /// @@ -229,7 +229,7 @@ public async Task AssertContainerCompletedCheck(int transferCount) /// /// This asserts that the expected events occurred during a container transfer that is expected - /// to have a at the end without any skips. + /// to have a at the end without any skips. /// Assuming was set. /// /// @@ -261,7 +261,7 @@ public async Task AssertContainerCompletedWithFailedCheck(int expectedFailureCou /// /// This asserts that the expected events occurred during a container transfer that is expected - /// to have a at the end without any skips. + /// to have a at the end without any skips. /// Assuming was set. /// /// @@ -292,7 +292,7 @@ public async Task AssertContainerCompletedWithFailedCheckContinue(int expectedFa /// /// This asserts that the expected events occurred during a container transfer that is expected - /// to have a at the end without any failures. + /// to have a at the end without any failures. /// /// /// Expected amount of skipped single transfers to occur within the container transfers. @@ -320,7 +320,7 @@ public async Task AssertPausedCheck() AssertTransferStatusCollection( new DataTransferStatus[] { InProgressStatus, - new DataTransferStatus(DataTransferStatus.TransferState.Paused, false, false) }, + new DataTransferStatus(DataTransferState.Paused, false, false) }, StatusEvents.Select(e => e.TransferStatus).ToArray()); } From 00b194ac4921fe314530dfb06ae8d718021d13a7 Mon Sep 17 00:00:00 2001 From: Amanda Nguyen Date: Fri, 8 Sep 2023 15:10:00 -0700 Subject: [PATCH 12/13] Export API --- .../api/Azure.Storage.DataMovement.net6.0.cs | 24 +++++++++---------- ...ure.Storage.DataMovement.netstandard2.0.cs | 24 +++++++++---------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/sdk/storage/Azure.Storage.DataMovement/api/Azure.Storage.DataMovement.net6.0.cs b/sdk/storage/Azure.Storage.DataMovement/api/Azure.Storage.DataMovement.net6.0.cs index 9d1c9471ee69c..095b159d7e057 100644 --- a/sdk/storage/Azure.Storage.DataMovement/api/Azure.Storage.DataMovement.net6.0.cs +++ b/sdk/storage/Azure.Storage.DataMovement/api/Azure.Storage.DataMovement.net6.0.cs @@ -70,25 +70,25 @@ protected internal DataTransferProperties() { } public virtual string SourceTypeId { get { throw null; } } public virtual string TransferId { get { throw null; } } } + public enum DataTransferState + { + None = 0, + Queued = 1, + InProgress = 2, + Pausing = 3, + Stopping = 4, + Paused = 5, + Completed = 6, + } public partial class DataTransferStatus : System.IEquatable { protected internal DataTransferStatus() { } - protected internal DataTransferStatus(Azure.Storage.DataMovement.DataTransferStatus.TransferState state, bool hasFailureItems, bool hasSkippedItems) { } + protected internal DataTransferStatus(Azure.Storage.DataMovement.DataTransferState state, bool hasFailureItems, bool hasSkippedItems) { } public bool HasCompletedSuccessfully { get { throw null; } } public bool HasFailedItems { get { throw null; } } public bool HasSkippedItems { get { throw null; } } - public Azure.Storage.DataMovement.DataTransferStatus.TransferState State { get { throw null; } } + public Azure.Storage.DataMovement.DataTransferState State { get { throw null; } } public bool Equals(Azure.Storage.DataMovement.DataTransferStatus other) { throw null; } - public enum TransferState - { - None = 0, - Queued = 1, - InProgress = 2, - Pausing = 3, - Stopping = 4, - Paused = 5, - Completed = 6, - } } public partial class LocalDirectoryStorageResourceContainer : Azure.Storage.DataMovement.StorageResourceContainer { diff --git a/sdk/storage/Azure.Storage.DataMovement/api/Azure.Storage.DataMovement.netstandard2.0.cs b/sdk/storage/Azure.Storage.DataMovement/api/Azure.Storage.DataMovement.netstandard2.0.cs index 9d1c9471ee69c..095b159d7e057 100644 --- a/sdk/storage/Azure.Storage.DataMovement/api/Azure.Storage.DataMovement.netstandard2.0.cs +++ b/sdk/storage/Azure.Storage.DataMovement/api/Azure.Storage.DataMovement.netstandard2.0.cs @@ -70,25 +70,25 @@ protected internal DataTransferProperties() { } public virtual string SourceTypeId { get { throw null; } } public virtual string TransferId { get { throw null; } } } + public enum DataTransferState + { + None = 0, + Queued = 1, + InProgress = 2, + Pausing = 3, + Stopping = 4, + Paused = 5, + Completed = 6, + } public partial class DataTransferStatus : System.IEquatable { protected internal DataTransferStatus() { } - protected internal DataTransferStatus(Azure.Storage.DataMovement.DataTransferStatus.TransferState state, bool hasFailureItems, bool hasSkippedItems) { } + protected internal DataTransferStatus(Azure.Storage.DataMovement.DataTransferState state, bool hasFailureItems, bool hasSkippedItems) { } public bool HasCompletedSuccessfully { get { throw null; } } public bool HasFailedItems { get { throw null; } } public bool HasSkippedItems { get { throw null; } } - public Azure.Storage.DataMovement.DataTransferStatus.TransferState State { get { throw null; } } + public Azure.Storage.DataMovement.DataTransferState State { get { throw null; } } public bool Equals(Azure.Storage.DataMovement.DataTransferStatus other) { throw null; } - public enum TransferState - { - None = 0, - Queued = 1, - InProgress = 2, - Pausing = 3, - Stopping = 4, - Paused = 5, - Completed = 6, - } } public partial class LocalDirectoryStorageResourceContainer : Azure.Storage.DataMovement.StorageResourceContainer { From 69db6d5102fbef5f4f5f5eb7be80b1f682806328 Mon Sep 17 00:00:00 2001 From: Amanda Nguyen Date: Wed, 13 Sep 2023 16:31:05 -0700 Subject: [PATCH 13/13] PR Comments --- .../src/DataTransferState.cs | 4 +- .../src/DataTransferStatus.cs | 55 +++++++------------ .../src/JobPartInternal.cs | 3 +- 3 files changed, 22 insertions(+), 40 deletions(-) diff --git a/sdk/storage/Azure.Storage.DataMovement/src/DataTransferState.cs b/sdk/storage/Azure.Storage.DataMovement/src/DataTransferState.cs index 1624dbf093ff3..fb68ba45ce3e9 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/DataTransferState.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/DataTransferState.cs @@ -26,7 +26,7 @@ public enum DataTransferState InProgress = 2, /// - /// The transfer has started and is in the process of being paused. + /// The transfer is in progress and is in the process of being paused. /// /// Transfer can be stopped if /// or is called. @@ -34,7 +34,7 @@ public enum DataTransferState Pausing = 3, /// - /// The transfer has started and is in the process of being stopped. + /// The transfer is in progress and is in the process of being stopped. /// /// Transfer can be stopped if is /// enabled in the . diff --git a/sdk/storage/Azure.Storage.DataMovement/src/DataTransferStatus.cs b/sdk/storage/Azure.Storage.DataMovement/src/DataTransferStatus.cs index e5805dde041f8..fde3d6e26603f 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/DataTransferStatus.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/DataTransferStatus.cs @@ -12,12 +12,14 @@ namespace Azure.Storage.DataMovement /// public class DataTransferStatus : IEquatable { - private object _stateLock = new object(); + private int _hasFailedItemValue; + private int _hasSkippedItemValue; + private int _stateValue; /// /// Defines the state of the transfer. /// - public DataTransferState State { get; internal set; } + public DataTransferState State => (DataTransferState)_stateValue; /// /// Represents if the transfer has completed successfully without any failure or skipped items. @@ -33,7 +35,7 @@ public class DataTransferStatus : IEquatable /// If set to `true`, the transfer has at least one failure item. /// If set to `false`, the transfer currently has no failures. /// - public bool HasFailedItems { get; internal set; } + public bool HasFailedItems => _hasFailedItemValue != 0; /// /// Represents if transfer has any skipped items. @@ -44,16 +46,16 @@ public class DataTransferStatus : IEquatable /// It's possible to never have any items skipped if /// is not enabled in the . /// - public bool HasSkippedItems { get; internal set; } + public bool HasSkippedItems => _hasSkippedItemValue != 0; /// /// Constructor to set the initial state to with no failures or skipped items. /// protected internal DataTransferStatus() { - State = DataTransferState.Queued; - HasFailedItems = false; - HasSkippedItems = false; + _stateValue = (int)DataTransferState.Queued; + _hasFailedItemValue = 0; // Initialized to false + _hasSkippedItemValue = 0; // Initialized to false } /// @@ -61,9 +63,9 @@ protected internal DataTransferStatus() /// protected internal DataTransferStatus(DataTransferState state, bool hasFailureItems, bool hasSkippedItems) { - State = state; - HasFailedItems = hasFailureItems; - HasSkippedItems = hasSkippedItems; + _stateValue = (int)state; + _hasFailedItemValue = hasFailureItems ? 1 : 0; + _hasSkippedItemValue = hasSkippedItems ? 1 : 0; } internal bool IsCompletedWithFailedItems => State.Equals(DataTransferState.Completed) && HasFailedItems; @@ -77,12 +79,7 @@ protected internal DataTransferStatus(DataTransferState state, bool hasFailureIt /// True if was updated. False otherwise. internal bool TrySetFailedItem() { - if (!HasFailedItems) - { - HasFailedItems = true; - return true; - } - return false; + return Interlocked.Exchange(ref _hasFailedItemValue, 1) != 1; } /// @@ -93,12 +90,7 @@ internal bool TrySetFailedItem() /// /// True if was updated. False otherwise. internal bool TrySetSkippedItem() { - if (!HasSkippedItems) - { - HasSkippedItems = true; - return true; - } - return false; + return Interlocked.Exchange(ref _hasSkippedItemValue, 1) != 1; } /// @@ -110,16 +102,7 @@ internal bool TrySetSkippedItem() /// True if was updated. False otherwise. internal bool TrySetTransferStateChange(DataTransferState state) { - lock (_stateLock) - { - if (state != DataTransferState.None && - State != state) - { - State = state; - return true; - } - } - return false; + return Interlocked.Exchange(ref _stateValue, (int)state) != (int)state; } /// @@ -137,11 +120,11 @@ public bool Equals(DataTransferStatus other) /// /// A deep copy of the respective . internal DataTransferStatus DeepCopy() - => new DataTransferStatus + => new() { - State = State, - HasFailedItems = HasFailedItems, - HasSkippedItems =HasSkippedItems, + _stateValue = _stateValue, + _hasFailedItemValue = _hasFailedItemValue, + _hasSkippedItemValue = _hasSkippedItemValue, }; } } diff --git a/sdk/storage/Azure.Storage.DataMovement/src/JobPartInternal.cs b/sdk/storage/Azure.Storage.DataMovement/src/JobPartInternal.cs index a3714e8e55e50..d51e7d7a438d5 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/JobPartInternal.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/JobPartInternal.cs @@ -299,8 +299,7 @@ internal async Task OnTransferStateChangedAsync(DataTransferState transferState) { _progressTracker.IncrementInProgressFiles(); } - - if (JobPartStatus.HasCompletedSuccessfully) + else if (JobPartStatus.HasCompletedSuccessfully) { _progressTracker.IncrementCompletedFiles(); await InvokeSingleCompletedArg().ConfigureAwait(false);