THRIFT-275. rb: Remove deprecated classes from Ruby library
This patch removes all the deprecation stuff and the t*.rb classes that were only placeholders. In addition, I've changed the implementations of some "abstract" methods to throw NotImplementedError instead of returning nil, and fixed the test accordingly. Finally, I removed the no longer required borrow and consume methods from all the transport implementations that had them. (Borrow and consume have been supplanted by the thrift_native package.)
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@757668 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/rb/spec/backwards_compatibility_spec.rb b/lib/rb/spec/backwards_compatibility_spec.rb
deleted file mode 100644
index 2ac3489..0000000
--- a/lib/rb/spec/backwards_compatibility_spec.rb
+++ /dev/null
@@ -1,136 +0,0 @@
-require File.dirname(__FILE__) + '/spec_helper'
-require 'thrift/protocol/binaryprotocol'
-require 'thrift/server/httpserver'
-require 'thrift/transport/httpclient'
-
-context "Backwards compatibility" do
- specify "old class names should map to new classes" do
- Thrift::DeprecationProxy.reset_deprecation_warnings
- # use an Array because a Hash will call #hash and trigger deprecation warnings
- klasses = [
- [:module, :ThriftClient, Thrift::Client],
- [:class, :TException, Thrift::Exception],
- [:class, :TApplicationException, Thrift::ApplicationException],
- [:module, :TProcessor, Thrift::Processor],
- [:class, :TProtocolException, Thrift::ProtocolException],
- [:class, :TProtocol, Thrift::Protocol],
- [:class, :TProtocolFactory, Thrift::ProtocolFactory],
- [:class, :TBinaryProtocol, Thrift::BinaryProtocol],
- [:class, :TBinaryProtocolFactory, Thrift::BinaryProtocolFactory],
- [:class, :TSimpleMongrelHTTPServer, Thrift::SimpleMongrelHTTPServer],
- [:class, :TServer, Thrift::Server],
- [:class, :TSimpleServer, Thrift::SimpleServer],
- [:class, :TThreadedServer, Thrift::ThreadedServer],
- [:class, :TThreadPoolServer, Thrift::ThreadPoolServer],
- [:module, :ThriftStruct, Thrift::Struct],
- [:class, :THttpClient, Thrift::HTTPClient],
- [:class, :TSocket, Thrift::Socket],
- [:class, :TServerSocket, Thrift::ServerSocket],
- [:class, :TTransportException, Thrift::TransportException],
- [:class, :TTransport, Thrift::Transport],
- [:class, :TServerTransport, Thrift::ServerTransport],
- [:class, :TTransportFactory, Thrift::TransportFactory],
- [:class, :TBufferedTransport, Thrift::BufferedTransport],
- [:class, :TBufferedTransportFactory, Thrift::BufferedTransportFactory],
- [:class, :TFramedTransport, Thrift::FramedTransport],
- [:class, :TFramedTransportFactory, Thrift::FramedTransportFactory],
- [:class, :TMemoryBuffer, Thrift::MemoryBuffer],
- [:class, :TIOStreamTransport, Thrift::IOStreamTransport],
- [:module, :TType, Thrift::Types],
- [:module, :TMessageType, Thrift::MessageTypes]
- ]
- klasses.each do |(type, oldname, newklass)|
- oldklass = Object.const_get(oldname)
- STDERR.should_receive(:puts).with("Warning: #{type} #{oldname} is deprecated").ordered
- STDERR.should_receive(:puts).with(" from #{__FILE__}:#{__LINE__+1}").ordered
- oldklass.should eql(newklass)
- STDERR.rspec_verify
- STDERR.rspec_reset
- end
- end
-
- specify "old method names should map to new method names" do
- mapping = {
- Thrift::Protocol => {
- :writeMessageBegin => :write_message_begin,
- :writeMessageEnd => :write_message_end,
- :writeStructBegin => :write_struct_begin,
- :writeStructEnd => :write_struct_end,
- :writeFieldBegin => :write_field_begin,
- :writeFieldEnd => :write_field_end,
- :writeFieldStop => :write_field_stop,
- :writeMapBegin => :write_map_begin,
- :writeMapEnd => :write_map_end,
- :writeListBegin => :write_list_begin,
- :writeListEnd => :write_list_end,
- :writeSetBegin => :write_set_begin,
- :writeSetEnd => :write_set_end,
- :writeBool => :write_bool,
- :writeByte => :write_byte,
- :writeI16 => :write_i16,
- :writeI32 => :write_i32,
- :writeI64 => :write_i64,
- :writeDouble => :write_double,
- :writeString => :write_string,
- :readMessageBegin => :read_message_begin,
- :readMessageEnd => :read_message_end,
- :readStructBegin => :read_struct_begin,
- :readStructEnd => :read_struct_end,
- :readFieldBegin => :read_field_begin,
- :readFieldEnd => :read_field_end,
- :readMapBegin => :read_map_begin,
- :readMapEnd => :read_map_end,
- :readListBegin => :read_list_begin,
- :readListEnd => :read_list_end,
- :readSetBegin => :read_set_begin,
- :readSetEnd => :read_set_end,
- :readBool => :read_bool,
- :readByte => :read_byte,
- :readI16 => :read_i16,
- :readI32 => :read_i32,
- :readI64 => :read_i64,
- :readDouble => :read_double,
- :readString => :read_string
- },
- Thrift::ProtocolFactory => {
- :getProtocol => :get_protocol
- },
- Thrift::Transport => {
- :isOpen => :open?,
- :is_open? => :open?,
- :readAll => :read_all
- },
- Thrift::TransportFactory => {
- :getTransport => :get_transport
- }
- }
- STDERR.stub!(:puts) # stub the deprecation warnings
- mapping.each_pair do |klass, methods|
- # save these so they can be used after being mocked up
- defn_method = klass.method(:define_method)
- inst_method = klass.method(:instance_method)
- methods.each_pair do |oldmeth, newmeth|
- # ensure that calling the old method will call the new method
- # and then redefine the old method to be the new one
- klass.should be_method_defined(oldmeth)
- klass.should be_method_defined(newmeth)
- orig_method = inst_method.call(:initialize)
- defn_method.call(:initialize, proc {} ) # stub out initialize
- begin
- mockmeth = mock("UnboundMethod: #{newmeth}")
- mockmeth.should_receive(:bind).and_return do
- mock("Method: #{newmeth}").tee do |meth|
- meth.should_receive(:call)
- end
- end
- klass.should_receive(:instance_method).with(newmeth).twice.and_return(mockmeth)
- klass.should_receive(:define_method).with(oldmeth, mockmeth)
- klass.new.send oldmeth
- klass.rspec_verify
- ensure
- defn_method.call(:initialize, orig_method)
- end
- end
- end
- end
-end
diff --git a/lib/rb/spec/deprecation_spec.rb b/lib/rb/spec/deprecation_spec.rb
deleted file mode 100644
index 0074528..0000000
--- a/lib/rb/spec/deprecation_spec.rb
+++ /dev/null
@@ -1,446 +0,0 @@
-require File.dirname(__FILE__) + '/spec_helper'
-
-shared_examples_for "deprecation" do
- before(:all) do
- # ensure deprecation is turned on
- Thrift.send :remove_const, :DEPRECATION
- Thrift.const_set :DEPRECATION, true
- end
-
- after(:all) do
- # now turn it off again
- # no other specs should want it
- Thrift.send :remove_const, :DEPRECATION
- Thrift.const_set :DEPRECATION, false
- end
-
- before(:each) do
- Thrift::DeprecationProxy.reset_deprecation_warnings
- end
-
- def ensure_const_removed(name, &block)
- begin
- block.call
- ensure
- Object.send :remove_const, name if Object.const_defined? name
- end
- end
-end
-
-describe 'deprecate!' do
- it_should_behave_like "deprecation"
-
- def stub_stderr(callstr, offset=1)
- STDERR.should_receive(:puts).with("Warning: calling deprecated method #{callstr}")
- line = caller.first[/\d+$/].to_i + offset
- STDERR.should_receive(:puts).with(" from #{__FILE__}:#{line}")
- end
-
- it "should work for Module methods" do
- mod = Module.new do
- class << self
- def new
- "new"
- end
- deprecate! :old => :new
- end
- end
- stub_stderr "#{mod.inspect}.old"
- mod.old.should == "new"
- end
-
- it "should work with Modules that extend themselves" do
- mod = Module.new do
- extend self
- def new
- "new"
- end
- deprecate! :old => :new
- end
- stub_stderr "#{mod.inspect}.old"
- mod.old.should == "new"
- end
-
- it "should work wtih Class methods" do
- klass = Class.new do
- class << self
- def new
- "new"
- end
- deprecate! :old => :new
- end
- end
- stub_stderr "#{klass.inspect}.old"
- klass.old.should == "new"
- end
-
- it "should work with Classes that include Modules" do
- mod = Module.new do
- def new
- "new"
- end
- deprecate! :old => :new
- end
- klass = Class.new do
- include mod
- end
- stub_stderr "#{klass.inspect}#old"
- klass.new.old.should == "new"
- end
-
- it "should work with instance methods" do
- klass = Class.new do
- def new
- "new"
- end
- deprecate! :old => :new
- end
- stub_stderr "#{klass.inspect}#old"
- klass.new.old.should == "new"
- end
-
- it "should work with multiple method names" do
- klass = Class.new do
- def new1
- "new 1"
- end
- def new2
- "new 2"
- end
- deprecate! :old1 => :new1, :old2 => :new2
- end
- stub_stderr("#{klass.inspect}#old1", 3).ordered
- stub_stderr("#{klass.inspect}#old2", 3).ordered
- inst = klass.new
- inst.old1.should == "new 1"
- inst.old2.should == "new 2"
- end
-
- it "should only log a message once, even across multiple instances" do
- klass = Class.new do
- def new
- "new"
- end
- deprecate! :old => :new
- end
- stub_stderr("#{klass.inspect}#old").once
- klass.new.old.should == "new"
- klass.new.old.should == "new"
- end
-
- it "should pass arguments" do
- klass = Class.new do
- def new(a, b)
- "new: #{a + b}"
- end
- deprecate! :old => :new
- end
- stub_stderr("#{klass.inspect}#old")
- klass.new.old(3, 5).should == "new: 8"
- end
-
- it "should pass blocks" do
- klass = Class.new do
- def new
- "new #{yield}"
- end
- deprecate! :old => :new
- end
- stub_stderr("#{klass.inspect}#old")
- klass.new.old { "block" }.should == "new block"
- end
-
- it "should not freeze the definition of the new method" do
- klass = Class.new do
- def new
- "new"
- end
- deprecate! :old => :new
- end
- klass.send :define_method, :new do
- "new 2"
- end
- stub_stderr("#{klass.inspect}#old")
- klass.new.old.should == "new 2"
- end
-
- it "should call the forwarded method in the same context as the original" do
- klass = Class.new do
- def myself
- self
- end
- deprecate! :me => :myself
- end
- inst = klass.new
- stub_stderr("#{klass.inspect}#me")
- inst.me.should eql(inst.myself)
- end
-end
-
-describe "deprecate_class!" do
- it_should_behave_like "deprecation"
-
- def stub_stderr_jruby(klass)
- return unless defined? JRUBY_VERSION
- stub_stderr(klass, nil, caller.first)
- end
-
- def stub_stderr_mri(klass, offset=1)
- return if defined? JRUBY_VERSION
- stub_stderr(klass, offset, caller.first)
- end
-
- def stub_stderr(klass, offset=1, called=nil)
- STDERR.should_receive(:puts).with("Warning: class #{klass} is deprecated")
- if offset
- line = (called || caller.first)[/\d+$/].to_i + offset
- STDERR.should_receive(:puts).with(" from #{__FILE__}:#{line}")
- else
- STDERR.should_receive(:puts).with(/^ from #{Regexp.escape(__FILE__)}:/)
- end
- end
-
- it "should create a new global constant that points to the old one" do
- ensure_const_removed :DeprecationSpecOldClass do
- klass = Class.new do
- def foo
- "foo"
- end
- end
- deprecate_class! :DeprecationSpecOldClass => klass
- stub_stderr(:DeprecationSpecOldClass)
- ::DeprecationSpecOldClass.should eql(klass)
- ::DeprecationSpecOldClass.new.foo.should == "foo"
- end
- end
-
- it "should create a global constant even from inside a module" do
- ensure_const_removed :DeprecationSpecOldClass do
- klass = nil #define scoping
- Module.new do
- klass = Class.new do
- def foo
- "foo"
- end
- end
- deprecate_class! :DeprecationSpecOldClass => klass
- end
- stub_stderr(:DeprecationSpecOldClass)
- ::DeprecationSpecOldClass.should eql(klass)
- ::DeprecationSpecOldClass.new.foo.should == "foo"
- end
- end
-
- it "should not prevent the deprecated class from being a superclass" do
- ensure_const_removed :DeprecationSpecOldClass do
- klass = Class.new do
- def foo
- "foo"
- end
- end
- deprecate_class! :DeprecationSpecOldClass => klass
- stub_stderr_jruby(:DeprecationSpecOldClass)
- subklass = Class.new(::DeprecationSpecOldClass) do
- def foo
- "subclass #{super}"
- end
- end
- stub_stderr_mri(:DeprecationSpecOldClass)
- subklass.superclass.should eql(klass)
- subklass.new.foo.should == "subclass foo"
- end
- end
-
- it "should not bleed info between deprecations" do
- ensure_const_removed :DeprecationSpecOldClass do
- ensure_const_removed :DeprecationSpecOldClass2 do
- klass = Class.new do
- def foo
- "foo"
- end
- end
- deprecate_class! :DeprecationSpecOldClass => klass
- klass2 = Class.new do
- def bar
- "bar"
- end
- end
- deprecate_class! :DeprecationSpecOldClass2 => klass2
- stub_stderr(:DeprecationSpecOldClass)
- ::DeprecationSpecOldClass.new.foo.should == "foo"
- stub_stderr(:DeprecationSpecOldClass2)
- ::DeprecationSpecOldClass2.new.bar.should == "bar"
- end
- end
- end
-
- it "should work when Object.inherited calls a method on self" do
- ensure_const_removed :DeprecationSpecOldClass do
- old_inherited = Object.method(:inherited)
- begin
- (class << Object;self;end).class_eval do
- define_method :inherited do |cls|
- cls.inspect
- old_inherited.call(cls)
- end
- end
- klass = Class.new do
- def foo
- "foo"
- end
- end
- STDERR.should_receive(:puts).exactly(0).times
- lambda { deprecate_class! :DeprecationSpecOldClass => klass }.should_not raise_error
- ensure
- (class << Object;self;end).class_eval do
- define_method :inherited, old_inherited
- end
- end
- end
- end
-end
-
-describe "deprecate_module!" do
- it_should_behave_like "deprecation"
-
- def stub_stderr_jruby(mod)
- return unless defined? JRUBY_VERSION
- stub_stderr(mod, nil, caller.first)
- end
-
- def stub_stderr_mri(mod, offset=1)
- return if defined? JRUBY_VERSION
- stub_stderr(mod, offset, caller.first)
- end
-
- def stub_stderr(mod, offset=1, called=nil)
- STDERR.should_receive(:puts).with("Warning: module #{mod} is deprecated")
- source = Regexp.escape(__FILE__) + ":"
- if offset
- line = (called || caller.first)[/\d+$/].to_i + offset
- source += Regexp.escape(line.to_s)
- else
- source += "\d+"
- end
- STDERR.should_receive(:puts).with(/^ from #{source}(?::in `[^']+')?$/)
- end
-
- it "should create a new global constant that points to the old one" do
- ensure_const_removed :DeprecationSpecOldModule do
- mod = Module.new do
- def self.foo
- "foo"
- end
- end
- deprecate_module! :DeprecationSpecOldModule => mod
- stub_stderr(:DeprecationSpecOldModule)
- ::DeprecationSpecOldModule.should eql(mod)
- ::DeprecationSpecOldModule.foo.should == "foo"
- end
- end
-
- it "should create a global constant even from inside a module" do
- ensure_const_removed :DeprecationSpecOldModule do
- mod = nil # scoping
- Module.new do
- mod = Module.new do
- def self.foo
- "foo"
- end
- end
- deprecate_module! :DeprecationSpecOldModule => mod
- end
- stub_stderr(:DeprecationSpecOldModule)
- ::DeprecationSpecOldModule.should eql(mod)
- ::DeprecationSpecOldModule.foo.should == "foo"
- end
- end
-
- it "should work for modules that extend themselves" do
- ensure_const_removed :DeprecationSpecOldModule do
- mod = Module.new do
- extend self
- def foo
- "foo"
- end
- end
- deprecate_module! :DeprecationSpecOldModule => mod
- stub_stderr(:DeprecationSpecOldModule)
- ::DeprecationSpecOldModule.should eql(mod)
- ::DeprecationSpecOldModule.foo.should == "foo"
- end
- end
-
- it "should work for modules included in other modules" do
- ensure_const_removed :DeprecationSpecOldModule do
- mod = Module.new do
- def foo
- "foo"
- end
- end
- deprecate_module! :DeprecationSpecOldModule => mod
- stub_stderr_jruby(:DeprecationSpecOldModule)
- mod2 = Module.new do
- class << self
- include ::DeprecationSpecOldModule
- end
- end
- stub_stderr_mri(:DeprecationSpecOldModule)
- mod2.foo.should == "foo"
- end
- end
-
- it "should work for modules included in classes" do
- ensure_const_removed :DeprecationSpecOldModule do
- mod = Module.new do
- def foo
- "foo"
- end
- end
- deprecate_module! :DeprecationSpecOldModule => mod
- stub_stderr_jruby(:DeprecationSpecOldModule)
- klass = Class.new do
- include ::DeprecationSpecOldModule
- end
- stub_stderr_mri(:DeprecationSpecOldModule)
- klass.new.foo.should == "foo"
- end
- end
-
- it "should not bleed info between deprecations" do
- ensure_const_removed :DeprecationSpecOldModule do
- ensure_const_removed :DeprecationSpecOldModule2 do
- mod = Module.new do
- def self.foo
- "foo"
- end
- end
- deprecate_module! :DeprecationSpecOldModule => mod
- mod2 = Module.new do
- def self.bar
- "bar"
- end
- end
- deprecate_module! :DeprecationSpecOldModule2 => mod2
- stub_stderr(:DeprecationSpecOldModule)
- ::DeprecationSpecOldModule.foo.should == "foo"
- stub_stderr(:DeprecationSpecOldModule2)
- ::DeprecationSpecOldModule2.bar.should == "bar"
- end
- end
- end
-
- it "should skip thrift library code when printing caller" do
- klass = Class.new do
- include ThriftStruct
- FIELDS = {
- 1 => {:name => "foo", :type => Thrift::Types::STRING}
- }
- def struct_fields
- FIELDS
- end
- end
- stub_stderr('ThriftStruct')
- klass.new(:foo => "foo")
- end
-end
diff --git a/lib/rb/spec/protocol_spec.rb b/lib/rb/spec/protocol_spec.rb
index a681cd8..1db4e19 100644
--- a/lib/rb/spec/protocol_spec.rb
+++ b/lib/rb/spec/protocol_spec.rb
@@ -134,9 +134,9 @@
end
describe ProtocolFactory do
- it "should return nil" do
+ it "should raise NotImplementedError" do
# returning nil since Protocol is just an abstract class
- ProtocolFactory.new.get_protocol(mock("MockTransport")).should be_nil
+ lambda {ProtocolFactory.new.get_protocol(mock("MockTransport"))}.should raise_error(NotImplementedError)
end
end
end
diff --git a/lib/rb/spec/transport_spec.rb b/lib/rb/spec/transport_spec.rb
index ef1918f..98408ab 100644
--- a/lib/rb/spec/transport_spec.rb
+++ b/lib/rb/spec/transport_spec.rb
@@ -221,40 +221,6 @@
@trans.should_receive(:write).with("\000\000\000\000")
ftrans.flush
end
-
- it "should refill its buffer when borrow is called and it is empty" do
- ftrans = FramedTransport.new(@trans)
- @trans.should_receive(:read_all).with(4).and_return([10].pack("N"))
- @trans.should_receive(:read_all).with(10).and_return("1234567890")
- ftrans.borrow(10).should == "1234567890"
- end
-
- it "should not consume any data when borrow is called" do
- ftrans = FramedTransport.new(@trans)
- @trans.should_receive(:read_all).with(4).and_return([10].pack("N"))
- @trans.should_receive(:read_all).with(10).and_return("1234567890")
- ftrans.borrow(10).should == "1234567890"
- ftrans.borrow(10).should == "1234567890"
- end
-
- it "should remove data from the buffer when consume! is called" do
- ftrans = FramedTransport.new(@trans)
- @trans.should_receive(:read_all).with(4).ordered.and_return([10].pack("N"))
- @trans.should_receive(:read_all).with(10).ordered.and_return("1234567890")
- ftrans.borrow(5).should == "1234567890"
- ftrans.consume!(5).should == "12345"
- ftrans.borrow(5).should == "67890"
- end
-
- it "should raise an EOFError when it is out of data and borrow is called" do
- ftrans = FramedTransport.new(@trans)
- @trans.should_receive(:read_all).with(4).ordered.and_return([10].pack("N"), [0].pack("N"))
- @trans.should_receive(:read_all).with(10).ordered.and_return("1234567890")
- @trans.should_receive(:read_all).with(0).ordered.and_return("")
- ftrans.borrow(10).should == "1234567890"
- ftrans.consume!(10).should == "1234567890"
- lambda {ftrans.borrow(10)}.should raise_error(EOFError)
- end
end
describe FramedTransportFactory do