Exemple #1
0
/**
 * Run the large_unary test.
 * Passes when run against the C++ server as of 2014-12-04
 * Not tested against any other server as of 2014-12-04
 * @param $stub Stub object that has service methods
 */
function largeUnary($stub)
{
    $request_len = 271828;
    $response_len = 314159;
    $request = new grpc\testing\SimpleRequest();
    $request->setResponseType(grpc\testing\PayloadType::COMPRESSABLE);
    $request->setResponseSize($response_len);
    $payload = new grpc\testing\Payload();
    $payload->setType(grpc\testing\PayloadType::COMPRESSABLE);
    $payload->setBody(str_repeat("", $request_len));
    $request->setPayload($payload);
    list($result, $status) = $stub->UnaryCall($request)->wait();
    hardAssert($status->code === Grpc\STATUS_OK, 'Call did not complete successfully');
    hardAssert($result !== null, 'Call returned a null response');
    $payload = $result->getPayload();
    hardAssert($payload->getType() === grpc\testing\PayloadType::COMPRESSABLE, 'Payload had the wrong type');
    hardAssert(strlen($payload->getBody()) === $response_len, 'Payload had the wrong length');
    hardAssert($payload->getBody() === str_repeat("", $response_len), 'Payload had the wrong content');
}
Exemple #2
0
/**
 * Shared code between large unary test and auth test.
 *
 * @param $stub Stub object that has service methods
 * @param $fillUsername boolean whether to fill result with username
 * @param $fillOauthScope boolean whether to fill result with oauth scope
 */
function performLargeUnary($stub, $fillUsername = false, $fillOauthScope = false, $callback = false)
{
    $request_len = 271828;
    $response_len = 314159;
    $request = new grpc\testing\SimpleRequest();
    $request->setResponseType(grpc\testing\PayloadType::COMPRESSABLE);
    $request->setResponseSize($response_len);
    $payload = new grpc\testing\Payload();
    $payload->setType(grpc\testing\PayloadType::COMPRESSABLE);
    $payload->setBody(str_repeat("", $request_len));
    $request->setPayload($payload);
    $request->setFillUsername($fillUsername);
    $request->setFillOauthScope($fillOauthScope);
    $options = false;
    if ($callback) {
        $options['call_credentials_callback'] = $callback;
    }
    list($result, $status) = $stub->UnaryCall($request, [], $options)->wait();
    hardAssert($status->code === Grpc\STATUS_OK, 'Call did not complete successfully');
    hardAssert($result !== null, 'Call returned a null response');
    $payload = $result->getPayload();
    hardAssert($payload->getType() === grpc\testing\PayloadType::COMPRESSABLE, 'Payload had the wrong type');
    hardAssert(strlen($payload->getBody()) === $response_len, 'Payload had the wrong length');
    hardAssert($payload->getBody() === str_repeat("", $response_len), 'Payload had the wrong content');
    return $result;
}
Exemple #3
0
function statusCodeAndMessage($stub)
{
    $echo_status = new grpc\testing\EchoStatus();
    $echo_status->setCode(2);
    $echo_status->setMessage('test status message');
    $request = new grpc\testing\SimpleRequest();
    $request->setResponseStatus($echo_status);
    $call = $stub->UnaryCall($request);
    list($result, $status) = $call->wait();
    hardAssert($status->code === 2, 'Received unexpected status code');
    hardAssert($status->details === 'test status message', 'Received unexpected status details');
    $streaming_call = $stub->FullDuplexCall();
    $streaming_request = new grpc\testing\StreamingOutputCallRequest();
    $streaming_request->setResponseStatus($echo_status);
    $streaming_call->write($streaming_request);
    $streaming_call->writesDone();
    $status = $streaming_call->getStatus();
    hardAssert($status->code === 2, 'Received unexpected status code');
    hardAssert($status->details === 'test status message', 'Received unexpected status details');
}