AggregateRegionStatsMonitor extends MBeanStatsMonitor { Number computeDelta(Map<String, Number> statsMap, String name, Number currentValue) { if (name.equals(StatsKey.PRIMARY_BUCKET_COUNT)) { Number prevValue = statsMap.getOrDefault(StatsKey.PRIMARY_BUCKET_COUNT, 0); return currentValue.intValue() - prevValue.intValue(); } if (name.equals(StatsKey.BUCKET_COUNT)) { Number prevValue = statsMap.getOrDefault(StatsKey.BUCKET_COUNT, 0); return currentValue.intValue() - prevValue.intValue(); } if (name.equals(StatsKey.TOTAL_BUCKET_SIZE)) { Number prevValue = statsMap.getOrDefault(StatsKey.TOTAL_BUCKET_SIZE, 0); return currentValue.intValue() - prevValue.intValue(); } if (name.equals(StatsKey.LRU_EVICTIONS)) { Number prevValue = statsMap.getOrDefault(StatsKey.LRU_EVICTIONS, 0); return currentValue.longValue() - prevValue.longValue(); } if (name.equals(StatsKey.LRU_DESTROYS)) { Number prevValue = statsMap.getOrDefault(StatsKey.LRU_DESTROYS, 0); return currentValue.longValue() - prevValue.longValue(); } if (name.equals(StatsKey.DISK_SPACE)) { Number prevValue = statsMap.getOrDefault(StatsKey.DISK_SPACE, 0); return currentValue.longValue() - prevValue.longValue(); } return 0; } AggregateRegionStatsMonitor(String name); long getDiskSpace(); int getTotalBucketCount(); int getTotalBucketSize(); int getTotalPrimaryBucketCount(); void removeLRUStatistics(Statistics stats); void removeDirectoryStatistics(Statistics stats); void removePartitionStatistics(Statistics stats); @Override Number getStatistic(String name); @Override void addStatisticsToMonitor(Statistics stats); @Override void stopListener(); @Override void removeStatisticsFromMonitor(Statistics stats);  }
@Test public void computeDeltaShouldReturnZeroForUnknownStatistics() { assertThat( aggregateRegionStatsMonitor.computeDelta(Collections.emptyMap(), "unknownStatistic", 6)) .isEqualTo(0); }
@Test public void computeDeltaShouldOperateForHandledStatistics() { Map<String, Number> statsMap = new HashMap<>(); statsMap.put(StatsKey.PRIMARY_BUCKET_COUNT, 5); statsMap.put(StatsKey.BUCKET_COUNT, 13); statsMap.put(StatsKey.TOTAL_BUCKET_SIZE, 1024); statsMap.put(StatsKey.LRU_EVICTIONS, 12); statsMap.put(StatsKey.LRU_DESTROYS, 5); statsMap.put(StatsKey.DISK_SPACE, 2048); assertThat(aggregateRegionStatsMonitor.computeDelta(statsMap, StatsKey.PRIMARY_BUCKET_COUNT, 6)) .isEqualTo(1); assertThat(aggregateRegionStatsMonitor.computeDelta(statsMap, StatsKey.BUCKET_COUNT, 15)) .isEqualTo(2); assertThat(aggregateRegionStatsMonitor.computeDelta(statsMap, StatsKey.TOTAL_BUCKET_SIZE, 1030)) .isEqualTo(6); assertThat(aggregateRegionStatsMonitor.computeDelta(statsMap, StatsKey.LRU_EVICTIONS, 20)) .isEqualTo(8L); assertThat(aggregateRegionStatsMonitor.computeDelta(statsMap, StatsKey.LRU_DESTROYS, 6)) .isEqualTo(1L); assertThat(aggregateRegionStatsMonitor.computeDelta(statsMap, StatsKey.DISK_SPACE, 2050)) .isEqualTo(2L); }