Class: PingPongPlayer

Inherits:
Object
  • Object
show all
Includes:
Grpc::Testing, Grpc::Testing::PayloadType
Defined in:
src/ruby/pb/test/client.rb

Overview

a PingPongPlayer implements the ping pong bidi test.

Constant Summary

Constants included from Grpc::Testing

Grpc::Testing::BoolValue, Grpc::Testing::ClientConfigureRequest, Grpc::Testing::ClientConfigureResponse, Grpc::Testing::EchoStatus, Grpc::Testing::Empty, Grpc::Testing::EmptyMessage, Grpc::Testing::GaugeRequest, Grpc::Testing::GaugeResponse, Grpc::Testing::GrpclbRouteType, Grpc::Testing::HookRequest, Grpc::Testing::HookResponse, Grpc::Testing::LoadBalancerAccumulatedStatsRequest, Grpc::Testing::LoadBalancerAccumulatedStatsResponse, Grpc::Testing::LoadBalancerStatsRequest, Grpc::Testing::LoadBalancerStatsResponse, Grpc::Testing::MemorySize, Grpc::Testing::Payload, Grpc::Testing::PayloadType, Grpc::Testing::ReconnectInfo, Grpc::Testing::ReconnectParams, Grpc::Testing::ResponseParameters, Grpc::Testing::SetReturnStatusRequest, Grpc::Testing::SimpleRequest, Grpc::Testing::SimpleResponse, Grpc::Testing::StreamingInputCallRequest, Grpc::Testing::StreamingInputCallResponse, Grpc::Testing::StreamingOutputCallRequest, Grpc::Testing::StreamingOutputCallResponse, Grpc::Testing::TestOrcaReport

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(msg_sizes) ⇒ PingPongPlayer

reqs is the enumerator over the requests



186
187
188
189
190
# File 'src/ruby/pb/test/client.rb', line 186

def initialize(msg_sizes)
  @queue = Queue.new
  @msg_sizes = msg_sizes
  @canceller_op = nil  # used to cancel after the first response
end

Instance Attribute Details

#canceller_opObject

Returns the value of attribute canceller_op.



183
184
185
# File 'src/ruby/pb/test/client.rb', line 183

def canceller_op
  @canceller_op
end

#queueObject

Returns the value of attribute queue.



182
183
184
# File 'src/ruby/pb/test/client.rb', line 182

def queue
  @queue
end

Instance Method Details

#each_itemObject



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'src/ruby/pb/test/client.rb', line 192

def each_item
  return enum_for(:each_item) unless block_given?
  req_cls, p_cls = StreamingOutputCallRequest, ResponseParameters  # short
  count = 0
  @msg_sizes.each do |m|
    req_size, resp_size = m
    req = req_cls.new(payload: Payload.new(body: nulls(req_size)),
                      response_type: :COMPRESSABLE,
                      response_parameters: [p_cls.new(size: resp_size)])
    yield req
    resp = @queue.pop
    assert('payload type is wrong') { :COMPRESSABLE == resp.payload.type }
    assert("payload body #{count} has the wrong length") do
      resp_size == resp.payload.body.length
    end
    p "OK: ping_pong #{count}"
    count += 1
    unless @canceller_op.nil?
      canceller_op.cancel
      break
    end
  end
end