コード例 #1
0
  /**
   * 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.",
        responseProcessor.getTransmissionTimeouts().isEmpty());

    long minDelay = 247000;

    SortedSet<Long> transmissionTimes =
        (SortedSet<Long>) responseProcessor.getTransmissions().keySet();

    long firstTransmissionTime = transmissionTimes.first();

    SortedSet<Long> transmissionTimeoutTimes =
        (SortedSet<Long>) responseProcessor.getTransmissionTimeouts().keySet();

    long transmissionTimeoutTime = transmissionTimeoutTimes.first();

    long actualDelay = transmissionTimeoutTime - firstTransmissionTime;

    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);
  }
コード例 #2
0
  /**
   * 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 = 5;

    SortedSetMultimap<Long, InternalMessageDataWrapper> tranmissions =
        responseProcessor.getTransmissions();
    assertEquals("Wrong number of sent messages!", expectedMessages, tranmissions.size());

    Iterator<Map.Entry<Long, InternalMessageDataWrapper>> transmissionIterator =
        tranmissions.entries().iterator();

    // ignore first message...
    transmissionIterator.next();

    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().getKey() - 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);
    }
  }