Class: TestTarget

Inherits:
Grpc::Testing::TestService::Service show all
Includes:
Grpc::Testing, Grpc::Testing::PayloadType
Defined in:
src/ruby/pb/test/server.rb

Overview

A runnable implementation of the schema-specified testing service, with each service method implemented as required by the interop testing spec.

Constant Summary

Constants included from Grpc::Testing

Grpc::Testing::CompressionType, Grpc::Testing::EchoStatus, Grpc::Testing::Empty, Grpc::Testing::Payload, Grpc::Testing::PayloadType, Grpc::Testing::ReconnectInfo, Grpc::Testing::ResponseParameters, Grpc::Testing::SimpleRequest, Grpc::Testing::SimpleResponse, Grpc::Testing::StreamingInputCallRequest, Grpc::Testing::StreamingInputCallResponse, Grpc::Testing::StreamingOutputCallRequest, Grpc::Testing::StreamingOutputCallResponse

Instance Method Summary collapse

Methods included from GRPC::GenericService

included, underscore

Instance Method Details

#empty_call(_empty, _call) ⇒ Object


159
160
161
# File 'src/ruby/pb/test/server.rb', line 159

def empty_call(_empty, _call)
  Empty.new
end

#full_duplex_call(reqs) ⇒ Object


183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'src/ruby/pb/test/server.rb', line 183

def full_duplex_call(reqs)
  # reqs is a lazy Enumerator of the requests sent by the client.
  q = EnumeratorQueue.new(self)
  cls = StreamingOutputCallResponse
  Thread.new do
    begin
      GRPC.logger.info('interop-server: started receiving')
      reqs.each do |req|
        resp_size = req.response_parameters[0].size
        GRPC.logger.info("read a req, response size is #{resp_size}")
        resp = cls.new(payload: Payload.new(type: req.response_type,
                                            body: nulls(resp_size)))
        q.push(resp)
      end
      GRPC.logger.info('interop-server: finished receiving')
      q.push(self)
    rescue StandardError => e
      GRPC.logger.info('interop-server: failed')
      GRPC.logger.warn(e)
      q.push(e)  # share the exception with the enumerator
    end
  end
  q.each_item
end

#half_duplex_call(reqs) ⇒ Object


208
209
210
211
212
# File 'src/ruby/pb/test/server.rb', line 208

def half_duplex_call(reqs)
  # TODO: update with unique behaviour of the half_duplex_call if that's
  # ever required by any of the tests.
  full_duplex_call(reqs)
end

#streaming_input_call(call) ⇒ Object


169
170
171
172
173
# File 'src/ruby/pb/test/server.rb', line 169

def streaming_input_call(call)
  sizes = call.each_remote_read.map { |x| x.payload.body.length }
  sum = sizes.inject(0) { |s, x| s + x }
  StreamingInputCallResponse.new(aggregated_payload_size: sum)
end

#streaming_output_call(req, _call) ⇒ Object


175
176
177
178
179
180
181
# File 'src/ruby/pb/test/server.rb', line 175

def streaming_output_call(req, _call)
  cls = StreamingOutputCallResponse
  req.response_parameters.map do |p|
    cls.new(payload: Payload.new(type: req.response_type,
                                 body: nulls(p.size)))
  end
end

#unary_call(simple_req, _call) ⇒ Object


163
164
165
166
167
# File 'src/ruby/pb/test/server.rb', line 163

def unary_call(simple_req, _call)
  req_size = simple_req.response_size
  SimpleResponse.new(payload: Payload.new(type: :COMPRESSABLE,
                                          body: nulls(req_size)))
end