class ZmqAsyncDealerRouterTestCase(unittest.TestCase): """ Test case for L{zmq.twisted.connection.Connection}. """ def setUp(self): self.factory = ZmqFactory() def tearDown(self): self.factory.shutdown() @inlineCallbacks def test_async_dealer_router(self): # Bind the ROUTER PONG server, wait for a second to make sure the # the socket is ready. bind_ep = ZmqEndpoint(ZmqEndpointType.Bind, "tcp://127.0.0.1:5000") server = ZmqTestServer(self.factory, bind_ep) yield _wait(1) # Connect the DEALER PING client, wait for a second to make sure the # socket is ready. connect_ep = ZmqEndpoint(ZmqEndpointType.Connect, "tcp://127.0.0.1:5000") client = ZmqTestClient(self.factory, connect_ep) yield _wait(1) # Launch 10 pingers, which will each ping 100 times and wait # for completion. results = yield DeferredList([ping(client) for x in range(0,10)]) # Server requests and responses should be 1:1 self.failUnlessEqual(server.requests, server.responses) # Client requests and responses should be 1:1 self.failUnlessEqual(client.requests, client.responses) # Servers and clients requests and responses should also match. self.failUnlessEqual(client.requests, server.responses) for row in results: if not row[0]: raise row[1] # Raise any errors encountered.
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()
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') return _wait(0.01).addCallback( lambda _: self.failUnlessEqual(getattr(self.r, 'messages', []), [['msg_id_1', ('aaa', 'aab')], ['msg_id_2', ('bbb',)]], "Message should have been received")) 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.""" return self.s.sendMsg('aaa').addCallback(lambda _: self.assertEqual(self.s._requests, {}))
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): self.failUnlessEqual("ZmqTestReceiver(ZmqFactory(), (ZmqEndpoint(type='bind', address='inproc://#1'),))", repr(ZmqTestReceiver(self.factory, ZmqEndpoint(ZmqEndpointType.Bind, "inproc://#1")))) 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') return _wait(0.01).addCallback( lambda _: self.failUnlessEqual(getattr(r, 'messages', []), [['abcd']], "Message should have been received")) 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)) return _wait(0.01).addCallback( lambda _: self.failUnlessEqual(getattr(r, 'messages', []), map(lambda i: [str(i)], xrange(100)), "Messages should have been received")) 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]) return _wait(0.01).addCallback( lambda _: self.failUnlessEqual(getattr(r, 'messages', []), [["0" * 10000, "1" * 10000]], "Messages should have been received"))
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') return _wait(0.01).addCallback( lambda _: self.failUnlessEqual(getattr(r, 'messages', []), [['tag1', 'abcd'], ['tag2', 'efgh']], "Message should have been received")) 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') return _wait(0.2).addCallback( lambda _: self.failUnlessEqual(getattr(r, 'messages', []), [['tag1', 'abcd']], "Message should have been received")) 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') return _wait(0.2).addCallback( lambda _: self.failUnlessEqual(getattr(r, 'messages', []), [['tag2', '222'], ['tag1', '111']], "Message should have been received"))
def setUp(self): self.factory = ZmqFactory() ZmqXREQConnection.identity = 'client' self.r = ZmqTestXREPConnection(self.factory, ZmqEndpoint(ZmqEndpointType.Bind, "ipc://test-sock")) self.s = ZmqXREQConnection(self.factory, ZmqEndpoint(ZmqEndpointType.Connect, "ipc://test-sock")) self.count = 0 def get_next_id(): self.count += 1 return 'msg_id_%d' % (self.count,) self.s.get_next_id = get_next_id
def setUp(self): self.factory = ZmqFactory()
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): self.failUnlessEqual( "ZmqTestReceiver(ZmqFactory(), (ZmqEndpoint(type='bind', address='inproc://#1'),))", repr( ZmqTestReceiver( self.factory, ZmqEndpoint(ZmqEndpointType.Bind, "inproc://#1")))) 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') return _wait(0.01).addCallback(lambda _: self.failUnlessEqual( getattr(r, 'messages', []), [['abcd']], "Message should have been received")) 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)) return _wait(0.01).addCallback(lambda _: self.failUnlessEqual( getattr(r, 'messages', []), map(lambda i: [str(i)], xrange(100)), "Messages should have been received")) 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]) return _wait(0.01).addCallback(lambda _: self.failUnlessEqual( getattr(r, 'messages', []), [["0" * 10000, "1" * 10000]], "Messages should have been received"))
def setUp(self): self.factory = ZmqFactory() ZmqPubConnection.allowLoopbackMulticast = True