Skip to content

Commit b5c7a1b

Browse files
authored
[Storage] Enable some of large payload tests. (Azure#19139)
* handle some tests. * wip
1 parent 2812f05 commit b5c7a1b

File tree

4 files changed

+67
-37
lines changed

4 files changed

+67
-37
lines changed

sdk/storage/Azure.Storage.Blobs/tests/LargeBlobTests.cs

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

44
using System;
5+
using System.IO;
56
using System.Linq;
67
using System.Threading.Tasks;
78
using Azure.Storage.Blobs.Models;
@@ -52,5 +53,69 @@ public async Task GetBlockListAsync_LongBlock()
5253
Assert.AreEqual(bigBlockSize, response.Value.CommittedBlocks.First().SizeLong);
5354
Assert.Throws<OverflowException>(() => _ = response.Value.CommittedBlocks.First().Size); // if no overflow then we didn't actually test handling of long lengths
5455
}
56+
57+
[Test]
58+
public async Task CanHandleLongBlockBufferedUpload()
59+
{
60+
// Arrange
61+
const long blockSize = int.MaxValue + 1024L;
62+
const int numBlocks = 2;
63+
Stream content = new Storage.Tests.Shared.PredictableStream(numBlocks * blockSize, revealsLength: false); // lack of Stream.Length forces buffered upload
64+
var blobContainerClient = blobServiceClient.GetBlobContainerClient(Guid.NewGuid().ToString());
65+
await blobContainerClient.CreateIfNotExistsAsync();
66+
var blobName = Guid.NewGuid().ToString();
67+
var blobClient = blobContainerClient.GetBlobClient(blobName);
68+
69+
// Act
70+
await blobClient.UploadAsync(content, new BlobUploadOptions()
71+
{
72+
TransferOptions = new StorageTransferOptions
73+
{
74+
InitialTransferSize = 1,
75+
MaximumTransferSize = blockSize,
76+
MaximumConcurrency = 1,
77+
}
78+
});
79+
BlockList blockList = await blobContainerClient.GetBlockBlobClient(blobName).GetBlockListAsync();
80+
81+
// Assert
82+
Assert.AreEqual(numBlocks * blockSize, blockList.BlobContentLength);
83+
Assert.AreEqual(numBlocks, blockList.CommittedBlocks.Count());
84+
foreach (var block in blockList.CommittedBlocks)
85+
{
86+
Assert.AreEqual(blockSize, block.SizeLong);
87+
}
88+
}
89+
90+
[Test]
91+
public async Task CanHandleLongBlockBufferedUploadInParallel()
92+
{
93+
// Arrange
94+
const long firstBlockSize = int.MaxValue + 1024L;
95+
const long secondBlockSize = 1024L;
96+
Stream content = new Storage.Tests.Shared.PredictableStream(firstBlockSize + secondBlockSize, revealsLength: false); // lack of Stream.Length forces buffered upload
97+
var blobContainerClient = blobServiceClient.GetBlobContainerClient(Guid.NewGuid().ToString());
98+
await blobContainerClient.CreateIfNotExistsAsync();
99+
var blobName = Guid.NewGuid().ToString();
100+
var blobClient = blobContainerClient.GetBlobClient(blobName);
101+
102+
// Act
103+
await blobClient.UploadAsync(content, new BlobUploadOptions()
104+
{
105+
TransferOptions = new StorageTransferOptions
106+
{
107+
InitialTransferSize = 1,
108+
MaximumTransferSize = firstBlockSize,
109+
MaximumConcurrency = 2,
110+
}
111+
});
112+
BlockList blockList = await blobContainerClient.GetBlockBlobClient(blobName).GetBlockListAsync();
113+
114+
// Assert
115+
Assert.AreEqual(firstBlockSize + secondBlockSize, blockList.BlobContentLength);
116+
Assert.AreEqual(2, blockList.CommittedBlocks.Count());
117+
Assert.AreEqual(firstBlockSize, blockList.CommittedBlocks.ElementAt(0).SizeLong);
118+
Assert.AreEqual(secondBlockSize, blockList.CommittedBlocks.ElementAt(1).SizeLong);
119+
}
55120
}
56121
}

sdk/storage/Azure.Storage.Blobs/tests/PartitionedUploaderTests.cs

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -248,40 +248,6 @@ public async Task AsyncUploadsAsSingleBlockIfUnderLimit()
248248
Assert.AreEqual(0, testPool.TotalRents);
249249
}
250250

251-
[Test]
252-
[Explicit]
253-
[Ignore("https://github.com/Azure/azure-sdk-for-net/issues/12312")]
254-
public async Task CanHandleLongBlockBufferedUpload()
255-
{
256-
const long blockSize = int.MaxValue + 1024L;
257-
const int numBlocks = 2;
258-
Stream content = new Storage.Tests.Shared.PredictableStream(numBlocks * blockSize, revealsLength: false); // lack of Stream.Length forces buffered upload
259-
TrackingArrayPool testPool = new TrackingArrayPool();
260-
StagingSink sink = new StagingSink(false); // sink can't hold long blocks, and we don't need to look at their data anyway.
261-
262-
Mock<BlockBlobClient> clientMock = new Mock<BlockBlobClient>(MockBehavior.Strict, new Uri("http://mock"), new BlobClientOptions());
263-
clientMock.SetupGet(c => c.ClientConfiguration.ClientDiagnostics).CallBase();
264-
SetupInternalStaging(clientMock, sink);
265-
266-
var uploader = new PartitionedUploader<BlobUploadOptions, BlobContentInfo>(
267-
BlockBlobClient.GetPartitionedUploaderBehaviors(clientMock.Object),
268-
new StorageTransferOptions
269-
{
270-
InitialTransferSize = 1,
271-
MaximumTransferSize = blockSize,
272-
},
273-
arrayPool: testPool);
274-
Response<BlobContentInfo> info = await InvokeUploadAsync(uploader, content);
275-
276-
Assert.AreEqual(s_response, info);
277-
Assert.AreEqual(numBlocks, sink.Staged.Count);
278-
Assert.AreEqual(numBlocks, sink.Blocks.Length);
279-
foreach (var block in sink.Staged.Values)
280-
{
281-
Assert.AreEqual(blockSize, block.StreamLength);
282-
}
283-
}
284-
285251
[Test]
286252
public async Task NoBufferWhenUploadInSequenceOnSeekableStream()
287253
{

sdk/storage/Azure.Storage.Common/tests/PooledMemoryStreamTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,9 @@ public async Task ReadStream(int dataSize, int bufferPartitionSize)
5656
}
5757

5858
[Test]
59-
[Ignore("https://github.com/Azure/azure-sdk-for-net/issues/12312")]
6059
public void StreamCanHoldLongData()
6160
{
62-
const long dataSize = 4000L * Constants.MB;
61+
const long dataSize = (long)int.MaxValue + Constants.MB;
6362
const int bufferPartitionSize = 512 * Constants.MB;
6463
PredictableStream originalStream = new PredictableStream();
6564
PooledMemoryStream arrayPoolStream = PooledMemoryStream.BufferStreamPartitionInternal(originalStream, dataSize, dataSize, 0, _pool, bufferPartitionSize, false, default).EnsureCompleted();

sdk/storage/Azure.Storage.Common/tests/Shared/PredictableStream.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ internal class PredictableStream : Stream
1414
{
1515
public override bool CanRead => true;
1616

17-
public override bool CanSeek => true;
17+
public override bool CanSeek => _revealsLength;
1818

1919
public override bool CanWrite => false;
2020

0 commit comments

Comments
 (0)