/**
   * Resulting absolute intervals 1st retransmission should be received after 2 - 3 sec 2nd
   * retransmission should be received after 6 - 9 sec 3rd retransmission should be received after
   * 14 - 21 sec 4th retransmission should be received after 30 - 45 sec
   */
  @Test
  public void testRetransmissionsWereSentInTime() {

    int expectedMessages = 4;

    Set<Long> transmissions = callback.getTransmissions();
    assertEquals("Wrong number of sent messages!", expectedMessages, transmissions.size());

    Iterator<Long> transmissionIterator = transmissions.iterator();

    long[][] delay =
        new long[][] {
          new long[] {2000, 3000},
          new long[] {6000, 9000},
          new long[] {14000, 21000},
          new long[] {30000, 45000}
        };

    int i = -1;
    while (transmissionIterator.hasNext()) {
      i += 1;
      long actualDelay = transmissionIterator.next() - timeRequestSent;

      String format =
          "Retransmission #%d (expected delay: %d - %d millis, actual delay: %d millis)";
      log.info(String.format(format, i + 1, delay[i][0], delay[i][1], actualDelay));

      assertTrue("Message was sent too early!", delay[i][0] <= actualDelay);
      assertTrue("Message was sent too late!", delay[i][1] >= actualDelay);
    }
  }
  /**
   * Test if the notification was to early. Minimum delay is the sum of minimal timeouts (30000)
   * plus the delay for timeout notification (5000). The maximum delay is the sum of maximum
   * timeouts (45000) plus the delay for timeout notification (5000) plus a tolerance of 2000.
   */
  @Test
  public void testClientReceivesTimeoutNotification() {
    assertFalse(
        "Client did not receive a timeout notification at all.",
        callback.getTransmissionTimeouts().isEmpty());

    long minDelay = 247000;

    long transmissionTimeout = callback.getTransmissionTimeouts().iterator().next();
    long actualDelay = transmissionTimeout - timeRequestSent;

    String format =
        "Internal transmission timeout notification (expected minimum delay: %d millis, actual: %d"
            + "millis)";
    log.info(String.format(format, minDelay, actualDelay));

    assertTrue(
        "Internal transmission timeout notification was too early!", minDelay <= actualDelay);
  }