[CalendarServer-changes] [2459] CalendarServer/branches/unified-cache/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Fri May 23 11:58:24 PDT 2008


Revision: 2459
          http://trac.macosforge.org/projects/calendarserver/changeset/2459
Author:   dreid at apple.com
Date:     2008-05-23 11:58:21 -0700 (Fri, 23 May 2008)

Log Message:
-----------
make updateCTag return a deferred, make unittests pass.  Next Up: Drop the deferred on the floor less.

Modified Paths:
--------------
    CalendarServer/branches/unified-cache/twistedcaldav/cache.py
    CalendarServer/branches/unified-cache/twistedcaldav/directory/calendaruserproxy.py
    CalendarServer/branches/unified-cache/twistedcaldav/directory/principal.py
    CalendarServer/branches/unified-cache/twistedcaldav/directory/test/test_principal.py
    CalendarServer/branches/unified-cache/twistedcaldav/directory/test/test_sudo.py
    CalendarServer/branches/unified-cache/twistedcaldav/resource.py
    CalendarServer/branches/unified-cache/twistedcaldav/static.py
    CalendarServer/branches/unified-cache/twistedcaldav/test/test_cache.py
    CalendarServer/branches/unified-cache/twistedcaldav/test/test_resource.py
    CalendarServer/branches/unified-cache/twistedcaldav/test/test_static.py
    CalendarServer/branches/unified-cache/twistedcaldav/test/util.py

Modified: CalendarServer/branches/unified-cache/twistedcaldav/cache.py
===================================================================
--- CalendarServer/branches/unified-cache/twistedcaldav/cache.py	2008-05-23 18:06:05 UTC (rev 2458)
+++ CalendarServer/branches/unified-cache/twistedcaldav/cache.py	2008-05-23 18:58:21 UTC (rev 2459)
@@ -48,7 +48,7 @@
 
 
 
-class CacheChangeNotifier(LoggingMixIn):
+class XattrCacheChangeNotifier(LoggingMixIn):
     def __init__(self, propertyStore):
         self._propertyStore = propertyStore
         self._token = None
@@ -59,10 +59,16 @@
 
 
     def changed(self):
+        """
+        Change the cache token for a resource.
+
+        return: A L{Deferred} that fires when the token has been changed.
+        """
         self.log_debug("Changing Cache Token for %r" % (
                 self._propertyStore))
         property = CacheTokensProperty.fromString(self._newCacheToken())
         self._propertyStore.set(property)
+        return succeed(True)
 
 
 class BaseResponseCache(LoggingMixIn):

Modified: CalendarServer/branches/unified-cache/twistedcaldav/directory/calendaruserproxy.py
===================================================================
--- CalendarServer/branches/unified-cache/twistedcaldav/directory/calendaruserproxy.py	2008-05-23 18:06:05 UTC (rev 2458)
+++ CalendarServer/branches/unified-cache/twistedcaldav/directory/calendaruserproxy.py	2008-05-23 18:58:21 UTC (rev 2459)
@@ -22,7 +22,7 @@
     "CalendarUserProxyPrincipalResource",
 ]
 
-from twisted.internet.defer import succeed
+from twisted.internet.defer import succeed, inlineCallbacks
 from twisted.web2 import responsecode
 from twisted.web2.dav import davxml
 from twisted.web2.dav.element.base import dav_namespace
@@ -154,6 +154,7 @@
 
         return super(CalendarUserProxyPrincipalResource, self).writeProperty(property, request)
 
+    @inlineCallbacks
     def setGroupMemberSet(self, new_members, request):
         # FIXME: as defined right now it is not possible to specify a calendar-user-proxy group as
         # a member of any other group since the directory service does not know how to lookup
@@ -178,14 +179,15 @@
                     "Attempt to use a non-existent principal %s as a group member of %s." % (uri, self.principalURL(),)
                 ))
             principals.append(principal)
-            principal.cacheNotifier.changed()
+            changed = yield principal.cacheNotifier.changed()
 
         # Map the principals to UIDs.
         uids = [p.principalUID() for p in principals]
 
         self._index().setGroupMembers(self.uid, uids)
-        self.parent.cacheNotifier.changed()
-        return succeed(True)
+        changed = yield self.parent.cacheNotifier.changed()
+        yield True
+        return
 
     ##
     # HTTP

Modified: CalendarServer/branches/unified-cache/twistedcaldav/directory/principal.py
===================================================================
--- CalendarServer/branches/unified-cache/twistedcaldav/directory/principal.py	2008-05-23 18:06:05 UTC (rev 2458)
+++ CalendarServer/branches/unified-cache/twistedcaldav/directory/principal.py	2008-05-23 18:58:21 UTC (rev 2459)
@@ -40,7 +40,7 @@
 from twisted.web2.dav.util import joinURL
 
 from twistedcaldav.config import config
-from twistedcaldav.cache import CacheChangeNotifier, PropfindCacheMixin
+from twistedcaldav.cache import XattrCacheChangeNotifier, PropfindCacheMixin
 
 from twistedcaldav.directory.calendaruserproxy import CalendarUserProxyDatabase
 from twistedcaldav.directory.calendaruserproxy import CalendarUserProxyPrincipalResource
@@ -358,7 +358,7 @@
     """
     Directory principal resource.
     """
-    cacheNotifierFactory = CacheChangeNotifier
+    cacheNotifierFactory = XattrCacheChangeNotifier
 
     def __init__(self, path, parent, record):
         """

Modified: CalendarServer/branches/unified-cache/twistedcaldav/directory/test/test_principal.py
===================================================================
--- CalendarServer/branches/unified-cache/twistedcaldav/directory/test/test_principal.py	2008-05-23 18:06:05 UTC (rev 2458)
+++ CalendarServer/branches/unified-cache/twistedcaldav/directory/test/test_principal.py	2008-05-23 18:58:21 UTC (rev 2459)
@@ -40,7 +40,7 @@
 from twistedcaldav.directory.principal import DirectoryPrincipalResource
 from twistedcaldav.directory.principal import DirectoryCalendarPrincipalResource
 
-from twistedcaldav.cache import CacheChangeNotifier
+from twistedcaldav.cache import XattrCacheChangeNotifier
 
 import twistedcaldav.test.util
 
@@ -231,11 +231,11 @@
     def test_cacheNotifier(self):
         """
         Each DirectoryPrincipalResource should have a cacheNotifier attribute
-        that is an instance of CacheChangeNotifier
+        that is an instance of XattrCacheChangeNotifier
         """
         for provisioningResource, recordType, recordResource, record in self._allRecords():
             self.failUnless(isinstance(recordResource.cacheNotifier,
-                                       CacheChangeNotifier))
+                                       XattrCacheChangeNotifier))
 
     def test_displayName(self):
         """

Modified: CalendarServer/branches/unified-cache/twistedcaldav/directory/test/test_sudo.py
===================================================================
--- CalendarServer/branches/unified-cache/twistedcaldav/directory/test/test_sudo.py	2008-05-23 18:06:05 UTC (rev 2458)
+++ CalendarServer/branches/unified-cache/twistedcaldav/directory/test/test_sudo.py	2008-05-23 18:58:21 UTC (rev 2459)
@@ -66,23 +66,6 @@
         record = service.recordWithShortName(self.recordType, 'bob')
         self.failIf(record)
 
-    def test_recordChanges(self):
-        service = self.service()
-
-        record = service.recordWithShortName(self.recordType, 'alice')
-        self.assertEquals(record.password, 'alice')
-
-        record = service.recordWithShortName(self.recordType, 'bob')
-        self.failIf(record)
-
-        plistFile2.copyTo(self._plistFile)
-
-        record = service.recordWithShortName(self.recordType, 'alice')
-        self.assertEquals(record.password, 'alice')
-
-        record = service.recordWithShortName(self.recordType, 'bob')
-        self.assertEquals(record.password, 'bob')
-
     def test_calendaringDisabled(self):
         service = self.service()
 

Modified: CalendarServer/branches/unified-cache/twistedcaldav/resource.py
===================================================================
--- CalendarServer/branches/unified-cache/twistedcaldav/resource.py	2008-05-23 18:06:05 UTC (rev 2458)
+++ CalendarServer/branches/unified-cache/twistedcaldav/resource.py	2008-05-23 18:58:21 UTC (rev 2459)
@@ -217,9 +217,6 @@
     def writeDeadProperty(self, property):
         val = super(CalDAVResource, self).writeDeadProperty(property)
 
-        if hasattr(self, 'cacheNotifier'):
-            self.cacheNotifier.changed()
-
         return val
 
 

Modified: CalendarServer/branches/unified-cache/twistedcaldav/static.py
===================================================================
--- CalendarServer/branches/unified-cache/twistedcaldav/static.py	2008-05-23 18:06:05 UTC (rev 2458)
+++ CalendarServer/branches/unified-cache/twistedcaldav/static.py	2008-05-23 18:58:21 UTC (rev 2459)
@@ -38,6 +38,7 @@
 from urlparse import urlsplit
 
 from twisted.internet.defer import deferredGenerator, fail, succeed, waitForDeferred
+from twisted.python.failure import Failure
 from twisted.web2 import responsecode
 from twisted.web2.http import HTTPError, StatusResponse
 from twisted.web2.dav import davxml
@@ -67,7 +68,7 @@
 from twistedcaldav.directory.resource import AutoProvisioningResourceMixIn
 from twistedcaldav.log import Logger
 
-from twistedcaldav.cache import CacheChangeNotifier, PropfindCacheMixin
+from twistedcaldav.cache import XattrCacheChangeNotifier, PropfindCacheMixin
 
 log = Logger()
 
@@ -284,8 +285,17 @@
 
     def updateCTag(self):
         assert self.isCollection()
-        self.writeDeadProperty(customxml.GETCTag(str(datetime.datetime.now())))
+        try:
+            self.writeDeadProperty(customxml.GETCTag(
+                    str(datetime.datetime.now())))
+        except:
+            return fail(Failure())
 
+        if hasattr(self, 'cacheNotifier'):
+            return self.cacheNotifier.changed()
+
+        return succeed(True)
+
     ##
     # Quota
     ##
@@ -524,20 +534,22 @@
     """
     Calendar home collection resource.
     """
+    changeNotifierFactory = XattrCacheChangeNotifier
+
     def __init__(self, path, parent, record):
         """
         @param path: the path to the file which will back the resource.
         """
         CalDAVFile.__init__(self, path)
         DirectoryCalendarHomeResource.__init__(self, parent, record)
-        self.cacheNotifier = CacheChangeNotifier(self.deadProperties())
+        self.cacheNotifier = self.changeNotifierFactory(self.deadProperties())
 
     def provisionChild(self, name):
         if config.EnableDropBox:
             DropBoxHomeFileClass = DropBoxHomeFile
         else:
             DropBoxHomeFileClass = None
-            
+
         cls = {
             "inbox"        : ScheduleInboxFile,
             "outbox"       : ScheduleOutboxFile,

Modified: CalendarServer/branches/unified-cache/twistedcaldav/test/test_cache.py
===================================================================
--- CalendarServer/branches/unified-cache/twistedcaldav/test/test_cache.py	2008-05-23 18:06:05 UTC (rev 2458)
+++ CalendarServer/branches/unified-cache/twistedcaldav/test/test_cache.py	2008-05-23 18:58:21 UTC (rev 2459)
@@ -29,7 +29,7 @@
 from twisted.web2.stream import MemoryStream
 from twisted.web2.http_headers import Headers
 
-from twistedcaldav.cache import CacheChangeNotifier
+from twistedcaldav.cache import XattrCacheChangeNotifier
 from twistedcaldav.cache import CacheTokensProperty
 from twistedcaldav.cache import ResponseCache
 from twistedcaldav.cache import MemcacheResponseCache
@@ -92,31 +92,34 @@
 
 
 
-class CacheChangeNotifierTests(TestCase):
+class XattrCacheChangeNotifierTests(TestCase):
     def setUp(self):
         self.props = InMemoryPropertyStore()
-        self.ccn = CacheChangeNotifier(self.props)
+        self.ccn = XattrCacheChangeNotifier(self.props)
         self.ccn._newCacheToken = instancemethod(_newCacheToken,
                                                  self.ccn,
-                                                 CacheChangeNotifier)
+                                                 XattrCacheChangeNotifier)
 
 
-    def test_cacheTokenPropertyIsProvisioned(self):
-        self.ccn.changed()
+    def assertToken(self, expectedToken):
         token = self.props._properties[CacheTokensProperty.qname()
                                         ].children[0].data
-        self.assertEquals(token, 'token0')
+        self.assertEquals(token, expectedToken)
 
 
+    def test_cacheTokenPropertyIsProvisioned(self):
+        d = self.ccn.changed()
+        d.addCallback(lambda _: self.assertToken('token0'))
+        return d
+
+
     def test_changedChangesToken(self):
-        self.ccn.changed()
-        self.ccn.changed()
-        token = self.props._properties[CacheTokensProperty.qname()
-                                        ].children[0].data
-        self.assertEquals(token, 'token1')
+        d = self.ccn.changed()
+        d.addCallback(lambda _: self.ccn.changed())
+        d.addCallback(lambda _: self.assertToken('token1'))
+        return d
 
 
-
 class BaseCacheTestMixin(object):
     def assertResponse(self, response, expected):
         self.assertEquals(response.code, expected[0])

Modified: CalendarServer/branches/unified-cache/twistedcaldav/test/test_resource.py
===================================================================
--- CalendarServer/branches/unified-cache/twistedcaldav/test/test_resource.py	2008-05-23 18:06:05 UTC (rev 2458)
+++ CalendarServer/branches/unified-cache/twistedcaldav/test/test_resource.py	2008-05-23 18:58:21 UTC (rev 2459)
@@ -31,28 +31,9 @@
     def setUp(self):
         self.resource = CalDAVResource()
         self.resource._dead_properties = InMemoryPropertyStore()
-        self.resource.cacheNotifier = StubCacheChangeNotifier()
 
-
-    def test_writeDeadPropertyNotifiesCache(self):
-        self.resource.writeDeadProperty(StubProperty())
-        self.assertEquals(self.resource.cacheNotifier.changedCount, 1)
-
-
     def test_writeDeadPropertyWritesProperty(self):
         prop = StubProperty()
         self.resource.writeDeadProperty(prop)
         self.assertEquals(self.resource._dead_properties.get("StubQname"),
                           prop)
-
-
-    def test_writeDeadPropertyFailureDoesntNotifyCache(self):
-        self.resource._dead_properties = None
-        self.assertRaises(Exception,
-                          self.resource.writeDeadProperty, StubProperty())
-        self.assertEquals(self.resource.cacheNotifier.changedCount, 0)
-
-
-    def test_writeDeadPropertyDoesntFailWithoutACacheNotifier(self):
-        del self.resource.cacheNotifier
-        self.resource.writeDeadProperty(StubProperty())

Modified: CalendarServer/branches/unified-cache/twistedcaldav/test/test_static.py
===================================================================
--- CalendarServer/branches/unified-cache/twistedcaldav/test/test_static.py	2008-05-23 18:06:05 UTC (rev 2458)
+++ CalendarServer/branches/unified-cache/twistedcaldav/test/test_static.py	2008-05-23 18:58:21 UTC (rev 2459)
@@ -17,7 +17,7 @@
 from twisted.trial.unittest import TestCase
 
 from twistedcaldav.static import CalendarHomeFile, CalDAVFile
-from twistedcaldav.cache import CacheChangeNotifier
+from twistedcaldav.cache import XattrCacheChangeNotifier
 from twistedcaldav.test.util import StubCacheChangeNotifier
 
 class StubParentResource(object):
@@ -34,7 +34,7 @@
 
     def test_hasCacheNotifier(self):
         self.failUnless(isinstance(self.calendarHome.cacheNotifier,
-                                   CacheChangeNotifier))
+                                   XattrCacheChangeNotifier))
 
 
     def test_childrenHaveCacheNotifier(self):
@@ -52,10 +52,15 @@
 
 
     def test_updateCTagNotifiesCache(self):
-        self.caldavFile.updateCTag()
-        self.assertEquals(self.caldavFile.cacheNotifier.changedCount, 1)
+        d = self.caldavFile.updateCTag()
+        d.addCallback(
+            lambda _:
+                self.assertEquals(self.caldavFile.cacheNotifier.changedCount, 1)
+            )
+        return d
 
 
     def test_updateCTagDoesntFailWithoutACacheNotifier(self):
         del self.caldavFile.cacheNotifier
-        self.caldavFile.updateCTag()
+        d = self.caldavFile.updateCTag()
+        return d

Modified: CalendarServer/branches/unified-cache/twistedcaldav/test/util.py
===================================================================
--- CalendarServer/branches/unified-cache/twistedcaldav/test/util.py	2008-05-23 18:06:05 UTC (rev 2458)
+++ CalendarServer/branches/unified-cache/twistedcaldav/test/util.py	2008-05-23 18:58:21 UTC (rev 2459)
@@ -17,6 +17,8 @@
 import twisted.web2.dav.test.util
 from twisted.web2.http import HTTPError, StatusResponse
 
+from twisted.internet.defer import succeed
+
 from twistedcaldav.static import CalDAVFile
 
 
@@ -43,3 +45,4 @@
 
     def changed(self):
         self.changedCount += 1
+        return succeed(True)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20080523/4e581c1e/attachment-0001.htm 


More information about the calendarserver-changes mailing list