upfluence-thrift 1.0.1

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 (128) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +43 -0
  3. data/benchmark/Benchmark.thrift +24 -0
  4. data/benchmark/benchmark.rb +271 -0
  5. data/benchmark/client.rb +74 -0
  6. data/benchmark/gen-rb/benchmark_constants.rb +11 -0
  7. data/benchmark/gen-rb/benchmark_service.rb +80 -0
  8. data/benchmark/gen-rb/benchmark_types.rb +10 -0
  9. data/benchmark/server.rb +82 -0
  10. data/benchmark/thin_server.rb +44 -0
  11. data/ext/binary_protocol_accelerated.c +460 -0
  12. data/ext/binary_protocol_accelerated.h +20 -0
  13. data/ext/bytes.c +36 -0
  14. data/ext/bytes.h +31 -0
  15. data/ext/compact_protocol.c +637 -0
  16. data/ext/compact_protocol.h +20 -0
  17. data/ext/constants.h +99 -0
  18. data/ext/extconf.rb +34 -0
  19. data/ext/macros.h +41 -0
  20. data/ext/memory_buffer.c +134 -0
  21. data/ext/memory_buffer.h +20 -0
  22. data/ext/protocol.c +0 -0
  23. data/ext/protocol.h +0 -0
  24. data/ext/strlcpy.c +41 -0
  25. data/ext/strlcpy.h +34 -0
  26. data/ext/struct.c +707 -0
  27. data/ext/struct.h +25 -0
  28. data/ext/thrift_native.c +201 -0
  29. data/lib/thrift.rb +68 -0
  30. data/lib/thrift/bytes.rb +131 -0
  31. data/lib/thrift/client.rb +71 -0
  32. data/lib/thrift/core_ext.rb +23 -0
  33. data/lib/thrift/core_ext/fixnum.rb +29 -0
  34. data/lib/thrift/exceptions.rb +87 -0
  35. data/lib/thrift/multiplexed_processor.rb +76 -0
  36. data/lib/thrift/processor.rb +57 -0
  37. data/lib/thrift/protocol/base_protocol.rb +379 -0
  38. data/lib/thrift/protocol/binary_protocol.rb +237 -0
  39. data/lib/thrift/protocol/binary_protocol_accelerated.rb +39 -0
  40. data/lib/thrift/protocol/compact_protocol.rb +435 -0
  41. data/lib/thrift/protocol/json_protocol.rb +769 -0
  42. data/lib/thrift/protocol/multiplexed_protocol.rb +40 -0
  43. data/lib/thrift/protocol/protocol_decorator.rb +194 -0
  44. data/lib/thrift/serializer/deserializer.rb +33 -0
  45. data/lib/thrift/serializer/serializer.rb +34 -0
  46. data/lib/thrift/server/base_server.rb +31 -0
  47. data/lib/thrift/server/mongrel_http_server.rb +60 -0
  48. data/lib/thrift/server/nonblocking_server.rb +305 -0
  49. data/lib/thrift/server/rack_application.rb +61 -0
  50. data/lib/thrift/server/simple_server.rb +43 -0
  51. data/lib/thrift/server/thin_http_server.rb +51 -0
  52. data/lib/thrift/server/thread_pool_server.rb +75 -0
  53. data/lib/thrift/server/threaded_server.rb +47 -0
  54. data/lib/thrift/struct.rb +237 -0
  55. data/lib/thrift/struct_union.rb +192 -0
  56. data/lib/thrift/thrift_native.rb +24 -0
  57. data/lib/thrift/transport/base_server_transport.rb +37 -0
  58. data/lib/thrift/transport/base_transport.rb +109 -0
  59. data/lib/thrift/transport/buffered_transport.rb +114 -0
  60. data/lib/thrift/transport/framed_transport.rb +117 -0
  61. data/lib/thrift/transport/http_client_transport.rb +56 -0
  62. data/lib/thrift/transport/io_stream_transport.rb +39 -0
  63. data/lib/thrift/transport/memory_buffer_transport.rb +125 -0
  64. data/lib/thrift/transport/server_socket.rb +63 -0
  65. data/lib/thrift/transport/socket.rb +139 -0
  66. data/lib/thrift/transport/unix_server_socket.rb +60 -0
  67. data/lib/thrift/transport/unix_socket.rb +40 -0
  68. data/lib/thrift/types.rb +101 -0
  69. data/lib/thrift/union.rb +179 -0
  70. data/spec/BaseService.thrift +27 -0
  71. data/spec/ExtendedService.thrift +25 -0
  72. data/spec/Referenced.thrift +44 -0
  73. data/spec/ThriftNamespacedSpec.thrift +53 -0
  74. data/spec/ThriftSpec.thrift +183 -0
  75. data/spec/base_protocol_spec.rb +217 -0
  76. data/spec/base_transport_spec.rb +350 -0
  77. data/spec/binary_protocol_accelerated_spec.rb +42 -0
  78. data/spec/binary_protocol_spec.rb +66 -0
  79. data/spec/binary_protocol_spec_shared.rb +455 -0
  80. data/spec/bytes_spec.rb +160 -0
  81. data/spec/client_spec.rb +99 -0
  82. data/spec/compact_protocol_spec.rb +143 -0
  83. data/spec/exception_spec.rb +141 -0
  84. data/spec/flat_spec.rb +62 -0
  85. data/spec/gen-rb/base/base_service.rb +80 -0
  86. data/spec/gen-rb/base/base_service_constants.rb +11 -0
  87. data/spec/gen-rb/base/base_service_types.rb +26 -0
  88. data/spec/gen-rb/extended/extended_service.rb +78 -0
  89. data/spec/gen-rb/extended/extended_service_constants.rb +11 -0
  90. data/spec/gen-rb/extended/extended_service_types.rb +12 -0
  91. data/spec/gen-rb/flat/namespaced_nonblocking_service.rb +272 -0
  92. data/spec/gen-rb/flat/referenced_constants.rb +11 -0
  93. data/spec/gen-rb/flat/referenced_types.rb +17 -0
  94. data/spec/gen-rb/flat/thrift_namespaced_spec_constants.rb +11 -0
  95. data/spec/gen-rb/flat/thrift_namespaced_spec_types.rb +28 -0
  96. data/spec/gen-rb/namespaced_spec_namespace/namespaced_nonblocking_service.rb +272 -0
  97. data/spec/gen-rb/namespaced_spec_namespace/thrift_namespaced_spec_constants.rb +11 -0
  98. data/spec/gen-rb/namespaced_spec_namespace/thrift_namespaced_spec_types.rb +28 -0
  99. data/spec/gen-rb/nonblocking_service.rb +272 -0
  100. data/spec/gen-rb/other_namespace/referenced_constants.rb +11 -0
  101. data/spec/gen-rb/other_namespace/referenced_types.rb +17 -0
  102. data/spec/gen-rb/thrift_spec_constants.rb +11 -0
  103. data/spec/gen-rb/thrift_spec_types.rb +538 -0
  104. data/spec/http_client_spec.rb +120 -0
  105. data/spec/json_protocol_spec.rb +513 -0
  106. data/spec/namespaced_spec.rb +67 -0
  107. data/spec/nonblocking_server_spec.rb +263 -0
  108. data/spec/processor_spec.rb +80 -0
  109. data/spec/serializer_spec.rb +67 -0
  110. data/spec/server_socket_spec.rb +79 -0
  111. data/spec/server_spec.rb +147 -0
  112. data/spec/socket_spec.rb +61 -0
  113. data/spec/socket_spec_shared.rb +104 -0
  114. data/spec/spec_helper.rb +64 -0
  115. data/spec/struct_nested_containers_spec.rb +191 -0
  116. data/spec/struct_spec.rb +293 -0
  117. data/spec/thin_http_server_spec.rb +141 -0
  118. data/spec/types_spec.rb +115 -0
  119. data/spec/union_spec.rb +203 -0
  120. data/spec/unix_socket_spec.rb +107 -0
  121. data/test/debug_proto/gen-rb/debug_proto_test_constants.rb +274 -0
  122. data/test/debug_proto/gen-rb/debug_proto_test_types.rb +761 -0
  123. data/test/debug_proto/gen-rb/empty_service.rb +24 -0
  124. data/test/debug_proto/gen-rb/inherited.rb +79 -0
  125. data/test/debug_proto/gen-rb/reverse_order_service.rb +82 -0
  126. data/test/debug_proto/gen-rb/service_for_exception_with_a_map.rb +81 -0
  127. data/test/debug_proto/gen-rb/srv.rb +330 -0
  128. metadata +388 -0
@@ -0,0 +1,79 @@
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 'Thrift::ServerSocket' do
24
+
25
+ describe Thrift::ServerSocket do
26
+ before(:each) do
27
+ @socket = Thrift::ServerSocket.new(1234)
28
+ end
29
+
30
+ it "should create a handle when calling listen" do
31
+ TCPServer.should_receive(:new).with(nil, 1234)
32
+ @socket.listen
33
+ end
34
+
35
+ it "should accept an optional host argument" do
36
+ @socket = Thrift::ServerSocket.new('localhost', 1234)
37
+ TCPServer.should_receive(:new).with('localhost', 1234)
38
+ @socket.listen
39
+ end
40
+
41
+ it "should create a Thrift::Socket to wrap accepted sockets" do
42
+ handle = mock("TCPServer")
43
+ TCPServer.should_receive(:new).with(nil, 1234).and_return(handle)
44
+ @socket.listen
45
+ sock = mock("sock")
46
+ handle.should_receive(:accept).and_return(sock)
47
+ trans = mock("Socket")
48
+ Thrift::Socket.should_receive(:new).and_return(trans)
49
+ trans.should_receive(:handle=).with(sock)
50
+ @socket.accept.should == trans
51
+ end
52
+
53
+ it "should close the handle when closed" do
54
+ handle = mock("TCPServer", :closed? => false)
55
+ TCPServer.should_receive(:new).with(nil, 1234).and_return(handle)
56
+ @socket.listen
57
+ handle.should_receive(:close)
58
+ @socket.close
59
+ end
60
+
61
+ it "should return nil when accepting if there is no handle" do
62
+ @socket.accept.should be_nil
63
+ end
64
+
65
+ it "should return true for closed? when appropriate" do
66
+ handle = mock("TCPServer", :closed? => false)
67
+ TCPServer.stub!(:new).and_return(handle)
68
+ @socket.listen
69
+ @socket.should_not be_closed
70
+ handle.stub!(:close)
71
+ @socket.close
72
+ @socket.should be_closed
73
+ @socket.listen
74
+ @socket.should_not be_closed
75
+ handle.stub!(:closed?).and_return(true)
76
+ @socket.should be_closed
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,147 @@
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
+
23
+ describe Thrift::BaseServer do
24
+ it "should default to BaseTransportFactory and BinaryProtocolFactory when not specified" do
25
+ server = Thrift::BaseServer.new(mock("Processor"), mock("BaseServerTransport"))
26
+ server.instance_variable_get(:'@transport_factory').should be_an_instance_of(Thrift::BaseTransportFactory)
27
+ server.instance_variable_get(:'@protocol_factory').should be_an_instance_of(Thrift::BinaryProtocolFactory)
28
+ end
29
+
30
+ # serve is a noop, so can't test that
31
+ end
32
+
33
+ describe Thrift::SimpleServer do
34
+ before(:each) do
35
+ @processor = mock("Processor")
36
+ @serverTrans = mock("ServerTransport")
37
+ @trans = mock("BaseTransport")
38
+ @prot = mock("BaseProtocol")
39
+ @client = mock("Client")
40
+ @server = described_class.new(@processor, @serverTrans, @trans, @prot)
41
+ end
42
+
43
+ it "should serve in the main thread" do
44
+ @serverTrans.should_receive(:listen).ordered
45
+ @serverTrans.should_receive(:accept).exactly(3).times.and_return(@client)
46
+ @trans.should_receive(:get_transport).exactly(3).times.with(@client).and_return(@trans)
47
+ @prot.should_receive(:get_protocol).exactly(3).times.with(@trans).and_return(@prot)
48
+ x = 0
49
+ @processor.should_receive(:process).exactly(3).times.with(@prot, @prot).and_return do
50
+ case (x += 1)
51
+ when 1 then raise Thrift::TransportException
52
+ when 2 then raise Thrift::ProtocolException
53
+ when 3 then throw :stop
54
+ end
55
+ end
56
+ @trans.should_receive(:close).exactly(3).times
57
+ @serverTrans.should_receive(:close).ordered
58
+ lambda { @server.serve }.should throw_symbol(:stop)
59
+ end
60
+ end
61
+
62
+ describe Thrift::ThreadedServer do
63
+ before(:each) do
64
+ @processor = mock("Processor")
65
+ @serverTrans = mock("ServerTransport")
66
+ @trans = mock("BaseTransport")
67
+ @prot = mock("BaseProtocol")
68
+ @client = mock("Client")
69
+ @server = described_class.new(@processor, @serverTrans, @trans, @prot)
70
+ end
71
+
72
+ it "should serve using threads" do
73
+ @serverTrans.should_receive(:listen).ordered
74
+ @serverTrans.should_receive(:accept).exactly(3).times.and_return(@client)
75
+ @trans.should_receive(:get_transport).exactly(3).times.with(@client).and_return(@trans)
76
+ @prot.should_receive(:get_protocol).exactly(3).times.with(@trans).and_return(@prot)
77
+ Thread.should_receive(:new).with(@prot, @trans).exactly(3).times.and_yield(@prot, @trans)
78
+ x = 0
79
+ @processor.should_receive(:process).exactly(3).times.with(@prot, @prot).and_return do
80
+ case (x += 1)
81
+ when 1 then raise Thrift::TransportException
82
+ when 2 then raise Thrift::ProtocolException
83
+ when 3 then throw :stop
84
+ end
85
+ end
86
+ @trans.should_receive(:close).exactly(3).times
87
+ @serverTrans.should_receive(:close).ordered
88
+ lambda { @server.serve }.should throw_symbol(:stop)
89
+ end
90
+ end
91
+
92
+ describe Thrift::ThreadPoolServer do
93
+ before(:each) do
94
+ @processor = mock("Processor")
95
+ @server_trans = mock("ServerTransport")
96
+ @trans = mock("BaseTransport")
97
+ @prot = mock("BaseProtocol")
98
+ @client = mock("Client")
99
+ @server = described_class.new(@processor, @server_trans, @trans, @prot)
100
+ end
101
+
102
+ it "should serve inside a thread" do
103
+ exception_q = @server.instance_variable_get(:@exception_q)
104
+ described_class.any_instance.should_receive(:serve) do
105
+ exception_q.push(StandardError.new('ERROR'))
106
+ end
107
+ expect { @server.rescuable_serve }.to(raise_error('ERROR'))
108
+ end
109
+
110
+ it "should avoid running the server twice when retrying rescuable_serve" do
111
+ exception_q = @server.instance_variable_get(:@exception_q)
112
+ described_class.any_instance.should_receive(:serve) do
113
+ exception_q.push(StandardError.new('ERROR1'))
114
+ exception_q.push(StandardError.new('ERROR2'))
115
+ end
116
+ expect { @server.rescuable_serve }.to(raise_error('ERROR1'))
117
+ expect { @server.rescuable_serve }.to(raise_error('ERROR2'))
118
+ end
119
+
120
+ it "should serve using a thread pool" do
121
+ thread_q = mock("SizedQueue")
122
+ exception_q = mock("Queue")
123
+ @server.instance_variable_set(:@thread_q, thread_q)
124
+ @server.instance_variable_set(:@exception_q, exception_q)
125
+ @server_trans.should_receive(:listen).ordered
126
+ thread_q.should_receive(:push).with(:token)
127
+ thread_q.should_receive(:pop)
128
+ Thread.should_receive(:new).and_yield
129
+ @server_trans.should_receive(:accept).exactly(3).times.and_return(@client)
130
+ @trans.should_receive(:get_transport).exactly(3).times.and_return(@trans)
131
+ @prot.should_receive(:get_protocol).exactly(3).times.and_return(@prot)
132
+ x = 0
133
+ error = RuntimeError.new("Stopped")
134
+ @processor.should_receive(:process).exactly(3).times.with(@prot, @prot).and_return do
135
+ case (x += 1)
136
+ when 1 then raise Thrift::TransportException
137
+ when 2 then raise Thrift::ProtocolException
138
+ when 3 then raise error
139
+ end
140
+ end
141
+ @trans.should_receive(:close).exactly(3).times
142
+ exception_q.should_receive(:push).with(error).and_throw(:stop)
143
+ @server_trans.should_receive(:close)
144
+ expect { @server.serve }.to(throw_symbol(:stop))
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,61 @@
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
+
25
+ describe Thrift::Socket do
26
+ before(:each) do
27
+ @socket = Thrift::Socket.new
28
+ @handle = mock("Handle", :closed? => false)
29
+ @handle.stub!(:close)
30
+ @handle.stub!(:connect_nonblock)
31
+ @handle.stub!(:setsockopt)
32
+ ::Socket.stub!(:new).and_return(@handle)
33
+ end
34
+
35
+ it_should_behave_like "a socket"
36
+
37
+ it "should raise a TransportException when it cannot open a socket" do
38
+ ::Socket.should_receive(:new).and_raise(StandardError)
39
+ lambda { @socket.open }.should raise_error(Thrift::TransportException) { |e| e.type.should == Thrift::TransportException::NOT_OPEN }
40
+ end
41
+
42
+ it "should open a ::Socket with default args" do
43
+ ::Socket.should_receive(:new).and_return(mock("Handle", :connect_nonblock => true, :setsockopt => nil))
44
+ ::Socket.should_receive(:getaddrinfo).with("localhost", 9090, nil, ::Socket::SOCK_STREAM).and_return([[]])
45
+ ::Socket.should_receive(:sockaddr_in)
46
+ @socket.open
47
+ end
48
+
49
+ it "should accept host/port options" do
50
+ ::Socket.should_receive(:new).and_return(mock("Handle", :connect_nonblock => true, :setsockopt => nil))
51
+ ::Socket.should_receive(:getaddrinfo).with("my.domain", 1234, nil, ::Socket::SOCK_STREAM).and_return([[]])
52
+ ::Socket.should_receive(:sockaddr_in)
53
+ Thrift::Socket.new('my.domain', 1234).open
54
+ end
55
+
56
+ it "should accept an optional timeout" do
57
+ ::Socket.stub!(:new)
58
+ Thrift::Socket.new('localhost', 8080, 5).timeout.should == 5
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,104 @@
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
+ @socket.open.should == @handle
25
+ end
26
+
27
+ it "should be open whenever it has a handle" do
28
+ @socket.should_not be_open
29
+ @socket.open
30
+ @socket.should be_open
31
+ @socket.handle = nil
32
+ @socket.should_not be_open
33
+ @socket.handle = @handle
34
+ @socket.close
35
+ @socket.should_not be_open
36
+ end
37
+
38
+ it "should write data to the handle" do
39
+ @socket.open
40
+ @handle.should_receive(:write).with("foobar")
41
+ @socket.write("foobar")
42
+ @handle.should_receive(:write).with("fail").and_raise(StandardError)
43
+ lambda { @socket.write("fail") }.should raise_error(Thrift::TransportException) { |e| e.type.should == 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
+ @handle.should_receive(:readpartial).with(17).and_raise(StandardError)
49
+ lambda { @socket.read(17) }.should raise_error(Thrift::TransportException) { |e| e.type.should == 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
+ @handle.should_receive(:readpartial).with(17).and_return("test data")
55
+ @socket.read(17).should == "test data"
56
+ end
57
+
58
+ it "should declare itself as closed when it has an error" do
59
+ @socket.open
60
+ @handle.should_receive(:write).with("fail").and_raise(StandardError)
61
+ @socket.should be_open
62
+ lambda { @socket.write("fail") }.should raise_error
63
+ @socket.should_not be_open
64
+ end
65
+
66
+ it "should raise an error when the stream is closed" do
67
+ @socket.open
68
+ @handle.stub!(:closed?).and_return(true)
69
+ @socket.should_not be_open
70
+ lambda { @socket.write("fail") }.should raise_error(IOError, "closed stream")
71
+ lambda { @socket.read(10) }.should raise_error(IOError, "closed stream")
72
+ end
73
+
74
+ it "should support the timeout accessor for read" do
75
+ @socket.timeout = 3
76
+ @socket.open
77
+ IO.should_receive(:select).with([@handle], nil, nil, 3).and_return([[@handle], [], []])
78
+ @handle.should_receive(:readpartial).with(17).and_return("test data")
79
+ @socket.read(17).should == "test data"
80
+ end
81
+
82
+ it "should support the timeout accessor for write" do
83
+ @socket.timeout = 3
84
+ @socket.open
85
+ IO.should_receive(:select).with(nil, [@handle], nil, 3).twice.and_return([[], [@handle], []])
86
+ @handle.should_receive(:write_nonblock).with("test data").and_return(4)
87
+ @handle.should_receive(:write_nonblock).with(" data").and_return(5)
88
+ @socket.write("test data").should == 9
89
+ end
90
+
91
+ it "should raise an error when read times out" do
92
+ @socket.timeout = 0.5
93
+ @socket.open
94
+ IO.should_receive(:select).once {sleep(0.5); nil}
95
+ lambda { @socket.read(17) }.should raise_error(Thrift::TransportException) { |e| e.type.should == Thrift::TransportException::TIMED_OUT }
96
+ end
97
+
98
+ it "should raise an error when write times out" do
99
+ @socket.timeout = 0.5
100
+ @socket.open
101
+ IO.should_receive(:select).with(nil, [@handle], nil, 0.5).any_number_of_times.and_return(nil)
102
+ lambda { @socket.write("test data") }.should raise_error(Thrift::TransportException) { |e| e.type.should == Thrift::TransportException::TIMED_OUT }
103
+ end
104
+ end
@@ -0,0 +1,64 @@
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 = 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
+