Example #1
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
Example #2
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:
Example #3
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:
Example #4
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: