|
|
|
|
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
|
|
|
|
/* |
|
|
|
|
* Copyright 2012-2020 the original author or authors. |
|
|
|
|
* Copyright 2012-2021 the original author or authors. |
|
|
|
|
* |
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
|
@ -21,6 +21,7 @@ import java.net.URI;
@@ -21,6 +21,7 @@ import java.net.URI;
|
|
|
|
|
import java.nio.file.Files; |
|
|
|
|
import java.nio.file.Path; |
|
|
|
|
import java.util.Arrays; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.HashSet; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
@ -62,6 +63,10 @@ class EmbeddedServerContainerInvocationContextProvider
@@ -62,6 +63,10 @@ class EmbeddedServerContainerInvocationContextProvider
|
|
|
|
|
private static final BuildOutput buildOutput = new BuildOutput( |
|
|
|
|
EmbeddedServerContainerInvocationContextProvider.class); |
|
|
|
|
|
|
|
|
|
private final Map<String, ApplicationBuilder> builderCache = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
private final Map<String, AbstractApplicationLauncher> launcherCache = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
private final Path tempDir; |
|
|
|
|
|
|
|
|
|
EmbeddedServerContainerInvocationContextProvider() throws IOException { |
|
|
|
|
@ -77,14 +82,13 @@ class EmbeddedServerContainerInvocationContextProvider
@@ -77,14 +82,13 @@ class EmbeddedServerContainerInvocationContextProvider
|
|
|
|
|
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext context) { |
|
|
|
|
EmbeddedServletContainerTest annotation = context.getRequiredTestClass() |
|
|
|
|
.getAnnotation(EmbeddedServletContainerTest.class); |
|
|
|
|
return CONTAINERS.stream() |
|
|
|
|
.map((container) -> new ApplicationBuilder(this.tempDir, annotation.packaging(), |
|
|
|
|
container)) |
|
|
|
|
return CONTAINERS |
|
|
|
|
.stream().map( |
|
|
|
|
(container) -> getApplicationBuilder(annotation, container)) |
|
|
|
|
.flatMap( |
|
|
|
|
(builder) -> Stream |
|
|
|
|
.of(annotation.launchers()).map( |
|
|
|
|
(launcherClass) -> ReflectionUtils.newInstance(launcherClass, builder, |
|
|
|
|
buildOutput)) |
|
|
|
|
(launcherClass) -> getAbstractApplicationLauncher(builder, launcherClass)) |
|
|
|
|
.map((launcher) -> new EmbeddedServletContainerInvocationContext( |
|
|
|
|
StringUtils.capitalize(builder.getContainer()) + ": " |
|
|
|
|
+ launcher.getDescription(builder.getPackaging()), |
|
|
|
|
@ -94,6 +98,34 @@ class EmbeddedServerContainerInvocationContextProvider
@@ -94,6 +98,34 @@ class EmbeddedServerContainerInvocationContextProvider
|
|
|
|
|
@Override |
|
|
|
|
public void afterAll(ExtensionContext context) throws Exception { |
|
|
|
|
FileSystemUtils.deleteRecursively(this.tempDir); |
|
|
|
|
cleanupCaches(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void cleanupCaches() { |
|
|
|
|
this.launcherCache.values().forEach(AbstractApplicationLauncher::destroyProcess); |
|
|
|
|
this.launcherCache.clear(); |
|
|
|
|
this.builderCache.clear(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private AbstractApplicationLauncher getAbstractApplicationLauncher(ApplicationBuilder builder, |
|
|
|
|
Class<? extends AbstractApplicationLauncher> launcherClass) { |
|
|
|
|
String cacheKey = builder.getContainer() + ":" + builder.getPackaging() + ":" + launcherClass.getName(); |
|
|
|
|
if (this.launcherCache.containsKey(cacheKey)) { |
|
|
|
|
return this.launcherCache.get(cacheKey); |
|
|
|
|
} |
|
|
|
|
AbstractApplicationLauncher launcher = ReflectionUtils.newInstance(launcherClass, builder, buildOutput); |
|
|
|
|
this.launcherCache.put(cacheKey, launcher); |
|
|
|
|
return launcher; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private ApplicationBuilder getApplicationBuilder(EmbeddedServletContainerTest annotation, String container) { |
|
|
|
|
String cacheKey = container + ":" + annotation.packaging(); |
|
|
|
|
if (this.builderCache.containsKey(cacheKey)) { |
|
|
|
|
return this.builderCache.get(cacheKey); |
|
|
|
|
} |
|
|
|
|
ApplicationBuilder builder = new ApplicationBuilder(this.tempDir, annotation.packaging(), container); |
|
|
|
|
this.builderCache.put(cacheKey, builder); |
|
|
|
|
return builder; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static class EmbeddedServletContainerInvocationContext implements TestTemplateInvocationContext, ParameterResolver { |
|
|
|
|
|