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/socket_spec.rb DELETED
@@ -1,174 +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 'Socket' do
25
- describe Thrift::Socket do
26
- before(:each) do
27
- @socket = Thrift::Socket.new
28
- @addrinfo = double("Addrinfo")
29
- @handle = double("Handle", :closed? => false)
30
- allow(@handle).to receive(:close)
31
- allow(@handle).to receive(:setsockopt)
32
- allow(@addrinfo).to receive(:connect).and_return(@handle)
33
- allow(Addrinfo).to receive(:foreach).and_yield(@addrinfo)
34
- end
35
-
36
- it_should_behave_like "a socket"
37
-
38
- it "should raise a TransportException when it cannot open a socket" do
39
- allow(Addrinfo).to receive(:foreach).and_raise(SocketError.new("lookup failed"))
40
- expect { @socket.open }.to raise_error(Thrift::TransportException) do |e|
41
- expect(e.type).to eq(Thrift::TransportException::NOT_OPEN)
42
- expect(e.message).to eq("Could not connect to localhost:9090")
43
- expect(e.cause).to be_a(SocketError)
44
- end
45
- end
46
-
47
- it "should open a ::Socket with default args" do
48
- expect(Addrinfo).to receive(:foreach).with("localhost", 9090, nil, :STREAM).and_yield(@addrinfo)
49
- expect(@addrinfo).to receive(:connect).with(no_args).and_return(@handle)
50
- expect(@handle).to receive(:setsockopt).with(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1)
51
- @socket.to_s == "socket(localhost:9090)"
52
- @socket.open
53
- end
54
-
55
- it "should accept host/port options" do
56
- handle = double("Handle", :closed? => false)
57
- allow(handle).to receive(:close)
58
- expect(handle).to receive(:setsockopt).with(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1)
59
- expect(Addrinfo).to receive(:foreach).with("my.domain", 1234, nil, :STREAM).and_yield(@addrinfo)
60
- expect(@addrinfo).to receive(:connect).with(no_args).and_return(handle)
61
- @socket = Thrift::Socket.new('my.domain', 1234).open
62
- @socket.to_s == "socket(my.domain:1234)"
63
- end
64
-
65
- it "should accept an optional timeout" do
66
- expect(Thrift::Socket.new('localhost', 8080, 5).timeout).to eq(5)
67
- end
68
-
69
- it "should provide a reasonable to_s" do
70
- expect(Thrift::Socket.new('myhost', 8090).to_s).to eq("socket(myhost:8090)")
71
- end
72
-
73
- it "should pass the remaining timeout to each address attempt" do
74
- @socket.timeout = 5
75
- second_addrinfo = double("Addrinfo")
76
-
77
- expect(Process).to receive(:clock_gettime).with(Process::CLOCK_MONOTONIC).and_return(100.0, 101.0, 103.0)
78
- expect(Addrinfo).to receive(:foreach).with("localhost", 9090, nil, :STREAM).and_yield(@addrinfo).and_yield(second_addrinfo)
79
- expect(@addrinfo).to receive(:connect).with(timeout: 4.0).and_raise(Errno::ECONNREFUSED)
80
- expect(second_addrinfo).to receive(:connect).with(timeout: 2.0).and_return(@handle)
81
- expect(@handle).to receive(:setsockopt).with(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1)
82
-
83
- expect(@socket.open).to eq(@handle)
84
- end
85
-
86
- it "should continue to the next address after a connect timeout while time remains" do
87
- @socket.timeout = 5
88
- second_addrinfo = double("Addrinfo")
89
-
90
- expect(Process).to receive(:clock_gettime).with(Process::CLOCK_MONOTONIC).and_return(100.0, 101.0, 103.0)
91
- expect(Addrinfo).to receive(:foreach).with("localhost", 9090, nil, :STREAM).and_yield(@addrinfo).and_yield(second_addrinfo)
92
- expect(@addrinfo).to receive(:connect).with(timeout: 4.0).and_raise(Errno::ETIMEDOUT)
93
- expect(second_addrinfo).to receive(:connect).with(timeout: 2.0).and_return(@handle)
94
- expect(@handle).to receive(:setsockopt).with(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1)
95
-
96
- expect(@socket.open).to eq(@handle)
97
- end
98
-
99
- it "should raise TIMED_OUT when an address attempt times out" do
100
- @socket.timeout = 5
101
-
102
- expect(Process).to receive(:clock_gettime).with(Process::CLOCK_MONOTONIC).and_return(100.0, 101.0)
103
- expect(@addrinfo).to receive(:connect).with(timeout: 4.0).and_raise(Errno::ETIMEDOUT)
104
-
105
- expect { @socket.open }.to raise_error(Thrift::TransportException) do |e|
106
- expect(e.type).to eq(Thrift::TransportException::TIMED_OUT)
107
- expect(e.message).to eq("Socket: Timed out opening connection to localhost:9090")
108
- end
109
- end
110
-
111
- it "should raise TIMED_OUT when the deadline expires before the next address attempt" do
112
- @socket.timeout = 5
113
- second_addrinfo = double("Addrinfo")
114
-
115
- expect(Process).to receive(:clock_gettime).with(Process::CLOCK_MONOTONIC).and_return(100.0, 101.0, 105.0)
116
- expect(Addrinfo).to receive(:foreach).with("localhost", 9090, nil, :STREAM).and_yield(@addrinfo).and_yield(second_addrinfo)
117
- expect(@addrinfo).to receive(:connect).with(timeout: 4.0).and_raise(Errno::ECONNREFUSED)
118
- expect(second_addrinfo).not_to receive(:connect)
119
-
120
- expect { @socket.open }.to raise_error(Thrift::TransportException) do |e|
121
- expect(e.type).to eq(Thrift::TransportException::TIMED_OUT)
122
- expect(e.message).to eq("Socket: Timed out opening connection to localhost:9090")
123
- end
124
- end
125
-
126
- it "should treat zero timeout as blocking for open" do
127
- @socket.timeout = 0
128
-
129
- expect(@addrinfo).to receive(:connect).with(no_args).and_return(@handle)
130
- expect(@handle).to receive(:setsockopt).with(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1)
131
-
132
- expect(@socket.open).to eq(@handle)
133
- end
134
-
135
- it "should report the last connection error when all addresses fail" do
136
- second_addrinfo = double("Addrinfo")
137
-
138
- expect(Addrinfo).to receive(:foreach).with("localhost", 9090, nil, :STREAM).and_yield(@addrinfo).and_yield(second_addrinfo)
139
- expect(@addrinfo).to receive(:connect).and_raise(Errno::ECONNREFUSED)
140
- expect(second_addrinfo).to receive(:connect).and_raise(Errno::EHOSTUNREACH)
141
-
142
- expect { @socket.open }.to raise_error(Thrift::TransportException) do |e|
143
- expect(e.type).to eq(Thrift::TransportException::NOT_OPEN)
144
- expect(e.message).to eq("Could not connect to localhost:9090")
145
- expect(e.cause).to be_a(Errno::EHOSTUNREACH)
146
- end
147
- end
148
-
149
- it "should close a connected candidate before falling back when socket setup fails" do
150
- first_addrinfo = @addrinfo
151
- second_addrinfo = double("Addrinfo")
152
- first_handle = double("Handle", :closed? => false)
153
- allow(first_handle).to receive(:close)
154
-
155
- expect(Addrinfo).to receive(:foreach).with("localhost", 9090, nil, :STREAM).and_yield(first_addrinfo).and_yield(second_addrinfo)
156
- expect(first_addrinfo).to receive(:connect).with(no_args).and_return(first_handle)
157
- expect(first_handle).to receive(:setsockopt).with(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1).and_raise(StandardError.new("setsockopt failed"))
158
- expect(first_handle).to receive(:close)
159
- expect(second_addrinfo).to receive(:connect).with(no_args).and_return(@handle)
160
- expect(@handle).to receive(:setsockopt).with(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1)
161
-
162
- expect(@socket.open).to eq(@handle)
163
- end
164
-
165
- it "should avoid a blank error when no addresses are returned" do
166
- allow(Addrinfo).to receive(:foreach)
167
-
168
- expect { @socket.open }.to raise_error(Thrift::TransportException) do |e|
169
- expect(e.type).to eq(Thrift::TransportException::NOT_OPEN)
170
- expect(e.message).to eq("Could not connect to localhost:9090")
171
- end
172
- end
173
- end
174
- end
@@ -1,168 +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
- shared_examples_for "a socket" do
24
- it "should open a socket" do
25
- expect(@socket.open).to eq(@handle)
26
- end
27
-
28
- it "should be open whenever it has a handle" do
29
- expect(@socket).not_to be_open
30
- @socket.open
31
- expect(@socket).to be_open
32
- @socket.handle = nil
33
- expect(@socket).not_to be_open
34
- @socket.handle = @handle
35
- @socket.close
36
- expect(@socket).not_to be_open
37
- end
38
-
39
- it "should write data to the handle" do
40
- @socket.open
41
- expect(@handle).to receive(:write).with("foobar")
42
- @socket.write("foobar")
43
- expect(@handle).to receive(:write).with("fail").and_raise(StandardError)
44
- expect { @socket.write("fail") }.to raise_error(Thrift::TransportException) { |e| expect(e.type).to eq(Thrift::TransportException::NOT_OPEN) }
45
- end
46
-
47
- it "should raise an error when it cannot read from the handle" do
48
- @socket.open
49
- expect(@handle).to receive(:readpartial).with(17).and_raise(StandardError)
50
- expect { @socket.read(17) }.to raise_error(Thrift::TransportException) { |e| expect(e.type).to eq(Thrift::TransportException::NOT_OPEN) }
51
- end
52
-
53
- it "should return the data read when reading from the handle works" do
54
- @socket.open
55
- expect(@handle).to receive(:readpartial).with(17).and_return("test data")
56
- expect(@socket.read(17)).to eq("test data")
57
- end
58
-
59
- it "should declare itself as closed when it has an error" do
60
- @socket.open
61
- expect(@handle).to receive(:write).with("fail").and_raise(StandardError)
62
- expect(@socket).to be_open
63
- expect { @socket.write("fail") }.to raise_error(Thrift::TransportException) { |e| expect(e.type).to eq(Thrift::TransportException::NOT_OPEN) }
64
- expect(@socket).not_to be_open
65
- end
66
-
67
- it "should raise an error when the stream is closed" do
68
- @socket.open
69
- allow(@handle).to receive(:closed?).and_return(true)
70
- expect(@socket).not_to be_open
71
- expect { @socket.write("fail") }.to raise_error(Thrift::TransportException, "closed stream") { |e| expect(e.type).to eq(Thrift::TransportException::NOT_OPEN) }
72
- expect { @socket.read(10) }.to raise_error(Thrift::TransportException, "closed stream") { |e| expect(e.type).to eq(Thrift::TransportException::NOT_OPEN) }
73
- end
74
-
75
- it "should support the timeout accessor for read" do
76
- @socket.timeout = 3
77
- @socket.open
78
- expect(@handle).to receive(:read_nonblock).with(17).and_raise(IO::EAGAINWaitReadable)
79
- expect(IO).to receive(:select) do |rd, wr, err, timeout|
80
- expect(rd).to eq([@handle])
81
- expect(wr).to be_nil
82
- expect(err).to be_nil
83
- expect(timeout).to be > 0
84
- expect(timeout).to be <= 3
85
- [[@handle], [], []]
86
- end
87
- expect(@handle).to receive(:read_nonblock).with(17).and_return("test data")
88
- expect(@socket.read(17)).to eq("test data")
89
- end
90
-
91
- it "should support the timeout accessor for write" do
92
- @socket.timeout = 3
93
- @socket.open
94
- write_calls = 0
95
- expect(@handle).to receive(:write_nonblock).exactly(3).times do |chunk|
96
- write_calls += 1
97
- case write_calls
98
- when 1
99
- expect(chunk).to eq("test data")
100
- raise IO::EAGAINWaitWritable
101
- when 2
102
- expect(chunk).to eq("test data")
103
- 4
104
- when 3
105
- expect(chunk).to eq(" data")
106
- 5
107
- end
108
- end
109
- expect(IO).to receive(:select) do |rd, wr, err, timeout|
110
- expect(rd).to be_nil
111
- expect(wr).to eq([@handle])
112
- expect(err).to be_nil
113
- expect(timeout).to be > 0
114
- expect(timeout).to be <= 3
115
- [[], [@handle], []]
116
- end
117
- expect(@socket.write("test data")).to eq(9)
118
- end
119
-
120
- it "should raise an error when read times out" do
121
- @socket.timeout = 0.5
122
- @socket.open
123
- expect(@handle).to receive(:read_nonblock).with(17).and_raise(IO::EAGAINWaitReadable)
124
- expect(IO).to receive(:select).once { sleep(0.6); nil }
125
- expect { @socket.read(17) }.to raise_error(Thrift::TransportException) { |e| expect(e.type).to eq(Thrift::TransportException::TIMED_OUT) }
126
- end
127
-
128
- it "should raise an error when write times out" do
129
- @socket.timeout = 0.5
130
- @socket.open
131
- expect(@handle).to receive(:write_nonblock).with("test data").and_raise(IO::EAGAINWaitWritable)
132
- expect(IO).to receive(:select).once { sleep(0.6); nil }
133
- expect { @socket.write("test data") }.to raise_error(Thrift::TransportException) { |e| expect(e.type).to eq(Thrift::TransportException::TIMED_OUT) }
134
- end
135
-
136
- it "should read buffered SSL data without waiting on the raw socket again" do
137
- @socket.timeout = 1
138
- @socket.open
139
-
140
- expect(@handle).to receive(:read_nonblock).with(4).ordered.and_raise(IO::EAGAINWaitReadable)
141
- expect(IO).to receive(:select).once.ordered do |rd, wr, err, timeout|
142
- expect(rd).to eq([@handle])
143
- expect(wr).to be_nil
144
- expect(err).to be_nil
145
- expect(timeout).to be > 0
146
- expect(timeout).to be <= 1
147
- [[@handle], [], []]
148
- end
149
- expect(@handle).to receive(:read_nonblock).with(4).ordered.and_return("ABCD")
150
- expect(@handle).to receive(:read_nonblock).with(5).ordered.and_return("12345")
151
-
152
- expect(@socket.read(4)).to eq("ABCD")
153
- expect(@socket.read(5)).to eq("12345")
154
- end
155
-
156
- it "should read without timeout using the blocking path" do
157
- @socket.timeout = nil
158
- @socket.open
159
-
160
- expect(IO).not_to receive(:select)
161
- expect(@handle).not_to receive(:read_nonblock)
162
- expect(@handle).to receive(:readpartial).with(4).ordered.and_return("ABCD")
163
- expect(@handle).to receive(:readpartial).with(5).ordered.and_return("12345")
164
-
165
- expect(@socket.read(4)).to eq("ABCD")
166
- expect(@socket.read(5)).to eq("12345")
167
- end
168
- end
data/spec/spec_helper.rb DELETED
@@ -1,70 +0,0 @@
1
- # encoding: UTF-8
2
- # frozen_string_literal: true
3
- #
4
- # Licensed to the Apache Software Foundation (ASF) under one
5
- # or more contributor license agreements. See the NOTICE file
6
- # distributed with this work for additional information
7
- # regarding copyright ownership. The ASF licenses this file
8
- # to you under the Apache License, Version 2.0 (the
9
- # "License"); you may not use this file except in compliance
10
- # with the License. You may obtain a copy of the License at
11
- #
12
- # http://www.apache.org/licenses/LICENSE-2.0
13
- #
14
- # Unless required by applicable law or agreed to in writing,
15
- # software distributed under the License is distributed on an
16
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17
- # KIND, either express or implied. See the License for the
18
- # specific language governing permissions and limitations
19
- # under the License.
20
- #
21
-
22
- require 'rubygems'
23
- require 'rspec'
24
-
25
- $:.unshift File.join(File.dirname(__FILE__), *%w[.. ext])
26
-
27
- # pretend we already loaded fastthread, otherwise the nonblocking_server_spec
28
- # will get screwed up
29
- # $" << 'fastthread.bundle'
30
-
31
- require 'thrift'
32
-
33
- unless Object.method_defined? :tap
34
- # if Object#tap isn't defined, then add it; this should only happen in Ruby < 1.8.7
35
- class Object
36
- def tap(&block)
37
- block.call(self)
38
- self
39
- end
40
- end
41
- end
42
-
43
- RSpec.configure do |configuration|
44
- configuration.before(:each) do
45
- Thrift.type_checking = true
46
- end
47
- end
48
-
49
- $:.unshift File.join(File.dirname(__FILE__), *%w[.. test debug_proto gen-rb])
50
- require 'srv'
51
- require 'debug_proto_test_constants'
52
-
53
- $:.unshift File.join(File.dirname(__FILE__), *%w[gen-rb])
54
- require 'thrift_spec_types'
55
- require 'nonblocking_service'
56
-
57
- module Fixtures
58
- COMPACT_PROTOCOL_TEST_STRUCT = Thrift::Test::COMPACT_TEST.dup
59
- COMPACT_PROTOCOL_TEST_STRUCT.a_binary = [0, 1, 2, 3, 4, 5, 6, 7, 8].pack('c*')
60
- COMPACT_PROTOCOL_TEST_STRUCT.set_byte_map = nil
61
- COMPACT_PROTOCOL_TEST_STRUCT.map_byte_map = nil
62
- end
63
-
64
- $:.unshift File.join(File.dirname(__FILE__), *%w[gen-rb/flat])
65
-
66
- if defined?(GC.verify_compaction_references) == 'method'
67
- # This method was added in Ruby 3.0.0. Calling it this way asks the GC to
68
- # move objects around, helping to find object movement bugs.
69
- GC.verify_compaction_references(double_heap: true, toward: :empty)
70
- end
@@ -1,85 +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 'SSLServerSocket' do
25
- describe Thrift::SSLServerSocket do
26
- before(:each) do
27
- @socket = Thrift::SSLServerSocket.new(1234)
28
- end
29
-
30
- it "should delegate to_io to the underlying SSL server handle" do
31
- tcp_server = double("TCPServer")
32
- ssl_server = double("SSLServer")
33
-
34
- allow(TCPServer).to receive(:new).with(nil, 1234).and_return(tcp_server)
35
- allow(OpenSSL::SSL::SSLServer).to receive(:new).with(tcp_server, nil).and_return(ssl_server)
36
- allow(ssl_server).to receive(:to_io).and_return(tcp_server)
37
-
38
- @socket.listen
39
- expect(@socket.to_io).to eq(tcp_server)
40
- end
41
-
42
- it "should default accepted sockets to a finite client timeout" do
43
- expect(@socket.client_timeout).to eq(5)
44
- end
45
-
46
- it "should preserve the positional ssl context argument" do
47
- context = double("SSLContext")
48
- socket = Thrift::SSLServerSocket.new(nil, 1234, context)
49
-
50
- expect(socket.ssl_context).to eq(context)
51
- expect(socket.client_timeout).to eq(5)
52
- end
53
-
54
- it "should accept a custom client timeout" do
55
- context = double("SSLContext")
56
- socket = Thrift::SSLServerSocket.new(nil, 1234, context, client_timeout: 2.5)
57
-
58
- expect(socket.ssl_context).to eq(context)
59
- expect(socket.client_timeout).to eq(2.5)
60
- end
61
-
62
- it "should apply the client timeout to accepted sockets" do
63
- tcp_server = double("TCPServer")
64
- ssl_server = double("SSLServer")
65
- sock = double("SSLSocket")
66
-
67
- allow(TCPServer).to receive(:new).with(nil, 1234).and_return(tcp_server)
68
- allow(OpenSSL::SSL::SSLServer).to receive(:new).with(tcp_server, nil).and_return(ssl_server)
69
- expect(ssl_server).to receive(:accept).and_return(sock)
70
- expect(sock).to receive(:setsockopt).with(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
71
-
72
- trans = double("Socket")
73
- expect(Thrift::Socket).to receive(:new).and_return(trans)
74
- expect(trans).to receive(:timeout=).with(Thrift::BaseServerTransport::DEFAULT_CLIENT_TIMEOUT)
75
- expect(trans).to receive(:handle=).with(sock)
76
-
77
- @socket.listen
78
- expect(@socket.accept).to eq(trans)
79
- end
80
-
81
- it "should provide a reasonable to_s" do
82
- expect(@socket.to_s).to eq("ssl(socket(:1234))")
83
- end
84
- end
85
- end