예제 #1
0
class ZmqFactoryTestCase(unittest.TestCase):
    """
    Test case for L{zmq.twisted.factory.Factory}.
    """
    def setUp(self):
        self.factory = ZmqFactory()

    def test_shutdown(self):
        self.factory.shutdown()
예제 #2
0
파일: test_factory.py 프로젝트: claws/tx0mq
class ZmqFactoryTestCase(unittest.TestCase):
    """
    Test case for L{zmq.twisted.factory.Factory}.
    """

    def setUp(self):
        self.factory = ZmqFactory()

    def test_shutdown(self):
        self.factory.shutdown()
예제 #3
0
    def setUp(self):
        self.factory = ZmqFactory()
        ZmqXREQConnection.identity = 'client'
        self.r = ZmqTestXREPConnection(
            self.factory, ZmqEndpoint(ZmqEndpointType.bind, "ipc://#3"))
        self.s = ZmqXREQConnection(
            self.factory, ZmqEndpoint(ZmqEndpointType.connect, "ipc://#3"))
        self.count = 0

        def get_next_id():
            self.count += 1
            return 'msg_id_%d' % (self.count, )

        self.s._getNextId = get_next_id
예제 #4
0
    def setUp(self):
        self.factory = ZmqFactory()
        ZmqXREQConnection.identity = 'client'
        self.r = ZmqTestXREPConnection(self.factory,
                ZmqEndpoint(ZmqEndpointType.bind, "ipc://#3"))
        self.s = ZmqXREQConnection(self.factory,
                ZmqEndpoint(ZmqEndpointType.connect, "ipc://#3"))
        self.count = 0

        def get_next_id():
            self.count += 1
            return 'msg_id_%d' % (self.count,)

        self.s._getNextId = get_next_id
예제 #5
0
 def setUp(self):
     self.factory = ZmqFactory()
예제 #6
0
class ZmqConnectionTestCase(unittest.TestCase):
    """
    Test case for L{zmq.twisted.connection.Connection}.
    """
    def setUp(self):
        self.factory = ZmqFactory()

    def tearDown(self):
        self.factory.shutdown()

    def test_interfaces(self):
        ziv.verifyClass(IReadDescriptor, ZmqConnection)
        ziv.verifyClass(IFileDescriptor, ZmqConnection)

    def test_init(self):
        ZmqTestReceiver(self.factory,
                        ZmqEndpoint(ZmqEndpointType.bind, "inproc://#1"))
        ZmqTestSender(self.factory,
                      ZmqEndpoint(ZmqEndpointType.connect, "inproc://#1"))

    def test_repr(self):
        expected = ("ZmqTestReceiver(ZmqFactory(), "
                    "(ZmqEndpoint(type='bind', address='inproc://#1'),))")
        result = ZmqTestReceiver(
            self.factory, ZmqEndpoint(ZmqEndpointType.bind, "inproc://#1"))
        self.failUnlessEqual(expected, repr(result))

    def test_send_recv(self):
        r = ZmqTestReceiver(self.factory,
                            ZmqEndpoint(ZmqEndpointType.bind, "inproc://#1"))
        s = ZmqTestSender(self.factory,
                          ZmqEndpoint(ZmqEndpointType.connect, "inproc://#1"))

        s.send('abcd')

        def check(ignore):
            result = getattr(r, 'messages', [])
            expected = [['abcd']]
            self.failUnlessEqual(result, expected,
                                 "Message should have been received")

        return _wait(0.01).addCallback(check)

    def test_send_recv_tcp(self):
        r = ZmqTestReceiver(
            self.factory,
            ZmqEndpoint(ZmqEndpointType.bind, "tcp://127.0.0.1:5555"))
        s = ZmqTestSender(
            self.factory,
            ZmqEndpoint(ZmqEndpointType.connect, "tcp://127.0.0.1:5555"))

        for i in xrange(100):
            s.send(str(i))

        def check(ignore):
            result = getattr(r, 'messages', [])
            expected = map(lambda i: [str(i)], xrange(100))
            self.failUnlessEqual(result, expected,
                                 "Messages should have been received")

        return _wait(0.01).addCallback(check)

    def test_send_recv_tcp_large(self):
        r = ZmqTestReceiver(
            self.factory,
            ZmqEndpoint(ZmqEndpointType.bind, "tcp://127.0.0.1:5555"))
        s = ZmqTestSender(
            self.factory,
            ZmqEndpoint(ZmqEndpointType.connect, "tcp://127.0.0.1:5555"))

        s.send(["0" * 10000, "1" * 10000])

        def check(ignore):
            result = getattr(r, 'messages', [])
            expected = [["0" * 10000, "1" * 10000]]
            self.failUnlessEqual(result, expected,
                                 "Messages should have been received")

        return _wait(0.01).addCallback(check)
예제 #7
0
 def setUp(self):
     self.factory = ZmqFactory()
예제 #8
0
class ZmqConnectionTestCase(unittest.TestCase):
    """
    Test case for L{zmq.twisted.connection.Connection}.
    """

    def setUp(self):
        self.factory = ZmqFactory()

    def tearDown(self):
        self.factory.shutdown()

    def test_interfaces(self):
        ziv.verifyClass(IReadDescriptor, ZmqConnection)
        ziv.verifyClass(IFileDescriptor, ZmqConnection)

    def test_init(self):
        ZmqTestReceiver(self.factory, ZmqEndpoint(ZmqEndpointType.bind, "inproc://#1"))
        ZmqTestSender(self.factory, ZmqEndpoint(ZmqEndpointType.connect, "inproc://#1"))

    def test_repr(self):
        expected = "ZmqTestReceiver(ZmqFactory(), " "(ZmqEndpoint(type='bind', address='inproc://#1'),))"
        result = ZmqTestReceiver(self.factory, ZmqEndpoint(ZmqEndpointType.bind, "inproc://#1"))
        self.failUnlessEqual(expected, repr(result))

    def test_send_recv(self):
        r = ZmqTestReceiver(self.factory, ZmqEndpoint(ZmqEndpointType.bind, "inproc://#1"))
        s = ZmqTestSender(self.factory, ZmqEndpoint(ZmqEndpointType.connect, "inproc://#1"))

        s.send("abcd")

        def check(ignore):
            result = getattr(r, "messages", [])
            expected = [["abcd"]]
            self.failUnlessEqual(result, expected, "Message should have been received")

        return _wait(0.01).addCallback(check)

    def test_send_recv_tcp(self):
        r = ZmqTestReceiver(self.factory, ZmqEndpoint(ZmqEndpointType.bind, "tcp://127.0.0.1:5555"))
        s = ZmqTestSender(self.factory, ZmqEndpoint(ZmqEndpointType.connect, "tcp://127.0.0.1:5555"))

        for i in xrange(100):
            s.send(str(i))

        def check(ignore):
            result = getattr(r, "messages", [])
            expected = map(lambda i: [str(i)], xrange(100))
            self.failUnlessEqual(result, expected, "Messages should have been received")

        return _wait(0.01).addCallback(check)

    def test_send_recv_tcp_large(self):
        r = ZmqTestReceiver(self.factory, ZmqEndpoint(ZmqEndpointType.bind, "tcp://127.0.0.1:5555"))
        s = ZmqTestSender(self.factory, ZmqEndpoint(ZmqEndpointType.connect, "tcp://127.0.0.1:5555"))

        s.send(["0" * 10000, "1" * 10000])

        def check(ignore):
            result = getattr(r, "messages", [])
            expected = [["0" * 10000, "1" * 10000]]
            self.failUnlessEqual(result, expected, "Messages should have been received")

        return _wait(0.01).addCallback(check)
예제 #9
0
class ZmqConnectionTestCase(unittest.TestCase):
    """
    Test case for L{zmq.twisted.connection.Connection}.
    """

    def setUp(self):
        self.factory = ZmqFactory()
        ZmqXREQConnection.identity = 'client'
        self.r = ZmqTestXREPConnection(self.factory,
                ZmqEndpoint(ZmqEndpointType.bind, "ipc://#3"))
        self.s = ZmqXREQConnection(self.factory,
                ZmqEndpoint(ZmqEndpointType.connect, "ipc://#3"))
        self.count = 0

        def get_next_id():
            self.count += 1
            return 'msg_id_%d' % (self.count,)

        self.s._getNextId = get_next_id

    def tearDown(self):
        ZmqXREQConnection.identity = None
        self.factory.shutdown()

    def test_send_recv(self):
        self.s.sendMsg('aaa', 'aab')
        self.s.sendMsg('bbb')

        def check(ignore):
            result = getattr(self.r, 'messages', [])
            expected = [['msg_id_1', ('aaa', 'aab')], ['msg_id_2', ('bbb',)]]
            self.failUnlessEqual(
                result, expected, "Message should have been received")

        return _wait(0.01).addCallback(check)

    def test_send_recv_reply(self):
        d = self.s.sendMsg('aaa')

        def check_response(response):
            self.assertEqual(response, ['aaa'])

        d.addCallback(check_response)
        return d

    def test_lot_send_recv_reply(self):
        deferreds = []
        for i in range(10):
            msg_id = "msg_id_%d" % (i,)
            d = self.s.sendMsg('aaa')

            def check_response(response, msg_id):
                self.assertEqual(response, ['aaa'])

            d.addCallback(check_response, msg_id)
            deferreds.append(d)
        return defer.DeferredList(deferreds)

    def xtest_cleanup_requests(self):
        """The request dict is cleanedup properly."""
        def check(ignore):
            self.assertEqual(self.s._requests, {})

        return self.s.sendMsg('aaa').addCallback(check)
예제 #10
0
파일: test_pubsub.py 프로젝트: d4g33z/tx0mq
 def setUp(self):
     self.factory = ZmqFactory()
     ZmqPubConnection.allowLoopbackMulticast = True
예제 #11
0
파일: test_pubsub.py 프로젝트: d4g33z/tx0mq
class ZmqConnectionTestCase(unittest.TestCase):
    """
    Test case for L{zmq.twisted.connection.Connection}.
    """

    def setUp(self):
        self.factory = ZmqFactory()
        ZmqPubConnection.allowLoopbackMulticast = True

    def tearDown(self):
        del ZmqPubConnection.allowLoopbackMulticast
        self.factory.shutdown()

    def test_send_recv(self):
        r = ZmqTestSubConnection(
            self.factory, ZmqEndpoint(ZmqEndpointType.bind, "ipc://test-sock"))
        s = ZmqPubConnection(
            self.factory, ZmqEndpoint(ZmqEndpointType.connect,
            "ipc://test-sock"))

        r.subscribe('tag')
        s.publish('xyz', 'different-tag')
        s.publish('abcd', 'tag1')
        s.publish('efgh', 'tag2')

        def check(ignore):
            result = getattr(r, 'messages', [])
            expected = [['tag1', 'abcd'], ['tag2', 'efgh']]
            self.failUnlessEqual(
                result, expected, "Message should have been received")

        return _wait(0.01).addCallback(check)

    def test_send_recv_pgm(self):
        r = ZmqTestSubConnection(self.factory, ZmqEndpoint(
            ZmqEndpointType.bind, "epgm://127.0.0.1;239.192.1.1:5556"))
        s = ZmqPubConnection(self.factory, ZmqEndpoint(
            ZmqEndpointType.connect, "epgm://127.0.0.1;239.192.1.1:5556"))

        r.subscribe('tag')
        s.publish('xyz', 'different-tag')
        s.publish('abcd', 'tag1')

        def check(ignore):
            result = getattr(r, 'messages', [])
            expected = [['tag1', 'abcd']]
            self.failUnlessEqual(
                result, expected, "Message should have been received")

        return _wait(0.2).addCallback(check)

    def test_send_recv_multiple_endpoints(self):
        r = ZmqTestSubConnection(
            self.factory,
            ZmqEndpoint(ZmqEndpointType.bind, "tcp://127.0.0.1:5556"),
            ZmqEndpoint(ZmqEndpointType.bind, "inproc://endpoint"))
        s1 = ZmqPubConnection(
            self.factory,
            ZmqEndpoint(ZmqEndpointType.connect, "tcp://127.0.0.1:5556"))
        s2 = ZmqPubConnection(
            self.factory,
            ZmqEndpoint(ZmqEndpointType.connect, "inproc://endpoint"))

        r.subscribe('')
        s1.publish('111', 'tag1')
        s2.publish('222', 'tag2')

        def check(ignore):
            result = getattr(r, 'messages', [])
            expected = [['tag2', '222'], ['tag1', '111']]
            self.failUnlessEqual(
                result, expected, "Message should have been received")

        return _wait(0.2).addCallback(check)
예제 #12
0
 def setUp(self):
     self.factory = ZmqFactory()
     ZmqPubConnection.allowLoopbackMulticast = True
예제 #13
0
class ZmqConnectionTestCase(unittest.TestCase):
    """
    Test case for L{zmq.twisted.connection.Connection}.
    """
    def setUp(self):
        self.factory = ZmqFactory()
        ZmqPubConnection.allowLoopbackMulticast = True

    def tearDown(self):
        del ZmqPubConnection.allowLoopbackMulticast
        self.factory.shutdown()

    def test_send_recv(self):
        r = ZmqTestSubConnection(
            self.factory, ZmqEndpoint(ZmqEndpointType.bind, "ipc://test-sock"))
        s = ZmqPubConnection(
            self.factory,
            ZmqEndpoint(ZmqEndpointType.connect, "ipc://test-sock"))

        r.subscribe('tag')
        s.publish('xyz', 'different-tag')
        s.publish('abcd', 'tag1')
        s.publish('efgh', 'tag2')

        def check(ignore):
            result = getattr(r, 'messages', [])
            expected = [['tag1', 'abcd'], ['tag2', 'efgh']]
            self.failUnlessEqual(result, expected,
                                 "Message should have been received")

        return _wait(0.01).addCallback(check)

    def test_send_recv_pgm(self):
        r = ZmqTestSubConnection(
            self.factory,
            ZmqEndpoint(ZmqEndpointType.bind,
                        "epgm://127.0.0.1;239.192.1.1:5556"))
        s = ZmqPubConnection(
            self.factory,
            ZmqEndpoint(ZmqEndpointType.connect,
                        "epgm://127.0.0.1;239.192.1.1:5556"))

        r.subscribe('tag')
        s.publish('xyz', 'different-tag')
        s.publish('abcd', 'tag1')

        def check(ignore):
            result = getattr(r, 'messages', [])
            expected = [['tag1', 'abcd']]
            self.failUnlessEqual(result, expected,
                                 "Message should have been received")

        return _wait(0.2).addCallback(check)

    def test_send_recv_multiple_endpoints(self):
        r = ZmqTestSubConnection(
            self.factory,
            ZmqEndpoint(ZmqEndpointType.bind, "tcp://127.0.0.1:5556"),
            ZmqEndpoint(ZmqEndpointType.bind, "inproc://endpoint"))
        s1 = ZmqPubConnection(
            self.factory,
            ZmqEndpoint(ZmqEndpointType.connect, "tcp://127.0.0.1:5556"))
        s2 = ZmqPubConnection(
            self.factory,
            ZmqEndpoint(ZmqEndpointType.connect, "inproc://endpoint"))

        r.subscribe('')
        s1.publish('111', 'tag1')
        s2.publish('222', 'tag2')

        def check(ignore):
            result = getattr(r, 'messages', [])
            expected = [['tag2', '222'], ['tag1', '111']]
            self.failUnlessEqual(result, expected,
                                 "Message should have been received")

        return _wait(0.2).addCallback(check)
예제 #14
0
class ZmqConnectionTestCase(unittest.TestCase):
    """
    Test case for L{zmq.twisted.connection.Connection}.
    """
    def setUp(self):
        self.factory = ZmqFactory()
        ZmqXREQConnection.identity = 'client'
        self.r = ZmqTestXREPConnection(
            self.factory, ZmqEndpoint(ZmqEndpointType.bind, "ipc://#3"))
        self.s = ZmqXREQConnection(
            self.factory, ZmqEndpoint(ZmqEndpointType.connect, "ipc://#3"))
        self.count = 0

        def get_next_id():
            self.count += 1
            return 'msg_id_%d' % (self.count, )

        self.s._getNextId = get_next_id

    def tearDown(self):
        ZmqXREQConnection.identity = None
        self.factory.shutdown()

    def test_send_recv(self):
        self.s.sendMsg('aaa', 'aab')
        self.s.sendMsg('bbb')

        def check(ignore):
            result = getattr(self.r, 'messages', [])
            expected = [['msg_id_1', ('aaa', 'aab')], ['msg_id_2', ('bbb', )]]
            self.failUnlessEqual(result, expected,
                                 "Message should have been received")

        return _wait(0.01).addCallback(check)

    def test_send_recv_reply(self):
        d = self.s.sendMsg('aaa')

        def check_response(response):
            self.assertEqual(response, ['aaa'])

        d.addCallback(check_response)
        return d

    def test_lot_send_recv_reply(self):
        deferreds = []
        for i in range(10):
            msg_id = "msg_id_%d" % (i, )
            d = self.s.sendMsg('aaa')

            def check_response(response, msg_id):
                self.assertEqual(response, ['aaa'])

            d.addCallback(check_response, msg_id)
            deferreds.append(d)
        return defer.DeferredList(deferreds)

    def xtest_cleanup_requests(self):
        """The request dict is cleanedup properly."""
        def check(ignore):
            self.assertEqual(self.s._requests, {})

        return self.s.sendMsg('aaa').addCallback(check)