thrift-mavericks 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +15 -0
  2. data/CHANGELOG +1 -0
  3. data/README +43 -0
  4. data/benchmark/Benchmark.thrift +24 -0
  5. data/benchmark/benchmark.rb +271 -0
  6. data/benchmark/client.rb +74 -0
  7. data/benchmark/gen-rb/benchmark_constants.rb +11 -0
  8. data/benchmark/gen-rb/benchmark_service.rb +80 -0
  9. data/benchmark/gen-rb/benchmark_types.rb +10 -0
  10. data/benchmark/server.rb +82 -0
  11. data/benchmark/thin_server.rb +44 -0
  12. data/ext/binary_protocol_accelerated.c +441 -0
  13. data/ext/binary_protocol_accelerated.h +20 -0
  14. data/ext/compact_protocol.c +618 -0
  15. data/ext/compact_protocol.h +20 -0
  16. data/ext/constants.h +96 -0
  17. data/ext/extconf.rb +30 -0
  18. data/ext/macros.h +41 -0
  19. data/ext/memory_buffer.c +131 -0
  20. data/ext/memory_buffer.h +20 -0
  21. data/ext/protocol.c +185 -0
  22. data/ext/protocol.h +20 -0
  23. data/ext/strlcpy.c +41 -0
  24. data/ext/strlcpy.h +32 -0
  25. data/ext/struct.c +691 -0
  26. data/ext/struct.h +25 -0
  27. data/ext/thrift_native.c +196 -0
  28. data/lib/thrift.rb +64 -0
  29. data/lib/thrift/client.rb +62 -0
  30. data/lib/thrift/core_ext.rb +23 -0
  31. data/lib/thrift/core_ext/fixnum.rb +29 -0
  32. data/lib/thrift/exceptions.rb +84 -0
  33. data/lib/thrift/processor.rb +57 -0
  34. data/lib/thrift/protocol/base_protocol.rb +290 -0
  35. data/lib/thrift/protocol/binary_protocol.rb +229 -0
  36. data/lib/thrift/protocol/binary_protocol_accelerated.rb +39 -0
  37. data/lib/thrift/protocol/compact_protocol.rb +426 -0
  38. data/lib/thrift/serializer/deserializer.rb +33 -0
  39. data/lib/thrift/serializer/serializer.rb +34 -0
  40. data/lib/thrift/server/base_server.rb +31 -0
  41. data/lib/thrift/server/mongrel_http_server.rb +58 -0
  42. data/lib/thrift/server/nonblocking_server.rb +305 -0
  43. data/lib/thrift/server/simple_server.rb +43 -0
  44. data/lib/thrift/server/thread_pool_server.rb +75 -0
  45. data/lib/thrift/server/threaded_server.rb +47 -0
  46. data/lib/thrift/struct.rb +237 -0
  47. data/lib/thrift/struct_union.rb +192 -0
  48. data/lib/thrift/thrift_native.rb +24 -0
  49. data/lib/thrift/transport/base_server_transport.rb +37 -0
  50. data/lib/thrift/transport/base_transport.rb +107 -0
  51. data/lib/thrift/transport/buffered_transport.rb +108 -0
  52. data/lib/thrift/transport/framed_transport.rb +116 -0
  53. data/lib/thrift/transport/http_client_transport.rb +51 -0
  54. data/lib/thrift/transport/io_stream_transport.rb +39 -0
  55. data/lib/thrift/transport/memory_buffer_transport.rb +125 -0
  56. data/lib/thrift/transport/server_socket.rb +63 -0
  57. data/lib/thrift/transport/socket.rb +137 -0
  58. data/lib/thrift/transport/unix_server_socket.rb +60 -0
  59. data/lib/thrift/transport/unix_socket.rb +40 -0
  60. data/lib/thrift/types.rb +101 -0
  61. data/lib/thrift/union.rb +179 -0
  62. data/spec/ThriftSpec.thrift +132 -0
  63. data/spec/base_protocol_spec.rb +160 -0
  64. data/spec/base_transport_spec.rb +351 -0
  65. data/spec/binary_protocol_accelerated_spec.rb +46 -0
  66. data/spec/binary_protocol_spec.rb +61 -0
  67. data/spec/binary_protocol_spec_shared.rb +375 -0
  68. data/spec/client_spec.rb +100 -0
  69. data/spec/compact_protocol_spec.rb +144 -0
  70. data/spec/exception_spec.rb +142 -0
  71. data/spec/gen-rb/nonblocking_service.rb +272 -0
  72. data/spec/gen-rb/thrift_spec_constants.rb +11 -0
  73. data/spec/gen-rb/thrift_spec_types.rb +346 -0
  74. data/spec/http_client_spec.rb +64 -0
  75. data/spec/mongrel_http_server_spec.rb +117 -0
  76. data/spec/nonblocking_server_spec.rb +265 -0
  77. data/spec/processor_spec.rb +83 -0
  78. data/spec/serializer_spec.rb +69 -0
  79. data/spec/server_socket_spec.rb +80 -0
  80. data/spec/server_spec.rb +159 -0
  81. data/spec/socket_spec.rb +61 -0
  82. data/spec/socket_spec_shared.rb +104 -0
  83. data/spec/spec_helper.rb +58 -0
  84. data/spec/struct_spec.rb +295 -0
  85. data/spec/types_spec.rb +116 -0
  86. data/spec/union_spec.rb +193 -0
  87. data/spec/unix_socket_spec.rb +108 -0
  88. data/test/debug_proto/gen-rb/debug_proto_test_constants.rb +274 -0
  89. data/test/debug_proto/gen-rb/debug_proto_test_types.rb +761 -0
  90. data/test/debug_proto/gen-rb/empty_service.rb +24 -0
  91. data/test/debug_proto/gen-rb/inherited.rb +79 -0
  92. data/test/debug_proto/gen-rb/reverse_order_service.rb +82 -0
  93. data/test/debug_proto/gen-rb/service_for_exception_with_a_map.rb +81 -0
  94. data/test/debug_proto/gen-rb/srv.rb +330 -0
  95. metadata +281 -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.expand_path("#{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.expand_path("#{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.expand_path("#{File.dirname(__FILE__)}/spec_helper")
21
+ require File.expand_path("#{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,274 @@
1
+ #
2
+ # Autogenerated by Thrift Compiler (0.9.0)
3
+ #
4
+ # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5
+ #
6
+
7
+ require 'thrift'
8
+ require 'debug_proto_test_types'
9
+
10
+ COMPACT_TEST = ::CompactProtoTestStruct.new({
11
+ %q"a_byte" => 127,
12
+ %q"a_i16" => 32000,
13
+ %q"a_i32" => 1000000000,
14
+ %q"a_i64" => 1099511627775,
15
+ %q"a_double" => 5.6789,
16
+ %q"a_string" => %q"my string",
17
+ %q"true_field" => true,
18
+ %q"false_field" => false,
19
+ %q"empty_struct_field" => ::Empty.new({
20
+ }),
21
+ %q"byte_list" => [
22
+ -127,
23
+ -1,
24
+ 0,
25
+ 1,
26
+ 127,
27
+ ],
28
+ %q"i16_list" => [
29
+ -1,
30
+ 0,
31
+ 1,
32
+ 32767,
33
+ ],
34
+ %q"i32_list" => [
35
+ -1,
36
+ 0,
37
+ 255,
38
+ 65535,
39
+ 16777215,
40
+ 2147483647,
41
+ ],
42
+ %q"i64_list" => [
43
+ -1,
44
+ 0,
45
+ 255,
46
+ 65535,
47
+ 16777215,
48
+ 4294967295,
49
+ 1099511627775,
50
+ 281474976710655,
51
+ 72057594037927935,
52
+ 9223372036854775807,
53
+ ],
54
+ %q"double_list" => [
55
+ 0.1,
56
+ 0.2,
57
+ 0.3,
58
+ ],
59
+ %q"string_list" => [
60
+ %q"first",
61
+ %q"second",
62
+ %q"third",
63
+ ],
64
+ %q"boolean_list" => [
65
+ true,
66
+ true,
67
+ true,
68
+ false,
69
+ false,
70
+ false,
71
+ ],
72
+ %q"struct_list" => [
73
+ ::Empty.new({
74
+ }),
75
+ ::Empty.new({
76
+ }),
77
+ ],
78
+ %q"byte_set" => Set.new([
79
+ -127,
80
+ -1,
81
+ 0,
82
+ 1,
83
+ 127,
84
+ ]),
85
+ %q"i16_set" => Set.new([
86
+ -1,
87
+ 0,
88
+ 1,
89
+ 32767,
90
+ ]),
91
+ %q"i32_set" => Set.new([
92
+ 1,
93
+ 2,
94
+ 3,
95
+ ]),
96
+ %q"i64_set" => Set.new([
97
+ -1,
98
+ 0,
99
+ 255,
100
+ 65535,
101
+ 16777215,
102
+ 4294967295,
103
+ 1099511627775,
104
+ 281474976710655,
105
+ 72057594037927935,
106
+ 9223372036854775807,
107
+ ]),
108
+ %q"double_set" => Set.new([
109
+ 0.1,
110
+ 0.2,
111
+ 0.3,
112
+ ]),
113
+ %q"string_set" => Set.new([
114
+ %q"first",
115
+ %q"second",
116
+ %q"third",
117
+ ]),
118
+ %q"boolean_set" => Set.new([
119
+ true,
120
+ false,
121
+ ]),
122
+ %q"struct_set" => Set.new([
123
+ ::Empty.new({
124
+ }),
125
+ ]),
126
+ %q"byte_byte_map" => {
127
+ 1 => 2,
128
+ },
129
+ %q"i16_byte_map" => {
130
+ 1 => 1,
131
+ -1 => 1,
132
+ 32767 => 1,
133
+ },
134
+ %q"i32_byte_map" => {
135
+ 1 => 1,
136
+ -1 => 1,
137
+ 2147483647 => 1,
138
+ },
139
+ %q"i64_byte_map" => {
140
+ 0 => 1,
141
+ 1 => 1,
142
+ -1 => 1,
143
+ 9223372036854775807 => 1,
144
+ },
145
+ %q"double_byte_map" => {
146
+ -1.1 => 1,
147
+ 1.1 => 1,
148
+ },
149
+ %q"string_byte_map" => {
150
+ %q"first" => 1,
151
+ %q"second" => 2,
152
+ %q"third" => 3,
153
+ %q"" => 0,
154
+ },
155
+ %q"boolean_byte_map" => {
156
+ true => 1,
157
+ false => 0,
158
+ },
159
+ %q"byte_i16_map" => {
160
+ 1 => 1,
161
+ 2 => -1,
162
+ 3 => 32767,
163
+ },
164
+ %q"byte_i32_map" => {
165
+ 1 => 1,
166
+ 2 => -1,
167
+ 3 => 2147483647,
168
+ },
169
+ %q"byte_i64_map" => {
170
+ 1 => 1,
171
+ 2 => -1,
172
+ 3 => 9223372036854775807,
173
+ },
174
+ %q"byte_double_map" => {
175
+ 1 => 0.1,
176
+ 2 => -0.1,
177
+ 3 => 1e+06,
178
+ },
179
+ %q"byte_string_map" => {
180
+ 1 => %q"",
181
+ 2 => %q"blah",
182
+ 3 => %q"loooooooooooooong string",
183
+ },
184
+ %q"byte_boolean_map" => {
185
+ 1 => true,
186
+ 2 => false,
187
+ },
188
+ %q"list_byte_map" => {
189
+ [
190
+ 1,
191
+ 2,
192
+ 3,
193
+ ] => 1,
194
+ [
195
+ 0,
196
+ 1,
197
+ ] => 2,
198
+ [
199
+ ] => 0,
200
+ },
201
+ %q"set_byte_map" => {
202
+ Set.new([
203
+ 1,
204
+ 2,
205
+ 3,
206
+ ]) => 1,
207
+ Set.new([
208
+ 0,
209
+ 1,
210
+ ]) => 2,
211
+ Set.new([
212
+ ]) => 0,
213
+ },
214
+ %q"map_byte_map" => {
215
+ {
216
+ 1 => 1,
217
+ } => 1,
218
+ {
219
+ 2 => 2,
220
+ } => 2,
221
+ {
222
+ } => 0,
223
+ },
224
+ %q"byte_map_map" => {
225
+ 0 => {
226
+ },
227
+ 1 => {
228
+ 1 => 1,
229
+ },
230
+ 2 => {
231
+ 1 => 1,
232
+ 2 => 2,
233
+ },
234
+ },
235
+ %q"byte_set_map" => {
236
+ 0 => Set.new([
237
+ ]),
238
+ 1 => Set.new([
239
+ 1,
240
+ ]),
241
+ 2 => Set.new([
242
+ 1,
243
+ 2,
244
+ ]),
245
+ },
246
+ %q"byte_list_map" => {
247
+ 0 => [
248
+ ],
249
+ 1 => [
250
+ 1,
251
+ ],
252
+ 2 => [
253
+ 1,
254
+ 2,
255
+ ],
256
+ },
257
+ })
258
+
259
+ MYCONST = 2
260
+
261
+ MY_SOME_ENUM = 1
262
+
263
+ MY_SOME_ENUM_1 = 1
264
+
265
+ MY_ENUM_MAP = {
266
+ 1 => 2,
267
+ }
268
+
269
+ EXTRA_CRAZY_MAP = {
270
+ 1 => ::StructWithSomeEnum.new({
271
+ %q"blah" => 2,
272
+ }),
273
+ }
274
+