private void sendRequest(int id, int count) throws Exception {
    int idx = id - 1;

    if (idx < 0) throw new IllegalArgumentException("Connection ID <= 0");

    _socket[idx] =
        _socket[idx] == null ? new Socket("localhost", _connector.getLocalPort()) : _socket[idx];
    _out[idx] =
        _out[idx] == null ? new PrintWriter(_socket[idx].getOutputStream(), true) : _out[idx];
    _in[idx] =
        _in[idx] == null
            ? new BufferedReader(new InputStreamReader(_socket[idx].getInputStream()))
            : _in[idx];

    _connect.reset();

    _out[idx].write("GET / HTTP/1.1\r\nHost: localhost\r\n\r\n");
    _out[idx].flush();

    _connect.await();

    assertEquals(count, _statistics.getConnectionsOpen());

    String line = _in[idx].readLine();
    while (line != null) {
      if ("Server response".equals(line)) break;
      line = _in[idx].readLine();
    }
  }
  @Test
  public void testMultipleRequests() throws Exception {
    doInit(1);

    sendRequest(1, 1);

    sendRequest(1, 1);

    doClose(1);

    assertEquals(1, _statistics.getConnections());
    assertEquals(0, _statistics.getConnectionsOpen());
    assertEquals(1, _statistics.getConnectionsOpenMax());
    assertTrue(_statistics.getConnectionsOpen() <= _statistics.getConnectionsOpenMax());

    assertTrue(_statistics.getConnectionsDurationMean() > 0);
    assertTrue(_statistics.getConnectionsDurationMax() > 0);
    assertTrue(_statistics.getConnectionsDurationMean() <= _statistics.getConnectionsDurationMax());

    assertEquals(2, _statistics.getMessagesIn());
    assertEquals(2.0, _statistics.getConnectionsMessagesInMean(), 0.01);
    assertEquals(2, _statistics.getConnectionsMessagesInMax());
    assertTrue(
        _statistics.getConnectionsMessagesInMean() <= _statistics.getConnectionsMessagesInMax());
  }
  @Test
  public void testMultipleConnections() throws Exception {
    doInit(3);

    sendRequest(1, 1); // request 1 connection 1

    sendRequest(2, 2); // request 1 connection 2

    sendRequest(3, 3); // request 1 connection 3

    sendRequest(2, 3); // request 2 connection 2

    sendRequest(3, 3); // request 2 connection 3

    sendRequest(3, 3); // request 3 connection 3

    doClose(3);

    assertEquals(3, _statistics.getConnections());
    assertEquals(0, _statistics.getConnectionsOpen());
    assertEquals(3, _statistics.getConnectionsOpenMax());
    assertTrue(_statistics.getConnectionsOpen() <= _statistics.getConnectionsOpenMax());

    assertTrue(_statistics.getConnectionsDurationMean() > 0);
    assertTrue(_statistics.getConnectionsDurationMax() > 0);
    assertTrue(_statistics.getConnectionsDurationMean() <= _statistics.getConnectionsDurationMax());

    assertEquals(6, _statistics.getMessagesIn());
    assertEquals(2.0, _statistics.getConnectionsMessagesInMean(), 0.01);
    assertEquals(3, _statistics.getConnectionsMessagesInMax());
    assertTrue(
        _statistics.getConnectionsMessagesInMean() <= _statistics.getConnectionsMessagesInMax());
  }
 @Before
 public void init() throws Exception {
   _statistics.reset();
 }