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

Fix BlobWriteStream: Commit block list on each flush #23

Merged
merged 7 commits into from
Oct 11, 2024
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 @@ -146,9 +146,17 @@ private async Task FlushUnsafeAsync(CancellationToken cancellationToken)

_blocks.Add(blockId);

var commitResult = await blobClient.CommitBlockListAsync(_blocks, options: _commitOptions, cancellationToken);

var newETag = commitResult.Value.ETag;

_commitOptions.Conditions.IfMatch = newETag;
_stageOptions.Conditions.IfMatch = newETag;

_bufferPosition = 0;
}


foreach (var interceptor in _interceptors)
{
await interceptor.FlushAsync();
Expand Down
37 changes: 37 additions & 0 deletions tests/Tests/Storage/Blobs/BlobClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using Azure.Storage.Blobs.Models;
using Azure.Storage.Blobs.Specialized;

using Spotflow.InMemory.Azure.Storage.FluentAssertions;

using Tests.Utils;

namespace Tests.Storage.Blobs;
Expand Down Expand Up @@ -326,6 +328,41 @@ public void OpenWrite_For_Existing_Blob_With_Conditions_Should_Fail(BlobClientTy

}

[TestMethod]
[TestCategory(TestCategory.AzureInfra)]
[DataRow(BlobClientType.Generic)]
[DataRow(BlobClientType.Block)]
public void OpenWrite_Stream_Should_Create_Block_And_Commit_On_Each_Flush(BlobClientType clientType)
{
var containerClient = ImplementationProvider.GetBlobContainerClient();

containerClient.CreateIfNotExists();

var blobName = Guid.NewGuid().ToString();

var blobClient = containerClient.GetBlobBaseClient(blobName, clientType);

using (var stream = OpenWrite(blobClient, true))
{
blobClient.Should().HaveNoCommittedBlocks();

stream.WriteByte(1);
stream.Flush();

blobClient.Should().HaveCommittedBlocks(1);

stream.WriteByte(2);
stream.Flush();

blobClient.Should().HaveCommittedBlocks(2);

stream.WriteByte(2);

}

blobClient.Should().HaveCommittedBlocks(3);
}


[TestMethod]
[TestCategory(TestCategory.AzureInfra)]
Expand Down