From cef53c7521e50f982853cc71065c81f99904aec5 Mon Sep 17 00:00:00 2001 From: tanyasethi-msft Date: Fri, 12 Jan 2024 19:45:07 +0530 Subject: [PATCH] append with flush --- sdk/storage/azdatalake/assets.json | 2 +- sdk/storage/azdatalake/file/client_test.go | 34 ++++++++++++++++++++++ sdk/storage/azdatalake/file/models.go | 3 ++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/sdk/storage/azdatalake/assets.json b/sdk/storage/azdatalake/assets.json index 626d6568abd4..81645a340794 100644 --- a/sdk/storage/azdatalake/assets.json +++ b/sdk/storage/azdatalake/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "go", "TagPrefix": "go/storage/azdatalake", - "Tag": "go/storage/azdatalake_3ae5e1441b" + "Tag": "go/storage/azdatalake_7a31b2404b" } diff --git a/sdk/storage/azdatalake/file/client_test.go b/sdk/storage/azdatalake/file/client_test.go index cf738b6587f2..227587944351 100644 --- a/sdk/storage/azdatalake/file/client_test.go +++ b/sdk/storage/azdatalake/file/client_test.go @@ -3419,6 +3419,40 @@ func (s *RecordedTestSuite) TestDownloadDataContentMD5() { _require.Equal(resp1.ContentMD5, mdf[:]) } +func (s *RecordedTestSuite) TestFileAppendWithFlushOption() { + _require := require.New(s.T()) + testName := s.T().Name() + + filesystemName := testcommon.GenerateFileSystemName(testName) + fsClient, err := testcommon.GetFileSystemClient(filesystemName, s.T(), testcommon.TestAccountDatalake, nil) + _require.NoError(err) + defer testcommon.DeleteFileSystem(context.Background(), _require, fsClient) + + _, err = fsClient.Create(context.Background(), nil) + _require.NoError(err) + + srcFileName := "src" + testcommon.GenerateFileName(testName) + + srcFClient, err := testcommon.GetFileClient(filesystemName, srcFileName, s.T(), testcommon.TestAccountDatalake, nil) + _require.NoError(err) + + resp, err := srcFClient.Create(context.Background(), nil) + _require.NoError(err) + _require.NotNil(resp) + + contentSize := 1024 * 8 // 8KB + rsc, _ := testcommon.GenerateData(contentSize) + opts := &file.AppendDataOptions{ + Flush: to.Ptr(true), + } + _, err = srcFClient.AppendData(context.Background(), 0, rsc, opts) + _require.NoError(err) + + gResp2, err := srcFClient.GetProperties(context.Background(), nil) + _require.NoError(err) + _require.Equal(*gResp2.ContentLength, int64(contentSize)) +} + func (s *RecordedTestSuite) TestFileAppendAndFlushData() { _require := require.New(s.T()) testName := s.T().Name() diff --git a/sdk/storage/azdatalake/file/models.go b/sdk/storage/azdatalake/file/models.go index 27fa5e163166..7ffba3b11a31 100644 --- a/sdk/storage/azdatalake/file/models.go +++ b/sdk/storage/azdatalake/file/models.go @@ -243,6 +243,8 @@ type AppendDataOptions struct { LeaseAccessConditions *LeaseAccessConditions // CPKInfo contains optional parameters to perform encryption using customer-provided key. CPKInfo *CPKInfo + //Flush Optional. If true, the file will be flushed after append. + Flush *bool } func (o *AppendDataOptions) format(offset int64, body io.ReadSeekCloser) (*generated.PathClientAppendDataOptions, *generated.LeaseAccessConditions, *generated.CPKInfo, error) { @@ -280,6 +282,7 @@ func (o *AppendDataOptions) format(offset int64, body io.ReadSeekCloser) (*gener cpkInfoOpts.EncryptionKeySHA256 = o.CPKInfo.EncryptionKeySHA256 cpkInfoOpts.EncryptionAlgorithm = o.CPKInfo.EncryptionAlgorithm } + appendDataOptions.Flush = o.Flush } if o != nil && o.TransactionalValidation != nil { _, err = o.TransactionalValidation.Apply(body, appendDataOptions)