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