-
Notifications
You must be signed in to change notification settings - Fork 3.2k
[storage] Blob async APIs #6489
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
59 commits
Select commit
Hold shift + click to select a range
8f85d8c
Updated blobs shared code
annatisch a3aff08
Started blob refactor
annatisch 90b9640
Refactoring upload
annatisch 6d33776
Merge remote-tracking branch 'upstream/storage-preview2'
annatisch de42b24
Updated shared code
annatisch d8ec863
Started fixing tests
annatisch 8d9bd39
Merge remote-tracking branch 'upstream/storage-preview2'
annatisch 3a231d8
Refactored sync blobs
annatisch d527688
Added blob async APIs
annatisch 76b9e3c
Some fixes
annatisch 9a8fb9d
Append blob async tests
annatisch 900e07b
blob access async tests
annatisch c8668c9
Blob client async tests
annatisch 05b9020
encryption async tests
annatisch bee7e3f
Patch for azure core exception
annatisch dda031b
blob retry async
annatisch 99bc35d
Retry async tests
annatisch 4fd5b84
Get blob async tests
annatisch 1eb8192
Bug fix for clear page operation
annatisch 24dd430
More async tests + upload fix
annatisch 30cbc1b
Merged from preview 2
annatisch 076d062
Merged blobs
annatisch fa808bb
Updated Files shared code
annatisch 38f6fc5
Updated queue shared code
annatisch e6d9544
Merge from upstream
annatisch 704d8bb
async tests pass except 2 common blob tests
kristapratico 9bcd94a
adds async paging to blobs and some async tests (not all pass)
kristapratico 8a6df99
Merge pull request #2 from annatisch/async-blob-tests
kristapratico d28961c
initial commit
rakshith91 375323e
block_blob_tests
rakshith91 35261e9
page blob tests
rakshith91 0b5eaed
Merge pull request #3 from annatisch/async_tests
bdd8396
Merge branch 'storage-preview2' into master
kristapratico 37fb8e3
fix for special chars, some tests, and recordings
kristapratico 4bcbca7
add to shared storage and fix import
kristapratico a984b39
adding more tests/recordings
kristapratico 90a7c61
more tests/recordings
kristapratico 36155a8
Merge pull request #4 from annatisch/async-blob-tests
kristapratico 5fb77f5
rerecord tests, fix imports
kristapratico e97af55
Merge pull request #5 from annatisch/async-blob-tests
kristapratico 4687f62
fix import again
kristapratico 7552cdb
Merge pull request #6 from annatisch/async-blob-tests
kristapratico 753006e
blacklist azure-servicemanagement-legacy
kristapratico 748237e
Merge pull request #7 from annatisch/async-blob-tests
kristapratico dfabb8b
get CI to run
kristapratico 0ad6851
Merge pull request #8 from annatisch/async-blob-tests
kristapratico 634a74a
rerecord all async tests
kristapratico 2848c33
Merge pull request #9 from annatisch/async-blob-tests
kristapratico c607dde
testing
kristapratico b3b67fc
Merge pull request #10 from annatisch/async-blob-tests
kristapratico 4df2eef
add variable indirection for storage live tests. this is a temporary …
danieljurek 615fc42
newline
danieljurek f51dfb4
Merge pull request #11 from danieljurek/async-blob-tests
kristapratico 7edbc6e
print envar
kristapratico ace7ea7
Merge pull request #12 from annatisch/async-blob-tests
kristapratico 85490ca
remove testing
kristapratico d48e917
Merge pull request #13 from annatisch/async-blob-tests
kristapratico 20adbbc
adjust pypy testing
kristapratico 2b1a0ae
Merge pull request #14 from annatisch/async-blob-tests
kristapratico File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
More async tests + upload fix
- Loading branch information
commit 24dd4303cd625640f57e8f371a5ae4f3b95cb73c
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
193 changes: 193 additions & 0 deletions
193
sdk/storage/azure-storage-blob/tests/test_block_blob_sync_copy_async.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,193 @@ | ||
| # ------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for | ||
| # license information. | ||
| # -------------------------------------------------------------------------- | ||
| import pytest | ||
| import asyncio | ||
|
|
||
| from datetime import datetime, timedelta | ||
| from azure.core import HttpResponseError | ||
| from azure.storage.blob.aio import ( | ||
| BlobServiceClient, | ||
| ContainerClient, | ||
| BlobClient, | ||
| StorageErrorCode, | ||
| BlobPermissions | ||
| ) | ||
| from azure.storage.blob._shared.policies import StorageContentValidation | ||
| from testcase import ( | ||
| StorageTestCase, | ||
| record, | ||
| TestMode | ||
| ) | ||
|
|
||
| # ------------------------------------------------------------------------------ | ||
| SOURCE_BLOB_SIZE = 8 * 1024 | ||
|
|
||
|
|
||
| # ------------------------------------------------------------------------------ | ||
|
|
||
| class StorageBlockBlobTestAsync(StorageTestCase): | ||
|
|
||
| def setUp(self): | ||
| super(StorageBlockBlobTestAsync, self).setUp() | ||
| url = self._get_account_url() | ||
| credential = self._get_shared_key_credential() | ||
|
|
||
| # test chunking functionality by reducing the size of each chunk, | ||
| # otherwise the tests would take too long to execute | ||
| self.bsc = BlobServiceClient( | ||
| url, | ||
| credential=credential, | ||
| connection_data_block_size=4 * 1024, | ||
| max_single_put_size=32 * 1024, | ||
| max_block_size=4 * 1024) | ||
| self.config = self.bsc._config | ||
| self.container_name = self.get_resource_name('utcontainer') | ||
|
|
||
| # create source blob to be copied from | ||
| self.source_blob_name = self.get_resource_name('srcblob') | ||
| self.source_blob_data = self.get_random_bytes(SOURCE_BLOB_SIZE) | ||
|
|
||
| blob = self.bsc.get_blob_client(self.container_name, self.source_blob_name) | ||
| if not self.is_playback(): | ||
| self.bsc.create_container(self.container_name) | ||
| blob.upload_blob(self.source_blob_data) | ||
|
|
||
| # generate a SAS so that it is accessible with a URL | ||
| sas_token = blob.generate_shared_access_signature( | ||
| permission=BlobPermissions.READ, | ||
| expiry=datetime.utcnow() + timedelta(hours=1), | ||
| ) | ||
| self.source_blob_url = BlobClient(blob.url, credential=sas_token).url | ||
|
|
||
| def tearDown(self): | ||
| if not self.is_playback(): | ||
| loop = asyncio.get_event_loop() | ||
| try: | ||
| loop.run_until_complete(self.bsc.delete_container(self.container_name)) | ||
| except: | ||
| pass | ||
|
|
||
| return super(StorageBlockBlobTestAsync, self).tearDown() | ||
|
|
||
| async def _setup(self): | ||
| blob = self.bsc.get_blob_client(self.container_name, self.source_blob_name) | ||
| if not self.is_playback(): | ||
| try: | ||
| await self.bsc.create_container(self.container_name) | ||
| except: | ||
| pass | ||
| await blob.upload_blob(self.source_blob_data, overwrite=True) | ||
|
|
||
| # generate a SAS so that it is accessible with a URL | ||
| sas_token = blob.generate_shared_access_signature( | ||
| permission=BlobPermissions.READ, | ||
| expiry=datetime.utcnow() + timedelta(hours=1), | ||
| ) | ||
| self.source_blob_url = BlobClient(blob.url, credential=sas_token).url | ||
|
|
||
| async def _test_put_block_from_url_and_commit_async(self): | ||
| # Arrange | ||
| await self._setup() | ||
| dest_blob_name = self.get_resource_name('destblob') | ||
| dest_blob = self.bsc.get_blob_client(self.container_name, dest_blob_name) | ||
|
|
||
| # Act part 1: make put block from url calls | ||
| futures = [ | ||
| dest_blob.stage_block_from_url( | ||
| block_id=1, | ||
| source_url=self.source_blob_url, | ||
| source_offset=0, | ||
| source_length=4 * 1024 - 1), | ||
| dest_blob.stage_block_from_url( | ||
| block_id=2, | ||
| source_url=self.source_blob_url, | ||
| source_offset=4 * 1024, | ||
| source_length=8 * 1024)] | ||
| await asyncio.gather(*futures) | ||
|
|
||
| # Assert blocks | ||
| committed, uncommitted = await dest_blob.get_block_list('all') | ||
| self.assertEqual(len(uncommitted), 2) | ||
| self.assertEqual(len(committed), 0) | ||
|
|
||
| # Act part 2: commit the blocks | ||
| await dest_blob.commit_block_list(['1', '2']) | ||
|
|
||
| # Assert destination blob has right content | ||
| content = await (await dest_blob.download_blob()).content_as_bytes() | ||
| self.assertEqual(content, self.source_blob_data) | ||
|
|
||
| def test_put_block_from_url_and_commit_async(self): | ||
| if TestMode.need_recording_file(self.test_mode): | ||
| return | ||
| loop = asyncio.get_event_loop() | ||
| loop.run_until_complete(self._test_put_block_from_url_and_commit_async()) | ||
|
|
||
| async def _test_put_block_from_url_and_validate_content_md5_async(self): | ||
| # Arrange | ||
| await self._setup() | ||
| dest_blob_name = self.get_resource_name('destblob') | ||
| dest_blob = self.bsc.get_blob_client(self.container_name, dest_blob_name) | ||
| src_md5 = StorageContentValidation.get_content_md5(self.source_blob_data) | ||
|
|
||
| # Act part 1: put block from url with md5 validation | ||
| await dest_blob.stage_block_from_url( | ||
| block_id=1, | ||
| source_url=self.source_blob_url, | ||
| source_content_md5=src_md5, | ||
| source_offset=0, | ||
| source_length=8 * 1024) | ||
|
|
||
| # Assert block was staged | ||
| committed, uncommitted = await dest_blob.get_block_list('all') | ||
| self.assertEqual(len(uncommitted), 1) | ||
| self.assertEqual(len(committed), 0) | ||
|
|
||
| # Act part 2: put block from url with wrong md5 | ||
| fake_md5 = StorageContentValidation.get_content_md5(b"POTATO") | ||
| with self.assertRaises(HttpResponseError) as error: | ||
| await dest_blob.stage_block_from_url( | ||
| block_id=2, | ||
| source_url=self.source_blob_url, | ||
| source_content_md5=fake_md5, | ||
| source_offset=0, | ||
| source_length=8 * 1024) | ||
| self.assertEqual(error.exception.error_code, StorageErrorCode.md5_mismatch) | ||
|
|
||
| # Assert block was not staged | ||
| committed, uncommitted = await dest_blob.get_block_list('all') | ||
| self.assertEqual(len(uncommitted), 1) | ||
| self.assertEqual(len(committed), 0) | ||
|
|
||
| def test_put_block_from_url_and_validate_content_md5_async(self): | ||
| if TestMode.need_recording_file(self.test_mode): | ||
| return | ||
| loop = asyncio.get_event_loop() | ||
| loop.run_until_complete(self._test_put_block_from_url_and_validate_content_md5_async()) | ||
|
|
||
| async def _test_copy_blob_sync_async(self): | ||
| # Arrange | ||
| await self._setup() | ||
| dest_blob_name = self.get_resource_name('destblob') | ||
| dest_blob = self.bsc.get_blob_client(self.container_name, dest_blob_name) | ||
|
|
||
| # Act | ||
| copy_props = await dest_blob.start_copy_from_url(self.source_blob_url, requires_sync=True) | ||
|
|
||
| # Assert | ||
| self.assertIsNotNone(copy_props) | ||
| self.assertIsNotNone(copy_props['copy_id']) | ||
| self.assertEqual('success', copy_props['copy_status']) | ||
|
|
||
| # Verify content | ||
| content = await (await dest_blob.download_blob()).content_as_bytes() | ||
| self.assertEqual(self.source_blob_data, content) | ||
|
|
||
| def test_copy_blob_sync_async(self): | ||
| if TestMode.need_recording_file(self.test_mode): | ||
| return | ||
| loop = asyncio.get_event_loop() | ||
| loop.run_until_complete(self._test_copy_blob_sync_async()) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: confusing file name