Merge remote-tracking branch 'origin/jetty-10.0.x' into jetty-11.0.x

This commit is contained in:
Lachlan Roberts 2020-10-16 15:41:55 +11:00
commit 8a34442967
4 changed files with 31 additions and 41 deletions

View File

@ -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;
@ -111,8 +110,8 @@ public class TestServer
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 class TestServer
);
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);

View File

@ -71,7 +71,6 @@ import org.eclipse.jetty.io.ClientConnector;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.ssl.SslContextFactory;
@ -187,12 +186,11 @@ public class HttpClientTransportOverHTTP2Test extends AbstractTest
@Test
public void testRequestHasHTTP2Version() throws Exception
{
start(new AbstractHandler()
start(new EmptyServerHandler()
{
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
protected void service(String target, Request jettyRequest, HttpServletRequest request, HttpServletResponse response)
{
baseRequest.setHandled(true);
HttpVersion version = HttpVersion.fromString(request.getProtocol());
response.setStatus(version == HttpVersion.HTTP_2 ? HttpStatus.OK_200 : HttpStatus.INTERNAL_SERVER_ERROR_500);
}
@ -313,12 +311,11 @@ public class HttpClientTransportOverHTTP2Test extends AbstractTest
{
String path = "/path";
String query = "a=b";
start(new AbstractHandler()
start(new EmptyServerHandler()
{
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
protected void service(String target, Request jettyRequest, HttpServletRequest request, HttpServletResponse response)
{
baseRequest.setHandled(true);
assertEquals(path, request.getRequestURI());
assertEquals(query, request.getQueryString());
}
@ -337,12 +334,11 @@ public class HttpClientTransportOverHTTP2Test extends AbstractTest
{
String path = "/path";
String query = "a=b";
start(new AbstractHandler()
start(new EmptyServerHandler()
{
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
protected void service(String target, Request jettyRequest, HttpServletRequest request, HttpServletResponse response)
{
baseRequest.setHandled(true);
assertEquals(path, request.getRequestURI());
assertEquals(query, request.getQueryString());
}

View File

@ -21,6 +21,8 @@ package org.eclipse.jetty.webapp;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Locale;
import org.eclipse.jetty.server.Connector;
@ -102,14 +104,10 @@ public class WebInfConfiguration extends AbstractConfiguration
@Override
public void cloneConfigure(WebAppContext template, WebAppContext context) throws Exception
{
File tmpDir = File.createTempFile(WebInfConfiguration.getCanonicalNameForWebAppTmpDir(context), "", template.getTempDirectory().getParentFile());
if (tmpDir.exists())
{
IO.delete(tmpDir);
}
tmpDir.mkdir();
tmpDir.deleteOnExit();
context.setTempDirectory(tmpDir);
Path tmpDir = Files.createTempDirectory(template.getTempDirectory().getParentFile().toPath(), WebInfConfiguration.getCanonicalNameForWebAppTmpDir(context));
File tmpDirAsFile = tmpDir.toFile();
tmpDirAsFile.deleteOnExit();
context.setTempDirectory(tmpDirAsFile);
}
/**
@ -237,11 +235,7 @@ public class WebInfConfiguration extends AbstractConfiguration
else
{
//ensure file will always be unique by appending random digits
tmpDir = File.createTempFile(temp, ".dir", parent);
//delete the file that was created
tmpDir.delete();
//and make a directory of the same name
tmpDir.mkdirs();
tmpDir = Files.createTempDirectory(parent.toPath(), temp).toFile();
}
configureTempDirectory(tmpDir, context);

View File

@ -20,9 +20,13 @@ package org.eclipse.jetty.server.session;
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.cache.Index;
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 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* 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 class InfinispanTestSupport
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)