Author: kclark
Date: Thu Jun 26 11:10:56 2008
New Revision: 671967

URL: http://svn.apache.org/viewvc?rev=671967&view=rev
Log:
rb: BufferedTransport should flush on close [THRIFT-49]

This also adds code and spec so nothing will be written to the transport
if there's nothing in the write buffer.

Modified:
    incubator/thrift/trunk/lib/rb/lib/thrift/transport.rb
    incubator/thrift/trunk/lib/rb/spec/transport_spec.rb

Modified: incubator/thrift/trunk/lib/rb/lib/thrift/transport.rb
URL: 
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/transport.rb?rev=671967&r1=671966&r2=671967&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/transport.rb (original)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/transport.rb Thu Jun 26 11:10:56 
2008
@@ -90,6 +90,7 @@
     end
 
     def close
+      flush
       @transport.close
     end
 
@@ -102,9 +103,12 @@
     end
 
     def flush
-      @transport.write(@wbuf)
+      if @wbuf != ''
+        @transport.write(@wbuf)
+        @wbuf = ''
+      end
+      
       @transport.flush
-      @wbuf = ''
     end
   end
   deprecate_class! :TBufferedTransport => BufferedTransport

Modified: incubator/thrift/trunk/lib/rb/spec/transport_spec.rb
URL: 
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/spec/transport_spec.rb?rev=671967&r1=671966&r2=671967&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/spec/transport_spec.rb (original)
+++ incubator/thrift/trunk/lib/rb/spec/transport_spec.rb Thu Jun 26 11:10:56 
2008
@@ -52,6 +52,7 @@
       trans = mock("Transport")
       trans.should_receive(:open?).ordered.and_return("+ open?")
       trans.should_receive(:open).ordered.and_return("+ open")
+      trans.should_receive(:flush).ordered # from the close
       trans.should_receive(:close).ordered.and_return("+ close")
       trans.should_receive(:read).with(217).ordered.and_return("+ read")
       btrans = BufferedTransport.new(trans)
@@ -81,7 +82,22 @@
       trans.should_receive(:write).with("one/two/three/")
       trans.stub!(:flush)
       btrans.flush
-      trans.should_receive(:write).with("")
+      # Nothing to flush with no data
+      btrans.flush
+    end
+    
+    it "should flush on close" do
+      trans = mock("Transport")
+      trans.should_receive(:close)
+      btrans = BufferedTransport.new(trans)
+      btrans.should_receive(:flush)
+      btrans.close
+    end
+    
+    it "should not write to socket if there's no data" do
+      trans = mock("Transport")
+      trans.should_receive(:flush)
+      btrans = BufferedTransport.new(trans)
       btrans.flush
     end
   end


Reply via email to