From 242f6621aed18c8c4689f3bb52c869ca48a73549 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Mon, 2 Aug 2021 09:15:09 -0700 Subject: [PATCH] Issue #5684 - Fixing DeploymentTempDirTest Using unique workdir per testcase. Don't expect to delete between tests (not supported on windows due to file locking anyway) Signed-off-by: Joakim Erdfelt --- .../jetty/deploy/DeploymentTempDirTest.java | 52 ++++++++----------- 1 file changed, 21 insertions(+), 31 deletions(-) diff --git a/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/DeploymentTempDirTest.java b/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/DeploymentTempDirTest.java index c98526f1a4b..4fff47bff3d 100644 --- a/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/DeploymentTempDirTest.java +++ b/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/DeploymentTempDirTest.java @@ -24,9 +24,7 @@ import java.io.FileWriter; import java.io.IOException; import java.nio.file.Path; import java.util.Arrays; -import java.util.List; import java.util.UUID; -import java.util.concurrent.CompletableFuture; import org.eclipse.jetty.deploy.providers.WebAppProvider; import org.eclipse.jetty.server.Handler; @@ -37,40 +35,47 @@ import org.eclipse.jetty.server.handler.DefaultHandler; import org.eclipse.jetty.server.handler.HandlerCollection; import org.eclipse.jetty.toolchain.test.FS; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; +import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; +import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension; import org.eclipse.jetty.util.IO; -import org.eclipse.jetty.util.Scanner; -import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.webapp.WebAppContext; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.junit.jupiter.api.Assertions.assertNotSame; import static org.junit.jupiter.api.Assertions.assertTrue; +@ExtendWith(WorkDirExtension.class) public class DeploymentTempDirTest { - private static final Logger LOG = Log.getLogger(DeploymentTempDirTest.class); + public WorkDir workDir; - private final WebAppProvider webAppProvider = new WebAppProvider(); - private final ContextHandlerCollection contexts = new ContextHandlerCollection(); - private final Path testDir = MavenTestingUtils.getTargetTestingPath(DeploymentTempDirTest.class.getSimpleName()); - private final Path tmpDir = testDir.resolve("tmpDir"); - private final Path webapps = testDir.resolve("webapps"); - private final Server server = new Server(); + private Path tmpDir; + private Path webapps; + private Server server; + private WebAppProvider webAppProvider; + private ContextHandlerCollection contexts; @BeforeEach public void setup() throws Exception { + Path testDir = workDir.getEmptyPathDir(); + tmpDir = testDir.resolve("tmpDir"); + webapps = testDir.resolve("webapps"); + + FS.ensureDirExists(tmpDir); + FS.ensureDirExists(webapps); + + server = new Server(); + ServerConnector connector = new ServerConnector(server); server.addConnector(connector); - FS.ensureEmpty(testDir); - FS.ensureEmpty(tmpDir); - FS.ensureEmpty(webapps); + webAppProvider = new WebAppProvider(); webAppProvider.setMonitoredDirName(webapps.toString()); webAppProvider.setScanInterval(0); @@ -78,6 +83,7 @@ public class DeploymentTempDirTest deploymentManager.addAppProvider(webAppProvider); server.addBean(deploymentManager); + contexts = new ContextHandlerCollection(); HandlerCollection handlerCollection = new HandlerCollection(); handlerCollection.addHandler(contexts); handlerCollection.addHandler(new DefaultHandler()); @@ -201,20 +207,4 @@ public class DeploymentTempDirTest { return IO.toString(new FileReader(filePath.toFile())); } - - public static class WaitScannerListener implements Scanner.BulkListener - { - CompletableFuture future = new CompletableFuture<>(); - - public void reset() - { - future = new CompletableFuture<>(); - } - - @Override - public void filesChanged(List filenames) - { - future.complete(null); - } - } }