Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #3 from hannosch/master

Change last_modified to Zookeeper mtime and some stuff
  • Loading branch information...
commit 12b17c1509dc8d19ddae0b8b2faa403541bf9167 2 parents 7e30f02 + 7d55c3f
@bbangert bbangert authored
View
2  .gitignore
@@ -23,5 +23,7 @@ docs/_build
bin/
lib/
include/
+zookeeper/
+zookeeper.out
.idea/
distribute-*.tar.gz
View
10 CHANGES.rst
@@ -1,6 +1,16 @@
Changelog
=========
+0.3 (unreleased)
+----------------
+
+Changes
+*******
+
+- Use the Zookeeper-provided mtime of a node as the last_modified
+ attribute, instead of client specific time.time()
+
+
0.2.1 (02/16/2012)
------------------
View
20 Makefile
@@ -1,5 +1,8 @@
+APPNAME = zktools
HERE = $(shell pwd)
BIN = $(HERE)/bin
+NOSE = $(BIN)/nosetests -s --with-xunit
+PYTHON = $(BIN)/python
ZOOKEEPER = $(BIN)/zookeeper
.PHONY: zookeeper
@@ -7,9 +10,24 @@ ZOOKEEPER = $(BIN)/zookeeper
$(ZOOKEEPER):
mkdir -p bin
cd bin && \
- curl --silent http://mirrors.ibiblio.org/apache//zookeeper/stable/zookeeper-3.3.4.tar.gz | tar -zvx
+ curl --silent http://mirrors.ibiblio.org/apache//zookeeper/stable/zookeeper-3.3.4.tar.gz | tar -zx
mv bin/zookeeper-3.3.4 bin/zookeeper
cd bin/zookeeper && ant compile
cp zoo.cfg bin/zookeeper/conf/
zookeeper: $(ZOOKEEPER)
+
+all: build
+
+$(BIN)/python:
+ virtualenv-2.6 --no-site-packages --distribute .
+
+build: $(BIN)/python
+ $(PYTHON) setup.py develop
+ $(BIN)/pip install nose
+ $(BIN)/pip install Mock
+
+test:
+ $(BIN)/zookeeper/bin/zkServer.sh start $(HERE)/zoo.cfg
+ $(NOSE) --with-coverage --cover-package=$(APPNAME) --cover-inclusive $(APPNAME)
+ $(BIN)/zookeeper/bin/zkServer.sh stop $(HERE)/zoo.cfg
View
4 README.rst
@@ -12,8 +12,8 @@ It currently provides:
in Zookeeper nodes.
* ``Locks`` - A Zookeeper lock with support for
non-blocking acquire, modeled on Python's Lock objects that also includes a
- `Revocable Shared Locks with Freaking Laser Beams` described in the
- `Zookeeper Recipe's
+ `Revocable Shared Locks with Freaking Laser Beams` described in the
+ `Zookeeper Recipe's
<http://zookeeper.apache.org/doc/current/recipes.html#sc_recoverableSharedLocks>`_.
See `the full docs`_ for more information.
View
16 zktools/node.py
@@ -11,7 +11,6 @@
import decimal
import json
import re
-import time
import threading
import UserDict
@@ -146,7 +145,8 @@ def __init__(self, connection, path, default=None, use_json=False,
The last time a :class:`ZkNode` has been modified either by
the user or due to a Zookeeper update is recorded as the
- :obj:`ZkNode.last_modified` attribute.
+ :obj:`ZkNode.last_modified` attribute, as a long in
+ milliseconds from epoch.
:param connection: Zookeeper connection object
:type connection: zc.zk Zookeeper instance
@@ -168,7 +168,6 @@ def __init__(self, connection, path, default=None, use_json=False,
self._use_json = use_json
self._value = None
self._reload_data = False
- self.last_modified = time.time()
with self._cv:
if not connection.exists(path, self._created_watcher):
@@ -191,9 +190,9 @@ def _node_watcher(self, handle, type, state, path):
"""Watch a node for updates"""
with self._cv:
if type == zookeeper.CHANGED_EVENT:
- data = self._zk.get(self._path, self._node_watcher)[0]
- self._value = _load_value(data, use_json=self._use_json)
- self.last_modified = time.time()
+ data = self._zk.get(self._path, self._node_watcher)
+ self.last_modified = data[1][u'mtime']
+ self._value = _load_value(data[0], use_json=self._use_json)
elif type in (zookeeper.EXPIRED_SESSION_STATE,
zookeeper.AUTH_FAILED_STATE):
self._reload_data = True
@@ -202,8 +201,9 @@ def _node_watcher(self, handle, type, state, path):
def _load(self):
"""Load data from the node, and coerce as necessary"""
with self._cv:
- data = self._zk.get(self._path, self._node_watcher)[0]
- self._value = _load_value(data, use_json=self._use_json)
+ data = self._zk.get(self._path, self._node_watcher)
+ self.last_modified = data[1][u'mtime']
+ self._value = _load_value(data[0], use_json=self._use_json)
@property
def value(self):
View
4 zktools/tests/test_node.py
@@ -27,13 +27,17 @@ def testUpdateValue(self):
n2 = self.makeOne('/zkTestNode')
eq_(n1.value, n2.value)
+ eq_(n1.last_modified, n2.last_modified)
+ old_modified = n1.last_modified
n1.value = 942
# It can take a fraction of a second on some machines on occasion
# for the other value to update
time.sleep(0.1)
eq_(n1.value, n2.value)
+ eq_(n1.last_modified, n2.last_modified)
+ self.assertTrue(n1.last_modified > old_modified)
def testJsonValue(self):
n1 = self.makeOne('/zkTestNode', use_json=True)
Please sign in to comment.
Something went wrong with that request. Please try again.