Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataMovement DataTransfer links back to owning TransferManager #37695

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) { }
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,7 +9,7 @@
namespace Azure.Storage.DataMovement
{
/// <summary>
/// Holds transfer information
/// Holds transfer information.
/// </summary>
public class DataTransfer
{
Expand All @@ -32,6 +28,11 @@ public class DataTransfer
/// </summary>
public string Id => _state.Id;

/// <summary>
/// The <see cref="TransferManager"/> responsible for this transfer.
/// </summary>
public TransferManager TransferManager { get; }

/// <summary>
/// Defines the current state of the transfer.
/// </summary>
Expand All @@ -48,13 +49,17 @@ internal DataTransfer()
/// Constructing a DataTransfer object.
/// </summary>
/// <param name="id">The transfer ID of the transfer object.</param>
/// <param name="transferManager">Reference to the transfer manager running this transfer.</param>
/// <param name="status">The Transfer Status of the Transfer. See <see cref="StorageTransferStatus"/>.</param>
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;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ private async Task<DataTransfer> 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;
Expand Down Expand Up @@ -805,6 +805,7 @@ private async Task SetDataTransfers()

_dataTransfers.Add(transferId, new DataTransfer(
id: transferId,
transferManager: this,
status: header.AtomicJobStatus));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -73,16 +81,19 @@ public void EnsureCompleted()
{
// Arrange
string transferId = GetNewTransferId();
TransferManager transferManager = new();

DataTransfer transfer = new DataTransfer(
id: transferId,
transferManager: transferManager,
status: StorageTransferStatus.Completed);

// Act
transfer.EnsureCompleted();

// Assert
Assert.AreEqual(transferId, transfer.Id);
Assert.AreEqual(transferManager, transfer.TransferManager);
Assert.IsTrue(transfer.HasCompleted);
}

Expand All @@ -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));

Expand All @@ -108,16 +120,19 @@ public async Task AwaitCompletion()
{
// Arrange
string transferId = GetNewTransferId();
TransferManager transferManager = new();

DataTransfer transfer = new DataTransfer(
id: transferId,
transferManager: transferManager,
status: StorageTransferStatus.Completed);

// Act
await transfer.AwaitCompletion();

// Assert
Assert.AreEqual(transferId, transfer.Id);
Assert.AreEqual(transferManager, transfer.TransferManager);
Assert.IsTrue(transfer.HasCompleted);
}

Expand All @@ -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));

Expand All @@ -145,6 +161,7 @@ public async Task TryPauseAsync()

DataTransfer transfer = new DataTransfer(
id: transferId,
transferManager: new(),
status: StorageTransferStatus.InProgress);

// Act
Expand Down Expand Up @@ -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);
Expand All @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ private DataTransfer GetNewDataTransfer(
{
return new DataTransfer(
id: Guid.NewGuid().ToString(),
transferManager: new(),
status: status);
}

Expand Down