Пример #1
0
    def test_zmqserver_exc(self):
        import gevent
        from synapse.node import NodeException
        from synapse.zmq_node import ZMQServer, ZMQClient
        conf_srv = {'uri': 'tcp://*:5557', 'name': 'zmqsrv'}

        conf_cli = {'uri': 'tcp://localhost:5557', 'name': 'zmqcli'}

        def srv_handler(msg):
            raise NodeException("buggy", "exc_result")

        server = ZMQServer(conf_srv, srv_handler)
        self.assertTrue(server.socket is None)
        server.start()
        self.assertTrue(server.socket is not None)
        self.assertRaises(NotImplementedError, server.send, "unimplemented")

        serverlet = gevent.spawn(server.loop)

        client = ZMQClient(conf_cli)
        self.assertTrue(client.socket is None)
        client.connect()
        self.assertTrue(client.socket is not None)
        client.send("sync_message")
        response = client.recv()
        self.assertEquals(response, "exc_result")
        gevent.kill(serverlet)
        client.close()
        server.stop()
Пример #2
0
    def test_zmqserver_sync(self):
        import gevent
        from synapse.zmq_node import ZMQServer, ZMQClient
        conf_srv = {'uri': 'tcp://*:5555',
                    'name': 'zmq_srv_sync'}

        conf_cli = {'uri': 'tcp://localhost:5555',
                    'name': 'zmq_cli_sync'}

        def srv_handler(msg):
            return "sync_response"

        server = ZMQServer(conf_srv, srv_handler)
        self.assertTrue(server.socket is None)
        server.start()
        self.assertTrue(server.socket is not None)
        self.assertRaises(NotImplementedError, server.send,
                          "unimplemented")

        serverlet = gevent.spawn(server.loop)

        client = ZMQClient(conf_cli)
        self.assertTrue(client.socket is None)
        client.connect()
        self.assertTrue(client.socket is not None)
        client.send("message")

        response = client.recv()
        self.assertEquals(response, "sync_response")
        gevent.kill(serverlet)
        client.close()
        server.stop()
Пример #3
0
                    'name': 'zmq_cli_async'}

        @async
        def srv_handler(msg):
            return "async_response"

        server = ZMQServer(conf_srv, srv_handler)
        self.assertTrue(server.socket is None)
        server.start()
        self.assertTrue(server.socket is not None)
        self.assertRaises(NotImplementedError, server.send,
                          "unimplemented")

        serverlet = gevent.spawn(server.loop)

        client = ZMQClient(conf_cli)
        self.assertTrue(client.socket is None)
        client.connect()
        self.assertTrue(client.socket is not None)
        client.send("message")
        response = client.recv()
        self.assertEquals(response, "async_response")
        gevent.sleep(1)
        gevent.kill(serverlet)
        client.close()
        server.stop()

    def test_zmqserver_exc(self):
        import gevent
        from synapse.node import NodeException
        from synapse.zmq_node import ZMQServer, ZMQClient
Пример #4
0
        conf_cli = {'uri': 'tcp://localhost:5556', 'name': 'zmq_cli_async'}

        @async
        def srv_handler(msg):
            return "async_response"

        server = ZMQServer(conf_srv, srv_handler)
        self.assertTrue(server.socket is None)
        server.start()
        self.assertTrue(server.socket is not None)
        self.assertRaises(NotImplementedError, server.send, "unimplemented")

        serverlet = gevent.spawn(server.loop)

        client = ZMQClient(conf_cli)
        self.assertTrue(client.socket is None)
        client.connect()
        self.assertTrue(client.socket is not None)
        client.send("message")
        response = client.recv()
        self.assertEquals(response, "async_response")
        gevent.sleep(1)
        gevent.kill(serverlet)
        client.close()
        server.stop()

    def test_zmqserver_exc(self):
        import gevent
        from synapse.node import NodeException
        from synapse.zmq_node import ZMQServer, ZMQClient