def test_with_default_values(): times = conf.retry_seconds_to_sleep_list() max_retries = conf.configurable_retry_policy_max_retries() policy = ConfigurableRetryPolicy(times, max_retries) assert_equals(times[0], policy.seconds_to_sleep(0)) assert_equals(times[0], policy.seconds_to_sleep(1)) assert_equals(times[1], policy.seconds_to_sleep(2)) assert_equals(times[2], policy.seconds_to_sleep(3)) assert_equals(times[3], policy.seconds_to_sleep(4)) assert_equals(times[4], policy.seconds_to_sleep(5)) assert_equals(times[4], policy.seconds_to_sleep(6)) assert_equals(times[4], policy.seconds_to_sleep(7)) assert_equals(times[4], policy.seconds_to_sleep(8)) assert_equals(times[4], policy.seconds_to_sleep(9)) # Check based on retry count assert_equals(True, policy.should_retry(500, False, 0)) assert_equals(True, policy.should_retry(500, False, 7)) assert_equals(True, policy.should_retry(500, False, 8)) assert_equals(False, policy.should_retry(500, False, 9)) # Check based on status code assert_equals(False, policy.should_retry(201, False, 0)) assert_equals(False, policy.should_retry(201, False, 9)) # Check based on error assert_equals(True, policy.should_retry(201, True, 0)) assert_equals(True, policy.should_retry(201, True, 9))
def _get_retry_policy(): policy = conf.retry_policy() if policy == LINEAR_RETRY: return LinearRetryPolicy(seconds_to_sleep=5, max_retries=5) elif policy == CONFIGURABLE_RETRY: return ConfigurableRetryPolicy( retry_seconds_to_sleep_list=conf.retry_seconds_to_sleep_list(), max_retries=conf.configurable_retry_policy_max_retries()) else: raise BadUserConfigurationException( u"Retry policy '{}' not supported".format(policy))
def test_retry_policy(): # Default is configurable retry times = conf.retry_seconds_to_sleep_list() max_retries = conf.configurable_retry_policy_max_retries() policy = LivyReliableHttpClient._get_retry_policy() assert type(policy) is ConfigurableRetryPolicy assert_equals(times, policy.retry_seconds_to_sleep_list) assert_equals(max_retries, policy.max_retries) # Configure to linear retry _override_policy(constants.LINEAR_RETRY) policy = LivyReliableHttpClient._get_retry_policy() assert type(policy) is LinearRetryPolicy assert_equals(5, policy.seconds_to_sleep(1)) assert_equals(5, policy.max_retries) # Configure to something invalid _override_policy("garbage") try: policy = LivyReliableHttpClient._get_retry_policy() assert False except BadUserConfigurationException: assert True