[CalendarServer-changes] [8437] CalendarServer/branches/users/glyph/shared-pool-fixes

source_changes at macosforge.org source_changes at macosforge.org
Tue Dec 13 13:50:45 PST 2011


Revision: 8437
          http://trac.macosforge.org/projects/calendarserver/changeset/8437
Author:   glyph at apple.com
Date:     2011-12-13 13:50:44 -0800 (Tue, 13 Dec 2011)
Log Message:
-----------
test for existing raiseOnZeroRowCount functionality

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/shared-pool-fixes/twext/enterprise/test/test_adbapi2.py

Property Changed:
----------------
    CalendarServer/branches/users/glyph/shared-pool-fixes/

Modified: CalendarServer/branches/users/glyph/shared-pool-fixes/twext/enterprise/test/test_adbapi2.py
===================================================================
--- CalendarServer/branches/users/glyph/shared-pool-fixes/twext/enterprise/test/test_adbapi2.py	2011-12-13 21:49:37 UTC (rev 8436)
+++ CalendarServer/branches/users/glyph/shared-pool-fixes/twext/enterprise/test/test_adbapi2.py	2011-12-13 21:50:44 UTC (rev 8437)
@@ -107,6 +107,7 @@
     Fake Stand-in for DB-API 2.0 connection.
 
     @ivar executions: the number of statements which have been executed.
+
     """
 
     executions = 0
@@ -192,7 +193,11 @@
         self.allExecutions.append((sql, args))
         self.sql = sql
         self.description = True
-        self.rowcount = 1
+        factory = self.connection.parent
+        if factory.hasResults and factory.shouldUpdateRowcount:
+            self.rowcount = 1
+        else:
+            self.rowcount = 0
         return
 
 
@@ -209,7 +214,11 @@
         """
         Just echo the SQL that was executed in the last query.
         """
-        return [[self.connection.id, self.sql]]
+        if self.connection.parent.hasResults:
+            return [[self.connection.id, self.sql]]
+        if self.description:
+            return []
+        return None
 
 
 
@@ -233,16 +242,28 @@
 
 
 class ConnectionFactory(Parent):
+    """
+    A factory for L{FakeConnection} objects.
 
+    @ivar shouldUpdateRowcount: Should C{execute} on cursors produced by
+        connections produced by this factory update their C{rowcount} or just
+        their C{description} attribute?
+
+    @ivar hasResults: should cursors produced by connections by this factory
+        have any results returned by C{fetchall()}?
+    """
+
     rollbackFail = False
     commitFail = False
 
-    def __init__(self):
+    def __init__(self, shouldUpdateRowcount=True, hasResults=True):
         Parent.__init__(self)
         self.idcounter = count(1)
         self._connectResultQueue = []
         self.defaultConnect()
         self.varvals = []
+        self.shouldUpdateRowcount = shouldUpdateRowcount
+        self.hasResults = hasResults
 
 
     @property
@@ -1289,7 +1310,22 @@
         self.assertRaises(AlreadyFinishedError, txn.commandBlock)
 
 
+    def test_raiseOnZeroRowCount(self):
+        """
+        L{IAsyncTransaction.execSQL} will return a L{Deferred} failing with the
+        exception passed as its raiseOnZeroRowCount argument if the underlying
+        query returns no rows.
+        """
+        self.factory.hasResults = False
+        txn = self.createTransaction()
+        f = self.resultOf(
+            txn.execSQL("hello", raiseOnZeroRowCount=ZeroDivisionError)
+        )[0]
+        self.assertRaises(ZeroDivisionError, f.raiseException)
+        txn.commit()
 
+
+
 class IOPump(object):
     """
     Connect a client and a server.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20111213/6574a247/attachment-0001.html>


More information about the calendarserver-changes mailing list