grpc 1.6.7 → 1.7.0.pre1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (277) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +579 -77
  3. data/include/grpc/byte_buffer.h +1 -63
  4. data/include/grpc/compression.h +27 -5
  5. data/include/grpc/fork.h +24 -0
  6. data/include/grpc/grpc.h +12 -6
  7. data/include/grpc/grpc_security.h +28 -7
  8. data/include/grpc/impl/codegen/atm.h +1 -0
  9. data/include/grpc/impl/codegen/byte_buffer.h +86 -0
  10. data/include/grpc/impl/codegen/compression_types.h +63 -5
  11. data/include/grpc/impl/codegen/fork.h +48 -0
  12. data/include/grpc/impl/codegen/grpc_types.h +26 -9
  13. data/include/grpc/impl/codegen/port_platform.h +11 -4
  14. data/include/grpc/impl/codegen/slice.h +6 -1
  15. data/include/grpc/impl/codegen/sync.h +3 -1
  16. data/include/grpc/impl/codegen/sync_custom.h +36 -0
  17. data/include/grpc/module.modulemap +75 -3
  18. data/include/grpc/slice.h +1 -5
  19. data/include/grpc/support/sync_custom.h +24 -0
  20. data/src/core/ext/census/base_resources.c +14 -14
  21. data/src/core/ext/census/context.c +7 -5
  22. data/src/core/ext/census/grpc_filter.c +12 -14
  23. data/src/core/ext/census/mlog.c +2 -1
  24. data/src/core/ext/census/resource.c +13 -9
  25. data/src/core/ext/filters/client_channel/channel_connectivity.c +15 -8
  26. data/src/core/ext/filters/client_channel/client_channel.c +418 -439
  27. data/src/core/ext/filters/client_channel/client_channel_factory.c +4 -5
  28. data/src/core/ext/filters/client_channel/client_channel_plugin.c +2 -2
  29. data/src/core/ext/filters/client_channel/http_connect_handshaker.c +7 -5
  30. data/src/core/ext/filters/client_channel/http_proxy.c +17 -21
  31. data/src/core/ext/filters/client_channel/lb_policy.c +1 -1
  32. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.c +7 -7
  33. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.c +371 -257
  34. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.c +7 -5
  35. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.c +25 -14
  36. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.c +16 -16
  37. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.c +33 -28
  38. data/src/core/ext/filters/client_channel/lb_policy_factory.c +10 -8
  39. data/src/core/ext/filters/client_channel/lb_policy_factory.h +1 -1
  40. data/src/core/ext/filters/client_channel/proxy_mapper_registry.c +1 -1
  41. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.c +7 -6
  42. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.c +62 -28
  43. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.c +29 -23
  44. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.c +25 -14
  45. data/src/core/ext/filters/client_channel/retry_throttle.c +9 -6
  46. data/src/core/ext/filters/client_channel/subchannel.c +30 -30
  47. data/src/core/ext/filters/client_channel/subchannel.h +1 -4
  48. data/src/core/ext/filters/client_channel/subchannel_index.c +31 -15
  49. data/src/core/ext/filters/client_channel/subchannel_index.h +7 -0
  50. data/src/core/ext/filters/client_channel/uri_parser.c +4 -3
  51. data/src/core/ext/filters/deadline/deadline_filter.c +78 -39
  52. data/src/core/ext/filters/deadline/deadline_filter.h +7 -1
  53. data/src/core/ext/filters/http/client/http_client_filter.c +14 -14
  54. data/src/core/ext/filters/http/http_filters_plugin.c +1 -1
  55. data/src/core/ext/filters/http/message_compress/message_compress_filter.c +240 -175
  56. data/src/core/ext/filters/http/server/http_server_filter.c +48 -36
  57. data/src/core/ext/filters/load_reporting/{load_reporting_filter.c → server_load_reporting_filter.c} +11 -12
  58. data/src/core/ext/filters/load_reporting/{load_reporting_filter.h → server_load_reporting_filter.h} +6 -5
  59. data/src/core/ext/filters/load_reporting/{load_reporting.c → server_load_reporting_plugin.c} +19 -13
  60. data/src/core/ext/filters/load_reporting/{load_reporting.h → server_load_reporting_plugin.h} +4 -3
  61. data/src/core/ext/filters/max_age/max_age_filter.c +2 -3
  62. data/src/core/ext/filters/message_size/message_size_filter.c +4 -2
  63. data/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.c +0 -1
  64. data/src/core/ext/transport/chttp2/client/chttp2_connector.c +5 -5
  65. data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +1 -1
  66. data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.c +1 -1
  67. data/src/core/ext/transport/chttp2/server/chttp2_server.c +20 -18
  68. data/src/core/ext/transport/chttp2/transport/chttp2_plugin.c +1 -0
  69. data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +493 -210
  70. data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +1 -0
  71. data/src/core/ext/transport/chttp2/transport/flow_control.c +9 -8
  72. data/src/core/ext/transport/chttp2/transport/frame_data.c +2 -2
  73. data/src/core/ext/transport/chttp2/transport/frame_goaway.c +2 -2
  74. data/src/core/ext/transport/chttp2/transport/frame_ping.c +5 -4
  75. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +1 -1
  76. data/src/core/ext/transport/chttp2/transport/frame_settings.c +10 -9
  77. data/src/core/ext/transport/chttp2/transport/frame_window_update.c +9 -5
  78. data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +62 -41
  79. data/src/core/ext/transport/chttp2/transport/hpack_parser.c +52 -8
  80. data/src/core/ext/transport/chttp2/transport/hpack_table.c +2 -2
  81. data/src/core/ext/transport/chttp2/transport/incoming_metadata.c +3 -2
  82. data/src/core/ext/transport/chttp2/transport/internal.h +60 -30
  83. data/src/core/ext/transport/chttp2/transport/parsing.c +16 -5
  84. data/src/core/ext/transport/chttp2/transport/stream_lists.c +36 -16
  85. data/src/core/ext/transport/chttp2/transport/stream_map.c +6 -4
  86. data/src/core/ext/transport/chttp2/transport/writing.c +133 -105
  87. data/src/core/ext/transport/inproc/inproc_transport.c +61 -65
  88. data/src/core/lib/channel/channel_args.c +112 -12
  89. data/src/core/lib/channel/channel_args.h +31 -0
  90. data/src/core/lib/channel/channel_stack.c +1 -15
  91. data/src/core/lib/channel/channel_stack.h +3 -10
  92. data/src/core/lib/channel/channel_stack_builder.c +41 -10
  93. data/src/core/lib/channel/channel_stack_builder.h +10 -0
  94. data/src/core/lib/channel/connected_channel.c +94 -23
  95. data/src/core/lib/channel/handshaker.c +8 -6
  96. data/src/core/lib/channel/handshaker_registry.c +1 -1
  97. data/src/core/lib/compression/algorithm_metadata.h +14 -0
  98. data/src/core/lib/compression/compression.c +101 -1
  99. data/src/core/lib/compression/stream_compression.c +32 -146
  100. data/src/core/lib/compression/stream_compression.h +28 -4
  101. data/src/core/lib/compression/stream_compression_gzip.c +228 -0
  102. data/src/core/lib/{iomgr/ev_epoll_thread_pool_linux.h → compression/stream_compression_gzip.h} +5 -7
  103. data/src/core/lib/compression/stream_compression_identity.c +94 -0
  104. data/src/core/lib/{iomgr/ev_epoll_limited_pollers_linux.h → compression/stream_compression_identity.h} +7 -8
  105. data/src/core/lib/debug/stats.c +174 -0
  106. data/src/core/lib/debug/stats.h +61 -0
  107. data/src/core/lib/debug/stats_data.c +687 -0
  108. data/src/core/lib/debug/stats_data.h +470 -0
  109. data/src/core/lib/debug/trace.c +3 -3
  110. data/src/core/lib/debug/trace.h +1 -1
  111. data/src/core/lib/http/format_request.c +1 -1
  112. data/src/core/lib/http/httpcli.c +8 -7
  113. data/src/core/lib/http/httpcli_security_connector.c +2 -1
  114. data/src/core/lib/http/parser.c +4 -3
  115. data/src/core/lib/iomgr/call_combiner.c +202 -0
  116. data/src/core/lib/iomgr/call_combiner.h +121 -0
  117. data/src/core/lib/iomgr/closure.c +18 -4
  118. data/src/core/lib/iomgr/combiner.c +11 -4
  119. data/src/core/lib/iomgr/error.c +26 -24
  120. data/src/core/lib/iomgr/ev_epoll1_linux.c +395 -212
  121. data/src/core/lib/iomgr/ev_epollex_linux.c +141 -128
  122. data/src/core/lib/iomgr/ev_epollsig_linux.c +44 -41
  123. data/src/core/lib/iomgr/ev_poll_posix.c +99 -75
  124. data/src/core/lib/iomgr/ev_posix.c +5 -9
  125. data/src/core/lib/iomgr/ev_posix.h +1 -1
  126. data/src/core/lib/iomgr/exec_ctx.h +6 -1
  127. data/src/core/lib/iomgr/executor.c +142 -36
  128. data/src/core/lib/iomgr/executor.h +6 -1
  129. data/src/core/lib/iomgr/fork_posix.c +88 -0
  130. data/src/core/lib/iomgr/fork_windows.c +39 -0
  131. data/src/core/lib/iomgr/iocp_windows.c +2 -0
  132. data/src/core/lib/iomgr/iomgr.c +2 -8
  133. data/src/core/lib/iomgr/is_epollexclusive_available.c +6 -6
  134. data/src/core/lib/iomgr/load_file.c +2 -1
  135. data/src/core/lib/iomgr/polling_entity.c +9 -9
  136. data/src/core/lib/iomgr/polling_entity.h +7 -1
  137. data/src/core/lib/iomgr/pollset.h +1 -1
  138. data/src/core/lib/iomgr/pollset_uv.c +1 -1
  139. data/src/core/lib/iomgr/pollset_windows.c +3 -3
  140. data/src/core/lib/iomgr/port.h +4 -0
  141. data/src/core/lib/iomgr/resolve_address_posix.c +8 -7
  142. data/src/core/lib/iomgr/resolve_address_windows.c +1 -1
  143. data/src/core/lib/iomgr/resource_quota.c +24 -19
  144. data/src/core/lib/iomgr/socket_factory_posix.c +4 -4
  145. data/src/core/lib/iomgr/socket_mutator.c +4 -4
  146. data/src/core/lib/iomgr/socket_utils_windows.c +0 -4
  147. data/src/core/lib/iomgr/tcp_client_posix.c +5 -4
  148. data/src/core/lib/iomgr/tcp_posix.c +181 -20
  149. data/src/core/lib/iomgr/tcp_server_posix.c +8 -7
  150. data/src/core/lib/iomgr/tcp_server_utils_posix_common.c +1 -1
  151. data/src/core/lib/iomgr/timer.h +4 -0
  152. data/src/core/lib/iomgr/timer_generic.c +138 -3
  153. data/src/core/lib/iomgr/timer_generic.h +3 -0
  154. data/src/core/lib/iomgr/timer_heap.c +4 -4
  155. data/src/core/lib/iomgr/timer_manager.c +2 -2
  156. data/src/core/lib/iomgr/timer_uv.c +2 -0
  157. data/src/core/lib/iomgr/udp_server.c +10 -8
  158. data/src/core/lib/iomgr/unix_sockets_posix.c +4 -2
  159. data/src/core/lib/iomgr/wakeup_fd_cv.c +9 -8
  160. data/src/core/lib/iomgr/wakeup_fd_cv.h +2 -2
  161. data/src/core/lib/json/json.c +1 -1
  162. data/src/core/lib/json/json_string.c +13 -13
  163. data/src/core/lib/profiling/timers.h +18 -8
  164. data/src/core/lib/security/credentials/composite/composite_credentials.c +4 -10
  165. data/src/core/lib/security/credentials/google_default/google_default_credentials.c +2 -1
  166. data/src/core/lib/security/credentials/jwt/jwt_verifier.c +11 -6
  167. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +4 -4
  168. data/src/core/lib/security/credentials/plugin/plugin_credentials.c +132 -50
  169. data/src/core/lib/security/credentials/plugin/plugin_credentials.h +2 -0
  170. data/src/core/lib/security/transport/client_auth_filter.c +68 -135
  171. data/src/core/lib/security/transport/secure_endpoint.c +110 -90
  172. data/src/core/lib/security/transport/secure_endpoint.h +8 -3
  173. data/src/core/lib/security/transport/security_connector.c +10 -12
  174. data/src/core/lib/security/transport/security_handshaker.c +45 -24
  175. data/src/core/lib/security/transport/server_auth_filter.c +71 -20
  176. data/src/core/lib/slice/b64.c +2 -2
  177. data/src/core/lib/slice/slice.c +16 -14
  178. data/src/core/lib/slice/slice_buffer.c +5 -4
  179. data/src/core/lib/slice/slice_hash_table.c +3 -2
  180. data/src/core/lib/slice/slice_intern.c +8 -5
  181. data/src/core/lib/support/block_annotate.h +22 -0
  182. data/src/core/lib/support/fork.c +62 -0
  183. data/src/core/lib/support/fork.h +35 -0
  184. data/src/core/lib/support/log_linux.c +1 -1
  185. data/src/core/lib/support/string.c +15 -1
  186. data/src/core/lib/support/string.h +3 -0
  187. data/src/core/lib/support/thd_internal.h +6 -0
  188. data/src/core/lib/support/thd_posix.c +56 -0
  189. data/src/core/lib/support/thd_windows.c +2 -0
  190. data/src/core/lib/surface/alarm.c +22 -15
  191. data/src/core/lib/surface/byte_buffer.c +4 -2
  192. data/src/core/lib/surface/call.c +442 -141
  193. data/src/core/lib/surface/call.h +6 -6
  194. data/src/core/lib/surface/call_log_batch.c +1 -1
  195. data/src/core/lib/surface/call_test_only.h +12 -0
  196. data/src/core/lib/surface/channel.c +39 -4
  197. data/src/core/lib/surface/channel_init.c +6 -6
  198. data/src/core/lib/surface/channel_ping.c +2 -2
  199. data/src/core/lib/surface/completion_queue.c +56 -57
  200. data/src/core/lib/surface/init.c +17 -3
  201. data/src/core/lib/surface/init_secure.c +5 -1
  202. data/src/core/lib/surface/lame_client.cc +9 -10
  203. data/src/core/lib/surface/server.c +81 -72
  204. data/src/core/lib/surface/version.c +2 -2
  205. data/src/core/lib/transport/byte_stream.c +1 -0
  206. data/src/core/lib/transport/byte_stream.h +3 -1
  207. data/src/core/lib/transport/connectivity_state.c +2 -1
  208. data/src/core/lib/transport/metadata.c +7 -4
  209. data/src/core/lib/transport/metadata_batch.c +18 -16
  210. data/src/core/lib/transport/metadata_batch.h +1 -0
  211. data/src/core/lib/transport/service_config.c +5 -3
  212. data/src/core/lib/transport/static_metadata.c +395 -614
  213. data/src/core/lib/transport/static_metadata.h +165 -133
  214. data/src/core/lib/transport/status_conversion.c +1 -1
  215. data/src/core/lib/transport/transport.c +20 -20
  216. data/src/core/lib/transport/transport.h +8 -5
  217. data/src/core/lib/transport/transport_impl.h +0 -3
  218. data/src/core/lib/transport/transport_op_string.c +8 -1
  219. data/src/core/plugin_registry/grpc_plugin_registry.c +4 -4
  220. data/src/core/tsi/fake_transport_security.c +133 -2
  221. data/src/core/tsi/fake_transport_security.h +5 -0
  222. data/src/core/tsi/ssl_transport_security.c +105 -8
  223. data/src/core/tsi/ssl_transport_security.h +30 -7
  224. data/src/core/tsi/transport_security.h +8 -2
  225. data/src/core/tsi/transport_security_grpc.c +20 -13
  226. data/src/core/tsi/transport_security_grpc.h +13 -9
  227. data/src/ruby/ext/grpc/rb_call_credentials.c +6 -2
  228. data/src/ruby/ext/grpc/rb_grpc.c +1 -1
  229. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +30 -20
  230. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +50 -35
  231. data/src/ruby/lib/grpc.rb +1 -0
  232. data/src/ruby/lib/grpc/generic/active_call.rb +34 -9
  233. data/src/ruby/lib/grpc/generic/bidi_call.rb +19 -10
  234. data/src/ruby/lib/grpc/generic/client_stub.rb +95 -38
  235. data/src/ruby/lib/grpc/generic/interceptor_registry.rb +53 -0
  236. data/src/ruby/lib/grpc/generic/interceptors.rb +186 -0
  237. data/src/ruby/lib/grpc/generic/rpc_desc.rb +66 -20
  238. data/src/ruby/lib/grpc/generic/rpc_server.rb +15 -3
  239. data/src/ruby/lib/grpc/google_rpc_status_utils.rb +1 -2
  240. data/src/ruby/lib/grpc/version.rb +1 -1
  241. data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services_pb.rb +1 -0
  242. data/src/ruby/spec/channel_connection_spec.rb +1 -34
  243. data/src/ruby/spec/client_server_spec.rb +188 -82
  244. data/src/ruby/spec/generic/active_call_spec.rb +65 -11
  245. data/src/ruby/spec/generic/client_interceptors_spec.rb +153 -0
  246. data/src/ruby/spec/generic/interceptor_registry_spec.rb +65 -0
  247. data/src/ruby/spec/generic/rpc_desc_spec.rb +38 -0
  248. data/src/ruby/spec/generic/rpc_server_spec.rb +1 -34
  249. data/src/ruby/spec/generic/server_interceptors_spec.rb +218 -0
  250. data/src/ruby/spec/spec_helper.rb +4 -0
  251. data/src/ruby/spec/support/helpers.rb +73 -0
  252. data/src/ruby/spec/support/services.rb +147 -0
  253. data/third_party/cares/ares_build.h +21 -62
  254. data/third_party/cares/cares/ares.h +23 -1
  255. data/third_party/cares/cares/ares__close_sockets.c +2 -2
  256. data/third_party/cares/cares/ares_create_query.c +3 -3
  257. data/third_party/cares/cares/ares_expand_name.c +6 -2
  258. data/third_party/cares/cares/ares_expand_string.c +1 -1
  259. data/third_party/cares/cares/ares_getnameinfo.c +27 -7
  260. data/third_party/cares/cares/ares_init.c +407 -39
  261. data/third_party/cares/cares/ares_library_init.c +10 -0
  262. data/third_party/cares/cares/ares_library_init.h +2 -1
  263. data/third_party/cares/cares/ares_nowarn.c +6 -6
  264. data/third_party/cares/cares/ares_nowarn.h +2 -2
  265. data/third_party/cares/cares/ares_parse_naptr_reply.c +6 -1
  266. data/third_party/cares/cares/ares_private.h +11 -0
  267. data/third_party/cares/cares/ares_process.c +126 -37
  268. data/third_party/cares/cares/ares_version.h +2 -2
  269. data/third_party/cares/cares/ares_writev.c +2 -2
  270. data/third_party/cares/cares/config-win32.h +8 -34
  271. data/third_party/cares/cares/inet_net_pton.c +2 -2
  272. data/third_party/cares/cares/setup_once.h +5 -5
  273. data/third_party/cares/config_darwin/ares_config.h +98 -196
  274. data/third_party/cares/config_linux/ares_config.h +103 -203
  275. metadata +47 -20
  276. data/src/core/lib/iomgr/ev_epoll_limited_pollers_linux.c +0 -1957
  277. data/src/core/lib/iomgr/ev_epoll_thread_pool_linux.c +0 -1182
@@ -11,8 +11,7 @@
11
11
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
-
15
- require 'grpc'
14
+ require 'spec_helper'
16
15
 
17
16
  def load_test_certs
18
17
  test_root = File.join(File.dirname(File.dirname(__FILE__)), 'testdata')
@@ -28,17 +27,6 @@ def check_md(wanted_md, received_md)
28
27
  end
29
28
  end
30
29
 
31
- # A test message
32
- class EchoMsg
33
- def self.marshal(_o)
34
- ''
35
- end
36
-
37
- def self.unmarshal(_o)
38
- EchoMsg.new
39
- end
40
- end
41
-
42
30
  # A test service with no methods.
43
31
  class EmptyService
44
32
  include GRPC::GenericService
@@ -50,27 +38,6 @@ class NoRpcImplementation
50
38
  rpc :an_rpc, EchoMsg, EchoMsg
51
39
  end
52
40
 
53
- # A test service with an echo implementation.
54
- class EchoService
55
- include GRPC::GenericService
56
- rpc :an_rpc, EchoMsg, EchoMsg
57
- attr_reader :received_md
58
-
59
- def initialize(**kw)
60
- @trailing_metadata = kw
61
- @received_md = []
62
- end
63
-
64
- def an_rpc(req, call)
65
- GRPC.logger.info('echo service received a request')
66
- call.output_metadata.update(@trailing_metadata)
67
- @received_md << call.metadata unless call.metadata.nil?
68
- req
69
- end
70
- end
71
-
72
- EchoStub = EchoService.rpc_stub_class
73
-
74
41
  # A test service with an implementation that fails with BadStatus
75
42
  class FailingService
76
43
  include GRPC::GenericService
@@ -0,0 +1,218 @@
1
+ # Copyright 2017 gRPC authors.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ require 'spec_helper'
15
+
16
+ describe 'Server Interceptors' do
17
+ let(:interceptor) { TestServerInterceptor.new }
18
+ let(:request) { EchoMsg.new }
19
+ let(:trailing_metadata) { {} }
20
+ let(:service) { EchoService.new(trailing_metadata) }
21
+ let(:interceptors) { [] }
22
+
23
+ before(:each) do
24
+ build_rpc_server(server_opts: { interceptors: interceptors })
25
+ end
26
+
27
+ context 'when a server interceptor is added' do
28
+ let(:interceptors) { [interceptor] }
29
+ let(:client_metadata) { { client_md: 'test' } }
30
+ let(:client_call_opts) { { metadata: client_metadata, return_op: true } }
31
+
32
+ context 'with a request/response call' do
33
+ let(:trailing_metadata) { { server_om: 'from_request_response' } }
34
+
35
+ it 'should be called', server: true do
36
+ expect(interceptor).to receive(:request_response)
37
+ .once.and_call_original
38
+
39
+ run_services_on_server(@server, services: [service]) do
40
+ stub = build_insecure_stub(EchoStub)
41
+ expect(stub.an_rpc(request)).to be_a(EchoMsg)
42
+ end
43
+ end
44
+
45
+ it 'can modify trailing metadata', server: true do
46
+ expect(interceptor).to receive(:request_response)
47
+ .once.and_call_original
48
+
49
+ run_services_on_server(@server, services: [service]) do
50
+ stub = build_insecure_stub(EchoStub)
51
+ expect_any_instance_of(GRPC::ActiveCall).to(
52
+ receive(:request_response).with(request, metadata: client_metadata)
53
+ .once.and_call_original
54
+ )
55
+ op = stub.an_rpc(request, client_call_opts)
56
+ msg = op.execute
57
+ expect(op.trailing_metadata).to eq(
58
+ 'interc' => 'from_request_response',
59
+ 'server_om' => 'from_request_response'
60
+ )
61
+ expect(msg).to be_a(EchoMsg)
62
+ end
63
+ end
64
+ end
65
+
66
+ context 'with a client streaming call' do
67
+ let(:trailing_metadata) { { server_om: 'from_client_streamer' } }
68
+ let(:requests) { [EchoMsg.new, EchoMsg.new] }
69
+
70
+ it 'should be called', server: true do
71
+ expect(interceptor).to receive(:client_streamer)
72
+ .once.and_call_original
73
+
74
+ run_services_on_server(@server, services: [service]) do
75
+ stub = build_insecure_stub(EchoStub)
76
+ expect(stub.a_client_streaming_rpc(requests)).to be_a(EchoMsg)
77
+ end
78
+ end
79
+
80
+ it 'can modify trailing metadata', server: true do
81
+ expect(interceptor).to receive(:client_streamer)
82
+ .once.and_call_original
83
+
84
+ run_services_on_server(@server, services: [service]) do
85
+ stub = build_insecure_stub(EchoStub)
86
+ expect_any_instance_of(GRPC::ActiveCall).to(
87
+ receive(:client_streamer).with(requests)
88
+ .once.and_call_original
89
+ )
90
+ op = stub.a_client_streaming_rpc(requests, client_call_opts)
91
+ msg = op.execute
92
+ expect(op.trailing_metadata).to eq(
93
+ 'interc' => 'from_client_streamer',
94
+ 'server_om' => 'from_client_streamer'
95
+ )
96
+ expect(msg).to be_a(EchoMsg)
97
+ end
98
+ end
99
+ end
100
+
101
+ context 'with a server streaming call' do
102
+ let(:trailing_metadata) { { server_om: 'from_server_streamer' } }
103
+ let(:request) { EchoMsg.new }
104
+
105
+ it 'should be called', server: true do
106
+ expect(interceptor).to receive(:server_streamer)
107
+ .once.and_call_original
108
+
109
+ run_services_on_server(@server, services: [service]) do
110
+ stub = build_insecure_stub(EchoStub)
111
+ responses = stub.a_server_streaming_rpc(request)
112
+ responses.each do |r|
113
+ expect(r).to be_a(EchoMsg)
114
+ end
115
+ end
116
+ end
117
+
118
+ it 'can modify trailing metadata', server: true do
119
+ expect(interceptor).to receive(:server_streamer)
120
+ .once.and_call_original
121
+
122
+ run_services_on_server(@server, services: [service]) do
123
+ stub = build_insecure_stub(EchoStub)
124
+ expect_any_instance_of(GRPC::ActiveCall).to(
125
+ receive(:server_streamer).with(request)
126
+ .once.and_call_original
127
+ )
128
+ op = stub.a_server_streaming_rpc(request, client_call_opts)
129
+ responses = op.execute
130
+ responses.each do |r|
131
+ expect(r).to be_a(EchoMsg)
132
+ end
133
+ expect(op.trailing_metadata).to eq(
134
+ 'interc' => 'from_server_streamer',
135
+ 'server_om' => 'from_server_streamer'
136
+ )
137
+ end
138
+ end
139
+ end
140
+
141
+ context 'with a bidi call' do
142
+ let(:trailing_metadata) { { server_om: 'from_bidi_streamer' } }
143
+ let(:requests) { [EchoMsg.new, EchoMsg.new] }
144
+
145
+ it 'should be called', server: true do
146
+ expect(interceptor).to receive(:bidi_streamer)
147
+ .once.and_call_original
148
+
149
+ run_services_on_server(@server, services: [service]) do
150
+ stub = build_insecure_stub(EchoStub)
151
+ responses = stub.a_bidi_rpc(requests)
152
+ responses.each do |r|
153
+ expect(r).to be_a(EchoMsg)
154
+ end
155
+ end
156
+ end
157
+
158
+ it 'can modify trailing metadata', server: true do
159
+ expect(interceptor).to receive(:bidi_streamer)
160
+ .once.and_call_original
161
+
162
+ run_services_on_server(@server, services: [service]) do
163
+ stub = build_insecure_stub(EchoStub)
164
+ expect_any_instance_of(GRPC::ActiveCall).to(
165
+ receive(:bidi_streamer).with(requests)
166
+ .once.and_call_original
167
+ )
168
+ op = stub.a_bidi_rpc(requests, client_call_opts)
169
+ responses = op.execute
170
+ responses.each do |r|
171
+ expect(r).to be_a(EchoMsg)
172
+ end
173
+ expect(op.trailing_metadata).to eq(
174
+ 'interc' => 'from_bidi_streamer',
175
+ 'server_om' => 'from_bidi_streamer'
176
+ )
177
+ end
178
+ end
179
+ end
180
+ end
181
+
182
+ context 'when multiple interceptors are added' do
183
+ let(:interceptor2) { TestServerInterceptor.new }
184
+ let(:interceptor3) { TestServerInterceptor.new }
185
+ let(:interceptors) do
186
+ [
187
+ interceptor,
188
+ interceptor2,
189
+ interceptor3
190
+ ]
191
+ end
192
+
193
+ it 'each should be called', server: true do
194
+ expect(interceptor).to receive(:request_response)
195
+ .once.and_call_original
196
+ expect(interceptor2).to receive(:request_response)
197
+ .once.and_call_original
198
+ expect(interceptor3).to receive(:request_response)
199
+ .once.and_call_original
200
+
201
+ run_services_on_server(@server, services: [service]) do
202
+ stub = build_insecure_stub(EchoStub)
203
+ expect(stub.an_rpc(request)).to be_a(EchoMsg)
204
+ end
205
+ end
206
+ end
207
+
208
+ context 'when an interceptor is not added' do
209
+ it 'should not be called', server: true do
210
+ expect(interceptor).to_not receive(:call)
211
+
212
+ run_services_on_server(@server, services: [service]) do
213
+ stub = build_insecure_stub(EchoStub)
214
+ expect(stub.an_rpc(request)).to be_a(EchoMsg)
215
+ end
216
+ end
217
+ end
218
+ end
@@ -32,6 +32,9 @@ require 'rspec'
32
32
  require 'logging'
33
33
  require 'rspec/logging_helper'
34
34
 
35
+ require_relative 'support/services'
36
+ require_relative 'support/helpers'
37
+
35
38
  # GRPC is the general RPC module
36
39
  #
37
40
  # Configure its logging for fine-grained log control during test runs
@@ -49,6 +52,7 @@ Logging.logger['GRPC::BidiCall'].level = :info
49
52
  RSpec.configure do |config|
50
53
  include RSpec::LoggingHelper
51
54
  config.capture_log_messages # comment this out to see logs during test runs
55
+ include GRPC::Spec::Helpers
52
56
  end
53
57
 
54
58
  RSpec::Expectations.configuration.warn_about_potential_false_positives = false
@@ -0,0 +1,73 @@
1
+ # Copyright 2017 gRPC authors.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ # GRPC contains the General RPC module.
16
+ module GRPC
17
+ ##
18
+ # GRPC RSpec base module
19
+ #
20
+ module Spec
21
+ ##
22
+ # A module that is used for providing generic helpers across the
23
+ # GRPC test suite
24
+ #
25
+ module Helpers
26
+ # Shortcut syntax for a GRPC RPC Server
27
+ RpcServer = GRPC::RpcServer
28
+
29
+ ##
30
+ # Build an RPC server used for testing
31
+ #
32
+ def build_rpc_server(server_opts: {},
33
+ client_opts: {})
34
+ @server = RpcServer.new({ poll_period: 1 }.merge(server_opts))
35
+ @port = @server.add_http2_port('0.0.0.0:0', :this_port_is_insecure)
36
+ @host = "0.0.0.0:#{@port}"
37
+ @client_opts = client_opts
38
+ @server
39
+ end
40
+
41
+ ##
42
+ # Run services on an RPC server, yielding to allow testing within
43
+ #
44
+ # @param [RpcServer] server
45
+ # @param [Array<Class>] services
46
+ #
47
+ def run_services_on_server(server, services: [])
48
+ services.each do |s|
49
+ server.handle(s)
50
+ end
51
+ t = Thread.new { server.run }
52
+ server.wait_till_running
53
+
54
+ yield
55
+
56
+ server.stop
57
+ t.join
58
+ end
59
+
60
+ ##
61
+ # Build an insecure stub from a given stub class
62
+ #
63
+ # @param [Class] klass
64
+ # @param [String] host
65
+ #
66
+ def build_insecure_stub(klass, host: nil, opts: nil)
67
+ host ||= @host
68
+ opts ||= @client_opts
69
+ klass.new(host, :this_channel_is_insecure, **opts)
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,147 @@
1
+ # Copyright 2017 gRPC authors.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ # Test stubs for various scenarios
16
+ require 'grpc'
17
+
18
+ # A test message
19
+ class EchoMsg
20
+ def self.marshal(_o)
21
+ ''
22
+ end
23
+
24
+ def self.unmarshal(_o)
25
+ EchoMsg.new
26
+ end
27
+ end
28
+
29
+ # A test service with an echo implementation.
30
+ class EchoService
31
+ include GRPC::GenericService
32
+ rpc :an_rpc, EchoMsg, EchoMsg
33
+ rpc :a_client_streaming_rpc, stream(EchoMsg), EchoMsg
34
+ rpc :a_server_streaming_rpc, EchoMsg, stream(EchoMsg)
35
+ rpc :a_bidi_rpc, stream(EchoMsg), stream(EchoMsg)
36
+ attr_reader :received_md
37
+
38
+ def initialize(**kw)
39
+ @trailing_metadata = kw
40
+ @received_md = []
41
+ end
42
+
43
+ def an_rpc(req, call)
44
+ GRPC.logger.info('echo service received a request')
45
+ call.output_metadata.update(@trailing_metadata)
46
+ @received_md << call.metadata unless call.metadata.nil?
47
+ req
48
+ end
49
+
50
+ def a_client_streaming_rpc(call)
51
+ # iterate through requests so call can complete
52
+ call.output_metadata.update(@trailing_metadata)
53
+ call.each_remote_read.each { |r| p r }
54
+ EchoMsg.new
55
+ end
56
+
57
+ def a_server_streaming_rpc(_req, call)
58
+ call.output_metadata.update(@trailing_metadata)
59
+ [EchoMsg.new, EchoMsg.new]
60
+ end
61
+
62
+ def a_bidi_rpc(requests, call)
63
+ call.output_metadata.update(@trailing_metadata)
64
+ requests.each { |r| p r }
65
+ [EchoMsg.new, EchoMsg.new]
66
+ end
67
+ end
68
+
69
+ EchoStub = EchoService.rpc_stub_class
70
+
71
+ # For testing server interceptors
72
+ class TestServerInterceptor < GRPC::ServerInterceptor
73
+ def request_response(request:, call:, method:)
74
+ p "Received request/response call at method #{method}" \
75
+ " with request #{request} for call #{call}"
76
+ call.output_metadata[:interc] = 'from_request_response'
77
+ p "[GRPC::Ok] (#{method.owner.name}.#{method.name})"
78
+ yield
79
+ end
80
+
81
+ def client_streamer(call:, method:)
82
+ call.output_metadata[:interc] = 'from_client_streamer'
83
+ call.each_remote_read.each do |r|
84
+ p "In interceptor: #{r}"
85
+ end
86
+ p "Received client streamer call at method #{method} for call #{call}"
87
+ yield
88
+ end
89
+
90
+ def server_streamer(request:, call:, method:)
91
+ p "Received server streamer call at method #{method} with request" \
92
+ " #{request} for call #{call}"
93
+ call.output_metadata[:interc] = 'from_server_streamer'
94
+ yield
95
+ end
96
+
97
+ def bidi_streamer(requests:, call:, method:)
98
+ requests.each do |r|
99
+ p "Bidi request: #{r}"
100
+ end
101
+ p "Received bidi streamer call at method #{method} with requests" \
102
+ " #{requests} for call #{call}"
103
+ call.output_metadata[:interc] = 'from_bidi_streamer'
104
+ yield
105
+ end
106
+ end
107
+
108
+ # For testing client interceptors
109
+ class TestClientInterceptor < GRPC::ClientInterceptor
110
+ def request_response(request:, call:, method:, metadata: {})
111
+ p "Intercepted request/response call at method #{method}" \
112
+ " with request #{request} for call #{call}" \
113
+ " and metadata: #{metadata}"
114
+ metadata['foo'] = 'bar_from_request_response'
115
+ yield
116
+ end
117
+
118
+ def client_streamer(requests:, call:, method:, metadata: {})
119
+ p "Received client streamer call at method #{method}" \
120
+ " with requests #{requests} for call #{call}" \
121
+ " and metadata: #{metadata}"
122
+ requests.each do |r|
123
+ p "In client interceptor: #{r}"
124
+ end
125
+ metadata['foo'] = 'bar_from_client_streamer'
126
+ yield
127
+ end
128
+
129
+ def server_streamer(request:, call:, method:, metadata: {})
130
+ p "Received server streamer call at method #{method}" \
131
+ " with request #{request} for call #{call}" \
132
+ " and metadata: #{metadata}"
133
+ metadata['foo'] = 'bar_from_server_streamer'
134
+ yield
135
+ end
136
+
137
+ def bidi_streamer(requests:, call:, method:, metadata: {})
138
+ p "Received bidi streamer call at method #{method}" \
139
+ "with requests #{requests} for call #{call}" \
140
+ " and metadata: #{metadata}"
141
+ requests.each do |r|
142
+ p "In client interceptor: #{r}"
143
+ end
144
+ metadata['foo'] = 'bar_from_bidi_streamer'
145
+ yield
146
+ end
147
+ end