Changeset 54:6548e1eeb7e2


Ignore:
Timestamp:
Apr 22, 2009, 4:45:04 PM (11 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Convert:
svn:b33ecbfc-034c-dc11-8662-000475d9059e/trunk@166
Message:

Allow InternalComponent? to host multiple domains.

Author: ralphm.
Fixes #43.

Location:
wokkel
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wokkel/component.py

    r41 r54  
    8686    components of this type connect to a router in the same process. This
    8787    allows for one-process XMPP servers.
    88     """
    89 
    90     def __init__(self, router, domain):
     88
     89    @ivar domains: Domains (as C{str}) this component will handle traffic for.
     90    @type domains: L{set}
     91    """
     92
     93    def __init__(self, router, domain=None):
    9194        XMPPHandlerCollection.__init__(self)
    92         self.router = router
    93         self.domain = domain
     95
     96        self._router = router
     97        self.domains = set()
     98        if domain:
     99            self.domains.add(domain)
    94100
    95101        self.xmlstream = None
     
    101107        service.Service.startService(self)
    102108
    103         self.pipe = XmlPipe()
    104         self.xmlstream = self.pipe.source
    105         self.router.addRoute(self.domain, self.pipe.sink)
     109        self._pipe = XmlPipe()
     110        self.xmlstream = self._pipe.source
     111
     112        for domain in self.domains:
     113            self._router.addRoute(domain, self._pipe.sink)
    106114
    107115        for e in self:
     
    116124        service.Service.stopService(self)
    117125
    118         self.router.removeRoute(self.domain, self.pipe.sink)
    119         self.pipe = None
     126        for domain in self.domains:
     127            self._router.removeRoute(domain, self._pipe.sink)
     128
     129        self._pipe = None
    120130        self.xmlstream = None
    121131
  • wokkel/test/test_component.py

    r41 r54  
    4242
    4343
    44     def test_startService(self):
    45         """
    46         Starting the service creates a new route and hooks up handlers.
    47         """
    48 
     44
     45    def test_startServiceRunning(self):
     46        """
     47        Starting the service makes it running.
     48        """
     49        self.assertFalse(self.component.running)
     50        self.component.startService()
     51        self.assertTrue(self.component.running)
     52
     53
     54    def test_startServiceAddRoute(self):
     55        """
     56        Starting the service creates a new route.
     57        """
     58        self.component.startService()
     59        self.assertIn('component', self.router.routes)
     60
     61
     62    def test_startServiceNoDomain(self):
     63        self.component = component.InternalComponent(self.router)
     64        self.component.startService()
     65
     66
     67    def test_startServiceAddMultipleRoutes(self):
     68        """
     69        Starting the service creates a new route.
     70        """
     71        self.component.domains.add('component2')
     72        self.component.startService()
     73        self.assertIn('component', self.router.routes)
     74        self.assertIn('component2', self.router.routes)
     75
     76
     77    def test_startServiceHandlerDispatch(self):
     78        """
     79        Starting the service hooks up handlers.
     80        """
    4981        events = []
    5082
     
    5789        TestHandler().setHandlerParent(self.component)
    5890
    59         self.assertFalse(self.component.running)
    60 
    61         self.component.startService()
    62 
    63         self.assertTrue(self.component.running)
    64         self.assertIn('component', self.router.routes)
    65 
     91        self.component.startService()
    6692        self.assertEquals([], events)
    6793        self.component.xmlstream.dispatch(None, '//event/test')
     
    6995
    7096
    71     def test_stopService(self):
    72         """
    73         Stopping the service removes the route and disconnects handlers.
    74         """
    75 
     97    def test_stopServiceNotRunning(self):
     98        """
     99        Stopping the service makes it not running.
     100        """
     101        self.component.startService()
     102        self.component.stopService()
     103        self.assertFalse(self.component.running)
     104
     105
     106    def test_stopServiceRemoveRoute(self):
     107        """
     108        Stopping the service removes routes.
     109        """
     110        self.component.startService()
     111        self.component.stopService()
     112        self.assertNotIn('component', self.router.routes)
     113
     114
     115    def test_stopServiceNoDomain(self):
     116        self.component = component.InternalComponent(self.router)
     117        self.component.startService()
     118        self.component.stopService()
     119
     120
     121    def test_startServiceRemoveMultipleRoutes(self):
     122        """
     123        Starting the service creates a new route.
     124        """
     125        self.component.domains.add('component2')
     126        self.component.startService()
     127        self.component.stopService()
     128        self.assertNotIn('component', self.router.routes)
     129        self.assertNotIn('component2', self.router.routes)
     130
     131
     132    def test_stopServiceHandlerDispatch(self):
     133        """
     134        Stopping the service disconnects handlers.
     135        """
    76136        events = []
    77137
     
    85145        self.component.startService()
    86146        self.component.stopService()
    87 
    88         self.assertFalse(self.component.running)
    89147        self.assertEquals(1, len(events))
    90         self.assertNotIn('component', self.router.routes)
    91148
    92149
Note: See TracChangeset for help on using the changeset viewer.