예제 #1
0
 def test_exceed_max_retry_count(self, number_sequence_func,
                                 exp_backoff_with_max_retry_count_policy):
     with pytest.raises(MaxRetryError) as e, mock.patch.object(
             exp_backoff_with_max_retry_count_policy.backoff_policy,
             'next_backoff_delay',
             return_value=0.1) as next_backoff_delay_spy:
         retry_on_condition(
             retry_policy=exp_backoff_with_max_retry_count_policy,
             retry_conditions=[Predicate(self.always_true)],
             func_to_retry=number_sequence_func)
     assert number_sequence_func.call_count == self.max_retry_count + 1
     assert e.value.last_result == 4
     assert next_backoff_delay_spy.call_count == self.max_retry_count
예제 #2
0
 def test_no_retry(self, number_sequence_func,
                   exp_backoff_with_max_retry_count_policy):
     actual = retry_on_condition(
         retry_policy=exp_backoff_with_max_retry_count_policy,
         retry_conditions=[Predicate(self.always_false)],
         func_to_retry=number_sequence_func)
     assert actual == 1
     assert number_sequence_func.call_count == 1
예제 #3
0
 def test_exceed_max_retry_count(
     self,
     number_sequence_func,
     exp_backoff_with_max_retry_count_policy
 ):
     with pytest.raises(MaxRetryError) as e, mock.patch.object(
         exp_backoff_with_max_retry_count_policy.backoff_policy,
         'next_backoff_delay',
         return_value=0.1
     ) as next_backoff_delay_spy:
         retry_on_condition(
             retry_policy=exp_backoff_with_max_retry_count_policy,
             retry_conditions=[Predicate(self.always_true)],
             func_to_retry=number_sequence_func
         )
     assert number_sequence_func.call_count == self.max_retry_count + 1
     assert e.value.last_result == 4
     assert next_backoff_delay_spy.call_count == self.max_retry_count
예제 #4
0
 def test_use_previous_result_as_params_in_retry(
         self, return_true_then_false_func,
         exp_backoff_with_max_retry_count_policy):
     actual = retry_on_condition(
         retry_policy=exp_backoff_with_max_retry_count_policy,
         retry_conditions=[Predicate(return_true_then_false_func)],
         func_to_retry=lambda i: i + i + i,
         use_previous_result_as_param=True,
         i=1)
     assert actual == 9
예제 #5
0
 def test_no_retry(
     self,
     number_sequence_func,
     exp_backoff_with_max_retry_count_policy
 ):
     actual = retry_on_condition(
         retry_policy=exp_backoff_with_max_retry_count_policy,
         retry_conditions=[Predicate(self.always_false)],
         func_to_retry=number_sequence_func
     )
     assert actual == 1
     assert number_sequence_func.call_count == 1
예제 #6
0
 def test_use_previous_result_as_params_in_retry(
     self,
     return_true_then_false_func,
     exp_backoff_with_max_retry_count_policy
 ):
     actual = retry_on_condition(
         retry_policy=exp_backoff_with_max_retry_count_policy,
         retry_conditions=[Predicate(return_true_then_false_func)],
         func_to_retry=lambda i: i + i + i,
         use_previous_result_as_param=True,
         i=1
     )
     assert actual == 9
예제 #7
0
    def _publish_produce_requests(self, requests):
        """It will try to publish all the produce requests for topics, and
        retry a number of times until either all the requests are successfully
        published or it can no longer retry, in which case, the exception will
        be thrown.

        Each time the requests that are successfully published in the previous
        round will be removed from the requests and won't be published again.
        """
        unpublished_requests = list(requests)
        retry_handler = RetryHandler(self.kafka_client, unpublished_requests)

        def has_requests_to_be_sent():
            return bool(retry_handler.requests_to_be_sent)

        retry_handler = retry_on_condition(
            retry_policy=self._publish_retry_policy,
            retry_conditions=[Predicate(has_requests_to_be_sent)],
            func_to_retry=self._publish_requests,
            use_previous_result_as_param=True,
            retry_handler=retry_handler)
        if retry_handler.has_unpublished_request:
            raise MaxRetryError(last_result=retry_handler)
예제 #8
0
    def _publish_produce_requests(self, requests):
        """It will try to publish all the produce requests for topics, and
        retry a number of times until either all the requests are successfully
        published or it can no longer retry, in which case, the exception will
        be thrown.

        Each time the requests that are successfully published in the previous
        round will be removed from the requests and won't be published again.
        """
        unpublished_requests = list(requests)
        retry_handler = RetryHandler(self.kafka_client, unpublished_requests)

        def has_requests_to_be_sent():
            return bool(retry_handler.requests_to_be_sent)

        retry_handler = retry_on_condition(
            retry_policy=self._publish_retry_policy,
            retry_conditions=[Predicate(has_requests_to_be_sent)],
            func_to_retry=self._publish_requests,
            use_previous_result_as_param=True,
            retry_handler=retry_handler
        )
        if retry_handler.has_unpublished_request:
            raise MaxRetryError(last_result=retry_handler)