summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiangge Zhang <tonyseek@gmail.com>2017-04-17 14:54:06 +0800
committerJiangge Zhang <tonyseek@gmail.com>2017-04-17 15:51:34 +0800
commite5cb097582e77094cd5fb8f034e803f9be0f2c0d (patch)
tree228973de24fa14ffcc7b5652a16b5960c41f1acf
parentf1b7edf0511023ad071151737cd262c9d7dbaa76 (diff)
downloadkazoo-e5cb097582e77094cd5fb8f034e803f9be0f2c0d.tar.gz
Closed tree cache could not be started again
-rw-r--r--kazoo/recipe/cache.py5
-rw-r--r--kazoo/tests/test_cache.py9
2 files changed, 13 insertions, 1 deletions
diff --git a/kazoo/recipe/cache.py b/kazoo/recipe/cache.py
index 525154a..bf6b92f 100644
--- a/kazoo/recipe/cache.py
+++ b/kazoo/recipe/cache.py
@@ -62,6 +62,8 @@ class TreeCache(object):
"""
if self._state == self.STATE_LATENT:
self._state = self.STATE_STARTED
+ elif self._state == self.STATE_CLOSED:
+ raise KazooException('already closed')
else:
raise KazooException('already started')
@@ -77,6 +79,9 @@ class TreeCache(object):
A closed cache was detached from ZooKeeper's changes. And all nodes
will be invalidated.
+ Once a tree cache was closed, it could not be started again. You should
+ only close a tree cache while you want to recycle it.
+
.. note::
This method is not thread safe.
diff --git a/kazoo/tests/test_cache.py b/kazoo/tests/test_cache.py
index 2e3312e..91aad05 100644
--- a/kazoo/tests/test_cache.py
+++ b/kazoo/tests/test_cache.py
@@ -62,10 +62,17 @@ class KazooTreeCacheTests(KazooTestCase):
eq_(self.cache._root._state, TreeNode.STATE_LIVE)
@raises(KazooException)
- def test_start_twice(self):
+ def test_start_started(self):
self.make_cache()
self.cache.start()
+ @raises(KazooException)
+ def test_start_closed(self):
+ self.make_cache()
+ self.cache.start()
+ self.cache.close()
+ self.cache.start()
+
def test_close(self):
self.make_cache()
self.wait_cache(since=TreeEvent.INITIALIZED)