[CalendarServer-changes] [8813] CalendarServer/trunk/txdav/common/datastore
source_changes at macosforge.org
source_changes at macosforge.org
Mon Mar 5 07:12:56 PST 2012
Revision: 8813
http://trac.macosforge.org/projects/calendarserver/changeset/8813
Author: cdaboo at apple.com
Date: 2012-03-05 07:12:52 -0800 (Mon, 05 Mar 2012)
Log Message:
-----------
Handle case where revision table entry might be missing.
Modified Paths:
--------------
CalendarServer/trunk/txdav/common/datastore/sql.py
CalendarServer/trunk/txdav/common/datastore/test/test_sql.py
Modified: CalendarServer/trunk/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql.py 2012-03-05 15:11:06 UTC (rev 8812)
+++ CalendarServer/trunk/txdav/common/datastore/sql.py 2012-03-05 15:12:52 UTC (rev 8813)
@@ -1683,15 +1683,26 @@
@inlineCallbacks
def _changeRevision(self, action, name):
+
+ # Need to handle the case where for some reason the revision entry is
+ # actually missing. For a "delete" we don't care, for an "update" we
+ # will turn it into an "insert".
if action == "delete":
- self._syncTokenRevision = (
+ rows = (
yield self._deleteBumpTokenQuery.on(
- self._txn, resourceID=self._resourceID, name=name))[0][0]
+ self._txn, resourceID=self._resourceID, name=name))
+ if rows:
+ self._syncTokenRevision = rows[0][0]
elif action == "update":
- self._syncTokenRevision = (
+ rows = (
yield self._updateBumpTokenQuery.on(
- self._txn, resourceID=self._resourceID, name=name))[0][0]
- elif action == "insert":
+ self._txn, resourceID=self._resourceID, name=name))
+ if rows:
+ self._syncTokenRevision = rows[0][0]
+ else:
+ action = "insert"
+
+ if action == "insert":
# Note that an "insert" may happen for a resource that previously
# existed and then was deleted. In that case an entry in the
# REVISIONS table still exists so we have to detect that and do db
Modified: CalendarServer/trunk/txdav/common/datastore/test/test_sql.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/test/test_sql.py 2012-03-05 15:11:06 UTC (rev 8812)
+++ CalendarServer/trunk/txdav/common/datastore/test/test_sql.py 2012-03-05 15:12:52 UTC (rev 8813)
@@ -19,15 +19,19 @@
"""
from twext.enterprise.dal.syntax import Select
+from twext.web2.dav import davxml
+
from twisted.internet.defer import inlineCallbacks
from twisted.internet.task import Clock
from twisted.trial.unittest import TestCase
-from txdav.common.datastore.sql import log, CommonStoreTransactionMonitor
-from txdav.common.datastore.sql_tables import schema
+
+from txdav.common.datastore.sql import log, CommonStoreTransactionMonitor,\
+ CommonHome, CommonHomeChild, ECALENDARTYPE
+from txdav.common.datastore.sql_tables import schema, CALENDAR_BIND_TABLE,\
+ CALENDAR_OBJECT_REVISIONS_TABLE
from txdav.common.datastore.test.util import CommonCommonTests, buildStore
from txdav.common.icommondatastore import AllRetriesFailed
-
class SubTransactionTests(CommonCommonTests, TestCase):
"""
Tests for L{UpgradeToDatabaseService}.
@@ -244,3 +248,60 @@
else:
self.fail("AllRetriesFailed not raised")
self.assertEqual(ctr[0], 3)
+
+ @inlineCallbacks
+ def test_changeRevision(self):
+ """
+ CommonHomeChild._changeRevision actions.
+ """
+
+ class TestCommonHome(CommonHome):
+ _bindTable = CALENDAR_BIND_TABLE
+ _revisionsTable = CALENDAR_OBJECT_REVISIONS_TABLE
+
+ class TestCommonHomeChild(CommonHomeChild):
+ _homeChildSchema = schema.CALENDAR
+ _homeChildMetaDataSchema = schema.CALENDAR_METADATA
+ _bindSchema = schema.CALENDAR_BIND
+ _revisionsSchema = schema.CALENDAR_OBJECT_REVISIONS
+ _bindTable = CALENDAR_BIND_TABLE
+ _revisionsTable = CALENDAR_OBJECT_REVISIONS_TABLE
+
+ def resourceType(self):
+ return davxml.ResourceType.calendar
+
+ txn = self.transactionUnderTest()
+ home = yield txn.homeWithUID(ECALENDARTYPE, "uid", create=True)
+ homeChild = yield TestCommonHomeChild.create(home, "B")
+
+ # insert test
+ token = yield homeChild.syncToken()
+ yield homeChild._changeRevision("insert", "C")
+ changed = yield homeChild.resourceNamesSinceToken(token)
+ self.assertEqual(changed, (["C"], [],))
+
+ # update test
+ token = yield homeChild.syncToken()
+ yield homeChild._changeRevision("update", "C")
+ changed = yield homeChild.resourceNamesSinceToken(token)
+ self.assertEqual(changed, (["C"], [],))
+
+ # delete test
+ token = yield homeChild.syncToken()
+ yield homeChild._changeRevision("delete", "C")
+ changed = yield homeChild.resourceNamesSinceToken(token)
+ self.assertEqual(changed, ([], ["C"],))
+
+ # missing update test
+ token = yield homeChild.syncToken()
+ yield homeChild._changeRevision("update", "D")
+ changed = yield homeChild.resourceNamesSinceToken(token)
+ self.assertEqual(changed, (["D"], [],))
+
+ # missing delete test
+ token = yield homeChild.syncToken()
+ yield homeChild._changeRevision("delete", "E")
+ changed = yield homeChild.resourceNamesSinceToken(token)
+ self.assertEqual(changed, ([], [],))
+
+ txn.abort()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120305/034dc9a7/attachment-0001.html>
More information about the calendarserver-changes
mailing list