示例#1
0
 def testMaxTries(self):
   """Test retry scenario in which the RetryPolicy max_tries is exceeded."""
   retry_policy = retry.RetryPolicy(max_tries=10, check_result=lambda res, err: True)
   retry.CallWithRetryAsync(retry_policy, self._AsyncFunc, callback=self._OnCompleted)
   self.wait()
   self.assertLogMatches('Retrying.*Retrying.*Retrying.*Retrying.*Retrying.*Retrying.*Retrying.*Retrying.*Retrying',
                         'Expected 9 retries in the log')
示例#2
0
 def testTimeoutAndDelays(self):
   """Test retry scenario in which the RetryPolicy timeout is exceeded."""
   retry_policy = retry.RetryPolicy(timeout=.6, min_delay=.05, max_delay=.2, check_result=lambda res, err: True)
   retry.CallWithRetryAsync(retry_policy, self._AsyncFunc, callback=self._OnCompleted)
   self.wait()
   self.assertLogMatches('Retrying.*Retrying.*Retrying',
                         'Expected at least 3 retries in the log')
示例#3
0
        def _Migrate(start_rank, mutate_item):
            last_rank = 0
            for version in versions:
                if version.rank < start_rank:
                    last_rank = version.rank
                    continue
                assert version.rank > last_rank, \
                    'tags listed out of order (! %d > %d)' % (version.rank, last_rank)
                last_rank = version.rank
                item_version = mutate_item._version or 0
                if item_version < version.rank:
                    logging.debug('upgrading item from %s to version %s' %
                                  (type(mutate_item)._table.name,
                                   version.__class__.__name__))
                    mutate_item._version = version.rank

                    # If Transform fails, retry several times before giving up.
                    transform_callback = partial(_Migrate, last_rank + 1)
                    retry.CallWithRetryAsync(Version._migrate_retry_policy,
                                             version.Transform,
                                             client,
                                             mutate_item,
                                             callback=transform_callback)
                    return

            callback(mutate_item if Version._mutate_items else original_item)
示例#4
0
 def testWithStackContext2(self):
   """Ensure Retry doesn't interfere with asynchronous function that throws immediately."""
   try:
     with stack_context.ExceptionStackContext(self._OnError):
       retry.CallWithRetryAsync(retry.RetryPolicy(), self._AsyncFuncRaisesError,
                                callback=self._OnCompleted)
     self.assert_(False, 'Expected exception to be raised')
   except:
     self.wait()
示例#5
0
  def testRetryWithException2(self):
    """Retry on exceptions raised by async function after stack transfer."""
    def CallAfterStackTransfer(dict, callback):
      func = functools.partial(self._AsyncFuncRaisesErrorOnce, dict, callback)
      self.io_loop.add_callback(func)

    retry_policy = retry.RetryPolicy(max_tries=3, check_exception=lambda typ, val, tb: True)
    retry.CallWithRetryAsync(retry_policy, CallAfterStackTransfer, dict(), callback=self.stop)
    self.wait()
示例#6
0
 def testWithStackContext3(self):
   """Ensure Retry doesn't interfere with asynchronous callback that throws."""
   try:
     with stack_context.ExceptionStackContext(self._OnError):
       retry.CallWithRetryAsync(retry.RetryPolicy(check_exception=lambda typ, val, tb: True), self._AsyncFunc,
                                callback=self._OnCompletedRaisesError)
     self.wait()
     self.assert_(False, 'Expected exception to be raised')
   except Exception as e:
     self.assert_('_OnCompletedRaisesError' in e.message, e)
示例#7
0
  def testWithStackContext1(self):
    """Ensure Retry preserves StackContext."""
    self.__in_context = False

    @contextlib.contextmanager
    def _MyContext():
      try:
        self.__in_context = True
        yield
      finally:
        self.__in_context = False

    def _OnCompletedCheckContext(result, error):
      self.assertTrue(self.__in_context)
      self.stop()

    with stack_context.StackContext(_MyContext):
      retry_policy = retry.RetryPolicy(max_tries=2, check_result=lambda res, err: err)
      retry.CallWithRetryAsync(retry_policy, self._AsyncFuncFailOnce, callback=_OnCompletedCheckContext)
    self.wait()
示例#8
0
 def testWithBarrier(self):
   """Ensure Retry doesn't interfere with barriers."""
   retry_policy = retry.RetryPolicy(max_tries=2, check_result=lambda res, err: err)
   with util.MonoBarrier(self._OnCompleted) as b:
     retry.CallWithRetryAsync(retry_policy, self._AsyncFuncFailOnce, callback=b.Callback())
   self.wait()
示例#9
0
 def CallWithRetry():
   retry_policy = retry.RetryPolicy(max_tries=3, check_exception=lambda typ, val, tb: True)
   retry.CallWithRetryAsync(retry_policy, self._AsyncFuncRaisesErrorOnce, dict(), callback=self.stop)