thrift 0.10.0.0 → 0.14.2
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 +5 -5
- data/lib/thrift/processor.rb +10 -1
- data/lib/thrift/protocol/base_protocol.rb +11 -3
- data/lib/thrift/protocol/binary_protocol.rb +8 -1
- data/lib/thrift/protocol/binary_protocol_accelerated.rb +8 -0
- data/lib/thrift/protocol/compact_protocol.rb +8 -0
- data/lib/thrift/protocol/json_protocol.rb +9 -1
- data/lib/thrift/protocol/multiplexed_protocol.rb +5 -1
- data/lib/thrift/server/base_server.rb +8 -2
- data/lib/thrift/server/simple_server.rb +5 -1
- data/lib/thrift/server/thread_pool_server.rb +5 -1
- data/lib/thrift/server/threaded_server.rb +5 -1
- data/lib/thrift/transport/base_server_transport.rb +1 -1
- data/lib/thrift/transport/base_transport.rb +8 -0
- data/lib/thrift/transport/buffered_transport.rb +9 -1
- data/lib/thrift/transport/framed_transport.rb +9 -1
- data/lib/thrift/transport/http_client_transport.rb +6 -0
- data/lib/thrift/transport/io_stream_transport.rb +4 -1
- data/lib/thrift/transport/memory_buffer_transport.rb +4 -0
- data/lib/thrift/transport/server_socket.rb +6 -1
- data/lib/thrift/transport/socket.rb +4 -2
- data/lib/thrift/transport/ssl_server_socket.rb +4 -0
- data/lib/thrift/transport/ssl_socket.rb +4 -0
- data/lib/thrift/transport/unix_server_socket.rb +5 -1
- data/lib/thrift/transport/unix_socket.rb +5 -1
- data/spec/base_protocol_spec.rb +79 -71
- data/spec/base_transport_spec.rb +155 -117
- data/spec/binary_protocol_accelerated_spec.rb +6 -2
- data/spec/binary_protocol_spec.rb +16 -8
- data/spec/binary_protocol_spec_shared.rb +73 -70
- data/spec/bytes_spec.rb +38 -38
- data/spec/client_spec.rb +41 -42
- data/spec/compact_protocol_spec.rb +23 -8
- data/spec/exception_spec.rb +54 -54
- data/spec/flat_spec.rb +5 -5
- data/spec/http_client_spec.rb +64 -38
- data/spec/json_protocol_spec.rb +146 -138
- data/spec/namespaced_spec.rb +5 -5
- data/spec/nonblocking_server_spec.rb +16 -16
- data/spec/processor_spec.rb +26 -26
- data/spec/serializer_spec.rb +20 -20
- data/spec/server_socket_spec.rb +27 -22
- data/spec/server_spec.rb +91 -51
- data/spec/socket_spec.rb +23 -16
- data/spec/socket_spec_shared.rb +31 -31
- data/spec/ssl_server_socket_spec.rb +34 -0
- data/spec/ssl_socket_spec.rb +26 -22
- data/spec/struct_nested_containers_spec.rb +24 -24
- data/spec/struct_spec.rb +120 -120
- data/spec/thin_http_server_spec.rb +18 -18
- data/spec/types_spec.rb +56 -53
- data/spec/union_spec.rb +42 -43
- data/spec/unix_socket_spec.rb +43 -34
- metadata +131 -94
data/spec/flat_spec.rb
CHANGED
@@ -32,7 +32,7 @@ describe 'generation' do
|
|
32
32
|
"other_namespace/referenced_constants.rb",
|
33
33
|
"other_namespace/referenced_types.rb"
|
34
34
|
].each do |name|
|
35
|
-
File.exist?(File.join(prefix, name)).
|
35
|
+
expect(File.exist?(File.join(prefix, name))).not_to be_truthy
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -44,19 +44,19 @@ describe 'generation' do
|
|
44
44
|
"referenced_constants.rb",
|
45
45
|
"referenced_types.rb"
|
46
46
|
].each do |name|
|
47
|
-
File.exist?(File.join(prefix, name)).
|
47
|
+
expect(File.exist?(File.join(prefix, name))).to be_truthy
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
51
|
it "has a service class in the right place" do
|
52
|
-
defined?(NamespacedSpecNamespace::NamespacedNonblockingService).
|
52
|
+
expect(defined?(NamespacedSpecNamespace::NamespacedNonblockingService)).to be_truthy
|
53
53
|
end
|
54
54
|
|
55
55
|
it "has a struct in the right place" do
|
56
|
-
defined?(NamespacedSpecNamespace::Hello).
|
56
|
+
expect(defined?(NamespacedSpecNamespace::Hello)).to be_truthy
|
57
57
|
end
|
58
58
|
|
59
59
|
it "required an included file" do
|
60
|
-
defined?(OtherNamespace::SomeEnum).
|
60
|
+
expect(defined?(OtherNamespace::SomeEnum)).to be_truthy
|
61
61
|
end
|
62
62
|
end
|
data/spec/http_client_spec.rb
CHANGED
@@ -25,28 +25,33 @@ describe 'Thrift::HTTPClientTransport' do
|
|
25
25
|
before(:each) do
|
26
26
|
@client = Thrift::HTTPClientTransport.new("http://my.domain.com/path/to/service?param=value")
|
27
27
|
end
|
28
|
+
|
29
|
+
it "should provide a reasonable to_s" do
|
30
|
+
@client.to_s == "http://my.domain.com/path/to/service?param=value"
|
31
|
+
end
|
28
32
|
|
29
33
|
it "should always be open" do
|
30
|
-
@client.
|
34
|
+
expect(@client).to be_open
|
31
35
|
@client.close
|
32
|
-
@client.
|
36
|
+
expect(@client).to be_open
|
33
37
|
end
|
34
38
|
|
35
39
|
it "should post via HTTP and return the results" do
|
36
40
|
@client.write "a test"
|
37
41
|
@client.write " frame"
|
38
|
-
Net::HTTP.
|
39
|
-
|
40
|
-
http.
|
41
|
-
http.
|
42
|
-
|
43
|
-
response.
|
42
|
+
expect(Net::HTTP).to receive(:new).with("my.domain.com", 80) do
|
43
|
+
double("Net::HTTP").tap do |http|
|
44
|
+
expect(http).to receive(:use_ssl=).with(false)
|
45
|
+
expect(http).to receive(:post).with("/path/to/service?param=value", "a test frame", {"Content-Type"=>"application/x-thrift"}) do
|
46
|
+
double("Net::HTTPOK").tap do |response|
|
47
|
+
expect(response).to receive(:body).and_return "data"
|
48
|
+
expect(response).to receive(:code).and_return "200"
|
44
49
|
end
|
45
50
|
end
|
46
51
|
end
|
47
52
|
end
|
48
53
|
@client.flush
|
49
|
-
@client.read(10).
|
54
|
+
expect(@client.read(10)).to eq("data")
|
50
55
|
end
|
51
56
|
|
52
57
|
it "should send custom headers if defined" do
|
@@ -55,12 +60,13 @@ describe 'Thrift::HTTPClientTransport' do
|
|
55
60
|
headers = {"Content-Type"=>"application/x-thrift"}.merge(custom_headers)
|
56
61
|
|
57
62
|
@client.add_headers(custom_headers)
|
58
|
-
Net::HTTP.
|
59
|
-
|
60
|
-
http.
|
61
|
-
http.
|
62
|
-
|
63
|
-
response.
|
63
|
+
expect(Net::HTTP).to receive(:new).with("my.domain.com", 80) do
|
64
|
+
double("Net::HTTP").tap do |http|
|
65
|
+
expect(http).to receive(:use_ssl=).with(false)
|
66
|
+
expect(http).to receive(:post).with("/path/to/service?param=value", "test", headers) do
|
67
|
+
double("Net::HTTPOK").tap do |response|
|
68
|
+
expect(response).to receive(:body).and_return "data"
|
69
|
+
expect(response).to receive(:code).and_return "200"
|
64
70
|
end
|
65
71
|
end
|
66
72
|
end
|
@@ -71,15 +77,33 @@ describe 'Thrift::HTTPClientTransport' do
|
|
71
77
|
it 'should reset the outbuf on HTTP failures' do
|
72
78
|
@client.write "test"
|
73
79
|
|
74
|
-
Net::HTTP.
|
75
|
-
|
76
|
-
http.
|
77
|
-
http.
|
80
|
+
expect(Net::HTTP).to receive(:new).with("my.domain.com", 80) do
|
81
|
+
double("Net::HTTP").tap do |http|
|
82
|
+
expect(http).to receive(:use_ssl=).with(false)
|
83
|
+
expect(http).to receive(:post).with("/path/to/service?param=value", "test", {"Content-Type"=>"application/x-thrift"}) { raise Net::ReadTimeout }
|
78
84
|
end
|
79
85
|
end
|
80
86
|
|
81
87
|
@client.flush rescue
|
82
|
-
@client.instance_variable_get(:@outbuf).
|
88
|
+
expect(@client.instance_variable_get(:@outbuf)).to eq(Thrift::Bytes.empty_byte_buffer)
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should raise TransportError on HTTP failures' do
|
92
|
+
@client.write "test"
|
93
|
+
|
94
|
+
expect(Net::HTTP).to receive(:new).with("my.domain.com", 80) do
|
95
|
+
double("Net::HTTP").tap do |http|
|
96
|
+
expect(http).to receive(:use_ssl=).with(false)
|
97
|
+
expect(http).to receive(:post).with("/path/to/service?param=value", "test", {"Content-Type"=>"application/x-thrift"}) do
|
98
|
+
double("Net::HTTPOK").tap do |response|
|
99
|
+
expect(response).not_to receive(:body)
|
100
|
+
expect(response).to receive(:code).at_least(:once).and_return "503"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
expect { @client.flush }.to raise_error(Thrift::TransportException)
|
83
107
|
end
|
84
108
|
|
85
109
|
end
|
@@ -95,20 +119,21 @@ describe 'Thrift::HTTPClientTransport' do
|
|
95
119
|
|
96
120
|
client.write "test"
|
97
121
|
|
98
|
-
Net::HTTP.
|
99
|
-
|
100
|
-
http.
|
101
|
-
http.
|
102
|
-
http.
|
103
|
-
"Content-Type" => "application/x-thrift")
|
104
|
-
|
105
|
-
response.
|
122
|
+
expect(Net::HTTP).to receive(:new).with("my.domain.com", 443) do
|
123
|
+
double("Net::HTTP").tap do |http|
|
124
|
+
expect(http).to receive(:use_ssl=).with(true)
|
125
|
+
expect(http).to receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_PEER)
|
126
|
+
expect(http).to receive(:post).with(@service_path, "test",
|
127
|
+
"Content-Type" => "application/x-thrift") do
|
128
|
+
double("Net::HTTPOK").tap do |response|
|
129
|
+
expect(response).to receive(:body).and_return "data"
|
130
|
+
expect(response).to receive(:code).and_return "200"
|
106
131
|
end
|
107
132
|
end
|
108
133
|
end
|
109
134
|
end
|
110
135
|
client.flush
|
111
|
-
client.read(4).
|
136
|
+
expect(client.read(4)).to eq("data")
|
112
137
|
end
|
113
138
|
|
114
139
|
it "should set SSL verify mode when specified" do
|
@@ -116,20 +141,21 @@ describe 'Thrift::HTTPClientTransport' do
|
|
116
141
|
:ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE)
|
117
142
|
|
118
143
|
client.write "test"
|
119
|
-
Net::HTTP.
|
120
|
-
|
121
|
-
http.
|
122
|
-
http.
|
123
|
-
http.
|
124
|
-
"Content-Type" => "application/x-thrift")
|
125
|
-
|
126
|
-
response.
|
144
|
+
expect(Net::HTTP).to receive(:new).with("my.domain.com", 443) do
|
145
|
+
double("Net::HTTP").tap do |http|
|
146
|
+
expect(http).to receive(:use_ssl=).with(true)
|
147
|
+
expect(http).to receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
|
148
|
+
expect(http).to receive(:post).with(@service_path, "test",
|
149
|
+
"Content-Type" => "application/x-thrift") do
|
150
|
+
double("Net::HTTPOK").tap do |response|
|
151
|
+
expect(response).to receive(:body).and_return "data"
|
152
|
+
expect(response).to receive(:code).and_return "200"
|
127
153
|
end
|
128
154
|
end
|
129
155
|
end
|
130
156
|
end
|
131
157
|
client.flush
|
132
|
-
client.read(4).
|
158
|
+
expect(client.read(4)).to eq("data")
|
133
159
|
end
|
134
160
|
end
|
135
161
|
end
|
data/spec/json_protocol_spec.rb
CHANGED
@@ -30,257 +30,257 @@ describe 'JsonProtocol' do
|
|
30
30
|
|
31
31
|
it "should write json escaped char" do
|
32
32
|
@prot.write_json_escape_char("\n")
|
33
|
-
@trans.read(@trans.available).
|
33
|
+
expect(@trans.read(@trans.available)).to eq('\u000a')
|
34
34
|
|
35
35
|
@prot.write_json_escape_char(" ")
|
36
|
-
@trans.read(@trans.available).
|
36
|
+
expect(@trans.read(@trans.available)).to eq('\u0020')
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should write json char" do
|
40
40
|
@prot.write_json_char("\n")
|
41
|
-
@trans.read(@trans.available).
|
41
|
+
expect(@trans.read(@trans.available)).to eq('\\n')
|
42
42
|
|
43
43
|
@prot.write_json_char(" ")
|
44
|
-
@trans.read(@trans.available).
|
44
|
+
expect(@trans.read(@trans.available)).to eq(' ')
|
45
45
|
|
46
46
|
@prot.write_json_char("\\")
|
47
|
-
@trans.read(@trans.available).
|
47
|
+
expect(@trans.read(@trans.available)).to eq("\\\\")
|
48
48
|
|
49
49
|
@prot.write_json_char("@")
|
50
|
-
@trans.read(@trans.available).
|
50
|
+
expect(@trans.read(@trans.available)).to eq('@')
|
51
51
|
end
|
52
52
|
|
53
53
|
it "should write json string" do
|
54
54
|
@prot.write_json_string("this is a \\ json\nstring")
|
55
|
-
@trans.read(@trans.available).
|
55
|
+
expect(@trans.read(@trans.available)).to eq("\"this is a \\\\ json\\nstring\"")
|
56
56
|
end
|
57
57
|
|
58
58
|
it "should write json base64" do
|
59
59
|
@prot.write_json_base64("this is a base64 string")
|
60
|
-
@trans.read(@trans.available).
|
60
|
+
expect(@trans.read(@trans.available)).to eq("\"dGhpcyBpcyBhIGJhc2U2NCBzdHJpbmc=\"")
|
61
61
|
end
|
62
62
|
|
63
63
|
it "should write json integer" do
|
64
64
|
@prot.write_json_integer(45)
|
65
|
-
@trans.read(@trans.available).
|
65
|
+
expect(@trans.read(@trans.available)).to eq("45")
|
66
66
|
|
67
67
|
@prot.write_json_integer(33000)
|
68
|
-
@trans.read(@trans.available).
|
68
|
+
expect(@trans.read(@trans.available)).to eq("33000")
|
69
69
|
|
70
70
|
@prot.write_json_integer(3000000000)
|
71
|
-
@trans.read(@trans.available).
|
71
|
+
expect(@trans.read(@trans.available)).to eq("3000000000")
|
72
72
|
|
73
73
|
@prot.write_json_integer(6000000000)
|
74
|
-
@trans.read(@trans.available).
|
74
|
+
expect(@trans.read(@trans.available)).to eq("6000000000")
|
75
75
|
end
|
76
76
|
|
77
77
|
it "should write json double" do
|
78
78
|
@prot.write_json_double(12.3)
|
79
|
-
@trans.read(@trans.available).
|
79
|
+
expect(@trans.read(@trans.available)).to eq("12.3")
|
80
80
|
|
81
81
|
@prot.write_json_double(-3.21)
|
82
|
-
@trans.read(@trans.available).
|
82
|
+
expect(@trans.read(@trans.available)).to eq("-3.21")
|
83
83
|
|
84
84
|
@prot.write_json_double(((+1.0/0.0)/(+1.0/0.0)))
|
85
|
-
@trans.read(@trans.available).
|
85
|
+
expect(@trans.read(@trans.available)).to eq("\"NaN\"")
|
86
86
|
|
87
87
|
@prot.write_json_double((+1.0/0.0))
|
88
|
-
@trans.read(@trans.available).
|
88
|
+
expect(@trans.read(@trans.available)).to eq("\"Infinity\"")
|
89
89
|
|
90
90
|
@prot.write_json_double((-1.0/0.0))
|
91
|
-
@trans.read(@trans.available).
|
91
|
+
expect(@trans.read(@trans.available)).to eq("\"-Infinity\"")
|
92
92
|
end
|
93
93
|
|
94
94
|
it "should write json object start" do
|
95
95
|
@prot.write_json_object_start
|
96
|
-
@trans.read(@trans.available).
|
96
|
+
expect(@trans.read(@trans.available)).to eq("{")
|
97
97
|
end
|
98
98
|
|
99
99
|
it "should write json object end" do
|
100
100
|
@prot.write_json_object_end
|
101
|
-
@trans.read(@trans.available).
|
101
|
+
expect(@trans.read(@trans.available)).to eq("}")
|
102
102
|
end
|
103
103
|
|
104
104
|
it "should write json array start" do
|
105
105
|
@prot.write_json_array_start
|
106
|
-
@trans.read(@trans.available).
|
106
|
+
expect(@trans.read(@trans.available)).to eq("[")
|
107
107
|
end
|
108
108
|
|
109
109
|
it "should write json array end" do
|
110
110
|
@prot.write_json_array_end
|
111
|
-
@trans.read(@trans.available).
|
111
|
+
expect(@trans.read(@trans.available)).to eq("]")
|
112
112
|
end
|
113
113
|
|
114
114
|
it "should write message begin" do
|
115
115
|
@prot.write_message_begin("name", 12, 32)
|
116
|
-
@trans.read(@trans.available).
|
116
|
+
expect(@trans.read(@trans.available)).to eq("[1,\"name\",12,32")
|
117
117
|
end
|
118
118
|
|
119
119
|
it "should write message end" do
|
120
120
|
@prot.write_message_end
|
121
|
-
@trans.read(@trans.available).
|
121
|
+
expect(@trans.read(@trans.available)).to eq("]")
|
122
122
|
end
|
123
123
|
|
124
124
|
it "should write struct begin" do
|
125
125
|
@prot.write_struct_begin("name")
|
126
|
-
@trans.read(@trans.available).
|
126
|
+
expect(@trans.read(@trans.available)).to eq("{")
|
127
127
|
end
|
128
128
|
|
129
129
|
it "should write struct end" do
|
130
130
|
@prot.write_struct_end
|
131
|
-
@trans.read(@trans.available).
|
131
|
+
expect(@trans.read(@trans.available)).to eq("}")
|
132
132
|
end
|
133
133
|
|
134
134
|
it "should write field begin" do
|
135
135
|
@prot.write_field_begin("name", Thrift::Types::STRUCT, 32)
|
136
|
-
@trans.read(@trans.available).
|
136
|
+
expect(@trans.read(@trans.available)).to eq("32{\"rec\"")
|
137
137
|
end
|
138
138
|
|
139
139
|
it "should write field end" do
|
140
140
|
@prot.write_field_end
|
141
|
-
@trans.read(@trans.available).
|
141
|
+
expect(@trans.read(@trans.available)).to eq("}")
|
142
142
|
end
|
143
143
|
|
144
144
|
it "should write field stop" do
|
145
145
|
@prot.write_field_stop
|
146
|
-
@trans.read(@trans.available).
|
146
|
+
expect(@trans.read(@trans.available)).to eq("")
|
147
147
|
end
|
148
148
|
|
149
149
|
it "should write map begin" do
|
150
150
|
@prot.write_map_begin(Thrift::Types::STRUCT, Thrift::Types::LIST, 32)
|
151
|
-
@trans.read(@trans.available).
|
151
|
+
expect(@trans.read(@trans.available)).to eq("[\"rec\",\"lst\",32,{")
|
152
152
|
end
|
153
153
|
|
154
154
|
it "should write map end" do
|
155
155
|
@prot.write_map_end
|
156
|
-
@trans.read(@trans.available).
|
156
|
+
expect(@trans.read(@trans.available)).to eq("}]")
|
157
157
|
end
|
158
158
|
|
159
159
|
it "should write list begin" do
|
160
160
|
@prot.write_list_begin(Thrift::Types::STRUCT, 32)
|
161
|
-
@trans.read(@trans.available).
|
161
|
+
expect(@trans.read(@trans.available)).to eq("[\"rec\",32")
|
162
162
|
end
|
163
163
|
|
164
164
|
it "should write list end" do
|
165
165
|
@prot.write_list_end
|
166
|
-
@trans.read(@trans.available).
|
166
|
+
expect(@trans.read(@trans.available)).to eq("]")
|
167
167
|
end
|
168
168
|
|
169
169
|
it "should write set begin" do
|
170
170
|
@prot.write_set_begin(Thrift::Types::STRUCT, 32)
|
171
|
-
@trans.read(@trans.available).
|
171
|
+
expect(@trans.read(@trans.available)).to eq("[\"rec\",32")
|
172
172
|
end
|
173
173
|
|
174
174
|
it "should write set end" do
|
175
175
|
@prot.write_set_end
|
176
|
-
@trans.read(@trans.available).
|
176
|
+
expect(@trans.read(@trans.available)).to eq("]")
|
177
177
|
end
|
178
178
|
|
179
179
|
it "should write bool" do
|
180
180
|
@prot.write_bool(true)
|
181
|
-
@trans.read(@trans.available).
|
181
|
+
expect(@trans.read(@trans.available)).to eq("1")
|
182
182
|
|
183
183
|
@prot.write_bool(false)
|
184
|
-
@trans.read(@trans.available).
|
184
|
+
expect(@trans.read(@trans.available)).to eq("0")
|
185
185
|
end
|
186
186
|
|
187
187
|
it "should write byte" do
|
188
188
|
@prot.write_byte(100)
|
189
|
-
@trans.read(@trans.available).
|
189
|
+
expect(@trans.read(@trans.available)).to eq("100")
|
190
190
|
end
|
191
191
|
|
192
192
|
it "should write i16" do
|
193
193
|
@prot.write_i16(1000)
|
194
|
-
@trans.read(@trans.available).
|
194
|
+
expect(@trans.read(@trans.available)).to eq("1000")
|
195
195
|
end
|
196
196
|
|
197
197
|
it "should write i32" do
|
198
198
|
@prot.write_i32(3000000000)
|
199
|
-
@trans.read(@trans.available).
|
199
|
+
expect(@trans.read(@trans.available)).to eq("3000000000")
|
200
200
|
end
|
201
201
|
|
202
202
|
it "should write i64" do
|
203
203
|
@prot.write_i64(6000000000)
|
204
|
-
@trans.read(@trans.available).
|
204
|
+
expect(@trans.read(@trans.available)).to eq("6000000000")
|
205
205
|
end
|
206
206
|
|
207
207
|
it "should write double" do
|
208
208
|
@prot.write_double(1.23)
|
209
|
-
@trans.read(@trans.available).
|
209
|
+
expect(@trans.read(@trans.available)).to eq("1.23")
|
210
210
|
|
211
211
|
@prot.write_double(-32.1)
|
212
|
-
@trans.read(@trans.available).
|
212
|
+
expect(@trans.read(@trans.available)).to eq("-32.1")
|
213
213
|
|
214
214
|
@prot.write_double(((+1.0/0.0)/(+1.0/0.0)))
|
215
|
-
@trans.read(@trans.available).
|
215
|
+
expect(@trans.read(@trans.available)).to eq("\"NaN\"")
|
216
216
|
|
217
217
|
@prot.write_double((+1.0/0.0))
|
218
|
-
@trans.read(@trans.available).
|
218
|
+
expect(@trans.read(@trans.available)).to eq("\"Infinity\"")
|
219
219
|
|
220
220
|
@prot.write_double((-1.0/0.0))
|
221
|
-
@trans.read(@trans.available).
|
221
|
+
expect(@trans.read(@trans.available)).to eq("\"-Infinity\"")
|
222
222
|
end
|
223
223
|
|
224
224
|
if RUBY_VERSION >= '1.9'
|
225
225
|
it 'should write string' do
|
226
226
|
@prot.write_string('this is a test string')
|
227
227
|
a = @trans.read(@trans.available)
|
228
|
-
a.
|
229
|
-
a.encoding.
|
228
|
+
expect(a).to eq('"this is a test string"'.force_encoding(Encoding::BINARY))
|
229
|
+
expect(a.encoding).to eq(Encoding::BINARY)
|
230
230
|
end
|
231
231
|
|
232
232
|
it 'should write string with unicode characters' do
|
233
233
|
@prot.write_string("this is a test string with unicode characters: \u20AC \u20AD")
|
234
234
|
a = @trans.read(@trans.available)
|
235
|
-
a.
|
236
|
-
a.encoding.
|
235
|
+
expect(a).to eq("\"this is a test string with unicode characters: \u20AC \u20AD\"".force_encoding(Encoding::BINARY))
|
236
|
+
expect(a.encoding).to eq(Encoding::BINARY)
|
237
237
|
end
|
238
238
|
else
|
239
239
|
it 'should write string' do
|
240
240
|
@prot.write_string('this is a test string')
|
241
|
-
@trans.read(@trans.available).
|
241
|
+
expect(@trans.read(@trans.available)).to eq('"this is a test string"')
|
242
242
|
end
|
243
243
|
end
|
244
244
|
|
245
245
|
it "should write binary" do
|
246
246
|
@prot.write_binary("this is a base64 string")
|
247
|
-
@trans.read(@trans.available).
|
247
|
+
expect(@trans.read(@trans.available)).to eq("\"dGhpcyBpcyBhIGJhc2U2NCBzdHJpbmc=\"")
|
248
248
|
end
|
249
249
|
|
250
250
|
it "should write long binary" do
|
251
251
|
@prot.write_binary((0...256).to_a.pack('C*'))
|
252
|
-
@trans.read(@trans.available).
|
252
|
+
expect(@trans.read(@trans.available)).to eq("\"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==\"")
|
253
253
|
end
|
254
254
|
|
255
255
|
it "should get type name for type id" do
|
256
256
|
expect {@prot.get_type_name_for_type_id(Thrift::Types::STOP)}.to raise_error(NotImplementedError)
|
257
257
|
expect {@prot.get_type_name_for_type_id(Thrift::Types::VOID)}.to raise_error(NotImplementedError)
|
258
|
-
@prot.get_type_name_for_type_id(Thrift::Types::BOOL).
|
259
|
-
@prot.get_type_name_for_type_id(Thrift::Types::BYTE).
|
260
|
-
@prot.get_type_name_for_type_id(Thrift::Types::DOUBLE).
|
261
|
-
@prot.get_type_name_for_type_id(Thrift::Types::I16).
|
262
|
-
@prot.get_type_name_for_type_id(Thrift::Types::I32).
|
263
|
-
@prot.get_type_name_for_type_id(Thrift::Types::I64).
|
264
|
-
@prot.get_type_name_for_type_id(Thrift::Types::STRING).
|
265
|
-
@prot.get_type_name_for_type_id(Thrift::Types::STRUCT).
|
266
|
-
@prot.get_type_name_for_type_id(Thrift::Types::MAP).
|
267
|
-
@prot.get_type_name_for_type_id(Thrift::Types::SET).
|
268
|
-
@prot.get_type_name_for_type_id(Thrift::Types::LIST).
|
258
|
+
expect(@prot.get_type_name_for_type_id(Thrift::Types::BOOL)).to eq("tf")
|
259
|
+
expect(@prot.get_type_name_for_type_id(Thrift::Types::BYTE)).to eq("i8")
|
260
|
+
expect(@prot.get_type_name_for_type_id(Thrift::Types::DOUBLE)).to eq("dbl")
|
261
|
+
expect(@prot.get_type_name_for_type_id(Thrift::Types::I16)).to eq("i16")
|
262
|
+
expect(@prot.get_type_name_for_type_id(Thrift::Types::I32)).to eq("i32")
|
263
|
+
expect(@prot.get_type_name_for_type_id(Thrift::Types::I64)).to eq("i64")
|
264
|
+
expect(@prot.get_type_name_for_type_id(Thrift::Types::STRING)).to eq("str")
|
265
|
+
expect(@prot.get_type_name_for_type_id(Thrift::Types::STRUCT)).to eq("rec")
|
266
|
+
expect(@prot.get_type_name_for_type_id(Thrift::Types::MAP)).to eq("map")
|
267
|
+
expect(@prot.get_type_name_for_type_id(Thrift::Types::SET)).to eq("set")
|
268
|
+
expect(@prot.get_type_name_for_type_id(Thrift::Types::LIST)).to eq("lst")
|
269
269
|
end
|
270
270
|
|
271
271
|
it "should get type id for type name" do
|
272
272
|
expect {@prot.get_type_id_for_type_name("pp")}.to raise_error(NotImplementedError)
|
273
|
-
@prot.get_type_id_for_type_name("tf").
|
274
|
-
@prot.get_type_id_for_type_name("i8").
|
275
|
-
@prot.get_type_id_for_type_name("dbl").
|
276
|
-
@prot.get_type_id_for_type_name("i16").
|
277
|
-
@prot.get_type_id_for_type_name("i32").
|
278
|
-
@prot.get_type_id_for_type_name("i64").
|
279
|
-
@prot.get_type_id_for_type_name("str").
|
280
|
-
@prot.get_type_id_for_type_name("rec").
|
281
|
-
@prot.get_type_id_for_type_name("map").
|
282
|
-
@prot.get_type_id_for_type_name("set").
|
283
|
-
@prot.get_type_id_for_type_name("lst").
|
273
|
+
expect(@prot.get_type_id_for_type_name("tf")).to eq(Thrift::Types::BOOL)
|
274
|
+
expect(@prot.get_type_id_for_type_name("i8")).to eq(Thrift::Types::BYTE)
|
275
|
+
expect(@prot.get_type_id_for_type_name("dbl")).to eq(Thrift::Types::DOUBLE)
|
276
|
+
expect(@prot.get_type_id_for_type_name("i16")).to eq(Thrift::Types::I16)
|
277
|
+
expect(@prot.get_type_id_for_type_name("i32")).to eq(Thrift::Types::I32)
|
278
|
+
expect(@prot.get_type_id_for_type_name("i64")).to eq(Thrift::Types::I64)
|
279
|
+
expect(@prot.get_type_id_for_type_name("str")).to eq(Thrift::Types::STRING)
|
280
|
+
expect(@prot.get_type_id_for_type_name("rec")).to eq(Thrift::Types::STRUCT)
|
281
|
+
expect(@prot.get_type_id_for_type_name("map")).to eq(Thrift::Types::MAP)
|
282
|
+
expect(@prot.get_type_id_for_type_name("set")).to eq(Thrift::Types::SET)
|
283
|
+
expect(@prot.get_type_id_for_type_name("lst")).to eq(Thrift::Types::LIST)
|
284
284
|
end
|
285
285
|
|
286
286
|
it "should read json syntax char" do
|
@@ -292,31 +292,31 @@ describe 'JsonProtocol' do
|
|
292
292
|
|
293
293
|
it "should read json escape char" do
|
294
294
|
@trans.write('0054')
|
295
|
-
@prot.read_json_escape_char.
|
295
|
+
expect(@prot.read_json_escape_char).to eq('T')
|
296
296
|
|
297
297
|
@trans.write("\"\\\"\"")
|
298
|
-
@prot.read_json_string(false).
|
298
|
+
expect(@prot.read_json_string(false)).to eq("\"")
|
299
299
|
|
300
300
|
@trans.write("\"\\\\\"")
|
301
|
-
@prot.read_json_string(false).
|
301
|
+
expect(@prot.read_json_string(false)).to eq("\\")
|
302
302
|
|
303
303
|
@trans.write("\"\\/\"")
|
304
|
-
@prot.read_json_string(false).
|
304
|
+
expect(@prot.read_json_string(false)).to eq("\/")
|
305
305
|
|
306
306
|
@trans.write("\"\\b\"")
|
307
|
-
@prot.read_json_string(false).
|
307
|
+
expect(@prot.read_json_string(false)).to eq("\b")
|
308
308
|
|
309
309
|
@trans.write("\"\\f\"")
|
310
|
-
@prot.read_json_string(false).
|
310
|
+
expect(@prot.read_json_string(false)).to eq("\f")
|
311
311
|
|
312
312
|
@trans.write("\"\\n\"")
|
313
|
-
@prot.read_json_string(false).
|
313
|
+
expect(@prot.read_json_string(false)).to eq("\n")
|
314
314
|
|
315
315
|
@trans.write("\"\\r\"")
|
316
|
-
@prot.read_json_string(false).
|
316
|
+
expect(@prot.read_json_string(false)).to eq("\r")
|
317
317
|
|
318
318
|
@trans.write("\"\\t\"")
|
319
|
-
@prot.read_json_string(false).
|
319
|
+
expect(@prot.read_json_string(false)).to eq("\t")
|
320
320
|
end
|
321
321
|
|
322
322
|
it "should read json string" do
|
@@ -324,36 +324,36 @@ describe 'JsonProtocol' do
|
|
324
324
|
expect {@prot.read_json_string(false)}.to raise_error(Thrift::ProtocolException)
|
325
325
|
|
326
326
|
@trans.write("\"this is a test string\"")
|
327
|
-
@prot.read_json_string.
|
327
|
+
expect(@prot.read_json_string).to eq("this is a test string")
|
328
328
|
end
|
329
329
|
|
330
330
|
it "should read json base64" do
|
331
331
|
@trans.write("\"dGhpcyBpcyBhIHRlc3Qgc3RyaW5n\"")
|
332
|
-
@prot.read_json_base64.
|
332
|
+
expect(@prot.read_json_base64).to eq("this is a test string")
|
333
333
|
end
|
334
334
|
|
335
335
|
it "should is json numeric" do
|
336
|
-
@prot.is_json_numeric("A").
|
337
|
-
@prot.is_json_numeric("+").
|
338
|
-
@prot.is_json_numeric("-").
|
339
|
-
@prot.is_json_numeric(".").
|
340
|
-
@prot.is_json_numeric("0").
|
341
|
-
@prot.is_json_numeric("1").
|
342
|
-
@prot.is_json_numeric("2").
|
343
|
-
@prot.is_json_numeric("3").
|
344
|
-
@prot.is_json_numeric("4").
|
345
|
-
@prot.is_json_numeric("5").
|
346
|
-
@prot.is_json_numeric("6").
|
347
|
-
@prot.is_json_numeric("7").
|
348
|
-
@prot.is_json_numeric("8").
|
349
|
-
@prot.is_json_numeric("9").
|
350
|
-
@prot.is_json_numeric("E").
|
351
|
-
@prot.is_json_numeric("e").
|
336
|
+
expect(@prot.is_json_numeric("A")).to eq(false)
|
337
|
+
expect(@prot.is_json_numeric("+")).to eq(true)
|
338
|
+
expect(@prot.is_json_numeric("-")).to eq(true)
|
339
|
+
expect(@prot.is_json_numeric(".")).to eq(true)
|
340
|
+
expect(@prot.is_json_numeric("0")).to eq(true)
|
341
|
+
expect(@prot.is_json_numeric("1")).to eq(true)
|
342
|
+
expect(@prot.is_json_numeric("2")).to eq(true)
|
343
|
+
expect(@prot.is_json_numeric("3")).to eq(true)
|
344
|
+
expect(@prot.is_json_numeric("4")).to eq(true)
|
345
|
+
expect(@prot.is_json_numeric("5")).to eq(true)
|
346
|
+
expect(@prot.is_json_numeric("6")).to eq(true)
|
347
|
+
expect(@prot.is_json_numeric("7")).to eq(true)
|
348
|
+
expect(@prot.is_json_numeric("8")).to eq(true)
|
349
|
+
expect(@prot.is_json_numeric("9")).to eq(true)
|
350
|
+
expect(@prot.is_json_numeric("E")).to eq(true)
|
351
|
+
expect(@prot.is_json_numeric("e")).to eq(true)
|
352
352
|
end
|
353
353
|
|
354
354
|
it "should read json numeric chars" do
|
355
355
|
@trans.write("1.453E45T")
|
356
|
-
@prot.read_json_numeric_chars.
|
356
|
+
expect(@prot.read_json_numeric_chars).to eq("1.453E45")
|
357
357
|
end
|
358
358
|
|
359
359
|
it "should read json integer" do
|
@@ -362,7 +362,7 @@ describe 'JsonProtocol' do
|
|
362
362
|
@prot.read_string
|
363
363
|
|
364
364
|
@trans.write("1453T")
|
365
|
-
@prot.read_json_integer.
|
365
|
+
expect(@prot.read_json_integer).to eq(1453)
|
366
366
|
end
|
367
367
|
|
368
368
|
it "should read json double" do
|
@@ -374,37 +374,37 @@ describe 'JsonProtocol' do
|
|
374
374
|
expect {@prot.read_json_double}.to raise_error(Thrift::ProtocolException)
|
375
375
|
|
376
376
|
@trans.write("1.453e01\"\"")
|
377
|
-
@prot.read_json_double.
|
377
|
+
expect(@prot.read_json_double).to eq(14.53)
|
378
378
|
@prot.read_string
|
379
379
|
|
380
380
|
@trans.write("\"NaN\"")
|
381
|
-
@prot.read_json_double.nan
|
381
|
+
expect(@prot.read_json_double.nan?).to eq(true)
|
382
382
|
|
383
383
|
@trans.write("\"Infinity\"")
|
384
|
-
@prot.read_json_double.
|
384
|
+
expect(@prot.read_json_double).to eq(+1.0/0.0)
|
385
385
|
|
386
386
|
@trans.write("\"-Infinity\"")
|
387
|
-
@prot.read_json_double.
|
387
|
+
expect(@prot.read_json_double).to eq(-1.0/0.0)
|
388
388
|
end
|
389
389
|
|
390
390
|
it "should read json object start" do
|
391
391
|
@trans.write("{")
|
392
|
-
@prot.read_json_object_start.
|
392
|
+
expect(@prot.read_json_object_start).to eq(nil)
|
393
393
|
end
|
394
394
|
|
395
395
|
it "should read json object end" do
|
396
396
|
@trans.write("}")
|
397
|
-
@prot.read_json_object_end.
|
397
|
+
expect(@prot.read_json_object_end).to eq(nil)
|
398
398
|
end
|
399
399
|
|
400
400
|
it "should read json array start" do
|
401
401
|
@trans.write("[")
|
402
|
-
@prot.read_json_array_start.
|
402
|
+
expect(@prot.read_json_array_start).to eq(nil)
|
403
403
|
end
|
404
404
|
|
405
405
|
it "should read json array end" do
|
406
406
|
@trans.write("]")
|
407
|
-
@prot.read_json_array_end.
|
407
|
+
expect(@prot.read_json_array_end).to eq(nil)
|
408
408
|
end
|
409
409
|
|
410
410
|
it "should read_message_begin" do
|
@@ -412,133 +412,141 @@ describe 'JsonProtocol' do
|
|
412
412
|
expect {@prot.read_message_begin}.to raise_error(Thrift::ProtocolException)
|
413
413
|
|
414
414
|
@trans.write("[1,\"name\",12,32\"\"")
|
415
|
-
@prot.read_message_begin.
|
415
|
+
expect(@prot.read_message_begin).to eq(["name", 12, 32])
|
416
416
|
end
|
417
417
|
|
418
418
|
it "should read message end" do
|
419
419
|
@trans.write("]")
|
420
|
-
@prot.read_message_end.
|
420
|
+
expect(@prot.read_message_end).to eq(nil)
|
421
421
|
end
|
422
422
|
|
423
423
|
it "should read struct begin" do
|
424
424
|
@trans.write("{")
|
425
|
-
@prot.read_struct_begin.
|
425
|
+
expect(@prot.read_struct_begin).to eq(nil)
|
426
426
|
end
|
427
427
|
|
428
428
|
it "should read struct end" do
|
429
429
|
@trans.write("}")
|
430
|
-
@prot.read_struct_end.
|
430
|
+
expect(@prot.read_struct_end).to eq(nil)
|
431
431
|
end
|
432
432
|
|
433
433
|
it "should read field begin" do
|
434
434
|
@trans.write("1{\"rec\"")
|
435
|
-
@prot.read_field_begin.
|
435
|
+
expect(@prot.read_field_begin).to eq([nil, 12, 1])
|
436
436
|
end
|
437
437
|
|
438
438
|
it "should read field end" do
|
439
439
|
@trans.write("}")
|
440
|
-
@prot.read_field_end.
|
440
|
+
expect(@prot.read_field_end).to eq(nil)
|
441
441
|
end
|
442
442
|
|
443
443
|
it "should read map begin" do
|
444
444
|
@trans.write("[\"rec\",\"lst\",2,{")
|
445
|
-
@prot.read_map_begin.
|
445
|
+
expect(@prot.read_map_begin).to eq([12, 15, 2])
|
446
446
|
end
|
447
447
|
|
448
448
|
it "should read map end" do
|
449
449
|
@trans.write("}]")
|
450
|
-
@prot.read_map_end.
|
450
|
+
expect(@prot.read_map_end).to eq(nil)
|
451
451
|
end
|
452
452
|
|
453
453
|
it "should read list begin" do
|
454
454
|
@trans.write("[\"rec\",2\"\"")
|
455
|
-
@prot.read_list_begin.
|
455
|
+
expect(@prot.read_list_begin).to eq([12, 2])
|
456
456
|
end
|
457
457
|
|
458
458
|
it "should read list end" do
|
459
459
|
@trans.write("]")
|
460
|
-
@prot.read_list_end.
|
460
|
+
expect(@prot.read_list_end).to eq(nil)
|
461
461
|
end
|
462
462
|
|
463
463
|
it "should read set begin" do
|
464
464
|
@trans.write("[\"rec\",2\"\"")
|
465
|
-
@prot.read_set_begin.
|
465
|
+
expect(@prot.read_set_begin).to eq([12, 2])
|
466
466
|
end
|
467
467
|
|
468
468
|
it "should read set end" do
|
469
469
|
@trans.write("]")
|
470
|
-
@prot.read_set_end.
|
470
|
+
expect(@prot.read_set_end).to eq(nil)
|
471
471
|
end
|
472
472
|
|
473
473
|
it "should read bool" do
|
474
474
|
@trans.write("0\"\"")
|
475
|
-
@prot.read_bool.
|
475
|
+
expect(@prot.read_bool).to eq(false)
|
476
476
|
@prot.read_string
|
477
477
|
|
478
478
|
@trans.write("1\"\"")
|
479
|
-
@prot.read_bool.
|
479
|
+
expect(@prot.read_bool).to eq(true)
|
480
480
|
end
|
481
481
|
|
482
482
|
it "should read byte" do
|
483
483
|
@trans.write("60\"\"")
|
484
|
-
@prot.read_byte.
|
484
|
+
expect(@prot.read_byte).to eq(60)
|
485
485
|
end
|
486
486
|
|
487
487
|
it "should read i16" do
|
488
488
|
@trans.write("1000\"\"")
|
489
|
-
@prot.read_i16.
|
489
|
+
expect(@prot.read_i16).to eq(1000)
|
490
490
|
end
|
491
491
|
|
492
492
|
it "should read i32" do
|
493
493
|
@trans.write("3000000000\"\"")
|
494
|
-
@prot.read_i32.
|
494
|
+
expect(@prot.read_i32).to eq(3000000000)
|
495
495
|
end
|
496
496
|
|
497
497
|
it "should read i64" do
|
498
498
|
@trans.write("6000000000\"\"")
|
499
|
-
@prot.read_i64.
|
499
|
+
expect(@prot.read_i64).to eq(6000000000)
|
500
500
|
end
|
501
501
|
|
502
502
|
it "should read double" do
|
503
503
|
@trans.write("12.23\"\"")
|
504
|
-
@prot.read_double.
|
504
|
+
expect(@prot.read_double).to eq(12.23)
|
505
505
|
end
|
506
506
|
|
507
507
|
if RUBY_VERSION >= '1.9'
|
508
508
|
it 'should read string' do
|
509
509
|
@trans.write('"this is a test string"'.force_encoding(Encoding::BINARY))
|
510
510
|
a = @prot.read_string
|
511
|
-
a.
|
512
|
-
a.encoding.
|
511
|
+
expect(a).to eq('this is a test string')
|
512
|
+
expect(a.encoding).to eq(Encoding::UTF_8)
|
513
513
|
end
|
514
514
|
|
515
515
|
it 'should read string with unicode characters' do
|
516
516
|
@trans.write('"this is a test string with unicode characters: \u20AC \u20AD"'.force_encoding(Encoding::BINARY))
|
517
517
|
a = @prot.read_string
|
518
|
-
a.
|
519
|
-
a.encoding.
|
518
|
+
expect(a).to eq("this is a test string with unicode characters: \u20AC \u20AD")
|
519
|
+
expect(a.encoding).to eq(Encoding::UTF_8)
|
520
520
|
end
|
521
521
|
else
|
522
522
|
it 'should read string' do
|
523
523
|
@trans.write('"this is a test string"')
|
524
|
-
@prot.read_string.
|
524
|
+
expect(@prot.read_string).to eq('this is a test string')
|
525
525
|
end
|
526
526
|
end
|
527
527
|
|
528
528
|
it "should read binary" do
|
529
529
|
@trans.write("\"dGhpcyBpcyBhIHRlc3Qgc3RyaW5n\"")
|
530
|
-
@prot.read_binary.
|
530
|
+
expect(@prot.read_binary).to eq("this is a test string")
|
531
531
|
end
|
532
532
|
|
533
533
|
it "should read long binary" do
|
534
534
|
@trans.write("\"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==\"")
|
535
|
-
@prot.read_binary.bytes.to_a.
|
535
|
+
expect(@prot.read_binary.bytes.to_a).to eq((0...256).to_a)
|
536
|
+
end
|
537
|
+
|
538
|
+
it "should provide a reasonable to_s" do
|
539
|
+
expect(@prot.to_s).to eq("json(memory)")
|
536
540
|
end
|
537
541
|
end
|
538
542
|
|
539
543
|
describe Thrift::JsonProtocolFactory do
|
540
544
|
it "should create a JsonProtocol" do
|
541
|
-
Thrift::JsonProtocolFactory.new.get_protocol(
|
545
|
+
expect(Thrift::JsonProtocolFactory.new.get_protocol(double("MockTransport"))).to be_instance_of(Thrift::JsonProtocol)
|
546
|
+
end
|
547
|
+
|
548
|
+
it "should provide a reasonable to_s" do
|
549
|
+
expect(Thrift::JsonProtocolFactory.new.to_s).to eq("json")
|
542
550
|
end
|
543
551
|
end
|
544
552
|
end
|