grpc 1.6.7-x86-mingw32 → 1.7.0.pre1-x86-mingw32

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 (36) hide show
  1. checksums.yaml +4 -4
  2. data/grpc_c.32.ruby +0 -0
  3. data/grpc_c.64.ruby +0 -0
  4. data/src/ruby/ext/grpc/rb_call_credentials.c +6 -2
  5. data/src/ruby/ext/grpc/rb_grpc.c +1 -1
  6. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +30 -20
  7. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +50 -35
  8. data/src/ruby/lib/grpc.rb +1 -0
  9. data/src/ruby/lib/grpc/2.0/grpc_c.so +0 -0
  10. data/src/ruby/lib/grpc/2.1/grpc_c.so +0 -0
  11. data/src/ruby/lib/grpc/2.2/grpc_c.so +0 -0
  12. data/src/ruby/lib/grpc/2.3/grpc_c.so +0 -0
  13. data/src/ruby/lib/grpc/2.4/grpc_c.so +0 -0
  14. data/src/ruby/lib/grpc/generic/active_call.rb +34 -9
  15. data/src/ruby/lib/grpc/generic/bidi_call.rb +19 -10
  16. data/src/ruby/lib/grpc/generic/client_stub.rb +95 -38
  17. data/src/ruby/lib/grpc/generic/interceptor_registry.rb +53 -0
  18. data/src/ruby/lib/grpc/generic/interceptors.rb +186 -0
  19. data/src/ruby/lib/grpc/generic/rpc_desc.rb +66 -20
  20. data/src/ruby/lib/grpc/generic/rpc_server.rb +15 -3
  21. data/src/ruby/lib/grpc/google_rpc_status_utils.rb +1 -2
  22. data/src/ruby/lib/grpc/grpc_c.so +0 -0
  23. data/src/ruby/lib/grpc/version.rb +1 -1
  24. data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services_pb.rb +1 -0
  25. data/src/ruby/spec/channel_connection_spec.rb +1 -34
  26. data/src/ruby/spec/client_server_spec.rb +188 -82
  27. data/src/ruby/spec/generic/active_call_spec.rb +65 -11
  28. data/src/ruby/spec/generic/client_interceptors_spec.rb +153 -0
  29. data/src/ruby/spec/generic/interceptor_registry_spec.rb +65 -0
  30. data/src/ruby/spec/generic/rpc_desc_spec.rb +38 -0
  31. data/src/ruby/spec/generic/rpc_server_spec.rb +1 -34
  32. data/src/ruby/spec/generic/server_interceptors_spec.rb +218 -0
  33. data/src/ruby/spec/spec_helper.rb +4 -0
  34. data/src/ruby/spec/support/helpers.rb +73 -0
  35. data/src/ruby/spec/support/services.rb +147 -0
  36. metadata +24 -12
@@ -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