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