当前位置: 首页>>代码示例>>Python>>正文


Python MultipartUploadContext.announce_upload_id方法代码示例

本文整理汇总了Python中awscli.customizations.s3.tasks.MultipartUploadContext.announce_upload_id方法的典型用法代码示例。如果您正苦于以下问题:Python MultipartUploadContext.announce_upload_id方法的具体用法?Python MultipartUploadContext.announce_upload_id怎么用?Python MultipartUploadContext.announce_upload_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在awscli.customizations.s3.tasks.MultipartUploadContext的用法示例。


在下文中一共展示了MultipartUploadContext.announce_upload_id方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_normal_non_threaded

# 需要导入模块: from awscli.customizations.s3.tasks import MultipartUploadContext [as 别名]
# 或者: from awscli.customizations.s3.tasks.MultipartUploadContext import announce_upload_id [as 别名]
 def test_normal_non_threaded(self):
     # The context object is pretty straightforward.
     # This shows the non threaded usage of this object.
     context = MultipartUploadContext(expected_parts=3)
     # First you can announce an upload id.
     context.announce_upload_id('my_upload_id')
     # Then a thread that was waiting on the id would be notified.
     self.assertEqual(context.wait_for_upload_id(), 'my_upload_id')
     # Then thread would chug away at the parts.
     context.announce_finished_part(etag='etag1', part_number=1)
     context.announce_finished_part(etag='etag2', part_number=2)
     context.announce_finished_part(etag='etag3', part_number=3)
     # Then a thread that was waiting for all the parts to finish
     # would be notified.
     self.assertEqual(context.wait_for_parts_to_finish(), [
         {'ETag': 'etag1', 'PartNumber': 1},
         {'ETag': 'etag2', 'PartNumber': 2},
         {'ETag': 'etag3', 'PartNumber': 3}])
开发者ID:andresvidal,项目名称:aws-cli,代码行数:20,代码来源:test_tasks.py

示例2: TestMultipartUploadContext

# 需要导入模块: from awscli.customizations.s3.tasks import MultipartUploadContext [as 别名]
# 或者: from awscli.customizations.s3.tasks.MultipartUploadContext import announce_upload_id [as 别名]
class TestMultipartUploadContext(unittest.TestCase):

    def setUp(self):
        self.context = MultipartUploadContext(expected_parts=1)
        self.calls = []
        self.threads = []
        self.call_lock = threading.Lock()
        self.caught_exception = None

    def tearDown(self):
        self.join_threads()

    def join_threads(self):
        for thread in self.threads:
            thread.join()

    def upload_part(self, part_number):
        # This simulates what a thread would do if it wanted to upload
        # a part.  First it would wait for the upload id.
        try:
            upload_id = self.context.wait_for_upload_id()
        except Exception as e:
            self.caught_exception = e
            return
        with self.call_lock:
            self.calls.append(('upload_part', part_number, upload_id))
        # Then it would call UploadPart here.
        # Then it would announce that it's finished with a part.
        self.context.announce_finished_part(etag='etag%s' % part_number,
                                            part_number=part_number)

    def complete_upload(self):
        try:
            upload_id = self.context.wait_for_upload_id()
            parts = self.context.wait_for_parts_to_finish()
        except Exception as e:
            self.caught_exception = e
            return
        with self.call_lock:
            self.calls.append(('complete_upload', upload_id, parts))
            self.context.announce_completed()

    def wait_for_upload_complete(self):
        try:
            self.context.wait_for_completion()
        except Exception as e:
            self.caught_exception = e
            return
        with self.call_lock:
            self.calls.append(('arbitrary_post_complete_operation',))

    def create_upload(self, upload_id):
        with self.call_lock:
            self.calls.append(('create_multipart_upload', 'my_upload_id'))
        self.context.announce_upload_id(upload_id)

    def start_thread(self, thread):
        thread.start()
        self.threads.append(thread)

    def test_normal_non_threaded(self):
        # The context object is pretty straightforward.
        # This shows the non threaded usage of this object.
        context = MultipartUploadContext(expected_parts=3)
        # First you can announce an upload id.
        context.announce_upload_id('my_upload_id')
        # Then a thread that was waiting on the id would be notified.
        self.assertEqual(context.wait_for_upload_id(), 'my_upload_id')
        # Then thread would chug away at the parts.
        context.announce_finished_part(etag='etag1', part_number=1)
        context.announce_finished_part(etag='etag2', part_number=2)
        context.announce_finished_part(etag='etag3', part_number=3)
        # Then a thread that was waiting for all the parts to finish
        # would be notified.
        self.assertEqual(context.wait_for_parts_to_finish(), [
            {'ETag': 'etag1', 'PartNumber': 1},
            {'ETag': 'etag2', 'PartNumber': 2},
            {'ETag': 'etag3', 'PartNumber': 3}])
        context.announce_completed()
        # This will return right away since we've already announced completion.
        self.assertIsNone(context.wait_for_completion())

    def test_basic_threaded_parts(self):
        # Now while test_normal_non_threaded showed the conceptual idea,
        # the real strength of MultipartUploadContext is that it works
        # when there are threads and when these threads operate out of
        # sequence.
        # For example, let's say a thread comes along that wants
        # to upload a part.  It needs to wait until the upload id
        # is announced.
        upload_part_thread = threading.Thread(target=self.upload_part,
                                              args=(1,))
        # Once this thread starts it will immediately block.
        self.start_thread(upload_part_thread)

        # Also, let's start the thread that will do the complete
        # multipart upload.  It will also block because it needs all
        # the parts so it's blocked up the upload_part_thread.  It also
        # needs the upload_id so it's blocked on that as well.
        complete_upload_thread = threading.Thread(target=self.complete_upload)
#.........这里部分代码省略.........
开发者ID:BillTheBest,项目名称:aws-cli,代码行数:103,代码来源:test_tasks.py


注:本文中的awscli.customizations.s3.tasks.MultipartUploadContext.announce_upload_id方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。