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.
- checksums.yaml +7 -0
- data/README.md +43 -0
- data/benchmark/Benchmark.thrift +24 -0
- data/benchmark/benchmark.rb +271 -0
- data/benchmark/client.rb +74 -0
- data/benchmark/gen-rb/benchmark_constants.rb +11 -0
- data/benchmark/gen-rb/benchmark_service.rb +80 -0
- data/benchmark/gen-rb/benchmark_types.rb +10 -0
- data/benchmark/server.rb +82 -0
- data/benchmark/thin_server.rb +44 -0
- data/ext/binary_protocol_accelerated.c +460 -0
- data/ext/binary_protocol_accelerated.h +20 -0
- data/ext/bytes.c +36 -0
- data/ext/bytes.h +31 -0
- data/ext/compact_protocol.c +637 -0
- data/ext/compact_protocol.h +20 -0
- data/ext/constants.h +99 -0
- data/ext/extconf.rb +34 -0
- data/ext/macros.h +41 -0
- data/ext/memory_buffer.c +134 -0
- data/ext/memory_buffer.h +20 -0
- data/ext/protocol.c +0 -0
- data/ext/protocol.h +0 -0
- data/ext/strlcpy.c +41 -0
- data/ext/strlcpy.h +34 -0
- data/ext/struct.c +707 -0
- data/ext/struct.h +25 -0
- data/ext/thrift_native.c +201 -0
- data/lib/thrift.rb +68 -0
- data/lib/thrift/bytes.rb +131 -0
- data/lib/thrift/client.rb +71 -0
- data/lib/thrift/core_ext.rb +23 -0
- data/lib/thrift/core_ext/fixnum.rb +29 -0
- data/lib/thrift/exceptions.rb +87 -0
- data/lib/thrift/multiplexed_processor.rb +76 -0
- data/lib/thrift/processor.rb +57 -0
- data/lib/thrift/protocol/base_protocol.rb +379 -0
- data/lib/thrift/protocol/binary_protocol.rb +237 -0
- data/lib/thrift/protocol/binary_protocol_accelerated.rb +39 -0
- data/lib/thrift/protocol/compact_protocol.rb +435 -0
- data/lib/thrift/protocol/json_protocol.rb +769 -0
- data/lib/thrift/protocol/multiplexed_protocol.rb +40 -0
- data/lib/thrift/protocol/protocol_decorator.rb +194 -0
- data/lib/thrift/serializer/deserializer.rb +33 -0
- data/lib/thrift/serializer/serializer.rb +34 -0
- data/lib/thrift/server/base_server.rb +31 -0
- data/lib/thrift/server/mongrel_http_server.rb +60 -0
- data/lib/thrift/server/nonblocking_server.rb +305 -0
- data/lib/thrift/server/rack_application.rb +61 -0
- data/lib/thrift/server/simple_server.rb +43 -0
- data/lib/thrift/server/thin_http_server.rb +51 -0
- data/lib/thrift/server/thread_pool_server.rb +75 -0
- data/lib/thrift/server/threaded_server.rb +47 -0
- data/lib/thrift/struct.rb +237 -0
- data/lib/thrift/struct_union.rb +192 -0
- data/lib/thrift/thrift_native.rb +24 -0
- data/lib/thrift/transport/base_server_transport.rb +37 -0
- data/lib/thrift/transport/base_transport.rb +109 -0
- data/lib/thrift/transport/buffered_transport.rb +114 -0
- data/lib/thrift/transport/framed_transport.rb +117 -0
- data/lib/thrift/transport/http_client_transport.rb +56 -0
- data/lib/thrift/transport/io_stream_transport.rb +39 -0
- data/lib/thrift/transport/memory_buffer_transport.rb +125 -0
- data/lib/thrift/transport/server_socket.rb +63 -0
- data/lib/thrift/transport/socket.rb +139 -0
- data/lib/thrift/transport/unix_server_socket.rb +60 -0
- data/lib/thrift/transport/unix_socket.rb +40 -0
- data/lib/thrift/types.rb +101 -0
- data/lib/thrift/union.rb +179 -0
- data/spec/BaseService.thrift +27 -0
- data/spec/ExtendedService.thrift +25 -0
- data/spec/Referenced.thrift +44 -0
- data/spec/ThriftNamespacedSpec.thrift +53 -0
- data/spec/ThriftSpec.thrift +183 -0
- data/spec/base_protocol_spec.rb +217 -0
- data/spec/base_transport_spec.rb +350 -0
- data/spec/binary_protocol_accelerated_spec.rb +42 -0
- data/spec/binary_protocol_spec.rb +66 -0
- data/spec/binary_protocol_spec_shared.rb +455 -0
- data/spec/bytes_spec.rb +160 -0
- data/spec/client_spec.rb +99 -0
- data/spec/compact_protocol_spec.rb +143 -0
- data/spec/exception_spec.rb +141 -0
- data/spec/flat_spec.rb +62 -0
- data/spec/gen-rb/base/base_service.rb +80 -0
- data/spec/gen-rb/base/base_service_constants.rb +11 -0
- data/spec/gen-rb/base/base_service_types.rb +26 -0
- data/spec/gen-rb/extended/extended_service.rb +78 -0
- data/spec/gen-rb/extended/extended_service_constants.rb +11 -0
- data/spec/gen-rb/extended/extended_service_types.rb +12 -0
- data/spec/gen-rb/flat/namespaced_nonblocking_service.rb +272 -0
- data/spec/gen-rb/flat/referenced_constants.rb +11 -0
- data/spec/gen-rb/flat/referenced_types.rb +17 -0
- data/spec/gen-rb/flat/thrift_namespaced_spec_constants.rb +11 -0
- data/spec/gen-rb/flat/thrift_namespaced_spec_types.rb +28 -0
- data/spec/gen-rb/namespaced_spec_namespace/namespaced_nonblocking_service.rb +272 -0
- data/spec/gen-rb/namespaced_spec_namespace/thrift_namespaced_spec_constants.rb +11 -0
- data/spec/gen-rb/namespaced_spec_namespace/thrift_namespaced_spec_types.rb +28 -0
- data/spec/gen-rb/nonblocking_service.rb +272 -0
- data/spec/gen-rb/other_namespace/referenced_constants.rb +11 -0
- data/spec/gen-rb/other_namespace/referenced_types.rb +17 -0
- data/spec/gen-rb/thrift_spec_constants.rb +11 -0
- data/spec/gen-rb/thrift_spec_types.rb +538 -0
- data/spec/http_client_spec.rb +120 -0
- data/spec/json_protocol_spec.rb +513 -0
- data/spec/namespaced_spec.rb +67 -0
- data/spec/nonblocking_server_spec.rb +263 -0
- data/spec/processor_spec.rb +80 -0
- data/spec/serializer_spec.rb +67 -0
- data/spec/server_socket_spec.rb +79 -0
- data/spec/server_spec.rb +147 -0
- data/spec/socket_spec.rb +61 -0
- data/spec/socket_spec_shared.rb +104 -0
- data/spec/spec_helper.rb +64 -0
- data/spec/struct_nested_containers_spec.rb +191 -0
- data/spec/struct_spec.rb +293 -0
- data/spec/thin_http_server_spec.rb +141 -0
- data/spec/types_spec.rb +115 -0
- data/spec/union_spec.rb +203 -0
- data/spec/unix_socket_spec.rb +107 -0
- data/test/debug_proto/gen-rb/debug_proto_test_constants.rb +274 -0
- data/test/debug_proto/gen-rb/debug_proto_test_types.rb +761 -0
- data/test/debug_proto/gen-rb/empty_service.rb +24 -0
- data/test/debug_proto/gen-rb/inherited.rb +79 -0
- data/test/debug_proto/gen-rb/reverse_order_service.rb +82 -0
- data/test/debug_proto/gen-rb/service_for_exception_with_a_map.rb +81 -0
- data/test/debug_proto/gen-rb/srv.rb +330 -0
- metadata +388 -0
@@ -0,0 +1,120 @@
|
|
1
|
+
#
|
2
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
3
|
+
# or more contributor license agreements. See the NOTICE file
|
4
|
+
# distributed with this work for additional information
|
5
|
+
# regarding copyright ownership. The ASF licenses this file
|
6
|
+
# to you under the Apache License, Version 2.0 (the
|
7
|
+
# "License"); you may not use this file except in compliance
|
8
|
+
# with the License. You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing,
|
13
|
+
# software distributed under the License is distributed on an
|
14
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
15
|
+
# KIND, either express or implied. See the License for the
|
16
|
+
# specific language governing permissions and limitations
|
17
|
+
# under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
require 'spec_helper'
|
21
|
+
|
22
|
+
describe 'Thrift::HTTPClientTransport' do
|
23
|
+
|
24
|
+
describe Thrift::HTTPClientTransport do
|
25
|
+
before(:each) do
|
26
|
+
@client = Thrift::HTTPClientTransport.new("http://my.domain.com/path/to/service?param=value")
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should always be open" do
|
30
|
+
@client.should be_open
|
31
|
+
@client.close
|
32
|
+
@client.should be_open
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should post via HTTP and return the results" do
|
36
|
+
@client.write "a test"
|
37
|
+
@client.write " frame"
|
38
|
+
Net::HTTP.should_receive(:new).with("my.domain.com", 80).and_return do
|
39
|
+
mock("Net::HTTP").tap do |http|
|
40
|
+
http.should_receive(:use_ssl=).with(false)
|
41
|
+
http.should_receive(:post).with("/path/to/service?param=value", "a test frame", {"Content-Type"=>"application/x-thrift"}).and_return do
|
42
|
+
mock("Net::HTTPOK").tap do |response|
|
43
|
+
response.should_receive(:body).and_return "data"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
@client.flush
|
49
|
+
@client.read(10).should == "data"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should send custom headers if defined" do
|
53
|
+
@client.write "test"
|
54
|
+
custom_headers = {"Cookie" => "Foo"}
|
55
|
+
headers = {"Content-Type"=>"application/x-thrift"}.merge(custom_headers)
|
56
|
+
|
57
|
+
@client.add_headers(custom_headers)
|
58
|
+
Net::HTTP.should_receive(:new).with("my.domain.com", 80).and_return do
|
59
|
+
mock("Net::HTTP").tap do |http|
|
60
|
+
http.should_receive(:use_ssl=).with(false)
|
61
|
+
http.should_receive(:post).with("/path/to/service?param=value", "test", headers).and_return do
|
62
|
+
mock("Net::HTTPOK").tap do |response|
|
63
|
+
response.should_receive(:body).and_return "data"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
@client.flush
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe 'ssl enabled' do
|
73
|
+
before(:each) do
|
74
|
+
@service_path = "/path/to/service?param=value"
|
75
|
+
@server_uri = "https://my.domain.com"
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should use SSL for https" do
|
79
|
+
client = Thrift::HTTPClientTransport.new("#{@server_uri}#{@service_path}")
|
80
|
+
|
81
|
+
client.write "test"
|
82
|
+
|
83
|
+
Net::HTTP.should_receive(:new).with("my.domain.com", 443).and_return do
|
84
|
+
mock("Net::HTTP").tap do |http|
|
85
|
+
http.should_receive(:use_ssl=).with(true)
|
86
|
+
http.should_receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_PEER)
|
87
|
+
http.should_receive(:post).with(@service_path, "test",
|
88
|
+
"Content-Type" => "application/x-thrift").and_return do
|
89
|
+
mock("Net::HTTPOK").tap do |response|
|
90
|
+
response.should_receive(:body).and_return "data"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
client.flush
|
96
|
+
client.read(4).should == "data"
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should set SSL verify mode when specified" do
|
100
|
+
client = Thrift::HTTPClientTransport.new("#{@server_uri}#{@service_path}",
|
101
|
+
:ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE)
|
102
|
+
|
103
|
+
client.write "test"
|
104
|
+
Net::HTTP.should_receive(:new).with("my.domain.com", 443).and_return do
|
105
|
+
mock("Net::HTTP").tap do |http|
|
106
|
+
http.should_receive(:use_ssl=).with(true)
|
107
|
+
http.should_receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
|
108
|
+
http.should_receive(:post).with(@service_path, "test",
|
109
|
+
"Content-Type" => "application/x-thrift").and_return do
|
110
|
+
mock("Net::HTTPOK").tap do |response|
|
111
|
+
response.should_receive(:body).and_return "data"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
client.flush
|
117
|
+
client.read(4).should == "data"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,513 @@
|
|
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 'JsonProtocol' do
|
24
|
+
|
25
|
+
describe Thrift::JsonProtocol do
|
26
|
+
before(:each) do
|
27
|
+
@trans = Thrift::MemoryBufferTransport.new
|
28
|
+
@prot = Thrift::JsonProtocol.new(@trans)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should write json escaped char" do
|
32
|
+
@prot.write_json_escape_char("\n")
|
33
|
+
@trans.read(@trans.available).should == '\u000a'
|
34
|
+
|
35
|
+
@prot.write_json_escape_char(" ")
|
36
|
+
@trans.read(@trans.available).should == '\u0020'
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should write json char" do
|
40
|
+
@prot.write_json_char("\n")
|
41
|
+
@trans.read(@trans.available).should == '\\n'
|
42
|
+
|
43
|
+
@prot.write_json_char(" ")
|
44
|
+
@trans.read(@trans.available).should == ' '
|
45
|
+
|
46
|
+
@prot.write_json_char("\\")
|
47
|
+
@trans.read(@trans.available).should == "\\\\"
|
48
|
+
|
49
|
+
@prot.write_json_char("@")
|
50
|
+
@trans.read(@trans.available).should == '@'
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should write json string" do
|
54
|
+
@prot.write_json_string("this is a \\ json\nstring")
|
55
|
+
@trans.read(@trans.available).should == "\"this is a \\\\ json\\nstring\""
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should write json base64" do
|
59
|
+
@prot.write_json_base64("this is a base64 string")
|
60
|
+
@trans.read(@trans.available).should == "\"\"dGhpcyBpcyBhIGJhc2U2NCBzdHJpbmc=\\n\"\""
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should write json integer" do
|
64
|
+
@prot.write_json_integer(45)
|
65
|
+
@trans.read(@trans.available).should == "45"
|
66
|
+
|
67
|
+
@prot.write_json_integer(33000)
|
68
|
+
@trans.read(@trans.available).should == "33000"
|
69
|
+
|
70
|
+
@prot.write_json_integer(3000000000)
|
71
|
+
@trans.read(@trans.available).should == "3000000000"
|
72
|
+
|
73
|
+
@prot.write_json_integer(6000000000)
|
74
|
+
@trans.read(@trans.available).should == "6000000000"
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should write json double" do
|
78
|
+
@prot.write_json_double(12.3)
|
79
|
+
@trans.read(@trans.available).should == "12.3"
|
80
|
+
|
81
|
+
@prot.write_json_double(-3.21)
|
82
|
+
@trans.read(@trans.available).should == "-3.21"
|
83
|
+
|
84
|
+
@prot.write_json_double(((+1.0/0.0)/(+1.0/0.0)))
|
85
|
+
@trans.read(@trans.available).should == "\"NaN\""
|
86
|
+
|
87
|
+
@prot.write_json_double((+1.0/0.0))
|
88
|
+
@trans.read(@trans.available).should == "\"Infinity\""
|
89
|
+
|
90
|
+
@prot.write_json_double((-1.0/0.0))
|
91
|
+
@trans.read(@trans.available).should == "\"-Infinity\""
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should write json object start" do
|
95
|
+
@prot.write_json_object_start
|
96
|
+
@trans.read(@trans.available).should == "{"
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should write json object end" do
|
100
|
+
@prot.write_json_object_end
|
101
|
+
@trans.read(@trans.available).should == "}"
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should write json array start" do
|
105
|
+
@prot.write_json_array_start
|
106
|
+
@trans.read(@trans.available).should == "["
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should write json array end" do
|
110
|
+
@prot.write_json_array_end
|
111
|
+
@trans.read(@trans.available).should == "]"
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should write message begin" do
|
115
|
+
@prot.write_message_begin("name", 12, 32)
|
116
|
+
@trans.read(@trans.available).should == "[1,\"name\",12,32"
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should write message end" do
|
120
|
+
@prot.write_message_end
|
121
|
+
@trans.read(@trans.available).should == "]"
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should write struct begin" do
|
125
|
+
@prot.write_struct_begin("name")
|
126
|
+
@trans.read(@trans.available).should == "{"
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should write struct end" do
|
130
|
+
@prot.write_struct_end
|
131
|
+
@trans.read(@trans.available).should == "}"
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should write field begin" do
|
135
|
+
@prot.write_field_begin("name", Thrift::Types::STRUCT, 32)
|
136
|
+
@trans.read(@trans.available).should == "32{\"rec\""
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should write field end" do
|
140
|
+
@prot.write_field_end
|
141
|
+
@trans.read(@trans.available).should == "}"
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should write field stop" do
|
145
|
+
@prot.write_field_stop
|
146
|
+
@trans.read(@trans.available).should == ""
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should write map begin" do
|
150
|
+
@prot.write_map_begin(Thrift::Types::STRUCT, Thrift::Types::LIST, 32)
|
151
|
+
@trans.read(@trans.available).should == "[\"rec\",\"lst\",32,{"
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should write map end" do
|
155
|
+
@prot.write_map_end
|
156
|
+
@trans.read(@trans.available).should == "}]"
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should write list begin" do
|
160
|
+
@prot.write_list_begin(Thrift::Types::STRUCT, 32)
|
161
|
+
@trans.read(@trans.available).should == "[\"rec\",32"
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should write list end" do
|
165
|
+
@prot.write_list_end
|
166
|
+
@trans.read(@trans.available).should == "]"
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should write set begin" do
|
170
|
+
@prot.write_set_begin(Thrift::Types::STRUCT, 32)
|
171
|
+
@trans.read(@trans.available).should == "[\"rec\",32"
|
172
|
+
end
|
173
|
+
|
174
|
+
it "should write set end" do
|
175
|
+
@prot.write_set_end
|
176
|
+
@trans.read(@trans.available).should == "]"
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should write bool" do
|
180
|
+
@prot.write_bool(true)
|
181
|
+
@trans.read(@trans.available).should == "1"
|
182
|
+
|
183
|
+
@prot.write_bool(false)
|
184
|
+
@trans.read(@trans.available).should == "0"
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should write byte" do
|
188
|
+
@prot.write_byte(100)
|
189
|
+
@trans.read(@trans.available).should == "100"
|
190
|
+
end
|
191
|
+
|
192
|
+
it "should write i16" do
|
193
|
+
@prot.write_i16(1000)
|
194
|
+
@trans.read(@trans.available).should == "1000"
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should write i32" do
|
198
|
+
@prot.write_i32(3000000000)
|
199
|
+
@trans.read(@trans.available).should == "3000000000"
|
200
|
+
end
|
201
|
+
|
202
|
+
it "should write i64" do
|
203
|
+
@prot.write_i64(6000000000)
|
204
|
+
@trans.read(@trans.available).should == "6000000000"
|
205
|
+
end
|
206
|
+
|
207
|
+
it "should write double" do
|
208
|
+
@prot.write_double(1.23)
|
209
|
+
@trans.read(@trans.available).should == "1.23"
|
210
|
+
|
211
|
+
@prot.write_double(-32.1)
|
212
|
+
@trans.read(@trans.available).should == "-32.1"
|
213
|
+
|
214
|
+
@prot.write_double(((+1.0/0.0)/(+1.0/0.0)))
|
215
|
+
@trans.read(@trans.available).should == "\"NaN\""
|
216
|
+
|
217
|
+
@prot.write_double((+1.0/0.0))
|
218
|
+
@trans.read(@trans.available).should == "\"Infinity\""
|
219
|
+
|
220
|
+
@prot.write_double((-1.0/0.0))
|
221
|
+
@trans.read(@trans.available).should == "\"-Infinity\""
|
222
|
+
end
|
223
|
+
|
224
|
+
if RUBY_VERSION >= '1.9'
|
225
|
+
it 'should write string' do
|
226
|
+
@prot.write_string('this is a test string')
|
227
|
+
a = @trans.read(@trans.available)
|
228
|
+
a.should == '"this is a test string"'.force_encoding(Encoding::BINARY)
|
229
|
+
a.encoding.should == Encoding::BINARY
|
230
|
+
end
|
231
|
+
|
232
|
+
it 'should write string with unicode characters' do
|
233
|
+
@prot.write_string("this is a test string with unicode characters: \u20AC \u20AD")
|
234
|
+
a = @trans.read(@trans.available)
|
235
|
+
a.should == "\"this is a test string with unicode characters: \u20AC \u20AD\"".force_encoding(Encoding::BINARY)
|
236
|
+
a.encoding.should == Encoding::BINARY
|
237
|
+
end
|
238
|
+
else
|
239
|
+
it 'should write string' do
|
240
|
+
@prot.write_string('this is a test string')
|
241
|
+
@trans.read(@trans.available).should == '"this is a test string"'
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
it "should write binary" do
|
246
|
+
@prot.write_binary("this is a base64 string")
|
247
|
+
@trans.read(@trans.available).should == "\"\"dGhpcyBpcyBhIGJhc2U2NCBzdHJpbmc=\\n\"\""
|
248
|
+
end
|
249
|
+
|
250
|
+
it "should get type name for type id" do
|
251
|
+
expect {@prot.get_type_name_for_type_id(Thrift::Types::STOP)}.to raise_error(NotImplementedError)
|
252
|
+
expect {@prot.get_type_name_for_type_id(Thrift::Types::VOID)}.to raise_error(NotImplementedError)
|
253
|
+
@prot.get_type_name_for_type_id(Thrift::Types::BOOL).should == "tf"
|
254
|
+
@prot.get_type_name_for_type_id(Thrift::Types::BYTE).should == "i8"
|
255
|
+
@prot.get_type_name_for_type_id(Thrift::Types::DOUBLE).should == "dbl"
|
256
|
+
@prot.get_type_name_for_type_id(Thrift::Types::I16).should == "i16"
|
257
|
+
@prot.get_type_name_for_type_id(Thrift::Types::I32).should == "i32"
|
258
|
+
@prot.get_type_name_for_type_id(Thrift::Types::I64).should == "i64"
|
259
|
+
@prot.get_type_name_for_type_id(Thrift::Types::STRING).should == "str"
|
260
|
+
@prot.get_type_name_for_type_id(Thrift::Types::STRUCT).should == "rec"
|
261
|
+
@prot.get_type_name_for_type_id(Thrift::Types::MAP).should == "map"
|
262
|
+
@prot.get_type_name_for_type_id(Thrift::Types::SET).should == "set"
|
263
|
+
@prot.get_type_name_for_type_id(Thrift::Types::LIST).should == "lst"
|
264
|
+
end
|
265
|
+
|
266
|
+
it "should get type id for type name" do
|
267
|
+
expect {@prot.get_type_id_for_type_name("pp")}.to raise_error(NotImplementedError)
|
268
|
+
@prot.get_type_id_for_type_name("tf").should == Thrift::Types::BOOL
|
269
|
+
@prot.get_type_id_for_type_name("i8").should == Thrift::Types::BYTE
|
270
|
+
@prot.get_type_id_for_type_name("dbl").should == Thrift::Types::DOUBLE
|
271
|
+
@prot.get_type_id_for_type_name("i16").should == Thrift::Types::I16
|
272
|
+
@prot.get_type_id_for_type_name("i32").should == Thrift::Types::I32
|
273
|
+
@prot.get_type_id_for_type_name("i64").should == Thrift::Types::I64
|
274
|
+
@prot.get_type_id_for_type_name("str").should == Thrift::Types::STRING
|
275
|
+
@prot.get_type_id_for_type_name("rec").should == Thrift::Types::STRUCT
|
276
|
+
@prot.get_type_id_for_type_name("map").should == Thrift::Types::MAP
|
277
|
+
@prot.get_type_id_for_type_name("set").should == Thrift::Types::SET
|
278
|
+
@prot.get_type_id_for_type_name("lst").should == Thrift::Types::LIST
|
279
|
+
end
|
280
|
+
|
281
|
+
it "should read json syntax char" do
|
282
|
+
@trans.write('F')
|
283
|
+
expect {@prot.read_json_syntax_char('G')}.to raise_error(Thrift::ProtocolException)
|
284
|
+
@trans.write('H')
|
285
|
+
@prot.read_json_syntax_char('H')
|
286
|
+
end
|
287
|
+
|
288
|
+
it "should read json escape char" do
|
289
|
+
@trans.write('0054')
|
290
|
+
@prot.read_json_escape_char.should == 'T'
|
291
|
+
end
|
292
|
+
|
293
|
+
it "should read json string" do
|
294
|
+
@trans.write("\"\\P")
|
295
|
+
expect {@prot.read_json_string(false)}.to raise_error(Thrift::ProtocolException)
|
296
|
+
|
297
|
+
@trans.write("\"\\n\"")
|
298
|
+
@prot.read_json_string(false).should == "\\n"
|
299
|
+
|
300
|
+
@trans.write("\"this is a test string\"")
|
301
|
+
@prot.read_json_string.should == "this is a test string"
|
302
|
+
end
|
303
|
+
|
304
|
+
it "should read json base64" do
|
305
|
+
@trans.write("\"dGhpcyBpcyBhIHRlc3Qgc3RyaW5n\"")
|
306
|
+
@prot.read_json_base64.should == "this is a test string"
|
307
|
+
end
|
308
|
+
|
309
|
+
it "should is json numeric" do
|
310
|
+
@prot.is_json_numeric("A").should == false
|
311
|
+
@prot.is_json_numeric("+").should == true
|
312
|
+
@prot.is_json_numeric("-").should == true
|
313
|
+
@prot.is_json_numeric(".").should == true
|
314
|
+
@prot.is_json_numeric("0").should == true
|
315
|
+
@prot.is_json_numeric("1").should == true
|
316
|
+
@prot.is_json_numeric("2").should == true
|
317
|
+
@prot.is_json_numeric("3").should == true
|
318
|
+
@prot.is_json_numeric("4").should == true
|
319
|
+
@prot.is_json_numeric("5").should == true
|
320
|
+
@prot.is_json_numeric("6").should == true
|
321
|
+
@prot.is_json_numeric("7").should == true
|
322
|
+
@prot.is_json_numeric("8").should == true
|
323
|
+
@prot.is_json_numeric("9").should == true
|
324
|
+
@prot.is_json_numeric("E").should == true
|
325
|
+
@prot.is_json_numeric("e").should == true
|
326
|
+
end
|
327
|
+
|
328
|
+
it "should read json numeric chars" do
|
329
|
+
@trans.write("1.453E45T")
|
330
|
+
@prot.read_json_numeric_chars.should == "1.453E45"
|
331
|
+
end
|
332
|
+
|
333
|
+
it "should read json integer" do
|
334
|
+
@trans.write("1.45\"\"")
|
335
|
+
expect {@prot.read_json_integer}.to raise_error(Thrift::ProtocolException)
|
336
|
+
@prot.read_string
|
337
|
+
|
338
|
+
@trans.write("1453T")
|
339
|
+
@prot.read_json_integer.should == 1453
|
340
|
+
end
|
341
|
+
|
342
|
+
it "should read json double" do
|
343
|
+
@trans.write("1.45e3e01\"\"")
|
344
|
+
expect {@prot.read_json_double}.to raise_error(Thrift::ProtocolException)
|
345
|
+
@prot.read_string
|
346
|
+
|
347
|
+
@trans.write("\"1.453e01\"")
|
348
|
+
expect {@prot.read_json_double}.to raise_error(Thrift::ProtocolException)
|
349
|
+
|
350
|
+
@trans.write("1.453e01\"\"")
|
351
|
+
@prot.read_json_double.should == 14.53
|
352
|
+
@prot.read_string
|
353
|
+
|
354
|
+
@trans.write("\"NaN\"")
|
355
|
+
@prot.read_json_double.nan?.should == true
|
356
|
+
|
357
|
+
@trans.write("\"Infinity\"")
|
358
|
+
@prot.read_json_double.should == +1.0/0.0
|
359
|
+
|
360
|
+
@trans.write("\"-Infinity\"")
|
361
|
+
@prot.read_json_double.should == -1.0/0.0
|
362
|
+
end
|
363
|
+
|
364
|
+
it "should read json object start" do
|
365
|
+
@trans.write("{")
|
366
|
+
@prot.read_json_object_start.should == nil
|
367
|
+
end
|
368
|
+
|
369
|
+
it "should read json object end" do
|
370
|
+
@trans.write("}")
|
371
|
+
@prot.read_json_object_end.should == nil
|
372
|
+
end
|
373
|
+
|
374
|
+
it "should read json array start" do
|
375
|
+
@trans.write("[")
|
376
|
+
@prot.read_json_array_start.should == nil
|
377
|
+
end
|
378
|
+
|
379
|
+
it "should read json array end" do
|
380
|
+
@trans.write("]")
|
381
|
+
@prot.read_json_array_end.should == nil
|
382
|
+
end
|
383
|
+
|
384
|
+
it "should read_message_begin" do
|
385
|
+
@trans.write("[2,")
|
386
|
+
expect {@prot.read_message_begin}.to raise_error(Thrift::ProtocolException)
|
387
|
+
|
388
|
+
@trans.write("[1,\"name\",12,32\"\"")
|
389
|
+
@prot.read_message_begin.should == ["name", 12, 32]
|
390
|
+
end
|
391
|
+
|
392
|
+
it "should read message end" do
|
393
|
+
@trans.write("]")
|
394
|
+
@prot.read_message_end.should == nil
|
395
|
+
end
|
396
|
+
|
397
|
+
it "should read struct begin" do
|
398
|
+
@trans.write("{")
|
399
|
+
@prot.read_struct_begin.should == nil
|
400
|
+
end
|
401
|
+
|
402
|
+
it "should read struct end" do
|
403
|
+
@trans.write("}")
|
404
|
+
@prot.read_struct_end.should == nil
|
405
|
+
end
|
406
|
+
|
407
|
+
it "should read field begin" do
|
408
|
+
@trans.write("1{\"rec\"")
|
409
|
+
@prot.read_field_begin.should == [nil, 12, 1]
|
410
|
+
end
|
411
|
+
|
412
|
+
it "should read field end" do
|
413
|
+
@trans.write("}")
|
414
|
+
@prot.read_field_end.should == nil
|
415
|
+
end
|
416
|
+
|
417
|
+
it "should read map begin" do
|
418
|
+
@trans.write("[\"rec\",\"lst\",2,{")
|
419
|
+
@prot.read_map_begin.should == [12, 15, 2]
|
420
|
+
end
|
421
|
+
|
422
|
+
it "should read map end" do
|
423
|
+
@trans.write("}]")
|
424
|
+
@prot.read_map_end.should == nil
|
425
|
+
end
|
426
|
+
|
427
|
+
it "should read list begin" do
|
428
|
+
@trans.write("[\"rec\",2\"\"")
|
429
|
+
@prot.read_list_begin.should == [12, 2]
|
430
|
+
end
|
431
|
+
|
432
|
+
it "should read list end" do
|
433
|
+
@trans.write("]")
|
434
|
+
@prot.read_list_end.should == nil
|
435
|
+
end
|
436
|
+
|
437
|
+
it "should read set begin" do
|
438
|
+
@trans.write("[\"rec\",2\"\"")
|
439
|
+
@prot.read_set_begin.should == [12, 2]
|
440
|
+
end
|
441
|
+
|
442
|
+
it "should read set end" do
|
443
|
+
@trans.write("]")
|
444
|
+
@prot.read_set_end.should == nil
|
445
|
+
end
|
446
|
+
|
447
|
+
it "should read bool" do
|
448
|
+
@trans.write("0\"\"")
|
449
|
+
@prot.read_bool.should == false
|
450
|
+
@prot.read_string
|
451
|
+
|
452
|
+
@trans.write("1\"\"")
|
453
|
+
@prot.read_bool.should == true
|
454
|
+
end
|
455
|
+
|
456
|
+
it "should read byte" do
|
457
|
+
@trans.write("60\"\"")
|
458
|
+
@prot.read_byte.should == 60
|
459
|
+
end
|
460
|
+
|
461
|
+
it "should read i16" do
|
462
|
+
@trans.write("1000\"\"")
|
463
|
+
@prot.read_i16.should == 1000
|
464
|
+
end
|
465
|
+
|
466
|
+
it "should read i32" do
|
467
|
+
@trans.write("3000000000\"\"")
|
468
|
+
@prot.read_i32.should == 3000000000
|
469
|
+
end
|
470
|
+
|
471
|
+
it "should read i64" do
|
472
|
+
@trans.write("6000000000\"\"")
|
473
|
+
@prot.read_i64.should == 6000000000
|
474
|
+
end
|
475
|
+
|
476
|
+
it "should read double" do
|
477
|
+
@trans.write("12.23\"\"")
|
478
|
+
@prot.read_double.should == 12.23
|
479
|
+
end
|
480
|
+
|
481
|
+
if RUBY_VERSION >= '1.9'
|
482
|
+
it 'should read string' do
|
483
|
+
@trans.write('"this is a test string"'.force_encoding(Encoding::BINARY))
|
484
|
+
a = @prot.read_string
|
485
|
+
a.should == 'this is a test string'
|
486
|
+
a.encoding.should == Encoding::UTF_8
|
487
|
+
end
|
488
|
+
|
489
|
+
it 'should read string with unicode characters' do
|
490
|
+
@trans.write('"this is a test string with unicode characters: \u20AC \u20AD"'.force_encoding(Encoding::BINARY))
|
491
|
+
a = @prot.read_string
|
492
|
+
a.should == "this is a test string with unicode characters: \u20AC \u20AD"
|
493
|
+
a.encoding.should == Encoding::UTF_8
|
494
|
+
end
|
495
|
+
else
|
496
|
+
it 'should read string' do
|
497
|
+
@trans.write('"this is a test string"')
|
498
|
+
@prot.read_string.should == 'this is a test string'
|
499
|
+
end
|
500
|
+
end
|
501
|
+
|
502
|
+
it "should read binary" do
|
503
|
+
@trans.write("\"dGhpcyBpcyBhIHRlc3Qgc3RyaW5n\"")
|
504
|
+
@prot.read_binary.should == "this is a test string"
|
505
|
+
end
|
506
|
+
end
|
507
|
+
|
508
|
+
describe Thrift::JsonProtocolFactory do
|
509
|
+
it "should create a JsonProtocol" do
|
510
|
+
Thrift::JsonProtocolFactory.new.get_protocol(mock("MockTransport")).should be_instance_of(Thrift::JsonProtocol)
|
511
|
+
end
|
512
|
+
end
|
513
|
+
end
|