SystemRamLimitMessageSender { @VisibleForTesting @ScheduleDelay(initialDelay = 60, delayParameterName = "system.ram.limit_check_period_sec") synchronized void checkRamLimitAndSendMessageIfNeeded() { try { boolean isSystemRamLimitExceeded = systemRamInfoProvider.getSystemRamInfo().isSystemRamLimitExceeded(); if (systemRamLimitExceedMessageSent != isSystemRamLimitExceeded) { sendMessage(isSystemRamLimitExceeded); systemRamLimitExceedMessageSent = isSystemRamLimitExceeded; } } catch (Exception exception) { LOG.error(exception.getMessage(), exception); } } @Inject  SystemRamLimitMessageSender(SystemRamInfoProvider systemRamInfoProvider);   }
@Test public void shouldSetSystemRamLimitExceedMessageSentFlagToFalseWhenRamLimitNotExceedMessageSent() throws Exception { systemRamLimitExceedMessageSent.set(systemRamLimitMessageSender, true); when(systemRamInfo.isSystemRamLimitExceeded()).thenReturn(false); systemRamLimitMessageSender.checkRamLimitAndSendMessageIfNeeded(); assertFalse((boolean) systemRamLimitExceedMessageSent.get(systemRamLimitMessageSender)); }
@Test public void shouldSetSystemRamLimitExceedMessageSentFlagToTrueWhenRamLimitExceedMessageSent() throws Exception { systemRamLimitExceedMessageSent.set(systemRamLimitMessageSender, false); when(systemRamInfo.isSystemRamLimitExceeded()).thenReturn(true); systemRamLimitMessageSender.checkRamLimitAndSendMessageIfNeeded(); assertTrue((boolean) systemRamLimitExceedMessageSent.get(systemRamLimitMessageSender)); }