From f4e700883b943775233b75770a12fd7affa9ef31 Mon Sep 17 00:00:00 2001 From: Kevin Clark Date: Fri, 18 Jul 2008 22:27:03 +0000 Subject: [PATCH] rb: Improve IOStreamTransport to behave more like a real transport [THRIFT-76] Author: Kevin Ballard git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@678065 13f79535-47bb-0310-9956-ffa450edef68 --- lib/rb/lib/thrift/transport.rb | 4 +++- lib/rb/spec/transport_spec.rb | 19 +++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/rb/lib/thrift/transport.rb b/lib/rb/lib/thrift/transport.rb index 6b1152e3..e4a70cdd 100644 --- a/lib/rb/lib/thrift/transport.rb +++ b/lib/rb/lib/thrift/transport.rb @@ -298,9 +298,11 @@ module Thrift @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 diff --git a/lib/rb/spec/transport_spec.rb b/lib/rb/spec/transport_spec.rb index 972e9846..98408abb 100644 --- a/lib/rb/spec/transport_spec.rb +++ b/lib/rb/spec/transport_spec.rb @@ -293,15 +293,20 @@ class ThriftTransportSpec < Spec::ExampleGroup 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 @@ class ThriftTransportSpec < Spec::ExampleGroup @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 -- 2.17.1