ChannelPool extends ManagedChannel { @Override public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { long endTimeNanos = System.nanoTime() + unit.toNanos(timeout); for (ManagedChannel channel : channels) { if (channel.isTerminated()) { continue; } long awaitTimeNanos = endTimeNanos - System.nanoTime(); if (awaitTimeNanos <= 0) { break; } channel.awaitTermination(awaitTimeNanos, TimeUnit.NANOSECONDS); } return isTerminated(); } ChannelPool(ChannelFactory factory, int count); @InternalApi("For internal usage only") static final String extractIdentifier(Metadata trailers); @Override String authority(); @Override ClientCall<ReqT, RespT> newCall(
      MethodDescriptor<ReqT, RespT> methodDescriptor, CallOptions callOptions); int size(); @Override synchronized ManagedChannel shutdown(); @Override boolean isShutdown(); @Override boolean isTerminated(); @Override ManagedChannel shutdownNow(); @Override boolean awaitTermination(long timeout, TimeUnit unit);  }
@Test public void testAwaitTermination() throws IOException, InterruptedException { MockChannelFactory factory = new MockChannelFactory(); ChannelPool pool = new ChannelPool(factory, 1); for (ManagedChannel managedChannel : factory.channels) { when(managedChannel.isTerminated()).thenReturn(false); } pool.awaitTermination(500, TimeUnit.MILLISECONDS); for (ManagedChannel managedChannel : factory.channels) { verify(managedChannel, times(1)).awaitTermination(anyLong(), eq(TimeUnit.NANOSECONDS)); } }