예제 #1
0
 def onConnectionLost(self, connection, reason):  # @UnusedVariable
     for waiting in self._receipts.values():
         if waiting.called:
             continue
         waiting.errback(
             StompCancelledError(
                 'Receipt did not arrive (connection lost)'))
예제 #2
0
 def onConnect(self, connection, frame,
               connectedTimeout):  # @UnusedVariable
     self._waiting = WaitingDeferred()
     yield self._waiting.wait(
         connectedTimeout,
         StompCancelledError(
             'STOMP broker did not answer on time [timeout=%s]' %
             connectedTimeout))
예제 #3
0
 def onSend(self, connection, frame): # @UnusedVariable
     if not frame:
         defer.returnValue(None)
     receipt = frame.headers.get(StompSpec.RECEIPT_HEADER)
     if receipt is None:
         defer.returnValue(None)
     with self._receipts(receipt, self.log) as receiptArrived:
         yield receiptArrived.wait(self._timeout, StompCancelledError('Receipt did not arrive on time: %s [timeout=%s]' % (receipt, self._timeout)))
예제 #4
0
 def _waitForMessages(self, timeout):
     return task.cooperate(
         handler.wait(
             timeout, StompCancelledError(
                 'Handlers did not finish in time.'))
         for handler in self._messages.values()).whenDone()
예제 #5
0
    def test_context_single(self):
        op = InFlightOperations('test')
        with op(1) as w:
            self.assertEquals(list(op), [1])
            self.assertIsInstance(w, defer.Deferred)
            self.assertIdentical(w, op[1])
            self.assertIdentical(op.get(1), op[1])
        self.assertEquals(list(op), [])

        with op(key=2, log=logging.getLogger(LOG_CATEGORY)):
            self.assertEquals(list(op), [2])
            self.assertIsInstance(op.get(2), defer.Deferred)
            self.assertIdentical(op.get(2), op[2])
        self.assertEquals(list(op), [])

        try:
            with op(None, logging.getLogger(LOG_CATEGORY)) as w:
                reactor.callLater(0, w.cancel)  # @UndefinedVariable
                yield w.wait(timeout=None, fail=None)
        except CancelledError:
            pass
        else:
            raise
        self.assertEquals(list(op), [])

        try:
            with op(None, logging.getLogger(LOG_CATEGORY)) as w:
                reactor.callLater(
                    0, w.errback,
                    StompCancelledError('4711'))  # @UndefinedVariable
                yield w.wait()
        except StompCancelledError as e:
            self.assertEquals(str(e), '4711')
        else:
            raise
        self.assertEquals(list(op), [])

        with op(None, logging.getLogger(LOG_CATEGORY)) as w:
            reactor.callLater(0, w.callback, 4711)  # @UndefinedVariable
            result = yield w.wait()
            self.assertEquals(result, 4711)
        self.assertEquals(list(op), [])

        try:
            with op(None) as w:
                raise RuntimeError('hi')
        except RuntimeError:
            pass
        self.assertEquals(list(op), [])
        try:
            yield w
        except RuntimeError as e:
            self.assertEquals(str(e), 'hi')
        else:
            raise

        try:
            with op(None) as w:
                d = w.wait()
                raise RuntimeError('hi')
        except RuntimeError:
            pass
        self.assertEquals(list(op), [])
        try:
            yield d
        except RuntimeError as e:
            self.assertEquals(str(e), 'hi')
        else:
            pass