コード例 #1
0
ファイル: test_endpoint.py プロジェクト: mguillaume/botocore
class TestResetStreamOnRetry(unittest.TestCase):
    def setUp(self):
        super(TestResetStreamOnRetry, self).setUp()
        self.total_calls = 0
        self.auth = Mock()
        self.session = Session(include_builtin_handlers=False)
        self.service = Mock()
        self.service.endpoint_prefix = 's3'
        self.service.session = self.session
        self.endpoint = RestEndpoint(self.service,
                                     'us-east-1',
                                     'https://s3.amazonaws.com/',
                                     auth=self.auth)
        self.http_session = Mock()
        self.endpoint.http_session = self.http_session
        self.get_response_patch = patch('botocore.response.get_response')
        self.get_response = self.get_response_patch.start()
        self.retried_on_exception = None

    def tearDown(self):
        self.get_response_patch.stop()

    def max_attempts_retry_handler(self, attempts, **kwargs):
        # Simulate a max requests of 3.
        self.total_calls += 1
        if attempts == 3:
            return None
        else:
            # Returning anything non-None will trigger a retry,
            # but 0 here is so that time.sleep(0) happens.
            return 0

    def test_reset_stream_on_retry(self):
        # It doesn't really matter what the operation is, we will
        # check in general if we're
        self.session.register('needs-retry.s3.PutObject',
                              self.max_attempts_retry_handler)
        op = Mock()
        payload = Payload()
        payload.literal_value = RecordStreamResets('foobar')
        op.name = 'PutObject'
        op.http = {'uri': '', 'method': 'POST'}
        self.endpoint.make_request(op, {'headers': {}, 'payload': payload})
        self.assertEqual(self.total_calls, 3)
        self.assertEqual(payload.literal_value.total_resets, 2)
コード例 #2
0
ファイル: test_endpoint.py プロジェクト: Debian/botocore
class TestResetStreamOnRetry(unittest.TestCase):
    def setUp(self):
        super(TestResetStreamOnRetry, self).setUp()
        self.total_calls = 0
        self.auth = Mock()
        self.session = Session(include_builtin_handlers=False)
        self.service = Mock()
        self.service.endpoint_prefix = 's3'
        self.service.session = self.session
        self.endpoint = RestEndpoint(
            self.service, 'us-east-1', 'https://s3.amazonaws.com/',
            auth=self.auth)
        self.http_session = Mock()
        self.endpoint.http_session = self.http_session
        self.get_response_patch = patch('botocore.response.get_response')
        self.get_response = self.get_response_patch.start()
        self.retried_on_exception = None

    def tearDown(self):
        self.get_response_patch.stop()

    def max_attempts_retry_handler(self, attempts, **kwargs):
        # Simulate a max requests of 3.
        self.total_calls += 1
        if attempts == 3:
            return None
        else:
            # Returning anything non-None will trigger a retry,
            # but 0 here is so that time.sleep(0) happens.
            return 0

    def test_reset_stream_on_retry(self):
        # It doesn't really matter what the operation is, we will
        # check in general if we're
        self.session.register('needs-retry.s3.PutObject',
                              self.max_attempts_retry_handler)
        op = Mock()
        payload = Payload()
        payload.literal_value = RecordStreamResets('foobar')
        op.name = 'PutObject'
        op.http = {'uri': '', 'method': 'POST'}
        self.endpoint.make_request(op, {'headers': {}, 'payload': payload})
        self.assertEqual(self.total_calls, 3)
        self.assertEqual(payload.literal_value.total_resets, 2)
コード例 #3
0
ファイル: base.py プロジェクト: onicagroup/runway
 def register_strategy(self, session: Session) -> None:
     """Register the sync strategy class to the given session."""
     session.register("choosing-s3-sync-strategy", self.use_sync_strategy)
コード例 #4
0
ファイル: test_endpoint.py プロジェクト: lukess/botocore
class TestRetryInterface(BaseSessionTest):
    def setUp(self):
        super(TestRetryInterface, self).setUp()
        self.total_calls = 0
        self.auth = Mock()
        self.session = Session(include_builtin_handlers=False)
        self.service = Mock()
        self.service.endpoint_prefix = 'ec2'
        self.service.session = self.session
        self.endpoint = QueryEndpoint(
            self.service, 'us-west-2', 'https://ec2.us-west-2.amazonaws.com/',
            auth=self.auth)
        self.http_session = Mock()
        self.endpoint.http_session = self.http_session
        self.get_response_patch = patch('botocore.response.get_response')
        self.get_response = self.get_response_patch.start()
        self.retried_on_exception = None

    def tearDown(self):
        self.get_response_patch.stop()

    def max_attempts_retry_handler(self, attempts, **kwargs):
        # Simulate a max requests of 3.
        self.total_calls += 1
        if attempts == 3:
            return None
        else:
            # Returning anything non-None will trigger a retry,
            # but 0 here is so that time.sleep(0) happens.
            return 0

    def connection_error_handler(self, attempts, caught_exception, **kwargs):
        self.total_calls += 1
        if attempts == 3:
            return None
        elif isinstance(caught_exception, ConnectionError):
            # Returning anything non-None will trigger a retry,
            # but 0 here is so that time.sleep(0) happens.
            return 0
        else:
            return None

    def test_retry_events_are_emitted(self):
        emitted_events = []
        self.session.register('needs-retry.ec2.DescribeInstances',
                              lambda **kwargs: emitted_events.append(kwargs))
        op = Mock()
        op.name = 'DescribeInstances'
        self.endpoint.make_request(op, {})
        self.assertEqual(len(emitted_events), 1)
        self.assertEqual(emitted_events[0]['event_name'],
                         'needs-retry.ec2.DescribeInstances')

    def test_retry_events_can_alter_behavior(self):
        self.session.register('needs-retry.ec2.DescribeInstances',
                              self.max_attempts_retry_handler)
        op = Mock()
        op.name = 'DescribeInstances'
        self.endpoint.make_request(op, {})
        self.assertEqual(self.total_calls, 3)

    def test_retry_on_socket_errors(self):
        self.session.register('needs-retry.ec2.DescribeInstances',
                              self.connection_error_handler)
        op = Mock()
        op.name = 'DescribeInstances'
        self.http_session.send.side_effect = ConnectionError()
        self.endpoint.make_request(op, {})
        self.assertEqual(self.total_calls, 3)