@Test public void testIncrPartial_multiple_calls() { // Arrange RateMetric rateMetric = new RateMetric(totalCountKey, partialCountKey, percentKey); // Act rateMetric.incrPartial(); rateMetric.incrPartial(); rateMetric.incrPartial(); rateMetric.incrPartial(); // Assert int partialCount = rateMetric.metricValues.get(partialCountKey); Assert.assertEquals(4, partialCount); }
@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); }