thrift 0.0.751142

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. data/CHANGELOG +2 -0
  2. data/COPYING +14 -0
  3. data/LICENSE +14 -0
  4. data/Makefile.am +15 -0
  5. data/Manifest +78 -0
  6. data/README +30 -0
  7. data/Rakefile +102 -0
  8. data/benchmark/Benchmark.thrift +5 -0
  9. data/benchmark/benchmark.rb +254 -0
  10. data/benchmark/client.rb +56 -0
  11. data/benchmark/gen-rb/BenchmarkService.rb +81 -0
  12. data/benchmark/gen-rb/Benchmark_constants.rb +11 -0
  13. data/benchmark/gen-rb/Benchmark_types.rb +10 -0
  14. data/benchmark/server.rb +64 -0
  15. data/benchmark/thin_server.rb +26 -0
  16. data/ext/binary_protocol_accelerated.c +463 -0
  17. data/ext/binary_protocol_accelerated.h +1 -0
  18. data/ext/constants.h +77 -0
  19. data/ext/extconf.rb +7 -0
  20. data/ext/memory_buffer.c +52 -0
  21. data/ext/memory_buffer.h +1 -0
  22. data/ext/protocol.c +166 -0
  23. data/ext/protocol.h +1 -0
  24. data/ext/struct.c +574 -0
  25. data/ext/struct.h +48 -0
  26. data/ext/thrift_native.c +173 -0
  27. data/lib/thrift/client.rb +44 -0
  28. data/lib/thrift/deprecation.rb +155 -0
  29. data/lib/thrift/exceptions.rb +65 -0
  30. data/lib/thrift/processor.rb +39 -0
  31. data/lib/thrift/protocol/binaryprotocol.rb +213 -0
  32. data/lib/thrift/protocol/binaryprotocolaccelerated.rb +19 -0
  33. data/lib/thrift/protocol/tbinaryprotocol.rb +2 -0
  34. data/lib/thrift/protocol/tprotocol.rb +2 -0
  35. data/lib/thrift/protocol.rb +270 -0
  36. data/lib/thrift/serializer.rb +27 -0
  37. data/lib/thrift/server/httpserver.rb +44 -0
  38. data/lib/thrift/server/nonblockingserver.rb +278 -0
  39. data/lib/thrift/server/thttpserver.rb +2 -0
  40. data/lib/thrift/server/tserver.rb +2 -0
  41. data/lib/thrift/server.rb +135 -0
  42. data/lib/thrift/struct.rb +272 -0
  43. data/lib/thrift/thrift.rb +14 -0
  44. data/lib/thrift/transport/httpclient.rb +29 -0
  45. data/lib/thrift/transport/socket.rb +167 -0
  46. data/lib/thrift/transport/thttpclient.rb +2 -0
  47. data/lib/thrift/transport/tsocket.rb +2 -0
  48. data/lib/thrift/transport/ttransport.rb +2 -0
  49. data/lib/thrift/transport/unixsocket.rb +58 -0
  50. data/lib/thrift/transport.rb +319 -0
  51. data/lib/thrift/types.rb +83 -0
  52. data/lib/thrift.rb +28 -0
  53. data/setup.rb +1585 -0
  54. data/spec/ThriftSpec.thrift +46 -0
  55. data/spec/backwards_compatibility_spec.rb +136 -0
  56. data/spec/binaryprotocol_spec.rb +45 -0
  57. data/spec/binaryprotocol_spec_shared.rb +274 -0
  58. data/spec/binaryprotocolaccelerated_spec.rb +101 -0
  59. data/spec/client_spec.rb +81 -0
  60. data/spec/deprecation_spec.rb +443 -0
  61. data/spec/exception_spec.rb +123 -0
  62. data/spec/gen-rb/NonblockingService.rb +268 -0
  63. data/spec/gen-rb/ThriftSpec_constants.rb +11 -0
  64. data/spec/gen-rb/ThriftSpec_types.rb +134 -0
  65. data/spec/httpclient_spec.rb +31 -0
  66. data/spec/httpserver_spec.rb +98 -0
  67. data/spec/nonblockingserver_spec.rb +245 -0
  68. data/spec/processor_spec.rb +64 -0
  69. data/spec/protocol_spec.rb +142 -0
  70. data/spec/serializer_spec.rb +52 -0
  71. data/spec/server_spec.rb +141 -0
  72. data/spec/socket_spec.rb +97 -0
  73. data/spec/socket_spec_shared.rb +85 -0
  74. data/spec/spec_helper.rb +35 -0
  75. data/spec/struct_spec.rb +244 -0
  76. data/spec/transport_spec.rb +359 -0
  77. data/spec/types_spec.rb +98 -0
  78. data/spec/unixsocket_spec.rb +90 -0
  79. data/thrift.gemspec +33 -0
  80. data.tar.gz.sig +0 -0
  81. metadata +200 -0
  82. metadata.gz.sig +0 -0
@@ -0,0 +1,359 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ class ThriftTransportSpec < Spec::ExampleGroup
4
+ include Thrift
5
+
6
+ describe TransportException do
7
+ it "should make type accessible" do
8
+ exc = TransportException.new(TransportException::ALREADY_OPEN, "msg")
9
+ exc.type.should == TransportException::ALREADY_OPEN
10
+ exc.message.should == "msg"
11
+ end
12
+ end
13
+
14
+ describe Transport do
15
+ it "should read the specified size" do
16
+ transport = Transport.new
17
+ transport.should_receive(:read).with(40).ordered.and_return("10 letters")
18
+ transport.should_receive(:read).with(30).ordered.and_return("fifteen letters")
19
+ transport.should_receive(:read).with(15).ordered.and_return("more characters")
20
+ transport.read_all(40).should == "10 lettersfifteen lettersmore characters"
21
+ end
22
+
23
+ it "should stub out the rest of the methods" do
24
+ # can't test for stubbiness, so just make sure they're defined
25
+ [:open?, :open, :close, :read, :write, :flush].each do |sym|
26
+ Transport.method_defined?(sym).should be_true
27
+ end
28
+ end
29
+
30
+ it "should alias << to write" do
31
+ Transport.instance_method(:<<).should == Transport.instance_method(:write)
32
+ end
33
+ end
34
+
35
+ describe ServerTransport do
36
+ it "should stub out its methods" do
37
+ [:listen, :accept, :close].each do |sym|
38
+ ServerTransport.method_defined?(sym).should be_true
39
+ end
40
+ end
41
+ end
42
+
43
+ describe TransportFactory do
44
+ it "should return the transport it's given" do
45
+ transport = mock("Transport")
46
+ TransportFactory.new.get_transport(transport).should eql(transport)
47
+ end
48
+ end
49
+
50
+ describe BufferedTransport do
51
+ it "should pass through everything but write/flush/read" do
52
+ trans = mock("Transport")
53
+ trans.should_receive(:open?).ordered.and_return("+ open?")
54
+ trans.should_receive(:open).ordered.and_return("+ open")
55
+ trans.should_receive(:flush).ordered # from the close
56
+ trans.should_receive(:close).ordered.and_return("+ close")
57
+ btrans = BufferedTransport.new(trans)
58
+ btrans.open?.should == "+ open?"
59
+ btrans.open.should == "+ open"
60
+ btrans.close.should == "+ close"
61
+ end
62
+
63
+ it "should buffer reads in chunks of #{BufferedTransport::DEFAULT_BUFFER}" do
64
+ trans = mock("Transport")
65
+ trans.should_receive(:read).with(BufferedTransport::DEFAULT_BUFFER).and_return("lorum ipsum dolor emet")
66
+ btrans = BufferedTransport.new(trans)
67
+ btrans.read(6).should == "lorum "
68
+ btrans.read(6).should == "ipsum "
69
+ btrans.read(6).should == "dolor "
70
+ btrans.read(6).should == "emet"
71
+ end
72
+
73
+ it "should buffer writes and send them on flush" do
74
+ trans = mock("Transport")
75
+ btrans = BufferedTransport.new(trans)
76
+ btrans.write("one/")
77
+ btrans.write("two/")
78
+ btrans.write("three/")
79
+ trans.should_receive(:write).with("one/two/three/").ordered
80
+ trans.should_receive(:flush).ordered
81
+ btrans.flush
82
+ end
83
+
84
+ it "should only send buffered data once" do
85
+ trans = mock("Transport")
86
+ btrans = BufferedTransport.new(trans)
87
+ btrans.write("one/")
88
+ btrans.write("two/")
89
+ btrans.write("three/")
90
+ trans.should_receive(:write).with("one/two/three/")
91
+ trans.stub!(:flush)
92
+ btrans.flush
93
+ # Nothing to flush with no data
94
+ btrans.flush
95
+ end
96
+
97
+ it "should flush on close" do
98
+ trans = mock("Transport")
99
+ trans.should_receive(:close)
100
+ btrans = BufferedTransport.new(trans)
101
+ btrans.should_receive(:flush)
102
+ btrans.close
103
+ end
104
+
105
+ it "should not write to socket if there's no data" do
106
+ trans = mock("Transport")
107
+ trans.should_receive(:flush)
108
+ btrans = BufferedTransport.new(trans)
109
+ btrans.flush
110
+ end
111
+ end
112
+
113
+ describe BufferedTransportFactory do
114
+ it "should wrap the given transport in a BufferedTransport" do
115
+ trans = mock("Transport")
116
+ btrans = mock("BufferedTransport")
117
+ BufferedTransport.should_receive(:new).with(trans).and_return(btrans)
118
+ BufferedTransportFactory.new.get_transport(trans).should == btrans
119
+ end
120
+ end
121
+
122
+ describe FramedTransport do
123
+ before(:each) do
124
+ @trans = mock("Transport")
125
+ end
126
+
127
+ it "should pass through open?/open/close" do
128
+ ftrans = FramedTransport.new(@trans)
129
+ @trans.should_receive(:open?).ordered.and_return("+ open?")
130
+ @trans.should_receive(:open).ordered.and_return("+ open")
131
+ @trans.should_receive(:close).ordered.and_return("+ close")
132
+ ftrans.open?.should == "+ open?"
133
+ ftrans.open.should == "+ open"
134
+ ftrans.close.should == "+ close"
135
+ end
136
+
137
+ it "should pass through read when read is turned off" do
138
+ ftrans = FramedTransport.new(@trans, false, true)
139
+ @trans.should_receive(:read).with(17).ordered.and_return("+ read")
140
+ ftrans.read(17).should == "+ read"
141
+ end
142
+
143
+ it "should pass through write/flush when write is turned off" do
144
+ ftrans = FramedTransport.new(@trans, true, false)
145
+ @trans.should_receive(:write).with("foo").ordered.and_return("+ write")
146
+ @trans.should_receive(:flush).ordered.and_return("+ flush")
147
+ ftrans.write("foo").should == "+ write"
148
+ ftrans.flush.should == "+ flush"
149
+ end
150
+
151
+ it "should return a full frame if asked for >= the frame's length" do
152
+ frame = "this is a frame"
153
+ @trans.should_receive(:read_all).with(4).and_return("\000\000\000\017")
154
+ @trans.should_receive(:read_all).with(frame.length).and_return(frame)
155
+ FramedTransport.new(@trans).read(frame.length + 10).should == frame
156
+ end
157
+
158
+ it "should return slices of the frame when asked for < the frame's length" do
159
+ frame = "this is a frame"
160
+ @trans.should_receive(:read_all).with(4).and_return("\000\000\000\017")
161
+ @trans.should_receive(:read_all).with(frame.length).and_return(frame)
162
+ ftrans = FramedTransport.new(@trans)
163
+ ftrans.read(4).should == "this"
164
+ ftrans.read(4).should == " is "
165
+ ftrans.read(16).should == "a frame"
166
+ end
167
+
168
+ it "should return nothing if asked for <= 0" do
169
+ FramedTransport.new(@trans).read(-2).should == ""
170
+ end
171
+
172
+ it "should pull a new frame when the first is exhausted" do
173
+ frame = "this is a frame"
174
+ frame2 = "yet another frame"
175
+ @trans.should_receive(:read_all).with(4).and_return("\000\000\000\017", "\000\000\000\021")
176
+ @trans.should_receive(:read_all).with(frame.length).and_return(frame)
177
+ @trans.should_receive(:read_all).with(frame2.length).and_return(frame2)
178
+ ftrans = FramedTransport.new(@trans)
179
+ ftrans.read(4).should == "this"
180
+ ftrans.read(8).should == " is a fr"
181
+ ftrans.read(6).should == "ame"
182
+ ftrans.read(4).should == "yet "
183
+ ftrans.read(16).should == "another frame"
184
+ end
185
+
186
+ it "should buffer writes" do
187
+ ftrans = FramedTransport.new(@trans)
188
+ @trans.should_not_receive(:write)
189
+ ftrans.write("foo")
190
+ ftrans.write("bar")
191
+ ftrans.write("this is a frame")
192
+ end
193
+
194
+ it "should write slices of the buffer" do
195
+ ftrans = FramedTransport.new(@trans)
196
+ ftrans.write("foobar", 3)
197
+ ftrans.write("barfoo", 1)
198
+ @trans.stub!(:flush)
199
+ @trans.should_receive(:write).with("\000\000\000\004foob")
200
+ ftrans.flush
201
+ end
202
+
203
+ it "should flush frames with a 4-byte header" do
204
+ ftrans = FramedTransport.new(@trans)
205
+ @trans.should_receive(:write).with("\000\000\000\035one/two/three/this is a frame").ordered
206
+ @trans.should_receive(:flush).ordered
207
+ ftrans.write("one/")
208
+ ftrans.write("two/")
209
+ ftrans.write("three/")
210
+ ftrans.write("this is a frame")
211
+ ftrans.flush
212
+ end
213
+
214
+ it "should not flush the same buffered data twice" do
215
+ ftrans = FramedTransport.new(@trans)
216
+ @trans.should_receive(:write).with("\000\000\000\007foo/bar")
217
+ @trans.stub!(:flush)
218
+ ftrans.write("foo")
219
+ ftrans.write("/bar")
220
+ ftrans.flush
221
+ @trans.should_receive(:write).with("\000\000\000\000")
222
+ ftrans.flush
223
+ end
224
+
225
+ it "should refill its buffer when borrow is called and it is empty" do
226
+ ftrans = FramedTransport.new(@trans)
227
+ @trans.should_receive(:read_all).with(4).and_return([10].pack("N"))
228
+ @trans.should_receive(:read_all).with(10).and_return("1234567890")
229
+ ftrans.borrow(10).should == "1234567890"
230
+ end
231
+
232
+ it "should not consume any data when borrow is called" do
233
+ ftrans = FramedTransport.new(@trans)
234
+ @trans.should_receive(:read_all).with(4).and_return([10].pack("N"))
235
+ @trans.should_receive(:read_all).with(10).and_return("1234567890")
236
+ ftrans.borrow(10).should == "1234567890"
237
+ ftrans.borrow(10).should == "1234567890"
238
+ end
239
+
240
+ it "should remove data from the buffer when consume! is called" do
241
+ ftrans = FramedTransport.new(@trans)
242
+ @trans.should_receive(:read_all).with(4).ordered.and_return([10].pack("N"))
243
+ @trans.should_receive(:read_all).with(10).ordered.and_return("1234567890")
244
+ ftrans.borrow(5).should == "1234567890"
245
+ ftrans.consume!(5).should == "12345"
246
+ ftrans.borrow(5).should == "67890"
247
+ end
248
+
249
+ it "should raise an EOFError when it is out of data and borrow is called" do
250
+ ftrans = FramedTransport.new(@trans)
251
+ @trans.should_receive(:read_all).with(4).ordered.and_return([10].pack("N"), [0].pack("N"))
252
+ @trans.should_receive(:read_all).with(10).ordered.and_return("1234567890")
253
+ @trans.should_receive(:read_all).with(0).ordered.and_return("")
254
+ ftrans.borrow(10).should == "1234567890"
255
+ ftrans.consume!(10).should == "1234567890"
256
+ lambda {ftrans.borrow(10)}.should raise_error(EOFError)
257
+ end
258
+ end
259
+
260
+ describe FramedTransportFactory do
261
+ it "should wrap the given transport in a FramedTransport" do
262
+ trans = mock("Transport")
263
+ FramedTransport.should_receive(:new).with(trans)
264
+ FramedTransportFactory.new.get_transport(trans)
265
+ end
266
+ end
267
+
268
+ describe MemoryBuffer do
269
+ before(:each) do
270
+ @buffer = MemoryBuffer.new
271
+ end
272
+
273
+ it "should accept a buffer on input and use it directly" do
274
+ s = "this is a test"
275
+ @buffer = MemoryBuffer.new(s)
276
+ @buffer.read(4).should == "this"
277
+ s.slice!(-4..-1)
278
+ @buffer.read(@buffer.available).should == " is a "
279
+ end
280
+
281
+ it "should always remain open" do
282
+ @buffer.should be_open
283
+ @buffer.close
284
+ @buffer.should be_open
285
+ end
286
+
287
+ it "should respond to peek and available" do
288
+ @buffer.write "some data"
289
+ @buffer.peek.should be_true
290
+ @buffer.available.should == 9
291
+ @buffer.read(4)
292
+ @buffer.peek.should be_true
293
+ @buffer.available.should == 5
294
+ @buffer.read(16)
295
+ @buffer.peek.should be_false
296
+ @buffer.available.should == 0
297
+ end
298
+
299
+ it "should be able to reset the buffer" do
300
+ @buffer.write "test data"
301
+ @buffer.reset_buffer("foobar")
302
+ @buffer.available.should == 6
303
+ @buffer.read(10).should == "foobar"
304
+ @buffer.reset_buffer
305
+ @buffer.available.should == 0
306
+ end
307
+
308
+ it "should copy the given string whne resetting the buffer" do
309
+ s = "this is a test"
310
+ @buffer.reset_buffer(s)
311
+ @buffer.available.should == 14
312
+ @buffer.read(10)
313
+ @buffer.available.should == 4
314
+ s.should == "this is a test"
315
+ end
316
+
317
+ it "should return from read what was given in write" do
318
+ @buffer.write "test data"
319
+ @buffer.read(4).should == "test"
320
+ @buffer.read(10).should == " data"
321
+ @buffer.read(10).should == ""
322
+ @buffer.write "foo"
323
+ @buffer.write " bar"
324
+ @buffer.read(10).should == "foo bar"
325
+ end
326
+ end
327
+
328
+ describe IOStreamTransport do
329
+ before(:each) do
330
+ @input = mock("Input", :closed? => false)
331
+ @output = mock("Output", :closed? => false)
332
+ @trans = IOStreamTransport.new(@input, @output)
333
+ end
334
+
335
+ it "should be open as long as both input or output are open" do
336
+ @trans.should be_open
337
+ @input.stub!(:closed?).and_return(true)
338
+ @trans.should be_open
339
+ @input.stub!(:closed?).and_return(false)
340
+ @output.stub!(:closed?).and_return(true)
341
+ @trans.should be_open
342
+ @input.stub!(:closed?).and_return(true)
343
+ @trans.should_not be_open
344
+ end
345
+
346
+ it "should pass through read/write to input/output" do
347
+ @input.should_receive(:read).with(17).and_return("+ read")
348
+ @output.should_receive(:write).with("foobar").and_return("+ write")
349
+ @trans.read(17).should == "+ read"
350
+ @trans.write("foobar").should == "+ write"
351
+ end
352
+
353
+ it "should close both input and output when closed" do
354
+ @input.should_receive(:close)
355
+ @output.should_receive(:close)
356
+ @trans.close
357
+ end
358
+ end
359
+ end
@@ -0,0 +1,98 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ require File.dirname(__FILE__) + '/gen-rb/ThriftSpec_types'
3
+
4
+ class ThriftTypesSpec < Spec::ExampleGroup
5
+ include Thrift
6
+
7
+ before(:each) do
8
+ Thrift.type_checking = true
9
+ end
10
+
11
+ after(:each) do
12
+ Thrift.type_checking = false
13
+ end
14
+
15
+ describe "Type checking" do
16
+ it "should return the proper name for each type" do
17
+ Thrift.type_name(Types::I16).should == "Types::I16"
18
+ Thrift.type_name(Types::VOID).should == "Types::VOID"
19
+ Thrift.type_name(Types::LIST).should == "Types::LIST"
20
+ Thrift.type_name(42).should be_nil
21
+ end
22
+
23
+ it "should check types properly" do
24
+ # lambda { Thrift.check_type(nil, Types::STOP) }.should raise_error(TypeError)
25
+ lambda { Thrift.check_type(3, {:type => Types::STOP}, :foo) }.should raise_error(TypeError)
26
+ lambda { Thrift.check_type(nil, {:type => Types::VOID}, :foo) }.should_not raise_error(TypeError)
27
+ lambda { Thrift.check_type(3, {:type => Types::VOID}, :foo) }.should raise_error(TypeError)
28
+ lambda { Thrift.check_type(true, {:type => Types::BOOL}, :foo) }.should_not raise_error(TypeError)
29
+ lambda { Thrift.check_type(3, {:type => Types::BOOL}, :foo) }.should raise_error(TypeError)
30
+ lambda { Thrift.check_type(42, {:type => Types::BYTE}, :foo) }.should_not raise_error(TypeError)
31
+ lambda { Thrift.check_type(42, {:type => Types::I16}, :foo) }.should_not raise_error(TypeError)
32
+ lambda { Thrift.check_type(42, {:type => Types::I32}, :foo) }.should_not raise_error(TypeError)
33
+ lambda { Thrift.check_type(42, {:type => Types::I64}, :foo) }.should_not raise_error(TypeError)
34
+ lambda { Thrift.check_type(3.14, {:type => Types::I32}, :foo) }.should raise_error(TypeError)
35
+ lambda { Thrift.check_type(3.14, {:type => Types::DOUBLE}, :foo) }.should_not raise_error(TypeError)
36
+ lambda { Thrift.check_type(3, {:type => Types::DOUBLE}, :foo) }.should raise_error(TypeError)
37
+ lambda { Thrift.check_type("3", {:type => Types::STRING}, :foo) }.should_not raise_error(TypeError)
38
+ lambda { Thrift.check_type(3, {:type => Types::STRING}, :foo) }.should raise_error(TypeError)
39
+ hello = SpecNamespace::Hello.new
40
+ lambda { Thrift.check_type(hello, {:type => Types::STRUCT, :class => SpecNamespace::Hello}, :foo) }.should_not raise_error(TypeError)
41
+ lambda { Thrift.check_type("foo", {:type => Types::STRUCT}, :foo) }.should raise_error(TypeError)
42
+ lambda { Thrift.check_type({:foo => 1}, {:type => Types::MAP}, :foo) }.should_not raise_error(TypeError)
43
+ lambda { Thrift.check_type([1], {:type => Types::MAP}, :foo) }.should raise_error(TypeError)
44
+ lambda { Thrift.check_type([1], {:type => Types::LIST}, :foo) }.should_not raise_error(TypeError)
45
+ lambda { Thrift.check_type({:foo => 1}, {:type => Types::LIST}, :foo) }.should raise_error(TypeError)
46
+ lambda { Thrift.check_type(Set.new([1,2]), {:type => Types::SET}, :foo) }.should_not raise_error(TypeError)
47
+ lambda { Thrift.check_type([1,2], {:type => Types::SET}, :foo) }.should raise_error(TypeError)
48
+ lambda { Thrift.check_type({:foo => true}, {:type => Types::SET}, :foo) }.should raise_error(TypeError)
49
+ end
50
+
51
+ it "should error out if nil is passed and skip_types is false" do
52
+ lambda { Thrift.check_type(nil, {:type => Types::BOOL}, :foo, false) }.should raise_error(TypeError)
53
+ lambda { Thrift.check_type(nil, {:type => Types::BYTE}, :foo, false) }.should raise_error(TypeError)
54
+ lambda { Thrift.check_type(nil, {:type => Types::I16}, :foo, false) }.should raise_error(TypeError)
55
+ lambda { Thrift.check_type(nil, {:type => Types::I32}, :foo, false) }.should raise_error(TypeError)
56
+ lambda { Thrift.check_type(nil, {:type => Types::I64}, :foo, false) }.should raise_error(TypeError)
57
+ lambda { Thrift.check_type(nil, {:type => Types::DOUBLE}, :foo, false) }.should raise_error(TypeError)
58
+ lambda { Thrift.check_type(nil, {:type => Types::STRING}, :foo, false) }.should raise_error(TypeError)
59
+ lambda { Thrift.check_type(nil, {:type => Types::STRUCT}, :foo, false) }.should raise_error(TypeError)
60
+ lambda { Thrift.check_type(nil, {:type => Types::LIST}, :foo, false) }.should raise_error(TypeError)
61
+ lambda { Thrift.check_type(nil, {:type => Types::SET}, :foo, false) }.should raise_error(TypeError)
62
+ lambda { Thrift.check_type(nil, {:type => Types::MAP}, :foo, false) }.should raise_error(TypeError)
63
+ end
64
+
65
+ it "should check element types on containers" do
66
+ field = {:type => Types::LIST, :element => {:type => Types::I32}}
67
+ lambda { Thrift.check_type([1, 2], field, :foo) }.should_not raise_error(TypeError)
68
+ lambda { Thrift.check_type([1, nil, 2], field, :foo) }.should raise_error(TypeError)
69
+ field = {:type => Types::MAP, :key => {:type => Types::I32}, :value => {:type => Types::STRING}}
70
+ lambda { Thrift.check_type({1 => "one", 2 => "two"}, field, :foo) }.should_not raise_error(TypeError)
71
+ lambda { Thrift.check_type({1 => "one", nil => "nil"}, field, :foo) }.should raise_error(TypeError)
72
+ lambda { Thrift.check_type({1 => nil, 2 => "two"}, field, :foo) }.should raise_error(TypeError)
73
+ field = {:type => Types::SET, :element => {:type => Types::I32}}
74
+ lambda { Thrift.check_type(Set.new([1, 2]), field, :foo) }.should_not raise_error(TypeError)
75
+ lambda { Thrift.check_type(Set.new([1, nil, 2]), field, :foo) }.should raise_error(TypeError)
76
+ lambda { Thrift.check_type(Set.new([1, 2.3, 2]), field, :foo) }.should raise_error(TypeError)
77
+
78
+ field = {:type => Types::STRUCT, :class => SpecNamespace::Hello}
79
+ lambda { Thrift.check_type(SpecNamespace::BoolStruct, field, :foo) }.should raise_error(TypeError)
80
+ end
81
+
82
+ it "should give the TypeError a readable message" do
83
+ msg = "Expected Types::STRING, received Fixnum for field foo"
84
+ lambda { Thrift.check_type(3, {:type => Types::STRING}, :foo) }.should raise_error(TypeError, msg)
85
+ msg = "Expected Types::STRING, received Fixnum for field foo.element"
86
+ field = {:type => Types::LIST, :element => {:type => Types::STRING}}
87
+ lambda { Thrift.check_type([3], field, :foo) }.should raise_error(TypeError, msg)
88
+ msg = "Expected Types::I32, received NilClass for field foo.element.key"
89
+ field = {:type => Types::LIST,
90
+ :element => {:type => Types::MAP,
91
+ :key => {:type => Types::I32},
92
+ :value => {:type => Types::I32}}}
93
+ lambda { Thrift.check_type([{nil => 3}], field, :foo) }.should raise_error(TypeError, msg)
94
+ msg = "Expected Types::I32, received NilClass for field foo.element.value"
95
+ lambda { Thrift.check_type([{1 => nil}], field, :foo) }.should raise_error(TypeError, msg)
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,90 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ require 'thrift/transport/unixsocket'
3
+ require File.dirname(__FILE__) + "/socket_spec_shared"
4
+
5
+ class ThriftUNIXSocketSpec < Spec::ExampleGroup
6
+ include Thrift
7
+
8
+ describe UNIXSocket do
9
+ before(:each) do
10
+ @path = '/tmp/thrift_spec_socket'
11
+ @socket = UNIXSocket.new(@path)
12
+ @handle = mock("Handle", :closed? => false)
13
+ @handle.stub!(:close)
14
+ ::UNIXSocket.stub!(:new).and_return(@handle)
15
+ end
16
+
17
+ it_should_behave_like "a socket"
18
+
19
+ it "should raise a TransportException when it cannot open a socket" do
20
+ ::UNIXSocket.should_receive(:new).and_raise(StandardError)
21
+ lambda { @socket.open }.should raise_error(Thrift::TransportException) { |e| e.type.should == Thrift::TransportException::NOT_OPEN }
22
+ end
23
+
24
+ it "should accept an optional timeout" do
25
+ ::UNIXSocket.stub!(:new)
26
+ UNIXSocket.new(@path, 5).timeout.should == 5
27
+ end
28
+ end
29
+
30
+ describe UNIXServerSocket do
31
+ before(:each) do
32
+ @path = '/tmp/thrift_spec_socket'
33
+ @socket = UNIXServerSocket.new(@path)
34
+ end
35
+
36
+ it "should create a handle when calling listen" do
37
+ UNIXServer.should_receive(:new).with(@path)
38
+ @socket.listen
39
+ end
40
+
41
+ it "should create a Thrift::UNIXSocket to wrap accepted sockets" do
42
+ handle = mock("UNIXServer")
43
+ UNIXServer.should_receive(:new).with(@path).and_return(handle)
44
+ @socket.listen
45
+ sock = mock("sock")
46
+ handle.should_receive(:accept).and_return(sock)
47
+ trans = mock("UNIXSocket")
48
+ UNIXSocket.should_receive(:new).and_return(trans)
49
+ trans.should_receive(:handle=).with(sock)
50
+ @socket.accept.should == trans
51
+ end
52
+
53
+ it "should close the handle when closed" do
54
+ handle = mock("UNIXServer", :closed? => false)
55
+ UNIXServer.should_receive(:new).with(@path).and_return(handle)
56
+ @socket.listen
57
+ handle.should_receive(:close)
58
+ File.stub!(:delete)
59
+ @socket.close
60
+ end
61
+
62
+ it "should delete the socket when closed" do
63
+ handle = mock("UNIXServer", :closed? => false)
64
+ UNIXServer.should_receive(:new).with(@path).and_return(handle)
65
+ @socket.listen
66
+ handle.stub!(:close)
67
+ File.should_receive(:delete).with(@path)
68
+ @socket.close
69
+ end
70
+
71
+ it "should return nil when accepting if there is no handle" do
72
+ @socket.accept.should be_nil
73
+ end
74
+
75
+ it "should return true for closed? when appropriate" do
76
+ handle = mock("UNIXServer", :closed? => false)
77
+ UNIXServer.stub!(:new).and_return(handle)
78
+ File.stub!(:delete)
79
+ @socket.listen
80
+ @socket.should_not be_closed
81
+ handle.stub!(:close)
82
+ @socket.close
83
+ @socket.should be_closed
84
+ @socket.listen
85
+ @socket.should_not be_closed
86
+ handle.stub!(:closed?).and_return(true)
87
+ @socket.should be_closed
88
+ end
89
+ end
90
+ end
data/thrift.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{thrift}
5
+ s.version = "0.0.751142"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Kevin Ballard, Kevin Clark, Mark Slee, Evan Weaver"]
9
+ s.cert_chain = ["/Users/eweaver/p/configuration/gem_certificates/evan_weaver-original-public_cert.pem"]
10
+ s.date = %q{2010-02-22}
11
+ s.description = %q{Ruby libraries for Thrift (a language-agnostic RPC system)}
12
+ s.email = %q{}
13
+ s.extensions = ["ext/extconf.rb"]
14
+ s.extra_rdoc_files = ["CHANGELOG", "COPYING", "LICENSE", "README", "ext/binary_protocol_accelerated.c", "ext/binary_protocol_accelerated.h", "ext/constants.h", "ext/extconf.rb", "ext/memory_buffer.c", "ext/memory_buffer.h", "ext/protocol.c", "ext/protocol.h", "ext/struct.c", "ext/struct.h", "ext/thrift_native.c", "lib/thrift.rb", "lib/thrift/client.rb", "lib/thrift/deprecation.rb", "lib/thrift/exceptions.rb", "lib/thrift/processor.rb", "lib/thrift/protocol.rb", "lib/thrift/protocol/binaryprotocol.rb", "lib/thrift/protocol/binaryprotocolaccelerated.rb", "lib/thrift/protocol/tbinaryprotocol.rb", "lib/thrift/protocol/tprotocol.rb", "lib/thrift/serializer.rb", "lib/thrift/server.rb", "lib/thrift/server/httpserver.rb", "lib/thrift/server/nonblockingserver.rb", "lib/thrift/server/thttpserver.rb", "lib/thrift/server/tserver.rb", "lib/thrift/struct.rb", "lib/thrift/thrift.rb", "lib/thrift/transport.rb", "lib/thrift/transport/httpclient.rb", "lib/thrift/transport/socket.rb", "lib/thrift/transport/thttpclient.rb", "lib/thrift/transport/tsocket.rb", "lib/thrift/transport/ttransport.rb", "lib/thrift/transport/unixsocket.rb", "lib/thrift/types.rb"]
15
+ s.files = ["CHANGELOG", "COPYING", "LICENSE", "Makefile.am", "Manifest", "README", "Rakefile", "benchmark/Benchmark.thrift", "benchmark/benchmark.rb", "benchmark/client.rb", "benchmark/gen-rb/BenchmarkService.rb", "benchmark/gen-rb/Benchmark_constants.rb", "benchmark/gen-rb/Benchmark_types.rb", "benchmark/server.rb", "benchmark/thin_server.rb", "ext/binary_protocol_accelerated.c", "ext/binary_protocol_accelerated.h", "ext/constants.h", "ext/extconf.rb", "ext/memory_buffer.c", "ext/memory_buffer.h", "ext/protocol.c", "ext/protocol.h", "ext/struct.c", "ext/struct.h", "ext/thrift_native.c", "lib/thrift.rb", "lib/thrift/client.rb", "lib/thrift/deprecation.rb", "lib/thrift/exceptions.rb", "lib/thrift/processor.rb", "lib/thrift/protocol.rb", "lib/thrift/protocol/binaryprotocol.rb", "lib/thrift/protocol/binaryprotocolaccelerated.rb", "lib/thrift/protocol/tbinaryprotocol.rb", "lib/thrift/protocol/tprotocol.rb", "lib/thrift/serializer.rb", "lib/thrift/server.rb", "lib/thrift/server/httpserver.rb", "lib/thrift/server/nonblockingserver.rb", "lib/thrift/server/thttpserver.rb", "lib/thrift/server/tserver.rb", "lib/thrift/struct.rb", "lib/thrift/thrift.rb", "lib/thrift/transport.rb", "lib/thrift/transport/httpclient.rb", "lib/thrift/transport/socket.rb", "lib/thrift/transport/thttpclient.rb", "lib/thrift/transport/tsocket.rb", "lib/thrift/transport/ttransport.rb", "lib/thrift/transport/unixsocket.rb", "lib/thrift/types.rb", "setup.rb", "spec/ThriftSpec.thrift", "spec/backwards_compatibility_spec.rb", "spec/binaryprotocol_spec.rb", "spec/binaryprotocol_spec_shared.rb", "spec/binaryprotocolaccelerated_spec.rb", "spec/client_spec.rb", "spec/deprecation_spec.rb", "spec/exception_spec.rb", "spec/gen-rb/NonblockingService.rb", "spec/gen-rb/ThriftSpec_constants.rb", "spec/gen-rb/ThriftSpec_types.rb", "spec/httpclient_spec.rb", "spec/httpserver_spec.rb", "spec/nonblockingserver_spec.rb", "spec/processor_spec.rb", "spec/protocol_spec.rb", "spec/serializer_spec.rb", "spec/server_spec.rb", "spec/socket_spec.rb", "spec/socket_spec_shared.rb", "spec/spec_helper.rb", "spec/struct_spec.rb", "spec/transport_spec.rb", "spec/types_spec.rb", "spec/unixsocket_spec.rb", "thrift.gemspec"]
16
+ s.homepage = %q{http://blog.evanweaver.com/files/doc/fauna/thrift/}
17
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Thrift", "--main", "README"]
18
+ s.require_paths = ["lib", "ext"]
19
+ s.rubyforge_project = %q{fauna}
20
+ s.rubygems_version = %q{1.3.5}
21
+ s.signing_key = %q{/Users/eweaver/p/configuration/gem_certificates/evan_weaver-original-private_key.pem}
22
+ s.summary = %q{Ruby libraries for Thrift (a language-agnostic RPC system)}
23
+
24
+ if s.respond_to? :specification_version then
25
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
26
+ s.specification_version = 3
27
+
28
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
29
+ else
30
+ end
31
+ else
32
+ end
33
+ end
data.tar.gz.sig ADDED
Binary file