blob: 2ac3489dd97402cced865543cc6d46dcabf45265 [file] [log] [blame]
Kevin Clarkd47cd662008-06-18 01:05:17 +00001require File.dirname(__FILE__) + '/spec_helper'
2require 'thrift/protocol/binaryprotocol'
3require 'thrift/server/httpserver'
4require 'thrift/transport/httpclient'
5
6context "Backwards compatibility" do
7 specify "old class names should map to new classes" do
Kevin Clark28744ab2008-06-26 18:45:29 +00008 Thrift::DeprecationProxy.reset_deprecation_warnings
Kevin Clarkd47cd662008-06-18 01:05:17 +00009 # use an Array because a Hash will call #hash and trigger deprecation warnings
10 klasses = [
11 [:module, :ThriftClient, Thrift::Client],
12 [:class, :TException, Thrift::Exception],
13 [:class, :TApplicationException, Thrift::ApplicationException],
14 [:module, :TProcessor, Thrift::Processor],
Kevin Clark8d1918b2008-07-18 21:57:07 +000015 [:class, :TProtocolException, Thrift::ProtocolException],
Kevin Clarkd47cd662008-06-18 01:05:17 +000016 [:class, :TProtocol, Thrift::Protocol],
17 [:class, :TProtocolFactory, Thrift::ProtocolFactory],
18 [:class, :TBinaryProtocol, Thrift::BinaryProtocol],
19 [:class, :TBinaryProtocolFactory, Thrift::BinaryProtocolFactory],
20 [:class, :TSimpleMongrelHTTPServer, Thrift::SimpleMongrelHTTPServer],
21 [:class, :TServer, Thrift::Server],
22 [:class, :TSimpleServer, Thrift::SimpleServer],
23 [:class, :TThreadedServer, Thrift::ThreadedServer],
24 [:class, :TThreadPoolServer, Thrift::ThreadPoolServer],
25 [:module, :ThriftStruct, Thrift::Struct],
26 [:class, :THttpClient, Thrift::HTTPClient],
27 [:class, :TSocket, Thrift::Socket],
28 [:class, :TServerSocket, Thrift::ServerSocket],
29 [:class, :TTransportException, Thrift::TransportException],
30 [:class, :TTransport, Thrift::Transport],
31 [:class, :TServerTransport, Thrift::ServerTransport],
32 [:class, :TTransportFactory, Thrift::TransportFactory],
33 [:class, :TBufferedTransport, Thrift::BufferedTransport],
34 [:class, :TBufferedTransportFactory, Thrift::BufferedTransportFactory],
35 [:class, :TFramedTransport, Thrift::FramedTransport],
36 [:class, :TFramedTransportFactory, Thrift::FramedTransportFactory],
37 [:class, :TMemoryBuffer, Thrift::MemoryBuffer],
38 [:class, :TIOStreamTransport, Thrift::IOStreamTransport],
39 [:module, :TType, Thrift::Types],
40 [:module, :TMessageType, Thrift::MessageTypes]
41 ]
42 klasses.each do |(type, oldname, newklass)|
43 oldklass = Object.const_get(oldname)
44 STDERR.should_receive(:puts).with("Warning: #{type} #{oldname} is deprecated").ordered
45 STDERR.should_receive(:puts).with(" from #{__FILE__}:#{__LINE__+1}").ordered
46 oldklass.should eql(newklass)
47 STDERR.rspec_verify
48 STDERR.rspec_reset
49 end
50 end
51
52 specify "old method names should map to new method names" do
53 mapping = {
54 Thrift::Protocol => {
55 :writeMessageBegin => :write_message_begin,
56 :writeMessageEnd => :write_message_end,
57 :writeStructBegin => :write_struct_begin,
58 :writeStructEnd => :write_struct_end,
59 :writeFieldBegin => :write_field_begin,
60 :writeFieldEnd => :write_field_end,
61 :writeFieldStop => :write_field_stop,
62 :writeMapBegin => :write_map_begin,
63 :writeMapEnd => :write_map_end,
64 :writeListBegin => :write_list_begin,
65 :writeListEnd => :write_list_end,
66 :writeSetBegin => :write_set_begin,
67 :writeSetEnd => :write_set_end,
68 :writeBool => :write_bool,
69 :writeByte => :write_byte,
70 :writeI16 => :write_i16,
71 :writeI32 => :write_i32,
72 :writeI64 => :write_i64,
73 :writeDouble => :write_double,
74 :writeString => :write_string,
75 :readMessageBegin => :read_message_begin,
76 :readMessageEnd => :read_message_end,
77 :readStructBegin => :read_struct_begin,
78 :readStructEnd => :read_struct_end,
79 :readFieldBegin => :read_field_begin,
80 :readFieldEnd => :read_field_end,
81 :readMapBegin => :read_map_begin,
82 :readMapEnd => :read_map_end,
83 :readListBegin => :read_list_begin,
84 :readListEnd => :read_list_end,
85 :readSetBegin => :read_set_begin,
86 :readSetEnd => :read_set_end,
87 :readBool => :read_bool,
88 :readByte => :read_byte,
89 :readI16 => :read_i16,
90 :readI32 => :read_i32,
91 :readI64 => :read_i64,
92 :readDouble => :read_double,
93 :readString => :read_string
94 },
95 Thrift::ProtocolFactory => {
96 :getProtocol => :get_protocol
97 },
98 Thrift::Transport => {
99 :isOpen => :open?,
100 :is_open? => :open?,
101 :readAll => :read_all
102 },
103 Thrift::TransportFactory => {
104 :getTransport => :get_transport
105 }
106 }
Kevin Clark2e4f9d62008-06-18 01:16:50 +0000107 STDERR.stub!(:puts) # stub the deprecation warnings
Kevin Clarkd47cd662008-06-18 01:05:17 +0000108 mapping.each_pair do |klass, methods|
Kevin Clark2e4f9d62008-06-18 01:16:50 +0000109 # save these so they can be used after being mocked up
110 defn_method = klass.method(:define_method)
111 inst_method = klass.method(:instance_method)
Kevin Clarkd47cd662008-06-18 01:05:17 +0000112 methods.each_pair do |oldmeth, newmeth|
Kevin Clark2e4f9d62008-06-18 01:16:50 +0000113 # ensure that calling the old method will call the new method
114 # and then redefine the old method to be the new one
Kevin Clarkd47cd662008-06-18 01:05:17 +0000115 klass.should be_method_defined(oldmeth)
116 klass.should be_method_defined(newmeth)
Kevin Clark2e4f9d62008-06-18 01:16:50 +0000117 orig_method = inst_method.call(:initialize)
118 defn_method.call(:initialize, proc {} ) # stub out initialize
119 begin
120 mockmeth = mock("UnboundMethod: #{newmeth}")
121 mockmeth.should_receive(:bind).and_return do
122 mock("Method: #{newmeth}").tee do |meth|
123 meth.should_receive(:call)
124 end
125 end
126 klass.should_receive(:instance_method).with(newmeth).twice.and_return(mockmeth)
127 klass.should_receive(:define_method).with(oldmeth, mockmeth)
128 klass.new.send oldmeth
129 klass.rspec_verify
130 ensure
131 defn_method.call(:initialize, orig_method)
132 end
Kevin Clarkd47cd662008-06-18 01:05:17 +0000133 end
134 end
135 end
136end