task: refine DistributionTest.keepAlive (#27612)
closes: #26981 Signed-off-by: Steve Hawkins <shawkins@redhat.com>
This commit is contained in:
parent
a6ec682d97
commit
ccc4cd2ab4
4 changed files with 15 additions and 16 deletions
|
@ -97,12 +97,12 @@ public class CLITestExtension extends QuarkusMainTestExtension {
|
|||
infinispanContainer = configureExternalInfinispan(context);
|
||||
|
||||
if (distConfig != null) {
|
||||
onKeepServerAlive(context.getRequiredTestMethod().getAnnotation(KeepServerAlive.class));
|
||||
|
||||
if (dist == null) {
|
||||
dist = createDistribution(distConfig, getStoreConfig(context), getDatabaseConfig(context));
|
||||
}
|
||||
|
||||
onKeepServerAlive(context.getRequiredTestMethod().getAnnotation(KeepServerAlive.class), true);
|
||||
|
||||
copyTestProvider(context.getRequiredTestClass().getAnnotation(TestProvider.class));
|
||||
copyTestProvider(context.getRequiredTestMethod().getAnnotation(TestProvider.class));
|
||||
onBeforeStartDistribution(context.getRequiredTestClass().getAnnotation(BeforeStartDistribution.class));
|
||||
|
@ -163,10 +163,10 @@ public class CLITestExtension extends QuarkusMainTestExtension {
|
|||
}
|
||||
}
|
||||
|
||||
private void onKeepServerAlive(KeepServerAlive annotation) {
|
||||
private void onKeepServerAlive(KeepServerAlive annotation, boolean setting) {
|
||||
if(annotation != null && dist != null) {
|
||||
try {
|
||||
dist.setManualStop(true);
|
||||
dist.setManualStop(setting);
|
||||
} catch (Exception cause) {
|
||||
throw new RuntimeException("Error when invoking " + annotation, cause);
|
||||
}
|
||||
|
@ -177,12 +177,11 @@ public class CLITestExtension extends QuarkusMainTestExtension {
|
|||
public void afterEach(ExtensionContext context) throws Exception {
|
||||
DistributionTest distConfig = getDistributionConfig(context);
|
||||
|
||||
if (distConfig != null) {
|
||||
if (distConfig.keepAlive()) {
|
||||
dist.stop();
|
||||
}
|
||||
if (dist != null) {
|
||||
onKeepServerAlive(context.getRequiredTestMethod().getAnnotation(KeepServerAlive.class), false);
|
||||
dist.stop();
|
||||
|
||||
if (DistributionTest.ReInstall.BEFORE_TEST.equals(distConfig.reInstall())) {
|
||||
if (distConfig != null && DistributionTest.ReInstall.BEFORE_TEST.equals(distConfig.reInstall())) {
|
||||
dist = null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,9 @@ import org.junit.jupiter.api.extension.ExtendWith;
|
|||
public @interface DistributionTest {
|
||||
|
||||
boolean debug() default false;
|
||||
/**
|
||||
* If the distribution should be left running after the launch.
|
||||
*/
|
||||
boolean keepAlive() default false;
|
||||
boolean enableTls() default false;
|
||||
|
||||
|
|
|
@ -17,13 +17,10 @@
|
|||
|
||||
package org.keycloak.it.junit5.extension;
|
||||
|
||||
import org.keycloak.it.utils.KeycloakDistribution;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* {@link KeepServerAlive} is used in a distributiontest to keep the server alive on test / method level.
|
||||
|
|
|
@ -52,7 +52,7 @@ public final class DockerKeycloakDistribution implements KeycloakDistribution {
|
|||
this.envVars.put(name, value);
|
||||
}
|
||||
|
||||
private GenericContainer getKeycloakContainer() {
|
||||
private GenericContainer<?> getKeycloakContainer() {
|
||||
File distributionFile = new File("../../dist/" + File.separator + "target" + File.separator + "keycloak-" + Version.VERSION + ".tar.gz");
|
||||
|
||||
if (!distributionFile.exists()) {
|
||||
|
@ -77,7 +77,7 @@ public final class DockerKeycloakDistribution implements KeycloakDistribution {
|
|||
image = new RemoteDockerImage(DockerImageName.parse("quay.io/keycloak/keycloak"));
|
||||
}
|
||||
|
||||
return new GenericContainer(image)
|
||||
return new GenericContainer<>(image)
|
||||
.withEnv(envVars)
|
||||
.withExposedPorts(8080)
|
||||
.withStartupAttempts(1)
|
||||
|
@ -113,6 +113,7 @@ public final class DockerKeycloakDistribution implements KeycloakDistribution {
|
|||
LOGGER.warn("Failed to start Keycloak container", cause);
|
||||
} finally {
|
||||
if (!manualStop) {
|
||||
stop();
|
||||
envVars.clear();
|
||||
}
|
||||
}
|
||||
|
@ -181,7 +182,6 @@ public final class DockerKeycloakDistribution implements KeycloakDistribution {
|
|||
private void cleanupContainer() {
|
||||
if (containerId != null) {
|
||||
try {
|
||||
final String finalContainerId = containerId;
|
||||
Runnable reaper = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -253,7 +253,7 @@ public final class DockerKeycloakDistribution implements KeycloakDistribution {
|
|||
}
|
||||
|
||||
if (type.isInstance(this)) {
|
||||
return (D) this;
|
||||
return type.cast(this);
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("Not a " + type + " type");
|
||||
|
|
Loading…
Reference in a new issue