slayer-thrift 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. data/CHANGELOG +1 -0
  2. data/InstalledFiles +1 -0
  3. data/Makefile +512 -0
  4. data/Makefile.am +49 -0
  5. data/Makefile.in +512 -0
  6. data/Manifest +103 -0
  7. data/README +43 -0
  8. data/Rakefile +102 -0
  9. data/benchmark/Benchmark.thrift +24 -0
  10. data/benchmark/benchmark.rb +271 -0
  11. data/benchmark/client.rb +74 -0
  12. data/benchmark/gen-rb/benchmark_constants.rb +10 -0
  13. data/benchmark/gen-rb/benchmark_service.rb +80 -0
  14. data/benchmark/gen-rb/benchmark_types.rb +9 -0
  15. data/benchmark/server.rb +82 -0
  16. data/benchmark/thin_server.rb +44 -0
  17. data/debug_proto_test/gen-rb/debug_proto_test_constants.rb +273 -0
  18. data/debug_proto_test/gen-rb/debug_proto_test_types.rb +705 -0
  19. data/debug_proto_test/gen-rb/empty_service.rb +24 -0
  20. data/debug_proto_test/gen-rb/inherited.rb +79 -0
  21. data/debug_proto_test/gen-rb/reverse_order_service.rb +82 -0
  22. data/debug_proto_test/gen-rb/service_for_exception_with_a_map.rb +81 -0
  23. data/debug_proto_test/gen-rb/srv.rb +330 -0
  24. data/ext/binary_protocol_accelerated.c +441 -0
  25. data/ext/binary_protocol_accelerated.h +20 -0
  26. data/ext/compact_protocol.c +618 -0
  27. data/ext/compact_protocol.h +20 -0
  28. data/ext/constants.h +96 -0
  29. data/ext/extconf.rb +30 -0
  30. data/ext/macros.h +41 -0
  31. data/ext/memory_buffer.c +131 -0
  32. data/ext/memory_buffer.h +20 -0
  33. data/ext/protocol.c +185 -0
  34. data/ext/protocol.h +20 -0
  35. data/ext/struct.c +716 -0
  36. data/ext/struct.h +25 -0
  37. data/ext/thrift_native.c +196 -0
  38. data/lib/thrift.rb +64 -0
  39. data/lib/thrift/client.rb +62 -0
  40. data/lib/thrift/core_ext.rb +23 -0
  41. data/lib/thrift/core_ext/fixnum.rb +29 -0
  42. data/lib/thrift/exceptions.rb +84 -0
  43. data/lib/thrift/processor.rb +57 -0
  44. data/lib/thrift/protocol/base_protocol.rb +290 -0
  45. data/lib/thrift/protocol/binary_protocol.rb +229 -0
  46. data/lib/thrift/protocol/binary_protocol_accelerated.rb +39 -0
  47. data/lib/thrift/protocol/compact_protocol.rb +426 -0
  48. data/lib/thrift/serializer/deserializer.rb +33 -0
  49. data/lib/thrift/serializer/serializer.rb +34 -0
  50. data/lib/thrift/server/base_server.rb +31 -0
  51. data/lib/thrift/server/mongrel_http_server.rb +58 -0
  52. data/lib/thrift/server/nonblocking_server.rb +305 -0
  53. data/lib/thrift/server/simple_server.rb +43 -0
  54. data/lib/thrift/server/thread_pool_server.rb +75 -0
  55. data/lib/thrift/server/threaded_server.rb +47 -0
  56. data/lib/thrift/struct.rb +237 -0
  57. data/lib/thrift/struct_union.rb +192 -0
  58. data/lib/thrift/thrift_native.rb +24 -0
  59. data/lib/thrift/transport/base_server_transport.rb +37 -0
  60. data/lib/thrift/transport/base_transport.rb +107 -0
  61. data/lib/thrift/transport/buffered_transport.rb +108 -0
  62. data/lib/thrift/transport/framed_transport.rb +116 -0
  63. data/lib/thrift/transport/http_client_transport.rb +51 -0
  64. data/lib/thrift/transport/io_stream_transport.rb +39 -0
  65. data/lib/thrift/transport/memory_buffer_transport.rb +125 -0
  66. data/lib/thrift/transport/server_socket.rb +63 -0
  67. data/lib/thrift/transport/socket.rb +137 -0
  68. data/lib/thrift/transport/unix_server_socket.rb +60 -0
  69. data/lib/thrift/transport/unix_socket.rb +40 -0
  70. data/lib/thrift/types.rb +101 -0
  71. data/lib/thrift/union.rb +179 -0
  72. data/script/proto_benchmark.rb +121 -0
  73. data/script/read_struct.rb +43 -0
  74. data/script/write_struct.rb +30 -0
  75. data/setup.rb +1585 -0
  76. data/slayer-thrift.gemspec +30 -0
  77. data/spec/ThriftSpec.thrift +132 -0
  78. data/spec/base_protocol_spec.rb +160 -0
  79. data/spec/base_transport_spec.rb +351 -0
  80. data/spec/binary_protocol_accelerated_spec.rb +46 -0
  81. data/spec/binary_protocol_spec.rb +61 -0
  82. data/spec/binary_protocol_spec_shared.rb +375 -0
  83. data/spec/client_spec.rb +100 -0
  84. data/spec/compact_protocol_spec.rb +133 -0
  85. data/spec/exception_spec.rb +142 -0
  86. data/spec/gen-rb/nonblocking_service.rb +272 -0
  87. data/spec/gen-rb/thrift_spec_constants.rb +10 -0
  88. data/spec/gen-rb/thrift_spec_types.rb +345 -0
  89. data/spec/http_client_spec.rb +64 -0
  90. data/spec/mongrel_http_server_spec.rb +117 -0
  91. data/spec/nonblocking_server_spec.rb +265 -0
  92. data/spec/processor_spec.rb +83 -0
  93. data/spec/serializer_spec.rb +69 -0
  94. data/spec/server_socket_spec.rb +80 -0
  95. data/spec/server_spec.rb +160 -0
  96. data/spec/socket_spec.rb +61 -0
  97. data/spec/socket_spec_shared.rb +104 -0
  98. data/spec/spec_helper.rb +58 -0
  99. data/spec/struct_spec.rb +295 -0
  100. data/spec/types_spec.rb +116 -0
  101. data/spec/union_spec.rb +193 -0
  102. data/spec/unix_socket_spec.rb +108 -0
  103. data/thrift.gemspec +30 -0
  104. data/tmp/thrift-0.7.0.gem +0 -0
  105. metadata +207 -0
@@ -0,0 +1,116 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ #
19
+
20
+ require File.dirname(__FILE__) + '/spec_helper'
21
+
22
+ class ThriftTypesSpec < Spec::ExampleGroup
23
+ include Thrift
24
+
25
+ before(:each) do
26
+ Thrift.type_checking = true
27
+ end
28
+
29
+ after(:each) do
30
+ Thrift.type_checking = false
31
+ end
32
+
33
+ describe "Type checking" do
34
+ it "should return the proper name for each type" do
35
+ Thrift.type_name(Types::I16).should == "Types::I16"
36
+ Thrift.type_name(Types::VOID).should == "Types::VOID"
37
+ Thrift.type_name(Types::LIST).should == "Types::LIST"
38
+ Thrift.type_name(42).should be_nil
39
+ end
40
+
41
+ it "should check types properly" do
42
+ # lambda { Thrift.check_type(nil, Types::STOP) }.should raise_error(TypeError)
43
+ lambda { Thrift.check_type(3, {:type => Types::STOP}, :foo) }.should raise_error(TypeError)
44
+ lambda { Thrift.check_type(nil, {:type => Types::VOID}, :foo) }.should_not raise_error(TypeError)
45
+ lambda { Thrift.check_type(3, {:type => Types::VOID}, :foo) }.should raise_error(TypeError)
46
+ lambda { Thrift.check_type(true, {:type => Types::BOOL}, :foo) }.should_not raise_error(TypeError)
47
+ lambda { Thrift.check_type(3, {:type => Types::BOOL}, :foo) }.should raise_error(TypeError)
48
+ lambda { Thrift.check_type(42, {:type => Types::BYTE}, :foo) }.should_not raise_error(TypeError)
49
+ lambda { Thrift.check_type(42, {:type => Types::I16}, :foo) }.should_not raise_error(TypeError)
50
+ lambda { Thrift.check_type(42, {:type => Types::I32}, :foo) }.should_not raise_error(TypeError)
51
+ lambda { Thrift.check_type(42, {:type => Types::I64}, :foo) }.should_not raise_error(TypeError)
52
+ lambda { Thrift.check_type(3.14, {:type => Types::I32}, :foo) }.should raise_error(TypeError)
53
+ lambda { Thrift.check_type(3.14, {:type => Types::DOUBLE}, :foo) }.should_not raise_error(TypeError)
54
+ lambda { Thrift.check_type(3, {:type => Types::DOUBLE}, :foo) }.should raise_error(TypeError)
55
+ lambda { Thrift.check_type("3", {:type => Types::STRING}, :foo) }.should_not raise_error(TypeError)
56
+ lambda { Thrift.check_type(3, {:type => Types::STRING}, :foo) }.should raise_error(TypeError)
57
+ hello = SpecNamespace::Hello.new
58
+ lambda { Thrift.check_type(hello, {:type => Types::STRUCT, :class => SpecNamespace::Hello}, :foo) }.should_not raise_error(TypeError)
59
+ lambda { Thrift.check_type("foo", {:type => Types::STRUCT}, :foo) }.should raise_error(TypeError)
60
+ lambda { Thrift.check_type({:foo => 1}, {:type => Types::MAP}, :foo) }.should_not raise_error(TypeError)
61
+ lambda { Thrift.check_type([1], {:type => Types::MAP}, :foo) }.should raise_error(TypeError)
62
+ lambda { Thrift.check_type([1], {:type => Types::LIST}, :foo) }.should_not raise_error(TypeError)
63
+ lambda { Thrift.check_type({:foo => 1}, {:type => Types::LIST}, :foo) }.should raise_error(TypeError)
64
+ lambda { Thrift.check_type(Set.new([1,2]), {:type => Types::SET}, :foo) }.should_not raise_error(TypeError)
65
+ lambda { Thrift.check_type([1,2], {:type => Types::SET}, :foo) }.should raise_error(TypeError)
66
+ lambda { Thrift.check_type({:foo => true}, {:type => Types::SET}, :foo) }.should raise_error(TypeError)
67
+ end
68
+
69
+ it "should error out if nil is passed and skip_types is false" do
70
+ lambda { Thrift.check_type(nil, {:type => Types::BOOL}, :foo, false) }.should raise_error(TypeError)
71
+ lambda { Thrift.check_type(nil, {:type => Types::BYTE}, :foo, false) }.should raise_error(TypeError)
72
+ lambda { Thrift.check_type(nil, {:type => Types::I16}, :foo, false) }.should raise_error(TypeError)
73
+ lambda { Thrift.check_type(nil, {:type => Types::I32}, :foo, false) }.should raise_error(TypeError)
74
+ lambda { Thrift.check_type(nil, {:type => Types::I64}, :foo, false) }.should raise_error(TypeError)
75
+ lambda { Thrift.check_type(nil, {:type => Types::DOUBLE}, :foo, false) }.should raise_error(TypeError)
76
+ lambda { Thrift.check_type(nil, {:type => Types::STRING}, :foo, false) }.should raise_error(TypeError)
77
+ lambda { Thrift.check_type(nil, {:type => Types::STRUCT}, :foo, false) }.should raise_error(TypeError)
78
+ lambda { Thrift.check_type(nil, {:type => Types::LIST}, :foo, false) }.should raise_error(TypeError)
79
+ lambda { Thrift.check_type(nil, {:type => Types::SET}, :foo, false) }.should raise_error(TypeError)
80
+ lambda { Thrift.check_type(nil, {:type => Types::MAP}, :foo, false) }.should raise_error(TypeError)
81
+ end
82
+
83
+ it "should check element types on containers" do
84
+ field = {:type => Types::LIST, :element => {:type => Types::I32}}
85
+ lambda { Thrift.check_type([1, 2], field, :foo) }.should_not raise_error(TypeError)
86
+ lambda { Thrift.check_type([1, nil, 2], field, :foo) }.should raise_error(TypeError)
87
+ field = {:type => Types::MAP, :key => {:type => Types::I32}, :value => {:type => Types::STRING}}
88
+ lambda { Thrift.check_type({1 => "one", 2 => "two"}, field, :foo) }.should_not raise_error(TypeError)
89
+ lambda { Thrift.check_type({1 => "one", nil => "nil"}, field, :foo) }.should raise_error(TypeError)
90
+ lambda { Thrift.check_type({1 => nil, 2 => "two"}, field, :foo) }.should raise_error(TypeError)
91
+ field = {:type => Types::SET, :element => {:type => Types::I32}}
92
+ lambda { Thrift.check_type(Set.new([1, 2]), field, :foo) }.should_not raise_error(TypeError)
93
+ lambda { Thrift.check_type(Set.new([1, nil, 2]), field, :foo) }.should raise_error(TypeError)
94
+ lambda { Thrift.check_type(Set.new([1, 2.3, 2]), field, :foo) }.should raise_error(TypeError)
95
+
96
+ field = {:type => Types::STRUCT, :class => SpecNamespace::Hello}
97
+ lambda { Thrift.check_type(SpecNamespace::BoolStruct, field, :foo) }.should raise_error(TypeError)
98
+ end
99
+
100
+ it "should give the TypeError a readable message" do
101
+ msg = "Expected Types::STRING, received Fixnum for field foo"
102
+ lambda { Thrift.check_type(3, {:type => Types::STRING}, :foo) }.should raise_error(TypeError, msg)
103
+ msg = "Expected Types::STRING, received Fixnum for field foo.element"
104
+ field = {:type => Types::LIST, :element => {:type => Types::STRING}}
105
+ lambda { Thrift.check_type([3], field, :foo) }.should raise_error(TypeError, msg)
106
+ msg = "Expected Types::I32, received NilClass for field foo.element.key"
107
+ field = {:type => Types::LIST,
108
+ :element => {:type => Types::MAP,
109
+ :key => {:type => Types::I32},
110
+ :value => {:type => Types::I32}}}
111
+ lambda { Thrift.check_type([{nil => 3}], field, :foo) }.should raise_error(TypeError, msg)
112
+ msg = "Expected Types::I32, received NilClass for field foo.element.value"
113
+ lambda { Thrift.check_type([{1 => nil}], field, :foo) }.should raise_error(TypeError, msg)
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,193 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ #
19
+
20
+ require File.dirname(__FILE__) + '/spec_helper'
21
+
22
+ class ThriftUnionSpec < Spec::ExampleGroup
23
+ include Thrift
24
+ include SpecNamespace
25
+
26
+ describe Union do
27
+ it "should return nil value in unset union" do
28
+ union = My_union.new
29
+ union.get_set_field.should == nil
30
+ union.get_value.should == nil
31
+ end
32
+
33
+ it "should set a field and be accessible through get_value and the named field accessor" do
34
+ union = My_union.new
35
+ union.integer32 = 25
36
+ union.get_set_field.should == :integer32
37
+ union.get_value.should == 25
38
+ union.integer32.should == 25
39
+ end
40
+
41
+ it "should work correctly when instantiated with static field constructors" do
42
+ union = My_union.integer32(5)
43
+ union.get_set_field.should == :integer32
44
+ union.integer32.should == 5
45
+ end
46
+
47
+ it "should raise for wrong set field" do
48
+ union = My_union.new
49
+ union.integer32 = 25
50
+ lambda { union.some_characters }.should raise_error(RuntimeError, "some_characters is not union's set field.")
51
+ end
52
+
53
+ it "should not be equal to nil" do
54
+ union = My_union.new
55
+ union.should_not == nil
56
+ end
57
+
58
+ it "should not equate two different unions, i32 vs. string" do
59
+ union = My_union.new(:integer32, 25)
60
+ other_union = My_union.new(:some_characters, "blah!")
61
+ union.should_not == other_union
62
+ end
63
+
64
+ it "should properly reset setfield and setvalue" do
65
+ union = My_union.new(:integer32, 25)
66
+ union.get_set_field.should == :integer32
67
+ union.some_characters = "blah!"
68
+ union.get_set_field.should == :some_characters
69
+ union.get_value.should == "blah!"
70
+ lambda { union.integer32 }.should raise_error(RuntimeError, "integer32 is not union's set field.")
71
+ end
72
+
73
+ it "should not equate two different unions with different values" do
74
+ union = My_union.new(:integer32, 25)
75
+ other_union = My_union.new(:integer32, 400)
76
+ union.should_not == other_union
77
+ end
78
+
79
+ it "should not equate two different unions with different fields" do
80
+ union = My_union.new(:integer32, 25)
81
+ other_union = My_union.new(:other_i32, 25)
82
+ union.should_not == other_union
83
+ end
84
+
85
+ it "should inspect properly" do
86
+ union = My_union.new(:integer32, 25)
87
+ union.inspect.should == "<SpecNamespace::My_union integer32: 25>"
88
+ end
89
+
90
+ it "should not allow setting with instance_variable_set" do
91
+ union = My_union.new(:integer32, 27)
92
+ union.instance_variable_set(:@some_characters, "hallo!")
93
+ union.get_set_field.should == :integer32
94
+ union.get_value.should == 27
95
+ lambda { union.some_characters }.should raise_error(RuntimeError, "some_characters is not union's set field.")
96
+ end
97
+
98
+ it "should serialize correctly" do
99
+ trans = Thrift::MemoryBufferTransport.new
100
+ proto = Thrift::BinaryProtocol.new(trans)
101
+
102
+ union = My_union.new(:integer32, 25)
103
+ union.write(proto)
104
+
105
+ other_union = My_union.new(:integer32, 25)
106
+ other_union.read(proto)
107
+ other_union.should == union
108
+ end
109
+
110
+ it "should raise when validating unset union" do
111
+ union = My_union.new
112
+ lambda { union.validate }.should raise_error(StandardError, "Union fields are not set.")
113
+
114
+ other_union = My_union.new(:integer32, 1)
115
+ lambda { other_union.validate }.should_not raise_error(StandardError, "Union fields are not set.")
116
+ end
117
+
118
+ it "should validate an enum field properly" do
119
+ union = TestUnion.new(:enum_field, 3)
120
+ union.get_set_field.should == :enum_field
121
+ lambda { union.validate }.should raise_error(ProtocolException, "Invalid value of field enum_field!")
122
+
123
+ other_union = TestUnion.new(:enum_field, 1)
124
+ lambda { other_union.validate }.should_not raise_error(ProtocolException, "Invalid value of field enum_field!")
125
+ end
126
+
127
+ it "should properly serialize and match structs with a union" do
128
+ union = My_union.new(:integer32, 26)
129
+ swu = Struct_with_union.new(:fun_union => union)
130
+
131
+ trans = Thrift::MemoryBufferTransport.new
132
+ proto = Thrift::CompactProtocol.new(trans)
133
+
134
+ swu.write(proto)
135
+
136
+ other_union = My_union.new(:some_characters, "hello there")
137
+ swu2 = Struct_with_union.new(:fun_union => other_union)
138
+
139
+ swu2.should_not == swu
140
+
141
+ swu2.read(proto)
142
+ swu2.should == swu
143
+ end
144
+
145
+ it "should support old style constructor" do
146
+ union = My_union.new(:integer32 => 26)
147
+ union.get_set_field.should == :integer32
148
+ union.get_value.should == 26
149
+ end
150
+
151
+ it "should not throw an error when inspected and unset" do
152
+ lambda{TestUnion.new().inspect}.should_not raise_error
153
+ end
154
+
155
+ it "should print enum value name when inspected" do
156
+ My_union.new(:some_enum => SomeEnum::ONE).inspect.should == "<SpecNamespace::My_union some_enum: ONE (0)>"
157
+
158
+ My_union.new(:my_map => {SomeEnum::ONE => [SomeEnum::TWO]}).inspect.should == "<SpecNamespace::My_union my_map: {ONE (0): [TWO (1)]}>"
159
+ end
160
+
161
+ it "should offer field? methods" do
162
+ My_union.new.some_enum?.should be_false
163
+ My_union.new(:some_enum => SomeEnum::ONE).some_enum?.should be_true
164
+ My_union.new(:im_true => false).im_true?.should be_true
165
+ My_union.new(:im_true => true).im_true?.should be_true
166
+ end
167
+
168
+ it "should pretty print binary fields" do
169
+ TestUnion.new(:binary_field => "\001\002\003").inspect.should == "<SpecNamespace::TestUnion binary_field: 010203>"
170
+ end
171
+
172
+ it "should be comparable" do
173
+ relationships = [
174
+ [0, -1, -1, -1],
175
+ [1, 0, -1, -1],
176
+ [1, 1, 0, -1],
177
+ [1, 1, 1, 0]]
178
+
179
+ objs = [
180
+ TestUnion.new(:string_field, "blah"),
181
+ TestUnion.new(:string_field, "blahblah"),
182
+ TestUnion.new(:i32_field, 1),
183
+ TestUnion.new()]
184
+
185
+ for y in 0..3
186
+ for x in 0..3
187
+ # puts "#{objs[y].inspect} <=> #{objs[x].inspect} should == #{relationships[y][x]}"
188
+ (objs[y] <=> objs[x]).should == relationships[y][x]
189
+ end
190
+ end
191
+ end
192
+ end
193
+ end
@@ -0,0 +1,108 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ #
19
+
20
+ require File.dirname(__FILE__) + '/spec_helper'
21
+ require File.dirname(__FILE__) + "/socket_spec_shared"
22
+
23
+ class ThriftUNIXSocketSpec < Spec::ExampleGroup
24
+ include Thrift
25
+
26
+ describe UNIXSocket do
27
+ before(:each) do
28
+ @path = '/tmp/thrift_spec_socket'
29
+ @socket = UNIXSocket.new(@path)
30
+ @handle = mock("Handle", :closed? => false)
31
+ @handle.stub!(:close)
32
+ ::UNIXSocket.stub!(:new).and_return(@handle)
33
+ end
34
+
35
+ it_should_behave_like "a socket"
36
+
37
+ it "should raise a TransportException when it cannot open a socket" do
38
+ ::UNIXSocket.should_receive(:new).and_raise(StandardError)
39
+ lambda { @socket.open }.should raise_error(Thrift::TransportException) { |e| e.type.should == Thrift::TransportException::NOT_OPEN }
40
+ end
41
+
42
+ it "should accept an optional timeout" do
43
+ ::UNIXSocket.stub!(:new)
44
+ UNIXSocket.new(@path, 5).timeout.should == 5
45
+ end
46
+ end
47
+
48
+ describe UNIXServerSocket do
49
+ before(:each) do
50
+ @path = '/tmp/thrift_spec_socket'
51
+ @socket = UNIXServerSocket.new(@path)
52
+ end
53
+
54
+ it "should create a handle when calling listen" do
55
+ UNIXServer.should_receive(:new).with(@path)
56
+ @socket.listen
57
+ end
58
+
59
+ it "should create a Thrift::UNIXSocket to wrap accepted sockets" do
60
+ handle = mock("UNIXServer")
61
+ UNIXServer.should_receive(:new).with(@path).and_return(handle)
62
+ @socket.listen
63
+ sock = mock("sock")
64
+ handle.should_receive(:accept).and_return(sock)
65
+ trans = mock("UNIXSocket")
66
+ UNIXSocket.should_receive(:new).and_return(trans)
67
+ trans.should_receive(:handle=).with(sock)
68
+ @socket.accept.should == trans
69
+ end
70
+
71
+ it "should close the handle when closed" do
72
+ handle = mock("UNIXServer", :closed? => false)
73
+ UNIXServer.should_receive(:new).with(@path).and_return(handle)
74
+ @socket.listen
75
+ handle.should_receive(:close)
76
+ File.stub!(:delete)
77
+ @socket.close
78
+ end
79
+
80
+ it "should delete the socket when closed" do
81
+ handle = mock("UNIXServer", :closed? => false)
82
+ UNIXServer.should_receive(:new).with(@path).and_return(handle)
83
+ @socket.listen
84
+ handle.stub!(:close)
85
+ File.should_receive(:delete).with(@path)
86
+ @socket.close
87
+ end
88
+
89
+ it "should return nil when accepting if there is no handle" do
90
+ @socket.accept.should be_nil
91
+ end
92
+
93
+ it "should return true for closed? when appropriate" do
94
+ handle = mock("UNIXServer", :closed? => false)
95
+ UNIXServer.stub!(:new).and_return(handle)
96
+ File.stub!(:delete)
97
+ @socket.listen
98
+ @socket.should_not be_closed
99
+ handle.stub!(:close)
100
+ @socket.close
101
+ @socket.should be_closed
102
+ @socket.listen
103
+ @socket.should_not be_closed
104
+ handle.stub!(:closed?).and_return(true)
105
+ @socket.should be_closed
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{thrift}
5
+ s.version = "0.7.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2.0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = [%q{Thrift Developers}]
9
+ s.date = %q{2011-08-16}
10
+ s.description = %q{Ruby bindings for the Apache Thrift RPC system}
11
+ s.email = [%q{dev@thrift.apache.org}]
12
+ s.extensions = [%q{ext/extconf.rb}]
13
+ s.extra_rdoc_files = [%q{CHANGELOG}, %q{README}, %q{ext/binary_protocol_accelerated.c}, %q{ext/binary_protocol_accelerated.h}, %q{ext/compact_protocol.c}, %q{ext/compact_protocol.h}, %q{ext/constants.h}, %q{ext/extconf.rb}, %q{ext/macros.h}, %q{ext/memory_buffer.c}, %q{ext/memory_buffer.h}, %q{ext/protocol.c}, %q{ext/protocol.h}, %q{ext/struct.c}, %q{ext/struct.h}, %q{ext/thrift_native.c}, %q{lib/thrift.rb}, %q{lib/thrift/client.rb}, %q{lib/thrift/core_ext.rb}, %q{lib/thrift/core_ext/fixnum.rb}, %q{lib/thrift/exceptions.rb}, %q{lib/thrift/processor.rb}, %q{lib/thrift/protocol/base_protocol.rb}, %q{lib/thrift/protocol/binary_protocol.rb}, %q{lib/thrift/protocol/binary_protocol_accelerated.rb}, %q{lib/thrift/protocol/compact_protocol.rb}, %q{lib/thrift/serializer/deserializer.rb}, %q{lib/thrift/serializer/serializer.rb}, %q{lib/thrift/server/base_server.rb}, %q{lib/thrift/server/mongrel_http_server.rb}, %q{lib/thrift/server/nonblocking_server.rb}, %q{lib/thrift/server/simple_server.rb}, %q{lib/thrift/server/thread_pool_server.rb}, %q{lib/thrift/server/threaded_server.rb}, %q{lib/thrift/struct.rb}, %q{lib/thrift/struct_union.rb}, %q{lib/thrift/thrift_native.rb}, %q{lib/thrift/transport/base_server_transport.rb}, %q{lib/thrift/transport/base_transport.rb}, %q{lib/thrift/transport/buffered_transport.rb}, %q{lib/thrift/transport/framed_transport.rb}, %q{lib/thrift/transport/http_client_transport.rb}, %q{lib/thrift/transport/io_stream_transport.rb}, %q{lib/thrift/transport/memory_buffer_transport.rb}, %q{lib/thrift/transport/server_socket.rb}, %q{lib/thrift/transport/socket.rb}, %q{lib/thrift/transport/unix_server_socket.rb}, %q{lib/thrift/transport/unix_socket.rb}, %q{lib/thrift/types.rb}, %q{lib/thrift/union.rb}]
14
+ s.files = [%q{CHANGELOG}, %q{InstalledFiles}, %q{Makefile}, %q{Makefile.am}, %q{Makefile.in}, %q{Manifest}, %q{README}, %q{Rakefile}, %q{benchmark/Benchmark.thrift}, %q{benchmark/benchmark.rb}, %q{benchmark/client.rb}, %q{benchmark/gen-rb/benchmark_constants.rb}, %q{benchmark/gen-rb/benchmark_service.rb}, %q{benchmark/gen-rb/benchmark_types.rb}, %q{benchmark/server.rb}, %q{benchmark/thin_server.rb}, %q{debug_proto_test/gen-rb/debug_proto_test_constants.rb}, %q{debug_proto_test/gen-rb/debug_proto_test_types.rb}, %q{debug_proto_test/gen-rb/empty_service.rb}, %q{debug_proto_test/gen-rb/inherited.rb}, %q{debug_proto_test/gen-rb/reverse_order_service.rb}, %q{debug_proto_test/gen-rb/service_for_exception_with_a_map.rb}, %q{debug_proto_test/gen-rb/srv.rb}, %q{ext/binary_protocol_accelerated.c}, %q{ext/binary_protocol_accelerated.h}, %q{ext/compact_protocol.c}, %q{ext/compact_protocol.h}, %q{ext/constants.h}, %q{ext/extconf.rb}, %q{ext/macros.h}, %q{ext/memory_buffer.c}, %q{ext/memory_buffer.h}, %q{ext/protocol.c}, %q{ext/protocol.h}, %q{ext/struct.c}, %q{ext/struct.h}, %q{ext/thrift_native.c}, %q{lib/thrift.rb}, %q{lib/thrift/client.rb}, %q{lib/thrift/core_ext.rb}, %q{lib/thrift/core_ext/fixnum.rb}, %q{lib/thrift/exceptions.rb}, %q{lib/thrift/processor.rb}, %q{lib/thrift/protocol/base_protocol.rb}, %q{lib/thrift/protocol/binary_protocol.rb}, %q{lib/thrift/protocol/binary_protocol_accelerated.rb}, %q{lib/thrift/protocol/compact_protocol.rb}, %q{lib/thrift/serializer/deserializer.rb}, %q{lib/thrift/serializer/serializer.rb}, %q{lib/thrift/server/base_server.rb}, %q{lib/thrift/server/mongrel_http_server.rb}, %q{lib/thrift/server/nonblocking_server.rb}, %q{lib/thrift/server/simple_server.rb}, %q{lib/thrift/server/thread_pool_server.rb}, %q{lib/thrift/server/threaded_server.rb}, %q{lib/thrift/struct.rb}, %q{lib/thrift/struct_union.rb}, %q{lib/thrift/thrift_native.rb}, %q{lib/thrift/transport/base_server_transport.rb}, %q{lib/thrift/transport/base_transport.rb}, %q{lib/thrift/transport/buffered_transport.rb}, %q{lib/thrift/transport/framed_transport.rb}, %q{lib/thrift/transport/http_client_transport.rb}, %q{lib/thrift/transport/io_stream_transport.rb}, %q{lib/thrift/transport/memory_buffer_transport.rb}, %q{lib/thrift/transport/server_socket.rb}, %q{lib/thrift/transport/socket.rb}, %q{lib/thrift/transport/unix_server_socket.rb}, %q{lib/thrift/transport/unix_socket.rb}, %q{lib/thrift/types.rb}, %q{lib/thrift/union.rb}, %q{script/proto_benchmark.rb}, %q{script/read_struct.rb}, %q{script/write_struct.rb}, %q{setup.rb}, %q{spec/ThriftSpec.thrift}, %q{spec/base_protocol_spec.rb}, %q{spec/base_transport_spec.rb}, %q{spec/binary_protocol_accelerated_spec.rb}, %q{spec/binary_protocol_spec.rb}, %q{spec/binary_protocol_spec_shared.rb}, %q{spec/client_spec.rb}, %q{spec/compact_protocol_spec.rb}, %q{spec/exception_spec.rb}, %q{spec/gen-rb/nonblocking_service.rb}, %q{spec/gen-rb/thrift_spec_constants.rb}, %q{spec/gen-rb/thrift_spec_types.rb}, %q{spec/http_client_spec.rb}, %q{spec/mongrel_http_server_spec.rb}, %q{spec/nonblocking_server_spec.rb}, %q{spec/processor_spec.rb}, %q{spec/serializer_spec.rb}, %q{spec/server_socket_spec.rb}, %q{spec/server_spec.rb}, %q{spec/socket_spec.rb}, %q{spec/socket_spec_shared.rb}, %q{spec/spec_helper.rb}, %q{spec/struct_spec.rb}, %q{spec/types_spec.rb}, %q{spec/union_spec.rb}, %q{spec/unix_socket_spec.rb}, %q{thrift.gemspec}, %q{tmp/thrift-0.7.0.gem}]
15
+ s.homepage = %q{http://thrift.apache.org}
16
+ s.rdoc_options = [%q{--line-numbers}, %q{--inline-source}, %q{--title}, %q{Thrift}, %q{--main}, %q{README}]
17
+ s.require_paths = [%q{lib}, %q{ext}]
18
+ s.rubyforge_project = %q{thrift}
19
+ s.rubygems_version = %q{1.8.6}
20
+ s.summary = %q{Ruby bindings for the Apache Thrift RPC system}
21
+
22
+ if s.respond_to? :specification_version then
23
+ s.specification_version = 3
24
+
25
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
+ else
27
+ end
28
+ else
29
+ end
30
+ end