GatewaySenderOverflowMonitor extends MBeanStatsMonitor { Number computeDelta(Map<String, Number> statsMap, String name, Number currentValue) { if (name.equals(StatsKey.GATEWAYSENDER_LRU_EVICTIONS)) { Number prevValue = statsMap.getOrDefault(StatsKey.GATEWAYSENDER_LRU_EVICTIONS, 0); return currentValue.longValue() - prevValue.longValue(); } if (name.equals(StatsKey.GATEWAYSENDER_ENTRIES_OVERFLOWED_TO_DISK)) { Number prevValue = statsMap.getOrDefault(StatsKey.GATEWAYSENDER_ENTRIES_OVERFLOWED_TO_DISK, 0); return currentValue.longValue() - prevValue.longValue(); } if (name.equals(StatsKey.GATEWAYSENDER_BYTES_OVERFLOWED_TO_DISK)) { Number prevValue = statsMap.getOrDefault(StatsKey.GATEWAYSENDER_BYTES_OVERFLOWED_TO_DISK, 0); return currentValue.longValue() - prevValue.longValue(); } return 0; } GatewaySenderOverflowMonitor(String name); long getBytesOverflowedToDisk(); long getEntriesOverflowedToDisk(); @Override Number getStatistic(String name); @Override void addStatisticsToMonitor(Statistics stats); @Override void stopListener(); @Override void removeStatisticsFromMonitor(Statistics stats);  }
@Test public void computeDeltaShouldReturnZeroForUnknownStatistics() { assertThat( gatewaySenderOverflowMonitor.computeDelta(Collections.emptyMap(), "unknownStatistic", 6)) .isEqualTo(0); }
@Test public void computeDeltaShouldOperateForHandledStatistics() { Map<String, Number> statsMap = new HashMap<>(); statsMap.put(StatsKey.GATEWAYSENDER_LRU_EVICTIONS, 50); statsMap.put(StatsKey.GATEWAYSENDER_BYTES_OVERFLOWED_TO_DISK, 2048); statsMap.put(StatsKey.GATEWAYSENDER_ENTRIES_OVERFLOWED_TO_DISK, 100); assertThat(gatewaySenderOverflowMonitor.computeDelta(statsMap, StatsKey.GATEWAYSENDER_LRU_EVICTIONS, 60)).isEqualTo(10L); assertThat(gatewaySenderOverflowMonitor.computeDelta(statsMap, StatsKey.GATEWAYSENDER_BYTES_OVERFLOWED_TO_DISK, 2100)).isEqualTo(52L); assertThat(gatewaySenderOverflowMonitor.computeDelta(statsMap, StatsKey.GATEWAYSENDER_ENTRIES_OVERFLOWED_TO_DISK, 150)).isEqualTo(50L); }