-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
164 additions
and
0 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
25 changes: 25 additions & 0 deletions
25
...e/experimental/src/test/java/io/smallrye/health/deployment/AsyncDependentHealthCheck.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,25 @@ | ||
package io.smallrye.health.deployment; | ||
|
||
import jakarta.annotation.PreDestroy; | ||
import jakarta.enterprise.context.Dependent; | ||
|
||
import org.eclipse.microprofile.health.HealthCheckResponse; | ||
import org.eclipse.microprofile.health.Liveness; | ||
|
||
import io.smallrye.health.api.AsyncHealthCheck; | ||
import io.smallrye.mutiny.Uni; | ||
|
||
@Dependent | ||
@Liveness | ||
public class AsyncDependentHealthCheck implements AsyncHealthCheck { | ||
|
||
@Override | ||
public Uni<HealthCheckResponse> call() { | ||
return Uni.createFrom().item(HealthCheckResponse.up(AsyncDependentHealthCheck.class.getName())); | ||
} | ||
|
||
@PreDestroy | ||
public void preDestroy() { | ||
DependentCallRecorder.asyncHealthCheckPreDestroyCalled = true; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...suite/experimental/src/test/java/io/smallrye/health/deployment/DependentCallRecorder.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,8 @@ | ||
package io.smallrye.health.deployment; | ||
|
||
public class DependentCallRecorder { | ||
|
||
public static volatile boolean healthCheckPreDestroyCalled = false; | ||
public static volatile boolean asyncHealthCheckPreDestroyCalled = false; | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
testsuite/experimental/src/test/java/io/smallrye/health/deployment/DependentHealthCheck.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,23 @@ | ||
package io.smallrye.health.deployment; | ||
|
||
import jakarta.annotation.PreDestroy; | ||
import jakarta.enterprise.context.Dependent; | ||
|
||
import org.eclipse.microprofile.health.HealthCheck; | ||
import org.eclipse.microprofile.health.HealthCheckResponse; | ||
import org.eclipse.microprofile.health.Liveness; | ||
|
||
@Dependent | ||
@Liveness | ||
public class DependentHealthCheck implements HealthCheck { | ||
|
||
@Override | ||
public org.eclipse.microprofile.health.HealthCheckResponse call() { | ||
return HealthCheckResponse.up(DependentHealthCheck.class.getName()); | ||
} | ||
|
||
@PreDestroy | ||
public void preDestroy() { | ||
DependentCallRecorder.healthCheckPreDestroyCalled = true; | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
testsuite/experimental/src/test/java/io/smallrye/health/test/DependentHealthChecksTest.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,76 @@ | ||
/* | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICES file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* You may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package io.smallrye.health.test; | ||
|
||
import jakarta.json.JsonArray; | ||
import jakarta.json.JsonObject; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.shrinkwrap.api.Archive; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
import io.smallrye.health.deployment.AsyncDependentHealthCheck; | ||
import io.smallrye.health.deployment.DependentCallRecorder; | ||
import io.smallrye.health.deployment.DependentHealthCheck; | ||
|
||
public class DependentHealthChecksTest extends TCKBase { | ||
|
||
@Deployment | ||
public static Archive getDeployment() { | ||
return DeploymentUtils.createWarFileWithClasses(DependentHealthChecksTest.class.getSimpleName(), | ||
DependentHealthCheck.class, AsyncDependentHealthCheck.class, DependentCallRecorder.class, TCKBase.class); | ||
} | ||
|
||
@Test | ||
public void testAsyncLiveness() { | ||
Response response = getUrlLiveContents(); | ||
|
||
// status code | ||
Assert.assertEquals(response.getStatus(), 200); | ||
|
||
JsonObject json = readJson(response); | ||
|
||
// response size | ||
JsonArray checks = json.getJsonArray("checks"); | ||
Assert.assertEquals(checks.size(), 2, "Expected two check responses"); | ||
|
||
for (JsonObject check : checks.getValuesAs(JsonObject.class)) { | ||
String id = check.getString("name"); | ||
|
||
if (id.equals(DependentHealthCheck.class.getName())) { | ||
verifySuccessStatus(check); | ||
Assert.assertTrue(DependentCallRecorder.healthCheckPreDestroyCalled, | ||
"HealthCheck - PreDestroy method was not called"); | ||
} else if (id.equals(AsyncDependentHealthCheck.class.getName())) { | ||
verifySuccessStatus(check); | ||
Assert.assertTrue(DependentCallRecorder.asyncHealthCheckPreDestroyCalled, | ||
"AsyncHealthCheck - PreDestroy method was not called"); | ||
} else { | ||
Assert.fail("Unexpected response payload structure"); | ||
} | ||
} | ||
|
||
assertOverallSuccess(json); | ||
} | ||
} |