示例#1
0
class TestTransportFactory(unittest.TestCase, iIpcTransportStateChangeListener, iIpcTransportDataReceiveListener):
    def setUp(self):
        self.transportDetails = QueueTransportDetails()
        self.transactionManager = TransactionManager()
        self.scl = self
        self.drl = self
    def teasrDown(self):
        self.transportDetails.del_qRx()
        self.transportDetails.del_qTx()
        del self.transportDetails
    def testHeadMQueue(self):
        h = TransportFactory.get(eHeadType.HEAD, self.transportDetails, self.transactionManager, self, self)
        assert isinstance(h, ApiArb)
        assert isinstance(h, iIpcTransport)
    def testNeckMQueue(self):
        h = TransportFactory.get(eHeadType.NECK, self.transportDetails, self.transactionManager, self, self)
        assert isinstance(h, ApiArb)
        assert isinstance(h, iIpcTransport)
    def testHeadMQueueNoArb(self):
        h = TransportFactory.getNoArb(eHeadType.HEAD, self.transportDetails, self.transactionManager, self, self)
        assert isinstance(h, HeadQueueTransporter)
        assert isinstance(h, iIpcTransport)
    def testNeckMQueueNoArb(self):
        h = TransportFactory.getNoArb(eHeadType.NECK, self.transportDetails, self.transactionManager, self, self)
        assert isinstance(h, QueueTransporter)
        assert isinstance(h, iIpcTransport)
    def testInvalidType(self):
        headType = eHeadType.HEAD
        type_ = eIpcTransportType.MQUEUE + "hello.world!"
        self.transportDetails._type = type_
        try:
            TransportFactory.get(headType, self.transportDetails, self.transactionManager, self, self)
        except ApiParamError, e:
            assert e.item == type_
            assert len(e.allowedTypes) == 1
            assert eIpcTransportType in e.allowedTypes
        else:
示例#2
0
 def setUp(self):
     self.logger = LogManager().getLogger("test")
     self.mr = MyResult()
     #    Create the IPC:
     tmHead = TransactionManager(HeadTransactionIdGenerator())
     tmNeck = TransactionManager(NeckTransactionIdGenerator())
     self.hl = My1Listener()
     self.nl = My1Listener()
     self.qTransport = QueueTransportDetails()
     self.ipcHead = QueueTransporter(self.qTransport, tmHead, self.hl, logger=LogManager().getLogger("Head"))
     self.ipcNeck = QueueTransporter(self.qTransport.invert(), tmNeck, self.nl, logger=LogManager().getLogger("Neck"))
     #    Symmetrical api:
     self.apiHead = Api("test")
     self.apiHead.ipc = self.ipcHead
     self.apiNeck = Api("test", solicited=True)
     self.apiNeck.ipc = self.ipcNeck
     #    Set the expected result object:
     self.apiNeck.parent.eResult = self.mr
示例#3
0
class TestRoundTripSynchronousUnsolicitedNeck(unittest.TestCase):
    def setUp(self):
        self.logger = LogManager().getLogger("test")
        self.mr = MyResult()
        #    Create the IPC:
        tmHead = TransactionManager(HeadTransactionIdGenerator())
        tmNeck = TransactionManager(NeckTransactionIdGenerator())
        self.hl = My1Listener()
        self.nl = My1Listener()
        self.qTransport = QueueTransportDetails()
        self.ipcHead = QueueTransporter(self.qTransport, tmHead, self.hl, logger=LogManager().getLogger("Head"))
        self.ipcNeck = QueueTransporter(self.qTransport.invert(), tmNeck, self.nl, logger=LogManager().getLogger("Neck"))
        #    Symmetrical api:
        self.apiHead = Api("test")
        self.apiHead.ipc = self.ipcHead
        self.apiNeck = Api("test", solicited=False)
        self.apiNeck.ipc = self.ipcNeck
        #    Set the expected result object:
        self.apiNeck.parent.eResult = self.mr
    def tearDown(self):
        self.ipcHead.close(ignoreErrors=True)
        self.ipcNeck.close(ignoreErrors=True)
        try:    self.apiHead.teardown()
        except: pass
        try:    self.apiNeck.teardown()
        except: pass
    def testHeadCatchallUnsolicitedEvent(self):
        eResult = Result()
        self.apiHead.parent.eResult = eResult
        self.ipcHead.connect()
        self.ipcNeck.connect()
        args = (0, 1, 2, 3)
        kwargs = {"four":4, "five":5}
        api = self.apiNeck.parent.method_b(*args, **kwargs)
        #    Test the API is unsupported first:
        #    Make it solicited so we can test that it's not supported:
        api.solicited = True
        try:
            api()
        except UnsupportedApiError, e:
            assert e.ns().lower() == u"api.parent.method_b"
        else:
示例#4
0
 def setUp(self):
     self.transportDetails = QueueTransportDetails()
     self.transactionManager = TransactionManager()
     self.scl = self
     self.drl = self
示例#5
0
class TestRoundTripSynchronous(unittest.TestCase):
    def setUp(self):
        self.logger = LogManager().getLogger("test")
        self.mr = MyResult()
        #    Create the IPC:
        tmHead = TransactionManager(HeadTransactionIdGenerator())
        tmNeck = TransactionManager(NeckTransactionIdGenerator())
        self.hl = My1Listener()
        self.nl = My1Listener()
        self.qTransport = QueueTransportDetails()
        self.ipcHead = QueueTransporter(self.qTransport, tmHead, self.hl, logger=LogManager().getLogger("Head"))
        self.ipcNeck = QueueTransporter(self.qTransport.invert(), tmNeck, self.nl, logger=LogManager().getLogger("Neck"))
        #    Symmetrical api:
        self.apiHead = Api("test")
        self.apiHead.ipc = self.ipcHead
        self.apiNeck = Api("test", solicited=True)
        self.apiNeck.ipc = self.ipcNeck
        #    Set the expected result object:
        self.apiNeck.parent.eResult = self.mr
    def tearDown(self):
        self.ipcHead.close(ignoreErrors=True)
        self.ipcNeck.close(ignoreErrors=True)
        try:    self.apiHead.teardown()
        except: pass
        try:    self.apiNeck.teardown()
        except: pass
    def test(self):
        r"""
        Create a single 2 layer symmetrical api with
        simple cause-and-effect.
        """ 
        self.ipcHead.connect()
        self.ipcNeck.connect()
        args = (0, 1, 2, 3)
        kwargs = {"four":4, "five":5}
        api = self.apiHead.parent.method_a(*args, **kwargs)
        self.mr.returnExact = True
        result = api()
        assert result[0] == args
        assert result[1] == kwargs
    def testCustomResult(self):
        r"""
        Create a single 2 layer symmetrical api with
        simple cause-and-effect.
        """ 
        eResult = Result()
        self.apiHead.parent.eResult = eResult
        self.ipcHead.connect()
        self.ipcNeck.connect()
        args = (0, 1, 2, 3)
        kwargs = {"four":4, "five":5}
        api = self.apiHead.parent.method_a(*args, **kwargs)
        self.mr.returnExact = False
        self.mr.altResult = eResult
        result = api()
        assert result.args == eResult.args, "Got: %(R)s" % {"R":result}
    def testCustomExceptionResult(self):
        eResult = ExceptionResult()
        self.apiHead.parent.eResult = eResult
        self.ipcHead.connect()
        self.ipcNeck.connect()
        args = (0, 1, 2, 3)
        kwargs = {"four":4, "five":5}
        api = self.apiHead.parent.method_a(*args, **kwargs)
        self.mr.returnExact = False
        self.mr.altResult = eResult
        try:
            api()
        except ExceptionResult, _e:
            assert True
        else:
示例#6
0
class TestRoundTripAsynchronous(unittest.TestCase):
    def setUp(self):
        self.logger = LogManager().getLogger("test")
        self.mr = MyResult()
        #    Create the IPC:
        tmHead = TransactionManager(HeadTransactionIdGenerator())
        tmNeck = TransactionManager(NeckTransactionIdGenerator())
        self.hl = My1Listener()
        self.nl = My1Listener()
        self.qTransport = QueueTransportDetails()
        self.ipcHead = QueueTransporter(self.qTransport, tmHead, self.hl, logger=LogManager().getLogger("Head"))
        self.ipcNeck = QueueTransporter(self.qTransport.invert(), tmNeck, self.nl, logger=LogManager().getLogger("Neck"))
        #    Symmetrical api:
        self.apiHead = Api("test")
        self.apiHead.ipc = self.ipcHead
        self.apiNeck = Api("test", solicited=True)
        self.apiNeck.ipc = self.ipcNeck
        #    Set the expected result object:
        self.apiNeck.parent.eResult = self.mr
    def tearDown(self):
        self.ipcHead.close(ignoreErrors=True)
        self.ipcNeck.close(ignoreErrors=True)
        try:    self.apiHead.teardown()
        except: pass
        try:    self.apiNeck.teardown()
        except: pass
    def test(self):
        self.ipcHead.connect()
        self.ipcNeck.connect()
        args = (0, 1, 2, 3)
        kwargs = {"four":4, "five":5}
        api = self.apiHead.parent.method_a(*args, **kwargs)
        self.mr.returnExact = True
        #    Make the call asynchronous:
        api.sync = eSync.ASYNCHRONOUS
        asyncResult = api()
        assert isinstance(asyncResult, iAsyncResult)
        #    Now wait on the asynchronous result:
        result = asyncResult.acquireNew()
        assert result == (args, kwargs)
        #    Check that the tId is NOT purged.
        assert asyncResult.tId() in self.ipcHead.getTransactionManager()._items
    def testWithPurge(self):
        self.ipcHead.connect()
        self.ipcNeck.connect()
        args = (0, 1, 2, 3)
        kwargs = {"four":4, "five":5}
        api = self.apiHead.parent.method_a(*args, **kwargs)
        self.mr.returnExact = True
        #    Make the call asynchronous:
        api.sync = eSync.ASYNCHRONOUS
        asyncResult = api()
        assert isinstance(asyncResult, iAsyncResult)
        #    Now wait on the asynchronous result:
        result = asyncResult.acquireNew(purge=True)
        assert result == (args, kwargs)
        #    Check that the tId IS purged.
        assert asyncResult.tId() not in self.ipcHead.getTransactionManager()._items
    def testCustomResult(self):
        eResult = Result()
        self.apiHead.parent.eResult = eResult
        self.ipcHead.connect()
        self.ipcNeck.connect()
        args = (0, 1, 2, 3)
        kwargs = {"four":4, "five":5}
        api = self.apiHead.parent.method_a(*args, **kwargs)
        #    Make the call asynchronous:
        api.sync = eSync.ASYNCHRONOUS
        self.mr.returnExact = False
        self.mr.altResult = eResult
        asyncResult = api()
        assert isinstance(asyncResult, iAsyncResult)
        #    Now wait on the asynchronous result:
        result = asyncResult.acquireNew()
        assert result.args == eResult.args, "Got: %(R)s" % {"R":result}
    def testCustomExceptionResult(self):
        eResult = ExceptionResult()
        self.apiHead.parent.eResult = eResult
        self.ipcHead.connect()
        self.ipcNeck.connect()
        args = (0, 1, 2, 3)
        kwargs = {"four":4, "five":5}
        api = self.apiHead.parent.method_a(*args, **kwargs)
        #    Make the call asynchronous:
        api.sync = eSync.ASYNCHRONOUS
        self.mr.returnExact = False
        self.mr.altResult = eResult
        asyncResult = api()
        assert isinstance(asyncResult, iAsyncResult)
        try:
            #    Now wait on the asynchronous result:
            asyncResult.acquireNew()
        except ExceptionResult, _result:
            assert True
        else: