Пример #1
0
 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()
Пример #2
0
    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)
Пример #3
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
Пример #4
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'
Пример #5
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()
Пример #6
0
#!/usr/bin/python
'''
Messaging node: "server" role.

Please note, that "server" or "client" role is not a
property of the node, it is just a way you use it.
'''
import sys
from pyroute2.rpc import Node
from pyroute2.rpc import public


class Namespace(object):
    '''
    Just a namespace to publish procedures
    '''
    @public
    def echo(self, msg):
        return '%s passed' % (msg)

node = Node()
node.register(Namespace())
node.serve('tcp://localhost:9824')
print(' hit Ctrl+D to exit ')
sys.stdin.read()
node.shutdown()
Пример #7
0
#!/usr/bin/python
'''
Messaging node: "server" role.

Please note, that "server" or "client" role is not a
property of the node, it is just a way you use it.
'''
import sys
from pyroute2.rpc import Node
from pyroute2.rpc import public


class Namespace(object):
    '''
    Just a namespace to publish procedures
    '''
    @public
    def echo(self, msg):
        return '%s passed' % (msg)


node = Node()
node.register(Namespace())
node.serve('tcp://localhost:9824')
print(' hit Ctrl+D to exit ')
sys.stdin.read()
node.shutdown()
Пример #8
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()
Пример #9
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()
Пример #10
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'))
Пример #11
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()
Пример #12
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'))