Ejemplo n.º 1
0
    def test_eventually_stops_retrying(self):
        rest = _RestProxyForTest()
        retrying_rest = RetryingRestProxy(rest, num_tries=3)

        expected_data = {}

        def check_input(data_dict):
            self.assertEqual(expected_data, data_dict)
            return True

        # The retryable errors will eventually no longer be retried.
        rest.expect_post("/test", check_input, 403, {'a': 1})
        rest.expect_post("/test", check_input, 403, {'a': 1})
        rest.expect_post("/test", check_input, 403, {'a': 1})
        code, response = retrying_rest.post("/test", {})
        self.assertEqual(403, code)
        self.assertDictEqual({'a': 1}, response)

        rest.expect_get("/test?a=1&b=2", 502, {'a': 1})
        rest.expect_get("/test?a=1&b=2", 502, {'a': 1})
        rest.expect_get("/test?a=1&b=2", 502, {'a': 1})
        code, response = retrying_rest.get("/test?a=1&b=2")
        self.assertEqual(502, code)
        self.assertDictEqual({'a': 1}, response)

        # Mixing errors is allowed - all count toward the same cumulative total.
        # The error on the final try will be reported.
        rest.expect_delete("/test?a=1&b=2", 403)
        rest.expect_delete("/test?a=1&b=2", 502)
        rest.expect_delete("/test?a=1&b=2", 503)
        code = retrying_rest.delete("/test?a=1&b=2")
        self.assertEqual(503, code)
Ejemplo n.º 2
0
    def test_retry_on_retryable_error(self):
        rest = _RestProxyForTest()
        retrying_rest = RetryingRestProxy(rest)

        expected_data = {}

        def check_input(data_dict):
            self.assertEqual(expected_data, data_dict)
            return True

        # A 403, 502, or 503 results in retrying.
        rest.expect_post("/test", check_input, 403, {'a': 1})
        rest.expect_post("/test", check_input, 200, {'a': 1})
        code, response = retrying_rest.post("/test", {})
        self.assertEqual(200, code)
        self.assertDictEqual({'a': 1}, response)

        rest.expect_get("/test?a=1&b=2", 502, {'a': 1})
        rest.expect_get("/test?a=1&b=2", 200, {'a': 1})
        code, response = retrying_rest.get("/test?a=1&b=2")
        self.assertEqual(200, code)
        self.assertDictEqual({'a': 1}, response)

        rest.expect_delete("/test?a=1&b=2", 503)
        rest.expect_delete("/test?a=1&b=2", 204)
        code = retrying_rest.delete("/test?a=1&b=2")
        self.assertEqual(204, code)
Ejemplo n.º 3
0
    def test_no_retry_on_nonretryable_error(self):
        rest = _RestProxyForTest()
        retrying_rest = RetryingRestProxy(rest)

        expected_data = {}
        def check_input(data_dict):
            self.assertEqual(expected_data, data_dict)
            return True
            
        # An error other than 403, 502, and 503 results in no retrying.
        rest.expect_post("/test", check_input, 404, {'a': 1})
        code, response = retrying_rest.post("/test", {})
        self.assertEqual(404, code)
        self.assertDictEqual({'a': 1}, response)

        rest.expect_get("/test?a=1&b=2", 418, {'a': 1})
        code, response  = retrying_rest.get("/test?a=1&b=2")
        self.assertEqual(418, code)
        self.assertDictEqual({'a': 1}, response)

        rest.expect_delete("/test?a=1&b=2", 500)
        code = retrying_rest.delete("/test?a=1&b=2")
        self.assertEqual(500, code)
Ejemplo n.º 4
0
    def test_good_response(self):
        rest = _RestProxyForTest()
        retrying_rest = RetryingRestProxy(rest)

        expected_data = {}
        def check_input(data_dict):
            self.assertEqual(expected_data, data_dict)
            return True
            
        # A 200 (or 204 for deletes) results in no retrying.
        rest.expect_post("/test", check_input, 200, {'a': 1})
        code, response = retrying_rest.post("/test", {})
        self.assertEqual(200, code)
        self.assertDictEqual({'a': 1}, response)

        rest.expect_get("/test?a=1&b=2", 200, {'a': 1})
        code, response  = retrying_rest.get("/test?a=1&b=2")
        self.assertEqual(200, code)
        self.assertDictEqual({'a': 1}, response)

        rest.expect_delete("/test?a=1&b=2", 204)
        code = retrying_rest.delete("/test?a=1&b=2")
        self.assertEqual(204, code)
Ejemplo n.º 5
0
    def setup(self):
        timer = Timer()
        timer.start("Setup")

        rest = RetryingRestProxy(RestRequests(self.config.get_url()))
        auth = Auth(rest)
        if not auth.authenticate(self.config.get_token()):
            print("Could not authenticate.")
            return False

        self.rest = AuthenticatingRestProxy(rest, self.config.get_token())
        self.projects = Projects(self.rest)
        self.batches = Batches(self.rest)
        self.groups = Groups(self.rest)
        self.permissions = Permissions(self.rest)

        timer.stop()
        return True
Ejemplo n.º 6
0
    def setup(self):
        timer = Timer()
        timer.start("Setup")

        rest = RetryingRestProxy(RestRequests(self.url))
        auth = Auth(rest)
        if not auth.authenticate(self.token):
            print("Could not authenticate.")
            return False

        self.rest = AuthenticatingRestProxy(rest, self.token)
        self.projects = Projects(self.rest)
        self.batches = Batches(self.rest)
        self.groups = Groups(self.rest)
        self.permissions = Permissions(self.rest)
        self.processing_service = AdamProcessingService(self.rest)

        timer.stop()
        return True
Ejemplo n.º 7
0
    def setup(self):
        """Sets up the API client and modules for issuing requests to the ADAM API."""
        timer = Timer()
        timer.start("Setup")

        retrying_rest = RetryingRestProxy(RestRequests())
        self.rest = AuthenticatingRestProxy(retrying_rest)
        auth = Auth(self.rest)
        if not auth.authenticate():
            print("Could not authenticate.")
            return False

        self.projects = ProjectsClient(self.rest)
        self.batches = Batches(self.rest)
        self.groups = Groups(self.rest)
        self.permissions = Permissions(self.rest)
        self.processing_service = AdamProcessingService(self.rest)

        timer.stop()
        return True