class BasicControllerServiceTest(DeferredTestCase, IControllerCoreTestCase):
    def setUp(self):
        self.controller = ControllerService()
        self.controller.startService()

    def tearDown(self):
        self.controller.stopService()
class FullSynchronousMultiEngineTestCase(DeferredTestCase,
                                         IFullSynchronousMultiEngineTestCase):
    def setUp(self):
        self.servers = []
        self.clients = []
        self.services = []

        self.controller = ControllerService()
        self.controller.startService()
        self.imultiengine = IMultiEngine(self.controller)
        self.imultiengine_factory = IXMLRPCMultiEngineFactory(
            self.imultiengine)
        self.servers.append(reactor.listenTCP(10105,
                                              self.imultiengine_factory))
        self.multiengine = XMLRPCFullSynchronousMultiEngineClient(
            ('localhost', 10105))
        self.engines = []

    def tearDown(self):
        l = []
        for s in self.servers:
            try:
                d = s.stopListening()
                if d is not None:
                    l.append(d)
            except:
                pass
        for c in self.clients:
            c.disconnect()
            del c
        dl = defer.DeferredList(l)
        self.controller.stopService()
        for e in self.engines:
            e.stopService()
        return dl
class SynchronousMultiEngineTestCase(DeferredTestCase,
                                     IMultiEngineBaseTestCase):
    def setUp(self):
        self.controller = ControllerService()
        self.controller.startService()
        self.multiengine = IMultiEngine(self.controller)
        self.smultiengine = ISynchronousMultiEngine(self.multiengine)
        self.engines = []

    def tearDown(self):
        self.controller.stopService()
        for e in self.engines:
            e.stopService()

    def testExecuteNoBlock(self):
        self.addEngine(2)
        result = [{
            'commandIndex': 0,
            'stdin': 'a=5',
            'id': 0,
            'stderr': '',
            'stdout': ''
        }, {
            'commandIndex': 0,
            'stdin': 'a=5',
            'id': 1,
            'stderr': '',
            'stdout': ''
        }]
        cid = self.smultiengine.registerClient()
        d = self.smultiengine.execute(cid, False, 'all', 'a=5')
        d.addCallback(
            lambda r: self.smultiengine.getPendingDeferred(cid, r, True))
        d.addCallback(lambda r: self.assert_(r == result))
        return d

    def testExecuteBlock(self):
        self.addEngine(2)
        result = [{
            'commandIndex': 0,
            'stdin': 'a=5',
            'id': 0,
            'stderr': '',
            'stdout': ''
        }, {
            'commandIndex': 0,
            'stdin': 'a=5',
            'id': 1,
            'stderr': '',
            'stdout': ''
        }]
        cid = self.smultiengine.registerClient()
        d = self.smultiengine.execute(cid, True, 'all', 'a=5')
        d.addCallback(lambda r: self.assert_(r == result))
        return d
class BasicMultiEngineTestCase(DeferredTestCase, IEngineMultiplexerTestCase):
    def setUp(self):
        self.controller = ControllerService()
        self.controller.startService()
        self.multiengine = IMultiEngine(self.controller)
        self.engines = []

    def tearDown(self):
        self.controller.stopService()
        for e in self.engines:
            e.stopService()
Beispiel #5
0
class SynchronousMultiEngineTestCase(DeferredTestCase, ISynchronousMultiEngineTestCase):
    
    def setUp(self):
        self.controller = ControllerService()
        self.controller.startService()
        self.multiengine = me.ISynchronousMultiEngine(me.IMultiEngine(self.controller))
        self.engines = []
        
    def tearDown(self):
        self.controller.stopService()
        for e in self.engines:
            e.stopService()
class SynchronousMultiEngineTestCase(DeferredTestCase,
                                     IMultiEngineBaseTestCase):
    def setUp(self):
        self.controller = ControllerService()
        self.controller.startService()
        self.multiengine = IMultiEngine(self.controller)
        self.smultiengine = ISynchronousMultiEngine(self.multiengine)
        self.engines = []

    def tearDown(self):
        self.controller.stopService()
        for e in self.engines:
            e.stopService()

    def testExecuteNoBlock(self):
        nengines = 2
        self.addEngine(nengines)
        cmd = 'a=5'
        results = [self.createShell().execute(cmd) for i in range(nengines)]
        for i, s in enumerate(results):
            s['id'] = i
        cid = self.smultiengine.registerClient()
        d = self.smultiengine.execute(cid, False, 'all', cmd)
        d.addCallback(
            lambda r: self.smultiengine.getPendingDeferred(cid, r, True))
        d.addCallback(lambda r: self.assert_(r == results))
        return d

    def testExecuteBlock(self):
        nengines = 2
        self.addEngine(nengines)
        cmd = 'a=5'
        results = [self.createShell().execute(cmd) for i in range(nengines)]
        for i, s in enumerate(results):
            s['id'] = i
        cid = self.smultiengine.registerClient()
        d = self.smultiengine.execute(cid, True, 'all', cmd)
        d.addCallback(lambda r: self.assert_(r == results))
        return d