function customMetadata($stub) { $ECHO_INITIAL_KEY = 'x-grpc-test-echo-initial'; $ECHO_INITIAL_VALUE = 'test_initial_metadata_value'; $ECHO_TRAILING_KEY = 'x-grpc-test-echo-trailing-bin'; $ECHO_TRAILING_VALUE = 'ababab'; $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); $metadata = [$ECHO_INITIAL_KEY => [$ECHO_INITIAL_VALUE], $ECHO_TRAILING_KEY => [$ECHO_TRAILING_VALUE]]; $call = $stub->UnaryCall($request, $metadata); $initial_metadata = $call->getMetadata(); hardAssert(array_key_exists($ECHO_INITIAL_KEY, $initial_metadata), 'Initial metadata does not contain expected key'); hardAssert($initial_metadata[$ECHO_INITIAL_KEY][0] == $ECHO_INITIAL_VALUE, 'Incorrect initial metadata value'); list($result, $status) = $call->wait(); hardAssert($status->code === Grpc\STATUS_OK, 'Call did not complete successfully'); $trailing_metadata = $call->getTrailingMetadata(); hardAssert(array_key_exists($ECHO_TRAILING_KEY, $trailing_metadata), 'Trailing metadata does not contain expected key'); hardAssert($trailing_metadata[$ECHO_TRAILING_KEY][0] == $ECHO_TRAILING_VALUE, 'Incorrect trailing metadata value'); $streaming_call = $stub->FullDuplexCall($metadata); $streaming_request = new grpc\testing\StreamingOutputCallRequest(); $streaming_request->setPayload($payload); $streaming_call->write($streaming_request); $streaming_call->writesDone(); hardAssert($streaming_call->getStatus()->code === Grpc\STATUS_OK, 'Call did not complete successfully'); $streaming_trailing_metadata = $streaming_call->getTrailingMetadata(); hardAssert(array_key_exists($ECHO_TRAILING_KEY, $streaming_trailing_metadata), 'Trailing metadata does not contain expected key'); hardAssert($streaming_trailing_metadata[$ECHO_TRAILING_KEY][0] == $ECHO_TRAILING_VALUE, 'Incorrect trailing metadata value'); }
function timeoutOnSleepingServer($stub) { $call = $stub->FullDuplexCall([], ['timeout' => 1000]); $request = new grpc\testing\StreamingOutputCallRequest(); $request->setResponseType(grpc\testing\PayloadType::COMPRESSABLE); $response_parameters = new grpc\testing\ResponseParameters(); $response_parameters->setSize(8); $request->addResponseParameters($response_parameters); $payload = new grpc\testing\Payload(); $payload->setBody(str_repeat("", 9)); $request->setPayload($payload); $call->write($request); $response = $call->read(); hardAssert($call->getStatus()->code === Grpc\STATUS_DEADLINE_EXCEEDED, 'Call status was not DEADLINE_EXCEEDED'); }
function cancelAfterFirstResponse($stub) { $call = $stub->FullDuplexCall(); $request = new grpc\testing\StreamingOutputCallRequest(); $request->setResponseType(grpc\testing\PayloadType::COMPRESSABLE); $response_parameters = new grpc\testing\ResponseParameters(); $response_parameters->setSize(31415); $request->addResponseParameters($response_parameters); $payload = new grpc\testing\Payload(); $payload->setBody(str_repeat("", 27182)); $request->setPayload($payload); $call->write($request); $response = $call->read(); $call->cancel(); hardAssert($call->getStatus()->code === Grpc\STATUS_CANCELLED, 'Call status was not CANCELLED'); }