You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by dr...@apache.org on 2008/06/30 21:48:04 UTC

svn commit: r672881 - /incubator/thrift/trunk/test/TBufferBaseTest.cpp

Author: dreiss
Date: Mon Jun 30 12:48:04 2008
New Revision: 672881

URL: http://svn.apache.org/viewvc?rev=672881&view=rev
Log:
(THRIFT-61) Fix "make check" for the C++ library by not doing empty flushes.

I changed the behavior of TFramedTransport when flush is called without
writing any data to the transport.  This broke the unit test, which was
relying on a weird corner of TFramedTransport's behavior in order to do
some stricter checking.  I altered the unit test to never flush without
writing and added a new test to verfy the "empty flush" behavior.

Modified:
    incubator/thrift/trunk/test/TBufferBaseTest.cpp

Modified: incubator/thrift/trunk/test/TBufferBaseTest.cpp
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/test/TBufferBaseTest.cpp?rev=672881&r1=672880&r2=672881&view=diff
==============================================================================
--- incubator/thrift/trunk/test/TBufferBaseTest.cpp (original)
+++ incubator/thrift/trunk/test/TBufferBaseTest.cpp Mon Jun 30 12:48:04 2008
@@ -555,7 +555,7 @@
           write_offset += dist[d1][write_index];
           flush_size += dist[d1][write_index];
           write_index++;
-          if (rand()%prob == 0) {
+          if (flush_size > 0 && rand()%prob == 0) {
             flush_sizes.push_back(flush_size);
             flush_size = 0;
             trans.flush();
@@ -586,4 +586,35 @@
   }
 }
 
+BOOST_AUTO_TEST_CASE( test_FramedTransport_Empty_Flush ) {
+  init_data();
+
+  string output1("\x00\x00\x00\x01""a", 5);
+  string output2("\x00\x00\x00\x01""a\x00\x00\x00\x02""bc", 11);
+
+  shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer());
+  TFramedTransport trans(buffer);
+
+  BOOST_CHECK_EQUAL(buffer->getBufferAsString(), "");
+  trans.flush();
+  BOOST_CHECK_EQUAL(buffer->getBufferAsString(), "");
+  trans.flush();
+  trans.flush();
+  BOOST_CHECK_EQUAL(buffer->getBufferAsString(), "");
+  trans.write((const uint8_t*)"a", 1);
+  BOOST_CHECK_EQUAL(buffer->getBufferAsString(), "");
+  trans.flush();
+  BOOST_CHECK_EQUAL(buffer->getBufferAsString(), output1);
+  trans.flush();
+  trans.flush();
+  BOOST_CHECK_EQUAL(buffer->getBufferAsString(), output1);
+  trans.write((const uint8_t*)"bc", 2);
+  BOOST_CHECK_EQUAL(buffer->getBufferAsString(), output1);
+  trans.flush();
+  BOOST_CHECK_EQUAL(buffer->getBufferAsString(), output2);
+  trans.flush();
+  trans.flush();
+  BOOST_CHECK_EQUAL(buffer->getBufferAsString(), output2);
+}
+
 BOOST_AUTO_TEST_SUITE_END()