Esempio n. 1
0
 def test_quota_reached_adds_retry_metadata(self):
     quota_checker = standard.RetryQuotaChecker(
         quota.RetryQuota(initial_capacity=0))
     context = self.create_context()
     self.assertFalse(quota_checker.acquire_retry_quota(context))
     self.assertEqual(context.get_retry_metadata(),
                      {'RetryQuotaReached': True})
Esempio n. 2
0
 def test_acquire_quota_fails(self):
     quota_checker = standard.RetryQuotaChecker(
         quota.RetryQuota(initial_capacity=5))
     # The first one succeeds.
     self.assertTrue(
         quota_checker.acquire_retry_quota(self.create_context()))
     # But we should fail now because we're out of quota.
     self.request_context.pop('retry_quota_capacity')
     self.assertFalse(
         quota_checker.acquire_retry_quota(self.create_context()))
     self.assertNotIn('retry_quota_capacity', self.request_context)
Esempio n. 3
0
def register_retry_handler(client, max_attempts=DEFAULT_MAX_ATTEMPTS):
    retry_quota = RetryQuotaChecker(quota.RetryQuota())

    service_id = client.meta.service_model.service_id
    service_event_name = service_id.hyphenize()
    client.meta.events.register('after-call.%s' % service_event_name,
                                retry_quota.release_retry_quota)

    handler = RetryHandler(
        retry_policy=RetryPolicy(
            retry_checker=StandardRetryConditions(max_attempts=max_attempts),
            retry_backoff=ExponentialBackoff(),
        ),
        retry_event_adapter=RetryEventAdapter(),
        retry_quota=retry_quota,
    )

    unique_id = 'retry-config-%s' % service_event_name
    client.meta.events.register('needs-retry.%s' % service_event_name,
                                handler.needs_retry,
                                unique_id=unique_id)
    return handler
Esempio n. 4
0
 def setUp(self):
     self.quota = quota.RetryQuota(500)
     self.quota_checker = standard.RetryQuotaChecker(self.quota)
     self.request_context = {}
Esempio n. 5
0
 def setUp(self):
     self.retry_quota = quota.RetryQuota(50)
Esempio n. 6
0
 def setUp(self):
     self.max_capacity = 50
     self.retry_quota = quota.RetryQuota(self.max_capacity)
     self.shutdown_threads = False
     self.seen_capacities = []