@Test
  public void testPendingRequestTimeOutWithDisconnection() throws Exception {
    List<RequestInfo> requestInfoList = new ArrayList<>();
    selector.setState(MockSelectorState.IdlePoll);
    requestInfoList.add(new RequestInfo(sslHost, sslPort, new MockSend(4), replicaOnSslNode, null));
    List<ResponseInfo> responseInfoList =
        networkClient.sendAndPoll(requestInfoList, Collections.emptySet(), POLL_TIMEOUT_MS);
    Assert.assertEquals(0, responseInfoList.size());
    responseInfoList.forEach(ResponseInfo::release);
    requestInfoList.clear();
    // now make the selector return any attempted connections as disconnections.
    selector.setState(MockSelectorState.FailConnectionInitiationOnPoll);
    // increment the time so that the request times out in the next cycle.
    time.sleep(2000);
    responseInfoList = networkClient.sendAndPoll(requestInfoList, Collections.emptySet(), POLL_TIMEOUT_MS);
    // the size of responseInfoList should be 2 because first response comes from dropping request in the queue that
    // waits too long. (This response would be handled by corresponding manager, i.e PutManager, GetManager, etc); second
    // response comes from underlying connection timeout in nioSelector (usually due to remote node is down). This response
    // will be handled by ResponseHandler to mark remote node down immediately.
    Assert.assertEquals("Mismatch in number of responses", 2, responseInfoList.size());
    Assert.assertEquals("Error received in first response should be ConnectionUnavailable",
        NetworkClientErrorCode.ConnectionUnavailable, responseInfoList.get(0).getError());
    Assert.assertEquals("Error received in second response should be NetworkError", NetworkClientErrorCode.NetworkError,
        responseInfoList.get(1).getError());
    responseInfoList.forEach(ResponseInfo::release);
    responseInfoList.clear();
    selector.setState(MockSelectorState.Good);
  }
Tests the case where a pending request for which a connection was initiated times out in the same
sendAndPoll cycle in which the connection disconnection is received.
@throws Exception
ambry-network/src/test/java/com/github/ambry/network/SocketNetworkClientTest.java