From 2109e53ac55fdd3b22301ccfd4016001de6ee2c8 Mon Sep 17 00:00:00 2001 From: Jocelyn Schreppler Date: Tue, 18 Jul 2023 11:24:02 -0400 Subject: [PATCH 1/2] add link DataTransfer -> TransferManager --- .../src/Shared/DataTransfer.cs | 15 ++++++++----- .../src/Shared/TransferManager.cs | 3 ++- .../tests/DataTransferTests.cs | 21 ++++++++++++++++++- .../tests/GetTransfersTests.cs | 1 + 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransfer.cs b/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransfer.cs index f4d855bd9019d..8b67014e2a54f 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransfer.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/Shared/DataTransfer.cs @@ -1,10 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Text; using System.Threading; using System.Threading.Tasks; using Azure.Core; @@ -13,7 +9,7 @@ namespace Azure.Storage.DataMovement { /// - /// Holds transfer information + /// Holds transfer information. /// public class DataTransfer { @@ -32,6 +28,11 @@ public class DataTransfer /// public string Id => _state.Id; + /// + /// The responsible for this transfer. + /// + public TransferManager TransferManager { get; } + /// /// Defines the current state of the transfer. /// @@ -48,13 +49,17 @@ internal DataTransfer() /// Constructing a DataTransfer object. /// /// The transfer ID of the transfer object. + /// Reference to the transfer manager running this transfer. /// The Transfer Status of the Transfer. See . internal DataTransfer( string id, + TransferManager transferManager, StorageTransferStatus status = StorageTransferStatus.Queued) { Argument.AssertNotNullOrEmpty(id, nameof(id)); + Argument.AssertNotNull(transferManager, nameof(transferManager)); _state = new DataTransferState(id, status); + TransferManager = transferManager; } /// diff --git a/sdk/storage/Azure.Storage.DataMovement/src/Shared/TransferManager.cs b/sdk/storage/Azure.Storage.DataMovement/src/Shared/TransferManager.cs index 060aa55c94df9..14905316ac21b 100644 --- a/sdk/storage/Azure.Storage.DataMovement/src/Shared/TransferManager.cs +++ b/sdk/storage/Azure.Storage.DataMovement/src/Shared/TransferManager.cs @@ -460,7 +460,7 @@ private async Task BuildAndAddTransferJobAsync( bool resumeJob, CancellationToken cancellationToken) { - DataTransfer dataTransfer = new DataTransfer(id: transferId); + DataTransfer dataTransfer = new DataTransfer(id: transferId, transferManager: this); _dataTransfers.Add(dataTransfer.Id, dataTransfer); TransferJobInternal transferJobInternal; @@ -805,6 +805,7 @@ private async Task SetDataTransfers() _dataTransfers.Add(transferId, new DataTransfer( id: transferId, + transferManager: this, status: header.AtomicJobStatus)); } } diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/DataTransferTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/DataTransferTests.cs index 5f111c8d058b0..81d5e9156f030 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/DataTransferTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/DataTransferTests.cs @@ -18,12 +18,14 @@ public void Ctor_Default() { // Arrange string transferId = GetNewTransferId(); + TransferManager transferManager = new(); // Act - DataTransfer transfer = new DataTransfer(id: transferId); + DataTransfer transfer = new DataTransfer(id: transferId, transferManager: transferManager); // Assert Assert.AreEqual(transferId, transfer.Id); + Assert.AreEqual(transferManager, transfer.TransferManager); Assert.IsFalse(transfer.HasCompleted); } @@ -38,14 +40,17 @@ public void HasCompleted_False(StorageTransferStatus status) { // Arrange string transferId = GetNewTransferId(); + TransferManager transferManager = new(); // Act DataTransfer transfer = new DataTransfer( id: transferId, + transferManager: transferManager, status: status); // Assert Assert.AreEqual(transferId, transfer.Id); + Assert.AreEqual(transferManager, transfer.TransferManager); Assert.IsFalse(transfer.HasCompleted); } @@ -57,14 +62,17 @@ public void HasCompleted_True(StorageTransferStatus status) { // Arrange string transferId = GetNewTransferId(); + TransferManager transferManager = new(); // Act DataTransfer transfer = new DataTransfer( id: transferId, + transferManager: transferManager, status: status); // Assert Assert.AreEqual(transferId, transfer.Id); + Assert.AreEqual(transferManager, transfer.TransferManager); Assert.IsTrue(transfer.HasCompleted); } @@ -73,9 +81,11 @@ public void EnsureCompleted() { // Arrange string transferId = GetNewTransferId(); + TransferManager transferManager = new(); DataTransfer transfer = new DataTransfer( id: transferId, + transferManager: transferManager, status: StorageTransferStatus.Completed); // Act @@ -83,6 +93,7 @@ public void EnsureCompleted() // Assert Assert.AreEqual(transferId, transfer.Id); + Assert.AreEqual(transferManager, transfer.TransferManager); Assert.IsTrue(transfer.HasCompleted); } @@ -94,6 +105,7 @@ public void EnsureCompleted_CancellationToken() DataTransfer transfer = new DataTransfer( id: transferId, + transferManager: new(), status: StorageTransferStatus.Queued); CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(1)); @@ -108,9 +120,11 @@ public async Task AwaitCompletion() { // Arrange string transferId = GetNewTransferId(); + TransferManager transferManager = new(); DataTransfer transfer = new DataTransfer( id: transferId, + transferManager: transferManager, status: StorageTransferStatus.Completed); // Act @@ -118,6 +132,7 @@ public async Task AwaitCompletion() // Assert Assert.AreEqual(transferId, transfer.Id); + Assert.AreEqual(transferManager, transfer.TransferManager); Assert.IsTrue(transfer.HasCompleted); } @@ -129,6 +144,7 @@ public void AwaitCompletion_CancellationToken() DataTransfer transfer = new DataTransfer( id: transferId, + transferManager: new(), status: StorageTransferStatus.Queued); CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(1)); @@ -145,6 +161,7 @@ public async Task TryPauseAsync() DataTransfer transfer = new DataTransfer( id: transferId, + transferManager: new(), status: StorageTransferStatus.InProgress); // Act @@ -176,6 +193,7 @@ public async Task TryPauseAsync_AlreadyPaused(StorageTransferStatus status) DataTransfer transfer = new DataTransfer( id: transferId, + transferManager: new(), status: status); Assert.AreEqual(status, transfer.TransferStatus); @@ -191,6 +209,7 @@ public async Task TryPauseAsync_CancellationToken() DataTransfer transfer = new DataTransfer( id: transferId, + transferManager: new(), status: StorageTransferStatus.InProgress); CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(1)); diff --git a/sdk/storage/Azure.Storage.DataMovement/tests/GetTransfersTests.cs b/sdk/storage/Azure.Storage.DataMovement/tests/GetTransfersTests.cs index d08dd8e25229a..ecb614934a040 100644 --- a/sdk/storage/Azure.Storage.DataMovement/tests/GetTransfersTests.cs +++ b/sdk/storage/Azure.Storage.DataMovement/tests/GetTransfersTests.cs @@ -43,6 +43,7 @@ private DataTransfer GetNewDataTransfer( { return new DataTransfer( id: Guid.NewGuid().ToString(), + transferManager: new(), status: status); } From 7a0a3fcc9c05219884b86a7fc21234af4268f6d7 Mon Sep 17 00:00:00 2001 From: Jocelyn Schreppler Date: Tue, 18 Jul 2023 11:25:42 -0400 Subject: [PATCH 2/2] exportapi --- .../api/Azure.Storage.DataMovement.net6.0.cs | 1 + .../api/Azure.Storage.DataMovement.netstandard2.0.cs | 1 + 2 files changed, 2 insertions(+) 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 a2fd3a8d7dac3..32db900941c43 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 @@ -5,6 +5,7 @@ public partial class DataTransfer internal DataTransfer() { } public bool HasCompleted { get { throw null; } } public string Id { get { throw null; } } + public Azure.Storage.DataMovement.TransferManager TransferManager { get { throw null; } } public Azure.Storage.DataMovement.StorageTransferStatus TransferStatus { get { throw null; } } public System.Threading.Tasks.Task AwaitCompletion(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public void EnsureCompleted(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { } 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 a2fd3a8d7dac3..32db900941c43 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 @@ -5,6 +5,7 @@ public partial class DataTransfer internal DataTransfer() { } public bool HasCompleted { get { throw null; } } public string Id { get { throw null; } } + public Azure.Storage.DataMovement.TransferManager TransferManager { get { throw null; } } public Azure.Storage.DataMovement.StorageTransferStatus TransferStatus { get { throw null; } } public System.Threading.Tasks.Task AwaitCompletion(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public void EnsureCompleted(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { }