@Test
  public void testThatMapCloseCausesCacheClosedException() throws Exception {
    ConnectionManagerImpl connectionManagerImpl = new ConnectionManagerImpl("pool", factory,
        endpointManager, 2, 0, -1, -1, logger, 60 * 1000, cancelCriterion, poolStats);
    manager = connectionManagerImpl;
    manager.start(background);
    ConnectionMap connectionMap = connectionManagerImpl.allConnectionsMap;

    CyclicBarrier cyclicBarrier = new CyclicBarrier(2);

    Future<Void> future = executorServiceRule.submit(() -> {
      cyclicBarrier.await(getTimeout().toMillis(), MILLISECONDS);
      connectionMap.close(false);
    });

    Connection connection = manager.borrowConnection(0);
    synchronized (connection) {
      cyclicBarrier.await(getTimeout().toMillis(), MILLISECONDS);

      // the other thread will now try to close the connection map but it will block
      // because this thread has locked one of the connections
      await().until(() -> connectionMap.closing);

      Throwable thrown = catchThrowable(() -> {
        manager.borrowConnection(0);
      });
      assertThat(thrown).isInstanceOf(CacheClosedException.class);
    }

    future.get(getTimeout().toMillis(), MILLISECONDS);
  }
This tests that a deadlock between connection formation and connection pool closing has been
fixed. See GEODE-4615
geode-core/src/integrationTest/java/org/apache/geode/cache/client/internal/pooling/ConnectionManagerJUnitTest.java