Turn LivenessState and ReadinessState into enums

Prior to this commit, `LivenessState` and `ReadinessState` were
immutable classes. This was done in order to have additional behavior
and information in those classes.

Because the current implementation doesn't need this, this commit turns
those classes into simple enums.
Additional state and information can be added to the
`*StateChangedEvent` classes.

See gh-19593
This commit is contained in:
Brian Clozel
2020-03-24 18:22:43 +01:00
parent 6aa3461611
commit eb70fd952f
10 changed files with 35 additions and 125 deletions

View File

@@ -38,7 +38,7 @@ public class LivenessProbeHealthIndicator extends AbstractHealthIndicator {
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
if (LivenessState.live().equals(this.applicationAvailabilityProvider.getLivenessState())) {
if (LivenessState.LIVE.equals(this.applicationAvailabilityProvider.getLivenessState())) {
builder.up();
}
else {

View File

@@ -38,7 +38,7 @@ public class ReadinessProbeHealthIndicator extends AbstractHealthIndicator {
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
if (ReadinessState.ready().equals(this.applicationAvailabilityProvider.getReadinessState())) {
if (ReadinessState.READY.equals(this.applicationAvailabilityProvider.getReadinessState())) {
builder.up();
}
else {

View File

@@ -46,13 +46,13 @@ class LivenessProbeHealthIndicatorTests {
@Test
void livenessIsLive() {
when(this.stateProvider.getLivenessState()).thenReturn(LivenessState.live());
when(this.stateProvider.getLivenessState()).thenReturn(LivenessState.LIVE);
assertThat(this.healthIndicator.health().getStatus()).isEqualTo(Status.UP);
}
@Test
void livenessIsBroken() {
when(this.stateProvider.getLivenessState()).thenReturn(LivenessState.broken());
when(this.stateProvider.getLivenessState()).thenReturn(LivenessState.BROKEN);
assertThat(this.healthIndicator.health().getStatus()).isEqualTo(Status.DOWN);
}

View File

@@ -46,13 +46,13 @@ class ReadinessProbeHealthIndicatorTests {
@Test
void readinessIsReady() {
when(this.stateProvider.getReadinessState()).thenReturn(ReadinessState.ready());
when(this.stateProvider.getReadinessState()).thenReturn(ReadinessState.READY);
assertThat(this.healthIndicator.health().getStatus()).isEqualTo(Status.UP);
}
@Test
void readinessIsUnready() {
when(this.stateProvider.getReadinessState()).thenReturn(ReadinessState.unready());
when(this.stateProvider.getReadinessState()).thenReturn(ReadinessState.UNREADY);
assertThat(this.healthIndicator.health().getStatus()).isEqualTo(Status.OUT_OF_SERVICE);
}