sessionm-thrift 0.8.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +1 -0
- data/README +43 -0
- data/benchmark/Benchmark.thrift +24 -0
- data/benchmark/benchmark.rb +271 -0
- data/benchmark/client.rb +74 -0
- data/benchmark/server.rb +82 -0
- data/benchmark/thin_server.rb +44 -0
- data/ext/binary_protocol_accelerated.c +441 -0
- data/ext/binary_protocol_accelerated.h +20 -0
- data/ext/compact_protocol.c +618 -0
- data/ext/compact_protocol.h +20 -0
- data/ext/constants.h +96 -0
- data/ext/extconf.rb +30 -0
- data/ext/macros.h +41 -0
- data/ext/memory_buffer.c +131 -0
- data/ext/memory_buffer.h +20 -0
- data/ext/protocol.c +185 -0
- data/ext/protocol.h +20 -0
- data/ext/strlcpy.c +41 -0
- data/ext/strlcpy.h +30 -0
- data/ext/struct.c +691 -0
- data/ext/struct.h +25 -0
- data/ext/thrift_native.c +196 -0
- data/lib/thrift.rb +64 -0
- data/lib/thrift/client.rb +62 -0
- data/lib/thrift/core_ext.rb +23 -0
- data/lib/thrift/core_ext/fixnum.rb +29 -0
- data/lib/thrift/exceptions.rb +84 -0
- data/lib/thrift/processor.rb +57 -0
- data/lib/thrift/protocol/base_protocol.rb +290 -0
- data/lib/thrift/protocol/binary_protocol.rb +229 -0
- data/lib/thrift/protocol/binary_protocol_accelerated.rb +39 -0
- data/lib/thrift/protocol/compact_protocol.rb +426 -0
- data/lib/thrift/serializer/deserializer.rb +33 -0
- data/lib/thrift/serializer/serializer.rb +34 -0
- data/lib/thrift/server/base_server.rb +31 -0
- data/lib/thrift/server/mongrel_http_server.rb +58 -0
- data/lib/thrift/server/nonblocking_server.rb +305 -0
- data/lib/thrift/server/simple_server.rb +43 -0
- data/lib/thrift/server/thread_pool_server.rb +75 -0
- data/lib/thrift/server/threaded_server.rb +47 -0
- data/lib/thrift/struct.rb +237 -0
- data/lib/thrift/struct_union.rb +192 -0
- data/lib/thrift/thrift_native.rb +24 -0
- data/lib/thrift/transport/base_server_transport.rb +37 -0
- data/lib/thrift/transport/base_transport.rb +107 -0
- data/lib/thrift/transport/buffered_transport.rb +108 -0
- data/lib/thrift/transport/framed_transport.rb +116 -0
- data/lib/thrift/transport/http_client_transport.rb +51 -0
- data/lib/thrift/transport/io_stream_transport.rb +39 -0
- data/lib/thrift/transport/memory_buffer_transport.rb +125 -0
- data/lib/thrift/transport/server_socket.rb +63 -0
- data/lib/thrift/transport/socket.rb +137 -0
- data/lib/thrift/transport/unix_server_socket.rb +60 -0
- data/lib/thrift/transport/unix_socket.rb +40 -0
- data/lib/thrift/types.rb +101 -0
- data/lib/thrift/union.rb +179 -0
- data/spec/ThriftSpec.thrift +132 -0
- data/spec/base_protocol_spec.rb +160 -0
- data/spec/base_transport_spec.rb +351 -0
- data/spec/binary_protocol_accelerated_spec.rb +46 -0
- data/spec/binary_protocol_spec.rb +61 -0
- data/spec/binary_protocol_spec_shared.rb +375 -0
- data/spec/client_spec.rb +100 -0
- data/spec/compact_protocol_spec.rb +144 -0
- data/spec/exception_spec.rb +142 -0
- data/spec/http_client_spec.rb +64 -0
- data/spec/mongrel_http_server_spec.rb +117 -0
- data/spec/nonblocking_server_spec.rb +265 -0
- data/spec/processor_spec.rb +83 -0
- data/spec/serializer_spec.rb +69 -0
- data/spec/server_socket_spec.rb +80 -0
- data/spec/server_spec.rb +159 -0
- data/spec/socket_spec.rb +61 -0
- data/spec/socket_spec_shared.rb +104 -0
- data/spec/spec_helper.rb +58 -0
- data/spec/struct_spec.rb +295 -0
- data/spec/types_spec.rb +116 -0
- data/spec/union_spec.rb +193 -0
- data/spec/unix_socket_spec.rb +108 -0
- metadata +247 -0
data/spec/types_spec.rb
ADDED
@@ -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
|
data/spec/union_spec.rb
ADDED
@@ -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
|
metadata
ADDED
@@ -0,0 +1,247 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sessionm-thrift
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.8.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Thrift Developers
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-11-29 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: &70252672445820 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70252672445820
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &70252672445180 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - =
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.3.2
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70252672445180
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: mongrel
|
38
|
+
requirement: &70252672444640 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70252672444640
|
47
|
+
description: Ruby bindings for the Apache Thrift RPC system
|
48
|
+
email:
|
49
|
+
- dev@thrift.apache.org
|
50
|
+
executables: []
|
51
|
+
extensions:
|
52
|
+
- ext/extconf.rb
|
53
|
+
extra_rdoc_files:
|
54
|
+
- CHANGELOG
|
55
|
+
- README
|
56
|
+
- ext/binary_protocol_accelerated.c
|
57
|
+
- ext/compact_protocol.c
|
58
|
+
- ext/memory_buffer.c
|
59
|
+
- ext/protocol.c
|
60
|
+
- ext/strlcpy.c
|
61
|
+
- ext/struct.c
|
62
|
+
- ext/thrift_native.c
|
63
|
+
- ext/binary_protocol_accelerated.h
|
64
|
+
- ext/compact_protocol.h
|
65
|
+
- ext/constants.h
|
66
|
+
- ext/macros.h
|
67
|
+
- ext/memory_buffer.h
|
68
|
+
- ext/protocol.h
|
69
|
+
- ext/strlcpy.h
|
70
|
+
- ext/struct.h
|
71
|
+
- ext/extconf.rb
|
72
|
+
- lib/thrift/client.rb
|
73
|
+
- lib/thrift/core_ext/fixnum.rb
|
74
|
+
- lib/thrift/core_ext.rb
|
75
|
+
- lib/thrift/exceptions.rb
|
76
|
+
- lib/thrift/processor.rb
|
77
|
+
- lib/thrift/protocol/base_protocol.rb
|
78
|
+
- lib/thrift/protocol/binary_protocol.rb
|
79
|
+
- lib/thrift/protocol/binary_protocol_accelerated.rb
|
80
|
+
- lib/thrift/protocol/compact_protocol.rb
|
81
|
+
- lib/thrift/serializer/deserializer.rb
|
82
|
+
- lib/thrift/serializer/serializer.rb
|
83
|
+
- lib/thrift/server/base_server.rb
|
84
|
+
- lib/thrift/server/mongrel_http_server.rb
|
85
|
+
- lib/thrift/server/nonblocking_server.rb
|
86
|
+
- lib/thrift/server/simple_server.rb
|
87
|
+
- lib/thrift/server/thread_pool_server.rb
|
88
|
+
- lib/thrift/server/threaded_server.rb
|
89
|
+
- lib/thrift/struct.rb
|
90
|
+
- lib/thrift/struct_union.rb
|
91
|
+
- lib/thrift/thrift_native.rb
|
92
|
+
- lib/thrift/transport/base_server_transport.rb
|
93
|
+
- lib/thrift/transport/base_transport.rb
|
94
|
+
- lib/thrift/transport/buffered_transport.rb
|
95
|
+
- lib/thrift/transport/framed_transport.rb
|
96
|
+
- lib/thrift/transport/http_client_transport.rb
|
97
|
+
- lib/thrift/transport/io_stream_transport.rb
|
98
|
+
- lib/thrift/transport/memory_buffer_transport.rb
|
99
|
+
- lib/thrift/transport/server_socket.rb
|
100
|
+
- lib/thrift/transport/socket.rb
|
101
|
+
- lib/thrift/transport/unix_server_socket.rb
|
102
|
+
- lib/thrift/transport/unix_socket.rb
|
103
|
+
- lib/thrift/types.rb
|
104
|
+
- lib/thrift/union.rb
|
105
|
+
- lib/thrift.rb
|
106
|
+
files:
|
107
|
+
- lib/thrift/client.rb
|
108
|
+
- lib/thrift/core_ext/fixnum.rb
|
109
|
+
- lib/thrift/core_ext.rb
|
110
|
+
- lib/thrift/exceptions.rb
|
111
|
+
- lib/thrift/processor.rb
|
112
|
+
- lib/thrift/protocol/base_protocol.rb
|
113
|
+
- lib/thrift/protocol/binary_protocol.rb
|
114
|
+
- lib/thrift/protocol/binary_protocol_accelerated.rb
|
115
|
+
- lib/thrift/protocol/compact_protocol.rb
|
116
|
+
- lib/thrift/serializer/deserializer.rb
|
117
|
+
- lib/thrift/serializer/serializer.rb
|
118
|
+
- lib/thrift/server/base_server.rb
|
119
|
+
- lib/thrift/server/mongrel_http_server.rb
|
120
|
+
- lib/thrift/server/nonblocking_server.rb
|
121
|
+
- lib/thrift/server/simple_server.rb
|
122
|
+
- lib/thrift/server/thread_pool_server.rb
|
123
|
+
- lib/thrift/server/threaded_server.rb
|
124
|
+
- lib/thrift/struct.rb
|
125
|
+
- lib/thrift/struct_union.rb
|
126
|
+
- lib/thrift/thrift_native.rb
|
127
|
+
- lib/thrift/transport/base_server_transport.rb
|
128
|
+
- lib/thrift/transport/base_transport.rb
|
129
|
+
- lib/thrift/transport/buffered_transport.rb
|
130
|
+
- lib/thrift/transport/framed_transport.rb
|
131
|
+
- lib/thrift/transport/http_client_transport.rb
|
132
|
+
- lib/thrift/transport/io_stream_transport.rb
|
133
|
+
- lib/thrift/transport/memory_buffer_transport.rb
|
134
|
+
- lib/thrift/transport/server_socket.rb
|
135
|
+
- lib/thrift/transport/socket.rb
|
136
|
+
- lib/thrift/transport/unix_server_socket.rb
|
137
|
+
- lib/thrift/transport/unix_socket.rb
|
138
|
+
- lib/thrift/types.rb
|
139
|
+
- lib/thrift/union.rb
|
140
|
+
- lib/thrift.rb
|
141
|
+
- spec/base_protocol_spec.rb
|
142
|
+
- spec/base_transport_spec.rb
|
143
|
+
- spec/binary_protocol_accelerated_spec.rb
|
144
|
+
- spec/binary_protocol_spec.rb
|
145
|
+
- spec/binary_protocol_spec_shared.rb
|
146
|
+
- spec/client_spec.rb
|
147
|
+
- spec/compact_protocol_spec.rb
|
148
|
+
- spec/exception_spec.rb
|
149
|
+
- spec/http_client_spec.rb
|
150
|
+
- spec/mongrel_http_server_spec.rb
|
151
|
+
- spec/nonblocking_server_spec.rb
|
152
|
+
- spec/processor_spec.rb
|
153
|
+
- spec/serializer_spec.rb
|
154
|
+
- spec/server_socket_spec.rb
|
155
|
+
- spec/server_spec.rb
|
156
|
+
- spec/socket_spec.rb
|
157
|
+
- spec/socket_spec_shared.rb
|
158
|
+
- spec/spec_helper.rb
|
159
|
+
- spec/struct_spec.rb
|
160
|
+
- spec/ThriftSpec.thrift
|
161
|
+
- spec/types_spec.rb
|
162
|
+
- spec/union_spec.rb
|
163
|
+
- spec/unix_socket_spec.rb
|
164
|
+
- CHANGELOG
|
165
|
+
- README
|
166
|
+
- ext/binary_protocol_accelerated.c
|
167
|
+
- ext/compact_protocol.c
|
168
|
+
- ext/memory_buffer.c
|
169
|
+
- ext/protocol.c
|
170
|
+
- ext/strlcpy.c
|
171
|
+
- ext/struct.c
|
172
|
+
- ext/thrift_native.c
|
173
|
+
- ext/binary_protocol_accelerated.h
|
174
|
+
- ext/compact_protocol.h
|
175
|
+
- ext/constants.h
|
176
|
+
- ext/macros.h
|
177
|
+
- ext/memory_buffer.h
|
178
|
+
- ext/protocol.h
|
179
|
+
- ext/strlcpy.h
|
180
|
+
- ext/struct.h
|
181
|
+
- ext/extconf.rb
|
182
|
+
- benchmark/benchmark.rb
|
183
|
+
- benchmark/Benchmark.thrift
|
184
|
+
- benchmark/client.rb
|
185
|
+
- benchmark/server.rb
|
186
|
+
- benchmark/thin_server.rb
|
187
|
+
homepage: http://thrift.apache.org
|
188
|
+
licenses:
|
189
|
+
- Apache 2.0
|
190
|
+
post_install_message:
|
191
|
+
rdoc_options:
|
192
|
+
- --line-numbers
|
193
|
+
- --inline-source
|
194
|
+
- --title
|
195
|
+
- Thrift
|
196
|
+
- --main
|
197
|
+
- README
|
198
|
+
require_paths:
|
199
|
+
- lib
|
200
|
+
- ext
|
201
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
202
|
+
none: false
|
203
|
+
requirements:
|
204
|
+
- - ! '>='
|
205
|
+
- !ruby/object:Gem::Version
|
206
|
+
version: '0'
|
207
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
208
|
+
none: false
|
209
|
+
requirements:
|
210
|
+
- - ! '>='
|
211
|
+
- !ruby/object:Gem::Version
|
212
|
+
version: '0'
|
213
|
+
requirements: []
|
214
|
+
rubyforge_project: thrift
|
215
|
+
rubygems_version: 1.8.6
|
216
|
+
signing_key:
|
217
|
+
specification_version: 3
|
218
|
+
summary: Ruby bindings for Apache Thrift
|
219
|
+
test_files:
|
220
|
+
- spec/base_protocol_spec.rb
|
221
|
+
- spec/base_transport_spec.rb
|
222
|
+
- spec/binary_protocol_accelerated_spec.rb
|
223
|
+
- spec/binary_protocol_spec.rb
|
224
|
+
- spec/binary_protocol_spec_shared.rb
|
225
|
+
- spec/client_spec.rb
|
226
|
+
- spec/compact_protocol_spec.rb
|
227
|
+
- spec/exception_spec.rb
|
228
|
+
- spec/http_client_spec.rb
|
229
|
+
- spec/mongrel_http_server_spec.rb
|
230
|
+
- spec/nonblocking_server_spec.rb
|
231
|
+
- spec/processor_spec.rb
|
232
|
+
- spec/serializer_spec.rb
|
233
|
+
- spec/server_socket_spec.rb
|
234
|
+
- spec/server_spec.rb
|
235
|
+
- spec/socket_spec.rb
|
236
|
+
- spec/socket_spec_shared.rb
|
237
|
+
- spec/spec_helper.rb
|
238
|
+
- spec/struct_spec.rb
|
239
|
+
- spec/ThriftSpec.thrift
|
240
|
+
- spec/types_spec.rb
|
241
|
+
- spec/union_spec.rb
|
242
|
+
- spec/unix_socket_spec.rb
|
243
|
+
- benchmark/benchmark.rb
|
244
|
+
- benchmark/Benchmark.thrift
|
245
|
+
- benchmark/client.rb
|
246
|
+
- benchmark/server.rb
|
247
|
+
- benchmark/thin_server.rb
|