예제 #1
0
 def test_do_not_retry_for_exception_success(self):
     # Test that we retry for exceptions not specified.
     client = self.make_client(
         [MemcacheClientError("Whoops."), b"VALUE key 0 5\r\nvalue\r\nEND\r\n"],
         attempts=2,
         do_not_retry_for=tuple([MemcacheUnknownError]),
     )
     result = client.get("key")
     assert result == b"value"
예제 #2
0
 def test_retry_for_exception_success(self):
     # Test that we retry for the exception specified.
     client = self.make_client([
         MemcacheClientError("Whoops."),
         b'VALUE key 0 5\r\nvalue\r\nEND\r\n'
     ],
                               attempts=2,
                               retry_for=tuple([MemcacheClientError]))
     result = client.get("key")
     assert result == b'value'
예제 #3
0
    def test_do_not_retry_for_exception_fail(self):
        # Test that we do not retry for the exception specified.
        client = self.make_client(
            [MemcacheClientError("Whoops."), b"VALUE key 0 5\r\nvalue\r\nEND\r\n"],
            attempts=2,
            do_not_retry_for=tuple([MemcacheClientError]),
        )

        with pytest.raises(MemcacheClientError):
            client.get("key")
예제 #4
0
    def _raise_errors(self, line, name):
        if line.startswith(b'ERROR'):
            raise MemcacheUnknownCommandError(name)

        if line.startswith(b'CLIENT_ERROR'):
            error = line[line.find(b' ') + 1:]
            raise MemcacheClientError(error)

        if line.startswith(b'SERVER_ERROR'):
            error = line[line.find(b' ') + 1:]
            raise MemcacheServerError(error)
예제 #5
0
    def test_both_exception_filters(self):
        # Test interacction between both exception filters.
        client = self.make_client([
            MemcacheClientError("Whoops."),
            b'VALUE key 0 5\r\nvalue\r\nEND\r\n',
            MemcacheUnknownError("Whoops."),
            b'VALUE key 0 5\r\nvalue\r\nEND\r\n',
        ],
                                  attempts=2,
                                  retry_for=tuple([MemcacheClientError]),
                                  do_not_retry_for=tuple(
                                      [MemcacheUnknownError]))

        # Check that we succeed where allowed.
        result = client.get("key")
        assert result == b'value'

        # Check that no retries are attempted for the banned exception.
        with pytest.raises(MemcacheUnknownError):
            client.get("key")
예제 #6
0
파일: utils.py 프로젝트: jparise/pymemcache
 def cas(self, key, value, cas, expire=0, noreply=False, flags=None):
     raise MemcacheClientError("CAS is not enabled for this instance")