def test_stopServer(self): """ You can have many servers running and stop them individually """ h = Hub() h.remote_echo = lambda x: x d = h.startServer(h.getPBServerFactory(), 'tcp:10999') d.addCallback(lambda x: h.startServer(h.getPBServerFactory(), 'tcp:10888')) def killOne(_): return h.stopServer('tcp:10888') d.addCallback(killOne) def testOne(_): # still can connect to the other self.clientPort = None client = clientFromString(reactor, 'tcp:host=127.0.0.1:port=10999') factory = pb.PBClientFactory() d = client.connect(factory) def saveClient(clientPort): self.clientPort = clientPort d.addCallback(saveClient) d.addCallback(lambda ign: factory.getRootObject()) d.addCallback(lambda obj: obj.callRemote('echo', 'foo')) d.addCallback(lambda res: self.assertEqual(res, 'foo')) d.addCallback(lambda ign: self.clientPort.transport.loseConnection()) d.addCallback(lambda ign: h.stopServer('tcp:10999')) return d d.addCallback(testOne) return d
def test_startServer(self): """ Should call twisted.internet.endpoints.serverFromString and hook that up to the factory """ h = Hub() h.remote_echo = lambda x: x h.startServer(h.getPBServerFactory(), 'tcp:10999') # connect to it self.clientPort = None client = clientFromString(reactor, 'tcp:host=127.0.0.1:port=10999') factory = pb.PBClientFactory() d = client.connect(factory) def saveClient(clientPort): self.clientPort = clientPort d.addCallback(saveClient) d.addCallback(lambda ign: factory.getRootObject()) d.addCallback(lambda obj: obj.callRemote('echo', 'foo')) d.addCallback(lambda res: self.assertEqual(res, 'foo')) d.addCallback(lambda ign: self.clientPort.transport.loseConnection()) d.addCallback(lambda ign: h.stopServer('tcp:10999')) return d
def test_getPBServerFactory(self): """ Should return an instance of pb.PBServerFactory with self passed in. """ h = Hub() f = h.getPBServerFactory() self.assertTrue(isinstance(f, pb.PBServerFactory)) self.assertEqual(f.root, h)
def test_connect(self): """ You can connect to other servers. This is functionalish """ server = Hub() client = Hub() called = [] client.remoteHubFactory = lambda x: 'foo' client.gotRemoteRoot = called.append server.startServer(server.getPBServerFactory(), 'tcp:10999') def check(r): self.assertEqual(called, ['foo'], "Should have called .gotRemoteRoot with wrapped remote") return r d = client.connect('tcp:host=127.0.0.1:port=10999') d.addCallback(check) d.addCallback(lambda x: client.disconnect( 'tcp:host=127.0.0.1:port=10999')) d.addCallback(lambda x: server.stopServer('tcp:10999')) return d
from twisted.internet import reactor from twisted.python import log import sys from simplebb.hub import Hub from simplebb.builder import FileBuilder log.startLogging(sys.stdout) fb = FileBuilder('example/projects') h = Hub() h.addBuilder(fb) h.startServer(h.getPBServerFactory(), 'tcp:9222') h.startServer(h.getShellServerFactory(), 'tcp:9223') reactor.run()