From e8ae5d3728de07e880d6477db0f63ed9a7c65415 Mon Sep 17 00:00:00 2001 From: Bryan Duxbury Date: Tue, 24 Mar 2009 05:23:52 +0000 Subject: [PATCH] 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 --- lib/rb/lib/thrift.rb | 1 - lib/rb/lib/thrift/client.rb | 1 - lib/rb/lib/thrift/deprecation.rb | 174 ------- lib/rb/lib/thrift/exceptions.rb | 2 - lib/rb/lib/thrift/processor.rb | 1 - lib/rb/lib/thrift/protocol.rb | 47 +- lib/rb/lib/thrift/protocol/binaryprotocol.rb | 2 - lib/rb/lib/thrift/protocol/tbinaryprotocol.rb | 21 - lib/rb/lib/thrift/protocol/tprotocol.rb | 21 - lib/rb/lib/thrift/server.rb | 4 - lib/rb/lib/thrift/server/httpserver.rb | 1 - lib/rb/lib/thrift/server/thttpserver.rb | 21 - lib/rb/lib/thrift/server/tserver.rb | 21 - lib/rb/lib/thrift/struct.rb | 1 - lib/rb/lib/thrift/thrift.rb | 33 -- lib/rb/lib/thrift/transport.rb | 77 +-- lib/rb/lib/thrift/transport/httpclient.rb | 1 - lib/rb/lib/thrift/transport/socket.rb | 2 - lib/rb/lib/thrift/transport/thttpclient.rb | 21 - lib/rb/lib/thrift/transport/tsocket.rb | 21 - lib/rb/lib/thrift/transport/ttransport.rb | 21 - lib/rb/lib/thrift/types.rb | 2 - lib/rb/spec/backwards_compatibility_spec.rb | 136 ------ lib/rb/spec/deprecation_spec.rb | 446 ------------------ lib/rb/spec/protocol_spec.rb | 4 +- lib/rb/spec/transport_spec.rb | 34 -- test/rb/core/test_backwards_compatability.rb | 2 +- test/rb/core/test_exceptions.rb | 2 +- test/rb/core/transport/test_transport.rb | 4 - 29 files changed, 18 insertions(+), 1106 deletions(-) delete mode 100644 lib/rb/lib/thrift/deprecation.rb delete mode 100644 lib/rb/lib/thrift/protocol/tbinaryprotocol.rb delete mode 100644 lib/rb/lib/thrift/protocol/tprotocol.rb delete mode 100644 lib/rb/lib/thrift/server/thttpserver.rb delete mode 100644 lib/rb/lib/thrift/server/tserver.rb delete mode 100644 lib/rb/lib/thrift/thrift.rb delete mode 100644 lib/rb/lib/thrift/transport/thttpclient.rb delete mode 100644 lib/rb/lib/thrift/transport/tsocket.rb delete mode 100644 lib/rb/lib/thrift/transport/ttransport.rb delete mode 100644 lib/rb/spec/backwards_compatibility_spec.rb delete mode 100644 lib/rb/spec/deprecation_spec.rb diff --git a/lib/rb/lib/thrift.rb b/lib/rb/lib/thrift.rb index fef7045b..df447a04 100644 --- a/lib/rb/lib/thrift.rb +++ b/lib/rb/lib/thrift.rb @@ -24,7 +24,6 @@ module Thrift DEPRECATION = false unless const_defined? :DEPRECATION end -require 'thrift/deprecation' require 'thrift/exceptions' require 'thrift/types' require 'thrift/processor' diff --git a/lib/rb/lib/thrift/client.rb b/lib/rb/lib/thrift/client.rb index 5934eea3..5b30f015 100644 --- a/lib/rb/lib/thrift/client.rb +++ b/lib/rb/lib/thrift/client.rb @@ -59,5 +59,4 @@ module Thrift end end end - deprecate_module! :ThriftClient => Client end diff --git a/lib/rb/lib/thrift/deprecation.rb b/lib/rb/lib/thrift/deprecation.rb deleted file mode 100644 index 8b15a169..00000000 --- a/lib/rb/lib/thrift/deprecation.rb +++ /dev/null @@ -1,174 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -# provide a backwards-compatible wrapper API and deprecate it - -module Thrift - DEPRECATION = true unless const_defined?(:DEPRECATION) -end - -class Module - # Wraps the given methods to print a warning and call the real method - # Example: - # deprecate! :readAll => :read_all - #-- - # Yeah, this is ugly, passing a string to module_eval, but unfortunately - # using a block removes the ability to pass blocks to the defined method - # and breaks spec - def deprecate!(methods) - return unless Thrift::DEPRECATION - methods.each_pair do |old, new| - module_eval <<-EOF - def #{old}(*args, &block) - old, new = #{[old,new].inspect} - STDERR.puts "Warning: calling deprecated method \#{self.is_a?(Module) ? "\#{self}." : "\#{self.class}#"}\#{old}" - STDERR.puts " from \#{caller.first}" - target = (self.is_a?(Module) ? (class << self;self;end) : self.class) - target.send :define_method, old, target.instance_method(new) # unwrap - target.instance_method(new).bind(self).call(*args, &block) - end - EOF - end - end -end - -module Thrift::DeprecationProxy # :nodoc: - # there's a really weird bug in Ruby where class variables behave wrong - # when used in a Class.new or #class_eval rather than in a class foo block. - CLASS_MAPPING = {} - MODULE_MAPPING = {} - def self.new_class(obj, name) - klass_id = CLASS_MAPPING.size - CLASS_MAPPING[klass_id] = [obj, name, true] - klass = Class.new(obj) do - klass = self - instance_methods.sort.reject { |x| [:__id__,:__send__].include? x.to_sym }.each do |sym| - undef_method sym - end - define_method :__thrift_deprecation_proxy_klass_id do - klass_id - end - def method_missing(sym, *args, &block) - klass_id = __thrift_deprecation_proxy_klass_id - obj, name, warned = CLASS_MAPPING[klass_id] - obj.instance_method(sym).bind(self).call(*args, &block) - end - (class << self;self;end).class_eval do - instance_methods.sort.reject { |x| [:__id__,:__send__].include? x.to_sym }.each do |sym| - undef_method sym - end - define_method :__thrift_deprecation_proxy_klass do - [klass, klass_id] - end - def method_missing(sym, *args, &block) - klass, klass_id = __thrift_deprecation_proxy_klass - obj, name, warned = CLASS_MAPPING[klass_id] - unless warned - STDERR.puts "Warning: class #{name} is deprecated" - STDERR.puts " from #{Thrift::DeprecationProxy.process_caller(caller)}" - CLASS_MAPPING[klass_id][2] = true - end - if klass.__id__ == self.__id__ - obj.send sym, *args, &block - else - obj.method(sym).unbind.bind(self).call(*args, &block) - end - end - end - end - CLASS_MAPPING[klass_id][2] = false - klass - end - def self.new_module(obj, name) - mod_id = MODULE_MAPPING.size - MODULE_MAPPING[mod_id] = [obj, name, true] - mod = Module.new do - include obj - instance_methods.sort.reject { |x| [:__id__,:__send__].include? x.to_sym }.each do |sym| - undef_method sym - end - define_method :__thrift_deprecation_proxy_module_id do - mod_id - end - def method_missing(sym, *args, &block) - mod_id = __thrift_deprecation_proxy_module_id - obj, name, warned = MODULE_MAPPING[mod_id] - unless warned - STDERR.puts "Warning: module #{name} is deprecated" - STDERR.puts " from #{Thrift::DeprecationProxy.process_caller(caller)}" - MODULE_MAPPING[mod_id][2] = true - end - obj.instance_method(sym).bind(self).call(*args, &block) - end - (class << self;self;end).class_eval do - instance_methods.sort.reject { |x| [:__id__,:__send__].include? x.to_sym }.each do |sym| - undef_method sym - end - define_method :__thrift_deprecation_proxy_module_id do - mod_id - end - def method_missing(sym, *args, &block) - mod_id = __thrift_deprecation_proxy_module_id - obj, name, warned = MODULE_MAPPING[mod_id] - unless warned - STDERR.puts "Warning: module #{name} is deprecated" - STDERR.puts " from #{Thrift::DeprecationProxy.process_caller(caller)}" - MODULE_MAPPING[mod_id][2] = true - end - obj.send sym, *args, &block - end - end - end - MODULE_MAPPING[mod_id][2] = false - mod - end - def self.process_caller(stack) - dir = File.dirname(__FILE__) - stack.find { |frame| frame[0,dir.size] != dir } - end - def self.reset_deprecation_warnings - CLASS_MAPPING.each { |k,v| v[2] = false } - MODULE_MAPPING.each { |k,v| v[2] = false } - end -end - -module Kernel - # Provides an alternate name for the class for deprecation purposes - # Example: - # deprecate_class! :TBinaryProtocol => Thrift::BinaryProtocol - #-- - # at the moment this only works for creating top-level constants - # if necessary, this can be extended to take something like :'Thrift::TBinaryProtocol' - # alternately, Module can be extended with a similar method - def deprecate_class!(klasses) - return unless Thrift::DEPRECATION - klasses.each_pair do |old, new| - raise "deprecate_class! expected Class, called with #{new}" unless new.is_a? Class - Object.const_set old, Thrift::DeprecationProxy.new_class(new, old) - end - end - - # like deprecate_class! but for Modules - def deprecate_module!(modules) - return unless Thrift::DEPRECATION - modules.each_pair do |old, new| - Object.const_set old, Thrift::DeprecationProxy.new_module(new, old) - end - end -end diff --git a/lib/rb/lib/thrift/exceptions.rb b/lib/rb/lib/thrift/exceptions.rb index 90afe8eb..dda70894 100644 --- a/lib/rb/lib/thrift/exceptions.rb +++ b/lib/rb/lib/thrift/exceptions.rb @@ -26,7 +26,6 @@ module Thrift attr_reader :message end - deprecate_class! :TException => Exception class ApplicationException < Exception @@ -80,5 +79,4 @@ module Thrift end end - deprecate_class! :TApplicationException => ApplicationException end \ No newline at end of file diff --git a/lib/rb/lib/thrift/processor.rb b/lib/rb/lib/thrift/processor.rb index 4ec819a3..5d9e0a11 100644 --- a/lib/rb/lib/thrift/processor.rb +++ b/lib/rb/lib/thrift/processor.rb @@ -54,5 +54,4 @@ module Thrift oprot.trans.flush end end - deprecate_module! :TProcessor => Processor end diff --git a/lib/rb/lib/thrift/protocol.rb b/lib/rb/lib/thrift/protocol.rb index e5ae4aaa..adeddefd 100644 --- a/lib/rb/lib/thrift/protocol.rb +++ b/lib/rb/lib/thrift/protocol.rb @@ -37,7 +37,6 @@ module Thrift end end - deprecate_class! :TProtocolException => ProtocolException class Protocol @@ -55,173 +54,134 @@ module Thrift def write_message_begin(name, type, seqid) raise NotImplementedError end - deprecate! :writeMessageBegin => :write_message_begin def write_message_end; nil; end - deprecate! :writeMessageEnd => :write_message_end def write_struct_begin(name) raise NotImplementedError end - deprecate! :writeStructBegin => :write_struct_begin def write_struct_end; nil; end - deprecate! :writeStructEnd => :write_struct_end def write_field_begin(name, type, id) raise NotImplementedError end - deprecate! :writeFieldBegin => :write_field_begin def write_field_end; nil; end - deprecate! :writeFieldEnd => :write_field_end def write_field_stop raise NotImplementedError end - deprecate! :writeFieldStop => :write_field_stop def write_map_begin(ktype, vtype, size) raise NotImplementedError end - deprecate! :writeMapBegin => :write_map_begin def write_map_end; nil; end - deprecate! :writeMapEnd => :write_map_end def write_list_begin(etype, size) raise NotImplementedError end - deprecate! :writeListBegin => :write_list_begin def write_list_end; nil; end - deprecate! :writeListEnd => :write_list_end def write_set_begin(etype, size) raise NotImplementedError end - deprecate! :writeSetBegin => :write_set_begin def write_set_end; nil; end - deprecate! :writeSetEnd => :write_set_end def write_bool(bool) raise NotImplementedError end - deprecate! :writeBool => :write_bool def write_byte(byte) raise NotImplementedError end - deprecate! :writeByte => :write_byte def write_i16(i16) raise NotImplementedError end - deprecate! :writeI16 => :write_i16 def write_i32(i32) raise NotImplementedError end - deprecate! :writeI32 => :write_i32 def write_i64(i64) raise NotImplementedError end - deprecate! :writeI64 => :write_i64 def write_double(dub) raise NotImplementedError end - deprecate! :writeDouble => :write_double def write_string(str) raise NotImplementedError end - deprecate! :writeString => :write_string def read_message_begin raise NotImplementedError end - deprecate! :readMessageBegin => :read_message_begin def read_message_end; nil; end - deprecate! :readMessageEnd => :read_message_end def read_struct_begin raise NotImplementedError end - deprecate! :readStructBegin => :read_struct_begin def read_struct_end; nil; end - deprecate! :readStructEnd => :read_struct_end def read_field_begin raise NotImplementedError end - deprecate! :readFieldBegin => :read_field_begin def read_field_end; nil; end - deprecate! :readFieldEnd => :read_field_end def read_map_begin raise NotImplementedError end - deprecate! :readMapBegin => :read_map_begin def read_map_end; nil; end - deprecate! :readMapEnd => :read_map_end def read_list_begin raise NotImplementedError end - deprecate! :readListBegin => :read_list_begin def read_list_end; nil; end - deprecate! :readListEnd => :read_list_end def read_set_begin raise NotImplementedError end - deprecate! :readSetBegin => :read_set_begin def read_set_end; nil; end - deprecate! :readSetEnd => :read_set_end def read_bool raise NotImplementedError end - deprecate! :readBool => :read_bool def read_byte raise NotImplementedError end - deprecate! :readByte => :read_byte def read_i16 raise NotImplementedError end - deprecate! :readI16 => :read_i16 def read_i32 raise NotImplementedError end - deprecate! :readI32 => :read_i32 def read_i64 raise NotImplementedError end - deprecate! :readI64 => :read_i64 def read_double raise NotImplementedError end - deprecate! :readDouble => :read_double def read_string raise NotImplementedError end - deprecate! :readString => :read_string def write_field(name, type, fid, value) write_field_begin(name, type, fid) @@ -323,11 +283,10 @@ module Thrift end end - deprecate_class! :TProtocol => Protocol class ProtocolFactory - def get_protocol(trans); nil; end - deprecate! :getProtocol => :get_protocol + def get_protocol(trans) + raise NotImplementedError + end end - deprecate_class! :TProtocolFactory => ProtocolFactory end diff --git a/lib/rb/lib/thrift/protocol/binaryprotocol.rb b/lib/rb/lib/thrift/protocol/binaryprotocol.rb index 9a7a6012..dd963f2c 100644 --- a/lib/rb/lib/thrift/protocol/binaryprotocol.rb +++ b/lib/rb/lib/thrift/protocol/binaryprotocol.rb @@ -216,12 +216,10 @@ module Thrift end end - deprecate_class! :TBinaryProtocol => BinaryProtocol class BinaryProtocolFactory < ProtocolFactory def get_protocol(trans) return Thrift::BinaryProtocol.new(trans) end end - deprecate_class! :TBinaryProtocolFactory => BinaryProtocolFactory end diff --git a/lib/rb/lib/thrift/protocol/tbinaryprotocol.rb b/lib/rb/lib/thrift/protocol/tbinaryprotocol.rb deleted file mode 100644 index 32211b78..00000000 --- a/lib/rb/lib/thrift/protocol/tbinaryprotocol.rb +++ /dev/null @@ -1,21 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -require 'thrift/deprecation' -require 'thrift/protocol/binaryprotocol' diff --git a/lib/rb/lib/thrift/protocol/tprotocol.rb b/lib/rb/lib/thrift/protocol/tprotocol.rb deleted file mode 100644 index 2bd1de75..00000000 --- a/lib/rb/lib/thrift/protocol/tprotocol.rb +++ /dev/null @@ -1,21 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -require 'thrift/deprecation' -require 'thrift/protocol' diff --git a/lib/rb/lib/thrift/server.rb b/lib/rb/lib/thrift/server.rb index 841a3fc1..bd428549 100644 --- a/lib/rb/lib/thrift/server.rb +++ b/lib/rb/lib/thrift/server.rb @@ -32,7 +32,6 @@ module Thrift def serve; nil; end end - deprecate_class! :TServer => Server class SimpleServer < Server def serve @@ -56,7 +55,6 @@ module Thrift end end end - deprecate_class! :TSimpleServer => SimpleServer end # do *not* use fastthread @@ -88,7 +86,6 @@ module Thrift end end end - deprecate_class! :TThreadedServer => ThreadedServer class ThreadPoolServer < Server def initialize(processor, serverTransport, transportFactory=nil, protocolFactory=nil, num=20) @@ -142,5 +139,4 @@ module Thrift end end end - deprecate_class! :TThreadPoolServer => ThreadPoolServer end diff --git a/lib/rb/lib/thrift/server/httpserver.rb b/lib/rb/lib/thrift/server/httpserver.rb index c75d631c..f26329f4 100644 --- a/lib/rb/lib/thrift/server/httpserver.rb +++ b/lib/rb/lib/thrift/server/httpserver.rb @@ -59,5 +59,4 @@ module Thrift @server.run.join end end - deprecate_class! :TSimpleMongrelHTTPServer => SimpleMongrelHTTPServer end diff --git a/lib/rb/lib/thrift/server/thttpserver.rb b/lib/rb/lib/thrift/server/thttpserver.rb deleted file mode 100644 index f0abf0d3..00000000 --- a/lib/rb/lib/thrift/server/thttpserver.rb +++ /dev/null @@ -1,21 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -require 'thrift/deprecation' -require 'thrift/server/httpserver' diff --git a/lib/rb/lib/thrift/server/tserver.rb b/lib/rb/lib/thrift/server/tserver.rb deleted file mode 100644 index 4066d425..00000000 --- a/lib/rb/lib/thrift/server/tserver.rb +++ /dev/null @@ -1,21 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -require 'thrift/deprecation' -require 'thrift/server' diff --git a/lib/rb/lib/thrift/struct.rb b/lib/rb/lib/thrift/struct.rb index 625badf2..9789a41e 100644 --- a/lib/rb/lib/thrift/struct.rb +++ b/lib/rb/lib/thrift/struct.rb @@ -292,5 +292,4 @@ module Thrift :element => field[:element] } end end - deprecate_module! :ThriftStruct => Struct end diff --git a/lib/rb/lib/thrift/thrift.rb b/lib/rb/lib/thrift/thrift.rb deleted file mode 100644 index cb5581c7..00000000 --- a/lib/rb/lib/thrift/thrift.rb +++ /dev/null @@ -1,33 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -# This file kept for backwards compatability -# require File.join(File.dirname(__FILE__), '../thrift') -$:.unshift File.dirname(File.dirname(__FILE__)) -require 'thrift/deprecation' -require 'thrift/types' -require 'thrift/processor' -require 'thrift/exceptions' -require 'thrift/client' -require 'thrift/struct' -begin - require "thrift_native" -rescue - puts "Could not load thrift_native libraries. Using pure ruby version." -end \ No newline at end of file diff --git a/lib/rb/lib/thrift/transport.rb b/lib/rb/lib/thrift/transport.rb index 00c5bee0..6c75ce86 100644 --- a/lib/rb/lib/thrift/transport.rb +++ b/lib/rb/lib/thrift/transport.rb @@ -32,15 +32,10 @@ module Thrift @type = type end end - deprecate_class! :TTransportException => TransportException -# Transport is basically an abstract class, but isn't raising NotImplementedError -# TODO: Think about if this is the right thing - Kevin Clark - 3/27/08 class Transport def open?; end - deprecate! :isOpen => :open? - deprecate! :is_open? => :open? - + def open; end def close; end @@ -59,33 +54,34 @@ module Thrift buf end - deprecate! :readAll => :read_all def write(buf); end alias_method :<<, :write def flush; end end - deprecate_class! :TTransport => Transport class ServerTransport - def listen; nil; end - - def accept; nil; end + def listen + raise NotImplementedError + end + def accept + raise NotImplementedError + end + def close; nil; end - def closed?; nil; end + def closed? + raise NotImplementedError + end end - deprecate_class! :TServerTransport => ServerTransport class TransportFactory def get_transport(trans) return trans end - deprecate! :getTransport => :get_transport end - deprecate_class! :TTransportFactory => TransportFactory class BufferedTransport < Transport DEFAULT_BUFFER = 4096 @@ -131,34 +127,13 @@ module Thrift @transport.flush end - - def borrow(requested_length = 0) - # $stderr.puts "#{Time.now.to_f} Have #{@rbuf.length} asking for #{requested_length.inspect}" - return @rbuf if @rbuf.length > requested_length - - if @rbuf.length < DEFAULT_BUFFER - @rbuf << @transport.read([requested_length, DEFAULT_BUFFER].max) - end - - if @rbuf.length < requested_length - @rbuf << @transport.read_all(requested_length - @rbuf.length) - end - - @rbuf - end - - def consume!(size) - @rbuf.slice!(0...size) - end end - deprecate_class! :TBufferedTransport => BufferedTransport class BufferedTransportFactory < TransportFactory def get_transport(transport) return BufferedTransport.new(transport) end end - deprecate_class! :TBufferedTransportFactory => BufferedTransportFactory class FramedTransport < Transport def initialize(transport, read=true, write=true) @@ -211,17 +186,6 @@ module Thrift @wbuf = '' end - def borrow(requested_length = 0) - read_frame if @rbuf.empty? - # there isn't any more coming, so if it's not enough, it's an error. - raise EOFError if requested_length > @rbuf.size - @rbuf - end - - def consume!(size) - @rbuf.slice!(0...size) - end - private def read_frame @@ -230,14 +194,12 @@ module Thrift @rbuf = @transport.read_all(sz).dup # protect against later #slice! end end - deprecate_class! :TFramedTransport => FramedTransport class FramedTransportFactory < TransportFactory def get_transport(transport) return FramedTransport.new(transport) end end - deprecate_class! :TFramedTransportFactory => FramedTransportFactory class MemoryBuffer < Transport GARBAGE_BUFFER_SIZE = 4*(2**10) # 4kB @@ -294,19 +256,6 @@ module Thrift def flush end - # For fast binary protocol access - def borrow(size = nil) - if size.nil? - @buf[@index..-1] - else - if size > available - raise EOFError # Memory buffers only get one shot. - else - @buf[@index, size] - end - end - end - def inspect_buffer out = [] for idx in 0...(@buf.size) @@ -322,10 +271,7 @@ module Thrift end out.join(" ") end - - alias_method :consume!, :read end - deprecate_class! :TMemoryBuffer => MemoryBuffer ## Very very simple implementation of wrapping two objects, one with a #read ## method and one with a #write method, into a transport for thrift. @@ -343,5 +289,4 @@ module Thrift def close; @input.close; @output.close end def to_io; @input end # we're assuming this is used in a IO.select for reading end - deprecate_class! :TIOStreamTransport => IOStreamTransport end diff --git a/lib/rb/lib/thrift/transport/httpclient.rb b/lib/rb/lib/thrift/transport/httpclient.rb index b6b1e94a..8a62ca20 100644 --- a/lib/rb/lib/thrift/transport/httpclient.rb +++ b/lib/rb/lib/thrift/transport/httpclient.rb @@ -44,5 +44,4 @@ module Thrift @outbuf = "" end end - deprecate_class! :THttpClient => HTTPClient end diff --git a/lib/rb/lib/thrift/transport/socket.rb b/lib/rb/lib/thrift/transport/socket.rb index d4ba3a74..49247ce4 100644 --- a/lib/rb/lib/thrift/transport/socket.rb +++ b/lib/rb/lib/thrift/transport/socket.rb @@ -132,7 +132,6 @@ module Thrift @handle end end - deprecate_class! :TSocket => Socket class ServerSocket < ServerTransport # call-seq: initialize(host = nil, port) @@ -173,5 +172,4 @@ module Thrift alias to_io handle end - deprecate_class! :TServerSocket => ServerSocket end diff --git a/lib/rb/lib/thrift/transport/thttpclient.rb b/lib/rb/lib/thrift/transport/thttpclient.rb deleted file mode 100644 index 9bb42562..00000000 --- a/lib/rb/lib/thrift/transport/thttpclient.rb +++ /dev/null @@ -1,21 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -require 'thrift/deprecation' -require 'thrift/transport/httpclient' diff --git a/lib/rb/lib/thrift/transport/tsocket.rb b/lib/rb/lib/thrift/transport/tsocket.rb deleted file mode 100644 index e58fedd8..00000000 --- a/lib/rb/lib/thrift/transport/tsocket.rb +++ /dev/null @@ -1,21 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -require 'thrift/deprecation' -require 'thrift/transport/socket' diff --git a/lib/rb/lib/thrift/transport/ttransport.rb b/lib/rb/lib/thrift/transport/ttransport.rb deleted file mode 100644 index 4b74ed06..00000000 --- a/lib/rb/lib/thrift/transport/ttransport.rb +++ /dev/null @@ -1,21 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -require 'thrift/deprecation' -require 'thrift/transport' diff --git a/lib/rb/lib/thrift/types.rb b/lib/rb/lib/thrift/types.rb index 6d027ce4..6d70eb58 100644 --- a/lib/rb/lib/thrift/types.rb +++ b/lib/rb/lib/thrift/types.rb @@ -35,7 +35,6 @@ module Thrift SET = 14 LIST = 15 end - deprecate_module! :TType => Types class << self attr_accessor :type_checking @@ -96,7 +95,6 @@ module Thrift REPLY = 2 EXCEPTION = 3 end - deprecate_module! :TMessageType => MessageTypes end Thrift.type_checking = false if Thrift.type_checking.nil? diff --git a/lib/rb/spec/backwards_compatibility_spec.rb b/lib/rb/spec/backwards_compatibility_spec.rb deleted file mode 100644 index 2ac3489d..00000000 --- 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 00745282..00000000 --- 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 a681cd87..1db4e19f 100644 --- a/lib/rb/spec/protocol_spec.rb +++ b/lib/rb/spec/protocol_spec.rb @@ -134,9 +134,9 @@ class ThriftProtocolSpec < Spec::ExampleGroup 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 ef1918fb..98408abb 100644 --- a/lib/rb/spec/transport_spec.rb +++ b/lib/rb/spec/transport_spec.rb @@ -221,40 +221,6 @@ class ThriftTransportSpec < Spec::ExampleGroup @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 diff --git a/test/rb/core/test_backwards_compatability.rb b/test/rb/core/test_backwards_compatability.rb index 2e5330d5..eda1ec4b 100644 --- a/test/rb/core/test_backwards_compatability.rb +++ b/test/rb/core/test_backwards_compatability.rb @@ -1,6 +1,6 @@ require File.join(File.dirname(__FILE__), '../test_helper') -require 'thrift/thrift' +require 'thrift' class TestThriftException < Test::Unit::TestCase def test_has_accessible_message diff --git a/test/rb/core/test_exceptions.rb b/test/rb/core/test_exceptions.rb index 88aacb0b..8488baa4 100644 --- a/test/rb/core/test_exceptions.rb +++ b/test/rb/core/test_exceptions.rb @@ -1,6 +1,6 @@ require File.join(File.dirname(__FILE__), '../test_helper') -require 'thrift/thrift' +require 'thrift' class TestException < Test::Unit::TestCase def test_has_accessible_message diff --git a/test/rb/core/transport/test_transport.rb b/test/rb/core/transport/test_transport.rb index 7a62e5a3..1cf001ff 100644 --- a/test/rb/core/transport/test_transport.rb +++ b/test/rb/core/transport/test_transport.rb @@ -30,10 +30,6 @@ class TestThriftTransport < Test::Unit::TestCase assert_nil @trans.close end - def test_read - assert_nil @trans.read(100) # arbitrary size - end - # TODO: # This doesn't necessarily test he right thing. # It _looks_ like read isn't guarenteed to return the length -- 2.17.1