2020import static com .google .common .truth .extensions .proto .ProtoTruth .assertThat ;
2121import static org .junit .Assert .assertThrows ;
2222
23- import io .grpc .CallOptions ;
2423import io .grpc .Channel ;
2524import io .grpc .ChannelCredentials ;
26- import io .grpc .ClientCall ;
2725import io .grpc .InsecureChannelCredentials ;
2826import io .grpc .ManagedChannel ;
29- import io .grpc .MethodDescriptor ;
3027import io .grpc .Server ;
3128import io .grpc .ServerBuilder ;
3229import io .grpc .ServerCredentials ;
3633import io .grpc .benchmarks .Utils ;
3734import io .grpc .internal .SharedResourceHolder .Resource ;
3835import io .grpc .netty .NettyServerBuilder ;
39- import io .grpc .s2a .internal .channel .S2AHandshakerServiceChannel .HandshakerServiceChannel ;
4036import io .grpc .stub .StreamObserver ;
4137import io .grpc .testing .GrpcCleanupRule ;
4238import io .grpc .testing .protobuf .SimpleRequest ;
4339import io .grpc .testing .protobuf .SimpleResponse ;
4440import io .grpc .testing .protobuf .SimpleServiceGrpc ;
4541import java .io .File ;
46- import java .util .concurrent .TimeUnit ;
4742import org .junit .Before ;
4843import org .junit .ClassRule ;
4944import org .junit .Test ;
@@ -183,72 +178,7 @@ public void close_mtlsSuccess() throws Exception {
183178 }
184179
185180 /**
186- * Verifies that an {@code HandshakerServiceChannel}'s {@code newCall} method can be used to
187- * perform a simple RPC.
188- */
189- @ Test
190- public void newCall_performSimpleRpcSuccess () {
191- Resource <Channel > resource =
192- S2AHandshakerServiceChannel .getChannelResource (
193- "localhost:" + plaintextServer .getPort (),
194- InsecureChannelCredentials .create ());
195- Channel channel = resource .create ();
196- assertThat (channel ).isInstanceOf (HandshakerServiceChannel .class );
197- assertThat (
198- SimpleServiceGrpc .newBlockingStub (channel ).unaryRpc (SimpleRequest .getDefaultInstance ()))
199- .isEqualToDefaultInstance ();
200- }
201-
202- /** Same as newCall_performSimpleRpcSuccess, but use mTLS. */
203- @ Test
204- public void newCall_mtlsPerformSimpleRpcSuccess () throws Exception {
205- Resource <Channel > resource =
206- S2AHandshakerServiceChannel .getChannelResource (
207- "localhost:" + mtlsServer .getPort (), getTlsChannelCredentials ());
208- Channel channel = resource .create ();
209- assertThat (channel ).isInstanceOf (HandshakerServiceChannel .class );
210- assertThat (
211- SimpleServiceGrpc .newBlockingStub (channel ).unaryRpc (SimpleRequest .getDefaultInstance ()))
212- .isEqualToDefaultInstance ();
213- }
214-
215- /** Creates a {@code HandshakerServiceChannel} instance and verifies its authority. */
216- @ Test
217- public void authority_success () throws Exception {
218- ManagedChannel channel = new FakeManagedChannel (true );
219- HandshakerServiceChannel eventLoopHoldingChannel =
220- HandshakerServiceChannel .create (channel );
221- assertThat (eventLoopHoldingChannel .authority ()).isEqualTo ("FakeManagedChannel" );
222- }
223-
224- /**
225- * Creates and closes a {@code HandshakerServiceChannel} when its {@code ManagedChannel}
226- * terminates successfully.
227- */
228- @ Test
229- public void close_withDelegateTerminatedSuccess () throws Exception {
230- ManagedChannel channel = new FakeManagedChannel (true );
231- HandshakerServiceChannel eventLoopHoldingChannel =
232- HandshakerServiceChannel .create (channel );
233- eventLoopHoldingChannel .close ();
234- assertThat (channel .isShutdown ()).isTrue ();
235- }
236-
237- /**
238- * Creates and closes a {@code HandshakerServiceChannel} when its {@code ManagedChannel} does not
239- * terminate successfully.
240- */
241- @ Test
242- public void close_withDelegateTerminatedFailure () throws Exception {
243- ManagedChannel channel = new FakeManagedChannel (false );
244- HandshakerServiceChannel eventLoopHoldingChannel =
245- HandshakerServiceChannel .create (channel );
246- eventLoopHoldingChannel .close ();
247- assertThat (channel .isShutdown ()).isTrue ();
248- }
249-
250- /**
251- * Creates and closes a {@code HandshakerServiceChannel}, creates a new channel from the same
181+ * Creates and closes a {@code ManagedChannel}, creates a new channel from the same
252182 * resource, and verifies that this second channel is useable.
253183 */
254184 @ Test
@@ -261,7 +191,7 @@ public void create_succeedsAfterCloseIsCalledOnce() throws Exception {
261191 resource .close (channelOne );
262192
263193 Channel channelTwo = resource .create ();
264- assertThat (channelTwo ).isInstanceOf (HandshakerServiceChannel .class );
194+ assertThat (channelTwo ).isInstanceOf (ManagedChannel .class );
265195 assertThat (
266196 SimpleServiceGrpc .newBlockingStub (channelTwo )
267197 .unaryRpc (SimpleRequest .getDefaultInstance ()))
@@ -279,7 +209,7 @@ public void create_mtlsSucceedsAfterCloseIsCalledOnce() throws Exception {
279209 resource .close (channelOne );
280210
281211 Channel channelTwo = resource .create ();
282- assertThat (channelTwo ).isInstanceOf (HandshakerServiceChannel .class );
212+ assertThat (channelTwo ).isInstanceOf (ManagedChannel .class );
283213 assertThat (
284214 SimpleServiceGrpc .newBlockingStub (channelTwo )
285215 .unaryRpc (SimpleRequest .getDefaultInstance ()))
@@ -325,53 +255,4 @@ public void unaryRpc(SimpleRequest request, StreamObserver<SimpleResponse> strea
325255 streamObserver .onCompleted ();
326256 }
327257 }
328-
329- private static class FakeManagedChannel extends ManagedChannel {
330- private final boolean isDelegateTerminatedSuccess ;
331- private boolean isShutdown = false ;
332-
333- FakeManagedChannel (boolean isDelegateTerminatedSuccess ) {
334- this .isDelegateTerminatedSuccess = isDelegateTerminatedSuccess ;
335- }
336-
337- @ Override
338- public String authority () {
339- return "FakeManagedChannel" ;
340- }
341-
342- @ Override
343- public <ReqT , RespT > ClientCall <ReqT , RespT > newCall (
344- MethodDescriptor <ReqT , RespT > methodDescriptor , CallOptions options ) {
345- throw new UnsupportedOperationException ("This method should not be called." );
346- }
347-
348- @ Override
349- public ManagedChannel shutdown () {
350- throw new UnsupportedOperationException ("This method should not be called." );
351- }
352-
353- @ Override
354- public boolean isShutdown () {
355- return isShutdown ;
356- }
357-
358- @ Override
359- public boolean isTerminated () {
360- throw new UnsupportedOperationException ("This method should not be called." );
361- }
362-
363- @ Override
364- public ManagedChannel shutdownNow () {
365- isShutdown = true ;
366- return null ;
367- }
368-
369- @ Override
370- public boolean awaitTermination (long timeout , TimeUnit unit ) throws InterruptedException {
371- if (isDelegateTerminatedSuccess ) {
372- return true ;
373- }
374- throw new InterruptedException ("Await termination was interrupted." );
375- }
376- }
377258}
0 commit comments