thrift 0.9.3.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/ext/struct.c +5 -1
  3. data/lib/thrift.rb +6 -4
  4. data/lib/thrift/processor.rb +10 -3
  5. data/lib/thrift/protocol/base_protocol.rb +11 -3
  6. data/lib/thrift/protocol/binary_protocol.rb +8 -1
  7. data/lib/thrift/protocol/binary_protocol_accelerated.rb +8 -0
  8. data/lib/thrift/protocol/compact_protocol.rb +8 -0
  9. data/lib/thrift/protocol/json_protocol.rb +21 -4
  10. data/lib/thrift/protocol/multiplexed_protocol.rb +5 -1
  11. data/lib/thrift/server/base_server.rb +8 -2
  12. data/lib/thrift/server/simple_server.rb +5 -1
  13. data/lib/thrift/server/thread_pool_server.rb +5 -1
  14. data/lib/thrift/server/threaded_server.rb +5 -1
  15. data/lib/thrift/transport/base_server_transport.rb +1 -1
  16. data/lib/thrift/transport/base_transport.rb +8 -0
  17. data/lib/thrift/transport/buffered_transport.rb +9 -1
  18. data/lib/thrift/transport/framed_transport.rb +9 -1
  19. data/lib/thrift/transport/http_client_transport.rb +7 -0
  20. data/lib/thrift/transport/io_stream_transport.rb +4 -1
  21. data/lib/thrift/transport/memory_buffer_transport.rb +4 -0
  22. data/lib/thrift/transport/server_socket.rb +6 -1
  23. data/lib/thrift/transport/socket.rb +21 -17
  24. data/lib/thrift/transport/ssl_server_socket.rb +41 -0
  25. data/lib/thrift/transport/ssl_socket.rb +51 -0
  26. data/lib/thrift/transport/unix_server_socket.rb +5 -1
  27. data/lib/thrift/transport/unix_socket.rb +5 -1
  28. data/spec/base_protocol_spec.rb +79 -71
  29. data/spec/base_transport_spec.rb +155 -117
  30. data/spec/binary_protocol_accelerated_spec.rb +6 -2
  31. data/spec/binary_protocol_spec.rb +16 -8
  32. data/spec/binary_protocol_spec_shared.rb +75 -72
  33. data/spec/bytes_spec.rb +38 -38
  34. data/spec/client_spec.rb +41 -42
  35. data/spec/compact_protocol_spec.rb +32 -17
  36. data/spec/exception_spec.rb +54 -54
  37. data/spec/flat_spec.rb +5 -5
  38. data/spec/http_client_spec.rb +74 -33
  39. data/spec/json_protocol_spec.rb +170 -131
  40. data/spec/namespaced_spec.rb +5 -5
  41. data/spec/nonblocking_server_spec.rb +16 -16
  42. data/spec/processor_spec.rb +26 -26
  43. data/spec/serializer_spec.rb +20 -20
  44. data/spec/server_socket_spec.rb +27 -22
  45. data/spec/server_spec.rb +91 -51
  46. data/spec/socket_spec.rb +23 -16
  47. data/spec/socket_spec_shared.rb +31 -31
  48. data/spec/spec_helper.rb +1 -1
  49. data/spec/ssl_server_socket_spec.rb +34 -0
  50. data/spec/ssl_socket_spec.rb +78 -0
  51. data/spec/struct_nested_containers_spec.rb +24 -24
  52. data/spec/struct_spec.rb +120 -120
  53. data/spec/thin_http_server_spec.rb +18 -18
  54. data/spec/types_spec.rb +56 -53
  55. data/spec/union_spec.rb +47 -41
  56. data/spec/unix_socket_spec.rb +43 -34
  57. metadata +184 -148
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)).should_not be_true
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)).should be_true
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).should be_true
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).should be_true
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).should be_true
60
+ expect(defined?(OtherNamespace::SomeEnum)).to be_truthy
61
61
  end
62
62
  end
@@ -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.should be_open
34
+ expect(@client).to be_open
31
35
  @client.close
32
- @client.should be_open
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.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"
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).should == "data"
54
+ expect(@client.read(10)).to eq("data")
50
55
  end
51
56
 
52
57
  it "should send custom headers if defined" do
@@ -55,18 +60,52 @@ 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.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"
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
67
73
  end
68
74
  @client.flush
69
75
  end
76
+
77
+ it 'should reset the outbuf on HTTP failures' do
78
+ @client.write "test"
79
+
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 }
84
+ end
85
+ end
86
+
87
+ @client.flush rescue
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)
107
+ end
108
+
70
109
  end
71
110
 
72
111
  describe 'ssl enabled' do
@@ -80,20 +119,21 @@ describe 'Thrift::HTTPClientTransport' do
80
119
 
81
120
  client.write "test"
82
121
 
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"
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"
91
131
  end
92
132
  end
93
133
  end
94
134
  end
95
135
  client.flush
96
- client.read(4).should == "data"
136
+ expect(client.read(4)).to eq("data")
97
137
  end
98
138
 
99
139
  it "should set SSL verify mode when specified" do
@@ -101,20 +141,21 @@ describe 'Thrift::HTTPClientTransport' do
101
141
  :ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE)
102
142
 
103
143
  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"
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"
112
153
  end
113
154
  end
114
155
  end
115
156
  end
116
157
  client.flush
117
- client.read(4).should == "data"
158
+ expect(client.read(4)).to eq("data")
118
159
  end
119
160
  end
120
161
  end
@@ -30,252 +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).should == '\u000a'
33
+ expect(@trans.read(@trans.available)).to eq('\u000a')
34
34
 
35
35
  @prot.write_json_escape_char(" ")
36
- @trans.read(@trans.available).should == '\u0020'
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).should == '\\n'
41
+ expect(@trans.read(@trans.available)).to eq('\\n')
42
42
 
43
43
  @prot.write_json_char(" ")
44
- @trans.read(@trans.available).should == ' '
44
+ expect(@trans.read(@trans.available)).to eq(' ')
45
45
 
46
46
  @prot.write_json_char("\\")
47
- @trans.read(@trans.available).should == "\\\\"
47
+ expect(@trans.read(@trans.available)).to eq("\\\\")
48
48
 
49
49
  @prot.write_json_char("@")
50
- @trans.read(@trans.available).should == '@'
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).should == "\"this is a \\\\ json\\nstring\""
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).should == "\"\"dGhpcyBpcyBhIGJhc2U2NCBzdHJpbmc=\\n\"\""
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).should == "45"
65
+ expect(@trans.read(@trans.available)).to eq("45")
66
66
 
67
67
  @prot.write_json_integer(33000)
68
- @trans.read(@trans.available).should == "33000"
68
+ expect(@trans.read(@trans.available)).to eq("33000")
69
69
 
70
70
  @prot.write_json_integer(3000000000)
71
- @trans.read(@trans.available).should == "3000000000"
71
+ expect(@trans.read(@trans.available)).to eq("3000000000")
72
72
 
73
73
  @prot.write_json_integer(6000000000)
74
- @trans.read(@trans.available).should == "6000000000"
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).should == "12.3"
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).should == "-3.21"
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).should == "\"NaN\""
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).should == "\"Infinity\""
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).should == "\"-Infinity\""
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).should == "{"
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).should == "}"
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).should == "["
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).should == "]"
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).should == "[1,\"name\",12,32"
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).should == "]"
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).should == "{"
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).should == "}"
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).should == "32{\"rec\""
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).should == "}"
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).should == ""
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).should == "[\"rec\",\"lst\",32,{"
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).should == "}]"
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).should == "[\"rec\",32"
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).should == "]"
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).should == "[\"rec\",32"
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).should == "]"
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).should == "1"
181
+ expect(@trans.read(@trans.available)).to eq("1")
182
182
 
183
183
  @prot.write_bool(false)
184
- @trans.read(@trans.available).should == "0"
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).should == "100"
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).should == "1000"
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).should == "3000000000"
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).should == "6000000000"
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).should == "1.23"
209
+ expect(@trans.read(@trans.available)).to eq("1.23")
210
210
 
211
211
  @prot.write_double(-32.1)
212
- @trans.read(@trans.available).should == "-32.1"
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).should == "\"NaN\""
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).should == "\"Infinity\""
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).should == "\"-Infinity\""
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.should == '"this is a test string"'.force_encoding(Encoding::BINARY)
229
- a.encoding.should == Encoding::BINARY
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.should == "\"this is a test string with unicode characters: \u20AC \u20AD\"".force_encoding(Encoding::BINARY)
236
- a.encoding.should == Encoding::BINARY
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).should == '"this is a test string"'
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).should == "\"\"dGhpcyBpcyBhIGJhc2U2NCBzdHJpbmc=\\n\"\""
247
+ expect(@trans.read(@trans.available)).to eq("\"dGhpcyBpcyBhIGJhc2U2NCBzdHJpbmc=\"")
248
+ end
249
+
250
+ it "should write long binary" do
251
+ @prot.write_binary((0...256).to_a.pack('C*'))
252
+ expect(@trans.read(@trans.available)).to eq("\"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==\"")
248
253
  end
249
254
 
250
255
  it "should get type name for type id" do
251
256
  expect {@prot.get_type_name_for_type_id(Thrift::Types::STOP)}.to raise_error(NotImplementedError)
252
257
  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"
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")
264
269
  end
265
270
 
266
271
  it "should get type id for type name" do
267
272
  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
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)
279
284
  end
280
285
 
281
286
  it "should read json syntax char" do
@@ -287,47 +292,68 @@ describe 'JsonProtocol' do
287
292
 
288
293
  it "should read json escape char" do
289
294
  @trans.write('0054')
290
- @prot.read_json_escape_char.should == 'T'
295
+ expect(@prot.read_json_escape_char).to eq('T')
296
+
297
+ @trans.write("\"\\\"\"")
298
+ expect(@prot.read_json_string(false)).to eq("\"")
299
+
300
+ @trans.write("\"\\\\\"")
301
+ expect(@prot.read_json_string(false)).to eq("\\")
302
+
303
+ @trans.write("\"\\/\"")
304
+ expect(@prot.read_json_string(false)).to eq("\/")
305
+
306
+ @trans.write("\"\\b\"")
307
+ expect(@prot.read_json_string(false)).to eq("\b")
308
+
309
+ @trans.write("\"\\f\"")
310
+ expect(@prot.read_json_string(false)).to eq("\f")
311
+
312
+ @trans.write("\"\\n\"")
313
+ expect(@prot.read_json_string(false)).to eq("\n")
314
+
315
+ @trans.write("\"\\r\"")
316
+ expect(@prot.read_json_string(false)).to eq("\r")
317
+
318
+ @trans.write("\"\\t\"")
319
+ expect(@prot.read_json_string(false)).to eq("\t")
291
320
  end
292
321
 
293
322
  it "should read json string" do
294
323
  @trans.write("\"\\P")
295
324
  expect {@prot.read_json_string(false)}.to raise_error(Thrift::ProtocolException)
296
325
 
297
- @trans.write("\"\\n\"")
298
- @prot.read_json_string(false).should == "\\n"
299
-
300
326
  @trans.write("\"this is a test string\"")
301
- @prot.read_json_string.should == "this is a test string"
327
+ expect(@prot.read_json_string).to eq("this is a test string")
302
328
  end
303
329
 
304
330
  it "should read json base64" do
305
331
  @trans.write("\"dGhpcyBpcyBhIHRlc3Qgc3RyaW5n\"")
306
- @prot.read_json_base64.should == "this is a test string"
332
+ expect(@prot.read_json_base64).to eq("this is a test string")
307
333
  end
308
334
 
309
335
  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
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)
326
352
  end
327
353
 
328
354
  it "should read json numeric chars" do
329
355
  @trans.write("1.453E45T")
330
- @prot.read_json_numeric_chars.should == "1.453E45"
356
+ expect(@prot.read_json_numeric_chars).to eq("1.453E45")
331
357
  end
332
358
 
333
359
  it "should read json integer" do
@@ -336,7 +362,7 @@ describe 'JsonProtocol' do
336
362
  @prot.read_string
337
363
 
338
364
  @trans.write("1453T")
339
- @prot.read_json_integer.should == 1453
365
+ expect(@prot.read_json_integer).to eq(1453)
340
366
  end
341
367
 
342
368
  it "should read json double" do
@@ -348,37 +374,37 @@ describe 'JsonProtocol' do
348
374
  expect {@prot.read_json_double}.to raise_error(Thrift::ProtocolException)
349
375
 
350
376
  @trans.write("1.453e01\"\"")
351
- @prot.read_json_double.should == 14.53
377
+ expect(@prot.read_json_double).to eq(14.53)
352
378
  @prot.read_string
353
379
 
354
380
  @trans.write("\"NaN\"")
355
- @prot.read_json_double.nan?.should == true
381
+ expect(@prot.read_json_double.nan?).to eq(true)
356
382
 
357
383
  @trans.write("\"Infinity\"")
358
- @prot.read_json_double.should == +1.0/0.0
384
+ expect(@prot.read_json_double).to eq(+1.0/0.0)
359
385
 
360
386
  @trans.write("\"-Infinity\"")
361
- @prot.read_json_double.should == -1.0/0.0
387
+ expect(@prot.read_json_double).to eq(-1.0/0.0)
362
388
  end
363
389
 
364
390
  it "should read json object start" do
365
391
  @trans.write("{")
366
- @prot.read_json_object_start.should == nil
392
+ expect(@prot.read_json_object_start).to eq(nil)
367
393
  end
368
394
 
369
395
  it "should read json object end" do
370
396
  @trans.write("}")
371
- @prot.read_json_object_end.should == nil
397
+ expect(@prot.read_json_object_end).to eq(nil)
372
398
  end
373
399
 
374
400
  it "should read json array start" do
375
401
  @trans.write("[")
376
- @prot.read_json_array_start.should == nil
402
+ expect(@prot.read_json_array_start).to eq(nil)
377
403
  end
378
404
 
379
405
  it "should read json array end" do
380
406
  @trans.write("]")
381
- @prot.read_json_array_end.should == nil
407
+ expect(@prot.read_json_array_end).to eq(nil)
382
408
  end
383
409
 
384
410
  it "should read_message_begin" do
@@ -386,128 +412,141 @@ describe 'JsonProtocol' do
386
412
  expect {@prot.read_message_begin}.to raise_error(Thrift::ProtocolException)
387
413
 
388
414
  @trans.write("[1,\"name\",12,32\"\"")
389
- @prot.read_message_begin.should == ["name", 12, 32]
415
+ expect(@prot.read_message_begin).to eq(["name", 12, 32])
390
416
  end
391
417
 
392
418
  it "should read message end" do
393
419
  @trans.write("]")
394
- @prot.read_message_end.should == nil
420
+ expect(@prot.read_message_end).to eq(nil)
395
421
  end
396
422
 
397
423
  it "should read struct begin" do
398
424
  @trans.write("{")
399
- @prot.read_struct_begin.should == nil
425
+ expect(@prot.read_struct_begin).to eq(nil)
400
426
  end
401
427
 
402
428
  it "should read struct end" do
403
429
  @trans.write("}")
404
- @prot.read_struct_end.should == nil
430
+ expect(@prot.read_struct_end).to eq(nil)
405
431
  end
406
432
 
407
433
  it "should read field begin" do
408
434
  @trans.write("1{\"rec\"")
409
- @prot.read_field_begin.should == [nil, 12, 1]
435
+ expect(@prot.read_field_begin).to eq([nil, 12, 1])
410
436
  end
411
437
 
412
438
  it "should read field end" do
413
439
  @trans.write("}")
414
- @prot.read_field_end.should == nil
440
+ expect(@prot.read_field_end).to eq(nil)
415
441
  end
416
442
 
417
443
  it "should read map begin" do
418
444
  @trans.write("[\"rec\",\"lst\",2,{")
419
- @prot.read_map_begin.should == [12, 15, 2]
445
+ expect(@prot.read_map_begin).to eq([12, 15, 2])
420
446
  end
421
447
 
422
448
  it "should read map end" do
423
449
  @trans.write("}]")
424
- @prot.read_map_end.should == nil
450
+ expect(@prot.read_map_end).to eq(nil)
425
451
  end
426
452
 
427
453
  it "should read list begin" do
428
454
  @trans.write("[\"rec\",2\"\"")
429
- @prot.read_list_begin.should == [12, 2]
455
+ expect(@prot.read_list_begin).to eq([12, 2])
430
456
  end
431
457
 
432
458
  it "should read list end" do
433
459
  @trans.write("]")
434
- @prot.read_list_end.should == nil
460
+ expect(@prot.read_list_end).to eq(nil)
435
461
  end
436
462
 
437
463
  it "should read set begin" do
438
464
  @trans.write("[\"rec\",2\"\"")
439
- @prot.read_set_begin.should == [12, 2]
465
+ expect(@prot.read_set_begin).to eq([12, 2])
440
466
  end
441
467
 
442
468
  it "should read set end" do
443
469
  @trans.write("]")
444
- @prot.read_set_end.should == nil
470
+ expect(@prot.read_set_end).to eq(nil)
445
471
  end
446
472
 
447
473
  it "should read bool" do
448
474
  @trans.write("0\"\"")
449
- @prot.read_bool.should == false
475
+ expect(@prot.read_bool).to eq(false)
450
476
  @prot.read_string
451
477
 
452
478
  @trans.write("1\"\"")
453
- @prot.read_bool.should == true
479
+ expect(@prot.read_bool).to eq(true)
454
480
  end
455
481
 
456
482
  it "should read byte" do
457
483
  @trans.write("60\"\"")
458
- @prot.read_byte.should == 60
484
+ expect(@prot.read_byte).to eq(60)
459
485
  end
460
486
 
461
487
  it "should read i16" do
462
488
  @trans.write("1000\"\"")
463
- @prot.read_i16.should == 1000
489
+ expect(@prot.read_i16).to eq(1000)
464
490
  end
465
491
 
466
492
  it "should read i32" do
467
493
  @trans.write("3000000000\"\"")
468
- @prot.read_i32.should == 3000000000
494
+ expect(@prot.read_i32).to eq(3000000000)
469
495
  end
470
496
 
471
497
  it "should read i64" do
472
498
  @trans.write("6000000000\"\"")
473
- @prot.read_i64.should == 6000000000
499
+ expect(@prot.read_i64).to eq(6000000000)
474
500
  end
475
501
 
476
502
  it "should read double" do
477
503
  @trans.write("12.23\"\"")
478
- @prot.read_double.should == 12.23
504
+ expect(@prot.read_double).to eq(12.23)
479
505
  end
480
506
 
481
507
  if RUBY_VERSION >= '1.9'
482
508
  it 'should read string' do
483
509
  @trans.write('"this is a test string"'.force_encoding(Encoding::BINARY))
484
510
  a = @prot.read_string
485
- a.should == 'this is a test string'
486
- a.encoding.should == Encoding::UTF_8
511
+ expect(a).to eq('this is a test string')
512
+ expect(a.encoding).to eq(Encoding::UTF_8)
487
513
  end
488
514
 
489
515
  it 'should read string with unicode characters' do
490
516
  @trans.write('"this is a test string with unicode characters: \u20AC \u20AD"'.force_encoding(Encoding::BINARY))
491
517
  a = @prot.read_string
492
- a.should == "this is a test string with unicode characters: \u20AC \u20AD"
493
- a.encoding.should == Encoding::UTF_8
518
+ expect(a).to eq("this is a test string with unicode characters: \u20AC \u20AD")
519
+ expect(a.encoding).to eq(Encoding::UTF_8)
494
520
  end
495
521
  else
496
522
  it 'should read string' do
497
523
  @trans.write('"this is a test string"')
498
- @prot.read_string.should == 'this is a test string'
524
+ expect(@prot.read_string).to eq('this is a test string')
499
525
  end
500
526
  end
501
527
 
502
528
  it "should read binary" do
503
529
  @trans.write("\"dGhpcyBpcyBhIHRlc3Qgc3RyaW5n\"")
504
- @prot.read_binary.should == "this is a test string"
530
+ expect(@prot.read_binary).to eq("this is a test string")
531
+ end
532
+
533
+ it "should read long binary" do
534
+ @trans.write("\"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==\"")
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)")
505
540
  end
506
541
  end
507
542
 
508
543
  describe Thrift::JsonProtocolFactory do
509
544
  it "should create a JsonProtocol" do
510
- Thrift::JsonProtocolFactory.new.get_protocol(mock("MockTransport")).should be_instance_of(Thrift::JsonProtocol)
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")
511
550
  end
512
551
  end
513
552
  end