THRIFT-926. cpp: Make TZlibTransport::flush() behave like other transports
Previously, TZlibTransport::flush() finished the zlib stream, so calling
write() after flush() would result in an error. Now it just flushes the
data, without finishing the stream. A new TZlibTransport::finish()
function has been added to finish the stream.
This breaks compatibility. I'm aware of anyone using this code outside
of Facebook, though.
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@1005151 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/test/TransportTest.cpp b/lib/cpp/test/TransportTest.cpp
index e5ddeee..7f95e38 100644
--- a/lib/cpp/test/TransportTest.cpp
+++ b/lib/cpp/test/TransportTest.cpp
@@ -36,6 +36,7 @@
#include <transport/TBufferTransports.h>
#include <transport/TFDTransport.h>
#include <transport/TFileTransport.h>
+#include <transport/TZlibTransport.h>
using namespace apache::thrift::transport;
@@ -178,6 +179,22 @@
boost::shared_ptr<TMemoryBuffer> buf;
};
+class CoupledZlibTransports : public CoupledTransports<TZlibTransport> {
+ public:
+ CoupledZlibTransports() :
+ buf(new TMemoryBuffer) {
+ in = new TZlibTransport(buf, false);
+ out = new TZlibTransport(buf, false);
+ }
+
+ ~CoupledZlibTransports() {
+ delete in;
+ delete out;
+ }
+
+ boost::shared_ptr<TMemoryBuffer> buf;
+};
+
class CoupledFDTransports : public CoupledTransports<TFDTransport> {
public:
CoupledFDTransports() {
@@ -363,7 +380,16 @@
read_size = rchunk_size - chunk_read;
}
- int bytes_read = transports.in->read(rbuf.get() + total_read, read_size);
+ int bytes_read = -1;
+ try {
+ bytes_read = transports.in->read(rbuf.get() + total_read, read_size);
+ } catch (TTransportException& e) {
+ BOOST_FAIL("read(pos=" << total_read << ", size=" << read_size <<
+ ") threw exception \"" << e.what() <<
+ "\"; written so far: " << total_written << " / " <<
+ totalSize << " bytes");
+ }
+
BOOST_REQUIRE_MESSAGE(bytes_read > 0,
"read(pos=" << total_read << ", size=" <<
read_size << ") returned " << bytes_read <<
@@ -449,6 +475,17 @@
BUFFER_TESTS(CoupledBufferedTransports)
BUFFER_TESTS(CoupledFramedTransports)
+ TEST_RW(CoupledZlibTransports, 1024*1024*10, 0, 0);
+ TEST_RW(CoupledZlibTransports, 1024*1024*10, rand4k, rand4k);
+ TEST_RW(CoupledZlibTransports, 1024*1024*5, 167, 163);
+ TEST_RW(CoupledZlibTransports, 1024*64, 1, 1);
+
+ TEST_RW(CoupledZlibTransports, 1024*1024*10, 0, 0, rand4k, rand4k);
+ TEST_RW(CoupledZlibTransports, 1024*1024*10,
+ rand4k, rand4k, rand4k, rand4k);
+ TEST_RW(CoupledZlibTransports, 1024*1024*5, 167, 163, rand4k, rand4k);
+ TEST_RW(CoupledZlibTransports, 1024*64, 1, 1, rand4k, rand4k);
+
// TFDTransport tests
// Since CoupledFDTransports tests with a pipe, writes will block
// if there is too much outstanding unread data in the pipe.