thrift 0.0.751142

Sign up to get free protection for your applications and to get access to all the features.
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,268 @@
1
+ #
2
+ # Autogenerated by Thrift
3
+ #
4
+ # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5
+ #
6
+
7
+ require 'thrift'
8
+ require 'thrift/protocol'
9
+ require File.dirname(__FILE__) + '/ThriftSpec_types'
10
+
11
+ module SpecNamespace
12
+ module NonblockingService
13
+ class Client
14
+ include ::Thrift::Client
15
+
16
+ def greeting(english)
17
+ send_greeting(english)
18
+ return recv_greeting()
19
+ end
20
+
21
+ def send_greeting(english)
22
+ send_message('greeting', Greeting_args, :english => english)
23
+ end
24
+
25
+ def recv_greeting()
26
+ result = receive_message(Greeting_result)
27
+ return result.success unless result.success.nil?
28
+ raise Thrift::ApplicationException.new(Thrift::ApplicationException::MISSING_RESULT, 'greeting failed: unknown result')
29
+ end
30
+
31
+ def block()
32
+ send_block()
33
+ return recv_block()
34
+ end
35
+
36
+ def send_block()
37
+ send_message('block', Block_args)
38
+ end
39
+
40
+ def recv_block()
41
+ result = receive_message(Block_result)
42
+ return result.success unless result.success.nil?
43
+ raise Thrift::ApplicationException.new(Thrift::ApplicationException::MISSING_RESULT, 'block failed: unknown result')
44
+ end
45
+
46
+ def unblock(n)
47
+ send_unblock(n)
48
+ end
49
+
50
+ def send_unblock(n)
51
+ send_message('unblock', Unblock_args, :n => n)
52
+ end
53
+ def shutdown()
54
+ send_shutdown()
55
+ end
56
+
57
+ def send_shutdown()
58
+ send_message('shutdown', Shutdown_args)
59
+ end
60
+ def sleep(seconds)
61
+ send_sleep(seconds)
62
+ recv_sleep()
63
+ end
64
+
65
+ def send_sleep(seconds)
66
+ send_message('sleep', Sleep_args, :seconds => seconds)
67
+ end
68
+
69
+ def recv_sleep()
70
+ result = receive_message(Sleep_result)
71
+ return
72
+ end
73
+
74
+ end
75
+
76
+ class Processor
77
+ include ::Thrift::Processor
78
+
79
+ def process_greeting(seqid, iprot, oprot)
80
+ args = read_args(iprot, Greeting_args)
81
+ result = Greeting_result.new()
82
+ result.success = @handler.greeting(args.english)
83
+ write_result(result, oprot, 'greeting', seqid)
84
+ end
85
+
86
+ def process_block(seqid, iprot, oprot)
87
+ args = read_args(iprot, Block_args)
88
+ result = Block_result.new()
89
+ result.success = @handler.block()
90
+ write_result(result, oprot, 'block', seqid)
91
+ end
92
+
93
+ def process_unblock(seqid, iprot, oprot)
94
+ args = read_args(iprot, Unblock_args)
95
+ @handler.unblock(args.n)
96
+ return
97
+ end
98
+
99
+ def process_shutdown(seqid, iprot, oprot)
100
+ args = read_args(iprot, Shutdown_args)
101
+ @handler.shutdown()
102
+ return
103
+ end
104
+
105
+ def process_sleep(seqid, iprot, oprot)
106
+ args = read_args(iprot, Sleep_args)
107
+ result = Sleep_result.new()
108
+ @handler.sleep(args.seconds)
109
+ write_result(result, oprot, 'sleep', seqid)
110
+ end
111
+
112
+ end
113
+
114
+ # HELPER FUNCTIONS AND STRUCTURES
115
+
116
+ class Greeting_args
117
+ include ::Thrift::Struct
118
+ ENGLISH = 1
119
+
120
+ Thrift::Struct.field_accessor self, :english
121
+ FIELDS = {
122
+ ENGLISH => {:type => Thrift::Types::BOOL, :name => 'english'}
123
+ }
124
+
125
+ def struct_fields; FIELDS; end
126
+
127
+ def validate
128
+ end
129
+
130
+ end
131
+
132
+ class Greeting_result
133
+ include ::Thrift::Struct
134
+ SUCCESS = 0
135
+
136
+ Thrift::Struct.field_accessor self, :success
137
+ FIELDS = {
138
+ SUCCESS => {:type => Thrift::Types::STRUCT, :name => 'success', :class => SpecNamespace::Hello}
139
+ }
140
+
141
+ def struct_fields; FIELDS; end
142
+
143
+ def validate
144
+ end
145
+
146
+ end
147
+
148
+ class Block_args
149
+ include ::Thrift::Struct
150
+
151
+ FIELDS = {
152
+
153
+ }
154
+
155
+ def struct_fields; FIELDS; end
156
+
157
+ def validate
158
+ end
159
+
160
+ end
161
+
162
+ class Block_result
163
+ include ::Thrift::Struct
164
+ SUCCESS = 0
165
+
166
+ Thrift::Struct.field_accessor self, :success
167
+ FIELDS = {
168
+ SUCCESS => {:type => Thrift::Types::BOOL, :name => 'success'}
169
+ }
170
+
171
+ def struct_fields; FIELDS; end
172
+
173
+ def validate
174
+ end
175
+
176
+ end
177
+
178
+ class Unblock_args
179
+ include ::Thrift::Struct
180
+ N = 1
181
+
182
+ Thrift::Struct.field_accessor self, :n
183
+ FIELDS = {
184
+ N => {:type => Thrift::Types::I32, :name => 'n'}
185
+ }
186
+
187
+ def struct_fields; FIELDS; end
188
+
189
+ def validate
190
+ end
191
+
192
+ end
193
+
194
+ class Unblock_result
195
+ include ::Thrift::Struct
196
+
197
+ FIELDS = {
198
+
199
+ }
200
+
201
+ def struct_fields; FIELDS; end
202
+
203
+ def validate
204
+ end
205
+
206
+ end
207
+
208
+ class Shutdown_args
209
+ include ::Thrift::Struct
210
+
211
+ FIELDS = {
212
+
213
+ }
214
+
215
+ def struct_fields; FIELDS; end
216
+
217
+ def validate
218
+ end
219
+
220
+ end
221
+
222
+ class Shutdown_result
223
+ include ::Thrift::Struct
224
+
225
+ FIELDS = {
226
+
227
+ }
228
+
229
+ def struct_fields; FIELDS; end
230
+
231
+ def validate
232
+ end
233
+
234
+ end
235
+
236
+ class Sleep_args
237
+ include ::Thrift::Struct
238
+ SECONDS = 1
239
+
240
+ Thrift::Struct.field_accessor self, :seconds
241
+ FIELDS = {
242
+ SECONDS => {:type => Thrift::Types::DOUBLE, :name => 'seconds'}
243
+ }
244
+
245
+ def struct_fields; FIELDS; end
246
+
247
+ def validate
248
+ end
249
+
250
+ end
251
+
252
+ class Sleep_result
253
+ include ::Thrift::Struct
254
+
255
+ FIELDS = {
256
+
257
+ }
258
+
259
+ def struct_fields; FIELDS; end
260
+
261
+ def validate
262
+ end
263
+
264
+ end
265
+
266
+ end
267
+
268
+ end
@@ -0,0 +1,11 @@
1
+ #
2
+ # Autogenerated by Thrift
3
+ #
4
+ # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5
+ #
6
+
7
+ require 'thrift/protocol'
8
+ require File.dirname(__FILE__) + '/ThriftSpec_types'
9
+
10
+ module SpecNamespace
11
+ end
@@ -0,0 +1,134 @@
1
+ #
2
+ # Autogenerated by Thrift
3
+ #
4
+ # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5
+ #
6
+
7
+ require 'thrift/protocol'
8
+
9
+ module SpecNamespace
10
+ class Hello
11
+ include ::Thrift::Struct
12
+ GREETING = 1
13
+
14
+ Thrift::Struct.field_accessor self, :greeting
15
+ FIELDS = {
16
+ GREETING => {:type => Thrift::Types::STRING, :name => 'greeting', :default => %q"hello world"}
17
+ }
18
+
19
+ def struct_fields; FIELDS; end
20
+
21
+ def validate
22
+ end
23
+
24
+ end
25
+
26
+ class Foo
27
+ include ::Thrift::Struct
28
+ SIMPLE = 1
29
+ WORDS = 2
30
+ HELLO = 3
31
+ INTS = 4
32
+ COMPLEX = 5
33
+ SHORTS = 6
34
+ OPT_STRING = 7
35
+
36
+ Thrift::Struct.field_accessor self, :simple, :words, :hello, :ints, :complex, :shorts, :opt_string
37
+ FIELDS = {
38
+ SIMPLE => {:type => Thrift::Types::I32, :name => 'simple', :default => 53},
39
+ WORDS => {:type => Thrift::Types::STRING, :name => 'words', :default => %q"words"},
40
+ HELLO => {:type => Thrift::Types::STRUCT, :name => 'hello', :default => Hello.new({
41
+ %q"greeting" => %q"hello, world!",
42
+ }), :class => SpecNamespace::Hello},
43
+ INTS => {:type => Thrift::Types::LIST, :name => 'ints', :default => [
44
+ 1,
45
+ 2,
46
+ 2,
47
+ 3,
48
+ ], :element => {:type => Thrift::Types::I32}},
49
+ COMPLEX => {:type => Thrift::Types::MAP, :name => 'complex', :key => {:type => Thrift::Types::I32}, :value => {:type => Thrift::Types::MAP, :key => {:type => Thrift::Types::STRING}, :value => {:type => Thrift::Types::DOUBLE}}},
50
+ SHORTS => {:type => Thrift::Types::SET, :name => 'shorts', :default => Set.new([ 5,
51
+ 17,
52
+ 239,
53
+ ]), :element => {:type => Thrift::Types::I16}},
54
+ OPT_STRING => {:type => Thrift::Types::STRING, :name => 'opt_string', :optional => true}
55
+ }
56
+
57
+ def struct_fields; FIELDS; end
58
+
59
+ def validate
60
+ end
61
+
62
+ end
63
+
64
+ class BoolStruct
65
+ include ::Thrift::Struct
66
+ YESNO = 1
67
+
68
+ Thrift::Struct.field_accessor self, :yesno
69
+ FIELDS = {
70
+ YESNO => {:type => Thrift::Types::BOOL, :name => 'yesno', :default => true}
71
+ }
72
+
73
+ def struct_fields; FIELDS; end
74
+
75
+ def validate
76
+ end
77
+
78
+ end
79
+
80
+ class SimpleList
81
+ include ::Thrift::Struct
82
+ BOOLS = 1
83
+ BYTES = 2
84
+ I16S = 3
85
+ I32S = 4
86
+ I64S = 5
87
+ DOUBLES = 6
88
+ STRINGS = 7
89
+ MAPS = 8
90
+ LISTS = 9
91
+ SETS = 10
92
+ HELLOS = 11
93
+
94
+ Thrift::Struct.field_accessor self, :bools, :bytes, :i16s, :i32s, :i64s, :doubles, :strings, :maps, :lists, :sets, :hellos
95
+ FIELDS = {
96
+ BOOLS => {:type => Thrift::Types::LIST, :name => 'bools', :element => {:type => Thrift::Types::BOOL}},
97
+ BYTES => {:type => Thrift::Types::LIST, :name => 'bytes', :element => {:type => Thrift::Types::BYTE}},
98
+ I16S => {:type => Thrift::Types::LIST, :name => 'i16s', :element => {:type => Thrift::Types::I16}},
99
+ I32S => {:type => Thrift::Types::LIST, :name => 'i32s', :element => {:type => Thrift::Types::I32}},
100
+ I64S => {:type => Thrift::Types::LIST, :name => 'i64s', :element => {:type => Thrift::Types::I64}},
101
+ DOUBLES => {:type => Thrift::Types::LIST, :name => 'doubles', :element => {:type => Thrift::Types::DOUBLE}},
102
+ STRINGS => {:type => Thrift::Types::LIST, :name => 'strings', :element => {:type => Thrift::Types::STRING}},
103
+ MAPS => {:type => Thrift::Types::LIST, :name => 'maps', :element => {:type => Thrift::Types::MAP, :key => {:type => Thrift::Types::I16}, :value => {:type => Thrift::Types::I16}}},
104
+ LISTS => {:type => Thrift::Types::LIST, :name => 'lists', :element => {:type => Thrift::Types::LIST, :element => {:type => Thrift::Types::I16}}},
105
+ SETS => {:type => Thrift::Types::LIST, :name => 'sets', :element => {:type => Thrift::Types::SET, :element => {:type => Thrift::Types::I16}}},
106
+ HELLOS => {:type => Thrift::Types::LIST, :name => 'hellos', :element => {:type => Thrift::Types::STRUCT, :class => SpecNamespace::Hello}}
107
+ }
108
+
109
+ def struct_fields; FIELDS; end
110
+
111
+ def validate
112
+ end
113
+
114
+ end
115
+
116
+ class Xception < Thrift::Exception
117
+ include ::Thrift::Struct
118
+ MESSAGE = 1
119
+ CODE = 2
120
+
121
+ Thrift::Struct.field_accessor self, :message, :code
122
+ FIELDS = {
123
+ MESSAGE => {:type => Thrift::Types::STRING, :name => 'message'},
124
+ CODE => {:type => Thrift::Types::I32, :name => 'code', :default => 1}
125
+ }
126
+
127
+ def struct_fields; FIELDS; end
128
+
129
+ def validate
130
+ end
131
+
132
+ end
133
+
134
+ end
@@ -0,0 +1,31 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ require 'thrift/transport/httpclient'
3
+
4
+ class ThriftHTTPClientSpec < Spec::ExampleGroup
5
+ include Thrift
6
+
7
+ describe HTTPClient do
8
+ before(:each) do
9
+ @client = HTTPClient.new("http://my.domain.com/path/to/service")
10
+ end
11
+
12
+ it "should always be open" do
13
+ @client.should be_open
14
+ @client.close
15
+ @client.should be_open
16
+ end
17
+
18
+ it "should post via HTTP and return the results" do
19
+ @client.write "a test"
20
+ @client.write " frame"
21
+ Net::HTTP.should_receive(:new).with("my.domain.com", 80).and_return do
22
+ mock("Net::HTTP").tee do |http|
23
+ http.should_receive(:use_ssl=).with(false)
24
+ http.should_receive(:post).with("/path/to/service", "a test frame", {"Content-Type"=>"application/x-thrift"}).and_return([nil, "data"])
25
+ end
26
+ end
27
+ @client.flush
28
+ @client.read(10).should == "data"
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,98 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ require 'thrift/server/httpserver'
3
+
4
+ class ThriftHTTPServerSpec < Spec::ExampleGroup
5
+ include Thrift
6
+
7
+ Handler = SimpleMongrelHTTPServer::Handler
8
+
9
+ describe SimpleMongrelHTTPServer do
10
+ it "should have appropriate defaults" do
11
+ mock_factory = mock("BinaryProtocolFactory")
12
+ mock_proc = mock("Processor")
13
+ BinaryProtocolFactory.should_receive(:new).and_return(mock_factory)
14
+ Mongrel::HttpServer.should_receive(:new).with("0.0.0.0", 80).and_return do
15
+ mock("Mongrel::HttpServer").tee do |mock|
16
+ handler = mock("Handler")
17
+ Handler.should_receive(:new).with(mock_proc, mock_factory).and_return(handler)
18
+ mock.should_receive(:register).with("/", handler)
19
+ end
20
+ end
21
+ SimpleMongrelHTTPServer.new(mock_proc)
22
+ end
23
+
24
+ it "should understand :ip, :port, :path, and :protocol_factory" do
25
+ mock_proc = mock("Processor")
26
+ mock_factory = mock("ProtocolFactory")
27
+ Mongrel::HttpServer.should_receive(:new).with("1.2.3.4", 1234).and_return do
28
+ mock("Mongrel::HttpServer").tee do |mock|
29
+ handler = mock("Handler")
30
+ Handler.should_receive(:new).with(mock_proc, mock_factory).and_return(handler)
31
+ mock.should_receive(:register).with("/foo", handler)
32
+ end
33
+ end
34
+ SimpleMongrelHTTPServer.new(mock_proc, :ip => "1.2.3.4", :port => 1234, :path => "foo",
35
+ :protocol_factory => mock_factory)
36
+ end
37
+
38
+ it "should serve using Mongrel::HttpServer" do
39
+ BinaryProtocolFactory.stub!(:new)
40
+ Mongrel::HttpServer.should_receive(:new).and_return do
41
+ mock("Mongrel::HttpServer").tee do |mock|
42
+ Handler.stub!(:new)
43
+ mock.stub!(:register)
44
+ mock.should_receive(:run).and_return do
45
+ mock("Mongrel::HttpServer.run").tee do |runner|
46
+ runner.should_receive(:join)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ SimpleMongrelHTTPServer.new(nil).serve
52
+ end
53
+ end
54
+
55
+ describe SimpleMongrelHTTPServer::Handler do
56
+ before(:each) do
57
+ @processor = mock("Processor")
58
+ @factory = mock("ProtocolFactory")
59
+ @handler = Handler.new(@processor, @factory)
60
+ end
61
+
62
+ it "should return 404 for non-POST requests" do
63
+ request = mock("request", :params => {"REQUEST_METHOD" => "GET"})
64
+ response = mock("response")
65
+ response.should_receive(:start).with(404)
66
+ response.should_not_receive(:start).with(200)
67
+ @handler.process(request, response)
68
+ end
69
+
70
+ it "should serve using application/x-thrift" do
71
+ request = mock("request", :params => {"REQUEST_METHOD" => "POST"}, :body => nil)
72
+ response = mock("response")
73
+ head = mock("head")
74
+ head.should_receive(:[]=).with("Content-Type", "application/x-thrift")
75
+ IOStreamTransport.stub!(:new)
76
+ @factory.stub!(:get_protocol)
77
+ @processor.stub!(:process)
78
+ response.should_receive(:start).with(200).and_yield(head, nil)
79
+ @handler.process(request, response)
80
+ end
81
+
82
+ it "should use the IOStreamTransport" do
83
+ body = mock("body")
84
+ request = mock("request", :params => {"REQUEST_METHOD" => "POST"}, :body => body)
85
+ response = mock("response")
86
+ head = mock("head")
87
+ head.stub!(:[]=)
88
+ out = mock("out")
89
+ protocol = mock("protocol")
90
+ transport = mock("transport")
91
+ IOStreamTransport.should_receive(:new).with(body, out).and_return(transport)
92
+ @factory.should_receive(:get_protocol).with(transport).and_return(protocol)
93
+ @processor.should_receive(:process).with(protocol, protocol)
94
+ response.should_receive(:start).with(200).and_yield(head, out)
95
+ @handler.process(request, response)
96
+ end
97
+ end
98
+ end