-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: health check for succesfull NeonBee start
- Loading branch information
Showing
4 changed files
with
103 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/io/neonbee/health/NeonBeeStartHealthCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.neonbee.health; | ||
|
||
import java.util.function.Function; | ||
|
||
import io.neonbee.NeonBee; | ||
import io.vertx.core.Handler; | ||
import io.vertx.core.Promise; | ||
import io.vertx.ext.healthchecks.Status; | ||
|
||
/** | ||
* A health check in order for NeonBee to only become healthy if the booting procedure succeeded. | ||
*/ | ||
public class NeonBeeStartHealthCheck extends AbstractHealthCheck { | ||
/** | ||
* Name of the health check. | ||
*/ | ||
public static final String NAME = "neonbee.start"; | ||
|
||
/** | ||
* Constructs an instance of {@link NeonBeeStartHealthCheck}. | ||
* | ||
* @param neonBee the current NeonBee instance | ||
*/ | ||
public NeonBeeStartHealthCheck(NeonBee neonBee) { | ||
super(neonBee); | ||
} | ||
|
||
@Override | ||
public String getId() { | ||
return NAME; | ||
} | ||
|
||
@Override | ||
public boolean isGlobal() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public Function<NeonBee, Handler<Promise<Status>>> createProcedure() { | ||
return neonBee -> healthCheckPromise -> { | ||
healthCheckPromise.complete(new Status().setOk(neonBee.isStarted())); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/test/java/io/neonbee/health/NeonBeeStartHealthCheckTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.neonbee.health; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.neonbee.NeonBee; | ||
import io.vertx.core.Promise; | ||
import io.vertx.ext.healthchecks.Status; | ||
|
||
class NeonBeeStartHealthCheckTest { | ||
@Test | ||
@DisplayName("Should return true if NeonBee was started") | ||
void testStarted() { | ||
NeonBee neonBeeMock = mock(NeonBee.class); | ||
NeonBeeStartHealthCheck healthCheck = new NeonBeeStartHealthCheck(neonBeeMock); | ||
|
||
when(neonBeeMock.isStarted()).thenReturn(false); | ||
Promise<Status> promise1 = Promise.promise(); | ||
healthCheck.createProcedure().apply(neonBeeMock).handle(promise1); | ||
assertThat(promise1.future().result().isOk()).isFalse(); | ||
|
||
when(neonBeeMock.isStarted()).thenReturn(true); | ||
Promise<Status> promise2 = Promise.promise(); | ||
healthCheck.createProcedure().apply(neonBeeMock).handle(promise2); | ||
assertThat(promise2.future().result().isOk()).isTrue(); | ||
} | ||
} |