grpc 1.58.3-aarch64-linux

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. checksums.yaml +7 -0
  2. data/etc/roots.pem +4337 -0
  3. data/grpc_c.32-msvcrt.ruby +0 -0
  4. data/grpc_c.64-msvcrt.ruby +0 -0
  5. data/grpc_c.64-ucrt.ruby +0 -0
  6. data/src/ruby/bin/math_client.rb +140 -0
  7. data/src/ruby/bin/math_pb.rb +40 -0
  8. data/src/ruby/bin/math_server.rb +191 -0
  9. data/src/ruby/bin/math_services_pb.rb +51 -0
  10. data/src/ruby/bin/noproto_client.rb +93 -0
  11. data/src/ruby/bin/noproto_server.rb +97 -0
  12. data/src/ruby/ext/grpc/ext-export-truffleruby-with-ruby-abi-version.clang +2 -0
  13. data/src/ruby/ext/grpc/ext-export-truffleruby-with-ruby-abi-version.gcc +7 -0
  14. data/src/ruby/ext/grpc/ext-export-with-ruby-abi-version.clang +2 -0
  15. data/src/ruby/ext/grpc/ext-export-with-ruby-abi-version.gcc +7 -0
  16. data/src/ruby/ext/grpc/ext-export.clang +1 -0
  17. data/src/ruby/ext/grpc/ext-export.gcc +6 -0
  18. data/src/ruby/ext/grpc/extconf.rb +208 -0
  19. data/src/ruby/ext/grpc/rb_byte_buffer.c +65 -0
  20. data/src/ruby/ext/grpc/rb_byte_buffer.h +35 -0
  21. data/src/ruby/ext/grpc/rb_call.c +1075 -0
  22. data/src/ruby/ext/grpc/rb_call.h +57 -0
  23. data/src/ruby/ext/grpc/rb_call_credentials.c +340 -0
  24. data/src/ruby/ext/grpc/rb_call_credentials.h +31 -0
  25. data/src/ruby/ext/grpc/rb_channel.c +875 -0
  26. data/src/ruby/ext/grpc/rb_channel.h +35 -0
  27. data/src/ruby/ext/grpc/rb_channel_args.c +170 -0
  28. data/src/ruby/ext/grpc/rb_channel_args.h +42 -0
  29. data/src/ruby/ext/grpc/rb_channel_credentials.c +285 -0
  30. data/src/ruby/ext/grpc/rb_channel_credentials.h +37 -0
  31. data/src/ruby/ext/grpc/rb_completion_queue.c +101 -0
  32. data/src/ruby/ext/grpc/rb_completion_queue.h +36 -0
  33. data/src/ruby/ext/grpc/rb_compression_options.c +470 -0
  34. data/src/ruby/ext/grpc/rb_compression_options.h +29 -0
  35. data/src/ruby/ext/grpc/rb_enable_cpp.cc +22 -0
  36. data/src/ruby/ext/grpc/rb_event_thread.c +161 -0
  37. data/src/ruby/ext/grpc/rb_event_thread.h +22 -0
  38. data/src/ruby/ext/grpc/rb_grpc.c +496 -0
  39. data/src/ruby/ext/grpc/rb_grpc.h +83 -0
  40. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +599 -0
  41. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +904 -0
  42. data/src/ruby/ext/grpc/rb_loader.c +61 -0
  43. data/src/ruby/ext/grpc/rb_loader.h +25 -0
  44. data/src/ruby/ext/grpc/rb_server.c +405 -0
  45. data/src/ruby/ext/grpc/rb_server.h +32 -0
  46. data/src/ruby/ext/grpc/rb_server_credentials.c +258 -0
  47. data/src/ruby/ext/grpc/rb_server_credentials.h +37 -0
  48. data/src/ruby/ext/grpc/rb_xds_channel_credentials.c +217 -0
  49. data/src/ruby/ext/grpc/rb_xds_channel_credentials.h +37 -0
  50. data/src/ruby/ext/grpc/rb_xds_server_credentials.c +169 -0
  51. data/src/ruby/ext/grpc/rb_xds_server_credentials.h +37 -0
  52. data/src/ruby/lib/grpc/2.6/grpc_c.so +0 -0
  53. data/src/ruby/lib/grpc/2.7/grpc_c.so +0 -0
  54. data/src/ruby/lib/grpc/3.0/grpc_c.so +0 -0
  55. data/src/ruby/lib/grpc/3.1/grpc_c.so +0 -0
  56. data/src/ruby/lib/grpc/3.2/grpc_c.so +0 -0
  57. data/src/ruby/lib/grpc/core/status_codes.rb +135 -0
  58. data/src/ruby/lib/grpc/core/time_consts.rb +56 -0
  59. data/src/ruby/lib/grpc/errors.rb +277 -0
  60. data/src/ruby/lib/grpc/generic/active_call.rb +670 -0
  61. data/src/ruby/lib/grpc/generic/bidi_call.rb +237 -0
  62. data/src/ruby/lib/grpc/generic/client_stub.rb +503 -0
  63. data/src/ruby/lib/grpc/generic/interceptor_registry.rb +53 -0
  64. data/src/ruby/lib/grpc/generic/interceptors.rb +186 -0
  65. data/src/ruby/lib/grpc/generic/rpc_desc.rb +204 -0
  66. data/src/ruby/lib/grpc/generic/rpc_server.rb +551 -0
  67. data/src/ruby/lib/grpc/generic/service.rb +211 -0
  68. data/src/ruby/lib/grpc/google_rpc_status_utils.rb +40 -0
  69. data/src/ruby/lib/grpc/grpc.rb +24 -0
  70. data/src/ruby/lib/grpc/logconfig.rb +44 -0
  71. data/src/ruby/lib/grpc/notifier.rb +45 -0
  72. data/src/ruby/lib/grpc/structs.rb +15 -0
  73. data/src/ruby/lib/grpc/version.rb +18 -0
  74. data/src/ruby/lib/grpc.rb +37 -0
  75. data/src/ruby/pb/README.md +42 -0
  76. data/src/ruby/pb/generate_proto_ruby.sh +46 -0
  77. data/src/ruby/pb/grpc/health/checker.rb +75 -0
  78. data/src/ruby/pb/grpc/health/v1/health_pb.rb +42 -0
  79. data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +62 -0
  80. data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services_pb.rb +44 -0
  81. data/src/ruby/pb/grpc/testing/metrics_pb.rb +28 -0
  82. data/src/ruby/pb/grpc/testing/metrics_services_pb.rb +49 -0
  83. data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +38 -0
  84. data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +63 -0
  85. data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +40 -0
  86. data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +152 -0
  87. data/src/ruby/pb/test/client.rb +785 -0
  88. data/src/ruby/pb/test/server.rb +252 -0
  89. data/src/ruby/pb/test/xds_client.rb +415 -0
  90. data/src/ruby/spec/call_credentials_spec.rb +42 -0
  91. data/src/ruby/spec/call_spec.rb +180 -0
  92. data/src/ruby/spec/channel_connection_spec.rb +126 -0
  93. data/src/ruby/spec/channel_credentials_spec.rb +124 -0
  94. data/src/ruby/spec/channel_spec.rb +207 -0
  95. data/src/ruby/spec/client_auth_spec.rb +152 -0
  96. data/src/ruby/spec/client_server_spec.rb +676 -0
  97. data/src/ruby/spec/compression_options_spec.rb +149 -0
  98. data/src/ruby/spec/debug_message_spec.rb +134 -0
  99. data/src/ruby/spec/error_sanity_spec.rb +49 -0
  100. data/src/ruby/spec/errors_spec.rb +142 -0
  101. data/src/ruby/spec/generic/active_call_spec.rb +692 -0
  102. data/src/ruby/spec/generic/client_interceptors_spec.rb +153 -0
  103. data/src/ruby/spec/generic/client_stub_spec.rb +1083 -0
  104. data/src/ruby/spec/generic/interceptor_registry_spec.rb +65 -0
  105. data/src/ruby/spec/generic/rpc_desc_spec.rb +374 -0
  106. data/src/ruby/spec/generic/rpc_server_pool_spec.rb +127 -0
  107. data/src/ruby/spec/generic/rpc_server_spec.rb +748 -0
  108. data/src/ruby/spec/generic/server_interceptors_spec.rb +218 -0
  109. data/src/ruby/spec/generic/service_spec.rb +263 -0
  110. data/src/ruby/spec/google_rpc_status_utils_spec.rb +282 -0
  111. data/src/ruby/spec/pb/codegen/grpc/testing/package_options.proto +28 -0
  112. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import.proto +22 -0
  113. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import2.proto +23 -0
  114. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_ruby_style.proto +41 -0
  115. data/src/ruby/spec/pb/codegen/grpc/testing/same_package_service_name.proto +27 -0
  116. data/src/ruby/spec/pb/codegen/grpc/testing/same_ruby_package_service_name.proto +29 -0
  117. data/src/ruby/spec/pb/codegen/package_option_spec.rb +98 -0
  118. data/src/ruby/spec/pb/duplicate/codegen_spec.rb +57 -0
  119. data/src/ruby/spec/pb/health/checker_spec.rb +236 -0
  120. data/src/ruby/spec/server_credentials_spec.rb +104 -0
  121. data/src/ruby/spec/server_spec.rb +231 -0
  122. data/src/ruby/spec/spec_helper.rb +61 -0
  123. data/src/ruby/spec/support/helpers.rb +107 -0
  124. data/src/ruby/spec/support/services.rb +160 -0
  125. data/src/ruby/spec/testdata/README +1 -0
  126. data/src/ruby/spec/testdata/ca.pem +20 -0
  127. data/src/ruby/spec/testdata/client.key +28 -0
  128. data/src/ruby/spec/testdata/client.pem +20 -0
  129. data/src/ruby/spec/testdata/server1.key +28 -0
  130. data/src/ruby/spec/testdata/server1.pem +22 -0
  131. data/src/ruby/spec/time_consts_spec.rb +74 -0
  132. data/src/ruby/spec/user_agent_spec.rb +74 -0
  133. metadata +406 -0
@@ -0,0 +1,180 @@
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
+
17
+ include GRPC::Core::StatusCodes
18
+
19
+ describe GRPC::Core::WriteFlags do
20
+ it 'should define the known write flag values' do
21
+ m = GRPC::Core::WriteFlags
22
+ expect(m.const_get(:BUFFER_HINT)).to_not be_nil
23
+ expect(m.const_get(:NO_COMPRESS)).to_not be_nil
24
+ end
25
+ end
26
+
27
+ describe GRPC::Core::RpcErrors do
28
+ before(:each) do
29
+ @known_types = {
30
+ OK: 0,
31
+ ERROR: 1,
32
+ NOT_ON_SERVER: 2,
33
+ NOT_ON_CLIENT: 3,
34
+ ALREADY_ACCEPTED: 4,
35
+ ALREADY_INVOKED: 5,
36
+ NOT_INVOKED: 6,
37
+ ALREADY_FINISHED: 7,
38
+ TOO_MANY_OPERATIONS: 8,
39
+ INVALID_FLAGS: 9,
40
+ ErrorMessages: {
41
+ 0 => 'ok',
42
+ 1 => 'unknown error',
43
+ 2 => 'not available on a server',
44
+ 3 => 'not available on a client',
45
+ 4 => 'call is already accepted',
46
+ 5 => 'call is already invoked',
47
+ 6 => 'call is not yet invoked',
48
+ 7 => 'call is already finished',
49
+ 8 => 'outstanding read or write present',
50
+ 9 => 'a bad flag was given'
51
+ }
52
+ }
53
+ end
54
+
55
+ it 'should have symbols for all the known error codes' do
56
+ m = GRPC::Core::RpcErrors
57
+ syms_and_codes = m.constants.collect { |c| [c, m.const_get(c)] }
58
+ expect(Hash[syms_and_codes]).to eq(@known_types)
59
+ end
60
+ end
61
+
62
+ describe GRPC::Core::CallOps do
63
+ before(:each) do
64
+ @known_types = {
65
+ SEND_INITIAL_METADATA: 0,
66
+ SEND_MESSAGE: 1,
67
+ SEND_CLOSE_FROM_CLIENT: 2,
68
+ SEND_STATUS_FROM_SERVER: 3,
69
+ RECV_INITIAL_METADATA: 4,
70
+ RECV_MESSAGE: 5,
71
+ RECV_STATUS_ON_CLIENT: 6,
72
+ RECV_CLOSE_ON_SERVER: 7
73
+ }
74
+ end
75
+
76
+ it 'should have symbols for all the known operation types' do
77
+ m = GRPC::Core::CallOps
78
+ syms_and_codes = m.constants.collect { |c| [c, m.const_get(c)] }
79
+ expect(Hash[syms_and_codes]).to eq(@known_types)
80
+ end
81
+ end
82
+
83
+ describe GRPC::Core::Call do
84
+ let(:test_tag) { Object.new }
85
+ let(:fake_host) { 'localhost:10101' }
86
+
87
+ before(:each) do
88
+ @ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure)
89
+ end
90
+
91
+ describe '#status' do
92
+ it 'can save the status and read it back' do
93
+ call = make_test_call
94
+ sts = Struct::Status.new(OK, 'OK')
95
+ expect { call.status = sts }.not_to raise_error
96
+ expect(call.status).to eq(sts)
97
+ end
98
+
99
+ it 'must be set to a status' do
100
+ call = make_test_call
101
+ bad_sts = Object.new
102
+ expect { call.status = bad_sts }.to raise_error(TypeError)
103
+ end
104
+
105
+ it 'can be set to nil' do
106
+ call = make_test_call
107
+ expect { call.status = nil }.not_to raise_error
108
+ end
109
+ end
110
+
111
+ describe '#metadata' do
112
+ it 'can save the metadata hash and read it back' do
113
+ call = make_test_call
114
+ md = { 'k1' => 'v1', 'k2' => 'v2' }
115
+ expect { call.metadata = md }.not_to raise_error
116
+ expect(call.metadata).to be(md)
117
+ end
118
+
119
+ it 'must be set with a hash' do
120
+ call = make_test_call
121
+ bad_md = Object.new
122
+ expect { call.metadata = bad_md }.to raise_error(TypeError)
123
+ end
124
+
125
+ it 'can be set to nil' do
126
+ call = make_test_call
127
+ expect { call.metadata = nil }.not_to raise_error
128
+ end
129
+ end
130
+
131
+ describe '#set_credentials!' do
132
+ it 'can set a valid CallCredentials object' do
133
+ call = make_test_call
134
+ auth_proc = proc { { 'plugin_key' => 'plugin_value' } }
135
+ creds = GRPC::Core::CallCredentials.new auth_proc
136
+ expect { call.set_credentials! creds }.not_to raise_error
137
+ end
138
+ end
139
+
140
+ describe '#cancel' do
141
+ it 'completes ok' do
142
+ call = make_test_call
143
+ expect { call.cancel }.not_to raise_error
144
+ end
145
+
146
+ it 'completes ok when the call is closed' do
147
+ call = make_test_call
148
+ call.close
149
+ expect { call.cancel }.not_to raise_error
150
+ end
151
+ end
152
+
153
+ describe '#cancel_with_status' do
154
+ it 'completes ok' do
155
+ call = make_test_call
156
+ expect do
157
+ call.cancel_with_status(0, 'test status')
158
+ end.not_to raise_error
159
+ expect do
160
+ call.cancel_with_status(0, nil)
161
+ end.to raise_error(TypeError)
162
+ end
163
+
164
+ it 'completes ok when the call is closed' do
165
+ call = make_test_call
166
+ call.close
167
+ expect do
168
+ call.cancel_with_status(0, 'test status')
169
+ end.not_to raise_error
170
+ end
171
+ end
172
+
173
+ def make_test_call
174
+ @ch.create_call(nil, nil, 'phony_method', nil, deadline)
175
+ end
176
+
177
+ def deadline
178
+ Time.now + 2 # in 2 seconds; arbitrary
179
+ end
180
+ end
@@ -0,0 +1,126 @@
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
+ require 'spec_helper'
15
+ require 'timeout'
16
+
17
+ include Timeout
18
+ include GRPC::Core
19
+ include GRPC::Spec::Helpers
20
+
21
+ def start_server(port = 0)
22
+ @srv = new_rpc_server_for_testing(pool_size: 1)
23
+ server_port = @srv.add_http2_port("localhost:#{port}", :this_port_is_insecure)
24
+ @srv.handle(EchoService)
25
+ @server_thd = Thread.new { @srv.run }
26
+ @srv.wait_till_running
27
+ server_port
28
+ end
29
+
30
+ def stop_server
31
+ expect(@srv.stopped?).to be(false)
32
+ @srv.stop
33
+ @server_thd.join
34
+ expect(@srv.stopped?).to be(true)
35
+ end
36
+
37
+ describe 'channel connection behavior' do
38
+ it 'the client channel handles temporary loss of a transport' do
39
+ port = start_server
40
+ stub = EchoStub.new("localhost:#{port}", :this_channel_is_insecure)
41
+ req = EchoMsg.new
42
+ expect(stub.an_rpc(req)).to be_a(EchoMsg)
43
+ stop_server
44
+ sleep 1
45
+ # TODO(apolcyn) grabbing the same port might fail, is this stable enough?
46
+ start_server(port)
47
+ expect(stub.an_rpc(req)).to be_a(EchoMsg)
48
+ stop_server
49
+ end
50
+
51
+ it 'observably connects and reconnects to transient server' \
52
+ ' when using the channel state API' do
53
+ port = start_server
54
+ ch = GRPC::Core::Channel.new("localhost:#{port}", {},
55
+ :this_channel_is_insecure)
56
+
57
+ expect(ch.connectivity_state).to be(GRPC::Core::ConnectivityStates::IDLE)
58
+
59
+ state = ch.connectivity_state(true)
60
+
61
+ count = 0
62
+ while count < 20 && state != GRPC::Core::ConnectivityStates::READY
63
+ ch.watch_connectivity_state(state, Time.now + 60)
64
+ state = ch.connectivity_state(true)
65
+ count += 1
66
+ end
67
+
68
+ expect(state).to be(GRPC::Core::ConnectivityStates::READY)
69
+
70
+ stop_server
71
+
72
+ state = ch.connectivity_state
73
+
74
+ count = 0
75
+ while count < 20 && state == GRPC::Core::ConnectivityStates::READY
76
+ ch.watch_connectivity_state(state, Time.now + 60)
77
+ state = ch.connectivity_state
78
+ count += 1
79
+ end
80
+
81
+ expect(state).to_not be(GRPC::Core::ConnectivityStates::READY)
82
+
83
+ start_server(port)
84
+
85
+ state = ch.connectivity_state(true)
86
+
87
+ count = 0
88
+ while count < 20 && state != GRPC::Core::ConnectivityStates::READY
89
+ ch.watch_connectivity_state(state, Time.now + 60)
90
+ state = ch.connectivity_state(true)
91
+ count += 1
92
+ end
93
+
94
+ expect(state).to be(GRPC::Core::ConnectivityStates::READY)
95
+
96
+ stop_server
97
+ end
98
+
99
+ it 'concurrent watches on the same channel' do
100
+ timeout(180) do
101
+ port = start_server
102
+ ch = GRPC::Core::Channel.new("localhost:#{port}", {},
103
+ :this_channel_is_insecure)
104
+ stop_server
105
+
106
+ thds = []
107
+ 50.times do
108
+ thds << Thread.new do
109
+ while ch.connectivity_state(true) != ConnectivityStates::READY
110
+ ch.watch_connectivity_state(
111
+ ConnectivityStates::READY, Time.now + 60)
112
+ break
113
+ end
114
+ end
115
+ end
116
+
117
+ sleep 0.01
118
+
119
+ start_server(port)
120
+
121
+ thds.each(&:join)
122
+
123
+ stop_server
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,124 @@
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
+
17
+ describe GRPC::Core::ChannelCredentials do
18
+ ChannelCredentials = GRPC::Core::ChannelCredentials
19
+ CallCredentials = GRPC::Core::CallCredentials
20
+
21
+ def load_test_certs
22
+ test_root = File.join(File.dirname(__FILE__), 'testdata')
23
+ files = ['ca.pem', 'server1.key', 'server1.pem']
24
+ files.map { |f| File.open(File.join(test_root, f)).read }
25
+ end
26
+
27
+ describe '#new' do
28
+ it 'can be constructed with fake inputs' do
29
+ blk = proc { ChannelCredentials.new('root_certs', 'key', 'cert') }
30
+ expect(&blk).not_to raise_error
31
+ end
32
+
33
+ it 'it can be constructed using specific test certificates' do
34
+ certs = load_test_certs
35
+ expect { ChannelCredentials.new(*certs) }.not_to raise_error
36
+ end
37
+
38
+ it 'can be constructed with server roots certs only' do
39
+ root_cert, _, _ = load_test_certs
40
+ expect { ChannelCredentials.new(root_cert) }.not_to raise_error
41
+ end
42
+
43
+ it 'can be constructed with a nil server roots' do
44
+ _, client_key, client_chain = load_test_certs
45
+ blk = proc { ChannelCredentials.new(nil, client_key, client_chain) }
46
+ expect(&blk).not_to raise_error
47
+ end
48
+
49
+ it 'can be constructed with no params' do
50
+ blk = proc { ChannelCredentials.new(nil) }
51
+ expect(&blk).not_to raise_error
52
+ end
53
+
54
+ it 'fails gracefully with constructed with a nil private key' do
55
+ blk = proc { GRPC::Core::ChannelCredentials.new(nil, nil, '') }
56
+ expect(&blk).to raise_error
57
+ end
58
+
59
+ it 'fails gracefully with constructed with a nil cert chain' do
60
+ blk = proc { GRPC::Core::ChannelCredentials.new(nil, '', nil) }
61
+ expect(&blk).to raise_error
62
+ end
63
+
64
+ it 'can be constructed with a fallback credential' do
65
+ blk = proc {
66
+ fallback = GRPC::Core::ChannelCredentials.new
67
+ GRPC::Core::XdsChannelCredentials.new(fallback)
68
+ }
69
+ expect(&blk).not_to raise_error
70
+ end
71
+
72
+ it 'fails gracefully constructed with nil' do
73
+ blk = proc {
74
+ GRPC::Core::XdsChannelCredentials.new(nil)
75
+ }
76
+ expect(&blk).to raise_error TypeError, /expected grpc_channel_credentials/
77
+ end
78
+
79
+ it 'fails gracefully constructed with a non-C-extension object' do
80
+ blk = proc {
81
+ not_a_fallback = 100
82
+ GRPC::Core::XdsChannelCredentials.new(not_a_fallback)
83
+ }
84
+ expect(&blk).to raise_error TypeError, /expected grpc_channel_credentials/
85
+ end
86
+
87
+ it 'fails gracefully constructed with a non-ChannelCredentials object' do
88
+ blk = proc {
89
+ not_a_fallback = GRPC::Core::Channel.new('dummy_host', nil,
90
+ :this_channel_is_insecure)
91
+ GRPC::Core::XdsChannelCredentials.new(not_a_fallback)
92
+ }
93
+ expect(&blk).to raise_error TypeError, /expected grpc_channel_credentials/
94
+ end
95
+ end
96
+
97
+ describe '#compose' do
98
+ it 'can compose with a CallCredentials' do
99
+ certs = load_test_certs
100
+ channel_creds = ChannelCredentials.new(*certs)
101
+ auth_proc = proc { { 'plugin_key' => 'plugin_value' } }
102
+ call_creds = CallCredentials.new auth_proc
103
+ expect { channel_creds.compose call_creds }.not_to raise_error
104
+ end
105
+
106
+ it 'can compose with multiple CallCredentials' do
107
+ certs = load_test_certs
108
+ channel_creds = ChannelCredentials.new(*certs)
109
+ auth_proc = proc { { 'plugin_key' => 'plugin_value' } }
110
+ call_creds1 = CallCredentials.new auth_proc
111
+ call_creds2 = CallCredentials.new auth_proc
112
+ expect do
113
+ channel_creds.compose(call_creds1, call_creds2)
114
+ end.not_to raise_error
115
+ end
116
+
117
+ it 'cannot compose with ChannelCredentials' do
118
+ certs = load_test_certs
119
+ channel_creds1 = ChannelCredentials.new(*certs)
120
+ channel_creds2 = ChannelCredentials.new(*certs)
121
+ expect { channel_creds1.compose channel_creds2 }.to raise_error(TypeError)
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,207 @@
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 'English'
17
+
18
+ def load_test_certs
19
+ test_root = File.join(File.dirname(__FILE__), 'testdata')
20
+ files = ['ca.pem', 'server1.key', 'server1.pem']
21
+ files.map { |f| File.open(File.join(test_root, f)).read }
22
+ end
23
+
24
+ describe GRPC::Core::Channel do
25
+ let(:fake_host) { 'localhost:0' }
26
+
27
+ def create_test_cert
28
+ GRPC::Core::ChannelCredentials.new(load_test_certs[0])
29
+ end
30
+
31
+ shared_examples '#new' do
32
+ it 'take a host name without channel args' do
33
+ blk = proc do
34
+ GRPC::Core::Channel.new('phony_host', nil, :this_channel_is_insecure)
35
+ end
36
+ expect(&blk).not_to raise_error
37
+ end
38
+
39
+ it 'does not take a hash with bad keys as channel args' do
40
+ blk = construct_with_args(Object.new => 1)
41
+ expect(&blk).to raise_error TypeError
42
+ blk = construct_with_args(1 => 1)
43
+ expect(&blk).to raise_error TypeError
44
+ end
45
+
46
+ it 'does not take a hash with bad values as channel args' do
47
+ blk = construct_with_args(symbol: Object.new)
48
+ expect(&blk).to raise_error TypeError
49
+ blk = construct_with_args('1' => {})
50
+ expect(&blk).to raise_error TypeError
51
+ end
52
+
53
+ it 'can take a hash with a symbol key as channel args' do
54
+ blk = construct_with_args(a_symbol: 1)
55
+ expect(&blk).to_not raise_error
56
+ end
57
+
58
+ it 'can take a hash with a string key as channel args' do
59
+ blk = construct_with_args('a_symbol' => 1)
60
+ expect(&blk).to_not raise_error
61
+ end
62
+
63
+ it 'can take a hash with a string value as channel args' do
64
+ blk = construct_with_args(a_symbol: '1')
65
+ expect(&blk).to_not raise_error
66
+ end
67
+
68
+ it 'can take a hash with a symbol value as channel args' do
69
+ blk = construct_with_args(a_symbol: :another_symbol)
70
+ expect(&blk).to_not raise_error
71
+ end
72
+
73
+ it 'can take a hash with a numeric value as channel args' do
74
+ blk = construct_with_args(a_symbol: 1)
75
+ expect(&blk).to_not raise_error
76
+ end
77
+
78
+ it 'can take a hash with many args as channel args' do
79
+ args = Hash[127.times.collect { |x| [x.to_s, x] }]
80
+ blk = construct_with_args(args)
81
+ expect(&blk).to_not raise_error
82
+ end
83
+ end
84
+
85
+ describe '#new for secure channels' do
86
+ def construct_with_args(a)
87
+ proc { GRPC::Core::Channel.new('phony_host', a, create_test_cert) }
88
+ end
89
+
90
+ it_behaves_like '#new'
91
+ end
92
+
93
+ describe '#new for insecure channels' do
94
+ it_behaves_like '#new'
95
+
96
+ def construct_with_args(a)
97
+ proc do
98
+ GRPC::Core::Channel.new('phony_host', a, :this_channel_is_insecure)
99
+ end
100
+ end
101
+ end
102
+
103
+ describe '#new for XDS channels' do
104
+ it_behaves_like '#new'
105
+
106
+ def construct_with_args(a)
107
+ proc do
108
+ xds_creds = GRPC::Core::XdsChannelCredentials.new(create_test_cert)
109
+ GRPC::Core::Channel.new('dummy_host', a, xds_creds)
110
+ end
111
+ end
112
+ end
113
+
114
+ describe '#create_call' do
115
+ it 'creates a call OK' do
116
+ ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure)
117
+
118
+ deadline = Time.now + 5
119
+
120
+ blk = proc do
121
+ ch.create_call(nil, nil, 'phony_method', nil, deadline)
122
+ end
123
+ expect(&blk).to_not raise_error
124
+ end
125
+
126
+ it 'raises an error if called on a closed channel' do
127
+ STDERR.puts "#{Time.now}: begin: raises an error if called on a closed channel"
128
+ ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure)
129
+ STDERR.puts "#{Time.now}: created channel"
130
+ ch.close
131
+ STDERR.puts "#{Time.now}: closed channel"
132
+
133
+ deadline = Time.now + 5
134
+ blk = proc do
135
+ ch.create_call(nil, nil, 'phony_method', nil, deadline)
136
+ STDERR.puts "#{Time.now}: created call"
137
+ end
138
+ expect(&blk).to raise_error(RuntimeError)
139
+ STDERR.puts "#{Time.now}: finished: raises an error if called on a closed channel"
140
+ end
141
+ end
142
+
143
+ describe '#destroy' do
144
+ it 'destroys a channel ok' do
145
+ ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure)
146
+ blk = proc { ch.destroy }
147
+ expect(&blk).to_not raise_error
148
+ end
149
+
150
+ it 'can be called more than once without error' do
151
+ ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure)
152
+ blk = proc { ch.destroy }
153
+ blk.call
154
+ expect(&blk).to_not raise_error
155
+ end
156
+ end
157
+
158
+ describe '#connectivity_state' do
159
+ it 'returns an enum' do
160
+ ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure)
161
+ valid_states = [
162
+ GRPC::Core::ConnectivityStates::IDLE,
163
+ GRPC::Core::ConnectivityStates::CONNECTING,
164
+ GRPC::Core::ConnectivityStates::READY,
165
+ GRPC::Core::ConnectivityStates::TRANSIENT_FAILURE,
166
+ GRPC::Core::ConnectivityStates::FATAL_FAILURE
167
+ ]
168
+
169
+ expect(valid_states).to include(ch.connectivity_state)
170
+ end
171
+
172
+ it 'returns an enum when trying to connect' do
173
+ ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure)
174
+ ch.connectivity_state(true)
175
+ valid_states = [
176
+ GRPC::Core::ConnectivityStates::IDLE,
177
+ GRPC::Core::ConnectivityStates::CONNECTING,
178
+ GRPC::Core::ConnectivityStates::READY,
179
+ GRPC::Core::ConnectivityStates::TRANSIENT_FAILURE,
180
+ GRPC::Core::ConnectivityStates::FATAL_FAILURE
181
+ ]
182
+
183
+ expect(valid_states).to include(ch.connectivity_state)
184
+ end
185
+ end
186
+
187
+ describe '::SSL_TARGET' do
188
+ it 'is a symbol' do
189
+ expect(GRPC::Core::Channel::SSL_TARGET).to be_a(Symbol)
190
+ end
191
+ end
192
+
193
+ describe '#close' do
194
+ it 'closes a channel ok' do
195
+ ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure)
196
+ blk = proc { ch.close }
197
+ expect(&blk).to_not raise_error
198
+ end
199
+
200
+ it 'can be called more than once without error' do
201
+ ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure)
202
+ blk = proc { ch.close }
203
+ blk.call
204
+ expect(&blk).to_not raise_error
205
+ end
206
+ end
207
+ end