MemberLevelDiskMonitor extends MBeanStatsMonitor { Number computeDelta(Map<String, Number> statsMap, String name, Number currentValue) { if (name.equals(StatsKey.DISK_READ_BYTES)) { Number prevValue = statsMap.getOrDefault(StatsKey.DISK_READ_BYTES, 0); return currentValue.longValue() - prevValue.longValue(); } if (name.equals(StatsKey.DISK_RECOVERED_BYTES)) { Number prevValue = statsMap.getOrDefault(StatsKey.DISK_RECOVERED_BYTES, 0); return currentValue.longValue() - prevValue.longValue(); } if (name.equals(StatsKey.DISK_WRITEN_BYTES)) { Number prevValue = statsMap.getOrDefault(StatsKey.DISK_WRITEN_BYTES, 0); return currentValue.longValue() - prevValue.longValue(); } if (name.equals(StatsKey.BACKUPS_IN_PROGRESS)) { Number prevValue = statsMap.getOrDefault(StatsKey.BACKUPS_IN_PROGRESS, 0); return currentValue.intValue() - prevValue.intValue(); } if (name.equals(StatsKey.BACKUPS_COMPLETED)) { Number prevValue = statsMap.getOrDefault(StatsKey.BACKUPS_COMPLETED, 0); return currentValue.intValue() - prevValue.intValue(); } if (name.equals(StatsKey.FLUSHED_BYTES)) { Number prevValue = statsMap.getOrDefault(StatsKey.FLUSHED_BYTES, 0); return currentValue.longValue() - prevValue.longValue(); } if (name.equals(StatsKey.NUM_FLUSHES)) { Number prevValue = statsMap.getOrDefault(StatsKey.NUM_FLUSHES, 0); return currentValue.longValue() - prevValue.longValue(); } if (name.equals(StatsKey.TOTAL_FLUSH_TIME)) { Number prevValue = statsMap.getOrDefault(StatsKey.TOTAL_FLUSH_TIME, 0); return currentValue.longValue() - prevValue.longValue(); } if (name.equals(StatsKey.DISK_QUEUE_SIZE)) { Number prevValue = statsMap.getOrDefault(StatsKey.DISK_QUEUE_SIZE, 0); return currentValue.intValue() - prevValue.intValue(); } return 0; } MemberLevelDiskMonitor(String name); long getFlushes(); int getQueueSize(); int getBackupsCompleted(); int getBackupsInProgress(); @Override Number getStatistic(String name); @Override void addStatisticsToMonitor(Statistics stats); @Override void stopListener(); @Override void removeStatisticsFromMonitor(Statistics stats);  }
@Test public void computeDeltaShouldReturnZeroForUnknownStatistics() { assertThat(memberLevelDiskMonitor.computeDelta(Collections.emptyMap(), "unknownStatistic", 6)) .isEqualTo(0); }
@Test public void computeDeltaShouldOperateForHandledStatistics() { Map<String, Number> statsMap = new HashMap<>(); statsMap.put(StatsKey.NUM_FLUSHES, 10); statsMap.put(StatsKey.DISK_QUEUE_SIZE, 148); statsMap.put(StatsKey.TOTAL_FLUSH_TIME, 10000); statsMap.put(StatsKey.FLUSHED_BYTES, 2048); statsMap.put(StatsKey.DISK_READ_BYTES, 1024); statsMap.put(StatsKey.DISK_RECOVERED_BYTES, 512); statsMap.put(StatsKey.BACKUPS_COMPLETED, 5); statsMap.put(StatsKey.DISK_WRITEN_BYTES, 8192); statsMap.put(StatsKey.BACKUPS_IN_PROGRESS, 2); assertThat(memberLevelDiskMonitor.computeDelta(statsMap, StatsKey.NUM_FLUSHES, 16)) .isEqualTo(6L); assertThat(memberLevelDiskMonitor.computeDelta(statsMap, StatsKey.DISK_QUEUE_SIZE, 150)) .isEqualTo(2); assertThat(memberLevelDiskMonitor.computeDelta(statsMap, StatsKey.TOTAL_FLUSH_TIME, 10000)) .isEqualTo(0L); assertThat(memberLevelDiskMonitor.computeDelta(statsMap, StatsKey.FLUSHED_BYTES, 3000)) .isEqualTo(952L); assertThat(memberLevelDiskMonitor.computeDelta(statsMap, StatsKey.DISK_READ_BYTES, 2048)) .isEqualTo(1024L); assertThat(memberLevelDiskMonitor.computeDelta(statsMap, StatsKey.DISK_RECOVERED_BYTES, 1024)) .isEqualTo(512L); assertThat(memberLevelDiskMonitor.computeDelta(statsMap, StatsKey.BACKUPS_COMPLETED, 6)) .isEqualTo(1); assertThat(memberLevelDiskMonitor.computeDelta(statsMap, StatsKey.DISK_WRITEN_BYTES, 8193)) .isEqualTo(1L); assertThat(memberLevelDiskMonitor.computeDelta(statsMap, StatsKey.BACKUPS_IN_PROGRESS, 1)) .isEqualTo(-1); }