Method: NamedTests#custom_metadata

Defined in:
src/ruby/pb/test/client.rb

#custom_metadataObject



584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
# File 'src/ruby/pb/test/client.rb', line 584

def 

  # Function wide constants
  req_size, wanted_response_size = 271_828, 314_159
   = "x-grpc-test-echo-initial"
   = "test_initial_metadata_value"
   = "x-grpc-test-echo-trailing-bin"
   = "\x0a\x0b\x0a\x0b\x0a\x0b"

   = {
     => ,
     => 
  }

  # Testing with UnaryCall
  payload = Payload.new(type: :COMPRESSABLE, body: nulls(req_size))
  req = SimpleRequest.new(response_type: :COMPRESSABLE,
      response_size: wanted_response_size,
      payload: payload)

  op = @stub.unary_call(req, metadata: , return_op: true)
  op.execute
  if not op..has_key?()
    fail AssertionError, "Expected initial metadata. None received"
  elsif op.[] != []
    fail AssertionError,
           "Expected initial metadata: #{metadata[initial_metadata_key]}. "\
           "Received: #{op.metadata[initial_metadata_key]}"
  end
  if not op..has_key?()
    fail AssertionError, "Expected trailing metadata. None received"
  elsif op.[] !=
        []
    fail AssertionError,
          "Expected trailing metadata: #{metadata[trailing_metadata_key]}. "\
          "Received: #{op.trailing_metadata[trailing_metadata_key]}"
  end

  # Testing with FullDuplex
  req_cls, p_cls = StreamingOutputCallRequest, ResponseParameters
  duplex_req = req_cls.new(payload: Payload.new(body: nulls(req_size)),
                response_type: :COMPRESSABLE,
                response_parameters: [p_cls.new(size: wanted_response_size)])

  duplex_op = @stub.full_duplex_call([duplex_req], metadata: ,
                                      return_op: true)
  resp = duplex_op.execute
  resp.each { |r| } # ensures that the server sends trailing data
  duplex_op.wait
  if not duplex_op..has_key?()
    fail AssertionError, "Expected initial metadata. None received"
  elsif duplex_op.[] !=
        []
    fail AssertionError,
           "Expected initial metadata: #{metadata[initial_metadata_key]}. "\
           "Received: #{duplex_op.metadata[initial_metadata_key]}"
  end
  if not duplex_op.[]
    fail AssertionError, "Expected trailing metadata. None received"
  elsif duplex_op.[] !=
        []
    fail AssertionError,
        "Expected trailing metadata: #{metadata[trailing_metadata_key]}. "\
        "Received: #{duplex_op.trailing_metadata[trailing_metadata_key]}"
  end

end