thrift 0.0.751142 → 0.0.810255.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +3 -1
- data/Manifest +47 -44
- data/README +19 -6
- data/Rakefile +1 -1
- data/benchmark/Benchmark.thrift +19 -0
- data/benchmark/benchmark.rb +20 -3
- data/benchmark/client.rb +20 -2
- data/benchmark/server.rb +22 -4
- data/benchmark/thin_server.rb +22 -4
- data/ext/binary_protocol_accelerated.c +32 -21
- data/ext/binary_protocol_accelerated.h +19 -0
- data/ext/compact_protocol.c +665 -0
- data/ext/compact_protocol.h +20 -0
- data/ext/constants.h +19 -1
- data/ext/extconf.rb +19 -0
- data/ext/macros.h +41 -0
- data/ext/memory_buffer.c +29 -5
- data/ext/memory_buffer.h +19 -0
- data/ext/protocol.c +20 -1
- data/ext/protocol.h +19 -0
- data/ext/struct.c +115 -83
- data/ext/struct.h +19 -0
- data/ext/thrift_native.c +23 -2
- data/lib/thrift/client.rb +19 -1
- data/lib/thrift/core_ext/fixnum.rb +29 -0
- data/lib/thrift/core_ext.rb +23 -0
- data/lib/thrift/exceptions.rb +19 -2
- data/lib/thrift/processor.rb +19 -1
- data/lib/thrift/protocol/base_protocol.rb +290 -0
- data/lib/thrift/protocol/{binaryprotocol.rb → binary_protocol.rb} +27 -15
- data/lib/thrift/protocol/binary_protocol_accelerated.rb +35 -0
- data/lib/thrift/protocol/compact_protocol.rb +422 -0
- data/lib/thrift/serializer/deserializer.rb +33 -0
- data/lib/thrift/serializer/serializer.rb +34 -0
- data/lib/thrift/server/base_server.rb +31 -0
- data/lib/thrift/server/{httpserver.rb → mongrel_http_server.rb} +19 -5
- data/lib/thrift/server/{nonblockingserver.rb → nonblocking_server.rb} +42 -24
- data/lib/thrift/server/simple_server.rb +43 -0
- data/lib/thrift/server/thread_pool_server.rb +75 -0
- data/lib/thrift/server/threaded_server.rb +47 -0
- data/lib/thrift/struct.rb +73 -47
- data/lib/thrift/thrift_native.rb +24 -0
- data/lib/thrift/transport/base_server_transport.rb +37 -0
- data/lib/thrift/transport/base_transport.rb +70 -0
- data/lib/thrift/transport/buffered_transport.rb +77 -0
- data/lib/thrift/transport/framed_transport.rb +90 -0
- data/lib/thrift/transport/http_client_transport.rb +45 -0
- data/lib/thrift/transport/io_stream_transport.rb +39 -0
- data/lib/thrift/transport/memory_buffer_transport.rb +96 -0
- data/lib/thrift/transport/server_socket.rb +63 -0
- data/lib/thrift/transport/socket.rb +22 -53
- data/lib/thrift/transport/unix_server_socket.rb +60 -0
- data/lib/thrift/transport/unix_socket.rb +40 -0
- data/lib/thrift/types.rb +20 -2
- data/lib/thrift.rb +50 -19
- data/script/proto_benchmark.rb +121 -0
- data/script/read_struct.rb +43 -0
- data/script/write_struct.rb +30 -0
- data/spec/ThriftSpec.thrift +40 -2
- data/spec/{protocol_spec.rb → base_protocol_spec.rb} +25 -7
- data/spec/{transport_spec.rb → base_transport_spec.rb} +44 -52
- data/spec/binary_protocol_accelerated_spec.rb +41 -0
- data/spec/{binaryprotocol_spec.rb → binary_protocol_spec.rb} +20 -2
- data/spec/{binaryprotocol_spec_shared.rb → binary_protocol_spec_shared.rb} +117 -16
- data/spec/client_spec.rb +23 -4
- data/spec/compact_protocol_spec.rb +117 -0
- data/spec/exception_spec.rb +19 -0
- data/spec/http_client_spec.rb +49 -0
- data/spec/{httpserver_spec.rb → mongrel_http_server_spec.rb} +26 -7
- data/spec/{nonblockingserver_spec.rb → nonblocking_server_spec.rb} +25 -5
- data/spec/processor_spec.rb +19 -0
- data/spec/serializer_spec.rb +27 -10
- data/spec/server_socket_spec.rb +80 -0
- data/spec/server_spec.rb +35 -16
- data/spec/socket_spec.rb +19 -55
- data/spec/socket_spec_shared.rb +19 -0
- data/spec/spec_helper.rb +34 -9
- data/spec/struct_spec.rb +26 -18
- data/spec/types_spec.rb +19 -1
- data/spec/{unixsocket_spec.rb → unix_socket_spec.rb} +19 -1
- data/thrift.gemspec +6 -6
- data.tar.gz.sig +0 -0
- metadata +80 -70
- metadata.gz.sig +0 -0
- data/COPYING +0 -14
- data/LICENSE +0 -14
- data/Makefile.am +0 -15
- data/benchmark/gen-rb/BenchmarkService.rb +0 -81
- data/benchmark/gen-rb/Benchmark_constants.rb +0 -11
- data/benchmark/gen-rb/Benchmark_types.rb +0 -10
- data/lib/thrift/deprecation.rb +0 -155
- data/lib/thrift/protocol/binaryprotocolaccelerated.rb +0 -19
- data/lib/thrift/protocol/tbinaryprotocol.rb +0 -2
- data/lib/thrift/protocol/tprotocol.rb +0 -2
- data/lib/thrift/protocol.rb +0 -270
- data/lib/thrift/serializer.rb +0 -27
- data/lib/thrift/server/thttpserver.rb +0 -2
- data/lib/thrift/server/tserver.rb +0 -2
- data/lib/thrift/server.rb +0 -135
- data/lib/thrift/thrift.rb +0 -14
- data/lib/thrift/transport/httpclient.rb +0 -29
- data/lib/thrift/transport/thttpclient.rb +0 -2
- data/lib/thrift/transport/tsocket.rb +0 -2
- data/lib/thrift/transport/ttransport.rb +0 -2
- data/lib/thrift/transport/unixsocket.rb +0 -58
- data/lib/thrift/transport.rb +0 -319
- data/spec/backwards_compatibility_spec.rb +0 -136
- data/spec/binaryprotocolaccelerated_spec.rb +0 -101
- data/spec/deprecation_spec.rb +0 -443
- data/spec/gen-rb/NonblockingService.rb +0 -268
- data/spec/gen-rb/ThriftSpec_constants.rb +0 -11
- data/spec/gen-rb/ThriftSpec_types.rb +0 -134
- data/spec/httpclient_spec.rb +0 -31
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'thrift/transport'
|
2
|
-
require 'socket'
|
3
|
-
|
4
|
-
module Thrift
|
5
|
-
class UNIXSocket < Socket
|
6
|
-
def initialize(path, timeout=nil)
|
7
|
-
@path = path
|
8
|
-
@timeout = timeout
|
9
|
-
@desc = @path # for read()'s error
|
10
|
-
@handle = nil
|
11
|
-
end
|
12
|
-
|
13
|
-
def open
|
14
|
-
begin
|
15
|
-
@handle = ::UNIXSocket.new(@path)
|
16
|
-
rescue StandardError
|
17
|
-
raise TransportException.new(TransportException::NOT_OPEN, "Could not open UNIX socket at #{@path}")
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
class UNIXServerSocket < ServerTransport
|
23
|
-
def initialize(path)
|
24
|
-
@path = path
|
25
|
-
@handle = nil
|
26
|
-
end
|
27
|
-
|
28
|
-
attr_accessor :handle
|
29
|
-
|
30
|
-
def listen
|
31
|
-
@handle = ::UNIXServer.new(@path)
|
32
|
-
end
|
33
|
-
|
34
|
-
def accept
|
35
|
-
unless @handle.nil?
|
36
|
-
sock = @handle.accept
|
37
|
-
trans = UNIXSocket.new(nil)
|
38
|
-
trans.handle = sock
|
39
|
-
trans
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def close
|
44
|
-
if @handle
|
45
|
-
@handle.close unless @handle.closed?
|
46
|
-
@handle = nil
|
47
|
-
# UNIXServer doesn't delete the socket file, so we have to do it ourselves
|
48
|
-
File.delete(@path)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def closed?
|
53
|
-
@handle.nil? or @handle.closed?
|
54
|
-
end
|
55
|
-
|
56
|
-
alias to_io handle
|
57
|
-
end
|
58
|
-
end
|
data/lib/thrift/transport.rb
DELETED
@@ -1,319 +0,0 @@
|
|
1
|
-
# Copyright (c) 2006- Facebook
|
2
|
-
# Distributed under the Apache Software License
|
3
|
-
#
|
4
|
-
# See accompanying file LICENSE or visit the Thrift site at:
|
5
|
-
# http://developers.facebook.com/thrift/
|
6
|
-
#
|
7
|
-
# Author: Mark Slee <mcslee@facebook.com>
|
8
|
-
#
|
9
|
-
|
10
|
-
module Thrift
|
11
|
-
class TransportException < Exception
|
12
|
-
UNKNOWN = 0
|
13
|
-
NOT_OPEN = 1
|
14
|
-
ALREADY_OPEN = 2
|
15
|
-
TIMED_OUT = 3
|
16
|
-
END_OF_FILE = 4
|
17
|
-
|
18
|
-
attr_reader :type
|
19
|
-
|
20
|
-
def initialize(type=UNKNOWN, message=nil)
|
21
|
-
super(message)
|
22
|
-
@type = type
|
23
|
-
end
|
24
|
-
end
|
25
|
-
deprecate_class! :TTransportException => TransportException
|
26
|
-
|
27
|
-
# Transport is basically an abstract class, but isn't raising NotImplementedError
|
28
|
-
# TODO: Think about if this is the right thing - Kevin Clark - 3/27/08
|
29
|
-
class Transport
|
30
|
-
def open?; end
|
31
|
-
deprecate! :isOpen => :open?
|
32
|
-
deprecate! :is_open? => :open?
|
33
|
-
|
34
|
-
def open; end
|
35
|
-
|
36
|
-
def close; end
|
37
|
-
|
38
|
-
def read(sz); end
|
39
|
-
|
40
|
-
def read_all(size)
|
41
|
-
buf = ''
|
42
|
-
|
43
|
-
while (buf.length < size)
|
44
|
-
chunk = read(size - buf.length)
|
45
|
-
buf << chunk
|
46
|
-
end
|
47
|
-
|
48
|
-
buf
|
49
|
-
end
|
50
|
-
deprecate! :readAll => :read_all
|
51
|
-
|
52
|
-
def write(buf); end
|
53
|
-
alias_method :<<, :write
|
54
|
-
|
55
|
-
def flush; end
|
56
|
-
end
|
57
|
-
deprecate_class! :TTransport => Transport
|
58
|
-
|
59
|
-
class ServerTransport
|
60
|
-
def listen; nil; end
|
61
|
-
|
62
|
-
def accept; nil; end
|
63
|
-
|
64
|
-
def close; nil; end
|
65
|
-
|
66
|
-
def closed?; nil; end
|
67
|
-
end
|
68
|
-
deprecate_class! :TServerTransport => ServerTransport
|
69
|
-
|
70
|
-
class TransportFactory
|
71
|
-
def get_transport(trans)
|
72
|
-
return trans
|
73
|
-
end
|
74
|
-
deprecate! :getTransport => :get_transport
|
75
|
-
end
|
76
|
-
deprecate_class! :TTransportFactory => TransportFactory
|
77
|
-
|
78
|
-
class BufferedTransport < Transport
|
79
|
-
DEFAULT_BUFFER = 4096
|
80
|
-
|
81
|
-
def initialize(transport)
|
82
|
-
@transport = transport
|
83
|
-
@wbuf = ''
|
84
|
-
@rbuf = ''
|
85
|
-
end
|
86
|
-
|
87
|
-
def open?
|
88
|
-
return @transport.open?
|
89
|
-
end
|
90
|
-
|
91
|
-
def open
|
92
|
-
@transport.open
|
93
|
-
end
|
94
|
-
|
95
|
-
def close
|
96
|
-
flush
|
97
|
-
@transport.close
|
98
|
-
end
|
99
|
-
|
100
|
-
def read(sz)
|
101
|
-
ret = @rbuf.slice!(0...sz)
|
102
|
-
if ret.length == 0
|
103
|
-
@rbuf = @transport.read([sz, DEFAULT_BUFFER].max)
|
104
|
-
@rbuf.slice!(0...sz)
|
105
|
-
else
|
106
|
-
ret
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
def write(buf)
|
111
|
-
@wbuf << buf
|
112
|
-
end
|
113
|
-
|
114
|
-
def flush
|
115
|
-
if @wbuf != ''
|
116
|
-
@transport.write(@wbuf)
|
117
|
-
@wbuf = ''
|
118
|
-
end
|
119
|
-
|
120
|
-
@transport.flush
|
121
|
-
end
|
122
|
-
|
123
|
-
def borrow(requested_length = 0)
|
124
|
-
# $stderr.puts "#{Time.now.to_f} Have #{@rbuf.length} asking for #{requested_length.inspect}"
|
125
|
-
return @rbuf if @rbuf.length > requested_length
|
126
|
-
|
127
|
-
if @rbuf.length < DEFAULT_BUFFER
|
128
|
-
@rbuf << @transport.read([requested_length, DEFAULT_BUFFER].max)
|
129
|
-
end
|
130
|
-
|
131
|
-
if @rbuf.length < requested_length
|
132
|
-
@rbuf << @transport.read_all(requested_length - @rbuf.length)
|
133
|
-
end
|
134
|
-
|
135
|
-
@rbuf
|
136
|
-
end
|
137
|
-
|
138
|
-
def consume!(size)
|
139
|
-
@rbuf.slice!(0...size)
|
140
|
-
end
|
141
|
-
end
|
142
|
-
deprecate_class! :TBufferedTransport => BufferedTransport
|
143
|
-
|
144
|
-
class BufferedTransportFactory < TransportFactory
|
145
|
-
def get_transport(transport)
|
146
|
-
return BufferedTransport.new(transport)
|
147
|
-
end
|
148
|
-
end
|
149
|
-
deprecate_class! :TBufferedTransportFactory => BufferedTransportFactory
|
150
|
-
|
151
|
-
class FramedTransport < Transport
|
152
|
-
def initialize(transport, read=true, write=true)
|
153
|
-
@transport = transport
|
154
|
-
@rbuf = ''
|
155
|
-
@wbuf = ''
|
156
|
-
@read = read
|
157
|
-
@write = write
|
158
|
-
end
|
159
|
-
|
160
|
-
def open?
|
161
|
-
@transport.open?
|
162
|
-
end
|
163
|
-
|
164
|
-
def open
|
165
|
-
@transport.open
|
166
|
-
end
|
167
|
-
|
168
|
-
def close
|
169
|
-
@transport.close
|
170
|
-
end
|
171
|
-
|
172
|
-
def read(sz)
|
173
|
-
return @transport.read(sz) unless @read
|
174
|
-
|
175
|
-
return '' if sz <= 0
|
176
|
-
|
177
|
-
read_frame if @rbuf.empty?
|
178
|
-
|
179
|
-
@rbuf.slice!(0, sz)
|
180
|
-
end
|
181
|
-
|
182
|
-
def write(buf,sz=nil)
|
183
|
-
return @transport.write(buf) unless @write
|
184
|
-
|
185
|
-
@wbuf << (sz ? buf[0...sz] : buf)
|
186
|
-
end
|
187
|
-
|
188
|
-
#
|
189
|
-
# Writes the output buffer to the stream in the format of a 4-byte length
|
190
|
-
# followed by the actual data.
|
191
|
-
#
|
192
|
-
def flush
|
193
|
-
return @transport.flush unless @write
|
194
|
-
|
195
|
-
out = [@wbuf.length].pack('N')
|
196
|
-
out << @wbuf
|
197
|
-
@transport.write(out)
|
198
|
-
@transport.flush
|
199
|
-
@wbuf = ''
|
200
|
-
end
|
201
|
-
|
202
|
-
def borrow(requested_length = 0)
|
203
|
-
read_frame if @rbuf.empty?
|
204
|
-
# there isn't any more coming, so if it's not enough, it's an error.
|
205
|
-
raise EOFError if requested_length > @rbuf.size
|
206
|
-
@rbuf
|
207
|
-
end
|
208
|
-
|
209
|
-
def consume!(size)
|
210
|
-
@rbuf.slice!(0...size)
|
211
|
-
end
|
212
|
-
|
213
|
-
private
|
214
|
-
|
215
|
-
def read_frame
|
216
|
-
sz = @transport.read_all(4).unpack('N').first
|
217
|
-
|
218
|
-
@rbuf = @transport.read_all(sz).dup # protect against later #slice!
|
219
|
-
end
|
220
|
-
end
|
221
|
-
deprecate_class! :TFramedTransport => FramedTransport
|
222
|
-
|
223
|
-
class FramedTransportFactory < TransportFactory
|
224
|
-
def get_transport(transport)
|
225
|
-
return FramedTransport.new(transport)
|
226
|
-
end
|
227
|
-
end
|
228
|
-
deprecate_class! :TFramedTransportFactory => FramedTransportFactory
|
229
|
-
|
230
|
-
class MemoryBuffer < Transport
|
231
|
-
GARBAGE_BUFFER_SIZE = 4*(2**10) # 4kB
|
232
|
-
|
233
|
-
# If you pass a string to this, you should #dup that string
|
234
|
-
# unless you want it to be modified by #read and #write
|
235
|
-
#--
|
236
|
-
# this behavior is no longer required. If you wish to change it
|
237
|
-
# go ahead, just make sure the specs pass
|
238
|
-
def initialize(buffer = nil)
|
239
|
-
@buf = buffer || ''
|
240
|
-
@index = 0
|
241
|
-
end
|
242
|
-
|
243
|
-
def open?
|
244
|
-
return true
|
245
|
-
end
|
246
|
-
|
247
|
-
def open
|
248
|
-
end
|
249
|
-
|
250
|
-
def close
|
251
|
-
end
|
252
|
-
|
253
|
-
def peek
|
254
|
-
@index < @buf.size
|
255
|
-
end
|
256
|
-
|
257
|
-
# this method does not use the passed object directly but copies it
|
258
|
-
def reset_buffer(new_buf = '')
|
259
|
-
@buf.replace new_buf
|
260
|
-
@index = 0
|
261
|
-
end
|
262
|
-
|
263
|
-
def available
|
264
|
-
@buf.length - @index
|
265
|
-
end
|
266
|
-
|
267
|
-
def read(len)
|
268
|
-
data = @buf.slice(@index, len)
|
269
|
-
@index += len
|
270
|
-
@index = @buf.size if @index > @buf.size
|
271
|
-
if @index >= GARBAGE_BUFFER_SIZE
|
272
|
-
@buf = @buf.slice(@index..-1)
|
273
|
-
@index = 0
|
274
|
-
end
|
275
|
-
data
|
276
|
-
end
|
277
|
-
|
278
|
-
def write(wbuf)
|
279
|
-
@buf << wbuf
|
280
|
-
end
|
281
|
-
|
282
|
-
def flush
|
283
|
-
end
|
284
|
-
|
285
|
-
# For fast binary protocol access
|
286
|
-
def borrow(size = nil)
|
287
|
-
if size.nil?
|
288
|
-
@buf[@index..-1]
|
289
|
-
else
|
290
|
-
if size > available
|
291
|
-
raise EOFError # Memory buffers only get one shot.
|
292
|
-
else
|
293
|
-
@buf[@index, size]
|
294
|
-
end
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
298
|
-
alias_method :consume!, :read
|
299
|
-
end
|
300
|
-
deprecate_class! :TMemoryBuffer => MemoryBuffer
|
301
|
-
|
302
|
-
## Very very simple implementation of wrapping two objects, one with a #read
|
303
|
-
## method and one with a #write method, into a transport for thrift.
|
304
|
-
##
|
305
|
-
## Assumes both objects are open, remain open, don't require flushing, etc.
|
306
|
-
class IOStreamTransport < Transport
|
307
|
-
def initialize(input, output)
|
308
|
-
@input = input
|
309
|
-
@output = output
|
310
|
-
end
|
311
|
-
|
312
|
-
def open?; not @input.closed? or not @output.closed? end
|
313
|
-
def read(sz); @input.read(sz) end
|
314
|
-
def write(buf); @output.write(buf) end
|
315
|
-
def close; @input.close; @output.close end
|
316
|
-
def to_io; @input end # we're assuming this is used in a IO.select for reading
|
317
|
-
end
|
318
|
-
deprecate_class! :TIOStreamTransport => IOStreamTransport
|
319
|
-
end
|
@@ -1,136 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
require 'thrift/protocol/binaryprotocol'
|
3
|
-
require 'thrift/server/httpserver'
|
4
|
-
require 'thrift/transport/httpclient'
|
5
|
-
|
6
|
-
context "Backwards compatibility" do
|
7
|
-
specify "old class names should map to new classes" do
|
8
|
-
Thrift::DeprecationProxy.reset_deprecation_warnings
|
9
|
-
# 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, :TProtocolException, Thrift::ProtocolException],
|
16
|
-
[: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
|
-
}
|
107
|
-
STDERR.stub!(:puts) # stub the deprecation warnings
|
108
|
-
mapping.each_pair do |klass, methods|
|
109
|
-
# 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)
|
112
|
-
methods.each_pair do |oldmeth, newmeth|
|
113
|
-
# ensure that calling the old method will call the new method
|
114
|
-
# and then redefine the old method to be the new one
|
115
|
-
klass.should be_method_defined(oldmeth)
|
116
|
-
klass.should be_method_defined(newmeth)
|
117
|
-
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
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
@@ -1,101 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
require 'thrift/protocol/binaryprotocolaccelerated'
|
3
|
-
require File.dirname(__FILE__) + '/binaryprotocol_spec_shared'
|
4
|
-
require File.dirname(__FILE__) + '/gen-rb/ThriftSpec_types'
|
5
|
-
|
6
|
-
class ThriftBinaryProtocolAcceleratedSpec < Spec::ExampleGroup
|
7
|
-
include Thrift
|
8
|
-
|
9
|
-
describe Thrift::BinaryProtocolAccelerated do
|
10
|
-
# since BinaryProtocolAccelerated should be directly equivalent to
|
11
|
-
# BinaryProtocol, we don't need any custom specs!
|
12
|
-
it_should_behave_like 'a binary protocol'
|
13
|
-
|
14
|
-
def protocol_class
|
15
|
-
BinaryProtocolAccelerated
|
16
|
-
end
|
17
|
-
|
18
|
-
# before(:each) do
|
19
|
-
# @buffer = ""
|
20
|
-
# @trans.stub!(:borrow).and_return { @buffer }
|
21
|
-
# @trans.stub!(:consume!).and_return do |*args|
|
22
|
-
# n = args.first || 0
|
23
|
-
# @buffer.slice!(0,n)
|
24
|
-
# end
|
25
|
-
# end
|
26
|
-
#
|
27
|
-
#
|
28
|
-
# it "should raise an exception if the message header has the wrong version" do
|
29
|
-
# @buffer = "\000\000\000\v"
|
30
|
-
# # @prot.should_receive(:read_i32).and_return(42)
|
31
|
-
# lambda { @prot.read_message_begin }.should raise_error(Thrift::ProtocolException, 'Missing version identifier') do |e|
|
32
|
-
# e.type == Thrift::ProtocolException::BAD_VERSION
|
33
|
-
# end
|
34
|
-
# end
|
35
|
-
#
|
36
|
-
# it "should encode a string with null bytes in it" do
|
37
|
-
# foo = SpecNamespace::Hello.new(:greeting => "Hello\000World!")
|
38
|
-
# @prot.encode_binary(foo).should == "\v\000\001\000\000\000\fHello\000World!\000"
|
39
|
-
# end
|
40
|
-
#
|
41
|
-
# it "should decode a string with null bytes in it" do
|
42
|
-
# trans = Thrift::MemoryBuffer.new("\v\000\001\000\000\000\fHello\000World!\000")
|
43
|
-
# @prot.decode_binary(SpecNamespace::Hello.new, trans).should == SpecNamespace::Hello.new(:greeting => "Hello\000World!")
|
44
|
-
# end
|
45
|
-
#
|
46
|
-
# it "should error when encoding a struct with a nil value in a list" do
|
47
|
-
# Thrift.type_checking = false
|
48
|
-
# sl = SpecNamespace::SimpleList
|
49
|
-
# hello = SpecNamespace::Hello
|
50
|
-
# # nil counts as false for bools
|
51
|
-
# # lambda { @prot.encode_binary(sl.new(:bools => [true, false, nil, false])) }.should raise_error
|
52
|
-
# lambda { @prot.encode_binary(sl.new(:bytes => [1, 2, nil, 3])) }.should raise_error
|
53
|
-
# lambda { @prot.encode_binary(sl.new(:i16s => [1, 2, nil, 3])) }.should raise_error
|
54
|
-
# lambda { @prot.encode_binary(sl.new(:i32s => [1, 2, nil, 3])) }.should raise_error
|
55
|
-
# lambda { @prot.encode_binary(sl.new(:i64s => [1, 2, nil, 3])) }.should raise_error
|
56
|
-
# lambda { @prot.encode_binary(sl.new(:doubles => [1.0, 2.0, nil, 3.0])) }.should raise_error
|
57
|
-
# lambda { @prot.encode_binary(sl.new(:strings => ["one", "two", nil, "three"])) }.should raise_error
|
58
|
-
# lambda { @prot.encode_binary(sl.new(:lists => [[1, 2], nil, [3, 4]])) }.should raise_error
|
59
|
-
# lambda { @prot.encode_binary(sl.new(:maps => [{1 => 2}, nil, {3 => 4}])) }.should raise_error
|
60
|
-
# lambda { @prot.encode_binary(sl.new(:sets => [Set.new([1, 2]), nil, Set.new([3, 4])])) }.should raise_error
|
61
|
-
# lambda { @prot.encode_binary(sl.new(:structs => [hello.new, nil, hello.new(:greeting => "hi")])) }.should raise_error
|
62
|
-
# end
|
63
|
-
#
|
64
|
-
# it "should error when encoding a non-nil, non-correctly-typed value in a list" do
|
65
|
-
# Thrift.type_checking = false
|
66
|
-
# sl = SpecNamespace::SimpleList
|
67
|
-
# hello = SpecNamespace::Hello
|
68
|
-
# # bool should accept any value
|
69
|
-
# # lambda { @prot.encode_binary(sl.new(:bools => [true, false, 3])) }.should raise_error
|
70
|
-
# lambda { @prot.encode_binary(sl.new(:bytes => [1, 2, "3", 5])) }.should raise_error
|
71
|
-
# lambda { @prot.encode_binary(sl.new(:i16s => ["one", 2, 3])) }.should raise_error
|
72
|
-
# lambda { @prot.encode_binary(sl.new(:i32s => [[1,2], 3, 4])) }.should raise_error
|
73
|
-
# lambda { @prot.encode_binary(sl.new(:i64s => [{1 => 2}, 3, 4])) }.should raise_error
|
74
|
-
# lambda { @prot.encode_binary(sl.new(:doubles => ["one", 2.3, 3.4])) }.should raise_error
|
75
|
-
# lambda { @prot.encode_binary(sl.new(:strings => ["one", "two", 3, 4])) }.should raise_error
|
76
|
-
# lambda { @prot.encode_binary(sl.new(:lists => [{1 => 2}, [3, 4]])) }.should raise_error
|
77
|
-
# lambda { @prot.encode_binary(sl.new(:maps => [{1 => 2}, [3, 4]])) }.should raise_error
|
78
|
-
# lambda { @prot.encode_binary(sl.new(:sets => [Set.new([1, 2]), 3, 4])) }.should raise_error
|
79
|
-
# lambda { @prot.encode_binary(sl.new(:structs => [3, "four"])) }.should raise_error
|
80
|
-
# end
|
81
|
-
#
|
82
|
-
# it "should error when encoding an improper object where a container is expected" do
|
83
|
-
# Thrift.type_checking = false
|
84
|
-
# sl = SpecNamespace::SimpleList
|
85
|
-
# lambda { @prot.encode_binary(sl.new(:strings => {"one" => "two", nil => "three"})) }.should raise_error
|
86
|
-
# lambda { @prot.encode_binary(sl.new(:maps => [[1, 2]])) }.should raise_error
|
87
|
-
# end
|
88
|
-
#
|
89
|
-
# it "should accept arrays and hashes as sets" do
|
90
|
-
# Thrift.type_checking = false
|
91
|
-
# sl = SpecNamespace::SimpleList
|
92
|
-
# lambda { @prot.encode_binary(sl.new(:sets => [[1, 2], {3 => true, 4 => true}])) }.should_not raise_error
|
93
|
-
# end
|
94
|
-
end
|
95
|
-
|
96
|
-
describe BinaryProtocolAcceleratedFactory do
|
97
|
-
it "should create a BinaryProtocolAccelerated" do
|
98
|
-
BinaryProtocolAcceleratedFactory.new.get_protocol(mock("MockTransport")).should be_instance_of(BinaryProtocolAccelerated)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|