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::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 Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(msg_sizes) ⇒ PingPongPlayer

reqs is the enumerator over the requests


167
168
169
170
171
# File 'src/ruby/pb/test/client.rb', line 167

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


164
165
166
# File 'src/ruby/pb/test/client.rb', line 164

def canceller_op
  @canceller_op
end

#queueObject

Returns the value of attribute queue


163
164
165
# File 'src/ruby/pb/test/client.rb', line 163

def queue
  @queue
end

Instance Method Details

#each_itemObject


173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'src/ruby/pb/test/client.rb', line 173

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