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/29 00:16:29 UTC

svn commit: r680538 - in /incubator/thrift/trunk/lib/rb: lib/thrift/client.rb spec/client_spec.rb

Author: kclark
Date: Mon Jul 28 15:16:28 2008
New Revision: 680538

URL: http://svn.apache.org/viewvc?rev=680538&view=rev
Log:
rb: Ensure the transport is closed if an exception is raised serializing data in Client.send_message [THRIFT-75]

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

Modified:
    incubator/thrift/trunk/lib/rb/lib/thrift/client.rb
    incubator/thrift/trunk/lib/rb/spec/client_spec.rb

Modified: incubator/thrift/trunk/lib/rb/lib/thrift/client.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/client.rb?rev=680538&r1=680537&r2=680538&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/client.rb (original)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/client.rb Mon Jul 28 15:16:28 2008
@@ -12,7 +12,12 @@
       args.each do |k, v|
         data.send("#{k.to_s}=", v)
       end
-      data.write(@oprot)
+      begin
+        data.write(@oprot)
+      rescue StandardError => e
+        @oprot.trans.close
+        raise e
+      end
       @oprot.write_message_end
       @oprot.trans.flush
     end

Modified: incubator/thrift/trunk/lib/rb/spec/client_spec.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/spec/client_spec.rb?rev=680538&r1=680537&r2=680538&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/spec/client_spec.rb (original)
+++ incubator/thrift/trunk/lib/rb/spec/client_spec.rb Mon Jul 28 15:16:28 2008
@@ -65,5 +65,17 @@
       end
       lambda { @client.receive_message(nil) }.should raise_error(StandardError)
     end
+
+    it "should close the transport if an error occurs while sending a message" do
+      @prot.stub!(:write_message_begin)
+      @prot.should_not_receive(:write_message_end)
+      mock_args = mock("#<TestMessage_args:mock>")
+      mock_args.should_receive(:write).with(@prot).and_raise(StandardError)
+      trans = mock("MockTransport")
+      @prot.stub!(:trans).and_return(trans)
+      trans.should_receive(:close)
+      klass = mock("TestMessage_args", :new => mock_args)
+      lambda { @client.send_message("testMessage", klass) }.should raise_error(StandardError)
+    end
   end
 end