upfluence-thrift 2.7.5 → 2.7.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d7364f74deded6f763d331becc4b5daae61421b94363b280eefbf2d8e7ae6d04
4
- data.tar.gz: ce0fdd32e91d447f715dc703dca1473130b2c1f63472fefe0e306bf830f7ee4f
3
+ metadata.gz: 8e31952e8e892fc4b82c5a19ac4145bf6c8d439474b83b8162119a11cedc5b0d
4
+ data.tar.gz: '049b17f3c6bba2b2ce85aff58417785465614992435667036fcda62bf4f43fa9'
5
5
  SHA512:
6
- metadata.gz: 00d26a6747c4af8df633b615759e53b7386de509339b8b3c1e56f9649c17ccbba1e94a06c9a607b45385b40c0b250bc30afece40bca46e9ea4a66ca8edd1d55e
7
- data.tar.gz: fb343c067f283d0ae87e93de2d5215907e9d4020997129fde989378e5538dce8d3da94521d1796e42d30ace9fd4f5044ef80fa1c56ae8580be544464e6ecee40
6
+ metadata.gz: b5a53855250a59549aaab99463b1fd8512c9d2379f6dfbee1407357f3270b8717ed009319923a64d023402ff50c01d7d62fb413c064d9e31cf94656529555f83
7
+ data.tar.gz: 98d79404c6044387670b06ceef345acdfa70d618d645da24d02b1ff191eef1cdf8a22723ce06b13de8a4b59653a9a6daec6b4639fb5b538ad283229458743887
@@ -59,22 +59,7 @@ module Thrift
59
59
 
60
60
  write_result(result, oprot, seqid)
61
61
  rescue => e
62
- write_exception(e, oprot, seqid)
63
- end
64
-
65
- def write_exception(exception, oprot, seqid)
66
- oprot.write_message_begin(@fname, MessageTypes::EXCEPTION, seqid)
67
-
68
- unless exception.is_a? ApplicationException
69
- exception = ApplicationException.new(
70
- ApplicationException::INTERNAL_ERROR,
71
- "Internal error processing #{@fname}: #{exception.class}: #{exception}"
72
- )
73
- end
74
-
75
- exception.write(oprot)
76
- oprot.write_message_end
77
- oprot.trans.flush
62
+ Processor.write_exception(e, oprot, @fname, seqid)
78
63
  end
79
64
 
80
65
  def write_result(result, oprot, seqid)
@@ -131,11 +116,18 @@ module Thrift
131
116
  end
132
117
 
133
118
  def process(iprot, oprot)
134
- name, _type, seqid = iprot.read_message_begin
119
+ name, type, seqid = iprot.read_message_begin
135
120
 
136
121
  mth = "process_#{name}"
137
122
  if respond_to?(mth)
138
- send(mth, seqid, iprot, oprot)
123
+ begin
124
+ send(mth, seqid, iprot, oprot)
125
+ rescue StandardError => e
126
+ raise e if type == MessageTypes::ONEWAY
127
+
128
+ Processor.write_internal_error(e, oprot, name, seqid)
129
+ end
130
+
139
131
  return true
140
132
  end
141
133
 
@@ -144,8 +136,35 @@ module Thrift
144
136
  ).process(seqid, iprot, oprot)
145
137
  end
146
138
 
139
+ def self.write_exception(exception, oprot, name, seqid)
140
+ oprot.write_message_begin(name, MessageTypes::EXCEPTION, seqid)
141
+
142
+ unless exception.is_a? ApplicationException
143
+ exception = ApplicationException.new(
144
+ ApplicationException::INTERNAL_ERROR,
145
+ "Internal error processing #{name}: #{exception.class}: #{exception}"
146
+ )
147
+ end
148
+
149
+ exception.write(oprot)
150
+ oprot.write_message_end
151
+ oprot.trans.flush
152
+ end
153
+
154
+ def self.write_internal_error(exception, oprot, name, seqid)
155
+ write_exception(
156
+ ApplicationException.new(
157
+ ApplicationException::INTERNAL_ERROR,
158
+ "Internal error processing #{name}: #{exception.class}: #{exception}"
159
+ ),
160
+ oprot,
161
+ name,
162
+ seqid
163
+ )
164
+ end
165
+
147
166
  def build_processor(name, info)
148
- if info[:result_klass].nil?
167
+ if info[:result_klass].nil? && info[:oneway]
149
168
  UnaryProcessor
150
169
  elsif info[:stream_klass].nil? && info[:sink_klass].nil?
151
170
  BinaryProcessor
@@ -173,21 +192,6 @@ module Thrift
173
192
  args
174
193
  end
175
194
 
176
- def write_exception(exception, oprot, name, seqid)
177
- oprot.write_message_begin(name, MessageTypes::EXCEPTION, seqid)
178
-
179
- unless exception.is_a? ApplicationException
180
- exception = ApplicationException.new(
181
- ApplicationException::INTERNAL_ERROR,
182
- "Internal error processing #{name}: #{exception.class}: #{exception}"
183
- )
184
- end
185
-
186
- exception.write(oprot)
187
- oprot.write_message_end
188
- oprot.trans.flush
189
- end
190
-
191
195
  def write_result(result, oprot, seqid)
192
196
  oprot.write_message_begin(@name, MessageTypes::REPLY, seqid)
193
197
  result.write(oprot)
@@ -236,18 +240,10 @@ module Thrift
236
240
 
237
241
  true
238
242
  rescue ApplicationException => e
239
- write_exception(e, oprot, @name, seqid)
243
+ Processor.write_exception(e, oprot, @name, seqid)
240
244
  true
241
245
  rescue StandardError => e
242
- write_exception(
243
- ApplicationException.new(
244
- ApplicationException::INTERNAL_ERROR,
245
- "Internal error processing #{@name}: #{e.class}: #{e}"
246
- ),
247
- oprot,
248
- @name,
249
- seqid
250
- )
246
+ Processor.write_internal_error(e, oprot, @name, seqid)
251
247
  true
252
248
  end
253
249
 
@@ -400,7 +396,7 @@ module Thrift
400
396
  def process(seqid, iprot, oprot)
401
397
  iprot.skip(Types::STRUCT)
402
398
  iprot.read_message_end
403
- write_exception(
399
+ Processor.write_exception(
404
400
  ApplicationException.new(
405
401
  ApplicationException::UNKNOWN_METHOD,
406
402
  'Unknown function ' + @name,
@@ -19,73 +19,200 @@
19
19
 
20
20
  require 'spec_helper'
21
21
 
22
- describe 'Processor' do
23
- class ProcessorSpec
24
- include Thrift::Processor
22
+ describe Thrift::Processor do
23
+ class EmptyArgs
24
+ include Thrift::Struct_Union
25
+ include Thrift::Struct
26
+
27
+ FIELDS = {}.freeze
28
+
29
+ def struct_fields
30
+ FIELDS
31
+ end
32
+
33
+ def validate; end
25
34
  end
26
35
 
27
- describe Thrift::Processor do
28
- before(:each) do
29
- @processor = ProcessorSpec.new(double('MockHandler'))
30
- @prot = double('MockProtocol')
36
+ class EmptyResult
37
+ include Thrift::Struct_Union
38
+ include Thrift::Struct
39
+
40
+ FIELDS = {}.freeze
41
+
42
+ def struct_fields
43
+ FIELDS
31
44
  end
32
45
 
33
- def mock_trans(obj)
34
- expect(obj).to receive(:trans).ordered do
35
- double('trans').tap do |trans|
36
- expect(trans).to receive(:flush).ordered
37
- end
46
+ def validate; end
47
+ end
48
+
49
+ class LegacyProcessor
50
+ include Thrift::Processor
51
+
52
+ def process_ping(seqid, iprot, oprot)
53
+ args = read_args(iprot, EmptyArgs)
54
+ result = @middleware.handle_binary('ping', args) do
55
+ @handler.ping
56
+ EmptyResult.new
38
57
  end
39
- end
40
58
 
41
- it 'should call process_<message> when it receives that message' do
42
- expect(@prot).to receive(:read_message_begin).ordered.and_return ['testMessage', Thrift::MessageTypes::CALL, 17]
43
- expect(@processor).to receive(:process_testMessage).with(17, @prot, @prot).ordered
44
- expect(@processor.process(@prot, @prot)).to eq(true)
59
+ write_result(result, oprot, 'ping', seqid)
45
60
  end
46
61
 
47
- it 'should raise an ApplicationException when the received message cannot be processed' do
48
- expect(@prot).to receive(:read_message_begin).ordered.and_return ['testMessage', Thrift::MessageTypes::CALL, 4]
49
- expect(@prot).to receive(:skip).with(Thrift::Types::STRUCT).ordered
50
- expect(@prot).to receive(:read_message_end).ordered
51
- expect(@prot).to receive(:write_message_begin).with('testMessage', Thrift::MessageTypes::EXCEPTION, 4).ordered
52
- e = Thrift::ApplicationException.new(
53
- Thrift::ApplicationException::UNKNOWN_METHOD,
54
- 'Unknown function testMessage'
55
- )
56
- expect(Thrift::ApplicationException).to receive(:new).with(Thrift::ApplicationException::UNKNOWN_METHOD,
57
- 'Unknown function testMessage').and_return(e)
58
- expect(@prot).to receive(:write_struct_begin).with('Thrift::ApplicationException').ordered
59
- expect(@prot).to receive(:write_field_begin).with('message', Thrift::Types::STRING, 1).ordered
60
- expect(@prot).to receive(:write_string).with('Unknown function testMessage').ordered
61
- expect(@prot).to receive(:write_field_end).ordered
62
- expect(@prot).to receive(:write_field_begin).with('type', Thrift::Types::I32, 2).ordered
63
- expect(@prot).to receive(:write_i32).with(Thrift::ApplicationException::UNKNOWN_METHOD).ordered
64
- expect(@prot).to receive(:write_field_end).ordered
65
- expect(@prot).to receive(:write_field_stop).ordered
66
- expect(@prot).to receive(:write_struct_end).ordered
67
- expect(@prot).to receive(:write_message_end).ordered
68
- mock_trans(@prot)
69
- @processor.process(@prot, @prot)
70
- end
62
+ def process_notify(_seqid, iprot, _oprot)
63
+ args = read_args(iprot, EmptyArgs)
71
64
 
72
- it 'should pass args off to the args class' do
73
- args_class = double('MockArgsClass')
74
- args = double('#<MockArgsClass:mock>').tap do |args|
75
- expect(args).to receive(:read).with(@prot).ordered
65
+ @middleware.handle_unary('notify', args) do
66
+ @handler.notify
76
67
  end
77
- expect(args_class).to receive(:new).and_return args
78
- expect(@prot).to receive(:read_message_end).ordered
79
- expect(@processor.read_args(@prot, args_class)).to eql(args)
80
68
  end
69
+ end
81
70
 
82
- it 'should write out a reply when asked' do
83
- expect(@prot).to receive(:write_message_begin).with('testMessage', Thrift::MessageTypes::REPLY, 23).ordered
84
- result = double('MockResult')
85
- expect(result).to receive(:write).with(@prot).ordered
86
- expect(@prot).to receive(:write_message_end).ordered
87
- mock_trans(@prot)
88
- @processor.write_result(result, @prot, 'testMessage', 23)
89
- end
71
+ class CurrentProcessor
72
+ include Thrift::Processor
73
+
74
+ METHODS = {
75
+ 'ping' => {
76
+ args_klass: EmptyArgs,
77
+ result_klass: EmptyResult,
78
+ args: [],
79
+ exceptions: {},
80
+ oneway: false
81
+ }
82
+ }.freeze
83
+ end
84
+
85
+ def request_protocol(name, type = Thrift::MessageTypes::CALL, seqid = 17)
86
+ trans = Thrift::MemoryBufferTransport.new
87
+ protocol = Thrift::BinaryProtocol.new(trans)
88
+ protocol.write_message_begin(name, type, seqid)
89
+ EmptyArgs.new.write(protocol)
90
+ protocol.write_message_end
91
+
92
+ Thrift::BinaryProtocol.new(trans)
93
+ end
94
+
95
+ def output_protocol
96
+ trans = Thrift::MemoryBufferTransport.new
97
+
98
+ [Thrift::BinaryProtocol.new(trans), trans]
99
+ end
100
+
101
+ def read_exception(protocol)
102
+ name, type, seqid = protocol.read_message_begin
103
+ exception = Thrift::ApplicationException.new
104
+ exception.read(protocol)
105
+ protocol.read_message_end
106
+
107
+ {
108
+ name: name,
109
+ type: type,
110
+ seqid: seqid,
111
+ exception_type: exception.type,
112
+ message: exception.message
113
+ }
114
+ end
115
+
116
+ it 'processes requests with a legacy generated stub' do
117
+ handler = double('handler', ping: nil)
118
+ processor = LegacyProcessor.new(handler)
119
+ oprot, trans = output_protocol
120
+
121
+ expect(processor.process(request_protocol('ping'), oprot)).to eq(true)
122
+ expect(oprot.read_message_begin).to eq(
123
+ ['ping', Thrift::MessageTypes::REPLY, 17]
124
+ )
125
+
126
+ EmptyResult.new.read(oprot)
127
+ oprot.read_message_end
128
+
129
+ expect(trans.available).to eq(0)
130
+ end
131
+
132
+ it 'writes internal errors raised by a legacy generated stub' do
133
+ handler = double('handler')
134
+ allow(handler).to receive(:ping).and_raise(StandardError, 'boom')
135
+ processor = LegacyProcessor.new(handler)
136
+ oprot, = output_protocol
137
+
138
+ expect(processor.process(request_protocol('ping'), oprot)).to eq(true)
139
+ expect(read_exception(oprot)).to eq(
140
+ name: 'ping',
141
+ type: Thrift::MessageTypes::EXCEPTION,
142
+ seqid: 17,
143
+ exception_type: Thrift::ApplicationException::INTERNAL_ERROR,
144
+ message: 'Internal error processing ping: StandardError: boom'
145
+ )
146
+ end
147
+
148
+ it 'raises errors from a legacy oneway method without writing a response' do
149
+ handler = double('handler')
150
+ allow(handler).to receive(:notify).and_raise(StandardError, 'boom')
151
+ processor = LegacyProcessor.new(handler)
152
+ oprot, trans = output_protocol
153
+
154
+ expect do
155
+ processor.process(
156
+ request_protocol('notify', Thrift::MessageTypes::ONEWAY),
157
+ oprot
158
+ )
159
+ end.to raise_error(StandardError, 'boom')
160
+ expect(trans.available).to eq(0)
161
+ end
162
+
163
+ it 'writes an unknown method exception' do
164
+ processor = CurrentProcessor.new(double('handler'))
165
+ oprot, = output_protocol
166
+
167
+ expect(
168
+ processor.process(
169
+ request_protocol('missing', Thrift::MessageTypes::CALL, 4),
170
+ oprot
171
+ )
172
+ ).to eq(false)
173
+ expect(read_exception(oprot)).to eq(
174
+ name: 'missing',
175
+ type: Thrift::MessageTypes::EXCEPTION,
176
+ seqid: 4,
177
+ exception_type: Thrift::ApplicationException::UNKNOWN_METHOD,
178
+ message: 'Unknown function missing'
179
+ )
180
+ end
181
+
182
+ it 'writes internal errors raised by a current processor' do
183
+ handler = double('handler')
184
+ allow(handler).to receive(:ping).and_raise(StandardError, 'boom')
185
+ processor = CurrentProcessor.new(handler)
186
+ oprot, = output_protocol
187
+
188
+ expect(processor.process(request_protocol('ping'), oprot)).to eq(true)
189
+ expect(read_exception(oprot)).to eq(
190
+ name: 'ping',
191
+ type: Thrift::MessageTypes::EXCEPTION,
192
+ seqid: 17,
193
+ exception_type: Thrift::ApplicationException::INTERNAL_ERROR,
194
+ message: 'Internal error processing ping: StandardError: boom'
195
+ )
196
+ end
197
+
198
+ it 'preserves application exceptions raised by a current processor' do
199
+ handler = double('handler')
200
+ allow(handler).to receive(:ping).and_raise(
201
+ Thrift::ApplicationException.new(
202
+ Thrift::ApplicationException::PROTOCOL_ERROR,
203
+ 'invalid request'
204
+ )
205
+ )
206
+ processor = CurrentProcessor.new(handler)
207
+ oprot, = output_protocol
208
+
209
+ expect(processor.process(request_protocol('ping'), oprot)).to eq(true)
210
+ expect(read_exception(oprot)).to eq(
211
+ name: 'ping',
212
+ type: Thrift::MessageTypes::EXCEPTION,
213
+ seqid: 17,
214
+ exception_type: Thrift::ApplicationException::PROTOCOL_ERROR,
215
+ message: 'invalid request'
216
+ )
90
217
  end
91
218
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: upfluence-thrift
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.5
4
+ version: 2.7.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thrift Developers
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2026-07-28 00:00:00.000000000 Z
10
+ date: 2026-08-13 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rspec