thrift 0.0.751142
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/COPYING +14 -0
- data/LICENSE +14 -0
- data/Makefile.am +15 -0
- data/Manifest +78 -0
- data/README +30 -0
- data/Rakefile +102 -0
- data/benchmark/Benchmark.thrift +5 -0
- data/benchmark/benchmark.rb +254 -0
- data/benchmark/client.rb +56 -0
- data/benchmark/gen-rb/BenchmarkService.rb +81 -0
- data/benchmark/gen-rb/Benchmark_constants.rb +11 -0
- data/benchmark/gen-rb/Benchmark_types.rb +10 -0
- data/benchmark/server.rb +64 -0
- data/benchmark/thin_server.rb +26 -0
- data/ext/binary_protocol_accelerated.c +463 -0
- data/ext/binary_protocol_accelerated.h +1 -0
- data/ext/constants.h +77 -0
- data/ext/extconf.rb +7 -0
- data/ext/memory_buffer.c +52 -0
- data/ext/memory_buffer.h +1 -0
- data/ext/protocol.c +166 -0
- data/ext/protocol.h +1 -0
- data/ext/struct.c +574 -0
- data/ext/struct.h +48 -0
- data/ext/thrift_native.c +173 -0
- data/lib/thrift/client.rb +44 -0
- data/lib/thrift/deprecation.rb +155 -0
- data/lib/thrift/exceptions.rb +65 -0
- data/lib/thrift/processor.rb +39 -0
- data/lib/thrift/protocol/binaryprotocol.rb +213 -0
- data/lib/thrift/protocol/binaryprotocolaccelerated.rb +19 -0
- data/lib/thrift/protocol/tbinaryprotocol.rb +2 -0
- data/lib/thrift/protocol/tprotocol.rb +2 -0
- data/lib/thrift/protocol.rb +270 -0
- data/lib/thrift/serializer.rb +27 -0
- data/lib/thrift/server/httpserver.rb +44 -0
- data/lib/thrift/server/nonblockingserver.rb +278 -0
- data/lib/thrift/server/thttpserver.rb +2 -0
- data/lib/thrift/server/tserver.rb +2 -0
- data/lib/thrift/server.rb +135 -0
- data/lib/thrift/struct.rb +272 -0
- data/lib/thrift/thrift.rb +14 -0
- data/lib/thrift/transport/httpclient.rb +29 -0
- data/lib/thrift/transport/socket.rb +167 -0
- data/lib/thrift/transport/thttpclient.rb +2 -0
- data/lib/thrift/transport/tsocket.rb +2 -0
- data/lib/thrift/transport/ttransport.rb +2 -0
- data/lib/thrift/transport/unixsocket.rb +58 -0
- data/lib/thrift/transport.rb +319 -0
- data/lib/thrift/types.rb +83 -0
- data/lib/thrift.rb +28 -0
- data/setup.rb +1585 -0
- data/spec/ThriftSpec.thrift +46 -0
- data/spec/backwards_compatibility_spec.rb +136 -0
- data/spec/binaryprotocol_spec.rb +45 -0
- data/spec/binaryprotocol_spec_shared.rb +274 -0
- data/spec/binaryprotocolaccelerated_spec.rb +101 -0
- data/spec/client_spec.rb +81 -0
- data/spec/deprecation_spec.rb +443 -0
- data/spec/exception_spec.rb +123 -0
- data/spec/gen-rb/NonblockingService.rb +268 -0
- data/spec/gen-rb/ThriftSpec_constants.rb +11 -0
- data/spec/gen-rb/ThriftSpec_types.rb +134 -0
- data/spec/httpclient_spec.rb +31 -0
- data/spec/httpserver_spec.rb +98 -0
- data/spec/nonblockingserver_spec.rb +245 -0
- data/spec/processor_spec.rb +64 -0
- data/spec/protocol_spec.rb +142 -0
- data/spec/serializer_spec.rb +52 -0
- data/spec/server_spec.rb +141 -0
- data/spec/socket_spec.rb +97 -0
- data/spec/socket_spec_shared.rb +85 -0
- data/spec/spec_helper.rb +35 -0
- data/spec/struct_spec.rb +244 -0
- data/spec/transport_spec.rb +359 -0
- data/spec/types_spec.rb +98 -0
- data/spec/unixsocket_spec.rb +90 -0
- data/thrift.gemspec +33 -0
- data.tar.gz.sig +0 -0
- metadata +200 -0
- metadata.gz.sig +0 -0
@@ -0,0 +1,443 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
shared_examples_for "deprecation" do
|
4
|
+
before(:all) do
|
5
|
+
# ensure deprecation is turned on
|
6
|
+
Thrift.send :remove_const, :DEPRECATION
|
7
|
+
Thrift.const_set :DEPRECATION, true
|
8
|
+
end
|
9
|
+
|
10
|
+
after(:all) do
|
11
|
+
# now turn it off again
|
12
|
+
# no other specs should want it
|
13
|
+
Thrift.send :remove_const, :DEPRECATION
|
14
|
+
Thrift.const_set :DEPRECATION, false
|
15
|
+
end
|
16
|
+
|
17
|
+
before(:each) do
|
18
|
+
Thrift::DeprecationProxy.reset_deprecation_warnings
|
19
|
+
end
|
20
|
+
|
21
|
+
def ensure_const_removed(name, &block)
|
22
|
+
begin
|
23
|
+
block.call
|
24
|
+
ensure
|
25
|
+
Object.send :remove_const, name if Object.const_defined? name
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'deprecate!' do
|
31
|
+
it_should_behave_like "deprecation"
|
32
|
+
|
33
|
+
def stub_stderr(callstr, offset=1)
|
34
|
+
STDERR.should_receive(:puts).with("Warning: calling deprecated method #{callstr}")
|
35
|
+
line = caller.first[/\d+$/].to_i + offset
|
36
|
+
STDERR.should_receive(:puts).with(" from #{__FILE__}:#{line}")
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should work for Module methods" do
|
40
|
+
mod = Module.new do
|
41
|
+
class << self
|
42
|
+
def new
|
43
|
+
"new"
|
44
|
+
end
|
45
|
+
deprecate! :old => :new
|
46
|
+
end
|
47
|
+
end
|
48
|
+
stub_stderr "#{mod.inspect}.old"
|
49
|
+
mod.old.should == "new"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should work with Modules that extend themselves" do
|
53
|
+
mod = Module.new do
|
54
|
+
extend self
|
55
|
+
def new
|
56
|
+
"new"
|
57
|
+
end
|
58
|
+
deprecate! :old => :new
|
59
|
+
end
|
60
|
+
stub_stderr "#{mod.inspect}.old"
|
61
|
+
mod.old.should == "new"
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should work wtih Class methods" do
|
65
|
+
klass = Class.new do
|
66
|
+
class << self
|
67
|
+
def new
|
68
|
+
"new"
|
69
|
+
end
|
70
|
+
deprecate! :old => :new
|
71
|
+
end
|
72
|
+
end
|
73
|
+
stub_stderr "#{klass.inspect}.old"
|
74
|
+
klass.old.should == "new"
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should work with Classes that include Modules" do
|
78
|
+
mod = Module.new do
|
79
|
+
def new
|
80
|
+
"new"
|
81
|
+
end
|
82
|
+
deprecate! :old => :new
|
83
|
+
end
|
84
|
+
klass = Class.new do
|
85
|
+
include mod
|
86
|
+
end
|
87
|
+
stub_stderr "#{klass.inspect}#old"
|
88
|
+
klass.new.old.should == "new"
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should work with instance methods" do
|
92
|
+
klass = Class.new do
|
93
|
+
def new
|
94
|
+
"new"
|
95
|
+
end
|
96
|
+
deprecate! :old => :new
|
97
|
+
end
|
98
|
+
stub_stderr "#{klass.inspect}#old"
|
99
|
+
klass.new.old.should == "new"
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should work with multiple method names" do
|
103
|
+
klass = Class.new do
|
104
|
+
def new1
|
105
|
+
"new 1"
|
106
|
+
end
|
107
|
+
def new2
|
108
|
+
"new 2"
|
109
|
+
end
|
110
|
+
deprecate! :old1 => :new1, :old2 => :new2
|
111
|
+
end
|
112
|
+
stub_stderr("#{klass.inspect}#old1", 3).ordered
|
113
|
+
stub_stderr("#{klass.inspect}#old2", 3).ordered
|
114
|
+
inst = klass.new
|
115
|
+
inst.old1.should == "new 1"
|
116
|
+
inst.old2.should == "new 2"
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should only log a message once, even across multiple instances" do
|
120
|
+
klass = Class.new do
|
121
|
+
def new
|
122
|
+
"new"
|
123
|
+
end
|
124
|
+
deprecate! :old => :new
|
125
|
+
end
|
126
|
+
stub_stderr("#{klass.inspect}#old").once
|
127
|
+
klass.new.old.should == "new"
|
128
|
+
klass.new.old.should == "new"
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should pass arguments" do
|
132
|
+
klass = Class.new do
|
133
|
+
def new(a, b)
|
134
|
+
"new: #{a + b}"
|
135
|
+
end
|
136
|
+
deprecate! :old => :new
|
137
|
+
end
|
138
|
+
stub_stderr("#{klass.inspect}#old")
|
139
|
+
klass.new.old(3, 5).should == "new: 8"
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should pass blocks" do
|
143
|
+
klass = Class.new do
|
144
|
+
def new
|
145
|
+
"new #{yield}"
|
146
|
+
end
|
147
|
+
deprecate! :old => :new
|
148
|
+
end
|
149
|
+
stub_stderr("#{klass.inspect}#old")
|
150
|
+
klass.new.old { "block" }.should == "new block"
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should not freeze the definition of the new method" do
|
154
|
+
klass = Class.new do
|
155
|
+
def new
|
156
|
+
"new"
|
157
|
+
end
|
158
|
+
deprecate! :old => :new
|
159
|
+
end
|
160
|
+
klass.send :define_method, :new do
|
161
|
+
"new 2"
|
162
|
+
end
|
163
|
+
stub_stderr("#{klass.inspect}#old")
|
164
|
+
klass.new.old.should == "new 2"
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should call the forwarded method in the same context as the original" do
|
168
|
+
klass = Class.new do
|
169
|
+
def myself
|
170
|
+
self
|
171
|
+
end
|
172
|
+
deprecate! :me => :myself
|
173
|
+
end
|
174
|
+
inst = klass.new
|
175
|
+
stub_stderr("#{klass.inspect}#me")
|
176
|
+
inst.me.should eql(inst.myself)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
describe "deprecate_class!" do
|
181
|
+
it_should_behave_like "deprecation"
|
182
|
+
|
183
|
+
def stub_stderr_jruby(klass)
|
184
|
+
return unless defined? JRUBY_VERSION
|
185
|
+
stub_stderr(klass, nil, caller.first)
|
186
|
+
end
|
187
|
+
|
188
|
+
def stub_stderr_mri(klass, offset=1)
|
189
|
+
return if defined? JRUBY_VERSION
|
190
|
+
stub_stderr(klass, offset, caller.first)
|
191
|
+
end
|
192
|
+
|
193
|
+
def stub_stderr(klass, offset=1, called=nil)
|
194
|
+
STDERR.should_receive(:puts).with("Warning: class #{klass} is deprecated")
|
195
|
+
if offset
|
196
|
+
line = (called || caller.first)[/\d+$/].to_i + offset
|
197
|
+
STDERR.should_receive(:puts).with(" from #{__FILE__}:#{line}")
|
198
|
+
else
|
199
|
+
STDERR.should_receive(:puts).with(/^ from #{Regexp.escape(__FILE__)}:/)
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
it "should create a new global constant that points to the old one" do
|
204
|
+
ensure_const_removed :DeprecationSpecOldClass do
|
205
|
+
klass = Class.new do
|
206
|
+
def foo
|
207
|
+
"foo"
|
208
|
+
end
|
209
|
+
end
|
210
|
+
deprecate_class! :DeprecationSpecOldClass => klass
|
211
|
+
stub_stderr(:DeprecationSpecOldClass)
|
212
|
+
::DeprecationSpecOldClass.should eql(klass)
|
213
|
+
::DeprecationSpecOldClass.new.foo.should == "foo"
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
it "should create a global constant even from inside a module" do
|
218
|
+
ensure_const_removed :DeprecationSpecOldClass do
|
219
|
+
klass = nil #define scoping
|
220
|
+
Module.new do
|
221
|
+
klass = Class.new do
|
222
|
+
def foo
|
223
|
+
"foo"
|
224
|
+
end
|
225
|
+
end
|
226
|
+
deprecate_class! :DeprecationSpecOldClass => klass
|
227
|
+
end
|
228
|
+
stub_stderr(:DeprecationSpecOldClass)
|
229
|
+
::DeprecationSpecOldClass.should eql(klass)
|
230
|
+
::DeprecationSpecOldClass.new.foo.should == "foo"
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
it "should not prevent the deprecated class from being a superclass" do
|
235
|
+
ensure_const_removed :DeprecationSpecOldClass do
|
236
|
+
klass = Class.new do
|
237
|
+
def foo
|
238
|
+
"foo"
|
239
|
+
end
|
240
|
+
end
|
241
|
+
deprecate_class! :DeprecationSpecOldClass => klass
|
242
|
+
stub_stderr_jruby(:DeprecationSpecOldClass)
|
243
|
+
subklass = Class.new(::DeprecationSpecOldClass) do
|
244
|
+
def foo
|
245
|
+
"subclass #{super}"
|
246
|
+
end
|
247
|
+
end
|
248
|
+
stub_stderr_mri(:DeprecationSpecOldClass)
|
249
|
+
subklass.superclass.should eql(klass)
|
250
|
+
subklass.new.foo.should == "subclass foo"
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
it "should not bleed info between deprecations" do
|
255
|
+
ensure_const_removed :DeprecationSpecOldClass do
|
256
|
+
ensure_const_removed :DeprecationSpecOldClass2 do
|
257
|
+
klass = Class.new do
|
258
|
+
def foo
|
259
|
+
"foo"
|
260
|
+
end
|
261
|
+
end
|
262
|
+
deprecate_class! :DeprecationSpecOldClass => klass
|
263
|
+
klass2 = Class.new do
|
264
|
+
def bar
|
265
|
+
"bar"
|
266
|
+
end
|
267
|
+
end
|
268
|
+
deprecate_class! :DeprecationSpecOldClass2 => klass2
|
269
|
+
stub_stderr(:DeprecationSpecOldClass)
|
270
|
+
::DeprecationSpecOldClass.new.foo.should == "foo"
|
271
|
+
stub_stderr(:DeprecationSpecOldClass2)
|
272
|
+
::DeprecationSpecOldClass2.new.bar.should == "bar"
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
it "should work when Object.inherited calls a method on self" do
|
278
|
+
ensure_const_removed :DeprecationSpecOldClass do
|
279
|
+
old_inherited = Object.method(:inherited)
|
280
|
+
begin
|
281
|
+
(class << Object;self;end).class_eval do
|
282
|
+
define_method :inherited do |cls|
|
283
|
+
cls.inspect
|
284
|
+
old_inherited.call(cls)
|
285
|
+
end
|
286
|
+
end
|
287
|
+
klass = Class.new do
|
288
|
+
def foo
|
289
|
+
"foo"
|
290
|
+
end
|
291
|
+
end
|
292
|
+
STDERR.should_receive(:puts).exactly(0).times
|
293
|
+
lambda { deprecate_class! :DeprecationSpecOldClass => klass }.should_not raise_error
|
294
|
+
ensure
|
295
|
+
(class << Object;self;end).class_eval do
|
296
|
+
define_method :inherited, old_inherited
|
297
|
+
end
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
describe "deprecate_module!" do
|
304
|
+
it_should_behave_like "deprecation"
|
305
|
+
|
306
|
+
def stub_stderr_jruby(mod)
|
307
|
+
return unless defined? JRUBY_VERSION
|
308
|
+
stub_stderr(mod, nil, caller.first)
|
309
|
+
end
|
310
|
+
|
311
|
+
def stub_stderr_mri(mod, offset=1)
|
312
|
+
return if defined? JRUBY_VERSION
|
313
|
+
stub_stderr(mod, offset, caller.first)
|
314
|
+
end
|
315
|
+
|
316
|
+
def stub_stderr(mod, offset=1, called=nil)
|
317
|
+
STDERR.should_receive(:puts).with("Warning: module #{mod} is deprecated")
|
318
|
+
source = Regexp.escape(__FILE__) + ":"
|
319
|
+
if offset
|
320
|
+
line = (called || caller.first)[/\d+$/].to_i + offset
|
321
|
+
source += Regexp.escape(line.to_s)
|
322
|
+
else
|
323
|
+
source += "\d+"
|
324
|
+
end
|
325
|
+
STDERR.should_receive(:puts).with(/^ from #{source}(?::in `[^']+')?$/)
|
326
|
+
end
|
327
|
+
|
328
|
+
it "should create a new global constant that points to the old one" do
|
329
|
+
ensure_const_removed :DeprecationSpecOldModule do
|
330
|
+
mod = Module.new do
|
331
|
+
def self.foo
|
332
|
+
"foo"
|
333
|
+
end
|
334
|
+
end
|
335
|
+
deprecate_module! :DeprecationSpecOldModule => mod
|
336
|
+
stub_stderr(:DeprecationSpecOldModule)
|
337
|
+
::DeprecationSpecOldModule.should eql(mod)
|
338
|
+
::DeprecationSpecOldModule.foo.should == "foo"
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
it "should create a global constant even from inside a module" do
|
343
|
+
ensure_const_removed :DeprecationSpecOldModule do
|
344
|
+
mod = nil # scoping
|
345
|
+
Module.new do
|
346
|
+
mod = Module.new do
|
347
|
+
def self.foo
|
348
|
+
"foo"
|
349
|
+
end
|
350
|
+
end
|
351
|
+
deprecate_module! :DeprecationSpecOldModule => mod
|
352
|
+
end
|
353
|
+
stub_stderr(:DeprecationSpecOldModule)
|
354
|
+
::DeprecationSpecOldModule.should eql(mod)
|
355
|
+
::DeprecationSpecOldModule.foo.should == "foo"
|
356
|
+
end
|
357
|
+
end
|
358
|
+
|
359
|
+
it "should work for modules that extend themselves" do
|
360
|
+
ensure_const_removed :DeprecationSpecOldModule do
|
361
|
+
mod = Module.new do
|
362
|
+
extend self
|
363
|
+
def foo
|
364
|
+
"foo"
|
365
|
+
end
|
366
|
+
end
|
367
|
+
deprecate_module! :DeprecationSpecOldModule => mod
|
368
|
+
stub_stderr(:DeprecationSpecOldModule)
|
369
|
+
::DeprecationSpecOldModule.should eql(mod)
|
370
|
+
::DeprecationSpecOldModule.foo.should == "foo"
|
371
|
+
end
|
372
|
+
end
|
373
|
+
|
374
|
+
it "should work for modules included in other modules" do
|
375
|
+
ensure_const_removed :DeprecationSpecOldModule do
|
376
|
+
mod = Module.new do
|
377
|
+
def foo
|
378
|
+
"foo"
|
379
|
+
end
|
380
|
+
end
|
381
|
+
deprecate_module! :DeprecationSpecOldModule => mod
|
382
|
+
stub_stderr_jruby(:DeprecationSpecOldModule)
|
383
|
+
mod2 = Module.new do
|
384
|
+
class << self
|
385
|
+
include ::DeprecationSpecOldModule
|
386
|
+
end
|
387
|
+
end
|
388
|
+
stub_stderr_mri(:DeprecationSpecOldModule)
|
389
|
+
mod2.foo.should == "foo"
|
390
|
+
end
|
391
|
+
end
|
392
|
+
|
393
|
+
it "should work for modules included in classes" do
|
394
|
+
ensure_const_removed :DeprecationSpecOldModule do
|
395
|
+
mod = Module.new do
|
396
|
+
def foo
|
397
|
+
"foo"
|
398
|
+
end
|
399
|
+
end
|
400
|
+
deprecate_module! :DeprecationSpecOldModule => mod
|
401
|
+
stub_stderr_jruby(:DeprecationSpecOldModule)
|
402
|
+
klass = Class.new do
|
403
|
+
include ::DeprecationSpecOldModule
|
404
|
+
end
|
405
|
+
stub_stderr_mri(:DeprecationSpecOldModule)
|
406
|
+
klass.new.foo.should == "foo"
|
407
|
+
end
|
408
|
+
end
|
409
|
+
|
410
|
+
it "should not bleed info between deprecations" do
|
411
|
+
ensure_const_removed :DeprecationSpecOldModule do
|
412
|
+
ensure_const_removed :DeprecationSpecOldModule2 do
|
413
|
+
mod = Module.new do
|
414
|
+
def self.foo
|
415
|
+
"foo"
|
416
|
+
end
|
417
|
+
end
|
418
|
+
deprecate_module! :DeprecationSpecOldModule => mod
|
419
|
+
mod2 = Module.new do
|
420
|
+
def self.bar
|
421
|
+
"bar"
|
422
|
+
end
|
423
|
+
end
|
424
|
+
deprecate_module! :DeprecationSpecOldModule2 => mod2
|
425
|
+
stub_stderr(:DeprecationSpecOldModule)
|
426
|
+
::DeprecationSpecOldModule.foo.should == "foo"
|
427
|
+
stub_stderr(:DeprecationSpecOldModule2)
|
428
|
+
::DeprecationSpecOldModule2.bar.should == "bar"
|
429
|
+
end
|
430
|
+
end
|
431
|
+
end
|
432
|
+
|
433
|
+
it "should skip thrift library code when printing caller" do
|
434
|
+
klass = Class.new do
|
435
|
+
include ThriftStruct
|
436
|
+
FIELDS = {
|
437
|
+
1 => {:name => "foo", :type => Thrift::Types::STRING}
|
438
|
+
}
|
439
|
+
end
|
440
|
+
stub_stderr('ThriftStruct')
|
441
|
+
klass.new(:foo => "foo")
|
442
|
+
end
|
443
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
class ThriftExceptionSpec < Spec::ExampleGroup
|
4
|
+
include Thrift
|
5
|
+
|
6
|
+
describe Exception do
|
7
|
+
it "should have an accessible message" do
|
8
|
+
e = Exception.new("test message")
|
9
|
+
e.message.should == "test message"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe ApplicationException do
|
14
|
+
it "should inherit from Thrift::Exception" do
|
15
|
+
ApplicationException.superclass.should == Exception
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should have an accessible type and message" do
|
19
|
+
e = ApplicationException.new
|
20
|
+
e.type.should == ApplicationException::UNKNOWN
|
21
|
+
e.message.should be_nil
|
22
|
+
e = ApplicationException.new(ApplicationException::UNKNOWN_METHOD, "test message")
|
23
|
+
e.type.should == ApplicationException::UNKNOWN_METHOD
|
24
|
+
e.message.should == "test message"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should read a struct off of a protocol" do
|
28
|
+
prot = mock("MockProtocol")
|
29
|
+
prot.should_receive(:read_struct_begin).ordered
|
30
|
+
prot.should_receive(:read_field_begin).exactly(3).times.and_return(
|
31
|
+
["message", Types::STRING, 1],
|
32
|
+
["type", Types::I32, 2],
|
33
|
+
[nil, Types::STOP, 0]
|
34
|
+
)
|
35
|
+
prot.should_receive(:read_string).ordered.and_return "test message"
|
36
|
+
prot.should_receive(:read_i32).ordered.and_return ApplicationException::BAD_SEQUENCE_ID
|
37
|
+
prot.should_receive(:read_field_end).exactly(2).times
|
38
|
+
prot.should_receive(:read_struct_end).ordered
|
39
|
+
|
40
|
+
e = ApplicationException.new
|
41
|
+
e.read(prot)
|
42
|
+
e.message.should == "test message"
|
43
|
+
e.type.should == ApplicationException::BAD_SEQUENCE_ID
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should skip bad fields when reading a struct" do
|
47
|
+
prot = mock("MockProtocol")
|
48
|
+
prot.should_receive(:read_struct_begin).ordered
|
49
|
+
prot.should_receive(:read_field_begin).exactly(5).times.and_return(
|
50
|
+
["type", Types::I32, 2],
|
51
|
+
["type", Types::STRING, 2],
|
52
|
+
["message", Types::MAP, 1],
|
53
|
+
["message", Types::STRING, 3],
|
54
|
+
[nil, Types::STOP, 0]
|
55
|
+
)
|
56
|
+
prot.should_receive(:read_i32).and_return ApplicationException::INVALID_MESSAGE_TYPE
|
57
|
+
prot.should_receive(:skip).with(Types::STRING).twice
|
58
|
+
prot.should_receive(:skip).with(Types::MAP)
|
59
|
+
prot.should_receive(:read_field_end).exactly(4).times
|
60
|
+
prot.should_receive(:read_struct_end).ordered
|
61
|
+
|
62
|
+
e = ApplicationException.new
|
63
|
+
e.read(prot)
|
64
|
+
e.message.should be_nil
|
65
|
+
e.type.should == ApplicationException::INVALID_MESSAGE_TYPE
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should write a Thrift::ApplicationException struct to the oprot" do
|
69
|
+
prot = mock("MockProtocol")
|
70
|
+
prot.should_receive(:write_struct_begin).with("Thrift::ApplicationException").ordered
|
71
|
+
prot.should_receive(:write_field_begin).with("message", Types::STRING, 1).ordered
|
72
|
+
prot.should_receive(:write_string).with("test message").ordered
|
73
|
+
prot.should_receive(:write_field_begin).with("type", Types::I32, 2).ordered
|
74
|
+
prot.should_receive(:write_i32).with(ApplicationException::UNKNOWN_METHOD).ordered
|
75
|
+
prot.should_receive(:write_field_end).twice
|
76
|
+
prot.should_receive(:write_field_stop).ordered
|
77
|
+
prot.should_receive(:write_struct_end).ordered
|
78
|
+
|
79
|
+
e = ApplicationException.new(ApplicationException::UNKNOWN_METHOD, "test message")
|
80
|
+
e.write(prot)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should skip nil fields when writing to the oprot" do
|
84
|
+
prot = mock("MockProtocol")
|
85
|
+
prot.should_receive(:write_struct_begin).with("Thrift::ApplicationException").ordered
|
86
|
+
prot.should_receive(:write_field_begin).with("message", Types::STRING, 1).ordered
|
87
|
+
prot.should_receive(:write_string).with("test message").ordered
|
88
|
+
prot.should_receive(:write_field_end).ordered
|
89
|
+
prot.should_receive(:write_field_stop).ordered
|
90
|
+
prot.should_receive(:write_struct_end).ordered
|
91
|
+
|
92
|
+
e = ApplicationException.new(nil, "test message")
|
93
|
+
e.write(prot)
|
94
|
+
|
95
|
+
prot = mock("MockProtocol")
|
96
|
+
prot.should_receive(:write_struct_begin).with("Thrift::ApplicationException").ordered
|
97
|
+
prot.should_receive(:write_field_begin).with("type", Types::I32, 2).ordered
|
98
|
+
prot.should_receive(:write_i32).with(ApplicationException::BAD_SEQUENCE_ID).ordered
|
99
|
+
prot.should_receive(:write_field_end).ordered
|
100
|
+
prot.should_receive(:write_field_stop).ordered
|
101
|
+
prot.should_receive(:write_struct_end).ordered
|
102
|
+
|
103
|
+
e = ApplicationException.new(ApplicationException::BAD_SEQUENCE_ID)
|
104
|
+
e.write(prot)
|
105
|
+
|
106
|
+
prot = mock("MockProtocol")
|
107
|
+
prot.should_receive(:write_struct_begin).with("Thrift::ApplicationException").ordered
|
108
|
+
prot.should_receive(:write_field_stop).ordered
|
109
|
+
prot.should_receive(:write_struct_end).ordered
|
110
|
+
|
111
|
+
e = ApplicationException.new(nil)
|
112
|
+
e.write(prot)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe ProtocolException do
|
117
|
+
it "should have an accessible type" do
|
118
|
+
prot = ProtocolException.new(ProtocolException::SIZE_LIMIT, "message")
|
119
|
+
prot.type.should == ProtocolException::SIZE_LIMIT
|
120
|
+
prot.message.should == "message"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|