Ejemplo n.º 1
0
  @Test
  public void testResetMetricValues() {
    // Arrange
    RateMetric rateMetric = new RateMetric("totalRecords", "partialRecords", "percent");

    // Act
    rateMetric.metricValues.put(rateMetric.totalCountKey, 1);
    rateMetric.metricValues.put(rateMetric.partialCountKey, 1);
    rateMetric.getValueAndReset();

    // Assert
    Assert.assertEquals(2, rateMetric.metricValues.size());
    Assert.assertEquals(0, (int) rateMetric.metricValues.get(rateMetric.totalCountKey));
    Assert.assertEquals(0, (int) rateMetric.metricValues.get(rateMetric.partialCountKey));
  }
Ejemplo n.º 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);
  }