grpc 1.42.0.pre1-x86_64-darwin

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 (128) hide show
  1. checksums.yaml +7 -0
  2. data/etc/roots.pem +4337 -0
  3. data/grpc_c.32.ruby +0 -0
  4. data/grpc_c.64.ruby +0 -0
  5. data/src/ruby/bin/math_client.rb +140 -0
  6. data/src/ruby/bin/math_pb.rb +34 -0
  7. data/src/ruby/bin/math_server.rb +191 -0
  8. data/src/ruby/bin/math_services_pb.rb +51 -0
  9. data/src/ruby/bin/noproto_client.rb +93 -0
  10. data/src/ruby/bin/noproto_server.rb +97 -0
  11. data/src/ruby/ext/grpc/ext-export.clang +1 -0
  12. data/src/ruby/ext/grpc/ext-export.gcc +6 -0
  13. data/src/ruby/ext/grpc/extconf.rb +123 -0
  14. data/src/ruby/ext/grpc/rb_byte_buffer.c +65 -0
  15. data/src/ruby/ext/grpc/rb_byte_buffer.h +35 -0
  16. data/src/ruby/ext/grpc/rb_call.c +1051 -0
  17. data/src/ruby/ext/grpc/rb_call.h +57 -0
  18. data/src/ruby/ext/grpc/rb_call_credentials.c +341 -0
  19. data/src/ruby/ext/grpc/rb_call_credentials.h +31 -0
  20. data/src/ruby/ext/grpc/rb_channel.c +846 -0
  21. data/src/ruby/ext/grpc/rb_channel.h +34 -0
  22. data/src/ruby/ext/grpc/rb_channel_args.c +155 -0
  23. data/src/ruby/ext/grpc/rb_channel_args.h +38 -0
  24. data/src/ruby/ext/grpc/rb_channel_credentials.c +286 -0
  25. data/src/ruby/ext/grpc/rb_channel_credentials.h +37 -0
  26. data/src/ruby/ext/grpc/rb_completion_queue.c +101 -0
  27. data/src/ruby/ext/grpc/rb_completion_queue.h +36 -0
  28. data/src/ruby/ext/grpc/rb_compression_options.c +471 -0
  29. data/src/ruby/ext/grpc/rb_compression_options.h +29 -0
  30. data/src/ruby/ext/grpc/rb_enable_cpp.cc +22 -0
  31. data/src/ruby/ext/grpc/rb_event_thread.c +145 -0
  32. data/src/ruby/ext/grpc/rb_event_thread.h +21 -0
  33. data/src/ruby/ext/grpc/rb_grpc.c +333 -0
  34. data/src/ruby/ext/grpc/rb_grpc.h +77 -0
  35. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +605 -0
  36. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +913 -0
  37. data/src/ruby/ext/grpc/rb_loader.c +57 -0
  38. data/src/ruby/ext/grpc/rb_loader.h +25 -0
  39. data/src/ruby/ext/grpc/rb_server.c +385 -0
  40. data/src/ruby/ext/grpc/rb_server.h +32 -0
  41. data/src/ruby/ext/grpc/rb_server_credentials.c +259 -0
  42. data/src/ruby/ext/grpc/rb_server_credentials.h +37 -0
  43. data/src/ruby/ext/grpc/rb_xds_channel_credentials.c +218 -0
  44. data/src/ruby/ext/grpc/rb_xds_channel_credentials.h +37 -0
  45. data/src/ruby/ext/grpc/rb_xds_server_credentials.c +170 -0
  46. data/src/ruby/ext/grpc/rb_xds_server_credentials.h +37 -0
  47. data/src/ruby/lib/grpc/2.4/grpc_c.bundle +0 -0
  48. data/src/ruby/lib/grpc/2.5/grpc_c.bundle +0 -0
  49. data/src/ruby/lib/grpc/2.6/grpc_c.bundle +0 -0
  50. data/src/ruby/lib/grpc/2.7/grpc_c.bundle +0 -0
  51. data/src/ruby/lib/grpc/3.0/grpc_c.bundle +0 -0
  52. data/src/ruby/lib/grpc/core/status_codes.rb +135 -0
  53. data/src/ruby/lib/grpc/core/time_consts.rb +56 -0
  54. data/src/ruby/lib/grpc/errors.rb +277 -0
  55. data/src/ruby/lib/grpc/generic/active_call.rb +669 -0
  56. data/src/ruby/lib/grpc/generic/bidi_call.rb +233 -0
  57. data/src/ruby/lib/grpc/generic/client_stub.rb +503 -0
  58. data/src/ruby/lib/grpc/generic/interceptor_registry.rb +53 -0
  59. data/src/ruby/lib/grpc/generic/interceptors.rb +186 -0
  60. data/src/ruby/lib/grpc/generic/rpc_desc.rb +204 -0
  61. data/src/ruby/lib/grpc/generic/rpc_server.rb +551 -0
  62. data/src/ruby/lib/grpc/generic/service.rb +211 -0
  63. data/src/ruby/lib/grpc/google_rpc_status_utils.rb +40 -0
  64. data/src/ruby/lib/grpc/grpc.rb +24 -0
  65. data/src/ruby/lib/grpc/logconfig.rb +44 -0
  66. data/src/ruby/lib/grpc/notifier.rb +45 -0
  67. data/src/ruby/lib/grpc/structs.rb +15 -0
  68. data/src/ruby/lib/grpc/version.rb +18 -0
  69. data/src/ruby/lib/grpc.rb +37 -0
  70. data/src/ruby/pb/README.md +42 -0
  71. data/src/ruby/pb/generate_proto_ruby.sh +51 -0
  72. data/src/ruby/pb/grpc/health/checker.rb +75 -0
  73. data/src/ruby/pb/grpc/health/v1/health_pb.rb +31 -0
  74. data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +62 -0
  75. data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services_pb.rb +44 -0
  76. data/src/ruby/pb/grpc/testing/metrics_pb.rb +28 -0
  77. data/src/ruby/pb/grpc/testing/metrics_services_pb.rb +49 -0
  78. data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +17 -0
  79. data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +145 -0
  80. data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +16 -0
  81. data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +152 -0
  82. data/src/ruby/pb/test/client.rb +769 -0
  83. data/src/ruby/pb/test/server.rb +252 -0
  84. data/src/ruby/pb/test/xds_client.rb +415 -0
  85. data/src/ruby/spec/call_credentials_spec.rb +42 -0
  86. data/src/ruby/spec/call_spec.rb +180 -0
  87. data/src/ruby/spec/channel_connection_spec.rb +126 -0
  88. data/src/ruby/spec/channel_credentials_spec.rb +124 -0
  89. data/src/ruby/spec/channel_spec.rb +245 -0
  90. data/src/ruby/spec/client_auth_spec.rb +152 -0
  91. data/src/ruby/spec/client_server_spec.rb +664 -0
  92. data/src/ruby/spec/compression_options_spec.rb +149 -0
  93. data/src/ruby/spec/debug_message_spec.rb +134 -0
  94. data/src/ruby/spec/error_sanity_spec.rb +49 -0
  95. data/src/ruby/spec/errors_spec.rb +142 -0
  96. data/src/ruby/spec/generic/active_call_spec.rb +683 -0
  97. data/src/ruby/spec/generic/client_interceptors_spec.rb +153 -0
  98. data/src/ruby/spec/generic/client_stub_spec.rb +1083 -0
  99. data/src/ruby/spec/generic/interceptor_registry_spec.rb +65 -0
  100. data/src/ruby/spec/generic/rpc_desc_spec.rb +374 -0
  101. data/src/ruby/spec/generic/rpc_server_pool_spec.rb +127 -0
  102. data/src/ruby/spec/generic/rpc_server_spec.rb +748 -0
  103. data/src/ruby/spec/generic/server_interceptors_spec.rb +218 -0
  104. data/src/ruby/spec/generic/service_spec.rb +263 -0
  105. data/src/ruby/spec/google_rpc_status_utils_spec.rb +282 -0
  106. data/src/ruby/spec/pb/codegen/grpc/testing/package_options.proto +28 -0
  107. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import.proto +22 -0
  108. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import2.proto +23 -0
  109. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_ruby_style.proto +41 -0
  110. data/src/ruby/spec/pb/codegen/grpc/testing/same_package_service_name.proto +27 -0
  111. data/src/ruby/spec/pb/codegen/grpc/testing/same_ruby_package_service_name.proto +29 -0
  112. data/src/ruby/spec/pb/codegen/package_option_spec.rb +98 -0
  113. data/src/ruby/spec/pb/duplicate/codegen_spec.rb +57 -0
  114. data/src/ruby/spec/pb/health/checker_spec.rb +236 -0
  115. data/src/ruby/spec/server_credentials_spec.rb +104 -0
  116. data/src/ruby/spec/server_spec.rb +231 -0
  117. data/src/ruby/spec/spec_helper.rb +61 -0
  118. data/src/ruby/spec/support/helpers.rb +107 -0
  119. data/src/ruby/spec/support/services.rb +160 -0
  120. data/src/ruby/spec/testdata/README +1 -0
  121. data/src/ruby/spec/testdata/ca.pem +20 -0
  122. data/src/ruby/spec/testdata/client.key +28 -0
  123. data/src/ruby/spec/testdata/client.pem +20 -0
  124. data/src/ruby/spec/testdata/server1.key +28 -0
  125. data/src/ruby/spec/testdata/server1.pem +22 -0
  126. data/src/ruby/spec/time_consts_spec.rb +74 -0
  127. data/src/ruby/spec/user_agent_spec.rb +74 -0
  128. metadata +404 -0
@@ -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
@@ -0,0 +1,263 @@
1
+ # Copyright 2015 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
+ require 'spec_helper'
16
+ require 'grpc/generic/rpc_desc'
17
+ require 'grpc/generic/service'
18
+
19
+ # A test message that encodes/decodes using marshal/marshal.
20
+ class GoodMsg
21
+ def self.marshal(_o)
22
+ ''
23
+ end
24
+
25
+ def self.unmarshal(_o)
26
+ GoodMsg.new
27
+ end
28
+ end
29
+
30
+ # A test message that encodes/decodes using encode/decode.
31
+ class EncodeDecodeMsg
32
+ def self.encode(_o)
33
+ ''
34
+ end
35
+
36
+ def self.decode(_o)
37
+ GoodMsg.new
38
+ end
39
+ end
40
+
41
+ GenericService = GRPC::GenericService
42
+ Dsl = GenericService::Dsl
43
+
44
+ describe Dsl do
45
+ it 'can be included in new classes' do
46
+ blk = proc { Class.new { include Dsl } }
47
+ expect(&blk).to_not raise_error
48
+ end
49
+ end
50
+
51
+ describe GenericService do
52
+ context '#underscore' do
53
+ it 'should convert CamelCase to underscore separated' do
54
+ expect(GenericService.underscore('AnRPC')).to eq('an_rpc')
55
+ expect(GenericService.underscore('AMethod')).to eq('a_method')
56
+ expect(GenericService.underscore('PrintHTML')).to eq('print_html')
57
+ expect(GenericService.underscore('SeeHTMLBooks')).to eq('see_html_books')
58
+
59
+ expect(GenericService.underscore('SeeHTMLBooks'.freeze)).to eq('see_html_books')
60
+ end
61
+ end
62
+
63
+ describe 'including it' do
64
+ it 'adds a class method, rpc' do
65
+ c = Class.new do
66
+ include GenericService
67
+ end
68
+ expect(c.methods).to include(:rpc)
69
+ end
70
+
71
+ it 'adds rpc descs using the added class method, #rpc' do
72
+ c = Class.new do
73
+ include GenericService
74
+ rpc :AnRpc, GoodMsg, GoodMsg
75
+ end
76
+
77
+ expect(c.rpc_descs).to include(:AnRpc)
78
+ expect(c.rpc_descs[:AnRpc]).to be_a(GRPC::RpcDesc)
79
+ end
80
+
81
+ it 'give subclasses access to #rpc_descs' do
82
+ base = Class.new do
83
+ include GenericService
84
+ rpc :AnRpc, GoodMsg, GoodMsg
85
+ end
86
+ c = Class.new(base) do
87
+ end
88
+ expect(c.rpc_descs).to include(:AnRpc)
89
+ expect(c.rpc_descs[:AnRpc]).to be_a(GRPC::RpcDesc)
90
+ end
91
+
92
+ it 'adds a default service name' do
93
+ c = Class.new do
94
+ include GenericService
95
+ end
96
+ expect(c.service_name).to eq('GenericService')
97
+ end
98
+
99
+ it 'adds a default service name to subclasses' do
100
+ base = Class.new do
101
+ include GenericService
102
+ end
103
+ c = Class.new(base) do
104
+ end
105
+ expect(c.service_name).to eq('GenericService')
106
+ end
107
+
108
+ it 'adds the specified service name' do
109
+ c = Class.new do
110
+ include GenericService
111
+ self.service_name = 'test.service.TestService'
112
+ end
113
+ expect(c.service_name).to eq('test.service.TestService')
114
+ end
115
+
116
+ it 'adds the specified service name to subclasses' do
117
+ base = Class.new do
118
+ include GenericService
119
+ self.service_name = 'test.service.TestService'
120
+ end
121
+ c = Class.new(base) do
122
+ end
123
+ expect(c.service_name).to eq('test.service.TestService')
124
+ end
125
+ end
126
+
127
+ describe '#include' do
128
+ it 'raises if #rpc is missing an arg' do
129
+ blk = proc do
130
+ Class.new do
131
+ include GenericService
132
+ rpc :AnRpc, GoodMsg
133
+ end
134
+ end
135
+ expect(&blk).to raise_error ArgumentError
136
+
137
+ blk = proc do
138
+ Class.new do
139
+ include GenericService
140
+ rpc :AnRpc
141
+ end
142
+ end
143
+ expect(&blk).to raise_error ArgumentError
144
+ end
145
+
146
+ describe 'when #rpc args are incorrect' do
147
+ it 'raises if an arg does not have the marshal or unmarshal methods' do
148
+ blk = proc do
149
+ Class.new do
150
+ include GenericService
151
+ rpc :AnRpc, GoodMsg, Object
152
+ end
153
+ end
154
+ expect(&blk).to raise_error ArgumentError
155
+ end
156
+
157
+ it 'raises if a type arg only has the marshal method' do
158
+ # a bad message type with only a marshal method
159
+ class OnlyMarshal
160
+ def marshal(o)
161
+ o
162
+ end
163
+ end
164
+
165
+ blk = proc do
166
+ Class.new do
167
+ include GenericService
168
+ rpc :AnRpc, OnlyMarshal, GoodMsg
169
+ end
170
+ end
171
+ expect(&blk).to raise_error ArgumentError
172
+ end
173
+
174
+ it 'raises if a type arg only has the unmarshal method' do
175
+ # a bad message type with only an unmarshal method
176
+ class OnlyUnmarshal
177
+ def self.ummarshal(o)
178
+ o
179
+ end
180
+ end
181
+ blk = proc do
182
+ Class.new do
183
+ include GenericService
184
+ rpc :AnRpc, GoodMsg, OnlyUnmarshal
185
+ end
186
+ end
187
+ expect(&blk).to raise_error ArgumentError
188
+ end
189
+ end
190
+
191
+ it 'is ok for services that expect the default {un,}marshal methods' do
192
+ blk = proc do
193
+ Class.new do
194
+ include GenericService
195
+ rpc :AnRpc, GoodMsg, GoodMsg
196
+ end
197
+ end
198
+ expect(&blk).not_to raise_error
199
+ end
200
+
201
+ it 'is ok for services that override the default {un,}marshal methods' do
202
+ blk = proc do
203
+ Class.new do
204
+ include GenericService
205
+ self.marshal_class_method = :encode
206
+ self.unmarshal_class_method = :decode
207
+ rpc :AnRpc, EncodeDecodeMsg, EncodeDecodeMsg
208
+ end
209
+ end
210
+ expect(&blk).not_to raise_error
211
+ end
212
+ end
213
+
214
+ describe '#rpc_stub_class' do
215
+ it 'generates a client class that defines any of the rpc methods' do
216
+ s = Class.new do
217
+ include GenericService
218
+ rpc :AnRpc, GoodMsg, GoodMsg
219
+ rpc :AServerStreamer, GoodMsg, stream(GoodMsg)
220
+ rpc :AClientStreamer, stream(GoodMsg), GoodMsg
221
+ rpc :ABidiStreamer, stream(GoodMsg), stream(GoodMsg)
222
+ end
223
+ client_class = s.rpc_stub_class
224
+ expect(client_class.instance_methods).to include(:an_rpc)
225
+ expect(client_class.instance_methods).to include(:a_server_streamer)
226
+ expect(client_class.instance_methods).to include(:a_client_streamer)
227
+ expect(client_class.instance_methods).to include(:a_bidi_streamer)
228
+ end
229
+
230
+ describe 'the generated instances' do
231
+ it 'can be instanciated with just a hostname and credentials' do
232
+ s = Class.new do
233
+ include GenericService
234
+ rpc :AnRpc, GoodMsg, GoodMsg
235
+ rpc :AServerStreamer, GoodMsg, stream(GoodMsg)
236
+ rpc :AClientStreamer, stream(GoodMsg), GoodMsg
237
+ rpc :ABidiStreamer, stream(GoodMsg), stream(GoodMsg)
238
+ end
239
+ client_class = s.rpc_stub_class
240
+ blk = proc do
241
+ client_class.new('fakehostname', :this_channel_is_insecure)
242
+ end
243
+ expect(&blk).not_to raise_error
244
+ end
245
+
246
+ it 'has the methods defined in the service' do
247
+ s = Class.new do
248
+ include GenericService
249
+ rpc :AnRpc, GoodMsg, GoodMsg
250
+ rpc :AServerStreamer, GoodMsg, stream(GoodMsg)
251
+ rpc :AClientStreamer, stream(GoodMsg), GoodMsg
252
+ rpc :ABidiStreamer, stream(GoodMsg), stream(GoodMsg)
253
+ end
254
+ client_class = s.rpc_stub_class
255
+ o = client_class.new('fakehostname', :this_channel_is_insecure)
256
+ expect(o.methods).to include(:an_rpc)
257
+ expect(o.methods).to include(:a_bidi_streamer)
258
+ expect(o.methods).to include(:a_client_streamer)
259
+ expect(o.methods).to include(:a_bidi_streamer)
260
+ end
261
+ end
262
+ end
263
+ end