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
data/spec/server_spec.rb DELETED
@@ -1,186 +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
- require 'spec_helper'
20
-
21
- describe 'Server' do
22
- describe Thrift::BaseServer do
23
- before(:each) do
24
- @processor = double("Processor")
25
- @serverTrans = double("ServerTransport")
26
- @trans = double("BaseTransport")
27
- @prot = double("BaseProtocol")
28
- @server = described_class.new(@processor, @serverTrans, @trans, @prot)
29
- end
30
-
31
- it "should default to BaseTransportFactory and BinaryProtocolFactory when not specified" do
32
- @server = Thrift::BaseServer.new(double("Processor"), double("BaseServerTransport"))
33
- expect(@server.instance_variable_get(:'@transport_factory')).to be_an_instance_of(Thrift::BaseTransportFactory)
34
- expect(@server.instance_variable_get(:'@protocol_factory')).to be_an_instance_of(Thrift::BinaryProtocolFactory)
35
- end
36
-
37
- it "should not serve" do
38
- expect { @server.serve() }.to raise_error(NotImplementedError)
39
- end
40
-
41
- it "should provide a reasonable to_s" do
42
- expect(@serverTrans).to receive(:to_s).once.and_return("serverTrans")
43
- expect(@trans).to receive(:to_s).once.and_return("trans")
44
- expect(@prot).to receive(:to_s).once.and_return("prot")
45
- expect(@server.to_s).to eq("server(prot(trans(serverTrans)))")
46
- end
47
- end
48
-
49
- describe Thrift::SimpleServer do
50
- before(:each) do
51
- @processor = double("Processor")
52
- @serverTrans = double("ServerTransport")
53
- @trans = double("BaseTransport")
54
- @prot = double("BaseProtocol")
55
- @client = double("Client")
56
- @server = described_class.new(@processor, @serverTrans, @trans, @prot)
57
- end
58
-
59
- it "should provide a reasonable to_s" do
60
- expect(@serverTrans).to receive(:to_s).once.and_return("serverTrans")
61
- expect(@trans).to receive(:to_s).once.and_return("trans")
62
- expect(@prot).to receive(:to_s).once.and_return("prot")
63
- expect(@server.to_s).to eq("simple(server(prot(trans(serverTrans))))")
64
- end
65
-
66
- it "should serve in the main thread" do
67
- expect(@serverTrans).to receive(:listen).ordered
68
- expect(@serverTrans).to receive(:accept).exactly(3).times.and_return(@client)
69
- expect(@trans).to receive(:get_transport).exactly(3).times.with(@client).and_return(@trans)
70
- expect(@prot).to receive(:get_protocol).exactly(3).times.with(@trans).and_return(@prot)
71
- x = 0
72
- expect(@processor).to receive(:process).exactly(3).times.with(@prot, @prot) do
73
- case (x += 1)
74
- when 1 then raise Thrift::TransportException
75
- when 2 then raise Thrift::ProtocolException
76
- when 3 then throw :stop
77
- end
78
- end
79
- expect(@trans).to receive(:close).exactly(3).times
80
- expect(@serverTrans).to receive(:close).ordered
81
- expect { @server.serve }.to throw_symbol(:stop)
82
- end
83
- end
84
-
85
- describe Thrift::ThreadedServer do
86
- before(:each) do
87
- @processor = double("Processor")
88
- @serverTrans = double("ServerTransport")
89
- @trans = double("BaseTransport")
90
- @prot = double("BaseProtocol")
91
- @client = double("Client")
92
- @server = described_class.new(@processor, @serverTrans, @trans, @prot)
93
- end
94
-
95
- it "should provide a reasonable to_s" do
96
- expect(@serverTrans).to receive(:to_s).once.and_return("serverTrans")
97
- expect(@trans).to receive(:to_s).once.and_return("trans")
98
- expect(@prot).to receive(:to_s).once.and_return("prot")
99
- expect(@server.to_s).to eq("threaded(server(prot(trans(serverTrans))))")
100
- end
101
-
102
- it "should serve using threads" do
103
- expect(@serverTrans).to receive(:listen).ordered
104
- expect(@serverTrans).to receive(:accept).exactly(3).times.and_return(@client)
105
- expect(@trans).to receive(:get_transport).exactly(3).times.with(@client).and_return(@trans)
106
- expect(@prot).to receive(:get_protocol).exactly(3).times.with(@trans).and_return(@prot)
107
- expect(Thread).to receive(:new).with(@prot, @trans).exactly(3).times.and_yield(@prot, @trans)
108
- x = 0
109
- expect(@processor).to receive(:process).exactly(3).times.with(@prot, @prot) do
110
- case (x += 1)
111
- when 1 then raise Thrift::TransportException
112
- when 2 then raise Thrift::ProtocolException
113
- when 3 then throw :stop
114
- end
115
- end
116
- expect(@trans).to receive(:close).exactly(3).times
117
- expect(@serverTrans).to receive(:close).ordered
118
- expect { @server.serve }.to throw_symbol(:stop)
119
- end
120
- end
121
-
122
- describe Thrift::ThreadPoolServer do
123
- before(:each) do
124
- @processor = double("Processor")
125
- @server_trans = double("ServerTransport")
126
- @trans = double("BaseTransport")
127
- @prot = double("BaseProtocol")
128
- @client = double("Client")
129
- @server = described_class.new(@processor, @server_trans, @trans, @prot)
130
- sleep(0.15)
131
- end
132
-
133
- it "should provide a reasonable to_s" do
134
- expect(@server_trans).to receive(:to_s).once.and_return("server_trans")
135
- expect(@trans).to receive(:to_s).once.and_return("trans")
136
- expect(@prot).to receive(:to_s).once.and_return("prot")
137
- expect(@server.to_s).to eq("threadpool(server(prot(trans(server_trans))))")
138
- end
139
-
140
- it "should serve inside a thread" do
141
- exception_q = @server.instance_variable_get(:@exception_q)
142
- expect_any_instance_of(described_class).to receive(:serve) do
143
- exception_q.push(StandardError.new('ERROR'))
144
- end
145
- expect { @server.rescuable_serve }.to(raise_error('ERROR'))
146
- sleep(0.15)
147
- end
148
-
149
- it "should avoid running the server twice when retrying rescuable_serve" do
150
- exception_q = @server.instance_variable_get(:@exception_q)
151
- expect_any_instance_of(described_class).to receive(:serve) do
152
- exception_q.push(StandardError.new('ERROR1'))
153
- exception_q.push(StandardError.new('ERROR2'))
154
- end
155
- expect { @server.rescuable_serve }.to(raise_error('ERROR1'))
156
- expect { @server.rescuable_serve }.to(raise_error('ERROR2'))
157
- end
158
-
159
- it "should serve using a thread pool" do
160
- thread_q = double("SizedQueue")
161
- exception_q = double("Queue")
162
- @server.instance_variable_set(:@thread_q, thread_q)
163
- @server.instance_variable_set(:@exception_q, exception_q)
164
- expect(@server_trans).to receive(:listen).ordered
165
- expect(thread_q).to receive(:push).with(:token)
166
- expect(thread_q).to receive(:pop)
167
- expect(Thread).to receive(:new).and_yield
168
- expect(@server_trans).to receive(:accept).exactly(3).times.and_return(@client)
169
- expect(@trans).to receive(:get_transport).exactly(3).times.and_return(@trans)
170
- expect(@prot).to receive(:get_protocol).exactly(3).times.and_return(@prot)
171
- x = 0
172
- error = RuntimeError.new("Stopped")
173
- expect(@processor).to receive(:process).exactly(3).times.with(@prot, @prot) do
174
- case (x += 1)
175
- when 1 then raise Thrift::TransportException
176
- when 2 then raise Thrift::ProtocolException
177
- when 3 then raise error
178
- end
179
- end
180
- expect(@trans).to receive(:close).exactly(3).times
181
- expect(exception_q).to receive(:push).with(error).and_throw(:stop)
182
- expect(@server_trans).to receive(:close)
183
- expect { @server.serve }.to(throw_symbol(:stop))
184
- end
185
- end
186
- end
data/spec/socket_spec.rb DELETED
@@ -1,67 +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 'Socket' do
24
- describe Thrift::Socket do
25
- before(:each) do
26
- @socket = Thrift::Socket.new
27
- @handle = double("Handle", :closed? => false)
28
- allow(@handle).to receive(:close)
29
- allow(@handle).to receive(:connect_nonblock)
30
- allow(@handle).to receive(:setsockopt)
31
- allow(::Socket).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(::Socket).to receive(:getaddrinfo).with("localhost", 9090, nil, ::Socket::SOCK_STREAM).and_return([[]])
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 open a ::Socket with default args" do
42
- expect(::Socket).to receive(:new).and_return(double("Handle", :connect_nonblock => true, :setsockopt => nil))
43
- expect(::Socket).to receive(:getaddrinfo).with("localhost", 9090, nil, ::Socket::SOCK_STREAM).and_return([[]])
44
- expect(::Socket).to receive(:sockaddr_in)
45
- @socket.to_s == "socket(localhost:9090)"
46
- @socket.open
47
- end
48
-
49
- it "should accept host/port options" do
50
- expect(::Socket).to receive(:new).and_return(double("Handle", :connect_nonblock => true, :setsockopt => nil))
51
- expect(::Socket).to receive(:getaddrinfo).with("my.domain", 1234, nil, ::Socket::SOCK_STREAM).and_return([[]])
52
- expect(::Socket).to receive(:sockaddr_in)
53
- @socket = Thrift::Socket.new('my.domain', 1234).open
54
- @socket.to_s == "socket(my.domain:1234)"
55
- end
56
-
57
- it "should accept an optional timeout" do
58
- allow(::Socket).to receive(:new)
59
- expect(Thrift::Socket.new('localhost', 8080, 5).timeout).to eq(5)
60
- end
61
-
62
- it "should provide a reasonable to_s" do
63
- allow(::Socket).to receive(:new)
64
- expect(Thrift::Socket.new('myhost', 8090).to_s).to eq("socket(myhost:8090)")
65
- end
66
- end
67
- end
@@ -1,167 +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
- shared_examples_for "a socket" do
23
- it "should open a socket" do
24
- expect(@socket.open).to eq(@handle)
25
- end
26
-
27
- it "should be open whenever it has a handle" do
28
- expect(@socket).not_to be_open
29
- @socket.open
30
- expect(@socket).to be_open
31
- @socket.handle = nil
32
- expect(@socket).not_to be_open
33
- @socket.handle = @handle
34
- @socket.close
35
- expect(@socket).not_to be_open
36
- end
37
-
38
- it "should write data to the handle" do
39
- @socket.open
40
- expect(@handle).to receive(:write).with("foobar")
41
- @socket.write("foobar")
42
- expect(@handle).to receive(:write).with("fail").and_raise(StandardError)
43
- expect { @socket.write("fail") }.to raise_error(Thrift::TransportException) { |e| expect(e.type).to eq(Thrift::TransportException::NOT_OPEN) }
44
- end
45
-
46
- it "should raise an error when it cannot read from the handle" do
47
- @socket.open
48
- expect(@handle).to receive(:readpartial).with(17).and_raise(StandardError)
49
- expect { @socket.read(17) }.to raise_error(Thrift::TransportException) { |e| expect(e.type).to eq(Thrift::TransportException::NOT_OPEN) }
50
- end
51
-
52
- it "should return the data read when reading from the handle works" do
53
- @socket.open
54
- expect(@handle).to receive(:readpartial).with(17).and_return("test data")
55
- expect(@socket.read(17)).to eq("test data")
56
- end
57
-
58
- it "should declare itself as closed when it has an error" do
59
- @socket.open
60
- expect(@handle).to receive(:write).with("fail").and_raise(StandardError)
61
- expect(@socket).to be_open
62
- expect { @socket.write("fail") }.to raise_error(Thrift::TransportException) { |e| expect(e.type).to eq(Thrift::TransportException::NOT_OPEN) }
63
- expect(@socket).not_to be_open
64
- end
65
-
66
- it "should raise an error when the stream is closed" do
67
- @socket.open
68
- allow(@handle).to receive(:closed?).and_return(true)
69
- expect(@socket).not_to be_open
70
- expect { @socket.write("fail") }.to raise_error(Thrift::TransportException, "closed stream") { |e| expect(e.type).to eq(Thrift::TransportException::NOT_OPEN) }
71
- expect { @socket.read(10) }.to raise_error(Thrift::TransportException, "closed stream") { |e| expect(e.type).to eq(Thrift::TransportException::NOT_OPEN) }
72
- end
73
-
74
- it "should support the timeout accessor for read" do
75
- @socket.timeout = 3
76
- @socket.open
77
- expect(@handle).to receive(:read_nonblock).with(17).and_raise(IO::EAGAINWaitReadable)
78
- expect(IO).to receive(:select) do |rd, wr, err, timeout|
79
- expect(rd).to eq([@handle])
80
- expect(wr).to be_nil
81
- expect(err).to be_nil
82
- expect(timeout).to be > 0
83
- expect(timeout).to be <= 3
84
- [[@handle], [], []]
85
- end
86
- expect(@handle).to receive(:read_nonblock).with(17).and_return("test data")
87
- expect(@socket.read(17)).to eq("test data")
88
- end
89
-
90
- it "should support the timeout accessor for write" do
91
- @socket.timeout = 3
92
- @socket.open
93
- write_calls = 0
94
- expect(@handle).to receive(:write_nonblock).exactly(3).times do |chunk|
95
- write_calls += 1
96
- case write_calls
97
- when 1
98
- expect(chunk).to eq("test data")
99
- raise IO::EAGAINWaitWritable
100
- when 2
101
- expect(chunk).to eq("test data")
102
- 4
103
- when 3
104
- expect(chunk).to eq(" data")
105
- 5
106
- end
107
- end
108
- expect(IO).to receive(:select) do |rd, wr, err, timeout|
109
- expect(rd).to be_nil
110
- expect(wr).to eq([@handle])
111
- expect(err).to be_nil
112
- expect(timeout).to be > 0
113
- expect(timeout).to be <= 3
114
- [[], [@handle], []]
115
- end
116
- expect(@socket.write("test data")).to eq(9)
117
- end
118
-
119
- it "should raise an error when read times out" do
120
- @socket.timeout = 0.5
121
- @socket.open
122
- expect(@handle).to receive(:read_nonblock).with(17).and_raise(IO::EAGAINWaitReadable)
123
- expect(IO).to receive(:select).once { sleep(0.6); nil }
124
- expect { @socket.read(17) }.to raise_error(Thrift::TransportException) { |e| expect(e.type).to eq(Thrift::TransportException::TIMED_OUT) }
125
- end
126
-
127
- it "should raise an error when write times out" do
128
- @socket.timeout = 0.5
129
- @socket.open
130
- expect(@handle).to receive(:write_nonblock).with("test data").and_raise(IO::EAGAINWaitWritable)
131
- expect(IO).to receive(:select).once { sleep(0.6); nil }
132
- expect { @socket.write("test data") }.to raise_error(Thrift::TransportException) { |e| expect(e.type).to eq(Thrift::TransportException::TIMED_OUT) }
133
- end
134
-
135
- it "should read buffered SSL data without waiting on the raw socket again" do
136
- @socket.timeout = 1
137
- @socket.open
138
-
139
- expect(@handle).to receive(:read_nonblock).with(4).ordered.and_raise(IO::EAGAINWaitReadable)
140
- expect(IO).to receive(:select).once.ordered do |rd, wr, err, timeout|
141
- expect(rd).to eq([@handle])
142
- expect(wr).to be_nil
143
- expect(err).to be_nil
144
- expect(timeout).to be > 0
145
- expect(timeout).to be <= 1
146
- [[@handle], [], []]
147
- end
148
- expect(@handle).to receive(:read_nonblock).with(4).ordered.and_return("ABCD")
149
- expect(@handle).to receive(:read_nonblock).with(5).ordered.and_return("12345")
150
-
151
- expect(@socket.read(4)).to eq("ABCD")
152
- expect(@socket.read(5)).to eq("12345")
153
- end
154
-
155
- it "should read without timeout using the blocking path" do
156
- @socket.timeout = nil
157
- @socket.open
158
-
159
- expect(IO).not_to receive(:select)
160
- expect(@handle).not_to receive(:read_nonblock)
161
- expect(@handle).to receive(:readpartial).with(4).ordered.and_return("ABCD")
162
- expect(@handle).to receive(:readpartial).with(5).ordered.and_return("12345")
163
-
164
- expect(@socket.read(4)).to eq("ABCD")
165
- expect(@socket.read(5)).to eq("12345")
166
- end
167
- end
data/spec/spec_helper.rb DELETED
@@ -1,69 +0,0 @@
1
- # encoding: UTF-8
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 'rubygems'
22
- require 'rspec'
23
-
24
- $:.unshift File.join(File.dirname(__FILE__), *%w[.. ext])
25
-
26
- # pretend we already loaded fastthread, otherwise the nonblocking_server_spec
27
- # will get screwed up
28
- # $" << 'fastthread.bundle'
29
-
30
- require 'thrift'
31
-
32
- unless Object.method_defined? :tap
33
- # if Object#tap isn't defined, then add it; this should only happen in Ruby < 1.8.7
34
- class Object
35
- def tap(&block)
36
- block.call(self)
37
- self
38
- end
39
- end
40
- end
41
-
42
- RSpec.configure do |configuration|
43
- configuration.before(:each) do
44
- Thrift.type_checking = true
45
- end
46
- end
47
-
48
- $:.unshift File.join(File.dirname(__FILE__), *%w[.. test debug_proto gen-rb])
49
- require 'srv'
50
- require 'debug_proto_test_constants'
51
-
52
- $:.unshift File.join(File.dirname(__FILE__), *%w[gen-rb])
53
- require 'thrift_spec_types'
54
- require 'nonblocking_service'
55
-
56
- module Fixtures
57
- COMPACT_PROTOCOL_TEST_STRUCT = Thrift::Test::COMPACT_TEST.dup
58
- COMPACT_PROTOCOL_TEST_STRUCT.a_binary = [0, 1, 2, 3, 4, 5, 6, 7, 8].pack('c*')
59
- COMPACT_PROTOCOL_TEST_STRUCT.set_byte_map = nil
60
- COMPACT_PROTOCOL_TEST_STRUCT.map_byte_map = nil
61
- end
62
-
63
- $:.unshift File.join(File.dirname(__FILE__), *%w[gen-rb/flat])
64
-
65
- if defined?(GC.verify_compaction_references) == 'method'
66
- # This method was added in Ruby 3.0.0. Calling it this way asks the GC to
67
- # move objects around, helping to find object movement bugs.
68
- GC.verify_compaction_references(double_heap: true, toward: :empty)
69
- end
@@ -1,45 +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 'SSLServerSocket' do
24
- describe Thrift::SSLServerSocket do
25
- before(:each) do
26
- @socket = Thrift::SSLServerSocket.new(1234)
27
- end
28
-
29
- it "should delegate to_io to the underlying SSL server handle" do
30
- tcp_server = double("TCPServer")
31
- ssl_server = double("SSLServer")
32
-
33
- allow(TCPServer).to receive(:new).with(nil, 1234).and_return(tcp_server)
34
- allow(OpenSSL::SSL::SSLServer).to receive(:new).with(tcp_server, nil).and_return(ssl_server)
35
- allow(ssl_server).to receive(:to_io).and_return(tcp_server)
36
-
37
- @socket.listen
38
- expect(@socket.to_io).to eq(tcp_server)
39
- end
40
-
41
- it "should provide a reasonable to_s" do
42
- expect(@socket.to_s).to eq("ssl(socket(:1234))")
43
- end
44
- end
45
- end
@@ -1,87 +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 'SSLSocket' do
24
- describe Thrift::SSLSocket do
25
- before(:each) do
26
- @context = OpenSSL::SSL::SSLContext.new
27
- @socket = Thrift::SSLSocket.new
28
- @simple_socket_handle = double("Handle", :closed? => false)
29
- allow(@simple_socket_handle).to receive(:close)
30
- allow(@simple_socket_handle).to receive(:connect_nonblock)
31
- allow(@simple_socket_handle).to receive(:setsockopt)
32
-
33
- @handle = double(double("SSLHandle", :connect_nonblock => true, :post_connection_check => true), :closed? => false)
34
- allow(@handle).to receive(:connect_nonblock)
35
- allow(@handle).to receive(:close)
36
- allow(@handle).to receive(:post_connection_check)
37
- allow(@handle).to receive(:to_io).and_return(@simple_socket_handle)
38
-
39
- allow(::Socket).to receive(:new).and_return(@simple_socket_handle)
40
- allow(OpenSSL::SSL::SSLSocket).to receive(:new).and_return(@handle)
41
- end
42
-
43
- it_should_behave_like "a socket"
44
-
45
- it "should raise a TransportException when it cannot open a ssl socket" do
46
- expect(::Socket).to receive(:getaddrinfo).with("localhost", 9090, nil, ::Socket::SOCK_STREAM).and_return([[]])
47
- expect { @socket.open }.to raise_error(Thrift::TransportException) { |e| expect(e.type).to eq(Thrift::TransportException::NOT_OPEN) }
48
- end
49
-
50
- it "should open a ::Socket with default args" do
51
- expect(OpenSSL::SSL::SSLSocket).to receive(:new).with(@simple_socket_handle, nil).and_return(@handle)
52
- expect(@handle).to receive(:post_connection_check).with('localhost')
53
- @socket.open
54
- end
55
-
56
- it "should accept host/port options" do
57
- handle = double("Handle", :connect_nonblock => true, :setsockopt => nil)
58
- allow(::Socket).to receive(:new).and_return(handle)
59
- expect(::Socket).to receive(:getaddrinfo).with("my.domain", 1234, nil, ::Socket::SOCK_STREAM).and_return([[]])
60
- expect(::Socket).to receive(:sockaddr_in)
61
- expect(OpenSSL::SSL::SSLSocket).to receive(:new).with(handle, nil).and_return(@handle)
62
- expect(@handle).to receive(:post_connection_check).with('my.domain')
63
- Thrift::SSLSocket.new('my.domain', 1234, 6000, nil).open
64
- end
65
-
66
- it "should accept an optional timeout" do
67
- expect(Thrift::SSLSocket.new('localhost', 8080, 5).timeout).to eq(5)
68
- end
69
-
70
- it "should accept an optional context" do
71
- expect(Thrift::SSLSocket.new('localhost', 8080, 5, @context).ssl_context).to eq(@context)
72
- end
73
-
74
- it "should delegate to_io to the underlying SSL socket handle" do
75
- @socket.open
76
- expect(@socket.to_io).to eq(@simple_socket_handle)
77
- end
78
-
79
- it "should raise IOError when to_io is called on a closed stream" do
80
- expect { @socket.to_io }.to raise_error(IOError, 'closed stream')
81
- end
82
-
83
- it "should provide a reasonable to_s" do
84
- expect(Thrift::SSLSocket.new('myhost', 8090).to_s).to eq("ssl(socket(myhost:8090))")
85
- end
86
- end
87
- end