@Test
  public void testConnectionUnavailable() {
    List<RequestInfo> requestInfoList = new ArrayList<>();
    List<ResponseInfo> responseInfoList;
    requestInfoList.add(new RequestInfo(sslHost, sslPort, new MockSend(3), replicaOnSslNode, null));
    requestInfoList.add(new RequestInfo(sslHost, sslPort, new MockSend(4), replicaOnSslNode, null));
    int requestCount = requestInfoList.size();
    int responseCount = 0;

    responseInfoList = networkClient.sendAndPoll(requestInfoList, Collections.emptySet(), POLL_TIMEOUT_MS);
    requestInfoList.clear();
    // The first sendAndPoll() initiates the connections. So, after the selector poll, new connections
    // would have been established, but no new responses or disconnects, so the SocketNetworkClient should not have been
    // able to create any ResponseInfos.
    Assert.assertEquals("There are no responses expected", 0, responseInfoList.size());
    // the requests were queued. Now increment the time so that they get timed out in the next sendAndPoll.
    time.sleep(CHECKOUT_TIMEOUT_MS + 1);

    do {
      responseInfoList = networkClient.sendAndPoll(requestInfoList, Collections.emptySet(), POLL_TIMEOUT_MS);
      requestInfoList.clear();
      for (ResponseInfo responseInfo : responseInfoList) {
        NetworkClientErrorCode error = responseInfo.getError();
        ByteBuf response = responseInfo.content();
        Assert.assertNotNull("Should have encountered an error", error);
        Assert.assertEquals("Should have received a connection unavailable error",
            NetworkClientErrorCode.ConnectionUnavailable, error);
        Assert.assertNull("Should not have received a valid response", response);
        responseCount++;
        responseInfo.release();
      }
    } while (requestCount > responseCount);
    responseInfoList = networkClient.sendAndPoll(requestInfoList, Collections.emptySet(), POLL_TIMEOUT_MS);
    responseInfoList.forEach(ResponseInfo::release);
    requestInfoList.clear();
    Assert.assertEquals("No responses are expected at this time", 0, responseInfoList.size());
  }
Tests a failure scenario where requests remain too long in the {@link SocketNetworkClient}'s pending requests queue.
ambry-network/src/test/java/com/github/ambry/network/SocketNetworkClientTest.java