thrift 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/benchmark/gen-rb/benchmark_constants.rb +3 -2
- data/benchmark/gen-rb/benchmark_service.rb +52 -52
- data/benchmark/gen-rb/benchmark_types.rb +3 -2
- data/ext/binary_protocol_accelerated.c +5 -2
- data/ext/bytes.c +36 -0
- data/ext/bytes.h +31 -0
- data/ext/compact_protocol.c +7 -4
- data/ext/constants.h +4 -0
- data/ext/extconf.rb +3 -1
- data/ext/memory_buffer.c +11 -8
- data/ext/thrift_native.c +9 -0
- data/lib/thrift.rb +2 -0
- data/lib/thrift/bytes.rb +131 -0
- data/lib/thrift/protocol/base_protocol.rb +10 -0
- data/lib/thrift/protocol/binary_protocol.rb +5 -5
- data/lib/thrift/protocol/compact_protocol.rb +4 -3
- data/lib/thrift/protocol/json_protocol.rb +765 -0
- data/lib/thrift/transport/base_transport.rb +22 -20
- data/lib/thrift/transport/buffered_transport.rb +16 -10
- data/lib/thrift/transport/framed_transport.rb +11 -10
- data/lib/thrift/transport/http_client_transport.rb +7 -5
- data/lib/thrift/transport/io_stream_transport.rb +1 -1
- data/lib/thrift/transport/memory_buffer_transport.rb +6 -6
- data/lib/thrift/transport/socket.rb +4 -2
- data/spec/ThriftSpec.thrift +52 -1
- data/spec/base_protocol_spec.rb +44 -45
- data/spec/base_transport_spec.rb +49 -50
- data/spec/binary_protocol_accelerated_spec.rb +9 -13
- data/spec/binary_protocol_spec.rb +15 -10
- data/spec/binary_protocol_spec_shared.rb +62 -12
- data/spec/bytes_spec.rb +160 -0
- data/spec/client_spec.rb +13 -14
- data/spec/compact_protocol_spec.rb +3 -2
- data/spec/exception_spec.rb +39 -40
- data/spec/gen-rb/nonblocking_service.rb +193 -193
- data/spec/gen-rb/thrift_spec_constants.rb +3 -2
- data/spec/gen-rb/thrift_spec_types.rb +455 -262
- data/spec/http_client_spec.rb +16 -9
- data/spec/json_protocol_spec.rb +513 -0
- data/spec/mongrel_http_server_spec.rb +19 -22
- data/spec/nonblocking_server_spec.rb +18 -20
- data/spec/processor_spec.rb +13 -16
- data/spec/serializer_spec.rb +17 -19
- data/spec/server_socket_spec.rb +6 -7
- data/spec/server_spec.rb +46 -58
- data/spec/socket_spec.rb +11 -11
- data/spec/socket_spec_shared.rb +1 -1
- data/spec/spec_helper.rb +13 -10
- data/spec/struct_nested_containers_spec.rb +191 -0
- data/spec/struct_spec.rb +84 -86
- data/spec/types_spec.rb +65 -66
- data/spec/union_spec.rb +44 -46
- data/spec/unix_socket_spec.rb +8 -9
- data/test/debug_proto/gen-rb/debug_proto_test_constants.rb +8 -7
- data/test/debug_proto/gen-rb/debug_proto_test_types.rb +24 -23
- data/test/debug_proto/gen-rb/empty_service.rb +1 -1
- data/test/debug_proto/gen-rb/inherited.rb +3 -3
- data/test/debug_proto/gen-rb/reverse_order_service.rb +1 -1
- data/test/debug_proto/gen-rb/service_for_exception_with_a_map.rb +3 -3
- data/test/debug_proto/gen-rb/srv.rb +2 -2
- metadata +43 -49
data/spec/types_spec.rb
CHANGED
@@ -17,10 +17,9 @@
|
|
17
17
|
# under the License.
|
18
18
|
#
|
19
19
|
|
20
|
-
require
|
20
|
+
require 'spec_helper'
|
21
21
|
|
22
|
-
|
23
|
-
include Thrift
|
22
|
+
describe Thrift::Types do
|
24
23
|
|
25
24
|
before(:each) do
|
26
25
|
Thrift.type_checking = true
|
@@ -30,87 +29,87 @@ class ThriftTypesSpec < Spec::ExampleGroup
|
|
30
29
|
Thrift.type_checking = false
|
31
30
|
end
|
32
31
|
|
33
|
-
|
32
|
+
context 'type checking' do
|
34
33
|
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"
|
34
|
+
Thrift.type_name(Thrift::Types::I16).should == "Types::I16"
|
35
|
+
Thrift.type_name(Thrift::Types::VOID).should == "Types::VOID"
|
36
|
+
Thrift.type_name(Thrift::Types::LIST).should == "Types::LIST"
|
38
37
|
Thrift.type_name(42).should be_nil
|
39
38
|
end
|
40
39
|
|
41
40
|
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)
|
41
|
+
# lambda { Thrift.check_type(nil, Thrift::Types::STOP) }.should raise_error(Thrift::TypeError)
|
42
|
+
lambda { Thrift.check_type(3, {:type => Thrift::Types::STOP}, :foo) }.should raise_error(Thrift::TypeError)
|
43
|
+
lambda { Thrift.check_type(nil, {:type => Thrift::Types::VOID}, :foo) }.should_not raise_error(Thrift::TypeError)
|
44
|
+
lambda { Thrift.check_type(3, {:type => Thrift::Types::VOID}, :foo) }.should raise_error(Thrift::TypeError)
|
45
|
+
lambda { Thrift.check_type(true, {:type => Thrift::Types::BOOL}, :foo) }.should_not raise_error(Thrift::TypeError)
|
46
|
+
lambda { Thrift.check_type(3, {:type => Thrift::Types::BOOL}, :foo) }.should raise_error(Thrift::TypeError)
|
47
|
+
lambda { Thrift.check_type(42, {:type => Thrift::Types::BYTE}, :foo) }.should_not raise_error(Thrift::TypeError)
|
48
|
+
lambda { Thrift.check_type(42, {:type => Thrift::Types::I16}, :foo) }.should_not raise_error(Thrift::TypeError)
|
49
|
+
lambda { Thrift.check_type(42, {:type => Thrift::Types::I32}, :foo) }.should_not raise_error(Thrift::TypeError)
|
50
|
+
lambda { Thrift.check_type(42, {:type => Thrift::Types::I64}, :foo) }.should_not raise_error(Thrift::TypeError)
|
51
|
+
lambda { Thrift.check_type(3.14, {:type => Thrift::Types::I32}, :foo) }.should raise_error(Thrift::TypeError)
|
52
|
+
lambda { Thrift.check_type(3.14, {:type => Thrift::Types::DOUBLE}, :foo) }.should_not raise_error(Thrift::TypeError)
|
53
|
+
lambda { Thrift.check_type(3, {:type => Thrift::Types::DOUBLE}, :foo) }.should raise_error(Thrift::TypeError)
|
54
|
+
lambda { Thrift.check_type("3", {:type => Thrift::Types::STRING}, :foo) }.should_not raise_error(Thrift::TypeError)
|
55
|
+
lambda { Thrift.check_type(3, {:type => Thrift::Types::STRING}, :foo) }.should raise_error(Thrift::TypeError)
|
57
56
|
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)
|
57
|
+
lambda { Thrift.check_type(hello, {:type => Thrift::Types::STRUCT, :class => SpecNamespace::Hello}, :foo) }.should_not raise_error(Thrift::TypeError)
|
58
|
+
lambda { Thrift.check_type("foo", {:type => Thrift::Types::STRUCT}, :foo) }.should raise_error(Thrift::TypeError)
|
59
|
+
lambda { Thrift.check_type({:foo => 1}, {:type => Thrift::Types::MAP}, :foo) }.should_not raise_error(Thrift::TypeError)
|
60
|
+
lambda { Thrift.check_type([1], {:type => Thrift::Types::MAP}, :foo) }.should raise_error(Thrift::TypeError)
|
61
|
+
lambda { Thrift.check_type([1], {:type => Thrift::Types::LIST}, :foo) }.should_not raise_error(Thrift::TypeError)
|
62
|
+
lambda { Thrift.check_type({:foo => 1}, {:type => Thrift::Types::LIST}, :foo) }.should raise_error(Thrift::TypeError)
|
63
|
+
lambda { Thrift.check_type(Set.new([1,2]), {:type => Thrift::Types::SET}, :foo) }.should_not raise_error(Thrift::TypeError)
|
64
|
+
lambda { Thrift.check_type([1,2], {:type => Thrift::Types::SET}, :foo) }.should raise_error(Thrift::TypeError)
|
65
|
+
lambda { Thrift.check_type({:foo => true}, {:type => Thrift::Types::SET}, :foo) }.should raise_error(Thrift::TypeError)
|
67
66
|
end
|
68
67
|
|
69
68
|
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)
|
69
|
+
lambda { Thrift.check_type(nil, {:type => Thrift::Types::BOOL}, :foo, false) }.should raise_error(Thrift::TypeError)
|
70
|
+
lambda { Thrift.check_type(nil, {:type => Thrift::Types::BYTE}, :foo, false) }.should raise_error(Thrift::TypeError)
|
71
|
+
lambda { Thrift.check_type(nil, {:type => Thrift::Types::I16}, :foo, false) }.should raise_error(Thrift::TypeError)
|
72
|
+
lambda { Thrift.check_type(nil, {:type => Thrift::Types::I32}, :foo, false) }.should raise_error(Thrift::TypeError)
|
73
|
+
lambda { Thrift.check_type(nil, {:type => Thrift::Types::I64}, :foo, false) }.should raise_error(Thrift::TypeError)
|
74
|
+
lambda { Thrift.check_type(nil, {:type => Thrift::Types::DOUBLE}, :foo, false) }.should raise_error(Thrift::TypeError)
|
75
|
+
lambda { Thrift.check_type(nil, {:type => Thrift::Types::STRING}, :foo, false) }.should raise_error(Thrift::TypeError)
|
76
|
+
lambda { Thrift.check_type(nil, {:type => Thrift::Types::STRUCT}, :foo, false) }.should raise_error(Thrift::TypeError)
|
77
|
+
lambda { Thrift.check_type(nil, {:type => Thrift::Types::LIST}, :foo, false) }.should raise_error(Thrift::TypeError)
|
78
|
+
lambda { Thrift.check_type(nil, {:type => Thrift::Types::SET}, :foo, false) }.should raise_error(Thrift::TypeError)
|
79
|
+
lambda { Thrift.check_type(nil, {:type => Thrift::Types::MAP}, :foo, false) }.should raise_error(Thrift::TypeError)
|
81
80
|
end
|
82
81
|
|
83
82
|
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)
|
83
|
+
field = {:type => Thrift::Types::LIST, :element => {:type => Thrift::Types::I32}}
|
84
|
+
lambda { Thrift.check_type([1, 2], field, :foo) }.should_not raise_error(Thrift::TypeError)
|
85
|
+
lambda { Thrift.check_type([1, nil, 2], field, :foo) }.should raise_error(Thrift::TypeError)
|
86
|
+
field = {:type => Thrift::Types::MAP, :key => {:type => Thrift::Types::I32}, :value => {:type => Thrift::Types::STRING}}
|
87
|
+
lambda { Thrift.check_type({1 => "one", 2 => "two"}, field, :foo) }.should_not raise_error(Thrift::TypeError)
|
88
|
+
lambda { Thrift.check_type({1 => "one", nil => "nil"}, field, :foo) }.should raise_error(Thrift::TypeError)
|
89
|
+
lambda { Thrift.check_type({1 => nil, 2 => "two"}, field, :foo) }.should raise_error(Thrift::TypeError)
|
90
|
+
field = {:type => Thrift::Types::SET, :element => {:type => Thrift::Types::I32}}
|
91
|
+
lambda { Thrift.check_type(Set.new([1, 2]), field, :foo) }.should_not raise_error(Thrift::TypeError)
|
92
|
+
lambda { Thrift.check_type(Set.new([1, nil, 2]), field, :foo) }.should raise_error(Thrift::TypeError)
|
93
|
+
lambda { Thrift.check_type(Set.new([1, 2.3, 2]), field, :foo) }.should raise_error(Thrift::TypeError)
|
94
|
+
|
95
|
+
field = {:type => Thrift::Types::STRUCT, :class => SpecNamespace::Hello}
|
96
|
+
lambda { Thrift.check_type(SpecNamespace::BoolStruct, field, :foo) }.should raise_error(Thrift::TypeError)
|
98
97
|
end
|
99
98
|
|
100
|
-
it "should give the TypeError a readable message" do
|
99
|
+
it "should give the Thrift::TypeError a readable message" do
|
101
100
|
msg = "Expected Types::STRING, received Fixnum for field foo"
|
102
|
-
lambda { Thrift.check_type(3, {:type => Types::STRING}, :foo) }.should raise_error(TypeError, msg)
|
101
|
+
lambda { Thrift.check_type(3, {:type => Thrift::Types::STRING}, :foo) }.should raise_error(Thrift::TypeError, msg)
|
103
102
|
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)
|
103
|
+
field = {:type => Thrift::Types::LIST, :element => {:type => Thrift::Types::STRING}}
|
104
|
+
lambda { Thrift.check_type([3], field, :foo) }.should raise_error(Thrift::TypeError, msg)
|
106
105
|
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)
|
106
|
+
field = {:type => Thrift::Types::LIST,
|
107
|
+
:element => {:type => Thrift::Types::MAP,
|
108
|
+
:key => {:type => Thrift::Types::I32},
|
109
|
+
:value => {:type => Thrift::Types::I32}}}
|
110
|
+
lambda { Thrift.check_type([{nil => 3}], field, :foo) }.should raise_error(Thrift::TypeError, msg)
|
112
111
|
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)
|
112
|
+
lambda { Thrift.check_type([{1 => nil}], field, :foo) }.should raise_error(Thrift::TypeError, msg)
|
114
113
|
end
|
115
114
|
end
|
116
115
|
end
|
data/spec/union_spec.rb
CHANGED
@@ -17,21 +17,19 @@
|
|
17
17
|
# under the License.
|
18
18
|
#
|
19
19
|
|
20
|
-
require
|
20
|
+
require 'spec_helper'
|
21
21
|
|
22
|
-
|
23
|
-
include Thrift
|
24
|
-
include SpecNamespace
|
22
|
+
describe 'Union' do
|
25
23
|
|
26
|
-
describe Union do
|
24
|
+
describe Thrift::Union do
|
27
25
|
it "should return nil value in unset union" do
|
28
|
-
union = My_union.new
|
26
|
+
union = SpecNamespace::My_union.new
|
29
27
|
union.get_set_field.should == nil
|
30
28
|
union.get_value.should == nil
|
31
29
|
end
|
32
30
|
|
33
31
|
it "should set a field and be accessible through get_value and the named field accessor" do
|
34
|
-
union = My_union.new
|
32
|
+
union = SpecNamespace::My_union.new
|
35
33
|
union.integer32 = 25
|
36
34
|
union.get_set_field.should == :integer32
|
37
35
|
union.get_value.should == 25
|
@@ -39,30 +37,30 @@ class ThriftUnionSpec < Spec::ExampleGroup
|
|
39
37
|
end
|
40
38
|
|
41
39
|
it "should work correctly when instantiated with static field constructors" do
|
42
|
-
union = My_union.integer32(5)
|
40
|
+
union = SpecNamespace::My_union.integer32(5)
|
43
41
|
union.get_set_field.should == :integer32
|
44
42
|
union.integer32.should == 5
|
45
43
|
end
|
46
44
|
|
47
45
|
it "should raise for wrong set field" do
|
48
|
-
union = My_union.new
|
46
|
+
union = SpecNamespace::My_union.new
|
49
47
|
union.integer32 = 25
|
50
48
|
lambda { union.some_characters }.should raise_error(RuntimeError, "some_characters is not union's set field.")
|
51
49
|
end
|
52
|
-
|
50
|
+
|
53
51
|
it "should not be equal to nil" do
|
54
|
-
union = My_union.new
|
52
|
+
union = SpecNamespace::My_union.new
|
55
53
|
union.should_not == nil
|
56
54
|
end
|
57
|
-
|
55
|
+
|
58
56
|
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!")
|
57
|
+
union = SpecNamespace::My_union.new(:integer32, 25)
|
58
|
+
other_union = SpecNamespace::My_union.new(:some_characters, "blah!")
|
61
59
|
union.should_not == other_union
|
62
60
|
end
|
63
61
|
|
64
62
|
it "should properly reset setfield and setvalue" do
|
65
|
-
union = My_union.new(:integer32, 25)
|
63
|
+
union = SpecNamespace::My_union.new(:integer32, 25)
|
66
64
|
union.get_set_field.should == :integer32
|
67
65
|
union.some_characters = "blah!"
|
68
66
|
union.get_set_field.should == :some_characters
|
@@ -71,24 +69,24 @@ class ThriftUnionSpec < Spec::ExampleGroup
|
|
71
69
|
end
|
72
70
|
|
73
71
|
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)
|
72
|
+
union = SpecNamespace::My_union.new(:integer32, 25)
|
73
|
+
other_union = SpecNamespace::My_union.new(:integer32, 400)
|
76
74
|
union.should_not == other_union
|
77
75
|
end
|
78
76
|
|
79
77
|
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)
|
78
|
+
union = SpecNamespace::My_union.new(:integer32, 25)
|
79
|
+
other_union = SpecNamespace::My_union.new(:other_i32, 25)
|
82
80
|
union.should_not == other_union
|
83
81
|
end
|
84
82
|
|
85
83
|
it "should inspect properly" do
|
86
|
-
union = My_union.new(:integer32, 25)
|
84
|
+
union = SpecNamespace::My_union.new(:integer32, 25)
|
87
85
|
union.inspect.should == "<SpecNamespace::My_union integer32: 25>"
|
88
86
|
end
|
89
87
|
|
90
88
|
it "should not allow setting with instance_variable_set" do
|
91
|
-
union = My_union.new(:integer32, 27)
|
89
|
+
union = SpecNamespace::My_union.new(:integer32, 27)
|
92
90
|
union.instance_variable_set(:@some_characters, "hallo!")
|
93
91
|
union.get_set_field.should == :integer32
|
94
92
|
union.get_value.should == 27
|
@@ -99,42 +97,42 @@ class ThriftUnionSpec < Spec::ExampleGroup
|
|
99
97
|
trans = Thrift::MemoryBufferTransport.new
|
100
98
|
proto = Thrift::BinaryProtocol.new(trans)
|
101
99
|
|
102
|
-
union = My_union.new(:integer32, 25)
|
100
|
+
union = SpecNamespace::My_union.new(:integer32, 25)
|
103
101
|
union.write(proto)
|
104
102
|
|
105
|
-
other_union = My_union.new(:integer32, 25)
|
103
|
+
other_union = SpecNamespace::My_union.new(:integer32, 25)
|
106
104
|
other_union.read(proto)
|
107
105
|
other_union.should == union
|
108
106
|
end
|
109
107
|
|
110
108
|
it "should raise when validating unset union" do
|
111
|
-
union = My_union.new
|
109
|
+
union = SpecNamespace::My_union.new
|
112
110
|
lambda { union.validate }.should raise_error(StandardError, "Union fields are not set.")
|
113
111
|
|
114
|
-
other_union = My_union.new(:integer32, 1)
|
112
|
+
other_union = SpecNamespace::My_union.new(:integer32, 1)
|
115
113
|
lambda { other_union.validate }.should_not raise_error(StandardError, "Union fields are not set.")
|
116
114
|
end
|
117
115
|
|
118
116
|
it "should validate an enum field properly" do
|
119
|
-
union = TestUnion.new(:enum_field, 3)
|
117
|
+
union = SpecNamespace::TestUnion.new(:enum_field, 3)
|
120
118
|
union.get_set_field.should == :enum_field
|
121
|
-
lambda { union.validate }.should raise_error(ProtocolException, "Invalid value of field enum_field!")
|
119
|
+
lambda { union.validate }.should raise_error(Thrift::ProtocolException, "Invalid value of field enum_field!")
|
122
120
|
|
123
|
-
other_union = TestUnion.new(:enum_field, 1)
|
124
|
-
lambda { other_union.validate }.should_not raise_error(ProtocolException, "Invalid value of field enum_field!")
|
121
|
+
other_union = SpecNamespace::TestUnion.new(:enum_field, 1)
|
122
|
+
lambda { other_union.validate }.should_not raise_error(Thrift::ProtocolException, "Invalid value of field enum_field!")
|
125
123
|
end
|
126
124
|
|
127
125
|
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)
|
126
|
+
union = SpecNamespace::My_union.new(:integer32, 26)
|
127
|
+
swu = SpecNamespace::Struct_with_union.new(:fun_union => union)
|
130
128
|
|
131
129
|
trans = Thrift::MemoryBufferTransport.new
|
132
130
|
proto = Thrift::CompactProtocol.new(trans)
|
133
131
|
|
134
132
|
swu.write(proto)
|
135
133
|
|
136
|
-
other_union = My_union.new(:some_characters, "hello there")
|
137
|
-
swu2 = Struct_with_union.new(:fun_union => other_union)
|
134
|
+
other_union = SpecNamespace::My_union.new(:some_characters, "hello there")
|
135
|
+
swu2 = SpecNamespace::Struct_with_union.new(:fun_union => other_union)
|
138
136
|
|
139
137
|
swu2.should_not == swu
|
140
138
|
|
@@ -143,30 +141,30 @@ class ThriftUnionSpec < Spec::ExampleGroup
|
|
143
141
|
end
|
144
142
|
|
145
143
|
it "should support old style constructor" do
|
146
|
-
union = My_union.new(:integer32 => 26)
|
144
|
+
union = SpecNamespace::My_union.new(:integer32 => 26)
|
147
145
|
union.get_set_field.should == :integer32
|
148
146
|
union.get_value.should == 26
|
149
147
|
end
|
150
148
|
|
151
149
|
it "should not throw an error when inspected and unset" do
|
152
|
-
lambda{TestUnion.new().inspect}.should_not raise_error
|
150
|
+
lambda{SpecNamespace::TestUnion.new().inspect}.should_not raise_error
|
153
151
|
end
|
154
152
|
|
155
153
|
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)>"
|
154
|
+
SpecNamespace::My_union.new(:some_enum => SpecNamespace::SomeEnum::ONE).inspect.should == "<SpecNamespace::My_union some_enum: ONE (0)>"
|
157
155
|
|
158
|
-
My_union.new(:my_map => {SomeEnum::ONE => [SomeEnum::TWO]}).inspect.should == "<SpecNamespace::My_union my_map: {ONE (0): [TWO (1)]}>"
|
156
|
+
SpecNamespace::My_union.new(:my_map => {SpecNamespace::SomeEnum::ONE => [SpecNamespace::SomeEnum::TWO]}).inspect.should == "<SpecNamespace::My_union my_map: {ONE (0): [TWO (1)]}>"
|
159
157
|
end
|
160
158
|
|
161
159
|
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
|
160
|
+
SpecNamespace::My_union.new.some_enum?.should be_false
|
161
|
+
SpecNamespace::My_union.new(:some_enum => SpecNamespace::SomeEnum::ONE).some_enum?.should be_true
|
162
|
+
SpecNamespace::My_union.new(:im_true => false).im_true?.should be_true
|
163
|
+
SpecNamespace::My_union.new(:im_true => true).im_true?.should be_true
|
166
164
|
end
|
167
165
|
|
168
166
|
it "should pretty print binary fields" do
|
169
|
-
TestUnion.new(:binary_field => "\001\002\003").inspect.should == "<SpecNamespace::TestUnion binary_field: 010203>"
|
167
|
+
SpecNamespace::TestUnion.new(:binary_field => "\001\002\003").inspect.should == "<SpecNamespace::TestUnion binary_field: 010203>"
|
170
168
|
end
|
171
169
|
|
172
170
|
it "should be comparable" do
|
@@ -177,10 +175,10 @@ class ThriftUnionSpec < Spec::ExampleGroup
|
|
177
175
|
[1, 1, 1, 0]]
|
178
176
|
|
179
177
|
objs = [
|
180
|
-
TestUnion.new(:string_field, "blah"),
|
181
|
-
TestUnion.new(:string_field, "blahblah"),
|
182
|
-
TestUnion.new(:i32_field, 1),
|
183
|
-
TestUnion.new()]
|
178
|
+
SpecNamespace::TestUnion.new(:string_field, "blah"),
|
179
|
+
SpecNamespace::TestUnion.new(:string_field, "blahblah"),
|
180
|
+
SpecNamespace::TestUnion.new(:i32_field, 1),
|
181
|
+
SpecNamespace::TestUnion.new()]
|
184
182
|
|
185
183
|
for y in 0..3
|
186
184
|
for x in 0..3
|
data/spec/unix_socket_spec.rb
CHANGED
@@ -17,16 +17,15 @@
|
|
17
17
|
# under the License.
|
18
18
|
#
|
19
19
|
|
20
|
-
require
|
20
|
+
require 'spec_helper'
|
21
21
|
require File.expand_path("#{File.dirname(__FILE__)}/socket_spec_shared")
|
22
22
|
|
23
|
-
|
24
|
-
include Thrift
|
23
|
+
describe 'UNIXSocket' do
|
25
24
|
|
26
|
-
describe UNIXSocket do
|
25
|
+
describe Thrift::UNIXSocket do
|
27
26
|
before(:each) do
|
28
27
|
@path = '/tmp/thrift_spec_socket'
|
29
|
-
@socket = UNIXSocket.new(@path)
|
28
|
+
@socket = Thrift::UNIXSocket.new(@path)
|
30
29
|
@handle = mock("Handle", :closed? => false)
|
31
30
|
@handle.stub!(:close)
|
32
31
|
::UNIXSocket.stub!(:new).and_return(@handle)
|
@@ -41,14 +40,14 @@ class ThriftUNIXSocketSpec < Spec::ExampleGroup
|
|
41
40
|
|
42
41
|
it "should accept an optional timeout" do
|
43
42
|
::UNIXSocket.stub!(:new)
|
44
|
-
UNIXSocket.new(@path, 5).timeout.should == 5
|
43
|
+
Thrift::UNIXSocket.new(@path, 5).timeout.should == 5
|
45
44
|
end
|
46
45
|
end
|
47
46
|
|
48
|
-
describe UNIXServerSocket do
|
47
|
+
describe Thrift::UNIXServerSocket do
|
49
48
|
before(:each) do
|
50
49
|
@path = '/tmp/thrift_spec_socket'
|
51
|
-
@socket = UNIXServerSocket.new(@path)
|
50
|
+
@socket = Thrift::UNIXServerSocket.new(@path)
|
52
51
|
end
|
53
52
|
|
54
53
|
it "should create a handle when calling listen" do
|
@@ -63,7 +62,7 @@ class ThriftUNIXSocketSpec < Spec::ExampleGroup
|
|
63
62
|
sock = mock("sock")
|
64
63
|
handle.should_receive(:accept).and_return(sock)
|
65
64
|
trans = mock("UNIXSocket")
|
66
|
-
UNIXSocket.should_receive(:new).and_return(trans)
|
65
|
+
Thrift::UNIXSocket.should_receive(:new).and_return(trans)
|
67
66
|
trans.should_receive(:handle=).with(sock)
|
68
67
|
@socket.accept.should == trans
|
69
68
|
end
|
@@ -1,12 +1,13 @@
|
|
1
1
|
#
|
2
|
-
# Autogenerated by Thrift Compiler (0.
|
2
|
+
# Autogenerated by Thrift Compiler (0.9.0)
|
3
3
|
#
|
4
4
|
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
5
5
|
#
|
6
6
|
|
7
|
+
require 'thrift'
|
7
8
|
require 'debug_proto_test_types'
|
8
9
|
|
9
|
-
COMPACT_TEST = CompactProtoTestStruct.new({
|
10
|
+
COMPACT_TEST = ::CompactProtoTestStruct.new({
|
10
11
|
%q"a_byte" => 127,
|
11
12
|
%q"a_i16" => 32000,
|
12
13
|
%q"a_i32" => 1000000000,
|
@@ -15,7 +16,7 @@ COMPACT_TEST = CompactProtoTestStruct.new({
|
|
15
16
|
%q"a_string" => %q"my string",
|
16
17
|
%q"true_field" => true,
|
17
18
|
%q"false_field" => false,
|
18
|
-
%q"empty_struct_field" => Empty.new({
|
19
|
+
%q"empty_struct_field" => ::Empty.new({
|
19
20
|
}),
|
20
21
|
%q"byte_list" => [
|
21
22
|
-127,
|
@@ -69,9 +70,9 @@ COMPACT_TEST = CompactProtoTestStruct.new({
|
|
69
70
|
false,
|
70
71
|
],
|
71
72
|
%q"struct_list" => [
|
72
|
-
Empty.new({
|
73
|
+
::Empty.new({
|
73
74
|
}),
|
74
|
-
Empty.new({
|
75
|
+
::Empty.new({
|
75
76
|
}),
|
76
77
|
],
|
77
78
|
%q"byte_set" => Set.new([
|
@@ -119,7 +120,7 @@ COMPACT_TEST = CompactProtoTestStruct.new({
|
|
119
120
|
false,
|
120
121
|
]),
|
121
122
|
%q"struct_set" => Set.new([
|
122
|
-
Empty.new({
|
123
|
+
::Empty.new({
|
123
124
|
}),
|
124
125
|
]),
|
125
126
|
%q"byte_byte_map" => {
|
@@ -266,7 +267,7 @@ MY_ENUM_MAP = {
|
|
266
267
|
}
|
267
268
|
|
268
269
|
EXTRA_CRAZY_MAP = {
|
269
|
-
1 => StructWithSomeEnum.new({
|
270
|
+
1 => ::StructWithSomeEnum.new({
|
270
271
|
%q"blah" => 2,
|
271
272
|
}),
|
272
273
|
}
|