pull/2533/head
David Garcia Quintas 9 years ago
parent cead5e83e2
commit 80f3995e47
  1. 5
      include/grpc++/client_context.h
  2. 4
      include/grpc++/server_context.h
  3. 31
      test/cpp/interop/client_helper.cc
  4. 18
      test/cpp/interop/client_helper.h
  5. 44
      test/cpp/interop/interop_client.cc
  6. 25
      test/cpp/interop/server.cc
  7. 8
      test/cpp/interop/server_helper.cc
  8. 4
      test/cpp/interop/server_helper.h

@ -71,6 +71,10 @@ class ClientAsyncReaderWriter;
template <class R>
class ClientAsyncResponseReader;
namespace testing {
class InteropClientContextInspector;
} // namespace testing
class ClientContext {
public:
ClientContext();
@ -129,6 +133,7 @@ class ClientContext {
ClientContext(const ClientContext&);
ClientContext& operator=(const ClientContext&);
friend class ::grpc::testing::InteropClientContextInspector;
friend class CallOpClientRecvStatus;
friend class CallOpRecvInitialMetadata;
friend class Channel;

@ -78,7 +78,7 @@ class CompletionQueue;
class Server;
namespace testing {
class InteropContextInspector;
class InteropServerContextInspector;
} // namespace testing
// Interface of server side rpc context.
@ -117,7 +117,7 @@ class ServerContext {
std::shared_ptr<const AuthContext> auth_context() const;
private:
friend class ::grpc::testing::InteropContextInspector;
friend class ::grpc::testing::InteropServerContextInspector;
friend class ::grpc::Server;
template <class W, class R>
friend class ::grpc::ServerAsyncReader;

@ -48,10 +48,13 @@
#include <grpc++/create_channel.h>
#include <grpc++/credentials.h>
#include <grpc++/stream.h>
#include "src/cpp/client/secure_credentials.h"
#include "test/core/security/oauth2_utils.h"
#include "test/cpp/util/create_test_channel.h"
#include "src/core/surface/call.h"
#include "src/cpp/client/secure_credentials.h"
DECLARE_bool(enable_ssl);
DECLARE_bool(use_prod_roots);
DECLARE_int32(server_port);
@ -62,6 +65,8 @@ DECLARE_string(default_service_account);
DECLARE_string(service_account_key_file);
DECLARE_string(oauth_scope);
using grpc::testing::CompressionType;
namespace grpc {
namespace testing {
@ -137,5 +142,29 @@ std::shared_ptr<ChannelInterface> CreateChannelForTestCase(
}
}
CompressionType GetInteropCompressionTypeFromCompressionAlgorithm(
grpc_compression_algorithm algorithm) {
switch (algorithm) {
case GRPC_COMPRESS_NONE:
return CompressionType::NONE;
case GRPC_COMPRESS_GZIP:
return CompressionType::GZIP;
case GRPC_COMPRESS_DEFLATE:
return CompressionType::DEFLATE;
default:
GPR_ASSERT(false);
}
}
InteropClientContextInspector::InteropClientContextInspector(
const ::grpc::ClientContext& context)
: context_(context) {}
grpc_compression_algorithm
InteropClientContextInspector::GetCallCompressionAlgorithm() const {
return grpc_call_get_compression_algorithm(context_.call_);
}
} // namespace testing
} // namespace grpc

@ -39,6 +39,8 @@
#include <grpc++/config.h>
#include <grpc++/channel_interface.h>
#include "test/proto/messages.grpc.pb.h"
namespace grpc {
namespace testing {
@ -49,6 +51,22 @@ grpc::string GetOauth2AccessToken();
std::shared_ptr<ChannelInterface> CreateChannelForTestCase(
const grpc::string& test_case);
grpc::testing::CompressionType
GetInteropCompressionTypeFromCompressionAlgorithm(
grpc_compression_algorithm algorithm);
class InteropClientContextInspector {
public:
InteropClientContextInspector(const ::grpc::ClientContext& context);
// Inspector methods, able to peek inside ClientContext, follow.
grpc_compression_algorithm GetCallCompressionAlgorithm() const;
private:
const ::grpc::ClientContext& context_;
};
} // namespace testing
} // namespace grpc

@ -43,6 +43,8 @@
#include <grpc++/client_context.h>
#include <grpc++/status.h>
#include <grpc++/stream.h>
#include "test/cpp/interop/client_helper.h"
#include "test/proto/test.grpc.pb.h"
#include "test/proto/empty.grpc.pb.h"
#include "test/proto/messages.grpc.pb.h"
@ -93,24 +95,18 @@ void InteropClient::PerformLargeUnary(SimpleRequest* request,
std::unique_ptr<TestService::Stub> stub(TestService::NewStub(channel_));
ClientContext context;
// XXX: add UNCOMPRESSABLE to the mix
//
// XXX: 1) set request.response_compression to all the diff available
// compression values. We can't check the compression method used at the
// application level, but if something is wrong, two different implementations
// of gRPC (java vs c) won't be able to communicate.
//
// 2) for UNCOMPRESSABLE, verify that the response can be whatever, most
// likely uncompressed
request->set_response_type(PayloadType::COMPRESSABLE);
InteropClientContextInspector inspector(context);
request->set_response_size(kLargeResponseSize);
grpc::string payload(kLargeRequestSize, '\0');
request->mutable_payload()->set_body(payload.c_str(), kLargeRequestSize);
Status s = stub->UnaryCall(&context, *request, response);
GPR_ASSERT(request->response_compression() ==
GetInteropCompressionTypeFromCompressionAlgorithm(
inspector.GetCallCompressionAlgorithm()));
AssertOkOrPrintErrorStatus(s);
GPR_ASSERT(response->payload().type() == PayloadType::COMPRESSABLE);
GPR_ASSERT(response->payload().type() == request->response_type());
GPR_ASSERT(response->payload().body() ==
grpc::string(kLargeResponseSize, '\0'));
}
@ -124,6 +120,7 @@ void InteropClient::DoComputeEngineCreds(
SimpleResponse response;
request.set_fill_username(true);
request.set_fill_oauth_scope(true);
request.set_response_type(PayloadType::COMPRESSABLE);
PerformLargeUnary(&request, &response);
gpr_log(GPR_INFO, "Got username %s", response.username().c_str());
gpr_log(GPR_INFO, "Got oauth_scope %s", response.oauth_scope().c_str());
@ -143,6 +140,7 @@ void InteropClient::DoServiceAccountCreds(const grpc::string& username,
SimpleResponse response;
request.set_fill_username(true);
request.set_fill_oauth_scope(true);
request.set_response_type(PayloadType::COMPRESSABLE);
PerformLargeUnary(&request, &response);
GPR_ASSERT(!response.username().empty());
GPR_ASSERT(!response.oauth_scope().empty());
@ -180,6 +178,7 @@ void InteropClient::DoJwtTokenCreds(const grpc::string& username) {
SimpleRequest request;
SimpleResponse response;
request.set_fill_username(true);
request.set_response_type(PayloadType::COMPRESSABLE);
PerformLargeUnary(&request, &response);
GPR_ASSERT(!response.username().empty());
GPR_ASSERT(username.find(response.username()) != grpc::string::npos);
@ -187,12 +186,19 @@ void InteropClient::DoJwtTokenCreds(const grpc::string& username) {
}
void InteropClient::DoLargeUnary() {
gpr_log(GPR_INFO, "Sending a large unary rpc...");
SimpleRequest request;
request.set_response_compression(grpc::testing::GZIP);
SimpleResponse response;
PerformLargeUnary(&request, &response);
gpr_log(GPR_INFO, "Large unary done.");
const CompressionType compression_types[] = {NONE, GZIP, DEFLATE};
const PayloadType payload_types[] = {COMPRESSABLE, UNCOMPRESSABLE, RANDOM};
for (const auto payload_type : payload_types) {
for (const auto compression_type : compression_types) {
gpr_log(GPR_INFO, "Sending a large unary rpc...");
SimpleRequest request;
SimpleResponse response;
request.set_response_type(payload_type);
request.set_response_compression(compression_type);
PerformLargeUnary(&request, &response);
gpr_log(GPR_INFO, "Large unary done.");
}
}
}
void InteropClient::DoRequestStreaming() {
@ -227,11 +233,15 @@ void InteropClient::DoResponseStreaming() {
ClientContext context;
StreamingOutputCallRequest request;
request.set_response_type(PayloadType::COMPRESSABLE);
request.set_response_compression(CompressionType::GZIP);
for (unsigned int i = 0; i < response_stream_sizes.size(); ++i) {
ResponseParameters* response_parameter = request.add_response_parameters();
response_parameter->set_size(response_stream_sizes[i]);
}
StreamingOutputCallResponse response;
std::unique_ptr<ClientReader<StreamingOutputCallResponse>> stream(
stub->StreamingOutputCall(&context, request));

@ -81,8 +81,28 @@ static bool got_sigint = false;
bool SetPayload(PayloadType type, int size, Payload* payload) {
PayloadType response_type = type;
payload->set_type(response_type);
std::unique_ptr<char[]> body(new char[size]());
payload->set_body(body.get(), size);
switch (type) {
case PayloadType::COMPRESSABLE:
{
std::unique_ptr<char[]> body(new char[size]());
payload->set_body(body.get(), size);
}
break;
case PayloadType::UNCOMPRESSABLE:
{
// XXX
std::unique_ptr<char[]> body(new char[size]());
payload->set_body(body.get(), size);
}
break;
case PayloadType::RANDOM:
{
// XXX
std::unique_ptr<char[]> body(new char[size]());
payload->set_body(body.get(), size);
}
break;
}
return true;
}
@ -122,6 +142,7 @@ class TestServiceImpl : public TestService::Service {
return Status(grpc::StatusCode::INTERNAL, "Error creating payload.");
}
}
return Status::OK;
}

@ -60,21 +60,21 @@ std::shared_ptr<ServerCredentials> CreateInteropServerCredentials() {
}
}
InteropContextInspector::InteropContextInspector(
InteropServerContextInspector::InteropServerContextInspector(
const ::grpc::ServerContext& context)
: context_(context) {}
grpc_compression_algorithm
InteropContextInspector::GetCallCompressionAlgorithm() const {
InteropServerContextInspector::GetCallCompressionAlgorithm() const {
return grpc_call_get_compression_algorithm(context_.call_);
}
std::shared_ptr<const AuthContext> InteropContextInspector::GetAuthContext()
std::shared_ptr<const AuthContext> InteropServerContextInspector::GetAuthContext()
const {
return context_.auth_context();
}
bool InteropContextInspector::IsCancelled() const {
bool InteropServerContextInspector::IsCancelled() const {
return context_.IsCancelled();
}

@ -45,9 +45,9 @@ namespace testing {
std::shared_ptr<ServerCredentials> CreateInteropServerCredentials();
class InteropContextInspector {
class InteropServerContextInspector {
public:
InteropContextInspector(const ::grpc::ServerContext& context);
InteropServerContextInspector(const ::grpc::ServerContext& context);
// Inspector methods, able to peek inside ServerContext, follow.
std::shared_ptr<const AuthContext> GetAuthContext() const;

Loading…
Cancel
Save