Beispiel #1
0
def test_exception_status_code_is_set(server, ThriftTest, server_ttypes):

    # Given this test server:

    @server.thrift.register(ThriftTest)
    def testException(request):
        raise server_ttypes.Xception(
            errorCode=1001,
            message=request.body.arg
        )

    # Make a call:

    conn = yield TornadoConnection.outgoing(server.hostport)
    res = yield conn.send(
        CallRequestMessage(
            service=b'service',
            headers={b'cn': b'client', b'as': b'thrift'},
            args=[
                b'ThriftTest::testException',
                b'',
                bytearray([
                    0x0B,        # type = string
                    0x00, 0x01,  # field ID 1

                    0x00, 0x00, 0x00, 0x00,  # empty string

                    0x00,  # STOP
                ]),
            ],
        )
    )

    assert 1 == res.status_code
def test_unexpected_error_from_handler(mock_server):
    # test for invalid call request message
    tchannel = TChannel(name='test')
    connection = yield StreamConnection.outgoing(
        hostport=mock_server.hostport,
        tchannel=tchannel,
    )

    callrequest = CallRequestMessage(flags=FlagsType.fragment,
                                     args=[
                                         'endpoint1',
                                         '',
                                         '',
                                     ])
    # set a wrong checksum
    callrequest.checksum = (ChecksumType.crc32c, 1)
    with pytest.raises(ProtocolError):
        yield connection.send(callrequest)
def test_unexpected_error_from_handler(tchannel_server):
    # test for invalid call request message
    hostport = 'localhost:%d' % tchannel_server.port
    tchannel = TChannel(name='test')
    connection = yield StreamConnection.outgoing(
        hostport=hostport,
        tchannel=tchannel,
    )

    callrequest = CallRequestMessage(
        flags=FlagsType.fragment, args=[
            'endpoint1',
            '',
            '',
        ])
    # set a wrong checksum
    callrequest.checksum = (ChecksumType.crc32c, 1)
    with pytest.raises(ProtocolError):
        yield connection.send(callrequest)
def test_invalid_message_during_streaming(mock_server):
    # test for invalid call request message
    tchannel = TChannel(name='test')
    connection = yield StreamConnection.outgoing(
        hostport=mock_server.hostport,
        tchannel=tchannel,
    )

    callrequest = CallRequestMessage(
        flags=FlagsType.fragment,
        args=[
            'endpoint2',
            'a',
            'a',
        ],
        headers={'as': 'raw'},
        id=1,
    )

    callreqcontinue = CallRequestContinueMessage(
        flags=FlagsType.fragment,
        args=[
            'a',
        ],
        id=1,
    )

    resp_future = connection.send(callrequest)
    for _ in xrange(10):
        yield connection.write(callreqcontinue)

    # bypass the default checksum calculation
    # set a wrong checksum
    callreqcontinue.checksum = (ChecksumType.crc32c, 1)
    yield connection._write(callreqcontinue)

    with pytest.raises(ProtocolError) as e:
        resp = yield resp_future
        yield resp.get_header()
        yield resp.get_body()

    assert e.value.message == u"Checksum does not match!"