@Test
  public void testMaxCnxLimit() throws Exception {
    PORT = createServer();
    createProxyAndRegionForClient();
    StatisticsType st = system.findType("CacheServerStats");
    final Statistics s = system.findStatisticsByType(st)[0];
    assertEquals(0, s.getInt("currentClients"));
    assertEquals(0, s.getInt("currentClientConnections"));
    Connection[] cnxs = new Connection[MAX_CNXS];
    for (int i = 0; i < MAX_CNXS; i++) {
      cnxs[i] = proxy.acquireConnection();
      system.getLogWriter().info("acquired connection[" + i + "]=" + cnxs[i]);
    }
    WaitCriterion ev = new WaitCriterion() {
      @Override
      public boolean done() {
        return s.getInt("currentClientConnections") == MAX_CNXS;
      }

      @Override
      public String description() {
        return null;
      }
    };
    GeodeAwaitility.await().untilAsserted(ev);
    assertEquals(MAX_CNXS, s.getInt("currentClientConnections"));
    assertEquals(1, s.getInt("currentClients"));
    system.getLogWriter().info(
        "<ExpectedException action=add>" + "exceeded max-connections" + "</ExpectedException>");
    try {
      Connection cnx = proxy.acquireConnection();
      if (cnx != null) {
        fail("should not have been able to connect more than " + MAX_CNXS
            + " times but was able to connect " + s.getInt("currentClientConnections")
            + " times. Last connection=" + cnx);
      }
      system.getLogWriter().info("acquire connection returned null which is ok");
    } catch (NoAvailableServersException expected) {
      // This is expected but due to race conditions in server handshake
      // we may get null back from acquireConnection instead.
      system.getLogWriter().info("received expected " + expected.getMessage());
    } catch (Exception ex) {
      fail("expected acquireConnection to throw NoAvailableServersException but instead it threw "
          + ex);
    } finally {
      system.getLogWriter().info("<ExpectedException action=remove>"
          + "exceeded max-connections" + "</ExpectedException>");
    }

    // now lets see what happens we we close our connections
    for (int i = 0; i < MAX_CNXS; i++) {
      cnxs[i].close(false);
    }
    ev = new WaitCriterion() {
      @Override
      public boolean done() {
        return s.getInt("currentClients") == 0;
      }

      @Override
      public String description() {
        return null;
      }
    };
    GeodeAwaitility.await().untilAsserted(ev);
    system.getLogWriter().info("currentClients=" + s.getInt("currentClients")
        + " currentClientConnections=" + s.getInt("currentClientConnections"));
    assertEquals(0, s.getInt("currentClientConnections"));
    assertEquals(0, s.getInt("currentClients"));
  }
This test performs the following:<br>
1)create server<br>
2)initialize proxy object and create region for client<br>
3)perform a PUT on client by acquiring Connection through proxy<br>
4)stop server monitor threads in client to ensure that server treats this as dead client <br>
5)wait for some time to allow server to clean up the dead client artifacts<br>
6)again perform a PUT on client through same Connection and verify after the put that the
Connection object used was new one.
geode-core/src/integrationTest/java/org/apache/geode/internal/cache/tier/sockets/CacheServerMaxConnectionsJUnitTest.java