예제 #1
0
 def test_create_context_from_exception(self):
     context = standard.RetryEventAdapter().create_retry_context(
         response=None,
         attempts=1,
         caught_exception=self.caught_exception,
         request_dict={'context': {'foo': 'bar'}},
         operation=mock.sentinel.operation_model,
     )
     self.assertEqual(context.parsed_response, None)
     self.assertEqual(context.http_response, None)
     self.assertEqual(context.caught_exception, self.caught_exception)
예제 #2
0
 def test_can_inject_metadata_back_to_context(self):
     adapter = standard.RetryEventAdapter()
     context = adapter.create_retry_context(attempts=1,
                                            operation=None,
                                            caught_exception=None,
                                            request_dict={'context': {}},
                                            response=(self.http_failed,
                                                      self.failed_response))
     context.add_retry_metadata(MaxAttemptsReached=True)
     adapter.adapt_retry_response_from_context(context)
     self.assertEqual(
         self.failed_response['ResponseMetadata']['MaxAttemptsReached'],
         True)
예제 #3
0
 def test_create_context_from_service_error(self):
     context = standard.RetryEventAdapter().create_retry_context(
         response=(self.http_failed, self.failed_response),
         attempts=1,
         caught_exception=None,
         request_dict={'context': {'foo': 'bar'}},
         operation=mock.sentinel.operation_model,
     )
     # We already tested the other attributes in
     # test_create_context_from_success_response so we're only checking
     # the attributes relevant to this test.
     self.assertEqual(context.parsed_response, self.failed_response)
     self.assertEqual(context.http_response, self.http_failed)
예제 #4
0
    def test_create_context_from_success_response(self):
        context = standard.RetryEventAdapter().create_retry_context(
            response=(self.http_success, self.success_response),
            attempts=1,
            caught_exception=None,
            request_dict={'context': {'foo': 'bar'}},
            operation=mock.sentinel.operation_model,
        )

        self.assertEqual(context.attempt_number, 1)
        self.assertEqual(context.operation_model,
                         mock.sentinel.operation_model)
        self.assertEqual(context.parsed_response, self.success_response)
        self.assertEqual(context.http_response, self.http_success)
        self.assertEqual(context.caught_exception, None)
        self.assertEqual(context.request_context, {'foo': 'bar'})
예제 #5
0
def register_retry_handler(client):
    clock = bucket.Clock()
    rate_adjustor = throttling.CubicCalculator(starting_max_rate=0,
                                               start_time=clock.current_time())
    token_bucket = bucket.TokenBucket(max_rate=1, clock=clock)
    rate_clocker = RateClocker(clock)
    throttling_detector = standard.ThrottlingErrorDetector(
        retry_event_adapter=standard.RetryEventAdapter(),
    )
    limiter = ClientRateLimiter(
        rate_adjustor=rate_adjustor,
        rate_clocker=rate_clocker,
        token_bucket=token_bucket,
        throttling_detector=throttling_detector,
        clock=clock,
    )
    client.meta.events.register(
        'before-send', limiter.on_sending_request,
    )
    client.meta.events.register(
        'needs-retry', limiter.on_receiving_response,
    )
    return limiter
예제 #6
0
 def setUp(self):
     self.throttling_detector = standard.ThrottlingErrorDetector(
         standard.RetryEventAdapter())