예제 #1
0
  @Test
  public void testIncrTotal_multiple_calls() {
    // Arrange
    RateMetric rateMetric = new RateMetric(totalCountKey, partialCountKey, percentKey);

    // Act
    rateMetric.incrTotal();
    rateMetric.incrTotal();
    rateMetric.incrTotal();

    // Assert
    int totalCount = rateMetric.metricValues.get(totalCountKey);
    Assert.assertEquals(3, totalCount);
  }
예제 #2
0
  @Test
  public void testGetValueAndReset() {
    // Arrange
    RateMetric rateMetric = new RateMetric(totalCountKey, partialCountKey, percentKey);

    // Act
    rateMetric.incrTotal();
    rateMetric.incrTotal();
    rateMetric.incrTotal();
    rateMetric.incrPartial();

    Map<String, Integer> metricValues = (Map<String, Integer>) rateMetric.getValueAndReset();
    int totalCount = metricValues.get(totalCountKey);
    int partialCount = metricValues.get(partialCountKey);
    int percentage = metricValues.get(percentKey);

    // Assert
    Assert.assertEquals(3, totalCount);
    Assert.assertEquals(1, partialCount);
    Assert.assertEquals(33, percentage);
  }