grpc-proxy-stream.t 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #
  2. # Licensed to the Apache Software Foundation (ASF) under one or more
  3. # contributor license agreements. See the NOTICE file distributed with
  4. # this work for additional information regarding copyright ownership.
  5. # The ASF licenses this file to You under the Apache License, Version 2.0
  6. # (the "License"); you may not use this file except in compliance with
  7. # the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. #
  17. use t::APISIX 'no_plan';
  18. no_long_string();
  19. no_root_location();
  20. no_shuffle();
  21. add_block_preprocessor(sub {
  22. my ($block) = @_;
  23. if (!$block->request) {
  24. $block->set_value("request", "GET /t");
  25. }
  26. if (!$block->no_error_log && !$block->error_log) {
  27. $block->set_value("no_error_log", "[error]\n[alert]");
  28. }
  29. });
  30. run_tests;
  31. __DATA__
  32. === TEST 1: Test server side streaming method through gRPC proxy
  33. --- http2
  34. --- apisix_yaml
  35. routes:
  36. -
  37. id: 1
  38. uris:
  39. - /helloworld.Greeter/SayHelloServerStream
  40. methods: [
  41. POST
  42. ]
  43. upstream:
  44. scheme: grpc
  45. nodes:
  46. "127.0.0.1:10051": 1
  47. type: roundrobin
  48. #END
  49. --- exec
  50. grpcurl -import-path ./t/grpc_server_example/proto -proto helloworld.proto -plaintext -d '{"name":"apisix"}' 127.0.0.1:1984 helloworld.Greeter.SayHelloServerStream
  51. --- response_body
  52. {
  53. "message": "Hello apisix"
  54. }
  55. {
  56. "message": "Hello apisix"
  57. }
  58. {
  59. "message": "Hello apisix"
  60. }
  61. {
  62. "message": "Hello apisix"
  63. }
  64. {
  65. "message": "Hello apisix"
  66. }
  67. === TEST 2: Test client side streaming method through gRPC proxy
  68. --- http2
  69. --- apisix_yaml
  70. routes:
  71. -
  72. id: 1
  73. uris:
  74. - /helloworld.Greeter/SayHelloClientStream
  75. methods: [
  76. POST
  77. ]
  78. upstream:
  79. scheme: grpc
  80. nodes:
  81. "127.0.0.1:10051": 1
  82. type: roundrobin
  83. #END
  84. --- exec
  85. grpcurl -import-path ./t/grpc_server_example/proto -proto helloworld.proto -plaintext -d '{"name":"apisix"} {"name":"apisix"} {"name":"apisix"} {"name":"apisix"}' 127.0.0.1:1984 helloworld.Greeter.SayHelloClientStream
  86. --- response_body
  87. {
  88. "message": "Hello apisix!Hello apisix!Hello apisix!Hello apisix!"
  89. }
  90. === TEST 3: Test bidirectional streaming method through gRPC proxy
  91. --- http2
  92. --- apisix_yaml
  93. routes:
  94. -
  95. id: 1
  96. uris:
  97. - /helloworld.Greeter/SayHelloBidirectionalStream
  98. methods: [
  99. POST
  100. ]
  101. upstream:
  102. scheme: grpc
  103. nodes:
  104. "127.0.0.1:10051": 1
  105. type: roundrobin
  106. #END
  107. --- exec
  108. grpcurl -import-path ./t/grpc_server_example/proto -proto helloworld.proto -plaintext -d '{"name":"apisix"} {"name":"apisix"} {"name":"apisix"} {"name":"apisix"}' 127.0.0.1:1984 helloworld.Greeter.SayHelloBidirectionalStream
  109. --- response_body
  110. {
  111. "message": "Hello apisix"
  112. }
  113. {
  114. "message": "Hello apisix"
  115. }
  116. {
  117. "message": "Hello apisix"
  118. }
  119. {
  120. "message": "Hello apisix"
  121. }
  122. {
  123. "message": "stream ended"
  124. }