Ejemplo n.º 1
0
class TestMessaging(object):

    def setup(self):
        url = 'unix://\0one_test_socket/service'
        self.node1 = Node()
        self.node1.register(Namespace())
        self.node1.serve(url)

        self.node2 = Node()
        self.proxy = self.node2.connect(url)

    def teardown(self):
        self.node2.shutdown()
        self.node1.shutdown()

    def test_req_rep(self):
        assert self.proxy.echo('test') == b'test passed'

    def test_exception(self):
        try:
            self.proxy.error()
        except RuntimeError:
            pass
Ejemplo n.º 2
0
class TestPush(object):

    def setup(self):
        self.url_tcp = 'tcp://0.0.0.0:9823/push'
        self.url_udp = 'udp://0.0.0.0:9823/push'
        self.node1 = Node()
        self.node1.serve(self.url_tcp)
        self.node1.serve(self.url_udp)
        self.node1.mirror()
        self.node2 = Node()

    def teardown(self):
        self.node2.shutdown()
        self.node1.shutdown()

    def test_tcp_push(self):
        proxy = self.node2.target(self.url_tcp)
        proxy.push('test1')
        assert self.node1.get() == b'test1'

    def test_udp_push(self):
        proxy = self.node2.target(self.url_tcp, self.url_udp, NLT_DGRAM)
        proxy.push('test2')
        assert self.node1.get() == b'test2'
Ejemplo n.º 3
0
#!/usr/bin/python
'''
Messaging node: "client" role
'''
from pyroute2.rpc import Node

node = Node()
proxy = node.connect('tcp://localhost:9824')
print(proxy.echo('test'))
node.shutdown()
Ejemplo n.º 4
0
from pyroute2.rpc import public
from pyroute2.rpc import Node


# define test echo server
class Namespace(object):
    @public
    def echo(self, msg):
        return '%s passed' % (msg)


# start server and client
url = 'tcp://localhost:9824/service'
node1 = Node()
node1.register(Namespace())
node1.serve(url)

node2 = Node()
proxy = node2.connect(url)

# request echo call
print(proxy.echo('test'))

node1.shutdown()
node2.shutdown()
Ejemplo n.º 5
0
'''
Push/pull using RPC
'''
from pyroute2.rpc import Node

# create the first endpoint, serve two sockets
node1 = Node()
node1.serve('tcp://0.0.0.0:9824/push')
node1.mirror()

# create the second endpoint, connect via TCP
node2 = Node()
proxy1 = node2.target('tcp://0.0.0.0:9824/push')
proxy1.push('hello, world!')

# wait the message on the first endpoint
print('waiting message from client')
msg = node1.get()
print(msg)

node2.shutdown()
node1.shutdown()
Ejemplo n.º 6
0
'''
Push/pull using RPC
'''
from pyroute2.rpc import Node

# create the first endpoint, serve two sockets
ioc1 = Node()
ioc1.serve('tcp://0.0.0.0:9824/push')
ioc1.mirror()

# create the second endpoint, connect via TCP
ioc2 = Node()
proxy1 = ioc2.target('tcp://0.0.0.0:9824/push')
proxy1.push('hello, world!')

# wait the message on the first endpoint
print('waiting message from client')
msg = ioc1.get()
print(msg)

ioc2.shutdown()
ioc1.shutdown()