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 <joakim.erdfelt@gmail.com>
This commit is contained in:
Joakim Erdfelt 2021-08-02 09:15:09 -07:00
parent 1c16aa8993
commit 242f6621ae
1 changed files with 21 additions and 31 deletions

View File

@ -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<Void> future = new CompletableFuture<>();
public void reset()
{
future = new CompletableFuture<>();
}
@Override
public void filesChanged(List<String> filenames)
{
future.complete(null);
}
}
}