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