source:
ralphm-patches/component_multiple.patch
@
2:ec684efc6a7b
Last change on this file since 2:ec684efc6a7b was 2:ec684efc6a7b, checked in by Ralph Meijer <ralphm@…>, 13 years ago | |
---|---|
File size: 5.2 KB |
-
wokkel/component.py
diff -r 5de8d8c9e331 wokkel/component.py
a b 85 85 Instead of opening a socket to connect to a router, like L{Component}, 86 86 components of this type connect to a router in the same process. This 87 87 allows for one-process XMPP servers. 88 89 @ivar domains: Domains (as C{str}) this component will handle traffic for. 90 @type domains: L{set} 88 91 """ 89 92 90 def __init__(self, router, domain ):93 def __init__(self, router, domain=None): 91 94 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) 94 100 95 101 self.xmlstream = None 96 102 … … 100 106 """ 101 107 service.Service.startService(self) 102 108 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) 106 114 107 115 for e in self: 108 116 e.makeConnection(self.xmlstream) … … 115 123 """ 116 124 service.Service.stopService(self) 117 125 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 120 130 self.xmlstream = None 121 131 122 132 for e in self: -
wokkel/test/test_component.py
diff -r 5de8d8c9e331 wokkel/test/test_component.py
a b 41 41 verifyObject(IXMPPHandlerCollection, self.component) 42 42 43 43 44 def test_startService(self): 44 45 def test_startServiceRunning(self): 45 46 """ 46 Starting the service creates a new route and hooks up handlers.47 Starting the service makes it running. 47 48 """ 49 self.assertFalse(self.component.running) 50 self.component.startService() 51 self.assertTrue(self.component.running) 48 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 """ 49 81 events = [] 50 82 51 83 class TestHandler(XMPPHandler): … … 56 88 57 89 TestHandler().setHandlerParent(self.component) 58 90 59 self.assertFalse(self.component.running)60 61 91 self.component.startService() 62 63 self.assertTrue(self.component.running)64 self.assertIn('component', self.router.routes)65 66 92 self.assertEquals([], events) 67 93 self.component.xmlstream.dispatch(None, '//event/test') 68 94 self.assertEquals([None], events) 69 95 70 96 71 def test_stopService (self):97 def test_stopServiceNotRunning(self): 72 98 """ 73 Stopping the service removes the route and disconnects handlers.99 Stopping the service makes it not running. 74 100 """ 101 self.component.startService() 102 self.component.stopService() 103 self.assertFalse(self.component.running) 75 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 """ 76 136 events = [] 77 137 78 138 class TestHandler(XMPPHandler): … … 84 144 85 145 self.component.startService() 86 146 self.component.stopService() 87 88 self.assertFalse(self.component.running)89 147 self.assertEquals(1, len(events)) 90 self.assertNotIn('component', self.router.routes)91 148 92 149 93 150 def test_addHandler(self):
Note: See TracBrowser
for help on using the repository browser.