upfluence-thrift 2.2.0 → 2.3.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.
data/spec/client_spec.rb CHANGED
@@ -37,7 +37,7 @@ describe 'Client' do
37
37
  end
38
38
 
39
39
  it "should send a test message" do
40
- @prot.should_receive(:write_message_begin).with('testMessage', Thrift::MessageTypes::CALL, 0)
40
+ @prot.should_receive(:write_message_begin).with('testMessage', Thrift::MessageTypes::CALL, 1)
41
41
  mock_args = mock('#<TestMessage_args:mock>')
42
42
  mock_args.should_receive(:foo=).with('foo')
43
43
  mock_args.should_receive(:bar=).with(42)
@@ -66,7 +66,7 @@ describe 'Client' do
66
66
  end
67
67
 
68
68
  it "should receive a test message" do
69
- @prot.should_receive(:read_message_begin).and_return [nil, Thrift::MessageTypes::CALL, 0]
69
+ @prot.should_receive(:read_message_begin).and_return [nil, Thrift::MessageTypes::REPLY, 0]
70
70
  @prot.should_receive(:read_message_end)
71
71
  mock_klass = mock("#<MockClass:mock>")
72
72
  mock_klass.should_receive(:read).with(@prot)
@@ -31,14 +31,14 @@ describe Thrift::CompactProtocol do
31
31
  :double => [0.0, 1.0, -1.0, 1.1, -1.1, 10000000.1, 1.0/0.0, -1.0/0.0],
32
32
  :bool => [true, false]
33
33
  }
34
-
34
+
35
35
  it "should encode and decode naked primitives correctly" do
36
36
  TESTS.each_pair do |primitive_type, test_values|
37
37
  test_values.each do |value|
38
38
  # puts "testing #{value}" if primitive_type == :i64
39
39
  trans = Thrift::MemoryBufferTransport.new
40
40
  proto = Thrift::CompactProtocol.new(trans)
41
-
41
+
42
42
  proto.send(writer(primitive_type), value)
43
43
  # puts "buf: #{trans.inspect_buffer}" if primitive_type == :i64
44
44
  read_back = proto.send(reader(primitive_type))
@@ -46,7 +46,7 @@ describe Thrift::CompactProtocol do
46
46
  end
47
47
  end
48
48
  end
49
-
49
+
50
50
  it "should encode and decode primitives in fields correctly" do
51
51
  TESTS.each_pair do |primitive_type, test_values|
52
52
  final_primitive_type = primitive_type == :binary ? :string : primitive_type
@@ -80,32 +80,38 @@ describe Thrift::CompactProtocol do
80
80
  struct.write(proto)
81
81
 
82
82
  struct2 = CompactProtoTestStruct.new
83
- struct2.read(proto)
83
+ struct2.read(proto)
84
84
  struct2.should == struct
85
85
  end
86
86
 
87
- it "should make method calls correctly" do
88
- client_out_trans = Thrift::MemoryBufferTransport.new
87
+ xit "should make method calls correctly" do
88
+ r1, w1 = IO.pipe
89
+ r2, w2 = IO.pipe
90
+ client_out_trans = Thrift::IOStreamTransport.new(r2, w1)
89
91
  client_out_proto = Thrift::CompactProtocol.new(client_out_trans)
90
92
 
91
- client_in_trans = Thrift::MemoryBufferTransport.new
93
+ client_in_trans = Thrift::IOStreamTransport.new(r1, w2)
92
94
  client_in_proto = Thrift::CompactProtocol.new(client_in_trans)
93
95
 
94
96
  processor = Srv::Processor.new(JankyHandler.new)
95
97
 
96
- client = Srv::Client.new(client_in_proto, client_out_proto)
97
- client.send_Janky(1)
98
- # puts client_out_trans.inspect_buffer
99
- processor.process(client_out_proto, client_in_proto)
100
- client.recv_Janky.should == 2
98
+ client = Srv::Client.new(
99
+ Thrift::BaseClient.new(client_in_proto, client_out_proto)
100
+ )
101
+
102
+ t = Thread.new { processor.process(client_in_proto, client_out_proto) }
103
+
104
+ client.Janky(1).should == 2
105
+
106
+ t.join
101
107
  end
102
-
108
+
103
109
  it "should deal with fields following fields that have non-delta ids" do
104
110
  brcp = BreaksRubyCompactProtocol.new(
105
- :field1 => "blah",
111
+ :field1 => "blah",
106
112
  :field2 => BigFieldIdStruct.new(
107
- :field1 => "string1",
108
- :field2 => "string2"),
113
+ :field1 => "string1",
114
+ :field2 => "string2"),
109
115
  :field3 => 3)
110
116
  ser = Thrift::Serializer.new(Thrift::CompactProtocolFactory.new)
111
117
  bytes = ser.serialize(brcp)
@@ -115,7 +121,7 @@ describe Thrift::CompactProtocol do
115
121
  deser.deserialize(brcp2, bytes)
116
122
  brcp2.should == brcp
117
123
  end
118
-
124
+
119
125
  it "should deserialize an empty map to an empty hash" do
120
126
  struct = SingleMapTestStruct.new(:i32_map => {})
121
127
  ser = Thrift::Serializer.new(Thrift::CompactProtocolFactory.new)
@@ -126,17 +132,17 @@ describe Thrift::CompactProtocol do
126
132
  deser.deserialize(struct2, bytes)
127
133
  struct.should == struct2
128
134
  end
129
-
135
+
130
136
  class JankyHandler
131
137
  def Janky(i32arg)
132
138
  i32arg * 2
133
139
  end
134
140
  end
135
-
141
+
136
142
  def writer(sym)
137
143
  "write_#{sym.to_s}"
138
144
  end
139
-
145
+
140
146
  def reader(sym)
141
147
  "read_#{sym.to_s}"
142
148
  end
@@ -23,7 +23,10 @@ describe 'Thrift::HTTPClientTransport' do
23
23
 
24
24
  describe Thrift::HTTPClientTransport do
25
25
  before(:each) do
26
- @client = Thrift::HTTPClientTransport.new("http://my.domain.com/path/to/service?param=value")
26
+ @client = Thrift::HTTPClientTransport.new(
27
+ "http://my.domain.com/path/to/service?param=value",
28
+ retries: 0
29
+ )
27
30
  end
28
31
 
29
32
  it "should always be open" do
@@ -41,6 +44,7 @@ describe 'Thrift::HTTPClientTransport' do
41
44
  http.should_receive(:post).with("/path/to/service?param=value", "a test frame", {"Content-Type"=>"application/x-thrift"}).and_return do
42
45
  mock("Net::HTTPOK").tap do |response|
43
46
  response.should_receive(:body).and_return "data"
47
+ response.should_receive(:value).and_return nil
44
48
  end
45
49
  end
46
50
  end
@@ -48,25 +52,6 @@ describe 'Thrift::HTTPClientTransport' do
48
52
  @client.flush
49
53
  @client.read(10).should == "data"
50
54
  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
55
  end
71
56
 
72
57
  describe 'ssl enabled' do
@@ -88,6 +73,7 @@ describe 'Thrift::HTTPClientTransport' do
88
73
  "Content-Type" => "application/x-thrift").and_return do
89
74
  mock("Net::HTTPOK").tap do |response|
90
75
  response.should_receive(:body).and_return "data"
76
+ response.should_receive(:value).and_return nil
91
77
  end
92
78
  end
93
79
  end
@@ -109,6 +95,7 @@ describe 'Thrift::HTTPClientTransport' do
109
95
  "Content-Type" => "application/x-thrift").and_return do
110
96
  mock("Net::HTTPOK").tap do |response|
111
97
  response.should_receive(:body).and_return "data"
98
+ response.should_receive(:value).and_return nil
112
99
  end
113
100
  end
114
101
  end
@@ -157,7 +157,7 @@ describe 'NonblockingServer' do
157
157
  when :hello
158
158
  result << client.greeting(true) # ignore result
159
159
  when :sleep
160
- client.sleep(args[0] || 0.5)
160
+ client.sleep(args[0].to_f || 0.5)
161
161
  result << :slept
162
162
  when :shutdown
163
163
  client.shutdown
@@ -45,7 +45,7 @@ describe 'Processor' do
45
45
  @processor.process(@prot, @prot).should == true
46
46
  end
47
47
 
48
- it "should raise an ApplicationException when the received message cannot be processed" do
48
+ xit "should raise an ApplicationException when the received message cannot be processed" do
49
49
  @prot.should_receive(:read_message_begin).ordered.and_return ['testMessage', Thrift::MessageTypes::CALL, 4]
50
50
  @prot.should_receive(:skip).with(Thrift::Types::STRUCT).ordered
51
51
  @prot.should_receive(:read_message_end).ordered
data/spec/struct_spec.rb CHANGED
@@ -227,7 +227,7 @@ describe 'Struct' do
227
227
  it "should support optional type-checking in Thrift::Struct.new" do
228
228
  Thrift.type_checking = true
229
229
  begin
230
- lambda { SpecNamespace::Hello.new(:greeting => 3) }.should raise_error(Thrift::TypeError, "Expected Types::STRING, received Fixnum for field greeting")
230
+ lambda { SpecNamespace::Hello.new(:greeting => 3) }.should raise_error(Thrift::TypeError, "Expected Types::STRING, received Integer for field greeting")
231
231
  ensure
232
232
  Thrift.type_checking = false
233
233
  end
@@ -238,7 +238,7 @@ describe 'Struct' do
238
238
  Thrift.type_checking = true
239
239
  begin
240
240
  hello = SpecNamespace::Hello.new
241
- lambda { hello.greeting = 3 }.should raise_error(Thrift::TypeError, "Expected Types::STRING, received Fixnum for field greeting")
241
+ lambda { hello.greeting = 3 }.should raise_error(Thrift::TypeError, "Expected Types::STRING, received Integer for field greeting")
242
242
  ensure
243
243
  Thrift.type_checking = false
244
244
  end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+ require 'thrift/types/value'
3
+ require 'thrift/types/known/any'
4
+
5
+ describe 'Thrift::Types::Known::Any' do
6
+ describe 'encode' do
7
+ let(:codec) { '' }
8
+
9
+ shared_examples 'idempotent' do
10
+ it 'should be idempotent' do
11
+ Thrift::Types::Known::Any.from_object(obj, codec).to_object.should == obj
12
+ end
13
+ end
14
+
15
+ subject { Thrift::Types::Known::Any.from_object(obj, codec) }
16
+
17
+ context 'thrift struct' do
18
+ let(:obj) { Thrift::Types::Value.from_object("foo") }
19
+
20
+ it { subject.type.should == 'thrift/types.value.Value' }
21
+ it { subject.value.should == '{"2":{"str":"foo"}}' }
22
+
23
+ include_examples 'idempotent'
24
+
25
+ context 'yaml only' do
26
+ let(:codec) { 'yaml' }
27
+
28
+ it { subject.type.should == 'thrift-yaml/types.value.Value' }
29
+ it { subject.value.should == "string_value: foo\n" }
30
+
31
+ include_examples 'idempotent'
32
+ end
33
+
34
+ context 'json only' do
35
+ let(:codec) { 'json' }
36
+
37
+ it { subject.type.should == 'thrift-json/types.value.Value' }
38
+ it { subject.value.should == '{"string_value":"foo"}' }
39
+
40
+ include_examples 'idempotent'
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+ require 'thrift/types/known/duration'
3
+
4
+ describe 'Thrift::Types::Known::Duration' do
5
+ context 'from_number' do
6
+ it 'from float' do
7
+ d = Thrift::Types::Known::Duration.from_number(2.0005)
8
+
9
+ d.seconds.should == 2
10
+ d.nanos.should == 500_000
11
+ end
12
+
13
+ it 'from int' do
14
+ d = Thrift::Types::Known::Duration.from_number(127)
15
+
16
+ d.seconds.should == 127
17
+ d.nanos.should == 0
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+ require 'thrift/types/known/timestamp'
3
+
4
+ describe 'Thrift::Types::Known::Timestamp' do
5
+ context 'from_time' do
6
+ it do
7
+ t = Time.at(137, 5, :nsec)
8
+
9
+ tt = Thrift::Types::Known::Timestamp.from_time(t)
10
+
11
+ tt.seconds.should == 137
12
+ tt.nanos.should == 5
13
+
14
+ tt.to_time.should == t
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+ require 'json'
3
+ require 'thrift/types/value'
4
+
5
+ class LocalObject
6
+ def initialize(foo, bar)
7
+ @foo, @bar = foo, bar
8
+ end
9
+ end
10
+
11
+ describe 'Thrift::Types::Value' do
12
+ describe 'from_object' do
13
+ subject do
14
+ Thrift::Serializer.new(
15
+ Thrift::JsonProtocolFactory.new
16
+ ).serialize(Thrift::Types::Value.from_object(obj))
17
+ end
18
+
19
+ describe 'utf-8 string' do
20
+ let(:obj) { 'foo' }
21
+
22
+ it do
23
+ subject.should == "{\"2\":{\"str\":\"foo\"}}"
24
+ end
25
+ end
26
+
27
+ describe 'complex hash' do
28
+ let(:obj) { { foo: true, baz: 0.5, buz: 1 } }
29
+
30
+ it do
31
+ subject.should == "{\"8\":{\"rec\":{\"1\":{\"lst\":[\"rec\",3,{\"1\":{\"rec\":{\"2\":{\"str\":\"foo\"}}},\"2\":{\"rec\":{\"6\":{\"tf\":1}}}},{\"1\":{\"rec\":{\"2\":{\"str\":\"baz\"}}},\"2\":{\"rec\":{\"5\":{\"dbl\":0.5}}}},{\"1\":{\"rec\":{\"2\":{\"str\":\"buz\"}}},\"2\":{\"rec\":{\"4\":{\"i64\":1}}}}]}}}}"
32
+ end
33
+ end
34
+
35
+ describe 'object' do
36
+ let(:obj) { LocalObject.new(1, true) }
37
+
38
+ it do
39
+ subject.should == "{\"9\":{\"rec\":{\"1\":{\"map\":[\"str\",\"rec\",2,{\"foo\":{\"4\":{\"i64\":1}},\"bar\":{\"6\":{\"tf\":1}}}]}}}}"
40
+ end
41
+ end
42
+ end
43
+ end
data/spec/types_spec.rb CHANGED
@@ -97,9 +97,9 @@ describe Thrift::Types do
97
97
  end
98
98
 
99
99
  it "should give the Thrift::TypeError a readable message" do
100
- msg = "Expected Types::STRING, received Fixnum for field foo"
100
+ msg = "Expected Types::STRING, received Integer for field foo"
101
101
  lambda { Thrift.check_type(3, {:type => Thrift::Types::STRING}, :foo) }.should raise_error(Thrift::TypeError, msg)
102
- msg = "Expected Types::STRING, received Fixnum for field foo.element"
102
+ msg = "Expected Types::STRING, received Integer for field foo.element"
103
103
  field = {:type => Thrift::Types::LIST, :element => {:type => Thrift::Types::STRING}}
104
104
  lambda { Thrift.check_type([3], field, :foo) }.should raise_error(Thrift::TypeError, msg)
105
105
  msg = "Expected Types::I32, received NilClass for field foo.element.key"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: upfluence-thrift
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thrift Developers
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-13 00:00:00.000000000 Z
11
+ date: 2021-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -128,6 +128,18 @@ extra_rdoc_files:
128
128
  - lib/thrift/union.rb
129
129
  - lib/thrift/serializer/serializer.rb
130
130
  - lib/thrift/serializer/deserializer.rb
131
+ - lib/thrift/types/value.rb
132
+ - lib/thrift/types/value_constants.rb
133
+ - lib/thrift/types/value_types.rb
134
+ - lib/thrift/types/known/any_types.rb
135
+ - lib/thrift/types/known/any.rb
136
+ - lib/thrift/types/known/timestamp.rb
137
+ - lib/thrift/types/known/timestamp_types.rb
138
+ - lib/thrift/types/known/any_constants.rb
139
+ - lib/thrift/types/known/timestamp_constants.rb
140
+ - lib/thrift/types/known/duration.rb
141
+ - lib/thrift/types/known/duration_types.rb
142
+ - lib/thrift/types/known/duration_constants.rb
131
143
  - lib/thrift/transport/base_server_transport.rb
132
144
  - lib/thrift/transport/framed_transport.rb
133
145
  - lib/thrift/transport/socket.rb
@@ -232,6 +244,18 @@ files:
232
244
  - lib/thrift/transport/unix_server_socket.rb
233
245
  - lib/thrift/transport/unix_socket.rb
234
246
  - lib/thrift/types.rb
247
+ - lib/thrift/types/known/any.rb
248
+ - lib/thrift/types/known/any_constants.rb
249
+ - lib/thrift/types/known/any_types.rb
250
+ - lib/thrift/types/known/duration.rb
251
+ - lib/thrift/types/known/duration_constants.rb
252
+ - lib/thrift/types/known/duration_types.rb
253
+ - lib/thrift/types/known/timestamp.rb
254
+ - lib/thrift/types/known/timestamp_constants.rb
255
+ - lib/thrift/types/known/timestamp_types.rb
256
+ - lib/thrift/types/value.rb
257
+ - lib/thrift/types/value_constants.rb
258
+ - lib/thrift/types/value_types.rb
235
259
  - lib/thrift/union.rb
236
260
  - spec/BaseService.thrift
237
261
  - spec/ExtendedService.thrift
@@ -263,6 +287,10 @@ files:
263
287
  - spec/struct_nested_containers_spec.rb
264
288
  - spec/struct_spec.rb
265
289
  - spec/thin_http_server_spec.rb
290
+ - spec/types/known/any_spec.rb
291
+ - spec/types/known/duration_spec.rb
292
+ - spec/types/known/timestamp_spec.rb
293
+ - spec/types/value_spec.rb
266
294
  - spec/types_spec.rb
267
295
  - spec/union_spec.rb
268
296
  - spec/unix_socket_spec.rb
@@ -270,7 +298,7 @@ homepage: http://thrift.apache.org
270
298
  licenses:
271
299
  - Apache 2.0
272
300
  metadata: {}
273
- post_install_message:
301
+ post_install_message:
274
302
  rdoc_options:
275
303
  - "--line-numbers"
276
304
  - "--inline-source"
@@ -293,7 +321,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
293
321
  version: '0'
294
322
  requirements: []
295
323
  rubygems_version: 3.0.3
296
- signing_key:
324
+ signing_key:
297
325
  specification_version: 4
298
326
  summary: Ruby bindings for Apache Thrift
299
327
  test_files:
@@ -306,6 +334,10 @@ test_files:
306
334
  - spec/compact_protocol_spec.rb
307
335
  - spec/base_protocol_spec.rb
308
336
  - spec/client_spec.rb
337
+ - spec/types/value_spec.rb
338
+ - spec/types/known/timestamp_spec.rb
339
+ - spec/types/known/duration_spec.rb
340
+ - spec/types/known/any_spec.rb
309
341
  - spec/server_spec.rb
310
342
  - spec/server_socket_spec.rb
311
343
  - spec/bytes_spec.rb