protected function expectRpc($request, $response, $call_options = [])
 {
     $stream_call_data = [];
     $options = array_merge(self::$rpc_default_options, $call_options);
     // Open call will supply the address and the RPC request.
     $address = sprintf('http://%s:%s%s', $options['host'], $options['port'], $options['proxy_path']);
     $remote_request = new Request();
     $remote_request->setServiceName($options['package_name']);
     $remote_request->setMethod($options['call_name']);
     $remote_request->setRequestId($options['ticket']);
     $remote_request->setRequest($request->serializeToString());
     $options['context']['http']['content'] = $remote_request->serializeToString();
     $options['context']['http']["timeout"] = $options['timeout'] + VmApiProxy::DEADLINE_DELTA_SECONDS;
     $options['http_headers'][VmApiProxy::SERVICE_DEADLINE_HEADER] = $options['timeout'];
     // Form the header string - sort by key as we do a string compare to check
     // for a match.
     ksort($options['http_headers']);
     $header_str = "";
     foreach ($options['http_headers'] as $k => $v) {
         $header_str .= sprintf("%s: %s\r\n", $k, $v);
     }
     $options['context']['http']['header'] = $header_str;
     $stream_call_data['stream_open'] = ['address' => $address, 'mode' => 'rb', 'context' => $options['context']];
     if (isset($options['http_open_failure'])) {
         $stream_call_data['stream_open']['http_open_failure'] = true;
     }
     $remote_response = new Response();
     if (isset($options['rpc_exception'])) {
         $error = $remote_response->mutableRpcError();
         $error->setCode($options['rpc_exception']);
     } else {
         if (isset($options['application_error'])) {
             $error = $remote_response->mutableApplicationError();
             $error->setCode($options['application_error']['code']);
             $error->setDetail($options['application_error']['detail']);
         } else {
             if (isset($options['generic_exception'])) {
                 $remote_response->setException(true);
             } else {
                 $remote_response->setResponse($response->serializeToString());
             }
         }
     }
     $serialized_remote_response = $remote_response->serializeToString();
     $stream_call_data['stream_stat'] = ['size' => strlen($serialized_remote_response)];
     $stream_call_data['stream_read'] = ['bytes' => $serialized_remote_response];
     $GLOBALS['mock_http'][] = $stream_call_data;
 }