class FactoryG(FactoryD): def setUp(self): kwargs = {'spec': 'file:../txamqp_ext/spec/amqp0-8.xml', 'parallel': False, 'exchange': EXC, 'full_content': True, 'delivery_mode': 1, 'parallel': False, 'timeout': 10, 'rk': RK2 } kwargs2 = copy(kwargs) kwargs2['push_back'] = True self.f = AmqpSynFactory(self, **kwargs) self.f.setup_read_queue(EXC, durable=False, auto_delete=True, exclusive=True) self.f2 = SimpleListenFactory(self, spec = 'file:../txamqp_ext/spec/amqp0-8.xml', rq_rk=RK2, exchange=EXC, callback=self._test_echoer, rq_durable=False, rq_autodelete = True, exclusive = True, no_ack = True, ) dl = DeferredList([self.f.connected, self.f2.connected]) return dl def _test_echoer(self, msg, d): return d.callback(msg)
def setUp(self): kwargs_fwdr = { "spec": "file:../txamqp_ext/spec/amqp0-9-1.xml", "parallel": True, "full_content": True, "skip_decoding": True, "skip_encoding": True, } self.forwarder = AmqpReconnectingFactory(self, **kwargs_fwdr) self.forwarder.setup_read_queue( EXC, RK2, self.fwdr_handle, queue_name="forwarder", durable=False, auto_delete=True ) self.backwarder = AmqpReconnectingFactory(self, **kwargs_fwdr) self.backwarder.setup_read_queue( EXC, RK3, self.fwdr_handle, queue_name="backwarder", durable=False, auto_delete=True ) kwargs_common = { "spec": "file:../txamqp_ext/spec/amqp0-9-1.xml", "parallel": True, "exchange": EXC, "serialization": "content_based", "rk": RK2, } kwargs_json = copy(kwargs_common) kwargs_json["default_content_type"] = "application/json" self.push_json = AmqpSynFactory(self, **kwargs_json) self.push_json.setup_read_queue(EXC, "route_json", durable=False, auto_delete=True) kwargs_pickle = copy(kwargs_common) kwargs_pickle["default_content_type"] = "application/x-pickle" self.push_pickle = AmqpSynFactory(self, **kwargs_pickle) self.push_pickle.setup_read_queue(EXC, "route_pickle", durable=False, auto_delete=True) kwargs_responder = { "spec": "file:../txamqp_ext/spec/amqp0-9-1.xml", "parallel": True, "push_back": True, "full_content": True, "serialization": "content_based", "default_content_type": "application/json", } self.responder = AmqpReconnectingFactory(self, **kwargs_responder) self.responder.setup_read_queue( EXC, RK, self.msg_handle, queue_name="responder", durable=False, auto_delete=True ) return DeferredList( [ self.forwarder.connected, self.backwarder.connected, self.push_json.connected, self.push_pickle.connected, self.responder.connected, ] )
def setUp(self): kwargs = {'spec': 'file:../txamqp_ext/spec/amqp0-8.xml', 'parallel': False, 'exchange': EXC, 'full_content': True, 'delivery_mode': 1, 'parallel': False, 'tid_name': 'webID', 'rb_name': 'routing_key', 'timeout':15, 'rk': RK } kwargs2 = copy(kwargs) kwargs2['push_back'] = True self.f = AmqpSynFactory(self, **kwargs) self.f.setup_read_queue(EXC, durable=False, auto_delete=True, exclusive=True) self.f2 = SimpleListenFactory(self, spec = 'file:../txamqp_ext/spec/amqp0-8.xml', rq_rk=RK, rq_name = QUE, exchange=EXC, callback=self._test_echoer, tid_name='webID', rb_name='routing_key' ) dl = DeferredList([self.f.connected, self.f2.connected]) return dl
class FactoryF(FactoryD): def setUp(self): kwargs = {'spec': 'file:../txamqp_ext/spec/amqp0-8.xml', 'exchange': EXC, 'full_content': True, 'delivery_mode': 1, 'serialization': 'cPickle', 'parallel': False, 'rk': RK2 } kwargs2 = copy(kwargs) kwargs2['push_back'] = True self.f = AmqpSynFactory(self, **kwargs) self.f.setup_read_queue(EXC, durable=False, auto_delete=True, exclusive=True) self.f2 = AmqpReconnectingFactory(self, **kwargs2) d = self.f2.setup_read_queue(EXC, RK2, self._test_echoer, durable=False, auto_delete=True, exclusive=True) dl = DeferredList([self.f.connected, self.f2.connected]) return dl
def setUp(self): kwargs = {'spec': 'file:../txamqp_ext/spec/amqp0-8.xml', 'parallel': False, 'exchange': EXC, 'full_content': True, 'delivery_mode': 1, 'timeout': 10, 'rk': RK2 } self.f = AmqpSynFactory(self, **kwargs) self.f.setup_read_queue(EXC, RK3, durable=False, auto_delete=True, exclusive=True) self.f2 = AmqpReconnectingFactory(self, **kwargs) d = self.f2.setup_read_queue(EXC, RK2, self._test_echoer, durable=False, auto_delete=True, exclusive=True) return DeferredList([self.f.connected, self.f2.connected])
class FactoryD(TestCase): timeout = 10 def setUp(self): kwargs = {'spec': 'file:../txamqp_ext/spec/amqp0-8.xml', 'parallel': False, 'exchange': EXC, 'full_content': True, 'timeout': 1, 'delivery_mode': 1, 'rk': RK2 } kwargs2 = copy(kwargs) kwargs2['push_back'] = True self.f = AmqpSynFactory(self, **kwargs) self.f.setup_read_queue(EXC, durable=False, auto_delete=True, exclusive=True) self.f2 = AmqpReconnectingFactory(self, **kwargs2) d = self.f2.setup_read_queue(EXC, RK2, self._test_echoer, durable=False, auto_delete=True, exclusive=True) dl = DeferredList([self.f.connected, self.f2.connected]) return dl def _test_echoer(self, msg, d): tid=msg['headers'].get('tid') return d.callback(tid) def test_01_pb_basic_start(self): pass def test_02_pb_send_rec(self): d1 = Deferred() def _get_result(result): print 'GOT RESULT: %r'%result d1.callback(True) def _push_msg(): print 'PUSH MESSAGE' d = self.f.push_message('test') d.addCallback(_get_result) reactor.callLater(0.05, _push_msg) return DeferredList([d1]) def test_03_pb_send_rec_many(self): d = {} def _get_result(result): tid = result['headers'][self.f.tid_name] assert result.body == tid, 'body: %r'%result.body d[tid].callback(True) for i in xrange(250): tid = str(int(time.time()*1e7)) d[tid] = Deferred() d1 = self.f.push_message(tid, tid=tid) d1.addCallback(_get_result) d1.addErrback(self._err) return DeferredList(d.values()) def test_04_reconnect(self): d = Deferred() def _sleep(n): s = Deferred() reactor.callLater(n, s.callback, True) return s def _get_result(result): d.callback(True) def _no_result(failure): print '%s'%failure.getTraceback() raise Exception('No result') def _resend(failure): d1 = self.f.push_message('test', timeout_sec=5) d1.addCallbacks(_get_result, _no_result) def sl(failure): s = _sleep(3) print 'Resend. %s'%failure.getTraceback() s.addCallback(_resend) def _ecb(*_any): raise Exception('ERR: %r'%(_any)) def push_first(): d1 = self.f.push_message('test', timeout_sec=0.5) d1.addCallback(_ecb) d1.addErrback(sl) self.f.client.shutdown_protocol() push_first() return d def _err(self, failure): raise failure def tearDown(self): dl = [] dl.append(self.f.shutdown_factory()) dl.append(self.f2.shutdown_factory()) return DeferredList(dl)
class FactoryC(TestCase): timeout = 10 def setUp(self): kwargs = {'spec': 'file:../txamqp_ext/spec/amqp0-8.xml', 'parallel': False, 'exchange': EXC, 'full_content': True, 'delivery_mode': 1, 'timeout': 10, 'rk': RK2 } self.f = AmqpSynFactory(self, **kwargs) self.f.setup_read_queue(EXC, RK3, durable=False, auto_delete=True, exclusive=True) self.f2 = AmqpReconnectingFactory(self, **kwargs) d = self.f2.setup_read_queue(EXC, RK2, self._test_echoer, durable=False, auto_delete=True, exclusive=True) return DeferredList([self.f.connected, self.f2.connected]) def _test_echoer(self, msg): c = Content(msg.body) c['headers'] = {'tid': msg['headers'].get('tid')} c['tid'] = msg['headers'].get('tid') #c['tid'] = msg['tid'] self.f2.send_message(EXC, RK3, c, tid=msg['headers'].get('tid')) def test_01_basic_start(self): pass def test_02_send_rec(self): d1 = Deferred() def _get_result(result): print 'GOT RESULT: %r'%result d1.callback(True) d = self.f.push_message('test') d.addCallback(_get_result) return DeferredList([d1, d]) def test_03_send_rec_many(self): d = {} def _get_result(result): tid = result['headers']['tid'] assert result.body == tid, 'body: %r'%result.body d[tid].callback(True) for i in xrange(500): tid = str(int(time.time()*1e7)) d[tid] = Deferred() d1 = self.f.push_message(tid, tid=tid) d1.addCallback(_get_result) d1.addErrback(self._err) return DeferredList(d.values()) def _err(self, failure): raise failure def tearDown(self): dl = [] dl.append(self.f.shutdown_factory()) dl.append(self.f2.shutdown_factory()) return DeferredList(dl)
class TestContentTypes(TestCase): timeout = 4 def setUp(self): kwargs_fwdr = { "spec": "file:../txamqp_ext/spec/amqp0-9-1.xml", "parallel": True, "full_content": True, "skip_decoding": True, "skip_encoding": True, } self.forwarder = AmqpReconnectingFactory(self, **kwargs_fwdr) self.forwarder.setup_read_queue( EXC, RK2, self.fwdr_handle, queue_name="forwarder", durable=False, auto_delete=True ) self.backwarder = AmqpReconnectingFactory(self, **kwargs_fwdr) self.backwarder.setup_read_queue( EXC, RK3, self.fwdr_handle, queue_name="backwarder", durable=False, auto_delete=True ) kwargs_common = { "spec": "file:../txamqp_ext/spec/amqp0-9-1.xml", "parallel": True, "exchange": EXC, "serialization": "content_based", "rk": RK2, } kwargs_json = copy(kwargs_common) kwargs_json["default_content_type"] = "application/json" self.push_json = AmqpSynFactory(self, **kwargs_json) self.push_json.setup_read_queue(EXC, "route_json", durable=False, auto_delete=True) kwargs_pickle = copy(kwargs_common) kwargs_pickle["default_content_type"] = "application/x-pickle" self.push_pickle = AmqpSynFactory(self, **kwargs_pickle) self.push_pickle.setup_read_queue(EXC, "route_pickle", durable=False, auto_delete=True) kwargs_responder = { "spec": "file:../txamqp_ext/spec/amqp0-9-1.xml", "parallel": True, "push_back": True, "full_content": True, "serialization": "content_based", "default_content_type": "application/json", } self.responder = AmqpReconnectingFactory(self, **kwargs_responder) self.responder.setup_read_queue( EXC, RK, self.msg_handle, queue_name="responder", durable=False, auto_delete=True ) return DeferredList( [ self.forwarder.connected, self.backwarder.connected, self.push_json.connected, self.push_pickle.connected, self.responder.connected, ] ) def tearDown(self): return DeferredList( [ self.forwarder.shutdown_factory(), self.backwarder.shutdown_factory(), self.push_json.shutdown_factory(), self.push_pickle.shutdown_factory(), self.responder.shutdown_factory(), ] ) @inlineCallbacks def msg_handle(self, full_msg, d): yield d.callback(full_msg) @inlineCallbacks def fwdr_handle(self, msg): real_back = msg["headers"].get("real_rb") if not real_back: msg["headers"]["real_rb"] = msg["headers"]["route_back"] msg["headers"]["route_back"] = RK3 yield self.forwarder.send_message(EXC, RK, msg) else: yield self.backwarder.send_message(EXC, msg["headers"]["real_rb"], msg) def test_0000(self): return def test_0001(self): d_json = Deferred() d_pickle = Deferred() @inlineCallbacks def run_json(): yield self.push_json.push_message({"test_message": 1}) d_json.callback(True) @inlineCallbacks def run_pickle(): yield self.push_pickle.push_message({"test_message": 1}) d_pickle.callback(True) run_json() run_pickle() return DeferredList([d_json, d_pickle])