thrift 0.24.0 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +107 -4
  3. data/ext/binary_protocol_accelerated.c +52 -17
  4. data/ext/compact_protocol.c +135 -70
  5. data/ext/constants.h +3 -0
  6. data/ext/extconf.rb +4 -4
  7. data/ext/macros.h +11 -0
  8. data/ext/memory_buffer.c +35 -17
  9. data/ext/struct.c +185 -64
  10. data/ext/thrift_native.c +6 -0
  11. data/lib/thrift/bytes.rb +2 -2
  12. data/lib/thrift/client.rb +31 -22
  13. data/lib/thrift/exceptions.rb +10 -8
  14. data/lib/thrift/multiplexed_processor.rb +5 -6
  15. data/lib/thrift/processor.rb +24 -3
  16. data/lib/thrift/protocol/base_protocol.rb +53 -27
  17. data/lib/thrift/protocol/binary_protocol.rb +54 -40
  18. data/lib/thrift/protocol/binary_protocol_accelerated.rb +6 -2
  19. data/lib/thrift/protocol/compact_protocol.rb +193 -88
  20. data/lib/thrift/protocol/header_protocol.rb +14 -3
  21. data/lib/thrift/protocol/json_protocol.rb +146 -104
  22. data/lib/thrift/protocol/multiplexed_protocol.rb +2 -3
  23. data/lib/thrift/protocol/protocol_decorator.rb +5 -2
  24. data/lib/thrift/serializer/serializer.rb +6 -0
  25. data/lib/thrift/server/base_server.rb +10 -2
  26. data/lib/thrift/server/nonblocking_server.rb +49 -26
  27. data/lib/thrift/server/rack_application.rb +69 -0
  28. data/lib/thrift/server/simple_server.rb +27 -23
  29. data/lib/thrift/server/thin_http_server.rb +20 -44
  30. data/lib/thrift/server/thread_pool_server.rb +20 -17
  31. data/lib/thrift/server/threaded_server.rb +22 -26
  32. data/lib/thrift/struct.rb +33 -18
  33. data/lib/thrift/struct_union.rb +36 -30
  34. data/lib/thrift/transport/base_transport.rb +23 -5
  35. data/lib/thrift/transport/buffered_transport.rb +4 -4
  36. data/lib/thrift/transport/framed_transport.rb +32 -7
  37. data/lib/thrift/transport/header_transport.rb +130 -50
  38. data/lib/thrift/transport/http_client_transport.rb +27 -14
  39. data/lib/thrift/transport/io_stream_transport.rb +2 -1
  40. data/lib/thrift/transport/memory_buffer_transport.rb +8 -10
  41. data/lib/thrift/transport/server_socket.rb +4 -5
  42. data/lib/thrift/transport/socket.rb +20 -22
  43. data/lib/thrift/transport/ssl_server_socket.rb +64 -4
  44. data/lib/thrift/transport/ssl_socket.rb +32 -5
  45. data/lib/thrift/transport/unix_server_socket.rb +1 -1
  46. data/lib/thrift/transport/unix_socket.rb +4 -6
  47. data/lib/thrift/types.rb +22 -22
  48. data/lib/thrift/union.rb +20 -11
  49. data/lib/thrift/uuid.rb +8 -8
  50. data/lib/thrift.rb +39 -39
  51. metadata +5 -230
  52. data/benchmark/Benchmark.thrift +0 -24
  53. data/benchmark/benchmark.rb +0 -286
  54. data/benchmark/client.rb +0 -118
  55. data/benchmark/server.rb +0 -121
  56. data/benchmark/thin_server.rb +0 -46
  57. data/lib/thrift/server/mongrel_http_server.rb +0 -61
  58. data/spec/BaseService.thrift +0 -27
  59. data/spec/ExtendedService.thrift +0 -25
  60. data/spec/Referenced.thrift +0 -44
  61. data/spec/ThriftNamespacedSpec.thrift +0 -53
  62. data/spec/ThriftSpec.thrift +0 -203
  63. data/spec/base_protocol_spec.rb +0 -244
  64. data/spec/base_transport_spec.rb +0 -428
  65. data/spec/binary_protocol_accelerated_spec.rb +0 -47
  66. data/spec/binary_protocol_spec.rb +0 -73
  67. data/spec/binary_protocol_spec_shared.rb +0 -509
  68. data/spec/bytes_spec.rb +0 -117
  69. data/spec/client_spec.rb +0 -167
  70. data/spec/compact_protocol_spec.rb +0 -295
  71. data/spec/constants_demo_spec.rb +0 -102
  72. data/spec/exception_spec.rb +0 -141
  73. data/spec/flat_spec.rb +0 -63
  74. data/spec/header_protocol_spec.rb +0 -476
  75. data/spec/header_transport_spec.rb +0 -431
  76. data/spec/http_client_spec.rb +0 -160
  77. data/spec/json_protocol_spec.rb +0 -574
  78. data/spec/multiplexed_processor_spec.rb +0 -75
  79. data/spec/namespaced_spec.rb +0 -67
  80. data/spec/nonblocking_server_spec.rb +0 -429
  81. data/spec/processor_spec.rb +0 -80
  82. data/spec/recursion_depth_spec.rb +0 -223
  83. data/spec/serializer_spec.rb +0 -67
  84. data/spec/server_socket_spec.rb +0 -121
  85. data/spec/server_spec.rb +0 -238
  86. data/spec/socket_spec.rb +0 -174
  87. data/spec/socket_spec_shared.rb +0 -168
  88. data/spec/spec_helper.rb +0 -70
  89. data/spec/ssl_server_socket_spec.rb +0 -85
  90. data/spec/ssl_socket_spec.rb +0 -248
  91. data/spec/struct_nested_containers_spec.rb +0 -191
  92. data/spec/struct_spec.rb +0 -398
  93. data/spec/support/header_protocol_helper.rb +0 -55
  94. data/spec/thin_http_server_spec.rb +0 -127
  95. data/spec/types_spec.rb +0 -118
  96. data/spec/union_spec.rb +0 -273
  97. data/spec/unix_socket_spec.rb +0 -131
  98. data/spec/uuid_validation_spec.rb +0 -239
  99. data/test/fuzz/Makefile +0 -779
  100. data/test/fuzz/Makefile.am +0 -173
  101. data/test/fuzz/Makefile.in +0 -775
  102. data/test/fuzz/README.md +0 -149
  103. data/test/fuzz/fuzz_common.rb +0 -96
  104. data/test/fuzz/fuzz_parse_binary_protocol.rb +0 -23
  105. data/test/fuzz/fuzz_parse_binary_protocol_accelerated.rb +0 -23
  106. data/test/fuzz/fuzz_parse_binary_protocol_accelerated_harness.rb +0 -23
  107. data/test/fuzz/fuzz_parse_binary_protocol_harness.rb +0 -23
  108. data/test/fuzz/fuzz_parse_compact_protocol.rb +0 -23
  109. data/test/fuzz/fuzz_parse_compact_protocol_harness.rb +0 -23
  110. data/test/fuzz/fuzz_parse_json_protocol.rb +0 -23
  111. data/test/fuzz/fuzz_parse_json_protocol_harness.rb +0 -23
  112. data/test/fuzz/fuzz_roundtrip_binary_protocol.rb +0 -23
  113. data/test/fuzz/fuzz_roundtrip_binary_protocol_accelerated.rb +0 -23
  114. data/test/fuzz/fuzz_roundtrip_binary_protocol_accelerated_harness.rb +0 -23
  115. data/test/fuzz/fuzz_roundtrip_binary_protocol_harness.rb +0 -23
  116. data/test/fuzz/fuzz_roundtrip_compact_protocol.rb +0 -23
  117. data/test/fuzz/fuzz_roundtrip_compact_protocol_harness.rb +0 -23
  118. data/test/fuzz/fuzz_roundtrip_json_protocol.rb +0 -23
  119. data/test/fuzz/fuzz_roundtrip_json_protocol_harness.rb +0 -23
  120. data/test/fuzz/fuzz_tracer.rb +0 -29
data/spec/types_spec.rb DELETED
@@ -1,118 +0,0 @@
1
- # frozen_string_literal: true
2
- #
3
- # Licensed to the Apache Software Foundation (ASF) under one
4
- # or more contributor license agreements. See the NOTICE file
5
- # distributed with this work for additional information
6
- # regarding copyright ownership. The ASF licenses this file
7
- # to you under the Apache License, Version 2.0 (the
8
- # "License"); you may not use this file except in compliance
9
- # with the License. You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing,
14
- # software distributed under the License is distributed on an
15
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
- # KIND, either express or implied. See the License for the
17
- # specific language governing permissions and limitations
18
- # under the License.
19
- #
20
-
21
- require 'spec_helper'
22
-
23
- describe Thrift::Types do
24
- before(:each) do
25
- Thrift.type_checking = true
26
- end
27
-
28
- after(:each) do
29
- Thrift.type_checking = false
30
- end
31
-
32
- context 'type checking' do
33
- it "should return the proper name for each type" do
34
- expect(Thrift.type_name(Thrift::Types::I16)).to eq("Types::I16")
35
- expect(Thrift.type_name(Thrift::Types::VOID)).to eq("Types::VOID")
36
- expect(Thrift.type_name(Thrift::Types::LIST)).to eq("Types::LIST")
37
- expect(Thrift.type_name(42)).to be_nil
38
- end
39
-
40
- it "should check types properly" do
41
- # lambda { Thrift.check_type(nil, Thrift::Types::STOP) }.should raise_error(Thrift::TypeError)
42
- expect { Thrift.check_type(3, {:type => Thrift::Types::STOP}, :foo) }.to raise_error(Thrift::TypeError)
43
- expect { Thrift.check_type(nil, {:type => Thrift::Types::VOID}, :foo) }.not_to raise_error
44
- expect { Thrift.check_type(3, {:type => Thrift::Types::VOID}, :foo) }.to raise_error(Thrift::TypeError)
45
- expect { Thrift.check_type(true, {:type => Thrift::Types::BOOL}, :foo) }.not_to raise_error
46
- expect { Thrift.check_type(3, {:type => Thrift::Types::BOOL}, :foo) }.to raise_error(Thrift::TypeError)
47
- expect { Thrift.check_type(42, {:type => Thrift::Types::BYTE}, :foo) }.not_to raise_error
48
- expect { Thrift.check_type(42, {:type => Thrift::Types::I16}, :foo) }.not_to raise_error
49
- expect { Thrift.check_type(42, {:type => Thrift::Types::I32}, :foo) }.not_to raise_error
50
- expect { Thrift.check_type(42, {:type => Thrift::Types::I64}, :foo) }.not_to raise_error
51
- expect { Thrift.check_type(3.14, {:type => Thrift::Types::I32}, :foo) }.to raise_error(Thrift::TypeError)
52
- expect { Thrift.check_type(3.14, {:type => Thrift::Types::DOUBLE}, :foo) }.not_to raise_error
53
- expect { Thrift.check_type(3, {:type => Thrift::Types::DOUBLE}, :foo) }.to raise_error(Thrift::TypeError)
54
- expect { Thrift.check_type("3", {:type => Thrift::Types::STRING}, :foo) }.not_to raise_error
55
- expect { Thrift.check_type(3, {:type => Thrift::Types::STRING}, :foo) }.to raise_error(Thrift::TypeError)
56
- hello = SpecNamespace::Hello.new
57
- expect { Thrift.check_type(hello, {:type => Thrift::Types::STRUCT, :class => SpecNamespace::Hello}, :foo) }.not_to raise_error
58
- expect { Thrift.check_type("foo", {:type => Thrift::Types::STRUCT}, :foo) }.to raise_error(Thrift::TypeError)
59
- field = {:type => Thrift::Types::MAP, :key => {:type => Thrift::Types::I32}, :value => {:type => Thrift::Types::STRING}}
60
- expect { Thrift.check_type({1 => "one"}, field, :foo) }.not_to raise_error
61
- expect { Thrift.check_type([1], field, :foo) }.to raise_error(Thrift::TypeError)
62
- field = {:type => Thrift::Types::LIST, :element => {:type => Thrift::Types::I32}}
63
- expect { Thrift.check_type([1], field, :foo) }.not_to raise_error
64
- expect { Thrift.check_type({:foo => 1}, field, :foo) }.to raise_error(Thrift::TypeError)
65
- field = {:type => Thrift::Types::SET, :element => {:type => Thrift::Types::I32}}
66
- expect { Thrift.check_type(Set.new([1, 2]), field, :foo) }.not_to raise_error
67
- expect { Thrift.check_type([1, 2], field, :foo) }.to raise_error(Thrift::TypeError)
68
- expect { Thrift.check_type({:foo => true}, field, :foo) }.to raise_error(Thrift::TypeError)
69
- end
70
-
71
- it "should error out if nil is passed and skip_types is false" do
72
- expect { Thrift.check_type(nil, {:type => Thrift::Types::BOOL}, :foo, false) }.to raise_error(Thrift::TypeError)
73
- expect { Thrift.check_type(nil, {:type => Thrift::Types::BYTE}, :foo, false) }.to raise_error(Thrift::TypeError)
74
- expect { Thrift.check_type(nil, {:type => Thrift::Types::I16}, :foo, false) }.to raise_error(Thrift::TypeError)
75
- expect { Thrift.check_type(nil, {:type => Thrift::Types::I32}, :foo, false) }.to raise_error(Thrift::TypeError)
76
- expect { Thrift.check_type(nil, {:type => Thrift::Types::I64}, :foo, false) }.to raise_error(Thrift::TypeError)
77
- expect { Thrift.check_type(nil, {:type => Thrift::Types::DOUBLE}, :foo, false) }.to raise_error(Thrift::TypeError)
78
- expect { Thrift.check_type(nil, {:type => Thrift::Types::STRING}, :foo, false) }.to raise_error(Thrift::TypeError)
79
- expect { Thrift.check_type(nil, {:type => Thrift::Types::STRUCT}, :foo, false) }.to raise_error(Thrift::TypeError)
80
- expect { Thrift.check_type(nil, {:type => Thrift::Types::LIST}, :foo, false) }.to raise_error(Thrift::TypeError)
81
- expect { Thrift.check_type(nil, {:type => Thrift::Types::SET}, :foo, false) }.to raise_error(Thrift::TypeError)
82
- expect { Thrift.check_type(nil, {:type => Thrift::Types::MAP}, :foo, false) }.to raise_error(Thrift::TypeError)
83
- end
84
-
85
- it "should check element types on containers" do
86
- field = {:type => Thrift::Types::LIST, :element => {:type => Thrift::Types::I32}}
87
- expect { Thrift.check_type([1, 2], field, :foo) }.not_to raise_error
88
- expect { Thrift.check_type([1, nil, 2], field, :foo) }.to raise_error(Thrift::TypeError)
89
- field = {:type => Thrift::Types::MAP, :key => {:type => Thrift::Types::I32}, :value => {:type => Thrift::Types::STRING}}
90
- expect { Thrift.check_type({1 => "one", 2 => "two"}, field, :foo) }.not_to raise_error
91
- expect { Thrift.check_type({1 => "one", nil => "nil"}, field, :foo) }.to raise_error(Thrift::TypeError)
92
- expect { Thrift.check_type({1 => nil, 2 => "two"}, field, :foo) }.to raise_error(Thrift::TypeError)
93
- field = {:type => Thrift::Types::SET, :element => {:type => Thrift::Types::I32}}
94
- expect { Thrift.check_type(Set.new([1, 2]), field, :foo) }.not_to raise_error
95
- expect { Thrift.check_type(Set.new([1, nil, 2]), field, :foo) }.to raise_error(Thrift::TypeError)
96
- expect { Thrift.check_type(Set.new([1, 2.3, 2]), field, :foo) }.to raise_error(Thrift::TypeError)
97
-
98
- field = {:type => Thrift::Types::STRUCT, :class => SpecNamespace::Hello}
99
- expect { Thrift.check_type(SpecNamespace::BoolStruct, field, :foo) }.to raise_error(Thrift::TypeError)
100
- end
101
-
102
- it "should give the Thrift::TypeError a readable message" do
103
- msg = "Expected Types::STRING, received Integer for field foo"
104
- expect { Thrift.check_type(3, {:type => Thrift::Types::STRING}, :foo) }.to raise_error(Thrift::TypeError, msg)
105
- msg = "Expected Types::STRING, received Integer for field foo.element"
106
- field = {:type => Thrift::Types::LIST, :element => {:type => Thrift::Types::STRING}}
107
- expect { Thrift.check_type([3], field, :foo) }.to raise_error(Thrift::TypeError, msg)
108
- msg = "Expected Types::I32, received NilClass for field foo.element.key"
109
- field = {:type => Thrift::Types::LIST,
110
- :element => {:type => Thrift::Types::MAP,
111
- :key => {:type => Thrift::Types::I32},
112
- :value => {:type => Thrift::Types::I32}}}
113
- expect { Thrift.check_type([{nil => 3}], field, :foo) }.to raise_error(Thrift::TypeError, msg)
114
- msg = "Expected Types::I32, received NilClass for field foo.element.value"
115
- expect { Thrift.check_type([{1 => nil}], field, :foo) }.to raise_error(Thrift::TypeError, msg)
116
- end
117
- end
118
- end
data/spec/union_spec.rb DELETED
@@ -1,273 +0,0 @@
1
- # frozen_string_literal: true
2
- #
3
- # Licensed to the Apache Software Foundation (ASF) under one
4
- # or more contributor license agreements. See the NOTICE file
5
- # distributed with this work for additional information
6
- # regarding copyright ownership. The ASF licenses this file
7
- # to you under the Apache License, Version 2.0 (the
8
- # "License"); you may not use this file except in compliance
9
- # with the License. You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing,
14
- # software distributed under the License is distributed on an
15
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
- # KIND, either express or implied. See the License for the
17
- # specific language governing permissions and limitations
18
- # under the License.
19
- #
20
-
21
- require 'spec_helper'
22
-
23
- describe 'Union' do
24
- describe Thrift::Union do
25
- it "should return nil value in unset union" do
26
- union = SpecNamespace::My_union.new
27
- expect(union.get_set_field).to eq(nil)
28
- expect(union.get_value).to eq(nil)
29
- end
30
-
31
- it "should set a field and be accessible through get_value and the named field accessor" do
32
- union = SpecNamespace::My_union.new
33
- union.integer32 = 25
34
- expect(union.get_set_field).to eq(:integer32)
35
- expect(union.get_value).to eq(25)
36
- expect(union.integer32).to eq(25)
37
- end
38
-
39
- it "should work correctly when instantiated with static field constructors" do
40
- union = SpecNamespace::My_union.integer32(5)
41
- expect(union.get_set_field).to eq(:integer32)
42
- expect(union.integer32).to eq(5)
43
- end
44
-
45
- it "should raise for wrong set field" do
46
- union = SpecNamespace::My_union.new
47
- union.integer32 = 25
48
- expect { union.some_characters }.to raise_error(RuntimeError, "some_characters is not union's set field.")
49
- end
50
-
51
- it "should raise for wrong set field when hash initialized and type checking is off" do
52
- Thrift.type_checking = false
53
- union = SpecNamespace::My_union.new({incorrect_field: :incorrect})
54
- expect { Thrift::Serializer.new.serialize(union) }.to raise_error(Thrift::ProtocolException, "set_field is not valid for this union!") { |error|
55
- expect(error.type).to eq(Thrift::ProtocolException::INVALID_DATA)
56
- }
57
- end
58
-
59
- it "should not be equal to nil" do
60
- union = SpecNamespace::My_union.new
61
- expect(union).not_to eq(nil)
62
- end
63
-
64
- it "should not be equal with an empty String" do
65
- union = SpecNamespace::My_union.new
66
- expect(union).not_to eq('')
67
- end
68
-
69
- it "should not equate two different unions, i32 vs. string" do
70
- union = SpecNamespace::My_union.new(:integer32, 25)
71
- other_union = SpecNamespace::My_union.new(:some_characters, "blah!")
72
- expect(union).not_to eq(other_union)
73
- end
74
-
75
- it "should properly reset setfield and setvalue" do
76
- union = SpecNamespace::My_union.new(:integer32, 25)
77
- expect(union.get_set_field).to eq(:integer32)
78
- union.some_characters = "blah!"
79
- expect(union.get_set_field).to eq(:some_characters)
80
- expect(union.get_value).to eq("blah!")
81
- expect { union.integer32 }.to raise_error(RuntimeError, "integer32 is not union's set field.")
82
- end
83
-
84
- it "should not equate two different unions with different values" do
85
- union = SpecNamespace::My_union.new(:integer32, 25)
86
- other_union = SpecNamespace::My_union.new(:integer32, 400)
87
- expect(union).not_to eq(other_union)
88
- end
89
-
90
- it "should not equate two different unions with different fields" do
91
- union = SpecNamespace::My_union.new(:integer32, 25)
92
- other_union = SpecNamespace::My_union.new(:other_i32, 25)
93
- expect(union).not_to eq(other_union)
94
- end
95
-
96
- it "should equate two unions with the same UUID value" do
97
- union = SpecNamespace::My_union.new(:unique_id, '550e8400-e29b-41d4-a716-446655440000')
98
- other_union = SpecNamespace::My_union.new(:unique_id, '550e8400-e29b-41d4-a716-446655440000')
99
- expect(union).to eq(other_union)
100
- end
101
-
102
- it "should not equate two unions with different UUID values" do
103
- union = SpecNamespace::My_union.new(:unique_id, '550e8400-e29b-41d4-a716-446655440000')
104
- other_union = SpecNamespace::My_union.new(:unique_id, '6ba7b810-9dad-11d1-80b4-00c04fd430c8')
105
- expect(union).not_to eq(other_union)
106
- end
107
-
108
- it "should not equate UUID union with different field type" do
109
- union = SpecNamespace::My_union.new(:unique_id, '550e8400-e29b-41d4-a716-446655440000')
110
- other_union = SpecNamespace::My_union.new(:some_characters, '550e8400-e29b-41d4-a716-446655440000')
111
- expect(union).not_to eq(other_union)
112
- end
113
-
114
- it "should inspect properly" do
115
- union = SpecNamespace::My_union.new(:integer32, 25)
116
- expect(union.inspect).to eq("<SpecNamespace::My_union integer32: 25>")
117
- end
118
-
119
- it "should not allow setting with instance_variable_set" do
120
- union = SpecNamespace::My_union.new(:integer32, 27)
121
- union.instance_variable_set(:@some_characters, "hallo!")
122
- expect(union.get_set_field).to eq(:integer32)
123
- expect(union.get_value).to eq(27)
124
- expect { union.some_characters }.to raise_error(RuntimeError, "some_characters is not union's set field.")
125
- end
126
-
127
- it "should serialize to binary correctly" do
128
- trans = Thrift::MemoryBufferTransport.new
129
- proto = Thrift::BinaryProtocol.new(trans)
130
-
131
- union = SpecNamespace::My_union.new(:integer32, 25)
132
- union.write(proto)
133
-
134
- other_union = SpecNamespace::My_union.new(:integer32, 25)
135
- other_union.read(proto)
136
- expect(other_union).to eq(union)
137
- end
138
-
139
- it "should serialize to json correctly" do
140
- trans = Thrift::MemoryBufferTransport.new
141
- proto = Thrift::JsonProtocol.new(trans)
142
-
143
- union = SpecNamespace::My_union.new(:integer32, 25)
144
- union.write(proto)
145
-
146
- other_union = SpecNamespace::My_union.new(:integer32, 25)
147
- other_union.read(proto)
148
- expect(other_union).to eq(union)
149
- end
150
-
151
- it "should raise when validating unset union" do
152
- union = SpecNamespace::My_union.new
153
- expect { union.validate }.to raise_error(Thrift::ProtocolException, "Union fields are not set.") { |error|
154
- expect(error.type).to eq(Thrift::ProtocolException::INVALID_DATA)
155
- }
156
-
157
- other_union = SpecNamespace::My_union.new(:integer32, 1)
158
- expect { other_union.validate }.not_to raise_error
159
- end
160
-
161
- it "should validate an enum field properly" do
162
- union = SpecNamespace::TestUnion.new(:enum_field, 3)
163
- expect(union.get_set_field).to eq(:enum_field)
164
- expect { union.validate }.to raise_error(Thrift::ProtocolException, "Invalid value of field enum_field!") { |error|
165
- expect(error.type).to eq(Thrift::ProtocolException::INVALID_DATA)
166
- }
167
-
168
- other_union = SpecNamespace::TestUnion.new(:enum_field, 1)
169
- expect { other_union.validate }.not_to raise_error
170
- end
171
-
172
- it "should properly serialize and match structs with a union" do
173
- union = SpecNamespace::My_union.new(:integer32, 26)
174
- swu = SpecNamespace::Struct_with_union.new(:fun_union => union)
175
-
176
- trans = Thrift::MemoryBufferTransport.new
177
- proto = Thrift::CompactProtocol.new(trans)
178
-
179
- swu.write(proto)
180
-
181
- other_union = SpecNamespace::My_union.new(:some_characters, "hello there")
182
- swu2 = SpecNamespace::Struct_with_union.new(:fun_union => other_union)
183
-
184
- expect(swu2).not_to eq(swu)
185
-
186
- swu2.read(proto)
187
- expect(swu2).to eq(swu)
188
- end
189
-
190
- it "should support old style constructor" do
191
- union = SpecNamespace::My_union.new(:integer32 => 26)
192
- expect(union.get_set_field).to eq(:integer32)
193
- expect(union.get_value).to eq(26)
194
- end
195
-
196
- it "should not throw an error when inspected and unset" do
197
- expect{ SpecNamespace::TestUnion.new().inspect }.not_to raise_error
198
- end
199
-
200
- it "should print enum value name when inspected" do
201
- expect(SpecNamespace::My_union.new(:some_enum => SpecNamespace::SomeEnum::ONE).inspect).to eq("<SpecNamespace::My_union some_enum: ONE (0)>")
202
-
203
- expect(SpecNamespace::My_union.new(:my_map => {SpecNamespace::SomeEnum::ONE => [SpecNamespace::SomeEnum::TWO]}).inspect).to eq("<SpecNamespace::My_union my_map: {ONE (0): [TWO (1)]}>")
204
- end
205
-
206
- it "should offer field? methods" do
207
- expect(SpecNamespace::My_union.new.some_enum?).to be_falsey
208
- expect(SpecNamespace::My_union.new(:some_enum => SpecNamespace::SomeEnum::ONE).some_enum?).to be_truthy
209
- expect(SpecNamespace::My_union.new(:im_true => false).im_true?).to be_truthy
210
- expect(SpecNamespace::My_union.new(:im_true => true).im_true?).to be_truthy
211
- end
212
-
213
- it "should pretty print binary fields" do
214
- expect(SpecNamespace::TestUnion.new(:binary_field => "\001\002\003").inspect).to eq("<SpecNamespace::TestUnion binary_field: 010203>")
215
- end
216
-
217
- it "should be comparable" do
218
- relationships = [
219
- [0, -1, -1, -1, -1, -1],
220
- [1, 0, -1, -1, -1, -1],
221
- [1, 1, 0, -1, -1, -1],
222
- [1, 1, 1, 0, -1, -1],
223
- [1, 1, 1, 1, 0, -1],
224
- [1, 1, 1, 1, 1, 0]]
225
-
226
- objs = [
227
- SpecNamespace::TestUnion.new(:string_field, "blah"),
228
- SpecNamespace::TestUnion.new(:string_field, "blahblah"),
229
- SpecNamespace::TestUnion.new(:i32_field, 1),
230
- SpecNamespace::TestUnion.new(:uuid_field, '550e8400-e29b-41d4-a716-446655440000'),
231
- SpecNamespace::TestUnion.new(:uuid_field, '6ba7b810-9dad-11d1-80b4-00c04fd430c8'),
232
- SpecNamespace::TestUnion.new()]
233
-
234
- objs.size.times do |y|
235
- objs.size.times do |x|
236
- # puts "#{objs[y].inspect} <=> #{objs[x].inspect} should == #{relationships[y][x]}"
237
- expect(objs[y] <=> objs[x]).to eq(relationships[y][x])
238
- end
239
- end
240
- end
241
-
242
- it "should handle UUID as union value" do
243
- union = SpecNamespace::My_union.new
244
- union.unique_id = 'ffffffff-ffff-ffff-ffff-ffffffffffff'
245
-
246
- trans = Thrift::MemoryBufferTransport.new
247
- prot = Thrift::CompactProtocol.new(trans)
248
-
249
- union.write(prot)
250
-
251
- result = SpecNamespace::My_union.new
252
- result.read(prot)
253
-
254
- expect(result.unique_id).to eq('ffffffff-ffff-ffff-ffff-ffffffffffff')
255
- expect(result.get_set_field).to eq(:unique_id)
256
- end
257
-
258
- it "should normalize UUID case in union" do
259
- union = SpecNamespace::My_union.new
260
- union.unique_id = '550E8400-E29B-41D4-A716-446655440000'
261
-
262
- trans = Thrift::MemoryBufferTransport.new
263
- prot = Thrift::BinaryProtocol.new(trans)
264
-
265
- union.write(prot)
266
-
267
- result = SpecNamespace::My_union.new
268
- result.read(prot)
269
-
270
- expect(result.unique_id).to eq('550e8400-e29b-41d4-a716-446655440000')
271
- end
272
- end
273
- end
@@ -1,131 +0,0 @@
1
- # frozen_string_literal: true
2
- #
3
- # Licensed to the Apache Software Foundation (ASF) under one
4
- # or more contributor license agreements. See the NOTICE file
5
- # distributed with this work for additional information
6
- # regarding copyright ownership. The ASF licenses this file
7
- # to you under the Apache License, Version 2.0 (the
8
- # "License"); you may not use this file except in compliance
9
- # with the License. You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing,
14
- # software distributed under the License is distributed on an
15
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
- # KIND, either express or implied. See the License for the
17
- # specific language governing permissions and limitations
18
- # under the License.
19
- #
20
-
21
- require 'spec_helper'
22
- require File.expand_path("#{File.dirname(__FILE__)}/socket_spec_shared")
23
-
24
- describe 'UNIXSocket' do
25
- describe Thrift::UNIXSocket do
26
- before(:each) do
27
- @path = '/tmp/thrift_spec_socket'
28
- @socket = Thrift::UNIXSocket.new(@path)
29
- @handle = double("Handle", :closed? => false)
30
- allow(@handle).to receive(:close)
31
- allow(::UNIXSocket).to receive(:new).and_return(@handle)
32
- end
33
-
34
- it_should_behave_like "a socket"
35
-
36
- it "should raise a TransportException when it cannot open a socket" do
37
- expect(::UNIXSocket).to receive(:new).and_raise(StandardError)
38
- expect { @socket.open }.to raise_error(Thrift::TransportException) { |e| expect(e.type).to eq(Thrift::TransportException::NOT_OPEN) }
39
- end
40
-
41
- it "should accept an optional timeout" do
42
- allow(::UNIXSocket).to receive(:new)
43
- expect(Thrift::UNIXSocket.new(@path, 5).timeout).to eq(5)
44
- end
45
-
46
- it "should provide a reasonable to_s" do
47
- allow(::UNIXSocket).to receive(:new)
48
- expect(Thrift::UNIXSocket.new(@path).to_s).to eq("domain(#{@path})")
49
- end
50
- end
51
-
52
- describe Thrift::UNIXServerSocket do
53
- before(:each) do
54
- @path = '/tmp/thrift_spec_socket'
55
- @socket = Thrift::UNIXServerSocket.new(@path)
56
- end
57
-
58
- it "should create a handle when calling listen" do
59
- expect(UNIXServer).to receive(:new).with(@path)
60
- @socket.listen
61
- end
62
-
63
- it "should create a Thrift::UNIXSocket to wrap accepted sockets" do
64
- handle = double("UNIXServer")
65
- expect(UNIXServer).to receive(:new).with(@path).and_return(handle)
66
- @socket.listen
67
- sock = double("sock")
68
- expect(handle).to receive(:accept).and_return(sock)
69
- trans = double("UNIXSocket")
70
- expect(Thrift::UNIXSocket).to receive(:new).and_return(trans)
71
- expect(trans).to receive(:timeout=).with(Thrift::BaseServerTransport::DEFAULT_CLIENT_TIMEOUT)
72
- expect(trans).to receive(:handle=).with(sock)
73
- expect(@socket.accept).to eq(trans)
74
- end
75
-
76
- it "should default accepted sockets to a finite client timeout" do
77
- expect(@socket.client_timeout).to eq(5)
78
- end
79
-
80
- it "should accept a custom client timeout" do
81
- @socket = Thrift::UNIXServerSocket.new(@path, client_timeout: 2.5)
82
- expect(@socket.client_timeout).to eq(2.5)
83
- end
84
-
85
- it "should allow blocking accepted sockets with nil or zero client timeout" do
86
- expect(Thrift::UNIXServerSocket.new(@path, client_timeout: nil).client_timeout).to be_nil
87
- expect(Thrift::UNIXServerSocket.new(@path, client_timeout: 0).client_timeout).to eq(0)
88
- end
89
-
90
- it "should close the handle when closed" do
91
- handle = double("UNIXServer", :closed? => false)
92
- expect(UNIXServer).to receive(:new).with(@path).and_return(handle)
93
- @socket.listen
94
- expect(handle).to receive(:close)
95
- allow(File).to receive(:delete)
96
- @socket.close
97
- end
98
-
99
- it "should delete the socket when closed" do
100
- handle = double("UNIXServer", :closed? => false)
101
- expect(UNIXServer).to receive(:new).with(@path).and_return(handle)
102
- @socket.listen
103
- allow(handle).to receive(:close)
104
- expect(File).to receive(:delete).with(@path)
105
- @socket.close
106
- end
107
-
108
- it "should return nil when accepting if there is no handle" do
109
- expect(@socket.accept).to be_nil
110
- end
111
-
112
- it "should return true for closed? when appropriate" do
113
- handle = double("UNIXServer", :closed? => false)
114
- allow(UNIXServer).to receive(:new).and_return(handle)
115
- allow(File).to receive(:delete)
116
- @socket.listen
117
- expect(@socket).not_to be_closed
118
- allow(handle).to receive(:close)
119
- @socket.close
120
- expect(@socket).to be_closed
121
- @socket.listen
122
- expect(@socket).not_to be_closed
123
- allow(handle).to receive(:closed?).and_return(true)
124
- expect(@socket).to be_closed
125
- end
126
-
127
- it "should provide a reasonable to_s" do
128
- expect(@socket.to_s).to eq("domain(#{@path})")
129
- end
130
- end
131
- end