@Override
  public ManagedChannel shutdownNow() {
    ArrayList<ManagedChannel> channels = new ArrayList<>();
    synchronized (this) {
      shutdownStarted = true;
      channels.addAll(usedChannels);
      channels.addAll(channelCache);
    }
    for (ManagedChannel channel : channels) {
      channel.shutdownNow();
    }
    return this;
  }
@Test
  public void testShutdownNow() throws Exception {
    ManagedChannel mockChannel = mock(ManagedChannel.class);
    when(channelSupplier.get()).thenReturn(mockChannel);
    ClientCall<Object, Object> mockCall1 = mock(ClientCall.class);
    ClientCall<Object, Object> mockCall2 = mock(ClientCall.class);
    when(mockChannel.newCall(any(), any())).thenReturn(mockCall1, mockCall2);

    IsolationChannel isolationChannel = IsolationChannel.create(channelSupplier);
    ClientCall<Object, Object> call1 =
        isolationChannel.newCall(methodDescriptor, CallOptions.DEFAULT);
    call1.start(new NoopClientCall.NoopClientCallListener<>(), new Metadata());
    ArgumentCaptor<Listener<Object>> captor1 = ArgumentCaptor.forClass(ClientCall.Listener.class);
    verify(mockCall1).start(captor1.capture(), any());

    when(mockChannel.shutdownNow()).thenReturn(mockChannel);
    when(mockChannel.isShutdown()).thenReturn(false, true);

    isolationChannel.shutdownNow();
    assertFalse(isolationChannel.isShutdown());

    ClientCall<Object, Object> call2 =
        isolationChannel.newCall(methodDescriptor, CallOptions.DEFAULT);
    call2.start(new NoopClientCall.NoopClientCallListener<>(), new Metadata());
    ArgumentCaptor<Listener<Object>> captor2 = ArgumentCaptor.forClass(ClientCall.Listener.class);
    verify(mockCall2).start(captor2.capture(), any());

    captor1.getValue().onClose(Status.CANCELLED, new Metadata());
    captor2.getValue().onClose(Status.CANCELLED, new Metadata());

    assertTrue(isolationChannel.isShutdown());

    verify(channelSupplier, times(1)).get();
    verify(mockChannel, times(2)).newCall(any(), any());
    verify(mockChannel, times(1)).shutdownNow();
    verify(mockChannel, times(2)).isShutdown();
  }