Example #1
0
 def test_create_retry_handler_with_no_operation(self):
     handler = retryhandler.create_retry_handler(
         self.retry_config, operation_name=None)
     self.assertIsInstance(handler, retryhandler.RetryHandler)
     # No good way to test for the delay function as the action
     # other than to just invoke it.
     self.assertEqual(handler._action(attempts=2), 2)
     self.assertEqual(handler._action(attempts=3), 4)
 def test_connection_timeouts_are_retried(self):
     # If a connection times out, we get a Timout exception
     # from requests.  We should be retrying those.
     handler = retryhandler.create_retry_handler(
         self.retry_config, operation_name='OperationBar')
     sleep_time = handler(response=None, attempts=1,
                          caught_exception=Timeout())
     self.assertEqual(sleep_time, 1)
Example #3
0
def _register_for_operations(config, session, service_name):
    # There's certainly a tradeoff for registering the retry config
    # for the operations when the service is created.  In practice,
    # there aren't a whole lot of per operation retry configs so
    # this is ok for now.
    for key in config:
        if key == "__default__":
            continue
        handler = retryhandler.create_retry_handler(config, key)
        unique_id = "retry-config-%s-%s" % (service_name, key)
        session.register("needs-retry.%s.%s" % (service_name, key), handler, unique_id=unique_id)
Example #4
0
def register_retries_for_service(service, **kwargs):
    if not hasattr(service, 'retry'):
        return
    logger.debug("Registering retry handlers for service: %s", service)
    config = service.retry
    session = service.session
    handler = retryhandler.create_retry_handler(config)
    unique_id = 'retry-config-%s' % service.endpoint_prefix
    session.register('needs-retry.%s' % service.endpoint_prefix,
                     handler, unique_id=unique_id)
    _register_for_operations(config, session,
                             service_name=service.endpoint_prefix)
Example #5
0
 def test_retry_pool_closed_errors(self):
     # A ClosedPoolError is retried (this is a workaround for a urllib3
     # bug).  Can be removed once we upgrade to requests 2.0.0.
     handler = retryhandler.create_retry_handler(
         self.retry_config, operation_name='OperationBar')
     # 4th attempt is retried.
     sleep_time = handler(
         response=None, attempts=4,
         caught_exception=ClosedPoolError('FakePool', 'Message'))
     self.assertEqual(sleep_time, 8)
     # But the 5th time propogates the error.
     with self.assertRaises(ClosedPoolError):
         handler(response=None, attempts=10,
                 caught_exception=ClosedPoolError('FakePool', 'Message'))
Example #6
0
def register_retries_for_service(service, **kwargs):
    loader = service.session.get_component('data_loader')
    config = _load_retry_config(loader, service.endpoint_prefix)
    if not config:
        return
    logger.debug("Registering retry handlers for service: %s", service)
    session = service.session
    handler = retryhandler.create_retry_handler(
        config, service.endpoint_prefix)
    unique_id = 'retry-config-%s' % service.endpoint_prefix
    session.register('needs-retry.%s' % service.endpoint_prefix,
                     handler, unique_id=unique_id)
    _register_for_operations(config, session,
                             service_name=service.endpoint_prefix)
Example #7
0
def register_retries_for_service(service, **kwargs):
    if not hasattr(service, 'retry'):
        return
    logger.debug("Registering retry handlers for service: %s", service)
    config = service.retry
    session = service.session
    handler = retryhandler.create_retry_handler(config)
    unique_id = 'retry-config-%s' % service.endpoint_prefix
    session.register('needs-retry.%s' % service.endpoint_prefix,
                     handler,
                     unique_id=unique_id)
    _register_for_operations(config,
                             session,
                             service_name=service.endpoint_prefix)
Example #8
0
 def test_retry_pool_closed_errors(self):
     # A ClosedPoolError is retried (this is a workaround for a urllib3
     # bug).  Can be removed once we upgrade to requests 2.0.0.
     handler = retryhandler.create_retry_handler(
         self.retry_config, operation_name='OperationBar')
     # 4th attempt is retried.
     sleep_time = handler(
         response=None, attempts=4,
         caught_exception=ClosedPoolError('FakePool', 'Message'))
     self.assertEqual(sleep_time, 8)
     # But the 5th time propogates the error.
     with self.assertRaises(ClosedPoolError):
         handler(response=None, attempts=10,
                 caught_exception=ClosedPoolError('FakePool', 'Message'))
Example #9
0
 def test_crc32_check_propogates_error(self):
     handler = retryhandler.create_retry_handler(
         self.retry_config, operation_name='OperationFoo')
     http_response = mock.Mock()
     http_response.status_code = 200
     # This is not the crc32 of b'foo', so this should
     # fail the crc32 check.
     http_response.headers = {'x-amz-crc32': 2356372768}
     http_response.content = b'foo'
     # The first 10 attempts we get a retry.
     self.assertEqual(handler(response=(http_response, {}), attempts=1,
                              caught_exception=None), 1)
     with self.assertRaises(ChecksumError):
         handler(response=(http_response, {}), attempts=10,
                 caught_exception=None)
Example #10
0
 def test_create_retry_handler_with_socket_errors(self):
     handler = retryhandler.create_retry_handler(
         self.retry_config, operation_name='OperationBar')
     with self.assertRaises(ConnectionError):
         handler(response=None, attempts=10,
                 caught_exception=ConnectionError())
     # No connection error raised because attempts < max_attempts.
     sleep_time = handler(response=None, attempts=1,
                          caught_exception=ConnectionError())
     self.assertEqual(sleep_time, 1)
     # But any other exception should be raised even if
     # attempts < max_attempts.
     with self.assertRaises(ValueError):
         sleep_time = handler(response=None, attempts=1,
                             caught_exception=ValueError())
Example #11
0
def register_retries_for_service(service, **kwargs):
    loader = service.session.get_component('data_loader')
    config = _load_retry_config(loader, service.endpoint_prefix)
    if not config:
        return
    logger.debug("Registering retry handlers for service: %s", service)
    session = service.session
    handler = retryhandler.create_retry_handler(config,
                                                service.endpoint_prefix)
    unique_id = 'retry-config-%s' % service.endpoint_prefix
    session.register('needs-retry.%s' % service.endpoint_prefix,
                     handler,
                     unique_id=unique_id)
    _register_for_operations(config,
                             session,
                             service_name=service.endpoint_prefix)
Example #12
0
def register_retries_for_service(service_data, session, service_name, **kwargs):
    loader = session.get_component("data_loader")
    endpoint_prefix = service_data.get("metadata", {}).get("endpointPrefix")
    if endpoint_prefix is None:
        logger.debug(
            "Not registering retry handlers, could not endpoint " "prefix from model for service %s", service_name
        )
        return
    config = _load_retry_config(loader, endpoint_prefix)
    if not config:
        return
    logger.debug("Registering retry handlers for service: %s", service_name)
    handler = retryhandler.create_retry_handler(config, endpoint_prefix)
    unique_id = "retry-config-%s" % endpoint_prefix
    session.register("needs-retry.%s" % endpoint_prefix, handler, unique_id=unique_id)
    _register_for_operations(config, session, service_name=endpoint_prefix)
Example #13
0
def register_retries_for_service(service_data, session, service_name,
                                 **kwargs):
    loader = session.get_component('data_loader')
    endpoint_prefix = service_data.get('metadata', {}).get('endpointPrefix')
    if endpoint_prefix is None:
        logger.debug(
            "Not registering retry handlers, could not endpoint "
            "prefix from model for service %s", service_name)
        return
    config = _load_retry_config(loader, endpoint_prefix)
    if not config:
        return
    logger.debug("Registering retry handlers for service: %s", service_name)
    handler = retryhandler.create_retry_handler(config, endpoint_prefix)
    unique_id = 'retry-config-%s' % endpoint_prefix
    session.register('needs-retry.%s' % endpoint_prefix,
                     handler,
                     unique_id=unique_id)
    _register_for_operations(config, session, service_name=endpoint_prefix)
Example #14
0
def register_retries_for_service(service_data, session,
                                 service_name, **kwargs):
    loader = session.get_component('data_loader')
    endpoint_prefix = service_data.get('metadata', {}).get('endpointPrefix')
    if endpoint_prefix is None:
        logger.debug("Not registering retry handlers, could not endpoint "
                     "prefix from model for service %s", service_name)
        return
    service_id = service_data.get('metadata', {}).get('serviceId')
    service_event_name = hyphenize_service_id(service_id)
    config = _load_retry_config(loader, endpoint_prefix)
    if not config:
        return
    logger.debug("Registering retry handlers for service: %s", service_name)
    handler = retryhandler.create_retry_handler(
        config, endpoint_prefix)
    unique_id = 'retry-config-%s' % service_event_name
    session.register('needs-retry.%s' % service_event_name,
                     handler, unique_id=unique_id)
    _register_for_operations(config, session, service_event_name)