diff options
author | 2015-07-22 09:10:39 -0700 | |
---|---|---|
committer | 2015-07-22 09:10:39 -0700 | |
commit | c899319fd854e7d9476ab3c304c059a99e549a21 (patch) | |
tree | fc1bd0b76b0072f7ac6859327651502df93259e8 /test/cpp/interop/server.cc | |
parent | 80f3995e47ae1ccd30a48c00ef8770cf18e51280 (diff) |
Updated interop tests with support for compression.
The support for uncompressable payloads relies on a 512KB file with data from /dev/urandom
Diffstat (limited to 'test/cpp/interop/server.cc')
-rw-r--r-- | test/cpp/interop/server.cc | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/test/cpp/interop/server.cc b/test/cpp/interop/server.cc index 55df82b567..32c60aff44 100644 --- a/test/cpp/interop/server.cc +++ b/test/cpp/interop/server.cc @@ -31,6 +31,7 @@ * */ +#include <fstream> #include <memory> #include <sstream> #include <thread> @@ -48,6 +49,7 @@ #include <grpc++/server_credentials.h> #include <grpc++/status.h> #include <grpc++/stream.h> + #include "test/proto/test.grpc.pb.h" #include "test/proto/empty.grpc.pb.h" #include "test/proto/messages.grpc.pb.h" @@ -77,31 +79,32 @@ using grpc::testing::TestService; using grpc::Status; static bool got_sigint = false; +static const char* kRandomFile = "test/cpp/interop/rnd.dat"; bool SetPayload(PayloadType type, int size, Payload* payload) { - PayloadType response_type = type; + PayloadType response_type; + if (type == PayloadType::RANDOM) { + response_type = + rand() & 0x1 ? PayloadType::COMPRESSABLE : PayloadType::UNCOMPRESSABLE; + } else { + response_type = type; + } payload->set_type(response_type); - 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; + switch (response_type) { + case PayloadType::COMPRESSABLE: { + std::unique_ptr<char[]> body(new char[size]()); + payload->set_body(body.get(), size); + } break; + case PayloadType::UNCOMPRESSABLE: { + std::unique_ptr<char[]> body(new char[size]()); + std::ifstream rnd_file(kRandomFile); + GPR_ASSERT(rnd_file.good()); + rnd_file.read(body.get(), size); + GPR_ASSERT(!rnd_file.eof()); // Requested more rnd bytes than available + payload->set_body(body.get(), size); + } break; + default: + GPR_ASSERT(false); } return true; } |