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/06/18 03:05:17 UTC

svn commit: r668942 - in /incubator/thrift/trunk/lib/rb/spec: backwards_compatibility_spec.rb spec_helper.rb

Author: kclark
Date: Tue Jun 17 18:05:17 2008
New Revision: 668942

URL: http://svn.apache.org/viewvc?rev=668942&view=rev
Log:
Add backwards-compatibility spec

Added:
    incubator/thrift/trunk/lib/rb/spec/backwards_compatibility_spec.rb
Modified:
    incubator/thrift/trunk/lib/rb/spec/spec_helper.rb

Added: incubator/thrift/trunk/lib/rb/spec/backwards_compatibility_spec.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/spec/backwards_compatibility_spec.rb?rev=668942&view=auto
==============================================================================
--- incubator/thrift/trunk/lib/rb/spec/backwards_compatibility_spec.rb (added)
+++ incubator/thrift/trunk/lib/rb/spec/backwards_compatibility_spec.rb Tue Jun 17 18:05:17 2008
@@ -0,0 +1,115 @@
+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
+    # 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,  :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
+      }
+    }
+    mapping.each_pair do |klass, methods|
+      methods.each_pair do |oldmeth, newmeth|
+        # at the moment there's no way to introspect the deprecated methods
+        # to make sure they point to the new ones
+        # so let's just make sure both old and new methods exist
+        klass.should be_method_defined(oldmeth)
+        klass.should be_method_defined(newmeth)
+      end
+    end
+  end
+end

Modified: incubator/thrift/trunk/lib/rb/spec/spec_helper.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/spec/spec_helper.rb?rev=668942&r1=668941&r2=668942&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/spec/spec_helper.rb (original)
+++ incubator/thrift/trunk/lib/rb/spec/spec_helper.rb Tue Jun 17 18:05:17 2008
@@ -1,6 +1,11 @@
 require 'rubygems'
 require 'spec'
 
+# turn on deprecation so we can test it
+module Thrift
+  DEPRECATION = true
+end
+
 require File.dirname(__FILE__) + '/../lib/thrift'
 
 class Object