예제 #1
0
class TestIOBroker(object):

    def setup(self):
        self.ioc1 = IOCore(secret='bala')
        self.ioc1.serve('tcp://localhost:9824')
        self.ioc2 = IOCore()
        self.host = self.ioc2.connect('tcp://localhost:9824')
        self.ioc2.register('bala', self.host[1])

    def teardown(self):
        self.ioc2.release()
        self.ioc1.release()

    def test_err_connect(self):
        try:
            self.ioc1.connect('tcp://localhost:404')
        except RuntimeError:
            pass

    def test_err_discover(self):
        try:
            self.ioc1.discover('non_existent')
        except RuntimeError:
            pass

    def _test_stop(self):
        #
        # FIXME
        #
        # this test stopped to work properly after the
        # broker became a separate process
        self.ioc2.command(IPRCMD_STOP, addr=self.host[1])

    def test_reload(self):
        self.ioc2.command(IPRCMD_RELOAD, addr=self.host[1])

    def test_provide_remove(self):
        self.ioc2.provide('/dala')
        self.ioc2.remove('/dala')

    def test_fail_access(self):
        self.ioc2.unregister(self.host[1])
        try:
            self.ioc2.command(IPRCMD_STOP, addr=self.host[1])
        except RuntimeError:
            pass
        self.ioc2.register('bala', self.host[1])

    def test_fail_disconnect(self):
        try:
            self.ioc2.disconnect('invalid_uid')
        except RuntimeError:
            pass

    def test_fail_connect(self):
        try:
            self.ioc2.connect('unix://\0invalid_socket')
        except RuntimeError:
            pass

    def test_fail_subscribe(self):
        try:
            self.ioc2.command(IPRCMD_SUBSCRIBE)
        except RuntimeError:
            pass
예제 #2
0
'''
Push/pull using raw IOCore

tcp -- control connection
udp -- data push
'''
from pyroute2 import IOCore
from pyroute2.iocore import NLT_DGRAM


ioc1 = IOCore()
ioc1.serve('tcp://0.0.0.0:9824')
ioc1.serve('udp://0.0.0.0:9824')
ioc1.provide('push')

ioc2 = IOCore()
(uid, addr) = ioc2.connect('tcp://localhost:9824')
ioc2.connect('udp://localhost:9824')
port = ioc2.discover('push', addr)
ioc2.push((addr, port), 'hello, world!', NLT_DGRAM)

print('waiting message from client')
ioc1.monitor()
msg = ioc1.get()[0]

print(msg)
ioc2.release()
ioc1.release()