11/*
2- * Copyright (c) 2019, 2020 Oracle and/or its affiliates.
2+ * Copyright (c) 2019, 2023 Oracle and/or its affiliates.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
3333
3434import com .oracle .bedrock .runtime .LocalPlatform ;
3535import com .oracle .bedrock .runtime .network .AvailablePortIterator ;
36- import io .grpc .Channel ;
3736import io .grpc .ManagedChannel ;
3837import io .grpc .StatusRuntimeException ;
3938import io .grpc .netty .GrpcSslContexts ;
4039import io .grpc .netty .NegotiationType ;
4140import io .grpc .netty .NettyChannelBuilder ;
4241import io .netty .handler .ssl .SslContext ;
4342import io .netty .handler .ssl .SslContextBuilder ;
44- import org .junit .AfterClass ;
43+ import org .junit .jupiter . api . AfterAll ;
4544import org .junit .jupiter .api .Assertions ;
4645import org .junit .jupiter .api .BeforeAll ;
4746import org .junit .jupiter .api .Test ;
@@ -86,7 +85,7 @@ public class SslIT {
8685 // ----- test lifecycle -------------------------------------------------
8786
8887 @ BeforeAll
89- public static void setup () throws Exception {
88+ public static void setup () {
9089 LogConfig .configureRuntime ();
9190
9291 AvailablePortIterator ports = LocalPlatform .get ().getAvailablePorts ();
@@ -100,7 +99,7 @@ public static void setup() throws Exception {
10099 grpcServer_2WaySSLConfig = startGrpcServer (port2WaySSLConfig , true /*mutual*/ , true /*useConfig*/ );
101100 }
102101
103- @ AfterClass
102+ @ AfterAll
104103 public static void cleanup () throws Exception
105104 {
106105 CompletableFuture <?>[] futures =
@@ -120,7 +119,7 @@ public void shouldConnectWithoutClientCertsFor1Way() throws Exception {
120119 // client do not have to provide certs for 1way ssl
121120 SslContext sslContext = clientSslContext (tlsCaCert , null , null );
122121
123- Channel channel = NettyChannelBuilder .forAddress ("localhost" , grpcServer_1WaySSL .port ())
122+ ManagedChannel channel = NettyChannelBuilder .forAddress ("localhost" , grpcServer_1WaySSL .port ())
124123 .negotiationType (NegotiationType .TLS )
125124 .sslContext (sslContext )
126125 .build ();
@@ -129,15 +128,15 @@ public void shouldConnectWithoutClientCertsFor1Way() throws Exception {
129128 Echo .EchoResponse response = EchoServiceGrpc .newBlockingStub (channel ).echo (Echo .EchoRequest .newBuilder ().setMessage ("foo" ).build ());
130129 assertThat (response .getMessage (), is ("foo" ));
131130
132- (( ManagedChannel ) channel ) .shutdown ().awaitTermination (5 , TimeUnit .SECONDS );
131+ channel .shutdown ().awaitTermination (5 , TimeUnit .SECONDS );
133132 }
134133
135134 @ Test
136135 public void shouldNotConnectWithoutCAFor1Way () throws Exception {
137136 // client do not have to provide certs for 1way ssl
138137 SslContext sslContext = clientSslContext (null , null , null );
139138
140- Channel channel = NettyChannelBuilder .forAddress ("localhost" , grpcServer_1WaySSL .port ())
139+ ManagedChannel channel = NettyChannelBuilder .forAddress ("localhost" , grpcServer_1WaySSL .port ())
141140 .negotiationType (NegotiationType .TLS )
142141 .sslContext (sslContext )
143142 .build ();
@@ -146,7 +145,7 @@ public void shouldNotConnectWithoutCAFor1Way() throws Exception {
146145 Assertions .assertThrows (StatusRuntimeException .class ,
147146 ()->EchoServiceGrpc .newBlockingStub (channel ).echo (Echo .EchoRequest .newBuilder ().setMessage ("foo" ).build ()));
148147
149- (( ManagedChannel ) channel ) .shutdown ().awaitTermination (5 , TimeUnit .SECONDS );
148+ channel .shutdown ().awaitTermination (5 , TimeUnit .SECONDS );
150149 }
151150
152151 @ Test
@@ -157,7 +156,7 @@ public void shouldConnectWithClientCertsFor2Way() throws Exception {
157156
158157 SslContext sslContext = clientSslContext (tlsCaCert , tlsClientCert , tlsClientKey );
159158
160- Channel channel = NettyChannelBuilder .forAddress ("localhost" , grpcServer_2WaySSL .port ())
159+ ManagedChannel channel = NettyChannelBuilder .forAddress ("localhost" , grpcServer_2WaySSL .port ())
161160 .negotiationType (NegotiationType .TLS )
162161 .sslContext (sslContext )
163162 .build ();
@@ -166,7 +165,7 @@ public void shouldConnectWithClientCertsFor2Way() throws Exception {
166165 Echo .EchoResponse response = EchoServiceGrpc .newBlockingStub (channel ).echo (Echo .EchoRequest .newBuilder ().setMessage ("foo" ).build ());
167166 assertThat (response .getMessage (), is ("foo" ));
168167
169- (( ManagedChannel ) channel ) .shutdown ().awaitTermination (5 , TimeUnit .SECONDS );
168+ channel .shutdown ().awaitTermination (5 , TimeUnit .SECONDS );
170169 }
171170
172171 @ Test
@@ -175,7 +174,7 @@ public void shouldNotConnectWithoutCAFor2Way() throws Exception {
175174 Resource tlsClientKey = Resource .create (CLIENT_KEY );
176175 SslContext sslContext = clientSslContext (null , tlsClientCert , tlsClientKey );
177176
178- Channel channel = NettyChannelBuilder .forAddress ("localhost" , grpcServer_2WaySSL .port ())
177+ ManagedChannel channel = NettyChannelBuilder .forAddress ("localhost" , grpcServer_2WaySSL .port ())
179178 .negotiationType (NegotiationType .TLS )
180179 .sslContext (sslContext )
181180 .build ();
@@ -184,7 +183,7 @@ public void shouldNotConnectWithoutCAFor2Way() throws Exception {
184183 Assertions .assertThrows (StatusRuntimeException .class ,
185184 ()->EchoServiceGrpc .newBlockingStub (channel ).echo (Echo .EchoRequest .newBuilder ().setMessage ("foo" ).build ()));
186185
187- (( ManagedChannel ) channel ) .shutdown ().awaitTermination (5 , TimeUnit .SECONDS );
186+ channel .shutdown ().awaitTermination (5 , TimeUnit .SECONDS );
188187 }
189188
190189 @ Test
@@ -193,7 +192,7 @@ public void shouldNotConnectWithoutClientCertFor2Way() throws Exception {
193192 Resource tlsClientKey = Resource .create (CLIENT_KEY );
194193 SslContext sslContext = clientSslContext (tlsCaCert , null , tlsClientKey );
195194
196- Channel channel = NettyChannelBuilder .forAddress ("localhost" , grpcServer_2WaySSL .port ())
195+ ManagedChannel channel = NettyChannelBuilder .forAddress ("localhost" , grpcServer_2WaySSL .port ())
197196 .negotiationType (NegotiationType .TLS )
198197 .sslContext (sslContext )
199198 .build ();
@@ -202,7 +201,7 @@ public void shouldNotConnectWithoutClientCertFor2Way() throws Exception {
202201 Assertions .assertThrows (StatusRuntimeException .class ,
203202 ()->EchoServiceGrpc .newBlockingStub (channel ).echo (Echo .EchoRequest .newBuilder ().setMessage ("foo" ).build ()));
204203
205- (( ManagedChannel ) channel ) .shutdown ().awaitTermination (5 , TimeUnit .SECONDS );
204+ channel .shutdown ().awaitTermination (5 , TimeUnit .SECONDS );
206205 }
207206
208207 @ Test
@@ -212,7 +211,7 @@ public void shouldConnectWithClientCertsFor2WayUseConfig() throws Exception{
212211 Resource tlsClientKey = Resource .create (CLIENT_KEY );
213212 SslContext sslContext = clientSslContext (tlsCaCert , tlsClientCert , tlsClientKey );
214213
215- Channel channel = NettyChannelBuilder .forAddress ("localhost" , grpcServer_2WaySSLConfig .port ())
214+ ManagedChannel channel = NettyChannelBuilder .forAddress ("localhost" , grpcServer_2WaySSLConfig .port ())
216215 .negotiationType (NegotiationType .TLS )
217216 .sslContext (sslContext )
218217 .build ();
@@ -221,7 +220,7 @@ public void shouldConnectWithClientCertsFor2WayUseConfig() throws Exception{
221220 Echo .EchoResponse response = EchoServiceGrpc .newBlockingStub (channel ).echo (Echo .EchoRequest .newBuilder ().setMessage ("foo" ).build ());
222221 assertThat (response .getMessage (), is ("foo" ));
223222
224- (( ManagedChannel ) channel ) .shutdown ().awaitTermination (5 , TimeUnit .SECONDS );
223+ channel .shutdown ().awaitTermination (5 , TimeUnit .SECONDS );
225224 }
226225
227226 @ Test
@@ -230,7 +229,7 @@ public void shouldNotConnectWithoutClientCertFor2WayUseConfig() throws Exception
230229 Resource tlsClientKey = Resource .create (CLIENT_KEY );
231230 SslContext sslContext = clientSslContext (tlsCaCert , null , tlsClientKey );
232231
233- Channel channel = NettyChannelBuilder .forAddress ("localhost" , grpcServer_2WaySSLConfig .port ())
232+ ManagedChannel channel = NettyChannelBuilder .forAddress ("localhost" , grpcServer_2WaySSLConfig .port ())
234233 .negotiationType (NegotiationType .TLS )
235234 .sslContext (sslContext )
236235 .build ();
@@ -239,7 +238,7 @@ public void shouldNotConnectWithoutClientCertFor2WayUseConfig() throws Exception
239238 Assertions .assertThrows (StatusRuntimeException .class ,
240239 ()->EchoServiceGrpc .newBlockingStub (channel ).echo (Echo .EchoRequest .newBuilder ().setMessage ("foo" ).build ()));
241240
242- (( ManagedChannel ) channel ) .shutdown ().awaitTermination (5 , TimeUnit .SECONDS );
241+ channel .shutdown ().awaitTermination (5 , TimeUnit .SECONDS );
243242 }
244243
245244 // ----- helper methods -------------------------------------------------
@@ -260,10 +259,8 @@ private static SslContext clientSslContext(Resource trustCertCollectionFilePath,
260259
261260 /**
262261 * Start the gRPC Server listening on the specified nPort.
263- *
264- * @throws Exception in case of an error
265262 */
266- private static GrpcServer startGrpcServer (int nPort , boolean mutual , boolean useConfig ) throws Exception {
263+ private static GrpcServer startGrpcServer (int nPort , boolean mutual , boolean useConfig ) {
267264 Resource tlsCert = Resource .create (SERVER_CERT );
268265 Resource tlsKey = Resource .create (SERVER_KEY );
269266 Resource tlsCaCert = Resource .create (CA_CERT );
0 commit comments