Skip to content

Commit c76b028

Browse files
Jumbo blob tests (Azure#19586)
* Adding tests for jumbo blob * Updating BlockSize from int to in64 in UploadStreamOptions
1 parent 1064f39 commit c76b028

File tree

6 files changed

+102
-6
lines changed

6 files changed

+102
-6
lines changed

sdk/storage/azblob/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
### Breaking Changes
1313

1414
* Corrected the name for `saoid` and `suoid` SAS parameters in `BlobSignatureValues` struct as per [this](https://learn.microsoft.com/rest/api/storageservices/create-user-delegation-sas#construct-a-user-delegation-sas)
15+
* Updated type of `BlockSize` from int to int64 in `UploadStreamOptions`
1516

1617
### Bugs Fixed
1718

sdk/storage/azblob/blockblob/client_test.go

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3433,7 +3433,7 @@ func (s *BlockBlobUnrecordedTestsSuite) TestUploadStreamToBlobProperties() {
34333433
// Perform UploadStream
34343434
_, err = bbClient.UploadStream(context.Background(), blobContentReader,
34353435
&blockblob.UploadStreamOptions{
3436-
BlockSize: bufferSize,
3436+
BlockSize: int64(bufferSize),
34373437
Concurrency: maxBuffers,
34383438
Metadata: testcommon.BasicMetadata,
34393439
Tags: testcommon.BasicBlobTagsMap,
@@ -3748,3 +3748,98 @@ func (s *BlockBlobUnrecordedTestsSuite) TestBlockBlobSetExpiryToPast() {
37483748
_require.Nil(err)
37493749
_require.Nil(resp.ExpiresOn)
37503750
}
3751+
3752+
func (s *BlockBlobUnrecordedTestsSuite) TestLargeBlockBlobStage() {
3753+
_require := require.New(s.T())
3754+
testName := s.T().Name()
3755+
svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil)
3756+
_require.NoError(err)
3757+
3758+
containerName := testcommon.GenerateContainerName(testName)
3759+
containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient)
3760+
defer testcommon.DeleteContainer(context.Background(), _require, containerClient)
3761+
3762+
bbClient := testcommon.GetBlockBlobClient(testcommon.GenerateBlobName(testName), containerClient)
3763+
3764+
var largeBlockSize int64 = blockblob.MaxStageBlockBytes
3765+
content := make([]byte, largeBlockSize)
3766+
body := bytes.NewReader(content)
3767+
rsc := streaming.NopCloser(body)
3768+
3769+
blockID := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%6d", 0)))
3770+
_, err = bbClient.StageBlock(context.Background(), blockID, rsc, nil)
3771+
_require.Nil(err)
3772+
3773+
_, err = bbClient.CommitBlockList(context.Background(), []string{blockID}, nil)
3774+
_require.Nil(err)
3775+
3776+
resp, err := bbClient.GetBlockList(context.Background(), blockblob.BlockListTypeAll, nil)
3777+
_require.Nil(err)
3778+
_require.Len(resp.BlockList.CommittedBlocks, 1)
3779+
committed := resp.BlockList.CommittedBlocks
3780+
_require.Equal(*(committed[0].Name), blockID)
3781+
_require.Equal(*(committed[0].Size), largeBlockSize)
3782+
_require.Nil(resp.BlockList.UncommittedBlocks)
3783+
}
3784+
3785+
func (s *BlockBlobUnrecordedTestsSuite) TestLargeBlockStreamUploadWithDifferentBlockSize() {
3786+
_require := require.New(s.T())
3787+
testName := s.T().Name()
3788+
svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil)
3789+
_require.NoError(err)
3790+
3791+
containerName := testcommon.GenerateContainerName(testName)
3792+
containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient)
3793+
defer testcommon.DeleteContainer(context.Background(), _require, containerClient)
3794+
3795+
bbClient := testcommon.GetBlockBlobClient(testcommon.GenerateBlobName(testName), containerClient)
3796+
3797+
var firstBlockSize, secondBlockSize int64 = 2500 * 1024 * 1024, 10 * 1024 * 1024
3798+
content := make([]byte, firstBlockSize+secondBlockSize)
3799+
body := bytes.NewReader(content)
3800+
rsc := streaming.NopCloser(body)
3801+
3802+
_, err = bbClient.UploadStream(context.Background(), rsc, &blockblob.UploadStreamOptions{
3803+
BlockSize: firstBlockSize,
3804+
Concurrency: 2,
3805+
})
3806+
_require.Nil(err)
3807+
3808+
resp, err := bbClient.GetBlockList(context.Background(), blockblob.BlockListTypeAll, nil)
3809+
_require.Nil(err)
3810+
_require.Len(resp.BlockList.CommittedBlocks, 2)
3811+
_require.Equal(*resp.BlobContentLength, firstBlockSize+secondBlockSize)
3812+
committed := resp.BlockList.CommittedBlocks
3813+
_require.Equal(*(committed[0].Size), firstBlockSize)
3814+
_require.Equal(*(committed[1].Size), secondBlockSize)
3815+
}
3816+
3817+
func (s *BlockBlobUnrecordedTestsSuite) TestLargeBlockBufferedUploadInParallel() {
3818+
_require := require.New(s.T())
3819+
testName := s.T().Name()
3820+
svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil)
3821+
_require.NoError(err)
3822+
3823+
containerName := testcommon.GenerateContainerName(testName)
3824+
containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient)
3825+
defer testcommon.DeleteContainer(context.Background(), _require, containerClient)
3826+
3827+
bbClient := testcommon.GetBlockBlobClient(testcommon.GenerateBlobName(testName), containerClient)
3828+
3829+
var largeBlockSize, numberOfBlocks int64 = 2500 * 1024 * 1024, 2
3830+
content := make([]byte, numberOfBlocks*largeBlockSize)
3831+
3832+
_, err = bbClient.UploadBuffer(context.Background(), content, &blockblob.UploadBufferOptions{
3833+
BlockSize: largeBlockSize,
3834+
Concurrency: 2,
3835+
})
3836+
_require.Nil(err)
3837+
3838+
resp, err := bbClient.GetBlockList(context.Background(), blockblob.BlockListTypeAll, nil)
3839+
_require.Nil(err)
3840+
_require.Len(resp.BlockList.CommittedBlocks, 2)
3841+
_require.Equal(*resp.BlobContentLength, numberOfBlocks*largeBlockSize)
3842+
committed := resp.BlockList.CommittedBlocks
3843+
_require.Equal(*(committed[0].Size), largeBlockSize)
3844+
_require.Equal(*(committed[1].Size), largeBlockSize)
3845+
}

sdk/storage/azblob/blockblob/models.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ type UploadStreamOptions struct {
260260
transferMangerNotSet bool
261261

262262
// BlockSize defines the size of the buffer used during upload. The default and mimimum value is 1 MiB.
263-
BlockSize int
263+
BlockSize int64
264264

265265
// Concurrency defines the number of concurrent uploads to be performed to upload the file.
266266
// Each concurrent upload will create a buffer of size BlockSize. The default value is one.

sdk/storage/azblob/client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func performUploadStreamToBlockBlobTest(t *testing.T, _require *require.Assertio
9797

9898
// Perform UploadStream
9999
_, err = client.UploadStream(ctx, containerName, blobName, blobContentReader,
100-
&blockblob.UploadStreamOptions{BlockSize: bufferSize, Concurrency: maxBuffers})
100+
&blockblob.UploadStreamOptions{BlockSize: int64(bufferSize), Concurrency: maxBuffers})
101101

102102
// Assert that upload was successful
103103
_require.NoError(err)

sdk/storage/azblob/internal/shared/transfer_manager.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ type TransferManager interface {
3737

3838
type staticBuffer struct {
3939
buffers chan []byte
40-
size int
40+
size int64
4141
threadpool chan func()
4242
}
4343

4444
// NewStaticBuffer creates a TransferManager that will use a channel as a circular buffer
4545
// that can hold "max" buffers of "size". The goroutine pool is also sized at max. This
4646
// can be shared between calls if you wish to control maximum memory and concurrency with
4747
// multiple concurrent calls.
48-
func NewStaticBuffer(size, max int) (TransferManager, error) {
48+
func NewStaticBuffer(size int64, max int) (TransferManager, error) {
4949
if size < 1 || max < 1 {
5050
return nil, fmt.Errorf("cannot be called with size or max set to < 1")
5151
}

sdk/storage/azblob/internal/testcommon/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func GenerateBlockIDsList(count int) []string {
122122
return blockIDs
123123
}
124124

125-
// blockIDIntToBase64 functions convert an int block ID to a base-64 string and vice versa
125+
// BlockIDIntToBase64 functions convert an int block ID to a base-64 string and vice versa
126126
func BlockIDIntToBase64(blockID int) string {
127127
binaryBlockID := (&[4]byte{})[:]
128128
binary.LittleEndian.PutUint32(binaryBlockID, uint32(blockID))

0 commit comments

Comments
 (0)