thrift 0.23.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 +203 -40
  3. data/ext/binary_protocol_accelerated.c +130 -40
  4. data/ext/bytes.c +14 -0
  5. data/ext/compact_protocol.c +184 -91
  6. data/ext/constants.h +3 -0
  7. data/ext/extconf.rb +12 -4
  8. data/ext/macros.h +11 -0
  9. data/ext/memory_buffer.c +67 -12
  10. data/ext/struct.c +192 -71
  11. data/ext/thrift_native.c +7 -0
  12. data/lib/thrift/bytes.rb +6 -3
  13. data/lib/thrift/client.rb +31 -33
  14. data/lib/thrift/exceptions.rb +11 -8
  15. data/lib/thrift/multiplexed_processor.rb +17 -8
  16. data/lib/thrift/processor.rb +25 -3
  17. data/lib/thrift/protocol/base_protocol.rb +66 -31
  18. data/lib/thrift/protocol/binary_protocol.rb +80 -37
  19. data/lib/thrift/protocol/binary_protocol_accelerated.rb +7 -2
  20. data/lib/thrift/protocol/compact_protocol.rb +204 -88
  21. data/lib/thrift/protocol/header_protocol.rb +15 -3
  22. data/lib/thrift/protocol/json_protocol.rb +158 -109
  23. data/lib/thrift/protocol/multiplexed_protocol.rb +3 -3
  24. data/lib/thrift/protocol/protocol_decorator.rb +6 -2
  25. data/lib/thrift/serializer/deserializer.rb +1 -0
  26. data/lib/thrift/serializer/serializer.rb +7 -0
  27. data/lib/thrift/server/base_server.rb +11 -2
  28. data/lib/thrift/server/nonblocking_server.rb +69 -20
  29. data/lib/thrift/server/rack_application.rb +69 -0
  30. data/lib/thrift/server/simple_server.rb +27 -15
  31. data/lib/thrift/server/thin_http_server.rb +21 -44
  32. data/lib/thrift/server/thread_pool_server.rb +21 -17
  33. data/lib/thrift/server/threaded_server.rb +22 -18
  34. data/lib/thrift/struct.rb +34 -18
  35. data/lib/thrift/struct_union.rb +37 -36
  36. data/lib/thrift/thrift_native.rb +2 -1
  37. data/lib/thrift/transport/base_server_transport.rb +3 -0
  38. data/lib/thrift/transport/base_transport.rb +26 -4
  39. data/lib/thrift/transport/buffered_transport.rb +5 -4
  40. data/lib/thrift/transport/framed_transport.rb +33 -7
  41. data/lib/thrift/transport/header_transport.rb +159 -33
  42. data/lib/thrift/transport/http_client_transport.rb +28 -14
  43. data/lib/thrift/transport/io_stream_transport.rb +3 -1
  44. data/lib/thrift/transport/memory_buffer_transport.rb +14 -9
  45. data/lib/thrift/transport/server_socket.rb +10 -8
  46. data/lib/thrift/transport/socket.rb +85 -48
  47. data/lib/thrift/transport/ssl_server_socket.rb +67 -6
  48. data/lib/thrift/transport/ssl_socket.rb +73 -14
  49. data/lib/thrift/transport/unix_server_socket.rb +6 -2
  50. data/lib/thrift/transport/unix_socket.rb +5 -6
  51. data/lib/thrift/types.rb +23 -22
  52. data/lib/thrift/union.rb +21 -11
  53. data/lib/thrift/uuid.rb +9 -8
  54. data/lib/thrift.rb +40 -39
  55. metadata +7 -266
  56. data/benchmark/Benchmark.thrift +0 -24
  57. data/benchmark/benchmark.rb +0 -285
  58. data/benchmark/client.rb +0 -117
  59. data/benchmark/server.rb +0 -120
  60. data/benchmark/thin_server.rb +0 -45
  61. data/lib/thrift/server/mongrel_http_server.rb +0 -60
  62. data/spec/BaseService.thrift +0 -27
  63. data/spec/ExtendedService.thrift +0 -25
  64. data/spec/Referenced.thrift +0 -44
  65. data/spec/ThriftNamespacedSpec.thrift +0 -53
  66. data/spec/ThriftSpec.thrift +0 -187
  67. data/spec/base_protocol_spec.rb +0 -224
  68. data/spec/base_transport_spec.rb +0 -387
  69. data/spec/binary_protocol_accelerated_spec.rb +0 -46
  70. data/spec/binary_protocol_spec.rb +0 -72
  71. data/spec/binary_protocol_spec_shared.rb +0 -445
  72. data/spec/bytes_spec.rb +0 -99
  73. data/spec/client_spec.rb +0 -166
  74. data/spec/compact_protocol_spec.rb +0 -196
  75. data/spec/constants_demo_spec.rb +0 -101
  76. data/spec/exception_spec.rb +0 -140
  77. data/spec/flat_spec.rb +0 -62
  78. data/spec/header_protocol_spec.rb +0 -475
  79. data/spec/header_transport_spec.rb +0 -386
  80. data/spec/http_client_spec.rb +0 -159
  81. data/spec/json_protocol_spec.rb +0 -552
  82. data/spec/namespaced_spec.rb +0 -66
  83. data/spec/nonblocking_server_spec.rb +0 -361
  84. data/spec/processor_spec.rb +0 -79
  85. data/spec/serializer_spec.rb +0 -66
  86. data/spec/server_socket_spec.rb +0 -84
  87. data/spec/server_spec.rb +0 -186
  88. data/spec/socket_spec.rb +0 -67
  89. data/spec/socket_spec_shared.rb +0 -167
  90. data/spec/spec_helper.rb +0 -69
  91. data/spec/ssl_server_socket_spec.rb +0 -45
  92. data/spec/ssl_socket_spec.rb +0 -87
  93. data/spec/struct_nested_containers_spec.rb +0 -190
  94. data/spec/struct_spec.rb +0 -397
  95. data/spec/support/header_protocol_helper.rb +0 -54
  96. data/spec/thin_http_server_spec.rb +0 -126
  97. data/spec/types_spec.rb +0 -117
  98. data/spec/union_spec.rb +0 -272
  99. data/spec/unix_socket_spec.rb +0 -115
  100. data/spec/uuid_validation_spec.rb +0 -238
  101. data/test/fuzz/Makefile.am +0 -173
  102. data/test/fuzz/README.md +0 -149
  103. data/test/fuzz/fuzz_common.rb +0 -95
  104. data/test/fuzz/fuzz_parse_binary_protocol.rb +0 -22
  105. data/test/fuzz/fuzz_parse_binary_protocol_accelerated.rb +0 -22
  106. data/test/fuzz/fuzz_parse_binary_protocol_accelerated_harness.rb +0 -22
  107. data/test/fuzz/fuzz_parse_binary_protocol_harness.rb +0 -22
  108. data/test/fuzz/fuzz_parse_compact_protocol.rb +0 -22
  109. data/test/fuzz/fuzz_parse_compact_protocol_harness.rb +0 -22
  110. data/test/fuzz/fuzz_parse_json_protocol.rb +0 -22
  111. data/test/fuzz/fuzz_parse_json_protocol_harness.rb +0 -22
  112. data/test/fuzz/fuzz_roundtrip_binary_protocol.rb +0 -22
  113. data/test/fuzz/fuzz_roundtrip_binary_protocol_accelerated.rb +0 -22
  114. data/test/fuzz/fuzz_roundtrip_binary_protocol_accelerated_harness.rb +0 -22
  115. data/test/fuzz/fuzz_roundtrip_binary_protocol_harness.rb +0 -22
  116. data/test/fuzz/fuzz_roundtrip_compact_protocol.rb +0 -22
  117. data/test/fuzz/fuzz_roundtrip_compact_protocol_harness.rb +0 -22
  118. data/test/fuzz/fuzz_roundtrip_json_protocol.rb +0 -22
  119. data/test/fuzz/fuzz_roundtrip_json_protocol_harness.rb +0 -22
  120. data/test/fuzz/fuzz_tracer.rb +0 -28
@@ -1,126 +0,0 @@
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 'spec_helper'
21
- require 'rack/test'
22
- require 'thrift/server/thin_http_server'
23
-
24
- describe Thrift::ThinHTTPServer do
25
- let(:processor) { double('processor') }
26
-
27
- describe "#initialize" do
28
- context "when using the defaults" do
29
- it "binds to port 80, with host 0.0.0.0, a path of '/'" do
30
- expect(Thin::Server).to receive(:new).with('0.0.0.0', 80, an_instance_of(Rack::Builder))
31
- Thrift::ThinHTTPServer.new(processor)
32
- end
33
-
34
- it 'creates a ThinHTTPServer::RackApplicationContext' do
35
- expect(Thrift::ThinHTTPServer::RackApplication).to receive(:for).with("/", processor, an_instance_of(Thrift::BinaryProtocolFactory)).and_return(anything)
36
- Thrift::ThinHTTPServer.new(processor)
37
- end
38
-
39
- it "uses the BinaryProtocolFactory" do
40
- expect(Thrift::BinaryProtocolFactory).to receive(:new)
41
- Thrift::ThinHTTPServer.new(processor)
42
- end
43
- end
44
-
45
- context "when using the options" do
46
- it 'accepts :ip, :port, :path' do
47
- ip = "192.168.0.1"
48
- port = 3000
49
- path = "/thin"
50
- expect(Thin::Server).to receive(:new).with(ip, port, an_instance_of(Rack::Builder))
51
- Thrift::ThinHTTPServer.new(processor,
52
- :ip => ip,
53
- :port => port,
54
- :path => path)
55
- end
56
-
57
- it 'creates a ThinHTTPServer::RackApplicationContext with a different protocol factory' do
58
- expect(Thrift::ThinHTTPServer::RackApplication).to receive(:for).with("/", processor, an_instance_of(Thrift::JsonProtocolFactory)).and_return(anything)
59
- Thrift::ThinHTTPServer.new(processor,
60
- :protocol_factory => Thrift::JsonProtocolFactory.new)
61
- end
62
- end
63
- end
64
-
65
- describe "#serve" do
66
- it 'starts the Thin server' do
67
- underlying_thin_server = double('thin server', :start => true)
68
- allow(Thin::Server).to receive(:new).and_return(underlying_thin_server)
69
-
70
- thin_thrift_server = Thrift::ThinHTTPServer.new(processor)
71
-
72
- expect(underlying_thin_server).to receive(:start)
73
- thin_thrift_server.serve
74
- end
75
- end
76
- end
77
-
78
- describe Thrift::ThinHTTPServer::RackApplication do
79
- include Rack::Test::Methods
80
-
81
- let(:processor) { double('processor') }
82
- let(:protocol_factory) { double('protocol factory') }
83
-
84
- def app
85
- Thrift::ThinHTTPServer::RackApplication.for("/", processor, protocol_factory)
86
- end
87
-
88
- context "404 response" do
89
- it 'receives a non-POST' do
90
- header('Content-Type', "application/x-thrift")
91
- get "/"
92
- expect(last_response.status).to eq 404
93
- end
94
-
95
- it 'receives a header other than application/x-thrift' do
96
- header('Content-Type', "application/json")
97
- post "/"
98
- expect(last_response.status).to eq 404
99
- end
100
- end
101
-
102
- context "200 response" do
103
- before do
104
- allow(protocol_factory).to receive(:get_protocol)
105
- allow(processor).to receive(:process)
106
- end
107
-
108
- it 'creates an IOStreamTransport' do
109
- header('Content-Type', "application/x-thrift")
110
- expect(Thrift::IOStreamTransport).to receive(:new).with(an_instance_of(Rack::Lint::InputWrapper), an_instance_of(Rack::Response))
111
- post "/"
112
- end
113
-
114
- it 'fetches the right protocol based on the Transport' do
115
- header('Content-Type', "application/x-thrift")
116
- expect(protocol_factory).to receive(:get_protocol).with(an_instance_of(Thrift::IOStreamTransport))
117
- post "/"
118
- end
119
-
120
- it 'status code 200' do
121
- header('Content-Type', "application/x-thrift")
122
- post "/"
123
- expect(last_response.ok?).to be true
124
- end
125
- end
126
- end
data/spec/types_spec.rb DELETED
@@ -1,117 +0,0 @@
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 'spec_helper'
21
-
22
- describe Thrift::Types do
23
- before(:each) do
24
- Thrift.type_checking = true
25
- end
26
-
27
- after(:each) do
28
- Thrift.type_checking = false
29
- end
30
-
31
- context 'type checking' do
32
- it "should return the proper name for each type" do
33
- expect(Thrift.type_name(Thrift::Types::I16)).to eq("Types::I16")
34
- expect(Thrift.type_name(Thrift::Types::VOID)).to eq("Types::VOID")
35
- expect(Thrift.type_name(Thrift::Types::LIST)).to eq("Types::LIST")
36
- expect(Thrift.type_name(42)).to be_nil
37
- end
38
-
39
- it "should check types properly" do
40
- # lambda { Thrift.check_type(nil, Thrift::Types::STOP) }.should raise_error(Thrift::TypeError)
41
- expect { Thrift.check_type(3, {:type => Thrift::Types::STOP}, :foo) }.to raise_error(Thrift::TypeError)
42
- expect { Thrift.check_type(nil, {:type => Thrift::Types::VOID}, :foo) }.not_to raise_error
43
- expect { Thrift.check_type(3, {:type => Thrift::Types::VOID}, :foo) }.to raise_error(Thrift::TypeError)
44
- expect { Thrift.check_type(true, {:type => Thrift::Types::BOOL}, :foo) }.not_to raise_error
45
- expect { Thrift.check_type(3, {:type => Thrift::Types::BOOL}, :foo) }.to raise_error(Thrift::TypeError)
46
- expect { Thrift.check_type(42, {:type => Thrift::Types::BYTE}, :foo) }.not_to raise_error
47
- expect { Thrift.check_type(42, {:type => Thrift::Types::I16}, :foo) }.not_to raise_error
48
- expect { Thrift.check_type(42, {:type => Thrift::Types::I32}, :foo) }.not_to raise_error
49
- expect { Thrift.check_type(42, {:type => Thrift::Types::I64}, :foo) }.not_to raise_error
50
- expect { Thrift.check_type(3.14, {:type => Thrift::Types::I32}, :foo) }.to raise_error(Thrift::TypeError)
51
- expect { Thrift.check_type(3.14, {:type => Thrift::Types::DOUBLE}, :foo) }.not_to raise_error
52
- expect { Thrift.check_type(3, {:type => Thrift::Types::DOUBLE}, :foo) }.to raise_error(Thrift::TypeError)
53
- expect { Thrift.check_type("3", {:type => Thrift::Types::STRING}, :foo) }.not_to raise_error
54
- expect { Thrift.check_type(3, {:type => Thrift::Types::STRING}, :foo) }.to raise_error(Thrift::TypeError)
55
- hello = SpecNamespace::Hello.new
56
- expect { Thrift.check_type(hello, {:type => Thrift::Types::STRUCT, :class => SpecNamespace::Hello}, :foo) }.not_to raise_error
57
- expect { Thrift.check_type("foo", {:type => Thrift::Types::STRUCT}, :foo) }.to raise_error(Thrift::TypeError)
58
- field = {:type => Thrift::Types::MAP, :key => {:type => Thrift::Types::I32}, :value => {:type => Thrift::Types::STRING}}
59
- expect { Thrift.check_type({1 => "one"}, field, :foo) }.not_to raise_error
60
- expect { Thrift.check_type([1], field, :foo) }.to raise_error(Thrift::TypeError)
61
- field = {:type => Thrift::Types::LIST, :element => {:type => Thrift::Types::I32}}
62
- expect { Thrift.check_type([1], field, :foo) }.not_to raise_error
63
- expect { Thrift.check_type({:foo => 1}, field, :foo) }.to raise_error(Thrift::TypeError)
64
- field = {:type => Thrift::Types::SET, :element => {:type => Thrift::Types::I32}}
65
- expect { Thrift.check_type(Set.new([1, 2]), field, :foo) }.not_to raise_error
66
- expect { Thrift.check_type([1, 2], field, :foo) }.to raise_error(Thrift::TypeError)
67
- expect { Thrift.check_type({:foo => true}, field, :foo) }.to raise_error(Thrift::TypeError)
68
- end
69
-
70
- it "should error out if nil is passed and skip_types is false" do
71
- expect { Thrift.check_type(nil, {:type => Thrift::Types::BOOL}, :foo, false) }.to raise_error(Thrift::TypeError)
72
- expect { Thrift.check_type(nil, {:type => Thrift::Types::BYTE}, :foo, false) }.to raise_error(Thrift::TypeError)
73
- expect { Thrift.check_type(nil, {:type => Thrift::Types::I16}, :foo, false) }.to raise_error(Thrift::TypeError)
74
- expect { Thrift.check_type(nil, {:type => Thrift::Types::I32}, :foo, false) }.to raise_error(Thrift::TypeError)
75
- expect { Thrift.check_type(nil, {:type => Thrift::Types::I64}, :foo, false) }.to raise_error(Thrift::TypeError)
76
- expect { Thrift.check_type(nil, {:type => Thrift::Types::DOUBLE}, :foo, false) }.to raise_error(Thrift::TypeError)
77
- expect { Thrift.check_type(nil, {:type => Thrift::Types::STRING}, :foo, false) }.to raise_error(Thrift::TypeError)
78
- expect { Thrift.check_type(nil, {:type => Thrift::Types::STRUCT}, :foo, false) }.to raise_error(Thrift::TypeError)
79
- expect { Thrift.check_type(nil, {:type => Thrift::Types::LIST}, :foo, false) }.to raise_error(Thrift::TypeError)
80
- expect { Thrift.check_type(nil, {:type => Thrift::Types::SET}, :foo, false) }.to raise_error(Thrift::TypeError)
81
- expect { Thrift.check_type(nil, {:type => Thrift::Types::MAP}, :foo, false) }.to raise_error(Thrift::TypeError)
82
- end
83
-
84
- it "should check element types on containers" do
85
- field = {:type => Thrift::Types::LIST, :element => {:type => Thrift::Types::I32}}
86
- expect { Thrift.check_type([1, 2], field, :foo) }.not_to raise_error
87
- expect { Thrift.check_type([1, nil, 2], field, :foo) }.to raise_error(Thrift::TypeError)
88
- field = {:type => Thrift::Types::MAP, :key => {:type => Thrift::Types::I32}, :value => {:type => Thrift::Types::STRING}}
89
- expect { Thrift.check_type({1 => "one", 2 => "two"}, field, :foo) }.not_to raise_error
90
- expect { Thrift.check_type({1 => "one", nil => "nil"}, field, :foo) }.to raise_error(Thrift::TypeError)
91
- expect { Thrift.check_type({1 => nil, 2 => "two"}, field, :foo) }.to raise_error(Thrift::TypeError)
92
- field = {:type => Thrift::Types::SET, :element => {:type => Thrift::Types::I32}}
93
- expect { Thrift.check_type(Set.new([1, 2]), field, :foo) }.not_to raise_error
94
- expect { Thrift.check_type(Set.new([1, nil, 2]), field, :foo) }.to raise_error(Thrift::TypeError)
95
- expect { Thrift.check_type(Set.new([1, 2.3, 2]), field, :foo) }.to raise_error(Thrift::TypeError)
96
-
97
- field = {:type => Thrift::Types::STRUCT, :class => SpecNamespace::Hello}
98
- expect { Thrift.check_type(SpecNamespace::BoolStruct, field, :foo) }.to raise_error(Thrift::TypeError)
99
- end
100
-
101
- it "should give the Thrift::TypeError a readable message" do
102
- msg = "Expected Types::STRING, received Integer for field foo"
103
- expect { Thrift.check_type(3, {:type => Thrift::Types::STRING}, :foo) }.to raise_error(Thrift::TypeError, msg)
104
- msg = "Expected Types::STRING, received Integer for field foo.element"
105
- field = {:type => Thrift::Types::LIST, :element => {:type => Thrift::Types::STRING}}
106
- expect { Thrift.check_type([3], field, :foo) }.to raise_error(Thrift::TypeError, msg)
107
- msg = "Expected Types::I32, received NilClass for field foo.element.key"
108
- field = {:type => Thrift::Types::LIST,
109
- :element => {:type => Thrift::Types::MAP,
110
- :key => {:type => Thrift::Types::I32},
111
- :value => {:type => Thrift::Types::I32}}}
112
- expect { Thrift.check_type([{nil => 3}], field, :foo) }.to raise_error(Thrift::TypeError, msg)
113
- msg = "Expected Types::I32, received NilClass for field foo.element.value"
114
- expect { Thrift.check_type([{1 => nil}], field, :foo) }.to raise_error(Thrift::TypeError, msg)
115
- end
116
- end
117
- end
data/spec/union_spec.rb DELETED
@@ -1,272 +0,0 @@
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 'spec_helper'
21
-
22
- describe 'Union' do
23
- describe Thrift::Union do
24
- it "should return nil value in unset union" do
25
- union = SpecNamespace::My_union.new
26
- expect(union.get_set_field).to eq(nil)
27
- expect(union.get_value).to eq(nil)
28
- end
29
-
30
- it "should set a field and be accessible through get_value and the named field accessor" do
31
- union = SpecNamespace::My_union.new
32
- union.integer32 = 25
33
- expect(union.get_set_field).to eq(:integer32)
34
- expect(union.get_value).to eq(25)
35
- expect(union.integer32).to eq(25)
36
- end
37
-
38
- it "should work correctly when instantiated with static field constructors" do
39
- union = SpecNamespace::My_union.integer32(5)
40
- expect(union.get_set_field).to eq(:integer32)
41
- expect(union.integer32).to eq(5)
42
- end
43
-
44
- it "should raise for wrong set field" do
45
- union = SpecNamespace::My_union.new
46
- union.integer32 = 25
47
- expect { union.some_characters }.to raise_error(RuntimeError, "some_characters is not union's set field.")
48
- end
49
-
50
- it "should raise for wrong set field when hash initialized and type checking is off" do
51
- Thrift.type_checking = false
52
- union = SpecNamespace::My_union.new({incorrect_field: :incorrect})
53
- expect { Thrift::Serializer.new.serialize(union) }.to raise_error(Thrift::ProtocolException, "set_field is not valid for this union!") { |error|
54
- expect(error.type).to eq(Thrift::ProtocolException::INVALID_DATA)
55
- }
56
- end
57
-
58
- it "should not be equal to nil" do
59
- union = SpecNamespace::My_union.new
60
- expect(union).not_to eq(nil)
61
- end
62
-
63
- it "should not be equal with an empty String" do
64
- union = SpecNamespace::My_union.new
65
- expect(union).not_to eq('')
66
- end
67
-
68
- it "should not equate two different unions, i32 vs. string" do
69
- union = SpecNamespace::My_union.new(:integer32, 25)
70
- other_union = SpecNamespace::My_union.new(:some_characters, "blah!")
71
- expect(union).not_to eq(other_union)
72
- end
73
-
74
- it "should properly reset setfield and setvalue" do
75
- union = SpecNamespace::My_union.new(:integer32, 25)
76
- expect(union.get_set_field).to eq(:integer32)
77
- union.some_characters = "blah!"
78
- expect(union.get_set_field).to eq(:some_characters)
79
- expect(union.get_value).to eq("blah!")
80
- expect { union.integer32 }.to raise_error(RuntimeError, "integer32 is not union's set field.")
81
- end
82
-
83
- it "should not equate two different unions with different values" do
84
- union = SpecNamespace::My_union.new(:integer32, 25)
85
- other_union = SpecNamespace::My_union.new(:integer32, 400)
86
- expect(union).not_to eq(other_union)
87
- end
88
-
89
- it "should not equate two different unions with different fields" do
90
- union = SpecNamespace::My_union.new(:integer32, 25)
91
- other_union = SpecNamespace::My_union.new(:other_i32, 25)
92
- expect(union).not_to eq(other_union)
93
- end
94
-
95
- it "should equate two unions with the same UUID value" do
96
- union = SpecNamespace::My_union.new(:unique_id, '550e8400-e29b-41d4-a716-446655440000')
97
- other_union = SpecNamespace::My_union.new(:unique_id, '550e8400-e29b-41d4-a716-446655440000')
98
- expect(union).to eq(other_union)
99
- end
100
-
101
- it "should not equate two unions with different UUID values" do
102
- union = SpecNamespace::My_union.new(:unique_id, '550e8400-e29b-41d4-a716-446655440000')
103
- other_union = SpecNamespace::My_union.new(:unique_id, '6ba7b810-9dad-11d1-80b4-00c04fd430c8')
104
- expect(union).not_to eq(other_union)
105
- end
106
-
107
- it "should not equate UUID union with different field type" do
108
- union = SpecNamespace::My_union.new(:unique_id, '550e8400-e29b-41d4-a716-446655440000')
109
- other_union = SpecNamespace::My_union.new(:some_characters, '550e8400-e29b-41d4-a716-446655440000')
110
- expect(union).not_to eq(other_union)
111
- end
112
-
113
- it "should inspect properly" do
114
- union = SpecNamespace::My_union.new(:integer32, 25)
115
- expect(union.inspect).to eq("<SpecNamespace::My_union integer32: 25>")
116
- end
117
-
118
- it "should not allow setting with instance_variable_set" do
119
- union = SpecNamespace::My_union.new(:integer32, 27)
120
- union.instance_variable_set(:@some_characters, "hallo!")
121
- expect(union.get_set_field).to eq(:integer32)
122
- expect(union.get_value).to eq(27)
123
- expect { union.some_characters }.to raise_error(RuntimeError, "some_characters is not union's set field.")
124
- end
125
-
126
- it "should serialize to binary correctly" do
127
- trans = Thrift::MemoryBufferTransport.new
128
- proto = Thrift::BinaryProtocol.new(trans)
129
-
130
- union = SpecNamespace::My_union.new(:integer32, 25)
131
- union.write(proto)
132
-
133
- other_union = SpecNamespace::My_union.new(:integer32, 25)
134
- other_union.read(proto)
135
- expect(other_union).to eq(union)
136
- end
137
-
138
- it "should serialize to json correctly" do
139
- trans = Thrift::MemoryBufferTransport.new
140
- proto = Thrift::JsonProtocol.new(trans)
141
-
142
- union = SpecNamespace::My_union.new(:integer32, 25)
143
- union.write(proto)
144
-
145
- other_union = SpecNamespace::My_union.new(:integer32, 25)
146
- other_union.read(proto)
147
- expect(other_union).to eq(union)
148
- end
149
-
150
- it "should raise when validating unset union" do
151
- union = SpecNamespace::My_union.new
152
- expect { union.validate }.to raise_error(Thrift::ProtocolException, "Union fields are not set.") { |error|
153
- expect(error.type).to eq(Thrift::ProtocolException::INVALID_DATA)
154
- }
155
-
156
- other_union = SpecNamespace::My_union.new(:integer32, 1)
157
- expect { other_union.validate }.not_to raise_error
158
- end
159
-
160
- it "should validate an enum field properly" do
161
- union = SpecNamespace::TestUnion.new(:enum_field, 3)
162
- expect(union.get_set_field).to eq(:enum_field)
163
- expect { union.validate }.to raise_error(Thrift::ProtocolException, "Invalid value of field enum_field!") { |error|
164
- expect(error.type).to eq(Thrift::ProtocolException::INVALID_DATA)
165
- }
166
-
167
- other_union = SpecNamespace::TestUnion.new(:enum_field, 1)
168
- expect { other_union.validate }.not_to raise_error
169
- end
170
-
171
- it "should properly serialize and match structs with a union" do
172
- union = SpecNamespace::My_union.new(:integer32, 26)
173
- swu = SpecNamespace::Struct_with_union.new(:fun_union => union)
174
-
175
- trans = Thrift::MemoryBufferTransport.new
176
- proto = Thrift::CompactProtocol.new(trans)
177
-
178
- swu.write(proto)
179
-
180
- other_union = SpecNamespace::My_union.new(:some_characters, "hello there")
181
- swu2 = SpecNamespace::Struct_with_union.new(:fun_union => other_union)
182
-
183
- expect(swu2).not_to eq(swu)
184
-
185
- swu2.read(proto)
186
- expect(swu2).to eq(swu)
187
- end
188
-
189
- it "should support old style constructor" do
190
- union = SpecNamespace::My_union.new(:integer32 => 26)
191
- expect(union.get_set_field).to eq(:integer32)
192
- expect(union.get_value).to eq(26)
193
- end
194
-
195
- it "should not throw an error when inspected and unset" do
196
- expect{ SpecNamespace::TestUnion.new().inspect }.not_to raise_error
197
- end
198
-
199
- it "should print enum value name when inspected" do
200
- expect(SpecNamespace::My_union.new(:some_enum => SpecNamespace::SomeEnum::ONE).inspect).to eq("<SpecNamespace::My_union some_enum: ONE (0)>")
201
-
202
- 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)]}>")
203
- end
204
-
205
- it "should offer field? methods" do
206
- expect(SpecNamespace::My_union.new.some_enum?).to be_falsey
207
- expect(SpecNamespace::My_union.new(:some_enum => SpecNamespace::SomeEnum::ONE).some_enum?).to be_truthy
208
- expect(SpecNamespace::My_union.new(:im_true => false).im_true?).to be_truthy
209
- expect(SpecNamespace::My_union.new(:im_true => true).im_true?).to be_truthy
210
- end
211
-
212
- it "should pretty print binary fields" do
213
- expect(SpecNamespace::TestUnion.new(:binary_field => "\001\002\003").inspect).to eq("<SpecNamespace::TestUnion binary_field: 010203>")
214
- end
215
-
216
- it "should be comparable" do
217
- relationships = [
218
- [0, -1, -1, -1, -1, -1],
219
- [1, 0, -1, -1, -1, -1],
220
- [1, 1, 0, -1, -1, -1],
221
- [1, 1, 1, 0, -1, -1],
222
- [1, 1, 1, 1, 0, -1],
223
- [1, 1, 1, 1, 1, 0]]
224
-
225
- objs = [
226
- SpecNamespace::TestUnion.new(:string_field, "blah"),
227
- SpecNamespace::TestUnion.new(:string_field, "blahblah"),
228
- SpecNamespace::TestUnion.new(:i32_field, 1),
229
- SpecNamespace::TestUnion.new(:uuid_field, '550e8400-e29b-41d4-a716-446655440000'),
230
- SpecNamespace::TestUnion.new(:uuid_field, '6ba7b810-9dad-11d1-80b4-00c04fd430c8'),
231
- SpecNamespace::TestUnion.new()]
232
-
233
- objs.size.times do |y|
234
- objs.size.times do |x|
235
- # puts "#{objs[y].inspect} <=> #{objs[x].inspect} should == #{relationships[y][x]}"
236
- expect(objs[y] <=> objs[x]).to eq(relationships[y][x])
237
- end
238
- end
239
- end
240
-
241
- it "should handle UUID as union value" do
242
- union = SpecNamespace::My_union.new
243
- union.unique_id = 'ffffffff-ffff-ffff-ffff-ffffffffffff'
244
-
245
- trans = Thrift::MemoryBufferTransport.new
246
- prot = Thrift::CompactProtocol.new(trans)
247
-
248
- union.write(prot)
249
-
250
- result = SpecNamespace::My_union.new
251
- result.read(prot)
252
-
253
- expect(result.unique_id).to eq('ffffffff-ffff-ffff-ffff-ffffffffffff')
254
- expect(result.get_set_field).to eq(:unique_id)
255
- end
256
-
257
- it "should normalize UUID case in union" do
258
- union = SpecNamespace::My_union.new
259
- union.unique_id = '550E8400-E29B-41D4-A716-446655440000'
260
-
261
- trans = Thrift::MemoryBufferTransport.new
262
- prot = Thrift::BinaryProtocol.new(trans)
263
-
264
- union.write(prot)
265
-
266
- result = SpecNamespace::My_union.new
267
- result.read(prot)
268
-
269
- expect(result.unique_id).to eq('550e8400-e29b-41d4-a716-446655440000')
270
- end
271
- end
272
- end
@@ -1,115 +0,0 @@
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 'spec_helper'
21
- require File.expand_path("#{File.dirname(__FILE__)}/socket_spec_shared")
22
-
23
- describe 'UNIXSocket' do
24
- describe Thrift::UNIXSocket do
25
- before(:each) do
26
- @path = '/tmp/thrift_spec_socket'
27
- @socket = Thrift::UNIXSocket.new(@path)
28
- @handle = double("Handle", :closed? => false)
29
- allow(@handle).to receive(:close)
30
- allow(::UNIXSocket).to receive(:new).and_return(@handle)
31
- end
32
-
33
- it_should_behave_like "a socket"
34
-
35
- it "should raise a TransportException when it cannot open a socket" do
36
- expect(::UNIXSocket).to receive(:new).and_raise(StandardError)
37
- expect { @socket.open }.to raise_error(Thrift::TransportException) { |e| expect(e.type).to eq(Thrift::TransportException::NOT_OPEN) }
38
- end
39
-
40
- it "should accept an optional timeout" do
41
- allow(::UNIXSocket).to receive(:new)
42
- expect(Thrift::UNIXSocket.new(@path, 5).timeout).to eq(5)
43
- end
44
-
45
- it "should provide a reasonable to_s" do
46
- allow(::UNIXSocket).to receive(:new)
47
- expect(Thrift::UNIXSocket.new(@path).to_s).to eq("domain(#{@path})")
48
- end
49
- end
50
-
51
- describe Thrift::UNIXServerSocket do
52
- before(:each) do
53
- @path = '/tmp/thrift_spec_socket'
54
- @socket = Thrift::UNIXServerSocket.new(@path)
55
- end
56
-
57
- it "should create a handle when calling listen" do
58
- expect(UNIXServer).to receive(:new).with(@path)
59
- @socket.listen
60
- end
61
-
62
- it "should create a Thrift::UNIXSocket to wrap accepted sockets" do
63
- handle = double("UNIXServer")
64
- expect(UNIXServer).to receive(:new).with(@path).and_return(handle)
65
- @socket.listen
66
- sock = double("sock")
67
- expect(handle).to receive(:accept).and_return(sock)
68
- trans = double("UNIXSocket")
69
- expect(Thrift::UNIXSocket).to receive(:new).and_return(trans)
70
- expect(trans).to receive(:handle=).with(sock)
71
- expect(@socket.accept).to eq(trans)
72
- end
73
-
74
- it "should close the handle when closed" do
75
- handle = double("UNIXServer", :closed? => false)
76
- expect(UNIXServer).to receive(:new).with(@path).and_return(handle)
77
- @socket.listen
78
- expect(handle).to receive(:close)
79
- allow(File).to receive(:delete)
80
- @socket.close
81
- end
82
-
83
- it "should delete the socket when closed" do
84
- handle = double("UNIXServer", :closed? => false)
85
- expect(UNIXServer).to receive(:new).with(@path).and_return(handle)
86
- @socket.listen
87
- allow(handle).to receive(:close)
88
- expect(File).to receive(:delete).with(@path)
89
- @socket.close
90
- end
91
-
92
- it "should return nil when accepting if there is no handle" do
93
- expect(@socket.accept).to be_nil
94
- end
95
-
96
- it "should return true for closed? when appropriate" do
97
- handle = double("UNIXServer", :closed? => false)
98
- allow(UNIXServer).to receive(:new).and_return(handle)
99
- allow(File).to receive(:delete)
100
- @socket.listen
101
- expect(@socket).not_to be_closed
102
- allow(handle).to receive(:close)
103
- @socket.close
104
- expect(@socket).to be_closed
105
- @socket.listen
106
- expect(@socket).not_to be_closed
107
- allow(handle).to receive(:closed?).and_return(true)
108
- expect(@socket).to be_closed
109
- end
110
-
111
- it "should provide a reasonable to_s" do
112
- expect(@socket.to_s).to eq("domain(#{@path})")
113
- end
114
- end
115
- end