private ConnectionTable mockConnectionTable(final boolean waitUntilReaderExits)
      throws UnknownHostException {
    final ConnectionTable connectionTable = mock(ConnectionTable.class);
    final Distribution distribution = mock(Distribution.class);
    final DistributionManager distributionManager = mock(DistributionManager.class);
    final DMStats dmStats = mock(DMStats.class);
    final CancelCriterion stopper = mock(CancelCriterion.class);
    final SocketCloser socketCloser = mock(SocketCloser.class);
    final TCPConduit tcpConduit = mock(TCPConduit.class);
    final ThreadsMonitoring threadMonitoring = mock(ThreadsMonitoring.class);
    final AbstractExecutor threadMonitoringExecutor = mock(AbstractExecutor.class);
    final DistributionConfig config = mock(DistributionConfig.class);

    System.setProperty(SECURITY_SYSTEM_PREFIX + SECURITY_PEER_AUTH_INIT, "true");
    tcpConduit.tcpBufferSize = DEFAULT_SOCKET_BUFFER_SIZE;

    when(connectionTable.getBufferPool()).thenReturn(new BufferPool(dmStats));
    when(connectionTable.getConduit()).thenReturn(tcpConduit);
    when(connectionTable.getDM()).thenReturn(distributionManager);
    when(connectionTable.getSocketCloser()).thenReturn(socketCloser);

    when(distributionManager.getConfig()).thenReturn(config);
    when(distributionManager.getDistribution()).thenReturn(distribution);
    when(distributionManager.getThreadMonitoring()).thenReturn(threadMonitoring);

    when(tcpConduit.getDM()).thenReturn(distributionManager);
    when(tcpConduit.getCancelCriterion()).thenReturn(stopper);
    when(tcpConduit.getSocketId()).thenReturn(new InetSocketAddress(getLocalHost(), 10337));
    when(tcpConduit.getStats()).thenReturn(dmStats);
    when(tcpConduit.getConfig()).thenReturn(config);

    when(stopper.cancelInProgress()).thenReturn(null);
    when(threadMonitoring.createAbstractExecutor(any())).thenReturn(threadMonitoringExecutor);

    doAnswer(invocationOnMock -> {
      final Runnable runnable = (invocationOnMock.getArgument(0));
      if (waitUntilReaderExits) {
        startReader(runnable);
      } else {
        CompletableFuture.runAsync(() -> startReader(runnable));
      }
      return null;
    }).when(connectionTable).executeCommand(any());
    return connectionTable;
  }
@param waitUntilReaderExits if true, start reader thread and wait until it exits,
       otherwise run it asynchronously.
geode-core/src/test/java/org/apache/geode/internal/tcp/ConnectionTransmissionTest.java