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

    // set beBad so that requests end up failing due to "network error".
    selector.setState(MockSelectorState.DisconnectOnSend);
    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.NetworkError,
            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());
    selector.setState(MockSelectorState.Good);
  }
Tests a failure scenario where connections get disconnected after requests are sent out.
ambry-network/src/test/java/com/github/ambry/network/SocketNetworkClientTest.java