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
@@ -12,7 +12,7 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- require 'grpc'
15
+ require 'spec_helper'
16
16
 
17
17
  include GRPC::Core::StatusCodes
18
18
 
@@ -22,6 +22,21 @@ describe GRPC::ActiveCall do
22
22
  CallOps = GRPC::Core::CallOps
23
23
  WriteFlags = GRPC::Core::WriteFlags
24
24
 
25
+ def ok_status
26
+ Struct::Status.new(OK, 'OK')
27
+ end
28
+
29
+ def send_and_receive_close_and_status(client_call, server_call)
30
+ client_call.run_batch(CallOps::SEND_CLOSE_FROM_CLIENT => nil)
31
+ server_call.run_batch(CallOps::RECV_CLOSE_ON_SERVER => nil,
32
+ CallOps::SEND_STATUS_FROM_SERVER => ok_status)
33
+ client_call.run_batch(CallOps::RECV_STATUS_ON_CLIENT => nil)
34
+ end
35
+
36
+ def inner_call_of_active_call(active_call)
37
+ active_call.instance_variable_get(:@call)
38
+ end
39
+
25
40
  before(:each) do
26
41
  @pass_through = proc { |x| x }
27
42
  host = '0.0.0.0:0'
@@ -67,16 +82,26 @@ describe GRPC::ActiveCall do
67
82
  end
68
83
  end
69
84
  end
85
+
86
+ describe '#interceptable' do
87
+ it 'exposes a fixed subset of the ActiveCall.methods' do
88
+ want = %w(deadline)
89
+ v = @client_call.interceptable
90
+ want.each do |w|
91
+ expect(v.methods.include?(w))
92
+ end
93
+ end
94
+ end
70
95
  end
71
96
 
72
97
  describe '#remote_send' do
73
- it 'allows a client to send a payload to the server' do
98
+ it 'allows a client to send a payload to the server', test: true do
74
99
  call = make_test_call
75
100
  ActiveCall.client_invoke(call)
76
- @client_call = ActiveCall.new(call, @pass_through,
77
- @pass_through, deadline)
101
+ client_call = ActiveCall.new(call, @pass_through,
102
+ @pass_through, deadline)
78
103
  msg = 'message is a string'
79
- @client_call.remote_send(msg)
104
+ client_call.remote_send(msg)
80
105
 
81
106
  # check that server rpc new was received
82
107
  recvd_rpc = @server.request_call
@@ -86,8 +111,13 @@ describe GRPC::ActiveCall do
86
111
  # Accept the call, and verify that the server reads the response ok.
87
112
  server_call = ActiveCall.new(recvd_call, @pass_through,
88
113
  @pass_through, deadline,
89
- metadata_received: true)
114
+ metadata_received: true,
115
+ started: false)
90
116
  expect(server_call.remote_read).to eq(msg)
117
+ # finish the call
118
+ server_call.send_initial_metadata
119
+ call.run_batch(CallOps::RECV_INITIAL_METADATA => nil)
120
+ send_and_receive_close_and_status(call, recvd_call)
91
121
  end
92
122
 
93
123
  it 'marshals the payload using the marshal func' do
@@ -109,6 +139,9 @@ describe GRPC::ActiveCall do
109
139
  @pass_through, deadline,
110
140
  metadata_received: true)
111
141
  expect(server_call.remote_read).to eq('marshalled:' + msg)
142
+ # finish the call
143
+ call.run_batch(CallOps::RECV_INITIAL_METADATA => nil)
144
+ send_and_receive_close_and_status(call, recvd_call)
112
145
  end
113
146
 
114
147
  TEST_WRITE_FLAGS = [WriteFlags::BUFFER_HINT, WriteFlags::NO_COMPRESS]
@@ -136,6 +169,9 @@ describe GRPC::ActiveCall do
136
169
  @pass_through, deadline,
137
170
  metadata_received: true)
138
171
  expect(server_call.remote_read).to eq('marshalled:' + msg)
172
+ # finish the call
173
+ server_call.send_status(OK, '', true)
174
+ client_call.receive_and_check_status
139
175
  end
140
176
  end
141
177
  end
@@ -177,7 +213,6 @@ describe GRPC::ActiveCall do
177
213
  @pass_through,
178
214
  @pass_through,
179
215
  deadline)
180
-
181
216
  expect(@client_call.metadata_sent).to eql(true)
182
217
  expect(call).to(
183
218
  receive(:run_batch).with(hash_including(
@@ -291,6 +326,10 @@ describe GRPC::ActiveCall do
291
326
  expect(recvd_rpc.metadata).to_not be_nil
292
327
  expect(recvd_rpc.metadata['k1']).to eq('v1')
293
328
  expect(recvd_rpc.metadata['k2']).to eq('v2')
329
+ # finish the call
330
+ recvd_call.run_batch(CallOps::SEND_INITIAL_METADATA => {})
331
+ call.run_batch(CallOps::RECV_INITIAL_METADATA => nil)
332
+ send_and_receive_close_and_status(call, recvd_call)
294
333
  end
295
334
  end
296
335
 
@@ -324,6 +363,8 @@ describe GRPC::ActiveCall do
324
363
  server_call = expect_server_to_receive(msg)
325
364
  server_call.remote_send('server_response')
326
365
  expect(client_call.remote_read).to eq('server_response')
366
+ send_and_receive_close_and_status(
367
+ call, inner_call_of_active_call(server_call))
327
368
  end
328
369
 
329
370
  it 'saves no metadata when the server adds no metadata' do
@@ -338,6 +379,8 @@ describe GRPC::ActiveCall do
338
379
  expect(client_call.metadata).to be_nil
339
380
  client_call.remote_read
340
381
  expect(client_call.metadata).to eq({})
382
+ send_and_receive_close_and_status(
383
+ call, inner_call_of_active_call(server_call))
341
384
  end
342
385
 
343
386
  it 'saves metadata add by the server' do
@@ -353,6 +396,8 @@ describe GRPC::ActiveCall do
353
396
  client_call.remote_read
354
397
  expected = { 'k1' => 'v1', 'k2' => 'v2' }
355
398
  expect(client_call.metadata).to eq(expected)
399
+ send_and_receive_close_and_status(
400
+ call, inner_call_of_active_call(server_call))
356
401
  end
357
402
 
358
403
  it 'get a status from server when nothing else sent from server' do
@@ -409,6 +454,8 @@ describe GRPC::ActiveCall do
409
454
  server_call = expect_server_to_receive(msg)
410
455
  server_call.remote_send('server_response')
411
456
  expect(client_call.remote_read).to eq('unmarshalled:server_response')
457
+ send_and_receive_close_and_status(
458
+ call, inner_call_of_active_call(server_call))
412
459
  end
413
460
  end
414
461
 
@@ -418,9 +465,11 @@ describe GRPC::ActiveCall do
418
465
  client_call = ActiveCall.new(call, @pass_through,
419
466
  @pass_through, deadline)
420
467
  expect(client_call.each_remote_read).to be_a(Enumerator)
468
+ # finish the call
469
+ client_call.cancel
421
470
  end
422
471
 
423
- it 'the returns an enumerator that can read n responses' do
472
+ it 'the returned enumerator can read n responses' do
424
473
  call = make_test_call
425
474
  ActiveCall.client_invoke(call)
426
475
  client_call = ActiveCall.new(call, @pass_through,
@@ -435,6 +484,8 @@ describe GRPC::ActiveCall do
435
484
  server_call.remote_send(reply)
436
485
  expect(e.next).to eq(reply)
437
486
  end
487
+ send_and_receive_close_and_status(
488
+ call, inner_call_of_active_call(server_call))
438
489
  end
439
490
 
440
491
  it 'the returns an enumerator that stops after an OK Status' do
@@ -453,7 +504,7 @@ describe GRPC::ActiveCall do
453
504
  server_call.remote_send(reply)
454
505
  expect(e.next).to eq(reply)
455
506
  end
456
- server_call.send_status(OK, 'OK')
507
+ server_call.send_status(OK, 'OK', true)
457
508
  expect { e.next }.to raise_error(StopIteration)
458
509
  end
459
510
  end
@@ -568,9 +619,11 @@ describe GRPC::ActiveCall do
568
619
  msgs
569
620
  end
570
621
 
622
+ int_ctx = GRPC::InterceptionContext.new
623
+
571
624
  @server_thread = Thread.new do
572
625
  @server_call.run_server_bidi(
573
- fake_gen_each_reply_with_no_call_param)
626
+ fake_gen_each_reply_with_no_call_param, int_ctx)
574
627
  @server_call.send_status(@server_status)
575
628
  end
576
629
  end
@@ -583,10 +636,11 @@ describe GRPC::ActiveCall do
583
636
  call_param.send_initial_metadata
584
637
  msgs
585
638
  end
639
+ int_ctx = GRPC::InterceptionContext.new
586
640
 
587
641
  @server_thread = Thread.new do
588
642
  @server_call.run_server_bidi(
589
- fake_gen_each_reply_with_call_param)
643
+ fake_gen_each_reply_with_call_param, int_ctx)
590
644
  @server_call.send_status(@server_status)
591
645
  end
592
646
  end
@@ -0,0 +1,153 @@
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 'Client Interceptors' do
17
+ let(:interceptor) { TestClientInterceptor.new }
18
+ let(:interceptors_opts) { { interceptors: [interceptor] } }
19
+ let(:request) { EchoMsg.new }
20
+ let(:service) { EchoService }
21
+
22
+ before(:each) do
23
+ build_rpc_server
24
+ end
25
+
26
+ context 'when a client interceptor is added' do
27
+ context 'with a request/response call' do
28
+ it 'should be called', server: true do
29
+ expect(interceptor).to receive(:request_response)
30
+ .once.and_call_original
31
+
32
+ run_services_on_server(@server, services: [service]) do
33
+ stub = build_insecure_stub(EchoStub, opts: interceptors_opts)
34
+ expect_any_instance_of(GRPC::ActiveCall).to receive(:request_response)
35
+ .once.and_call_original
36
+ expect(stub.an_rpc(request)).to be_a(EchoMsg)
37
+ end
38
+ end
39
+
40
+ it 'can modify outgoing metadata', server: true do
41
+ expect(interceptor).to receive(:request_response)
42
+ .once.and_call_original
43
+
44
+ run_services_on_server(@server, services: [service]) do
45
+ stub = build_insecure_stub(EchoStub, opts: interceptors_opts)
46
+ expect_any_instance_of(GRPC::ActiveCall).to receive(:request_response)
47
+ .with(request, metadata: { 'foo' => 'bar_from_request_response' })
48
+ .once.and_call_original
49
+ expect(stub.an_rpc(request)).to be_a(EchoMsg)
50
+ end
51
+ end
52
+ end
53
+
54
+ context 'with a client streaming call' do
55
+ it 'should be called', server: true do
56
+ expect(interceptor).to receive(:client_streamer)
57
+ .once.and_call_original
58
+
59
+ run_services_on_server(@server, services: [service]) do
60
+ stub = build_insecure_stub(EchoStub, opts: interceptors_opts)
61
+ expect_any_instance_of(GRPC::ActiveCall).to receive(:client_streamer)
62
+ .once.and_call_original
63
+ requests = [EchoMsg.new, EchoMsg.new]
64
+ expect(stub.a_client_streaming_rpc(requests)).to be_a(EchoMsg)
65
+ end
66
+ end
67
+
68
+ it 'can modify outgoing metadata', server: true do
69
+ expect(interceptor).to receive(:client_streamer)
70
+ .once.and_call_original
71
+
72
+ run_services_on_server(@server, services: [service]) do
73
+ stub = build_insecure_stub(EchoStub, opts: interceptors_opts)
74
+ requests = [EchoMsg.new, EchoMsg.new]
75
+ expect_any_instance_of(GRPC::ActiveCall).to receive(:client_streamer)
76
+ .with(requests, metadata: { 'foo' => 'bar_from_client_streamer' })
77
+ .once.and_call_original
78
+ expect(stub.a_client_streaming_rpc(requests)).to be_a(EchoMsg)
79
+ end
80
+ end
81
+ end
82
+
83
+ context 'with a server streaming call' do
84
+ it 'should be called', server: true do
85
+ expect(interceptor).to receive(:server_streamer)
86
+ .once.and_call_original
87
+
88
+ run_services_on_server(@server, services: [service]) do
89
+ stub = build_insecure_stub(EchoStub, opts: interceptors_opts)
90
+ request = EchoMsg.new
91
+ expect_any_instance_of(GRPC::ActiveCall).to receive(:server_streamer)
92
+ .once.and_call_original
93
+ responses = stub.a_server_streaming_rpc(request)
94
+ responses.each do |r|
95
+ expect(r).to be_a(EchoMsg)
96
+ end
97
+ end
98
+ end
99
+
100
+ it 'can modify outgoing metadata', server: true do
101
+ expect(interceptor).to receive(:server_streamer)
102
+ .once.and_call_original
103
+
104
+ run_services_on_server(@server, services: [service]) do
105
+ stub = build_insecure_stub(EchoStub, opts: interceptors_opts)
106
+ request = EchoMsg.new
107
+ expect_any_instance_of(GRPC::ActiveCall).to receive(:server_streamer)
108
+ .with(request, metadata: { 'foo' => 'bar_from_server_streamer' })
109
+ .once.and_call_original
110
+ responses = stub.a_server_streaming_rpc(request)
111
+ responses.each do |r|
112
+ expect(r).to be_a(EchoMsg)
113
+ end
114
+ end
115
+ end
116
+ end
117
+
118
+ context 'with a bidi call' do
119
+ it 'should be called', server: true do
120
+ expect(interceptor).to receive(:bidi_streamer)
121
+ .once.and_call_original
122
+
123
+ run_services_on_server(@server, services: [service]) do
124
+ stub = build_insecure_stub(EchoStub, opts: interceptors_opts)
125
+ expect_any_instance_of(GRPC::ActiveCall).to receive(:bidi_streamer)
126
+ .once.and_call_original
127
+ requests = [EchoMsg.new, EchoMsg.new]
128
+ responses = stub.a_bidi_rpc(requests)
129
+ responses.each do |r|
130
+ expect(r).to be_a(EchoMsg)
131
+ end
132
+ end
133
+ end
134
+
135
+ it 'can modify outgoing metadata', server: true do
136
+ expect(interceptor).to receive(:bidi_streamer)
137
+ .once.and_call_original
138
+
139
+ run_services_on_server(@server, services: [service]) do
140
+ stub = build_insecure_stub(EchoStub, opts: interceptors_opts)
141
+ requests = [EchoMsg.new, EchoMsg.new]
142
+ expect_any_instance_of(GRPC::ActiveCall).to receive(:bidi_streamer)
143
+ .with(requests, metadata: { 'foo' => 'bar_from_bidi_streamer' })
144
+ .once.and_call_original
145
+ responses = stub.a_bidi_rpc(requests)
146
+ responses.each do |r|
147
+ expect(r).to be_a(EchoMsg)
148
+ end
149
+ end
150
+ end
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,65 @@
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 GRPC::InterceptorRegistry do
17
+ let(:server) { RpcServer.new }
18
+ let(:interceptor) { TestServerInterceptor.new }
19
+ let(:interceptors) { [interceptor] }
20
+ let(:registry) { described_class.new(interceptors) }
21
+
22
+ describe 'initialization' do
23
+ subject { registry }
24
+
25
+ context 'with an interceptor extending GRPC::ServerInterceptor' do
26
+ it 'should add the interceptor to the registry' do
27
+ subject
28
+ is = registry.instance_variable_get('@interceptors')
29
+ expect(is.count).to eq 1
30
+ expect(is.first).to eq interceptor
31
+ end
32
+ end
33
+
34
+ context 'with multiple interceptors' do
35
+ let(:interceptor2) { TestServerInterceptor.new }
36
+ let(:interceptor3) { TestServerInterceptor.new }
37
+ let(:interceptors) { [interceptor, interceptor2, interceptor3] }
38
+
39
+ it 'should maintain order of insertion when iterated against' do
40
+ subject
41
+ is = registry.instance_variable_get('@interceptors')
42
+ expect(is.count).to eq 3
43
+ is.each_with_index do |i, idx|
44
+ case idx
45
+ when 0
46
+ expect(i).to eq interceptor
47
+ when 1
48
+ expect(i).to eq interceptor2
49
+ when 2
50
+ expect(i).to eq interceptor3
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ context 'with an interceptor not extending GRPC::ServerInterceptor' do
57
+ let(:interceptor) { Class }
58
+ let(:err) { GRPC::InterceptorRegistry::DescendantError }
59
+
60
+ it 'should raise an InvalidArgument exception' do
61
+ expect { subject }.to raise_error(err)
62
+ end
63
+ end
64
+ end
65
+ end
@@ -52,6 +52,13 @@ describe GRPC::RpcDesc do
52
52
  this_desc.run_server_method(@call, method(:other_error))
53
53
  end
54
54
 
55
+ it 'sends status UNKNOWN if NotImplementedErrors are raised' do
56
+ expect(@call).to receive(:read_unary_request).once.and_return(Object.new)
57
+ expect(@call).to receive(:send_status).once.with(
58
+ UNKNOWN, not_implemented_error_msg, false, metadata: {})
59
+ this_desc.run_server_method(@call, method(:not_implemented))
60
+ end
61
+
55
62
  it 'absorbs CallError with no further action' do
56
63
  expect(@call).to receive(:read_unary_request).once.and_raise(CallError)
57
64
  blk = proc do
@@ -102,6 +109,12 @@ describe GRPC::RpcDesc do
102
109
  @client_streamer.run_server_method(@call, method(:other_error_alt))
103
110
  end
104
111
 
112
+ it 'sends status UNKNOWN if NotImplementedErrors are raised' do
113
+ expect(@call).to receive(:send_status).once.with(
114
+ UNKNOWN, not_implemented_error_msg, false, metadata: {})
115
+ @client_streamer.run_server_method(@call, method(:not_implemented_alt))
116
+ end
117
+
105
118
  it 'absorbs CallError with no further action' do
106
119
  expect(@call).to receive(:server_unary_response).once.and_raise(
107
120
  CallError)
@@ -166,6 +179,14 @@ describe GRPC::RpcDesc do
166
179
  @bidi_streamer.run_server_method(@call, method(:other_error_alt))
167
180
  end
168
181
 
182
+ it 'sends status UNKNOWN if NotImplementedErrors are raised' do
183
+ expect(@call).to receive(:run_server_bidi).and_raise(
184
+ not_implemented_error)
185
+ expect(@call).to receive(:send_status).once.with(
186
+ UNKNOWN, not_implemented_error_msg, false, metadata: {})
187
+ @bidi_streamer.run_server_method(@call, method(:not_implemented_alt))
188
+ end
189
+
169
190
  it 'closes the stream if there no errors' do
170
191
  expect(@call).to receive(:run_server_bidi)
171
192
  expect(@call).to receive(:output_metadata).and_return(fake_md)
@@ -329,8 +350,25 @@ describe GRPC::RpcDesc do
329
350
  fail(ArgumentError, 'other error')
330
351
  end
331
352
 
353
+ def not_implemented(_req, _call)
354
+ fail not_implemented_error
355
+ end
356
+
357
+ def not_implemented_alt(_call)
358
+ fail not_implemented_error
359
+ end
360
+
332
361
  def arg_error_msg(error = nil)
333
362
  error ||= ArgumentError.new('other error')
334
363
  "#{error.class}: #{error.message}"
335
364
  end
365
+
366
+ def not_implemented_error
367
+ NotImplementedError.new('some OS feature not implemented')
368
+ end
369
+
370
+ def not_implemented_error_msg(error = nil)
371
+ error ||= not_implemented_error
372
+ "#{error.class}: #{error.message}"
373
+ end
336
374
  end