Esempio n. 1
0
def _cancel_after_first_response(stub):
    request_response_sizes = (31415, 9, 2653, 58979)
    request_payload_sizes = (27182, 8, 1828, 45904)
    with stub, _Pipe() as pipe:
        response_iterator = stub.FullDuplexCall(pipe, _TIMEOUT)

        response_size = request_response_sizes[0]
        payload_size = request_payload_sizes[0]
        request = messages_pb2.StreamingOutputCallRequest(
            response_type=messages_pb2.COMPRESSABLE,
            response_parameters=(messages_pb2.ResponseParameters(
                size=response_size), ),
            payload=messages_pb2.Payload(body=b'\x00' * payload_size))
        pipe.add(request)
        response = next(response_iterator)
        # We test the contents of `response` in the Ping Pong test - don't check
        # them here.
        response_iterator.cancel()

        try:
            next(response_iterator)
        except Exception:
            pass
        else:
            raise ValueError('expected call to be cancelled')
Esempio n. 2
0
def _server_streaming(stub):
    sizes = (31415, 9, 2653, 58979)

    with stub:
        request = messages_pb2.StreamingOutputCallRequest(
            response_type=messages_pb2.COMPRESSABLE,
            response_parameters=(
                messages_pb2.ResponseParameters(size=sizes[0]),
                messages_pb2.ResponseParameters(size=sizes[1]),
                messages_pb2.ResponseParameters(size=sizes[2]),
                messages_pb2.ResponseParameters(size=sizes[3]),
            ))
        response_iterator = stub.StreamingOutputCall(request, _TIMEOUT)
        for index, response in enumerate(response_iterator):
            if response.payload.type != messages_pb2.COMPRESSABLE:
                raise ValueError('response body of invalid type %s!' %
                                 response.payload.type)
            if len(response.payload.body) != sizes[index]:
                raise ValueError('response body of invalid size %d!' %
                                 len(response.payload.body))
Esempio n. 3
0
def _ping_pong(stub):
    request_response_sizes = (31415, 9, 2653, 58979)
    request_payload_sizes = (27182, 8, 1828, 45904)

    with stub, _Pipe() as pipe:
        response_iterator = stub.FullDuplexCall(pipe, _TIMEOUT)
        print 'Starting ping-pong with response iterator %s' % response_iterator
        for response_size, payload_size in zip(request_response_sizes,
                                               request_payload_sizes):
            request = messages_pb2.StreamingOutputCallRequest(
                response_type=messages_pb2.COMPRESSABLE,
                response_parameters=(messages_pb2.ResponseParameters(
                    size=response_size), ),
                payload=messages_pb2.Payload(body=b'\x00' * payload_size))
            pipe.add(request)
            response = next(response_iterator)
            if response.payload.type != messages_pb2.COMPRESSABLE:
                raise ValueError('response body of invalid type %s!' %
                                 response.payload.type)
            if len(response.payload.body) != response_size:
                raise ValueError('response body of invalid size %d!' %
                                 len(response.payload.body))