You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by kc...@apache.org on 2008/07/19 00:27:04 UTC

svn commit: r678065 - in /incubator/thrift/trunk/lib/rb: lib/thrift/transport.rb spec/transport_spec.rb

Author: kclark
Date: Fri Jul 18 15:27:03 2008
New Revision: 678065

URL: http://svn.apache.org/viewvc?rev=678065&view=rev
Log:
rb: Improve IOStreamTransport to behave more like a real transport [THRIFT-76]

Author: Kevin Ballard <ke...@rapleaf.com>

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=678065&r1=678064&r2=678065&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/transport.rb (original)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/transport.rb Fri Jul 18 15:27:03 2008
@@ -298,9 +298,11 @@
       @output = output
     end
 
-    def open?; true end
+    def open?; not @input.closed? or not @output.closed? end
     def read(sz); @input.read(sz) end
     def write(buf); @output.write(buf) end
+    def close; @input.close; @output.close end
+    def to_io; @input end # we're assuming this is used in a IO.select for reading
   end
   deprecate_class! :TIOStreamTransport => IOStreamTransport
 end

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=678065&r1=678064&r2=678065&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/spec/transport_spec.rb (original)
+++ incubator/thrift/trunk/lib/rb/spec/transport_spec.rb Fri Jul 18 15:27:03 2008
@@ -293,15 +293,20 @@
 
   describe IOStreamTransport do
     before(:each) do
-      @input = mock("Input")
-      @output = mock("Output")
+      @input = mock("Input", :closed? => false)
+      @output = mock("Output", :closed? => false)
       @trans = IOStreamTransport.new(@input, @output)
     end
 
-    it "should always be open" do
+    it "should be open as long as both input or output are open" do
       @trans.should be_open
-      @trans.close
+      @input.stub!(:closed?).and_return(true)
+      @trans.should be_open
+      @input.stub!(:closed?).and_return(false)
+      @output.stub!(:closed?).and_return(true)
       @trans.should be_open
+      @input.stub!(:closed?).and_return(true)
+      @trans.should_not be_open
     end
 
     it "should pass through read/write to input/output" do
@@ -310,5 +315,11 @@
       @trans.read(17).should == "+ read"
       @trans.write("foobar").should == "+ write"
     end
+
+    it "should close both input and output when closed" do
+      @input.should_receive(:close)
+      @output.should_receive(:close)
+      @trans.close
+    end
   end
 end