diff --git a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/InfinispanTestSupport.java b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/InfinispanTestSupport.java index cb12972ced6f..bf822dd7e7e2 100644 --- a/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/InfinispanTestSupport.java +++ b/tests/test-sessions/test-infinispan-sessions/src/test/java/org/eclipse/jetty/server/session/InfinispanTestSupport.java @@ -20,9 +20,13 @@ import java.io.File; import java.lang.annotation.ElementType; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.Properties; -import org.eclipse.jetty.toolchain.test.MavenTestingUtils; +import org.eclipse.jetty.toolchain.test.FS; +import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; +import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension; import org.eclipse.jetty.util.IO; import org.hibernate.search.cfg.Environment; import org.hibernate.search.cfg.SearchMapping; @@ -33,6 +37,7 @@ import org.infinispan.configuration.global.GlobalConfigurationBuilder; import org.infinispan.manager.DefaultCacheManager; import org.infinispan.manager.EmbeddedCacheManager; +import org.junit.jupiter.api.extension.ExtendWith; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -40,8 +45,10 @@ /** * InfinispanTestSupport */ +@ExtendWith(WorkDirExtension.class) public class InfinispanTestSupport { + public WorkDir workDir; public static final String DEFAULT_CACHE_NAME = "session_test_cache"; public Cache _cache; @@ -95,22 +102,20 @@ public Cache getCache() public void setup() throws Exception { - File testdir = MavenTestingUtils.getTargetTestingDir(); - File tmp = new File(testdir, "indexes"); - IO.delete(tmp); - tmp.mkdirs(); + Path root = workDir.getEmptyPathDir(); + Path indexesDir = root.resolve("indexes"); + FS.ensureDirExists(indexesDir); SearchMapping mapping = new SearchMapping(); mapping.entity(SessionData.class).indexed().providedId().property("expiry", ElementType.FIELD).field(); Properties properties = new Properties(); properties.put(Environment.MODEL_MAPPING, mapping); - properties.put("hibernate.search.default.indexBase", tmp.getAbsolutePath()); + properties.put("hibernate.search.default.indexBase", indexesDir.toString()); if (_useFileStore) { - _tmpdir = File.createTempFile("infini", "span"); - _tmpdir.delete(); - _tmpdir.mkdir(); + Path tmpDir = Files.createTempDirectory("infinispan"); + _tmpdir = tmpDir.toFile(); ConfigurationChildBuilder b = _builder.indexing() .index(Index.ALL) diff --git a/tests/test-webapps/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java b/tests/test-webapps/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java index 8ae623725962..28fd6547db47 100644 --- a/tests/test-webapps/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java +++ b/tests/test-webapps/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java @@ -18,7 +18,6 @@ package org.eclipse.jetty; -import java.io.File; import java.io.IOException; import java.lang.management.ManagementFactory; import java.nio.file.FileSystems; @@ -116,8 +115,8 @@ public static void main(String[] args) throws Exception login.setConfig(jettyRoot.resolve("tests/test-webapps/test-jetty-webapp/src/main/config/demo-base/etc/realm.properties").toString()); server.addBean(login); - File log = File.createTempFile("jetty-yyyy_mm_dd", "log"); - CustomRequestLog requestLog = new CustomRequestLog(log.toString()); + Path logPath = Files.createTempFile("jetty-yyyy_mm_dd", "log"); + CustomRequestLog requestLog = new CustomRequestLog(logPath.toString()); server.setRequestLog(requestLog); server.setStopAtShutdown(true); @@ -127,15 +126,11 @@ public static void main(String[] args) throws Exception webapp.setParentLoaderPriority(true); webapp.setResourceBase(jettyRoot.resolve("tests/test-webapps/test-jetty-webapp/src/main/webapp").toString()); webapp.setAttribute("testAttribute", "testValue"); - File sessiondir = File.createTempFile("sessions", null); - if (sessiondir.exists()) - sessiondir.delete(); - sessiondir.mkdir(); - sessiondir.deleteOnExit(); + Path sessionDir = Files.createTempDirectory("sessions"); DefaultSessionCache ss = new DefaultSessionCache(webapp.getSessionHandler()); FileSessionDataStore sds = new FileSessionDataStore(); ss.setSessionDataStore(sds); - sds.setStoreDir(sessiondir); + sds.setStoreDir(sessionDir.toFile()); webapp.getSessionHandler().setSessionCache(ss); contexts.addHandler(webapp);