aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Stanley Cheung <stanleycheung@google.com>2016-05-18 14:37:20 -0700
committerGravatar Stanley Cheung <stanleycheung@google.com>2016-06-17 11:52:51 -0700
commite2e08735e5226195ed3706bc10a9d297dd88bdf0 (patch)
tree8d9053a4dfa2d8d9027b64734621c6aa82a2163c
parentfd79790c009204c9367487513f8922e59eba8ee1 (diff)
php: implement custom_metadata interop test
-rwxr-xr-xsrc/php/tests/interop/interop_client.php61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/php/tests/interop/interop_client.php b/src/php/tests/interop/interop_client.php
index c5bb7c490e..e3c234e869 100755
--- a/src/php/tests/interop/interop_client.php
+++ b/src/php/tests/interop/interop_client.php
@@ -388,6 +388,64 @@ function timeoutOnSleepingServer($stub)
'Call status was not DEADLINE_EXCEEDED');
}
+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("\0", $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 _makeStub($args)
{
if (!array_key_exists('server_host', $args)) {
@@ -514,6 +572,9 @@ function interop_main($args, $stub = false)
case 'timeout_on_sleeping_server':
timeoutOnSleepingServer($stub);
break;
+ case 'custom_metadata':
+ customMetadata($stub);
+ break;
case 'service_account_creds':
serviceAccountCreds($stub, $args);
break;