@Test public void shouldReturnFalseForRealSuccessIfThereIsAtleastOneWarning() throws Exception { ServerHealthStates states = new ServerHealthStates(ServerHealthState.warning("another", "some", HealthStateType.databaseDiskFull())); assertThat(states.isRealSuccess(), is(false)); }
@Test public void shouldReturntrueForRealSuccess() throws Exception { assertThat(new ServerHealthStates(ServerHealthState.success(HealthStateType.databaseDiskFull())).isRealSuccess(), is(true)); } }
@Test public void shouldReturnTheErrorCount() throws Exception { ServerHealthStates states = new ServerHealthStates(ServerHealthState.error("msg", "desc", HealthStateType.artifactsDirChanged()), ServerHealthState.warning("another", "some", HealthStateType.databaseDiskFull())); assertThat(states.errorCount(), is(1)); assertThat(states.warningCount(), is(1)); }
@Test public void shouldExpireAfterTheExpiryTime() throws Exception { testingClock.setTime(new Date()); ServerHealthState expireInFiveMins = ServerHealthState.warning("message", "desc", HealthStateType.databaseDiskFull(), Timeout.FIVE_MINUTES); ServerHealthState expireNever = ServerHealthState.warning("message", "desc", HealthStateType.databaseDiskFull()); assertThat(expireInFiveMins.hasExpired(),is(false)); testingClock.addMillis((int) Timeout.TWO_MINUTES.inMillis()); assertThat(expireInFiveMins.hasExpired(),is(false)); testingClock.addMillis((int) Timeout.THREE_MINUTES.inMillis()); assertThat(expireInFiveMins.hasExpired(),is(false)); testingClock.addMillis(10); assertThat(expireInFiveMins.hasExpired(),is(true)); testingClock.addMillis(999999999); assertThat(expireNever.hasExpired(),is(false)); }
@Test public void shouldRemoveExpiredLogMessages() throws Exception { testingClock.setTime(new DateTime(2002,10,10,10,10,10,10)); ServerHealthState expiresInNintySecs = warning("hg-message1", "description", HealthStateType.databaseDiskFull(), Timeout.NINETY_SECONDS); ServerHealthState expiresInThreeMins = warning("hg-message2", "description", HealthStateType.artifactsDirChanged(), Timeout.THREE_MINUTES); ServerHealthState expiresNever = warning("hg-message3", "description", HealthStateType.artifactsDiskFull(), Timeout.NEVER); serverHealthService.update(expiresInThreeMins); serverHealthService.update(expiresInNintySecs); serverHealthService.update(expiresNever); serverHealthService.purgeStaleHealthMessages(new BasicCruiseConfig()); ServerHealthStates logs = serverHealthService.logs(); assertThat(logs.size(), is(3)); assertThat(logs, hasItems(expiresInThreeMins,expiresInNintySecs, expiresNever)); testingClock.addSeconds(100); serverHealthService.purgeStaleHealthMessages(new BasicCruiseConfig()); logs = serverHealthService.logs(); assertThat(logs.size(), is(2)); assertThat(logs,hasItems(expiresInThreeMins, expiresNever)); testingClock.addMillis((int) Timeout.TWO_MINUTES.inMillis()); serverHealthService.purgeStaleHealthMessages(new BasicCruiseConfig()); logs = serverHealthService.logs(); assertThat(logs.size(), is(1)); assertThat(logs,hasItem(expiresNever)); }