thrift 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/benchmark/gen-rb/benchmark_constants.rb +3 -2
- data/benchmark/gen-rb/benchmark_service.rb +52 -52
- data/benchmark/gen-rb/benchmark_types.rb +3 -2
- data/ext/binary_protocol_accelerated.c +5 -2
- data/ext/bytes.c +36 -0
- data/ext/bytes.h +31 -0
- data/ext/compact_protocol.c +7 -4
- data/ext/constants.h +4 -0
- data/ext/extconf.rb +3 -1
- data/ext/memory_buffer.c +11 -8
- data/ext/thrift_native.c +9 -0
- data/lib/thrift.rb +2 -0
- data/lib/thrift/bytes.rb +131 -0
- data/lib/thrift/protocol/base_protocol.rb +10 -0
- data/lib/thrift/protocol/binary_protocol.rb +5 -5
- data/lib/thrift/protocol/compact_protocol.rb +4 -3
- data/lib/thrift/protocol/json_protocol.rb +765 -0
- data/lib/thrift/transport/base_transport.rb +22 -20
- data/lib/thrift/transport/buffered_transport.rb +16 -10
- data/lib/thrift/transport/framed_transport.rb +11 -10
- data/lib/thrift/transport/http_client_transport.rb +7 -5
- data/lib/thrift/transport/io_stream_transport.rb +1 -1
- data/lib/thrift/transport/memory_buffer_transport.rb +6 -6
- data/lib/thrift/transport/socket.rb +4 -2
- data/spec/ThriftSpec.thrift +52 -1
- data/spec/base_protocol_spec.rb +44 -45
- data/spec/base_transport_spec.rb +49 -50
- data/spec/binary_protocol_accelerated_spec.rb +9 -13
- data/spec/binary_protocol_spec.rb +15 -10
- data/spec/binary_protocol_spec_shared.rb +62 -12
- data/spec/bytes_spec.rb +160 -0
- data/spec/client_spec.rb +13 -14
- data/spec/compact_protocol_spec.rb +3 -2
- data/spec/exception_spec.rb +39 -40
- data/spec/gen-rb/nonblocking_service.rb +193 -193
- data/spec/gen-rb/thrift_spec_constants.rb +3 -2
- data/spec/gen-rb/thrift_spec_types.rb +455 -262
- data/spec/http_client_spec.rb +16 -9
- data/spec/json_protocol_spec.rb +513 -0
- data/spec/mongrel_http_server_spec.rb +19 -22
- data/spec/nonblocking_server_spec.rb +18 -20
- data/spec/processor_spec.rb +13 -16
- data/spec/serializer_spec.rb +17 -19
- data/spec/server_socket_spec.rb +6 -7
- data/spec/server_spec.rb +46 -58
- data/spec/socket_spec.rb +11 -11
- data/spec/socket_spec_shared.rb +1 -1
- data/spec/spec_helper.rb +13 -10
- data/spec/struct_nested_containers_spec.rb +191 -0
- data/spec/struct_spec.rb +84 -86
- data/spec/types_spec.rb +65 -66
- data/spec/union_spec.rb +44 -46
- data/spec/unix_socket_spec.rb +8 -9
- data/test/debug_proto/gen-rb/debug_proto_test_constants.rb +8 -7
- data/test/debug_proto/gen-rb/debug_proto_test_types.rb +24 -23
- data/test/debug_proto/gen-rb/empty_service.rb +1 -1
- data/test/debug_proto/gen-rb/inherited.rb +3 -3
- data/test/debug_proto/gen-rb/reverse_order_service.rb +1 -1
- data/test/debug_proto/gen-rb/service_for_exception_with_a_map.rb +3 -3
- data/test/debug_proto/gen-rb/srv.rb +2 -2
- metadata +43 -49
data/spec/bytes_spec.rb
ADDED
@@ -0,0 +1,160 @@
|
|
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 'spec_helper'
|
22
|
+
|
23
|
+
describe Thrift::Bytes do
|
24
|
+
if RUBY_VERSION >= '1.9'
|
25
|
+
describe '.empty_byte_buffer' do
|
26
|
+
it 'should create an empty buffer' do
|
27
|
+
b = Thrift::Bytes.empty_byte_buffer
|
28
|
+
b.length.should == 0
|
29
|
+
b.encoding.should == Encoding::BINARY
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should create an empty buffer of given size' do
|
33
|
+
b = Thrift::Bytes.empty_byte_buffer 2
|
34
|
+
b.length.should == 2
|
35
|
+
b.getbyte(0).should == 0
|
36
|
+
b.getbyte(1).should == 0
|
37
|
+
b.encoding.should == Encoding::BINARY
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '.force_binary_encoding' do
|
42
|
+
it 'should change encoding' do
|
43
|
+
e = 'STRING'.encode('UTF-8')
|
44
|
+
e.encoding.should_not == Encoding::BINARY
|
45
|
+
a = Thrift::Bytes.force_binary_encoding e
|
46
|
+
a.encoding.should == Encoding::BINARY
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '.get_string_byte' do
|
51
|
+
it 'should get the byte at index' do
|
52
|
+
s = "\x41\x42"
|
53
|
+
Thrift::Bytes.get_string_byte(s, 0).should == 0x41
|
54
|
+
Thrift::Bytes.get_string_byte(s, 1).should == 0x42
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '.set_string_byte' do
|
59
|
+
it 'should set byte value at index' do
|
60
|
+
s = "\x41\x42"
|
61
|
+
Thrift::Bytes.set_string_byte(s, 0, 0x43)
|
62
|
+
s.getbyte(0).should == 0x43
|
63
|
+
s.should == 'CB'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '.convert_to_utf8_byte_buffer' do
|
68
|
+
it 'should convert UTF-8 String to byte buffer' do
|
69
|
+
e = "\u20AC".encode('UTF-8') # a string with euro sign character U+20AC
|
70
|
+
e.length.should == 1
|
71
|
+
|
72
|
+
a = Thrift::Bytes.convert_to_utf8_byte_buffer e
|
73
|
+
a.encoding.should == Encoding::BINARY
|
74
|
+
a.length.should == 3
|
75
|
+
a.unpack('C*').should == [0xE2, 0x82, 0xAC]
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should convert ISO-8859-15 String to UTF-8 byte buffer' do
|
79
|
+
# Assumptions
|
80
|
+
e = "\u20AC".encode('ISO-8859-15') # a string with euro sign character U+20AC, then converted to ISO-8859-15
|
81
|
+
e.length.should == 1
|
82
|
+
e.unpack('C*').should == [0xA4] # euro sign is a different code point in ISO-8859-15
|
83
|
+
|
84
|
+
a = Thrift::Bytes.convert_to_utf8_byte_buffer e
|
85
|
+
a.encoding.should == Encoding::BINARY
|
86
|
+
a.length.should == 3
|
87
|
+
a.unpack('C*').should == [0xE2, 0x82, 0xAC]
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe '.convert_to_string' do
|
92
|
+
it 'should convert UTF-8 byte buffer to a UTF-8 String' do
|
93
|
+
e = [0xE2, 0x82, 0xAC].pack("C*")
|
94
|
+
e.encoding.should == Encoding::BINARY
|
95
|
+
a = Thrift::Bytes.convert_to_string e
|
96
|
+
a.encoding.should == Encoding::UTF_8
|
97
|
+
a.should == "\u20AC"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
else # RUBY_VERSION
|
102
|
+
describe '.empty_byte_buffer' do
|
103
|
+
it 'should create an empty buffer' do
|
104
|
+
b = Thrift::Bytes.empty_byte_buffer
|
105
|
+
b.length.should == 0
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'should create an empty buffer of given size' do
|
109
|
+
b = Thrift::Bytes.empty_byte_buffer 2
|
110
|
+
b.length.should == 2
|
111
|
+
b[0].should == 0
|
112
|
+
b[1].should == 0
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe '.force_binary_encoding' do
|
117
|
+
it 'should be a no-op' do
|
118
|
+
e = 'STRING'
|
119
|
+
a = Thrift::Bytes.force_binary_encoding e
|
120
|
+
a.should == e
|
121
|
+
a.should be(e)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe '.get_string_byte' do
|
126
|
+
it 'should get the byte at index' do
|
127
|
+
s = "\x41\x42"
|
128
|
+
Thrift::Bytes.get_string_byte(s, 0).should == 0x41
|
129
|
+
Thrift::Bytes.get_string_byte(s, 1).should == 0x42
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe '.set_string_byte' do
|
134
|
+
it 'should set byte value at index' do
|
135
|
+
s = "\x41\x42"
|
136
|
+
Thrift::Bytes.set_string_byte(s, 0, 0x43)
|
137
|
+
s[0].should == 0x43
|
138
|
+
s.should == 'CB'
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe '.convert_to_utf8_byte_buffer' do
|
143
|
+
it 'should be a no-op' do
|
144
|
+
e = 'STRING'
|
145
|
+
a = Thrift::Bytes.convert_to_utf8_byte_buffer e
|
146
|
+
a.should == e
|
147
|
+
a.should be(e)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
describe '.convert_to_string' do
|
152
|
+
it 'should be a no-op' do
|
153
|
+
e = 'STRING'
|
154
|
+
a = Thrift::Bytes.convert_to_string e
|
155
|
+
a.should == e
|
156
|
+
a.should be(e)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
data/spec/client_spec.rb
CHANGED
@@ -17,10 +17,9 @@
|
|
17
17
|
# under the License.
|
18
18
|
#
|
19
19
|
|
20
|
-
require
|
20
|
+
require 'spec_helper'
|
21
21
|
|
22
|
-
|
23
|
-
include Thrift
|
22
|
+
describe 'Client' do
|
24
23
|
|
25
24
|
class ClientSpec
|
26
25
|
include Thrift::Client
|
@@ -31,21 +30,21 @@ class ThriftClientSpec < Spec::ExampleGroup
|
|
31
30
|
@client = ClientSpec.new(@prot)
|
32
31
|
end
|
33
32
|
|
34
|
-
describe Client do
|
33
|
+
describe Thrift::Client do
|
35
34
|
it "should re-use iprot for oprot if not otherwise specified" do
|
36
35
|
@client.instance_variable_get(:'@iprot').should eql(@prot)
|
37
36
|
@client.instance_variable_get(:'@oprot').should eql(@prot)
|
38
37
|
end
|
39
38
|
|
40
39
|
it "should send a test message" do
|
41
|
-
@prot.should_receive(:write_message_begin).with('testMessage', MessageTypes::CALL, 0)
|
40
|
+
@prot.should_receive(:write_message_begin).with('testMessage', Thrift::MessageTypes::CALL, 0)
|
42
41
|
mock_args = mock('#<TestMessage_args:mock>')
|
43
42
|
mock_args.should_receive(:foo=).with('foo')
|
44
43
|
mock_args.should_receive(:bar=).with(42)
|
45
44
|
mock_args.should_receive(:write).with(@prot)
|
46
45
|
@prot.should_receive(:write_message_end)
|
47
46
|
@prot.should_receive(:trans) do
|
48
|
-
mock('trans').
|
47
|
+
mock('trans').tap do |trans|
|
49
48
|
trans.should_receive(:flush)
|
50
49
|
end
|
51
50
|
end
|
@@ -55,19 +54,19 @@ class ThriftClientSpec < Spec::ExampleGroup
|
|
55
54
|
|
56
55
|
it "should increment the sequence id when sending messages" do
|
57
56
|
pending "it seems sequence ids are completely ignored right now" do
|
58
|
-
@prot.should_receive(:write_message_begin).with('testMessage', MessageTypes::CALL, 0).ordered
|
59
|
-
@prot.should_receive(:write_message_begin).with('testMessage2', MessageTypes::CALL, 1).ordered
|
60
|
-
@prot.should_receive(:write_message_begin).with('testMessage3', MessageTypes::CALL, 2).ordered
|
57
|
+
@prot.should_receive(:write_message_begin).with('testMessage', Thrift::MessageTypes::CALL, 0).ordered
|
58
|
+
@prot.should_receive(:write_message_begin).with('testMessage2', Thrift::MessageTypes::CALL, 1).ordered
|
59
|
+
@prot.should_receive(:write_message_begin).with('testMessage3', Thrift::MessageTypes::CALL, 2).ordered
|
61
60
|
@prot.stub!(:write_message_end)
|
62
61
|
@prot.stub!(:trans).and_return mock("trans").as_null_object
|
63
62
|
@client.send_message('testMessage', mock("args class").as_null_object)
|
64
63
|
@client.send_message('testMessage2', mock("args class").as_null_object)
|
65
|
-
@client.send_message('testMessage3', mock("args class").as_null_object)
|
64
|
+
@client.send_message('testMessage3', mock("args class").as_null_object)
|
66
65
|
end
|
67
66
|
end
|
68
67
|
|
69
68
|
it "should receive a test message" do
|
70
|
-
@prot.should_receive(:read_message_begin).and_return [nil, MessageTypes::CALL, 0]
|
69
|
+
@prot.should_receive(:read_message_begin).and_return [nil, Thrift::MessageTypes::CALL, 0]
|
71
70
|
@prot.should_receive(:read_message_end)
|
72
71
|
mock_klass = mock("#<MockClass:mock>")
|
73
72
|
mock_klass.should_receive(:read).with(@prot)
|
@@ -75,10 +74,10 @@ class ThriftClientSpec < Spec::ExampleGroup
|
|
75
74
|
end
|
76
75
|
|
77
76
|
it "should handle received exceptions" do
|
78
|
-
@prot.should_receive(:read_message_begin).and_return [nil, MessageTypes::EXCEPTION, 0]
|
77
|
+
@prot.should_receive(:read_message_begin).and_return [nil, Thrift::MessageTypes::EXCEPTION, 0]
|
79
78
|
@prot.should_receive(:read_message_end)
|
80
|
-
ApplicationException.should_receive(:new).and_return do
|
81
|
-
StandardError.new.
|
79
|
+
Thrift::ApplicationException.should_receive(:new).and_return do
|
80
|
+
StandardError.new.tap do |mock_exc|
|
82
81
|
mock_exc.should_receive(:read).with(@prot)
|
83
82
|
end
|
84
83
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: UTF-8
|
1
2
|
#
|
2
3
|
# Licensed to the Apache Software Foundation (ASF) under one
|
3
4
|
# or more contributor license agreements. See the NOTICE file
|
@@ -17,7 +18,7 @@
|
|
17
18
|
# under the License.
|
18
19
|
#
|
19
20
|
|
20
|
-
require
|
21
|
+
require 'spec_helper'
|
21
22
|
|
22
23
|
describe Thrift::CompactProtocol do
|
23
24
|
TESTS = {
|
@@ -25,7 +26,7 @@ describe Thrift::CompactProtocol do
|
|
25
26
|
:i16 => (0..14).map {|shift| [1 << shift, -(1 << shift)]}.flatten.sort,
|
26
27
|
:i32 => (0..30).map {|shift| [1 << shift, -(1 << shift)]}.flatten.sort,
|
27
28
|
:i64 => (0..62).map {|shift| [1 << shift, -(1 << shift)]}.flatten.sort,
|
28
|
-
:string => ["", "1", "short", "fourteen123456", "fifteen12345678", "1" * 127, "1" * 3000],
|
29
|
+
:string => ["", "1", "short", "fourteen123456", "fifteen12345678", "unicode characters: \u20AC \u20AD", "1" * 127, "1" * 3000],
|
29
30
|
:binary => ["", "\001", "\001" * 5, "\001" * 14, "\001" * 15, "\001" * 127, "\001" * 3000],
|
30
31
|
:double => [0.0, 1.0, -1.0, 1.1, -1.1, 10000000.1, 1.0/0.0, -1.0/0.0],
|
31
32
|
:bool => [true, false]
|
data/spec/exception_spec.rb
CHANGED
@@ -17,29 +17,28 @@
|
|
17
17
|
# under the License.
|
18
18
|
#
|
19
19
|
|
20
|
-
require
|
20
|
+
require 'spec_helper'
|
21
21
|
|
22
|
-
|
23
|
-
include Thrift
|
22
|
+
describe 'Exception' do
|
24
23
|
|
25
|
-
describe Exception do
|
24
|
+
describe Thrift::Exception do
|
26
25
|
it "should have an accessible message" do
|
27
|
-
e = Exception.new("test message")
|
26
|
+
e = Thrift::Exception.new("test message")
|
28
27
|
e.message.should == "test message"
|
29
28
|
end
|
30
29
|
end
|
31
30
|
|
32
|
-
describe ApplicationException do
|
31
|
+
describe Thrift::ApplicationException do
|
33
32
|
it "should inherit from Thrift::Exception" do
|
34
|
-
ApplicationException.superclass.should == Exception
|
33
|
+
Thrift::ApplicationException.superclass.should == Thrift::Exception
|
35
34
|
end
|
36
35
|
|
37
36
|
it "should have an accessible type and message" do
|
38
|
-
e = ApplicationException.new
|
39
|
-
e.type.should == ApplicationException::UNKNOWN
|
37
|
+
e = Thrift::ApplicationException.new
|
38
|
+
e.type.should == Thrift::ApplicationException::UNKNOWN
|
40
39
|
e.message.should be_nil
|
41
|
-
e = ApplicationException.new(ApplicationException::UNKNOWN_METHOD, "test message")
|
42
|
-
e.type.should == ApplicationException::UNKNOWN_METHOD
|
40
|
+
e = Thrift::ApplicationException.new(Thrift::ApplicationException::UNKNOWN_METHOD, "test message")
|
41
|
+
e.type.should == Thrift::ApplicationException::UNKNOWN_METHOD
|
43
42
|
e.message.should == "test message"
|
44
43
|
end
|
45
44
|
|
@@ -47,79 +46,79 @@ class ThriftExceptionSpec < Spec::ExampleGroup
|
|
47
46
|
prot = mock("MockProtocol")
|
48
47
|
prot.should_receive(:read_struct_begin).ordered
|
49
48
|
prot.should_receive(:read_field_begin).exactly(3).times.and_return(
|
50
|
-
["message", Types::STRING, 1],
|
51
|
-
["type", Types::I32, 2],
|
52
|
-
[nil, Types::STOP, 0]
|
49
|
+
["message", Thrift::Types::STRING, 1],
|
50
|
+
["type", Thrift::Types::I32, 2],
|
51
|
+
[nil, Thrift::Types::STOP, 0]
|
53
52
|
)
|
54
53
|
prot.should_receive(:read_string).ordered.and_return "test message"
|
55
|
-
prot.should_receive(:read_i32).ordered.and_return ApplicationException::BAD_SEQUENCE_ID
|
54
|
+
prot.should_receive(:read_i32).ordered.and_return Thrift::ApplicationException::BAD_SEQUENCE_ID
|
56
55
|
prot.should_receive(:read_field_end).exactly(2).times
|
57
56
|
prot.should_receive(:read_struct_end).ordered
|
58
57
|
|
59
|
-
e = ApplicationException.new
|
58
|
+
e = Thrift::ApplicationException.new
|
60
59
|
e.read(prot)
|
61
60
|
e.message.should == "test message"
|
62
|
-
e.type.should == ApplicationException::BAD_SEQUENCE_ID
|
61
|
+
e.type.should == Thrift::ApplicationException::BAD_SEQUENCE_ID
|
63
62
|
end
|
64
63
|
|
65
64
|
it "should skip bad fields when reading a struct" do
|
66
65
|
prot = mock("MockProtocol")
|
67
66
|
prot.should_receive(:read_struct_begin).ordered
|
68
67
|
prot.should_receive(:read_field_begin).exactly(5).times.and_return(
|
69
|
-
["type", Types::I32, 2],
|
70
|
-
["type", Types::STRING, 2],
|
71
|
-
["message", Types::MAP, 1],
|
72
|
-
["message", Types::STRING, 3],
|
73
|
-
[nil, Types::STOP, 0]
|
68
|
+
["type", Thrift::Types::I32, 2],
|
69
|
+
["type", Thrift::Types::STRING, 2],
|
70
|
+
["message", Thrift::Types::MAP, 1],
|
71
|
+
["message", Thrift::Types::STRING, 3],
|
72
|
+
[nil, Thrift::Types::STOP, 0]
|
74
73
|
)
|
75
|
-
prot.should_receive(:read_i32).and_return ApplicationException::INVALID_MESSAGE_TYPE
|
76
|
-
prot.should_receive(:skip).with(Types::STRING).twice
|
77
|
-
prot.should_receive(:skip).with(Types::MAP)
|
74
|
+
prot.should_receive(:read_i32).and_return Thrift::ApplicationException::INVALID_MESSAGE_TYPE
|
75
|
+
prot.should_receive(:skip).with(Thrift::Types::STRING).twice
|
76
|
+
prot.should_receive(:skip).with(Thrift::Types::MAP)
|
78
77
|
prot.should_receive(:read_field_end).exactly(4).times
|
79
78
|
prot.should_receive(:read_struct_end).ordered
|
80
79
|
|
81
|
-
e = ApplicationException.new
|
80
|
+
e = Thrift::ApplicationException.new
|
82
81
|
e.read(prot)
|
83
82
|
e.message.should be_nil
|
84
|
-
e.type.should == ApplicationException::INVALID_MESSAGE_TYPE
|
83
|
+
e.type.should == Thrift::ApplicationException::INVALID_MESSAGE_TYPE
|
85
84
|
end
|
86
85
|
|
87
86
|
it "should write a Thrift::ApplicationException struct to the oprot" do
|
88
87
|
prot = mock("MockProtocol")
|
89
88
|
prot.should_receive(:write_struct_begin).with("Thrift::ApplicationException").ordered
|
90
|
-
prot.should_receive(:write_field_begin).with("message", Types::STRING, 1).ordered
|
89
|
+
prot.should_receive(:write_field_begin).with("message", Thrift::Types::STRING, 1).ordered
|
91
90
|
prot.should_receive(:write_string).with("test message").ordered
|
92
|
-
prot.should_receive(:write_field_begin).with("type", Types::I32, 2).ordered
|
93
|
-
prot.should_receive(:write_i32).with(ApplicationException::UNKNOWN_METHOD).ordered
|
91
|
+
prot.should_receive(:write_field_begin).with("type", Thrift::Types::I32, 2).ordered
|
92
|
+
prot.should_receive(:write_i32).with(Thrift::ApplicationException::UNKNOWN_METHOD).ordered
|
94
93
|
prot.should_receive(:write_field_end).twice
|
95
94
|
prot.should_receive(:write_field_stop).ordered
|
96
95
|
prot.should_receive(:write_struct_end).ordered
|
97
96
|
|
98
|
-
e = ApplicationException.new(ApplicationException::UNKNOWN_METHOD, "test message")
|
97
|
+
e = Thrift::ApplicationException.new(Thrift::ApplicationException::UNKNOWN_METHOD, "test message")
|
99
98
|
e.write(prot)
|
100
99
|
end
|
101
100
|
|
102
101
|
it "should skip nil fields when writing to the oprot" do
|
103
102
|
prot = mock("MockProtocol")
|
104
103
|
prot.should_receive(:write_struct_begin).with("Thrift::ApplicationException").ordered
|
105
|
-
prot.should_receive(:write_field_begin).with("message", Types::STRING, 1).ordered
|
104
|
+
prot.should_receive(:write_field_begin).with("message", Thrift::Types::STRING, 1).ordered
|
106
105
|
prot.should_receive(:write_string).with("test message").ordered
|
107
106
|
prot.should_receive(:write_field_end).ordered
|
108
107
|
prot.should_receive(:write_field_stop).ordered
|
109
108
|
prot.should_receive(:write_struct_end).ordered
|
110
109
|
|
111
|
-
e = ApplicationException.new(nil, "test message")
|
110
|
+
e = Thrift::ApplicationException.new(nil, "test message")
|
112
111
|
e.write(prot)
|
113
112
|
|
114
113
|
prot = mock("MockProtocol")
|
115
114
|
prot.should_receive(:write_struct_begin).with("Thrift::ApplicationException").ordered
|
116
|
-
prot.should_receive(:write_field_begin).with("type", Types::I32, 2).ordered
|
117
|
-
prot.should_receive(:write_i32).with(ApplicationException::BAD_SEQUENCE_ID).ordered
|
115
|
+
prot.should_receive(:write_field_begin).with("type", Thrift::Types::I32, 2).ordered
|
116
|
+
prot.should_receive(:write_i32).with(Thrift::ApplicationException::BAD_SEQUENCE_ID).ordered
|
118
117
|
prot.should_receive(:write_field_end).ordered
|
119
118
|
prot.should_receive(:write_field_stop).ordered
|
120
119
|
prot.should_receive(:write_struct_end).ordered
|
121
120
|
|
122
|
-
e = ApplicationException.new(ApplicationException::BAD_SEQUENCE_ID)
|
121
|
+
e = Thrift::ApplicationException.new(Thrift::ApplicationException::BAD_SEQUENCE_ID)
|
123
122
|
e.write(prot)
|
124
123
|
|
125
124
|
prot = mock("MockProtocol")
|
@@ -127,15 +126,15 @@ class ThriftExceptionSpec < Spec::ExampleGroup
|
|
127
126
|
prot.should_receive(:write_field_stop).ordered
|
128
127
|
prot.should_receive(:write_struct_end).ordered
|
129
128
|
|
130
|
-
e = ApplicationException.new(nil)
|
129
|
+
e = Thrift::ApplicationException.new(nil)
|
131
130
|
e.write(prot)
|
132
131
|
end
|
133
132
|
end
|
134
133
|
|
135
|
-
describe ProtocolException do
|
134
|
+
describe Thrift::ProtocolException do
|
136
135
|
it "should have an accessible type" do
|
137
|
-
prot = ProtocolException.new(ProtocolException::SIZE_LIMIT, "message")
|
138
|
-
prot.type.should == ProtocolException::SIZE_LIMIT
|
136
|
+
prot = Thrift::ProtocolException.new(Thrift::ProtocolException::SIZE_LIMIT, "message")
|
137
|
+
prot.type.should == Thrift::ProtocolException::SIZE_LIMIT
|
139
138
|
prot.message.should == "message"
|
140
139
|
end
|
141
140
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#
|
2
|
-
# Autogenerated by Thrift Compiler (0.
|
2
|
+
# Autogenerated by Thrift Compiler (0.9.0)
|
3
3
|
#
|
4
4
|
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
5
5
|
#
|
@@ -7,266 +7,266 @@
|
|
7
7
|
require 'thrift'
|
8
8
|
require 'thrift_spec_types'
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
def greeting(english)
|
16
|
-
send_greeting(english)
|
17
|
-
return recv_greeting()
|
18
|
-
end
|
19
|
-
|
20
|
-
def send_greeting(english)
|
21
|
-
send_message('greeting', Greeting_args, :english => english)
|
22
|
-
end
|
23
|
-
|
24
|
-
def recv_greeting()
|
25
|
-
result = receive_message(Greeting_result)
|
26
|
-
return result.success unless result.success.nil?
|
27
|
-
raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'greeting failed: unknown result')
|
28
|
-
end
|
29
|
-
|
30
|
-
def block()
|
31
|
-
send_block()
|
32
|
-
return recv_block()
|
33
|
-
end
|
34
|
-
|
35
|
-
def send_block()
|
36
|
-
send_message('block', Block_args)
|
37
|
-
end
|
38
|
-
|
39
|
-
def recv_block()
|
40
|
-
result = receive_message(Block_result)
|
41
|
-
return result.success unless result.success.nil?
|
42
|
-
raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'block failed: unknown result')
|
43
|
-
end
|
44
|
-
|
45
|
-
def unblock(n)
|
46
|
-
send_unblock(n)
|
47
|
-
end
|
48
|
-
|
49
|
-
def send_unblock(n)
|
50
|
-
send_message('unblock', Unblock_args, :n => n)
|
51
|
-
end
|
52
|
-
def shutdown()
|
53
|
-
send_shutdown()
|
54
|
-
end
|
10
|
+
module SpecNamespace
|
11
|
+
module NonblockingService
|
12
|
+
class Client
|
13
|
+
include ::Thrift::Client
|
55
14
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
send_sleep(seconds)
|
61
|
-
recv_sleep()
|
62
|
-
end
|
15
|
+
def greeting(english)
|
16
|
+
send_greeting(english)
|
17
|
+
return recv_greeting()
|
18
|
+
end
|
63
19
|
|
64
|
-
|
65
|
-
|
66
|
-
|
20
|
+
def send_greeting(english)
|
21
|
+
send_message('greeting', Greeting_args, :english => english)
|
22
|
+
end
|
67
23
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
24
|
+
def recv_greeting()
|
25
|
+
result = receive_message(Greeting_result)
|
26
|
+
return result.success unless result.success.nil?
|
27
|
+
raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'greeting failed: unknown result')
|
28
|
+
end
|
72
29
|
|
73
|
-
|
30
|
+
def block()
|
31
|
+
send_block()
|
32
|
+
return recv_block()
|
33
|
+
end
|
74
34
|
|
75
|
-
|
76
|
-
|
35
|
+
def send_block()
|
36
|
+
send_message('block', Block_args)
|
37
|
+
end
|
77
38
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
end
|
39
|
+
def recv_block()
|
40
|
+
result = receive_message(Block_result)
|
41
|
+
return result.success unless result.success.nil?
|
42
|
+
raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'block failed: unknown result')
|
43
|
+
end
|
84
44
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
result.success = @handler.block()
|
89
|
-
write_result(result, oprot, 'block', seqid)
|
90
|
-
end
|
45
|
+
def unblock(n)
|
46
|
+
send_unblock(n)
|
47
|
+
end
|
91
48
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
49
|
+
def send_unblock(n)
|
50
|
+
send_message('unblock', Unblock_args, :n => n)
|
51
|
+
end
|
52
|
+
def shutdown()
|
53
|
+
send_shutdown()
|
54
|
+
end
|
97
55
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
56
|
+
def send_shutdown()
|
57
|
+
send_message('shutdown', Shutdown_args)
|
58
|
+
end
|
59
|
+
def sleep(seconds)
|
60
|
+
send_sleep(seconds)
|
61
|
+
recv_sleep()
|
62
|
+
end
|
103
63
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
64
|
+
def send_sleep(seconds)
|
65
|
+
send_message('sleep', Sleep_args, :seconds => seconds)
|
66
|
+
end
|
67
|
+
|
68
|
+
def recv_sleep()
|
69
|
+
result = receive_message(Sleep_result)
|
70
|
+
return
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
class Processor
|
76
|
+
include ::Thrift::Processor
|
77
|
+
|
78
|
+
def process_greeting(seqid, iprot, oprot)
|
79
|
+
args = read_args(iprot, Greeting_args)
|
80
|
+
result = Greeting_result.new()
|
81
|
+
result.success = @handler.greeting(args.english)
|
82
|
+
write_result(result, oprot, 'greeting', seqid)
|
83
|
+
end
|
84
|
+
|
85
|
+
def process_block(seqid, iprot, oprot)
|
86
|
+
args = read_args(iprot, Block_args)
|
87
|
+
result = Block_result.new()
|
88
|
+
result.success = @handler.block()
|
89
|
+
write_result(result, oprot, 'block', seqid)
|
90
|
+
end
|
91
|
+
|
92
|
+
def process_unblock(seqid, iprot, oprot)
|
93
|
+
args = read_args(iprot, Unblock_args)
|
94
|
+
@handler.unblock(args.n)
|
95
|
+
return
|
96
|
+
end
|
110
97
|
|
111
|
-
|
98
|
+
def process_shutdown(seqid, iprot, oprot)
|
99
|
+
args = read_args(iprot, Shutdown_args)
|
100
|
+
@handler.shutdown()
|
101
|
+
return
|
102
|
+
end
|
112
103
|
|
113
|
-
|
104
|
+
def process_sleep(seqid, iprot, oprot)
|
105
|
+
args = read_args(iprot, Sleep_args)
|
106
|
+
result = Sleep_result.new()
|
107
|
+
@handler.sleep(args.seconds)
|
108
|
+
write_result(result, oprot, 'sleep', seqid)
|
109
|
+
end
|
114
110
|
|
115
|
-
|
116
|
-
include ::Thrift::Struct, ::Thrift::Struct_Union
|
117
|
-
ENGLISH = 1
|
111
|
+
end
|
118
112
|
|
119
|
-
|
120
|
-
ENGLISH => {:type => ::Thrift::Types::BOOL, :name => 'english'}
|
121
|
-
}
|
113
|
+
# HELPER FUNCTIONS AND STRUCTURES
|
122
114
|
|
123
|
-
|
115
|
+
class Greeting_args
|
116
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
117
|
+
ENGLISH = 1
|
124
118
|
|
125
|
-
|
126
|
-
|
119
|
+
FIELDS = {
|
120
|
+
ENGLISH => {:type => ::Thrift::Types::BOOL, :name => 'english'}
|
121
|
+
}
|
127
122
|
|
128
|
-
|
129
|
-
end
|
123
|
+
def struct_fields; FIELDS; end
|
130
124
|
|
131
|
-
|
132
|
-
|
133
|
-
SUCCESS = 0
|
125
|
+
def validate
|
126
|
+
end
|
134
127
|
|
135
|
-
|
136
|
-
|
137
|
-
}
|
128
|
+
::Thrift::Struct.generate_accessors self
|
129
|
+
end
|
138
130
|
|
139
|
-
|
131
|
+
class Greeting_result
|
132
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
133
|
+
SUCCESS = 0
|
140
134
|
|
141
|
-
|
142
|
-
|
135
|
+
FIELDS = {
|
136
|
+
SUCCESS => {:type => ::Thrift::Types::STRUCT, :name => 'success', :class => ::SpecNamespace::Hello}
|
137
|
+
}
|
143
138
|
|
144
|
-
|
145
|
-
end
|
139
|
+
def struct_fields; FIELDS; end
|
146
140
|
|
147
|
-
|
148
|
-
|
141
|
+
def validate
|
142
|
+
end
|
149
143
|
|
150
|
-
|
144
|
+
::Thrift::Struct.generate_accessors self
|
145
|
+
end
|
151
146
|
|
152
|
-
|
147
|
+
class Block_args
|
148
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
153
149
|
|
154
|
-
|
150
|
+
FIELDS = {
|
155
151
|
|
156
|
-
|
157
|
-
end
|
152
|
+
}
|
158
153
|
|
159
|
-
|
160
|
-
end
|
154
|
+
def struct_fields; FIELDS; end
|
161
155
|
|
162
|
-
|
163
|
-
|
164
|
-
SUCCESS = 0
|
156
|
+
def validate
|
157
|
+
end
|
165
158
|
|
166
|
-
|
167
|
-
|
168
|
-
}
|
159
|
+
::Thrift::Struct.generate_accessors self
|
160
|
+
end
|
169
161
|
|
170
|
-
|
162
|
+
class Block_result
|
163
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
164
|
+
SUCCESS = 0
|
171
165
|
|
172
|
-
|
173
|
-
|
166
|
+
FIELDS = {
|
167
|
+
SUCCESS => {:type => ::Thrift::Types::BOOL, :name => 'success'}
|
168
|
+
}
|
174
169
|
|
175
|
-
|
176
|
-
end
|
170
|
+
def struct_fields; FIELDS; end
|
177
171
|
|
178
|
-
|
179
|
-
|
180
|
-
N = 1
|
172
|
+
def validate
|
173
|
+
end
|
181
174
|
|
182
|
-
|
183
|
-
|
184
|
-
}
|
175
|
+
::Thrift::Struct.generate_accessors self
|
176
|
+
end
|
185
177
|
|
186
|
-
|
178
|
+
class Unblock_args
|
179
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
180
|
+
N = 1
|
187
181
|
|
188
|
-
|
189
|
-
|
182
|
+
FIELDS = {
|
183
|
+
N => {:type => ::Thrift::Types::I32, :name => 'n'}
|
184
|
+
}
|
190
185
|
|
191
|
-
|
192
|
-
end
|
186
|
+
def struct_fields; FIELDS; end
|
193
187
|
|
194
|
-
|
195
|
-
|
188
|
+
def validate
|
189
|
+
end
|
196
190
|
|
197
|
-
|
191
|
+
::Thrift::Struct.generate_accessors self
|
192
|
+
end
|
198
193
|
|
199
|
-
|
194
|
+
class Unblock_result
|
195
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
200
196
|
|
201
|
-
|
197
|
+
FIELDS = {
|
202
198
|
|
203
|
-
|
204
|
-
end
|
199
|
+
}
|
205
200
|
|
206
|
-
|
207
|
-
end
|
201
|
+
def struct_fields; FIELDS; end
|
208
202
|
|
209
|
-
|
210
|
-
|
203
|
+
def validate
|
204
|
+
end
|
211
205
|
|
212
|
-
|
206
|
+
::Thrift::Struct.generate_accessors self
|
207
|
+
end
|
213
208
|
|
214
|
-
|
209
|
+
class Shutdown_args
|
210
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
215
211
|
|
216
|
-
|
212
|
+
FIELDS = {
|
217
213
|
|
218
|
-
|
219
|
-
end
|
214
|
+
}
|
220
215
|
|
221
|
-
|
222
|
-
end
|
216
|
+
def struct_fields; FIELDS; end
|
223
217
|
|
224
|
-
|
225
|
-
|
218
|
+
def validate
|
219
|
+
end
|
226
220
|
|
227
|
-
|
221
|
+
::Thrift::Struct.generate_accessors self
|
222
|
+
end
|
228
223
|
|
229
|
-
|
224
|
+
class Shutdown_result
|
225
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
230
226
|
|
231
|
-
|
227
|
+
FIELDS = {
|
232
228
|
|
233
|
-
|
234
|
-
end
|
229
|
+
}
|
235
230
|
|
236
|
-
|
237
|
-
end
|
231
|
+
def struct_fields; FIELDS; end
|
238
232
|
|
239
|
-
|
240
|
-
|
241
|
-
SECONDS = 1
|
233
|
+
def validate
|
234
|
+
end
|
242
235
|
|
243
|
-
|
244
|
-
|
245
|
-
}
|
236
|
+
::Thrift::Struct.generate_accessors self
|
237
|
+
end
|
246
238
|
|
247
|
-
|
239
|
+
class Sleep_args
|
240
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
241
|
+
SECONDS = 1
|
248
242
|
|
249
|
-
|
250
|
-
|
243
|
+
FIELDS = {
|
244
|
+
SECONDS => {:type => ::Thrift::Types::DOUBLE, :name => 'seconds'}
|
245
|
+
}
|
251
246
|
|
252
|
-
|
253
|
-
end
|
247
|
+
def struct_fields; FIELDS; end
|
254
248
|
|
255
|
-
|
256
|
-
|
249
|
+
def validate
|
250
|
+
end
|
257
251
|
|
258
|
-
|
252
|
+
::Thrift::Struct.generate_accessors self
|
253
|
+
end
|
259
254
|
|
260
|
-
|
255
|
+
class Sleep_result
|
256
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
261
257
|
|
262
|
-
|
258
|
+
FIELDS = {
|
263
259
|
|
264
|
-
|
265
|
-
end
|
260
|
+
}
|
266
261
|
|
267
|
-
|
268
|
-
end
|
262
|
+
def struct_fields; FIELDS; end
|
269
263
|
|
264
|
+
def validate
|
270
265
|
end
|
271
266
|
|
267
|
+
::Thrift::Struct.generate_accessors self
|
272
268
|
end
|
269
|
+
|
270
|
+
end
|
271
|
+
|
272
|
+
end
|