[CalendarServer-changes] [8559] CalendarServer/trunk/txdav/common/datastore
source_changes at macosforge.org
source_changes at macosforge.org
Thu Jan 19 07:45:25 PST 2012
Revision: 8559
http://trac.macosforge.org/projects/calendarserver/changeset/8559
Author: cdaboo at apple.com
Date: 2012-01-19 07:45:24 -0800 (Thu, 19 Jan 2012)
Log Message:
-----------
Make sure subtransaction does only the number of requested retries.
Modified Paths:
--------------
CalendarServer/trunk/txdav/common/datastore/sql.py
Added Paths:
-----------
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-01-18 00:06:29 UTC (rev 8558)
+++ CalendarServer/trunk/txdav/common/datastore/sql.py 2012-01-19 15:45:24 UTC (rev 8559)
@@ -1,6 +1,6 @@
# -*- test-case-name: txdav.caldav.datastore.test.test_sql,txdav.carddav.datastore.test.test_sql -*-
##
-# Copyright (c) 2010-2011 Apple Inc. All rights reserved.
+# Copyright (c) 2010-2012 Apple Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -483,7 +483,7 @@
block = self._sqlTxn.commandBlock()
sp = self._savepoint()
failuresToMaybeLog = []
- triesLeft = retries + 1
+ triesLeft = retries
try:
while True:
yield sp.acquire(block)
Added: CalendarServer/trunk/txdav/common/datastore/test/test_sql.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/test/test_sql.py (rev 0)
+++ CalendarServer/trunk/txdav/common/datastore/test/test_sql.py 2012-01-19 15:45:24 UTC (rev 8559)
@@ -0,0 +1,149 @@
+##
+# Copyright (c) 2012 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+from txdav.common.datastore.sql_tables import schema
+from twext.enterprise.dal.syntax import Select
+from txdav.common.icommondatastore import AllRetriesFailed
+
+"""
+Tests for L{txdav.common.datastore.sql}.
+"""
+
+from twisted.internet.defer import inlineCallbacks
+from twisted.trial.unittest import TestCase
+from txdav.common.datastore.test.util import CommonCommonTests, buildStore
+
+
+class SubTransactionTests(CommonCommonTests, TestCase):
+ """
+ Tests for L{UpgradeToDatabaseService}.
+ """
+
+ @inlineCallbacks
+ def setUp(self):
+ """
+ Set up two stores to migrate between.
+ """
+ yield super(SubTransactionTests, self).setUp()
+ self._sqlStore = yield buildStore(self, self.notifierFactory)
+
+
+ def storeUnderTest(self):
+ """
+ Return a store for testing.
+ """
+ return self._sqlStore
+
+
+ @inlineCallbacks
+ def test_subtransactionOK(self):
+ """
+ txn.subtransaction runs loop once.
+ """
+
+ txn = self.transactionUnderTest()
+ ctr = [0]
+
+ def _test(subtxn):
+ ctr[0] += 1
+ cs = schema.CALENDARSERVER
+ return Select(
+ [cs.VALUE,],
+ From=cs,
+ Where=cs.NAME == 'VERSION',
+ ).on(subtxn)
+
+ _ignore = (yield txn.subtransaction(_test, retries=0))[0][0]
+ self.assertEqual(ctr[0], 1)
+
+
+ @inlineCallbacks
+ def test_subtransactionOKAfterRetry(self):
+ """
+ txn.subtransaction runs loop twice when one failure.
+ """
+
+ txn = self.transactionUnderTest()
+ ctr = [0]
+
+ def _test(subtxn):
+ ctr[0] += 1
+ if ctr[0] == 1:
+ raise ValueError
+ cs = schema.CALENDARSERVER
+ return Select(
+ [cs.VALUE,],
+ From=cs,
+ Where=cs.NAME == 'VERSION',
+ ).on(subtxn)
+
+ _ignore = (yield txn.subtransaction(_test, retries=1))[0][0]
+ self.assertEqual(ctr[0], 2)
+
+
+ @inlineCallbacks
+ def test_subtransactionFailNoRetry(self):
+ """
+ txn.subtransaction runs loop once when one failure and no retries.
+ """
+
+ txn = self.transactionUnderTest()
+ ctr = [0]
+
+ def _test(subtxn):
+ ctr[0] += 1
+ raise ValueError
+ cs = schema.CALENDARSERVER
+ return Select(
+ [cs.VALUE,],
+ From=cs,
+ Where=cs.NAME == 'VERSION',
+ ).on(subtxn)
+
+ try:
+ _ignore = (yield txn.subtransaction(_test, retries=0))[0][0]
+ except AllRetriesFailed:
+ pass
+ else:
+ self.fail("AllRetriesFailed not raised")
+ self.assertEqual(ctr[0], 1)
+
+
+ @inlineCallbacks
+ def test_subtransactionFailSomeRetries(self):
+ """
+ txn.subtransaction runs loop three times when all fail and two retries requested.
+ """
+
+ txn = self.transactionUnderTest()
+ ctr = [0]
+
+ def _test(subtxn):
+ ctr[0] += 1
+ raise ValueError
+ cs = schema.CALENDARSERVER
+ return Select(
+ [cs.VALUE,],
+ From=cs,
+ Where=cs.NAME == 'VERSION',
+ ).on(subtxn)
+
+ try:
+ _ignore = (yield txn.subtransaction(_test, retries=2))[0][0]
+ except AllRetriesFailed:
+ pass
+ else:
+ self.fail("AllRetriesFailed not raised")
+ self.assertEqual(ctr[0], 3)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120119/d477e103/attachment.html>
More information about the calendarserver-changes
mailing list