示例#1
0
文件: link.py 项目: flaper87/pyngus
    def test_dynamic_receiver_props(self):
        """Verify dynamic-node-properties can be requested."""
        # dynamic receive link:
        DELETE_ON_CLOSE = 0x000000000000002b
        desired_props = {symbol("lifetime-policy"): DELETE_ON_CLOSE}
        props = {"dynamic-node-properties": desired_props}
        sender = self.conn1.create_sender("saddr",
                                          target_address=None,
                                          properties=props)
        sender.open()
        self.process_connections()
        assert self.conn2_handler.receiver_requested_ct == 1
        args = self.conn2_handler.receiver_requested_args[0]
        dnp = args.properties.get('dynamic-node-properties')
        assert dnp and dnp == desired_props

        # dynamic send link:
        desired_props = {symbol("supported-dist-modes"):
                         [symbol("move"), symbol("copy")]}
        props = {"dynamic-node-properties": desired_props}
        receiver = self.conn1.create_receiver("taddr",
                                              source_address=None,
                                              properties=props)
        receiver.open()
        self.process_connections()
        assert self.conn2_handler.sender_requested_ct == 1
        args = self.conn2_handler.sender_requested_args[0]
        dnp = args.properties.get('dynamic-node-properties')
        assert dnp and dnp == desired_props
 def on_start(self, event):
     self.timer          = event.reactor.schedule(10.0, Timeout(self))
     self.sender_conn    = event.container.connect(self.sender_host)
     self.receiver_conn  = event.container.connect(self.receiver_host)
     self.waypoint_conn  = event.container.connect(self.waypoint_host)
     self.sender         = event.container.create_sender(self.sender_conn, self.addr)
     self.receiver       = event.container.create_receiver(self.receiver_conn, self.addr)
     self.wp_sender      = event.container.create_sender(self.waypoint_conn, self.addr)
     self.wp_receiver    = event.container.create_receiver(self.waypoint_conn, self.addr)
     self.wp_sender.target.capabilities.put_object(symbol("qd.waypoint"))
     self.wp_receiver.source.capabilities.put_object(symbol("qd.waypoint"))
示例#3
0
 def __init__(self, props={}):
     self.properties = {}
     for k in props:
         if isinstance(k, symbol):
             self.properties[k] = props[k]
         else:
             self.properties[symbol(k)] = props[k]
 def on_start(self, event):
     self.timer              = event.reactor.schedule(10.0, Timeout(self))
     self.sender_conn        = event.container.connect(self.sender_host)
     self.primary_conn       = event.container.connect(self.primary_host)
     self.fallback_conn     = event.container.connect(self.fallback_host)
     self.primary_receiver   = event.container.create_receiver(self.primary_conn, self.addr)
     self.fallback_receiver = event.container.create_receiver(self.primary_conn, self.addr, name=self.addr)
     self.fallback_receiver.source.capabilities.put_object(symbol("qd.fallback"))
    def on_start(self, event):
        self.timer          = event.reactor.schedule(10.0, Timeout(self))
        self.sender_conn    = event.container.connect(self.sender_host)
        self.receiver_conn  = event.container.connect(self.receiver_host)
        self.sender         = event.container.create_sender(self.sender_conn, self.addr)
        self.receiver       = event.container.create_receiver(self.receiver_conn, self.addr)
        for host in self.waypoint_hosts:
            self.waypoint_conns.append(event.container.connect(host))

        ordinal = 1
        for conn in self.waypoint_conns:
            sender   = event.container.create_sender(conn, self.addr)
            receiver = event.container.create_receiver(conn, self.addr)

            sender.target.capabilities.put_object(symbol("qd.waypoint.%d" % ordinal))
            receiver.source.capabilities.put_object(symbol("qd.waypoint.%d" % ordinal))

            self.wp_senders.append(sender)
            self.wp_receivers.append(receiver)
            ordinal += 1
示例#6
0
    def declare_transaction(self, context, handler=None, settle_before_discharge=False):
        if not _get_attr(context, '_txn_ctrl'):
            class InternalTransactionHandler(OutgoingMessageHandler):
                def __init__(self):
                    super(InternalTransactionHandler, self).__init__(auto_settle=True)

                def on_settled(self, event):
                    if hasattr(event.delivery, "transaction"):
                        event.transaction = event.delivery.transaction
                        event.delivery.transaction.handle_outcome(event)
            context._txn_ctrl = self.create_sender(context, None, name='txn-ctrl', handler=InternalTransactionHandler())
            context._txn_ctrl.target.type = Terminus.COORDINATOR
            context._txn_ctrl.target.capabilities.put_object(symbol(u'amqp:local-transactions'))
        return Transaction(context._txn_ctrl, handler, settle_before_discharge)
 def on_sendable(self, event):
     if not self.sent:
         msg = Message()
         msg.address = self.address
         msg.id = '123455'
         msg.user_id = 'testuser'
         msg.subject = 'test-subject'
         msg.content_type = 'text/html; charset=utf-8'
         msg.correlation_id = 89
         msg.creation_time = 1487772623.883
         msg.group_id = "group1"
         msg.reply_to = 'hello_world'
         msg.content_encoding = 'gzip, deflate'
         msg.reply_to_group_id = "group0"
         application_properties = dict()
         application_properties['app-property'] = [10, 20, 30]
         application_properties['some-other'] = symbol("O_one")
         msg.properties = application_properties
         msg.body = u"Hello World!"
         event.sender.send(msg)
         self.sent = True
示例#8
0
 def __init__(self, value, name='selector'):
     super(Selector, self).__init__({symbol(name): Described(symbol('apache.org:selector-filter:string'), value)})
示例#9
0
 def discharge(self, failed):
     self.failed = failed
     self._discharge = self._send_ctrl(symbol(u'amqp:discharge:list'), [self.id, failed])
示例#10
0
 def declare(self):
     self._declare = self._send_ctrl(symbol(u'amqp:declare:list'), [None])
示例#11
0
from __future__ import absolute_import

from threading import Thread, Event
from uuid import uuid4

from proton import Message, Url, Array, UNDESCRIBED, Data, symbol, ConnectionException
from proton.handlers import MessagingHandler
from proton.reactor import Container
from proton.utils import SyncRequestResponse, BlockingConnection

from .common import Test, free_tcp_port
from .common import ensureCanTestExtendedSASL

CONNECTION_PROPERTIES={u'connection': u'properties'}
OFFERED_CAPABILITIES = Array(UNDESCRIBED, Data.SYMBOL, symbol("O_one"), symbol("O_two"), symbol("O_three"))
DESIRED_CAPABILITIES = Array(UNDESCRIBED, Data.SYMBOL, symbol("D_one"), symbol("D_two"), symbol("D_three"))
ANONYMOUS='ANONYMOUS'
EXTERNAL='EXTERNAL'


class EchoServer(MessagingHandler, Thread):
    """
    Simple echo server that echos messages to their reply-to. Runs in a thread.
    Will only accept a single connection and shut down when that connection closes.
    """

    def __init__(self, url, timeout):
        MessagingHandler.__init__(self)
        Thread.__init__(self)
        self.daemon = True
示例#12
0
 def test_non_unicode_selector(self):
     assert Selector(b"Hello").filter_set[symbol('selector')].value == u"Hello"