[CalendarServer-changes] [7696] CalendarServer/trunk/contrib/performance/loadtest

source_changes at macosforge.org source_changes at macosforge.org
Thu Jun 30 09:48:44 PDT 2011


Revision: 7696
          http://trac.macosforge.org/projects/calendarserver/changeset/7696
Author:   exarkun at twistedmatrix.com
Date:     2011-06-30 09:48:43 -0700 (Thu, 30 Jun 2011)
Log Message:
-----------
Extract XMPP push parameters from propfind response

Modified Paths:
--------------
    CalendarServer/trunk/contrib/performance/loadtest/ical.py
    CalendarServer/trunk/contrib/performance/loadtest/test_ical.py

Modified: CalendarServer/trunk/contrib/performance/loadtest/ical.py
===================================================================
--- CalendarServer/trunk/contrib/performance/loadtest/ical.py	2011-06-30 16:37:39 UTC (rev 7695)
+++ CalendarServer/trunk/contrib/performance/loadtest/ical.py	2011-06-30 16:48:43 UTC (rev 7696)
@@ -29,6 +29,7 @@
 from twisted.python.log import addObserver, err, msg
 from twisted.python.filepath import FilePath
 from twisted.python.failure import Failure
+from twisted.python.util import FancyEqMixin
 from twisted.internet.defer import inlineCallbacks, returnValue
 from twisted.internet.task import LoopingCall
 from twisted.web.http_headers import Headers
@@ -67,6 +68,19 @@
 
 
 
+class XMPPPush(object, FancyEqMixin):
+    """
+    This represents an XMPP PubSub location where push notifications for
+    particular calendar home might be received.
+    """
+    compareAttributes = ('server', 'uri')
+
+    def __init__(self, server, uri):
+        self.server = server
+        self.uri = uri
+
+
+
 class Event(object):
     def __init__(self, url, etag, vevent=None):
         self.url = url
@@ -177,6 +191,11 @@
         # part of), values are Event instances.
         self._events = {}
 
+        # Keep track of XMPP parameters for calendar homes we encounter.  This
+        # dictionary has calendar home URLs as keys and XMPPPush instances as
+        # values.
+        self.xmpp = {}
+
         # Allow events to go out into the world.
         self.catalog = {
             "eventChanged": Periodical(),
@@ -232,9 +251,13 @@
             csxml.notification,
             csxml.dropbox_home,
             ])
-    def _extractCalendars(self, response):
+    def _extractCalendars(self, response, calendarHome=None):
         """
-        Parse 
+        Parse a calendar home PROPFIND response and create local state
+        representing the calendars it contains.
+
+        If XMPP push is enabled, also look for and record information about
+        that from the response.
         """
         calendars = []
         principals = self._parseMultiStatus(response)
@@ -242,6 +265,14 @@
         # XXX Here, it would be really great to somehow use
         # CalDAVClientLibrary.client.principal.CalDAVPrincipal.listCalendars
         for principal in principals:
+
+            if principal == calendarHome:
+                text = principals[principal].getTextProperties()
+                server = text[csxml.xmpp_server]
+                uri = text[csxml.xmpp_uri]
+                if server and uri:
+                    self.xmpp[principal] = XMPPPush(server, uri)
+
             nodes = principals[principal].getNodeProperties()
             for nodeType in nodes[davxml.resourcetype].getchildren():
                 if nodeType.tag in self._CALENDAR_TYPES:
@@ -308,7 +339,7 @@
                     'depth': ['1']}),
             StringProducer(self._STARTUP_CALENDARHOME_PROPFIND))
         d.addCallback(readBody)
-        d.addCallback(self._extractCalendars)
+        d.addCallback(self._extractCalendars, '/' + calendarHomeSet)
         return d
 
 

Modified: CalendarServer/trunk/contrib/performance/loadtest/test_ical.py
===================================================================
--- CalendarServer/trunk/contrib/performance/loadtest/test_ical.py	2011-06-30 16:37:39 UTC (rev 7695)
+++ CalendarServer/trunk/contrib/performance/loadtest/test_ical.py	2011-06-30 16:48:43 UTC (rev 7696)
@@ -34,7 +34,7 @@
 from protocol.caldav.definitions import caldavxml
 from protocol.caldav.definitions import csxml
 
-from loadtest.ical import Event, Calendar, SnowLeopard
+from loadtest.ical import XMPPPush, Event, Calendar, SnowLeopard
 from httpclient import MemoryConsumer, StringProducer
 
 EVENT_UID = 'D94F247D-7433-43AF-B84B-ADD684D023B0'
@@ -172,16 +172,14 @@
 </multistatus>
 """
 
-
-CALENDAR_HOME_PROPFIND_RESPONSE = """\
+_CALENDAR_HOME_PROPFIND_RESPONSE_TEMPLATE = """\
 <?xml version='1.0' encoding='UTF-8'?>
 <multistatus xmlns='DAV:'>
   <response>
     <href>/calendars/__uids__/user01/</href>
     <propstat>
       <prop>
-        <xmpp-server xmlns='http://calendarserver.org/ns/'/>
-        <xmpp-uri xmlns='http://calendarserver.org/ns/'/>
+        %(xmpp)s
         <displayname>User 01</displayname>
         <resourcetype>
           <collection/>
@@ -798,7 +796,19 @@
 </multistatus>
 """
 
+CALENDAR_HOME_PROPFIND_RESPONSE = _CALENDAR_HOME_PROPFIND_RESPONSE_TEMPLATE % {
+    "xmpp": """\
+        <xmpp-server xmlns='http://calendarserver.org/ns/'/>
+        <xmpp-uri xmlns='http://calendarserver.org/ns/'/>""",
+    }
 
+CALENDAR_HOME_PROPFIND_RESPONSE_WITH_XMPP = _CALENDAR_HOME_PROPFIND_RESPONSE_TEMPLATE % {
+    "xmpp": """\
+        <xmpp-server xmlns='http://calendarserver.org/ns/'>xmpp.example.invalid:1952</xmpp-server>
+        <xmpp-uri xmlns='http://calendarserver.org/ns/'>xmpp:pubsub.xmpp.example.invalid?pubsub;node=/CalDAV/another.example.invalid/user01/</xmpp-uri>""",
+    }
+
+
 class MemoryResponse(object):
     def __init__(self, version, code, phrase, headers, bodyProducer):
         self.version = version
@@ -883,7 +893,9 @@
         PROPFIND response body and returns a list of calendar objects
         constructed from the data extracted from the response.
         """
-        calendars = self.client._extractCalendars(CALENDAR_HOME_PROPFIND_RESPONSE)
+        home = "/calendars/__uids__/user01/"
+        calendars = self.client._extractCalendars(
+            CALENDAR_HOME_PROPFIND_RESPONSE, home)
         calendars.sort(key=lambda cal: cal.resourceType)
         dropbox, notification, calendar, inbox, outbox = calendars
 
@@ -912,7 +924,24 @@
         self.assertEquals(outbox.url, "/calendars/__uids__/user01/outbox/")
         self.assertEquals(outbox.ctag, None)
 
+        self.assertEqual({}, self.client.xmpp)
 
+
+    def test_extractCalendarsXMPP(self):
+        """
+        If there is XMPP push information in a calendar home PROPFIND response,
+        L{SnowLeopard._extractCalendars} finds it and records it.
+        """
+        home = "/calendars/__uids__/user01/"
+        calendars = self.client._extractCalendars(
+            CALENDAR_HOME_PROPFIND_RESPONSE_WITH_XMPP, home)
+        self.assertEqual({
+                home: XMPPPush(
+                    "xmpp.example.invalid:1952",
+                    "xmpp:pubsub.xmpp.example.invalid?pubsub;node=/CalDAV/another.example.invalid/user01/")},
+                         self.client.xmpp)
+
+
     def test_changeEventAttendee(self):
         """
         SnowLeopard.changeEventAttendee removes one attendee from an
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110630/97ac66bc/attachment-0001.html>


More information about the calendarserver-changes mailing list