summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Charriere <nicholascharriere@gmail.com>2016-10-28 08:23:54 -0700
committerGitHub <noreply@github.com>2016-10-28 08:23:54 -0700
commit29a638a72e8f75b17e1c5eee67ec1ae102e03927 (patch)
treea564f421020ac64f687b7dd4b1bddf72743ecdd5
parentbfea304918cd0b950566f0c15e6bdcc0e5741364 (diff)
parent829d966ed114d84ca6a3e31e71ffc37b56aba933 (diff)
downloadpymemcache-29a638a72e8f75b17e1c5eee67ec1ae102e03927.tar.gz
Merge pull request #125 from kols/pooled-client-noreply
[fix #123] PooledClient now use default_noreply arg set on init
-rw-r--r--pymemcache/client/base.py20
-rw-r--r--pymemcache/test/test_client.py120
2 files changed, 106 insertions, 34 deletions
diff --git a/pymemcache/client/base.py b/pymemcache/client/base.py
index d62dd80..384223f 100644
--- a/pymemcache/client/base.py
+++ b/pymemcache/client/base.py
@@ -884,25 +884,25 @@ class PooledClient(object):
def close(self):
self.client_pool.clear()
- def set(self, key, value, expire=0, noreply=True):
+ def set(self, key, value, expire=0, noreply=None):
with self.client_pool.get_and_release(destroy_on_fail=True) as client:
return client.set(key, value, expire=expire, noreply=noreply)
- def set_many(self, values, expire=0, noreply=True):
+ def set_many(self, values, expire=0, noreply=None):
with self.client_pool.get_and_release(destroy_on_fail=True) as client:
return client.set_many(values, expire=expire, noreply=noreply)
set_multi = set_many
- def replace(self, key, value, expire=0, noreply=True):
+ def replace(self, key, value, expire=0, noreply=None):
with self.client_pool.get_and_release(destroy_on_fail=True) as client:
return client.replace(key, value, expire=expire, noreply=noreply)
- def append(self, key, value, expire=0, noreply=True):
+ def append(self, key, value, expire=0, noreply=None):
with self.client_pool.get_and_release(destroy_on_fail=True) as client:
return client.append(key, value, expire=expire, noreply=noreply)
- def prepend(self, key, value, expire=0, noreply=True):
+ def prepend(self, key, value, expire=0, noreply=None):
with self.client_pool.get_and_release(destroy_on_fail=True) as client:
return client.prepend(key, value, expire=expire, noreply=noreply)
@@ -953,17 +953,17 @@ class PooledClient(object):
else:
raise
- def delete(self, key, noreply=True):
+ def delete(self, key, noreply=None):
with self.client_pool.get_and_release(destroy_on_fail=True) as client:
return client.delete(key, noreply=noreply)
- def delete_many(self, keys, noreply=True):
+ def delete_many(self, keys, noreply=None):
with self.client_pool.get_and_release(destroy_on_fail=True) as client:
return client.delete_many(keys, noreply=noreply)
delete_multi = delete_many
- def add(self, key, value, expire=0, noreply=True):
+ def add(self, key, value, expire=0, noreply=None):
with self.client_pool.get_and_release(destroy_on_fail=True) as client:
return client.add(key, value, expire=expire, noreply=noreply)
@@ -975,7 +975,7 @@ class PooledClient(object):
with self.client_pool.get_and_release(destroy_on_fail=True) as client:
return client.decr(key, value, noreply=noreply)
- def touch(self, key, expire=0, noreply=True):
+ def touch(self, key, expire=0, noreply=None):
with self.client_pool.get_and_release(destroy_on_fail=True) as client:
return client.touch(key, expire=expire, noreply=noreply)
@@ -993,7 +993,7 @@ class PooledClient(object):
with self.client_pool.get_and_release(destroy_on_fail=True) as client:
return client.version()
- def flush_all(self, delay=0, noreply=True):
+ def flush_all(self, delay=0, noreply=None):
with self.client_pool.get_and_release(destroy_on_fail=True) as client:
return client.flush_all(delay=delay, noreply=noreply)
diff --git a/pymemcache/test/test_client.py b/pymemcache/test/test_client.py
index 6d658f5..ab72652 100644
--- a/pymemcache/test/test_client.py
+++ b/pymemcache/test/test_client.py
@@ -637,45 +637,61 @@ class TestClient(ClientTestMixin, unittest.TestCase):
with pytest.raises(MemcacheClientError):
client.get(u'\u3053\u3093\u306b\u3061\u306f')
- def test_default_noreply_set(self):
- client = self.make_client([b'STORED\r\n'], default_noreply=False)
- result = client.set(b'key', b'value')
+ def _default_noreply_false(self, cmd, args, response):
+ client = self.make_client(response, default_noreply=False)
+ result = getattr(client, cmd)(*args)
+ assert result is False
+
+ def _default_noreply_true(self, cmd, args, response):
+ client = self.make_client(response, default_noreply=True)
+ result = getattr(client, cmd)(*args)
assert result is True
+ def test_default_noreply_set(self):
+ with pytest.raises(MemcacheUnknownError):
+ self._default_noreply_false(
+ 'set', (b'key', b'value'), [b'NOT_STORED\r\n'])
+ self._default_noreply_true(
+ 'set', (b'key', b'value'), [b'NOT_STORED\r\n'])
+
def test_default_noreply_set_many(self):
- client = self.make_client([b'STORED\r\n'], default_noreply=False)
- result = client.set_many({b'key': b'value'})
- assert result is True
+ with pytest.raises(MemcacheUnknownError):
+ self._default_noreply_false(
+ 'set_many', ({b'key': b'value'},), [b'NOT_STORED\r\n'])
+ self._default_noreply_true(
+ 'set_many', ({b'key': b'value'},), [b'NOT_STORED\r\n'])
def test_default_noreply_add(self):
- client = self.make_client([b'STORED\r', b'\n'], default_noreply=False)
- result = client.add(b'key', b'value')
- assert result is True
+ self._default_noreply_false(
+ 'add', (b'key', b'value'), [b'NOT_STORED\r\n'])
+ self._default_noreply_true(
+ 'add', (b'key', b'value'), [b'NOT_STORED\r\n'])
def test_default_noreply_replace(self):
- client = self.make_client([b'STORED\r\n'], default_noreply=False)
- result = client.replace(b'key', b'value')
- assert result is True
+ self._default_noreply_false(
+ 'replace', (b'key', b'value'), [b'NOT_STORED\r\n'])
+ self._default_noreply_true(
+ 'replace', (b'key', b'value'), [b'NOT_STORED\r\n'])
def test_default_noreply_append(self):
- client = self.make_client([b'STORED\r\n'], default_noreply=False)
- result = client.append(b'key', b'value')
- assert result is True
+ self._default_noreply_false(
+ 'append', (b'key', b'value'), [b'NOT_STORED\r\n'])
+ self._default_noreply_true(
+ 'append', (b'key', b'value'), [b'NOT_STORED\r\n'])
def test_default_noreply_prepend(self):
- client = self.make_client([b'STORED\r\n'], default_noreply=False)
- result = client.prepend(b'key', b'value')
- assert result is True
+ self._default_noreply_false(
+ 'prepend', (b'key', b'value'), [b'NOT_STORED\r\n'])
+ self._default_noreply_true(
+ 'prepend', (b'key', b'value'), [b'NOT_STORED\r\n'])
def test_default_noreply_touch(self):
- client = self.make_client([b'TOUCHED\r\n'], default_noreply=False)
- result = client.touch(b'key')
- assert result is True
+ self._default_noreply_false('touch', (b'key',), [b'NOT_FOUND\r\n'])
+ self._default_noreply_true('touch', (b'key',), [b'NOT_FOUND\r\n'])
def test_default_noreply_flush_all(self):
- client = self.make_client([b'OK\r\n'], default_noreply=False)
- result = client.flush_all()
- assert result is True
+ self._default_noreply_false('flush_all', (), [b'__FAKE_RESPONSE__\r\n'])
+ self._default_noreply_true('flush_all', (), [b'__FAKE_RESPONSE__\r\n'])
def test_version_success(self):
client = self.make_client([b'VERSION 1.2.3\r\n'],
@@ -725,6 +741,62 @@ class TestPooledClient(ClientTestMixin, unittest.TestCase):
client.client_pool = pool.ObjectPool(lambda: mock_client)
return client
+ def _default_noreply_false(self, cmd, args, response):
+ client = self.make_client(response, default_noreply=False)
+ result = getattr(client, cmd)(*args)
+ assert result is False
+
+ def _default_noreply_true(self, cmd, args, response):
+ client = self.make_client(response, default_noreply=True)
+ result = getattr(client, cmd)(*args)
+ assert result is True
+
+ def test_default_noreply_set(self):
+ with pytest.raises(MemcacheUnknownError):
+ self._default_noreply_false(
+ 'set', (b'key', b'value'), [b'NOT_STORED\r\n'])
+ self._default_noreply_true(
+ 'set', (b'key', b'value'), [b'NOT_STORED\r\n'])
+
+ def test_default_noreply_set_many(self):
+ with pytest.raises(MemcacheUnknownError):
+ self._default_noreply_false(
+ 'set_many', ({b'key': b'value'},), [b'NOT_STORED\r\n'])
+ self._default_noreply_true(
+ 'set_many', ({b'key': b'value'},), [b'NOT_STORED\r\n'])
+
+ def test_default_noreply_add(self):
+ self._default_noreply_false(
+ 'add', (b'key', b'value'), [b'NOT_STORED\r\n'])
+ self._default_noreply_true(
+ 'add', (b'key', b'value'), [b'NOT_STORED\r\n'])
+
+ def test_default_noreply_replace(self):
+ self._default_noreply_false(
+ 'replace', (b'key', b'value'), [b'NOT_STORED\r\n'])
+ self._default_noreply_true(
+ 'replace', (b'key', b'value'), [b'NOT_STORED\r\n'])
+
+ def test_default_noreply_append(self):
+ self._default_noreply_false(
+ 'append', (b'key', b'value'), [b'NOT_STORED\r\n'])
+ self._default_noreply_true(
+ 'append', (b'key', b'value'), [b'NOT_STORED\r\n'])
+
+ def test_default_noreply_prepend(self):
+ self._default_noreply_false(
+ 'prepend', (b'key', b'value'), [b'NOT_STORED\r\n'])
+ self._default_noreply_true(
+ 'prepend', (b'key', b'value'), [b'NOT_STORED\r\n'])
+
+ def test_default_noreply_touch(self):
+ self._default_noreply_false('touch', (b'key',), [b'NOT_FOUND\r\n'])
+ self._default_noreply_true('touch', (b'key',), [b'NOT_FOUND\r\n'])
+
+ def test_default_noreply_flush_all(self):
+ self._default_noreply_false('flush_all', (), [b'__FAKE_RESPONSE__\r\n'])
+ self._default_noreply_true('flush_all', (), [b'__FAKE_RESPONSE__\r\n'])
+
class TestMockClient(ClientTestMixin, unittest.TestCase):
def make_client(self, mock_socket_values, **kwargs):