Exemplo n.º 1
0
def test_read_long_data():
    val = 'z' * 97 * 1024

    unix_sock = "/tmp/thriftpy_test.sock"

    def serve():
        server_sock = TServerSocket(unix_socket=unix_sock)
        server_sock.listen()
        client = server_sock.accept()
        t = TCyBufferedTransport(client)
        proto.write_val(t, TType.STRING, val)
        t.flush()

        # wait for client to read
        time.sleep(1)

    p = multiprocessing.Process(target=serve)
    p.start()
    time.sleep(0.1)

    try:
        sock = TSocket(unix_socket=unix_sock)
        b = TCyBufferedTransport(sock)
        b.open()
        assert val == proto.read_val(b, TType.STRING)
        sock.close()
    finally:
        p.terminate()
        try:
            os.remove(unix_sock)
        except IOError:
            pass
Exemplo n.º 2
0
def test_read_long_data():
    val = 'z' * 97 * 1024

    def serve():
        server_sock = TServerSocket(
            unix_socket="./thriftpy_test.sock")
        server_sock.listen()
        client = server_sock.accept()
        t = TCyBufferedTransport(client)
        proto.write_val(t, TType.STRING, val)
        t.flush()

    p = multiprocessing.Process(target=serve)
    p.start()
    time.sleep(0.1)

    try:
        sock = TSocket(unix_socket="./thriftpy_test.sock")
        b = TCyBufferedTransport(sock)
        b.open()
        assert val == proto.read_val(b, TType.STRING)
        sock.close()
    finally:
        p.terminate()
        try:
            os.remove("./thriftpy_test.sock")
        except IOError:
            pass
Exemplo n.º 3
0
 def serve():
     server_sock = TServerSocket(unix_socket="./thriftpy_test.sock")
     server_sock.listen()
     client = server_sock.accept()
     t = TCyBufferedTransport(client)
     proto.write_val(t, TType.STRING, val)
     t.flush()
Exemplo n.º 4
0
 def serve():
     server_sock = TServerSocket(
         unix_socket="./thriftpy_test.sock")
     server_sock.listen()
     client = server_sock.accept()
     t = TCyBufferedTransport(client)
     proto.write_val(t, TType.STRING, val)
     t.flush()
Exemplo n.º 5
0
    def serve():
        server_sock = TServerSocket(unix_socket=unix_sock)
        server_sock.listen()
        client = server_sock.accept()
        t = TCyBufferedTransport(client)
        proto.write_val(t, TType.STRING, val)
        t.flush()

        # wait for client to read
        time.sleep(1)
Exemplo n.º 6
0
    def serve():
        server_sock = TServerSocket(unix_socket=unix_sock)
        server_sock.listen()
        client = server_sock.accept()
        t = TCyBufferedTransport(client)
        proto.write_val(t, TType.STRING, val)
        t.flush()

        # wait for client to read
        time.sleep(1)
Exemplo n.º 7
0
def test_transport_mismatch():
    s = TMemoryBuffer()

    t1 = TCyBufferedTransport(s)
    t1.write(b"\x80\x01\x00\x01\x00\x00\x00\x04ping hello world")
    t1.flush()

    with pytest.raises(TTransportException) as exc:
        t2 = TCyFramedTransport(s)
        t2.read(4)

    assert "No frame" in str(exc.value)
Exemplo n.º 8
0
def test_transport_handle():
    from thriftpy._compat import CYTHON
    if not CYTHON:
        return

    from thriftpy.transport import TSocket
    from thriftpy.transport.memory import TCyMemoryBuffer

    s = TSocket()
    s.set_handle('the sock')

    assert TCyBufferedTransport(s).sock == 'the sock'
    assert TCyFramedTransport(s).sock == 'the sock'
    assert TCyMemoryBuffer().sock is None
    assert TCyBufferedTransport(TCyFramedTransport(s)).sock == 'the sock'
    assert TCyBufferedTransport(TCyMemoryBuffer()).sock is None
Exemplo n.º 9
0
def test_buffered_read():
    s = TMemoryBuffer()

    t = TCyBufferedTransport(s)
    t.write(b"ping")
    t.flush()

    assert t.read(4) == b"ping"
Exemplo n.º 10
0
def test_buffered_read():
    s = TMemoryBuffer()

    t = TCyBufferedTransport(s)
    t.write(b"ping")
    t.flush()

    assert t.read(4) == b"ping"
Exemplo n.º 11
0
def test_transport_mismatch():
    s = TMemoryBuffer()

    t1 = TCyBufferedTransport(s)
    t1.write(b"\x80\x01\x00\x01\x00\x00\x00\x04ping hello world")
    t1.flush()

    with pytest.raises(TTransportException) as exc:
        t2 = TCyFramedTransport(s)
        t2.read(4)

    assert "No frame" in str(exc.value)