コード例 #1
0
  def do_request_async(self, url, method='GET', headers=None, payload=None,
                       deadline=None, callback=None):
    """Issue one HTTP request.

    It performs async retries using tasklets.

    Args:
      url: the url to fetch.
      method: the method in which to fetch.
      headers: the http headers.
      payload: the data to submit in the fetch.
      deadline: the deadline in which to make the call.
      callback: the call to make once completed.

    Yields:
      The async fetch of the url.
    """
    retry_wrapper = api_utils._RetryWrapper(
        self.retry_params,
        retriable_exceptions=api_utils._RETRIABLE_EXCEPTIONS,
        should_retry=api_utils._should_retry)
    resp = yield retry_wrapper.run(
        self.urlfetch_async,
        url=url,
        method=method,
        headers=headers,
        payload=payload,
        deadline=deadline,
        callback=callback,
        follow_redirects=False)
    raise ndb.Return((resp.status_code, resp.headers, resp.content))
コード例 #2
0
 def testTooLittleRetry(self):
     fut = api_utils._RetryWrapper(api_utils.RetryParams(min_retries=0,
                                                         max_retries=1),
                                   retriable_exceptions=(ValueError, )).run(
                                       self.tasklet_for_test,
                                       results=[ValueError, ValueError])
     self.assertRaises(ValueError, fut.get_result)
コード例 #3
0
 def testRetryReturnedABadResult(self):
   fut = api_utils._RetryWrapper(
       api_utils.RetryParams(min_retries=1, max_retries=3),
       should_retry=lambda r: r < 0).run(
           self.tasklet_for_test, results=[-1, -1, -1, -1])
   r = fut.get_result()
   self.assertEqual(-1, r)
コード例 #4
0
 def testTooLittleRetry(self):
   fut = api_utils._RetryWrapper(
       api_utils.RetryParams(min_retries=0, max_retries=1),
       retriable_exceptions=(ValueError,)).run(
           self.tasklet_for_test,
           results=[ValueError, ValueError])
   self.assertRaises(ValueError, fut.get_result)
コード例 #5
0
    def do_request_async(self,
                         url,
                         method='GET',
                         headers=None,
                         payload=None,
                         deadline=None,
                         callback=None):
        """Issue one HTTP request.

    It performs async retries using tasklets.

    Args:
      url: the url to fetch.
      method: the method in which to fetch.
      headers: the http headers.
      payload: the data to submit in the fetch.
      deadline: the deadline in which to make the call.
      callback: the call to make once completed.

    Yields:
      The async fetch of the url.
    """
        retry_wrapper = api_utils._RetryWrapper(
            self.retry_params,
            retriable_exceptions=api_utils._RETRIABLE_EXCEPTIONS,
            should_retry=api_utils._should_retry)
        resp = yield retry_wrapper.run(self.urlfetch_async,
                                       url=url,
                                       method=method,
                                       headers=headers,
                                       payload=payload,
                                       deadline=deadline,
                                       callback=callback,
                                       follow_redirects=False)
        raise ndb.Return((resp.status_code, resp.headers, resp.content))
コード例 #6
0
 def testRetryDueToError(self):
     fut = api_utils._RetryWrapper(
         api_utils.RetryParams(min_retries=1, max_retries=3),
         retriable_exceptions=(ValueError, )).run(
             self.tasklet_for_test,
             results=[ValueError, ValueError, ValueError, 1])
     r = fut.get_result()
     self.assertEqual(1, r)
コード例 #7
0
 def testRetryReturnedABadResult(self):
     fut = api_utils._RetryWrapper(api_utils.RetryParams(min_retries=1,
                                                         max_retries=3),
                                   should_retry=lambda r: r < 0).run(
                                       self.tasklet_for_test,
                                       results=[-1, -1, -1, -1])
     r = fut.get_result()
     self.assertEqual(-1, r)
コード例 #8
0
 def testRetryDueToError(self):
   fut = api_utils._RetryWrapper(
       api_utils.RetryParams(min_retries=1, max_retries=3),
       retriable_exceptions=(ValueError,)).run(
           self.tasklet_for_test,
           results=[ValueError, ValueError, ValueError, 1])
   r = fut.get_result()
   self.assertEqual(1, r)
コード例 #9
0
  def testRetryDueToTransientError(self):
    results = [urlfetch.DownloadError, apiproxy_errors.Error,
               app_identity.InternalError, app_identity.BackendDeadlineExceeded,
               urlfetch_errors.InternalTransientError, 1]

    fut = api_utils._RetryWrapper(
        api_utils.RetryParams(min_retries=1, max_retries=len(results)),
        retriable_exceptions=api_utils._RETRIABLE_EXCEPTIONS).run(
            self.tasklet_for_test,
            results=results)
    r = fut.get_result()
    self.assertEqual(1, r)
コード例 #10
0
    def testRetryDueToTransientError(self):
        results = [
            urlfetch.DownloadError, apiproxy_errors.Error,
            app_identity.InternalError, app_identity.BackendDeadlineExceeded,
            urlfetch_errors.InternalTransientError, 1
        ]

        fut = api_utils._RetryWrapper(
            api_utils.RetryParams(min_retries=1, max_retries=len(results)),
            retriable_exceptions=api_utils._RETRIABLE_EXCEPTIONS).run(
                self.tasklet_for_test, results=results)
        r = fut.get_result()
        self.assertEqual(1, r)
コード例 #11
0
 def testNoRetryDueToRetryParams(self):
     retry_params = api_utils.RetryParams(min_retries=0, max_retries=0)
     fut = api_utils._RetryWrapper(retry_params,
                                   retriable_exceptions=[ValueError]).run(
                                       test_tasklet3, a=1)
     self.assertRaises(ValueError, fut.get_result)
コード例 #12
0
 def testTaskletWasSuccessful(self):
     fut = api_utils._RetryWrapper(api_utils.RetryParams()).run(
         test_tasklet1, a=1, b=2)
     a, b = fut.get_result()
     self.assertEqual(1, a)
     self.assertEqual(2, b)
コード例 #13
0
 def testNoRetryDueToErrorType(self):
   fut = api_utils._RetryWrapper(
       api_utils.RetryParams(),
       retriable_exceptions=[TypeError]).run(
           test_tasklet3, a=1)
   self.assertRaises(ValueError, fut.get_result)
コード例 #14
0
 def testNoRetryDueToRetryParams(self):
   retry_params = api_utils.RetryParams(min_retries=0, max_retries=0)
   fut = api_utils._RetryWrapper(
       retry_params, retriable_exceptions=[ValueError]).run(
           test_tasklet3, a=1)
   self.assertRaises(ValueError, fut.get_result)
コード例 #15
0
 def testTaskletWasSuccessful(self):
   fut = api_utils._RetryWrapper(api_utils.RetryParams()).run(
       test_tasklet1, a=1, b=2)
   a, b = fut.get_result()
   self.assertEqual(1, a)
   self.assertEqual(2, b)
コード例 #16
0
 def testNoRetryDueToErrorType(self):
     fut = api_utils._RetryWrapper(api_utils.RetryParams(),
                                   retriable_exceptions=[TypeError]).run(
                                       test_tasklet3, a=1)
     self.assertRaises(ValueError, fut.get_result)
コード例 #17
0
 def testRuntimeError(self):
     fut = api_utils._RetryWrapper(
         api_utils.RetryParams()).run(test_tasklet4)
     self.assertRaises(runtime.DeadlineExceededError, fut.get_result)
コード例 #18
0
 def testRuntimeError(self):
   fut = api_utils._RetryWrapper(
       api_utils.RetryParams()).run(test_tasklet4)
   self.assertRaises(runtime.DeadlineExceededError, fut.get_result)