Ejemplo n.º 1
0
    def _test_protocol_write(self, obj):
        # cython版本
        buff0 = TCyMemoryBuffer()
        op0 = TCyBinaryProtocol(buff0)
        op0.write_struct(obj)
        value0 = buff0.getvalue()

        # Python版本
        buff1 = TMemoryBuffer()
        op1 = TUtf8BinaryProtocol(buff1)
        obj.write(op1)
        value1 = buff1.get_raw_value()

        self.assertEqual(value1, value0, "write result not the same")
Ejemplo n.º 2
0
    def _test_protocol_write(self, obj):
        # cython版本
        buff0 = TCyMemoryBuffer()
        op0 = TCyBinaryProtocol(buff0)
        op0.write_struct(obj)
        value0 = buff0.getvalue()

        # Python版本
        buff1 = TMemoryBuffer()
        op1 = TUtf8BinaryProtocol(buff1)
        obj.write(op1)
        value1 = buff1.get_raw_value()

        self.assertEqual(value1, value0, "write result not the same")
Ejemplo n.º 3
0
    def test_read_write_exception(self):
        """
            测试可行性
            py.test test/test_protocol.py::SimpleTest::test_read_write_exception -s
        """
        ex = RpcException(1, "Hello")

        self._test_protocol_write(ex)

        total_time = 1
        t = time.time()
        for i in range(total_time):
            buff0 = TCyMemoryBuffer()
            op0 = TCyBinaryProtocol(buff0)
            op0.write_struct(ex)
            value0 = buff0.getvalue()
        t = time.time() - t
        print "T: %.3fms" % (t * 1000)
        print "Value0:", ["%03d" % ord(i) for i in value0]

        buff0 = TCyMemoryBuffer(value0)
        op0 = TCyBinaryProtocol(buff0)
        ex0 = op0.read_struct(RpcException())
        print "Code: ", ex0.code
        print "Msg: ", ex0.msg







        t = time.time()
        for i in range(total_time):
            buff1 = TMemoryBuffer()
            op1 = TBinaryProtocol(buff1)
            ex.write(op1)
            value1 = buff1.get_raw_value()
        t = time.time() - t
        print "T: %.3fms" % (t * 1000)
        print "Value1:", ["%03d" % ord(i) for i in value1]

        self.assertEqual(value1, value0, "write struct test failed")
Ejemplo n.º 4
0
    def test_read_write_exception(self):
        """
            测试可行性
            py.test test/test_protocol.py::SimpleTest::test_read_write_exception -s
        """
        ex = RpcException(1, "Hello")

        self._test_protocol_write(ex)

        total_time = 1
        t = time.time()
        for i in range(total_time):
            buff0 = TCyMemoryBuffer()
            op0 = TCyBinaryProtocol(buff0)
            op0.write_struct(ex)
            value0 = buff0.getvalue()
        t = time.time() - t
        print "T: %.3fms" % (t * 1000)
        print "Value0:", ["%03d" % ord(i) for i in value0]

        buff0 = TCyMemoryBuffer(value0)
        op0 = TCyBinaryProtocol(buff0)
        ex0 = op0.read_struct(RpcException())
        print "Code: ", ex0.code
        print "Msg: ", ex0.msg

        t = time.time()
        for i in range(total_time):
            buff1 = TMemoryBuffer()
            op1 = TBinaryProtocol(buff1)
            ex.write(op1)
            value1 = buff1.get_raw_value()
        t = time.time() - t
        print "T: %.3fms" % (t * 1000)
        print "Value1:", ["%03d" % ord(i) for i in value1]

        self.assertEqual(value1, value0, "write struct test failed")