Skip to content

Commit

Permalink
Added missing payloads to streaming compressed test
Browse files Browse the repository at this point in the history
  • Loading branch information
dgquintas committed Aug 25, 2015
1 parent f355272 commit 04ecfa1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
31 changes: 24 additions & 7 deletions test/cpp/interop/interop_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -362,20 +362,37 @@ void InteropClient::DoResponseCompressedStreaming() {
request.set_response_type(payload_types[i]);
request.set_response_compression(compression_types[j]);

for (unsigned int i = 0; i < response_stream_sizes.size(); ++i) {
for (size_t k = 0; k < response_stream_sizes.size(); ++k) {
ResponseParameters* response_parameter =
request.add_response_parameters();
response_parameter->set_size(response_stream_sizes[i]);
response_parameter->set_size(response_stream_sizes[k]);
}
StreamingOutputCallResponse response;

std::unique_ptr<ClientReader<StreamingOutputCallResponse>> stream(
stub->StreamingOutputCall(&context, request));

unsigned int i = 0;
size_t k = 0;
while (stream->Read(&response)) {
GPR_ASSERT(response.payload().body() ==
grpc::string(response_stream_sizes[i], '\0'));
// Payload related checks.
if (request.response_type() != PayloadType::RANDOM) {
GPR_ASSERT(response.payload().type() == request.response_type());
}
switch (response.payload().type()) {
case PayloadType::COMPRESSABLE:
GPR_ASSERT(response.payload().body() ==
grpc::string(response_stream_sizes[k], '\0'));
break;
case PayloadType::UNCOMPRESSABLE: {
std::ifstream rnd_file(kRandomFile);
GPR_ASSERT(rnd_file.good());
for (int n = 0; n < response_stream_sizes[k]; n++) {
GPR_ASSERT(response.payload().body()[n] == (char)rnd_file.get());
}
} break;
default:
GPR_ASSERT(false);
}

// Compression related checks.
GPR_ASSERT(request.response_compression() ==
Expand All @@ -391,10 +408,10 @@ void InteropClient::DoResponseCompressedStreaming() {
GRPC_WRITE_INTERNAL_COMPRESS);
}

++i;
++k;
}

GPR_ASSERT(response_stream_sizes.size() == i);
GPR_ASSERT(response_stream_sizes.size() == k);
Status s = stream->Finish();

AssertOkOrPrintErrorStatus(s);
Expand Down
8 changes: 5 additions & 3 deletions test/cpp/interop/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,13 @@ class TestServiceImpl : public TestService::Service {
SetResponseCompression(context, *request);
StreamingOutputCallResponse response;
bool write_success = true;
response.mutable_payload()->set_type(request->response_type());
for (int i = 0; write_success && i < request->response_parameters_size();
i++) {
response.mutable_payload()->set_body(
grpc::string(request->response_parameters(i).size(), '\0'));
if (!SetPayload(request->response_type(),
request->response_parameters(i).size(),
response.mutable_payload())) {
return Status(grpc::StatusCode::INTERNAL, "Error creating payload.");
}
write_success = writer->Write(response);
}
if (write_success) {
Expand Down

0 comments on commit 04ecfa1

Please sign in to comment.