Issue #5684 - Windows test overhaul (#6581)

Issue #5684 - Window's test overhaul

+ Migrate from @DisabledOnOs(WINDOWS) to assumptions on capabilities instead.
+ Fix other outstanding windows testing issues.
+ Cleanup FileBufferedResponseHandlerTest expectations on Windows.
+ PathWatcher scan interval is variable on windows
+ If unable to start testcase based on assumption,
  the stop shouldn't fail testcase
+ Increase various wait timeouts
+ Make tests less strict due to system speed issues
+ Disable Sni tests due to TLS behaviors differences in Windows
  + Windows TLSv1.3 seems to introduce this difference
  + If we restrict to TLSv1.2 this passes.
  + On Linux TLSv.13 on client side will always return a
  + javax.net.ssl.SSLHandshakeException in those test cases that expect it.
  + However, on Windows, Only the TLSv1.2 implementation will return a javax.net.ssl.SSLHandshakeException,
  + All other TLS versions on Windows will result in a
  + javax.net.ssl.SSLException: Software caused connection abort: recv failed
+ Disable ConcurrentStreamCreationTest
  + Not possible to create all of these streams.
+ Fixing DeploymentTempDirTest
  + Using unique workdir per testcase.
  + Don't expect to delete files / directories between tests
    (not supported on windows due to file locking anyway)
 + Fixing line ending difference on windows
 + InvalidPathException is a 404 Not Found
 + Cannot reuse test directory between runs due to memory mapped files that are still in use from previous run.
 + java.nio.file.FileSystemException: C:\code\jetty.project\jetty-webapp\target\tests\welcome#\index.html: The requested operation cannot be performed on a file with a user-mapped section open.

	at java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:92)
	at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
	at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:108)
	at java.base/sun.nio.fs.WindowsFileSystemProvider.newByteChannel(WindowsFileSystemProvider.java:235)
	at java.base/java.nio.file.spi.FileSystemProvider.newOutputStream(FileSystemProvider.java:478)
	at java.base/java.nio.file.Files.newOutputStream(Files.java:220)
	at org.eclipse.jetty.webapp/org.eclipse.jetty.webapp.WebAppDefaultServletTest.prepareServer(WebAppDefaultServletTest.java:84)

 + As is typical on windows, we are often unable to delete a file due to file locking issues.
 + Use a unique resource base between tests.
   This is to avoid file locking behaviors that prevent the
   resource base from being reused too quickly on windows.
 + Prevent test run if symlinks not supported
 + Allowing for Windows slosh char as well in asserts
 + SelectorUtils is File.separator dependent
 + Regex is now FS.separator independent
 + Using SelectorUtils from plexus correctly for include/exclude
 + Turning off mapped files for testing reasons.
 + Fix and re-enable RFC2616NIOHttpsTest
 + Issue #6552 - Fix test failures due to slf4j dep
 + Issue #6552 - upgrade testcontainers
 + Issue #6552 - move to assumption based docker existence
 + Issue #6552 - Fix enforcer rule violation on jna.
  Addresses the following side effect of upgrading testcontainers.

[WARNING] Rule 3: org.apache.maven.plugins.enforcer.RequireUpperBoundDeps failed with message:
Failed while enforcing RequireUpperBoundDeps. The error(s) are [
Require upper bound dependencies error for net.java.dev.jna:jna:5.6.0 paths to dependency are:
+-org.eclipse.jetty:infinispan-remote-query:10.0.7-SNAPSHOT
  +-org.testcontainers:testcontainers:1.16.0
    +-com.github.docker-java:docker-java-transport-zerodep:3.2.11
      +-net.java.dev.jna:jna:5.6.0 (managed) <-- net.java.dev.jna:jna:5.8.0

 + use annotation to disable test when docker not available and needed
 + Disabling FileSessionDistributionTests.stopRestartWebappTestSessionContentSaved on Windows
 + Using TLS basic
 + Programmatic removal of memory mapped behavior during testing
 + Fixing slf4j warning

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
Co-authored-by: Olivier Lamy <oliver.lamy@gmail.com>
This commit is contained in:
Joakim Erdfelt 2021-08-26 11:26:46 -05:00 committed by GitHub
parent 2689cf75d1
commit c5a33e27d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
55 changed files with 461 additions and 421 deletions

View File

@ -68,7 +68,6 @@ import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.EnabledOnJre;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.JRE;
@ -82,7 +81,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.condition.OS.LINUX;
import static org.junit.jupiter.api.condition.OS.WINDOWS;
// Other JREs have slight differences in how TLS work
// and this test expects a very specific TLS behavior.
@ -1027,7 +1025,6 @@ public class SslBytesServerTest extends SslBytesTest
}
@Test
@DisabledOnOs(WINDOWS) // Don't run on Windows (buggy JVM)
public void testRequestWithBigContentWriteBlockedThenReset() throws Exception
{
final SSLSocket client = newClient();
@ -1082,7 +1079,6 @@ public class SslBytesServerTest extends SslBytesTest
}
@Test
@DisabledOnOs(WINDOWS) // Don't run on Windows (buggy JVM)
public void testRequestWithBigContentReadBlockedThenReset() throws Exception
{
final SSLSocket client = newClient();

View File

@ -33,41 +33,49 @@ 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;
private final TestListener listener = new TestListener();
@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);
@ -75,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());

View File

@ -26,13 +26,10 @@ import org.eclipse.jetty.util.resource.Resource;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.extension.ExtendWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.junit.jupiter.api.condition.OS.WINDOWS;
/**
* Similar in scope to {@link ScanningAppProviderStartupTest}, except is concerned with the modification of existing
* deployed webapps due to incoming changes identified by the {@link ScanningAppProvider}.
@ -155,8 +152,6 @@ public class ScanningAppProviderRuntimeUpdatesTest
* @throws Exception on test failure
*/
@Test
@DisabledOnOs(WINDOWS)
// This test will not work on Windows as second war file would, not be written over the first one because of a file lock
public void testAfterStartupThenUpdateContext() throws Exception
{
jetty.copyWebapp("foo-webapp-1.war", "foo.war");

View File

@ -99,6 +99,8 @@ public class WebAppProviderTest
@Test
public void testStartupContext()
{
assumeTrue(symlinkSupported);
// Check Server for Handlers
jetty.assertWebAppContextsExists("/bar", "/foo", "/bob");

View File

@ -29,9 +29,12 @@ import org.eclipse.jetty.http2.frames.HeadersFrame;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.Promise;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
import static org.junit.jupiter.api.Assertions.assertTrue;
@DisabledOnOs(value = OS.WINDOWS, disabledReason = "Unable to create all of the streams")
public class ConcurrentStreamCreationTest extends AbstractTest
{
@Test

View File

@ -98,9 +98,8 @@ public class SmallThreadPoolLoadTest extends AbstractTest
Thread testThread = Thread.currentThread();
Scheduler.Task task = client.getScheduler().schedule(() ->
{
logger.warn("Interrupting test, it is taking too long{}Server:{}{}{}Client:{}{}",
System.lineSeparator(), System.lineSeparator(), server.dump(),
System.lineSeparator(), System.lineSeparator(), client.dump());
logger.warn("Interrupting test, it is taking too long - \nServer: \n" +
server.dump() + "\nClient: \n" + client.dump());
testThread.interrupt();
}, iterations * factor, TimeUnit.MILLISECONDS);
@ -184,9 +183,8 @@ public class SmallThreadPoolLoadTest extends AbstractTest
if (success)
latch.countDown();
else
logger.warn("Request {} took too long{}Server:{}{}{}Client:{}{}", requestId,
System.lineSeparator(), System.lineSeparator(), server.dump(),
System.lineSeparator(), System.lineSeparator(), client.dump());
logger.warn("Request {} took too long - \nServer: \n" +
server.dump() + "\nClient: \n" + client.dump(), requestId);
return !reset.get();
}

View File

@ -125,6 +125,11 @@
<artifactId>maven-artifact-transfer</artifactId>
<version>0.12.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>

View File

@ -28,7 +28,6 @@ import java.util.jar.Manifest;
import org.codehaus.plexus.util.SelectorUtils;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.resource.JarResource;
import org.slf4j.Logger;
@ -87,7 +86,7 @@ public class SelectiveJarResource extends JarResource
{
for (String include : _includes)
{
if (SelectorUtils.matchPath(include, name, _caseSensitive))
if (SelectorUtils.matchPath(include, name, "/", _caseSensitive))
{
return true;
}
@ -99,7 +98,7 @@ public class SelectiveJarResource extends JarResource
{
for (String exclude : _excludes)
{
if (SelectorUtils.matchPath(exclude, name, _caseSensitive))
if (SelectorUtils.matchPath(exclude, name, "/", _caseSensitive))
{
return true;
}
@ -140,8 +139,8 @@ public class SelectiveJarResource extends JarResource
String entryName = entry.getName();
LOG.debug("Looking at {}", entryName);
String dotCheck = StringUtil.replace(entryName, '\\', '/');
dotCheck = URIUtil.canonicalPath(dotCheck);
// make sure no access out of the root entry is present
String dotCheck = URIUtil.canonicalPath(entryName);
if (dotCheck == null)
{
LOG.info("Invalid entry: {}", entryName);

View File

@ -13,96 +13,81 @@
package org.eclipse.jetty.maven.plugin;
import java.io.File;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.util.resource.Resource;
import org.junit.jupiter.api.BeforeEach;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
*
*
*/
@ExtendWith(WorkDirExtension.class)
public class TestSelectiveJarResource
{
File unpackParent;
@BeforeEach
public void setUp() throws Exception
{
unpackParent = MavenTestingUtils.getTargetTestingDir("selective-jar-resource");
unpackParent.mkdirs();
}
public WorkDir workDir;
@Test
public void testIncludesNoExcludes() throws Exception
{
File unpackDir = File.createTempFile("inc", "exc", unpackParent);
unpackDir.delete();
unpackDir.mkdirs();
Path unpackDir = workDir.getEmptyPathDir();
File testJar = MavenTestingUtils.getTestResourceFile("selective-jar-test.jar");
try (SelectiveJarResource sjr = new SelectiveJarResource(new URL("jar:" + Resource.toURL(testJar).toString() + "!/"));)
Path testJar = MavenTestingUtils.getTestResourcePathFile("selective-jar-test.jar");
try (SelectiveJarResource sjr = new SelectiveJarResource(new URL("jar:" + testJar.toUri().toASCIIString() + "!/")))
{
sjr.setCaseSensitive(false);
List<String> includes = new ArrayList<>();
includes.add("**/*.html");
sjr.setIncludes(includes);
sjr.copyTo(unpackDir);
assertTrue(Files.exists(unpackDir.toPath().resolve("top.html")));
assertTrue(Files.exists(unpackDir.toPath().resolve("aa/a1.html")));
assertTrue(Files.exists(unpackDir.toPath().resolve("aa/a2.html")));
assertTrue(Files.exists(unpackDir.toPath().resolve("aa/deep/a3.html")));
assertTrue(Files.exists(unpackDir.toPath().resolve("bb/b1.html")));
assertTrue(Files.exists(unpackDir.toPath().resolve("bb/b2.html")));
assertTrue(Files.exists(unpackDir.toPath().resolve("cc/c1.html")));
assertTrue(Files.exists(unpackDir.toPath().resolve("cc/c2.html")));
sjr.copyTo(unpackDir.toFile());
assertTrue(Files.exists(unpackDir.resolve("top.html")));
assertTrue(Files.exists(unpackDir.resolve("aa/a1.html")));
assertTrue(Files.exists(unpackDir.resolve("aa/a2.html")));
assertTrue(Files.exists(unpackDir.resolve("aa/deep/a3.html")));
assertTrue(Files.exists(unpackDir.resolve("bb/b1.html")));
assertTrue(Files.exists(unpackDir.resolve("bb/b2.html")));
assertTrue(Files.exists(unpackDir.resolve("cc/c1.html")));
assertTrue(Files.exists(unpackDir.resolve("cc/c2.html")));
}
}
@Test
public void testExcludesNoIncludes() throws Exception
{
File unpackDir = File.createTempFile("exc", "inc", unpackParent);
unpackDir.delete();
unpackDir.mkdirs();
File testJar = MavenTestingUtils.getTestResourceFile("selective-jar-test.jar");
try (SelectiveJarResource sjr = new SelectiveJarResource(new URL("jar:" + Resource.toURL(testJar).toString() + "!/"));)
Path unpackDir = workDir.getEmptyPathDir();
Path testJar = MavenTestingUtils.getTestResourcePathFile("selective-jar-test.jar");
try (SelectiveJarResource sjr = new SelectiveJarResource(new URL("jar:" + testJar.toUri().toASCIIString() + "!/")))
{
sjr.setCaseSensitive(false);
List<String> excludes = new ArrayList<>();
excludes.add("**/*");
sjr.setExcludes(excludes);
sjr.copyTo(unpackDir);
assertFalse(Files.exists(unpackDir.toPath().resolve("top.html")));
assertFalse(Files.exists(unpackDir.toPath().resolve("aa/a1.html")));
assertFalse(Files.exists(unpackDir.toPath().resolve("aa/a2.html")));
assertFalse(Files.exists(unpackDir.toPath().resolve("aa/deep/a3.html")));
assertFalse(Files.exists(unpackDir.toPath().resolve("bb/b1.html")));
assertFalse(Files.exists(unpackDir.toPath().resolve("bb/b2.html")));
assertFalse(Files.exists(unpackDir.toPath().resolve("cc/c1.html")));
assertFalse(Files.exists(unpackDir.toPath().resolve("cc/c2.html")));
sjr.copyTo(unpackDir.toFile());
assertFalse(Files.exists(unpackDir.resolve("top.html")));
assertFalse(Files.exists(unpackDir.resolve("aa/a1.html")));
assertFalse(Files.exists(unpackDir.resolve("aa/a2.html")));
assertFalse(Files.exists(unpackDir.resolve("aa/deep/a3.html")));
assertFalse(Files.exists(unpackDir.resolve("bb/b1.html")));
assertFalse(Files.exists(unpackDir.resolve("bb/b2.html")));
assertFalse(Files.exists(unpackDir.resolve("cc/c1.html")));
assertFalse(Files.exists(unpackDir.resolve("cc/c2.html")));
}
}
@Test
public void testIncludesExcludes() throws Exception
{
File unpackDir = File.createTempFile("exc", "andinc", unpackParent);
unpackDir.delete();
unpackDir.mkdirs();
File testJar = MavenTestingUtils.getTestResourceFile("selective-jar-test.jar");
try (SelectiveJarResource sjr = new SelectiveJarResource(new URL("jar:" + Resource.toURL(testJar).toString() + "!/"));)
Path unpackDir = workDir.getEmptyPathDir();
Path testJar = MavenTestingUtils.getTestResourcePathFile("selective-jar-test.jar");
try (SelectiveJarResource sjr = new SelectiveJarResource(new URL("jar:" + testJar.toUri().toASCIIString() + "!/")))
{
sjr.setCaseSensitive(false);
List<String> excludes = new ArrayList<>();
@ -111,15 +96,15 @@ public class TestSelectiveJarResource
List<String> includes = new ArrayList<>();
includes.add("bb/*");
sjr.setIncludes(includes);
sjr.copyTo(unpackDir);
assertFalse(Files.exists(unpackDir.toPath().resolve("top.html")));
assertFalse(Files.exists(unpackDir.toPath().resolve("aa/a1.html")));
assertFalse(Files.exists(unpackDir.toPath().resolve("aa/a2.html")));
assertFalse(Files.exists(unpackDir.toPath().resolve("aa/deep/a3.html")));
assertTrue(Files.exists(unpackDir.toPath().resolve("bb/b1.html")));
assertTrue(Files.exists(unpackDir.toPath().resolve("bb/b2.html")));
assertFalse(Files.exists(unpackDir.toPath().resolve("cc/c1.html")));
assertFalse(Files.exists(unpackDir.toPath().resolve("cc/c2.html")));
sjr.copyTo(unpackDir.toFile());
assertFalse(Files.exists(unpackDir.resolve("top.html")));
assertFalse(Files.exists(unpackDir.resolve("aa/a1.html")));
assertFalse(Files.exists(unpackDir.resolve("aa/a2.html")));
assertFalse(Files.exists(unpackDir.resolve("aa/deep/a3.html")));
assertTrue(Files.exists(unpackDir.resolve("bb/b1.html")));
assertTrue(Files.exists(unpackDir.resolve("bb/b2.html")));
assertFalse(Files.exists(unpackDir.resolve("cc/c1.html")));
assertFalse(Files.exists(unpackDir.resolve("cc/c2.html")));
}
}
}

View File

@ -0,0 +1,5 @@
# Jetty Logging using jetty-slf4j-impl
#org.eclipse.jetty.maven.plugin.LEVEL=DEBUG
#org.eclipse.jetty.LEVEL=DEBUG
#org.eclipse.jetty.server.LEVEL=DEBUG
#org.eclipse.jetty.http.LEVEL=DEBUG

View File

@ -1290,7 +1290,7 @@ public class AsyncMiddleManServletTest
startClient();
ContentResponse response = client.newRequest("localhost", serverConnector.getLocalPort())
.timeout(5, TimeUnit.SECONDS)
.timeout(10, TimeUnit.SECONDS)
.send();
assertEquals(200, response.getStatus());

View File

@ -48,7 +48,6 @@ import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.condition.OS.MAC;
import static org.junit.jupiter.api.condition.OS.WINDOWS;
@ExtendWith(WorkDirExtension.class)
public class PropertyUserStoreTest
@ -277,7 +276,6 @@ public class PropertyUserStoreTest
}
@Test
@DisabledOnOs({MAC, WINDOWS}) // File is locked on OS, cannot change.
public void testPropertyUserStoreLoadRemoveUser() throws Exception
{
testdir.ensureEmpty();

View File

@ -19,6 +19,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.nio.file.InvalidPathException;
import java.util.Collection;
import java.util.Enumeration;
import java.util.List;
@ -297,6 +298,16 @@ public class ResourceService
// Send the data
releaseContent = sendData(request, response, included, content, reqRanges);
}
// Can be thrown from contentFactory.getContent() call when using invalid characters
catch (InvalidPathException e)
{
if (LOG.isDebugEnabled())
LOG.debug("InvalidPathException for pathInContext: {}", pathInContext, e);
if (included)
throw new FileNotFoundException("!" + pathInContext);
notFound(request, response);
return response.isCommitted();
}
catch (IllegalArgumentException e)
{
LOG.warn("Failed to serve resource: {}", pathInContext, e);

View File

@ -114,7 +114,9 @@ public class FileBufferedResponseHandler extends BufferedResponseHandler
}
catch (Throwable t)
{
LOG.warn("Could not delete file {}", _filePath, t);
if (LOG.isDebugEnabled())
LOG.debug("Could not immediately delete file (delaying to jvm exit) {}", _filePath, t);
_filePath.toFile().deleteOnExit();
}
_filePath = null;
}

View File

@ -149,7 +149,7 @@ public class GracefulStopTest
HttpTester.Response response = HttpTester.parseResponse(client.getInputStream());
assertThat(response.getStatus(), is(200));
assertThat(response.getContent(), is("read 10/10\n"));
assertThat(response.getContent(), is("read [10/10]"));
assertThat(response.get(HttpHeader.CONNECTION), nullValue());
return client;
@ -164,7 +164,7 @@ public class GracefulStopTest
HttpTester.Response response = HttpTester.parseResponse(client.getInputStream());
assertThat(response.getStatus(), is(200));
assertThat(response.getContent(), is("read 10/10\n"));
assertThat(response.getContent(), is("read [10/10]"));
assertThat(response.get(HttpHeader.CONNECTION), nullValue());
}
@ -224,7 +224,7 @@ public class GracefulStopTest
assertThat(response.get(HttpHeader.CONNECTION), is("close"));
else
assertThat(response.get(HttpHeader.CONNECTION), nullValue());
assertThat(response.getContent(), is("read 10/10\n"));
assertThat(response.getContent(), is("read [10/10]"));
}
void assert500Response(Socket client) throws Exception
@ -414,7 +414,7 @@ public class GracefulStopTest
}
}
response.getWriter().printf("read %d/%d%n", c, contentLength);
response.getWriter().printf("read [%d/%d]", c, contentLength);
}
catch (Throwable th)
{

View File

@ -45,6 +45,8 @@ import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.util.IO;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.anyOf;
@ -214,6 +216,7 @@ public class ServerConnectorTest
}
@Test
@DisabledOnOs(value = OS.WINDOWS, disabledReason = "SO_REUSEPORT not available on windows")
public void testReusePort() throws Exception
{
int port;

View File

@ -30,10 +30,8 @@ import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -42,11 +40,8 @@ import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.condition.OS.MAC;
@Disabled
@Tag("stress")
@DisabledOnOs(MAC) // TODO: needs investigation
public class StressTest
{
private static final Logger LOG = LoggerFactory.getLogger(StressTest.class);
@ -129,6 +124,7 @@ public class StressTest
}
@Test
@Tag("Slow")
public void testNonPersistent() throws Throwable
{
doThreads(20, 20, false);
@ -145,6 +141,7 @@ public class StressTest
}
@Test
@Tag("Slow")
public void testPersistent() throws Throwable
{
doThreads(40, 40, true);

View File

@ -45,10 +45,14 @@ import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
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.Callback;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.api.extension.ExtendWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -60,10 +64,13 @@ import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ExtendWith(WorkDirExtension.class)
public class FileBufferedResponseHandlerTest
{
private static final Logger LOG = LoggerFactory.getLogger(FileBufferedResponseHandlerTest.class);
public WorkDir _workDir;
private final CountDownLatch _disposeLatch = new CountDownLatch(1);
private Server _server;
private LocalConnector _localConnector;
@ -74,8 +81,7 @@ public class FileBufferedResponseHandlerTest
@BeforeEach
public void before() throws Exception
{
_testDir = MavenTestingUtils.getTargetTestingPath(FileBufferedResponseHandlerTest.class.getName());
FS.ensureDirExists(_testDir);
_testDir = _workDir.getEmptyPathDir();
_server = new Server();
HttpConfiguration config = new HttpConfiguration();
@ -109,8 +115,6 @@ public class FileBufferedResponseHandlerTest
_bufferedHandler.getPathIncludeExclude().exclude("*.exclude");
_bufferedHandler.getMimeIncludeExclude().exclude("text/excluded");
_server.setHandler(_bufferedHandler);
FS.ensureEmpty(_testDir);
}
@AfterEach
@ -175,8 +179,13 @@ public class FileBufferedResponseHandlerTest
assertThat(responseContent, containsString("Committed: false"));
assertThat(responseContent, containsString("NumFiles: 1"));
assertTrue(_disposeLatch.await(5, TimeUnit.SECONDS));
assertThat(getNumFiles(), is(0));
// Unable to verify file deletion on windows, as immediate delete not possible.
// only after a GC has occurred.
if (!OS.WINDOWS.isCurrentOs())
{
assertTrue(_disposeLatch.await(5, TimeUnit.SECONDS));
assertThat(getNumFiles(), is(0));
}
}
@Test
@ -269,8 +278,13 @@ public class FileBufferedResponseHandlerTest
assertThat(responseContent, containsString("Committed: false"));
assertThat(responseContent, containsString("NumFiles: 1"));
assertTrue(_disposeLatch.await(5, TimeUnit.SECONDS));
assertThat(getNumFiles(), is(0));
// Unable to verify file deletion on windows, as immediate delete not possible.
// only after a GC has occurred.
if (!OS.WINDOWS.isCurrentOs())
{
assertTrue(_disposeLatch.await(5, TimeUnit.SECONDS));
assertThat(getNumFiles(), is(0));
}
}
@Test
@ -301,8 +315,13 @@ public class FileBufferedResponseHandlerTest
assertThat(responseContent, not(containsString("writtenAfterClose")));
assertThat(responseContent, containsString("NumFiles: 1"));
assertTrue(_disposeLatch.await(5, TimeUnit.SECONDS));
assertThat(getNumFiles(), is(0));
// Unable to verify file deletion on windows, as immediate delete not possible.
// only after a GC has occurred.
if (!OS.WINDOWS.isCurrentOs())
{
assertTrue(_disposeLatch.await(5, TimeUnit.SECONDS));
assertThat(getNumFiles(), is(0));
}
}
@Test
@ -363,8 +382,13 @@ public class FileBufferedResponseHandlerTest
assertThat(response.getStatus(), is(HttpStatus.OK_200));
assertThat(responseContent, containsString("NumFiles: 0"));
assertTrue(_disposeLatch.await(5, TimeUnit.SECONDS));
assertThat(getNumFiles(), is(0));
// Unable to verify file deletion on windows, as immediate delete not possible.
// only after a GC has occurred.
if (!OS.WINDOWS.isCurrentOs())
{
assertTrue(_disposeLatch.await(5, TimeUnit.SECONDS));
assertThat(getNumFiles(), is(0));
}
}
@Test
@ -400,12 +424,18 @@ public class FileBufferedResponseHandlerTest
// Resetting the response buffer will delete the file.
assertThat(response.getStatus(), is(HttpStatus.OK_200));
assertThat(responseContent, not(containsString("THIS WILL BE RESET")));
assertThat(responseContent, containsString("NumFilesBeforeReset: 1"));
assertThat(responseContent, containsString("NumFilesAfterReset: 0"));
assertThat(responseContent, containsString("NumFilesAfterWrite: 1"));
assertTrue(_disposeLatch.await(5, TimeUnit.SECONDS));
assertThat(getNumFiles(), is(0));
// Unable to verify file deletion on windows, as immediate delete not possible.
// only after a GC has occurred.
if (!OS.WINDOWS.isCurrentOs())
{
assertTrue(_disposeLatch.await(5, TimeUnit.SECONDS));
assertThat(getNumFiles(), is(0));
}
}
@Test
@ -479,8 +509,13 @@ public class FileBufferedResponseHandlerTest
assertThat(response.get("FileSize"), is(Long.toString(fileSize)));
assertThat(received.get(), is(fileSize));
assertTrue(_disposeLatch.await(5, TimeUnit.SECONDS));
assertThat(getNumFiles(), is(0));
// Unable to verify file deletion on windows, as immediate delete not possible.
// only after a GC has occurred.
if (!OS.WINDOWS.isCurrentOs())
{
assertTrue(_disposeLatch.await(5, TimeUnit.SECONDS));
assertThat(getNumFiles(), is(0));
}
}
@Test
@ -553,9 +588,14 @@ public class FileBufferedResponseHandlerTest
Throwable error = errorFuture.get(5, TimeUnit.SECONDS);
assertThat(error.getMessage(), containsString("intentionally throwing from interceptor"));
// All files were deleted.
assertTrue(_disposeLatch.await(5, TimeUnit.SECONDS));
assertThat(getNumFiles(), is(0));
// Unable to verify file deletion on windows, as immediate delete not possible.
// only after a GC has occurred.
if (!OS.WINDOWS.isCurrentOs())
{
// All files were deleted.
assertTrue(_disposeLatch.await(5, TimeUnit.SECONDS));
assertThat(getNumFiles(), is(0));
}
}
@Test

View File

@ -17,7 +17,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.SocketException;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.security.KeyStore;
@ -26,7 +25,6 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManagerFactory;
import javax.servlet.ServletException;
@ -49,7 +47,6 @@ import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -59,7 +56,6 @@ import static org.hamcrest.Matchers.emptyOrNullString;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.condition.OS.WINDOWS;
/**
* HttpServer Tester for SSL based ServerConnector
@ -124,43 +120,6 @@ public class ServerConnectorSslServerTest extends HttpServerTestBase
return socket;
}
@Override
@DisabledOnOs(WINDOWS) // Don't run on Windows (buggy JVM)
public void testFullMethod() throws Exception
{
try
{
super.testFullMethod();
}
catch (SocketException e)
{
// TODO This needs to be investigated #2244
LOG.warn("Close overtook 400 response", e);
}
catch (SSLException e)
{
// TODO This needs to be investigated #2244
if (e.getCause() instanceof SocketException)
LOG.warn("Close overtook 400 response", e);
else
throw e;
}
}
@Override
@DisabledOnOs(WINDOWS) // Don't run on Windows (buggy JVM)
public void testFullURI() throws Exception
{
try
{
super.testFullURI();
}
catch (SocketException e)
{
LOG.warn("Close overtook 400 response", e);
}
}
@Override
public void testFullHeader() throws Exception
{

View File

@ -235,8 +235,8 @@ public class SniSslConnectionFactoryTest
assertThat(response, Matchers.containsString("Invalid SNI"));
}
@DisabledOnOs(value = OS.WINDOWS, disabledReason = "See Issue #6609 - TLSv1.3 behavior differences between Linux and Windows")
@Test
@DisabledOnOs(OS.WINDOWS)
public void testWrongSNIRejectedConnection() throws Exception
{
start(ssl ->
@ -275,8 +275,8 @@ public class SniSslConnectionFactoryTest
assertThat(response.getStatus(), is(400));
}
@DisabledOnOs(value = OS.WINDOWS, disabledReason = "See Issue #6609 - TLSv1.3 behavior differences between Linux and Windows")
@Test
@DisabledOnOs(OS.WINDOWS)
public void testWrongSNIRejectedFunction() throws Exception
{
start((ssl, customizer) ->
@ -302,8 +302,8 @@ public class SniSslConnectionFactoryTest
assertThat(response.getStatus(), is(400));
}
@DisabledOnOs(value = OS.WINDOWS, disabledReason = "See Issue #6609 - TLSv1.3 behavior differences between Linux and Windows")
@Test
@DisabledOnOs(OS.WINDOWS)
public void testWrongSNIRejectedConnectionWithNonSNIKeystore() throws Exception
{
start(ssl ->

View File

@ -37,6 +37,7 @@ import org.eclipse.jetty.util.URIUtil;
* will be handled by any servlets mapped to that URL.
*
* Requests to "/some/directory" will be redirected to "/some/directory/".
* @deprecated no replacement is offered, use standard Servlet web.xml welcome features
*/
@Deprecated
public class WelcomeFilter implements Filter

View File

@ -45,6 +45,7 @@ import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.lessThan;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ -289,7 +290,8 @@ public abstract class AbstractDoSFilterTest
String responses = doRequests(request1 + request2 + request1 + request2 + request1, 2, 1100, 1100, last);
assertEquals(11, count(responses, "HTTP/1.1 200 OK"));
assertEquals(0, count(responses, "DoSFilter: delayed"));
// This test is system speed dependent, so allow some (20%-ish) requests to be delayed, but not more.
assertThat("delayed count", count(responses, "DoSFilter: delayed"), lessThan(2));
// alternate between sessions
responses = doRequests(request1 + request2 + request1 + request2 + request1, 2, 250, 250, last);

View File

@ -25,6 +25,7 @@ import org.eclipse.jetty.http.UriCompliance;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.LocalConnector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.DefaultServlet;
import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.webapp.WebAppContext;
@ -80,6 +81,8 @@ public class WelcomeFilterTest
}
WebAppContext context = new WebAppContext(server, directoryPath.toString(), "/");
// Turn off memory-mapped behavior in DefaultServlet for Windows testing reasons.
context.setInitParameter(DefaultServlet.CONTEXT_INIT + "useFileMappedBuffer", "false");
server.setHandler(context);
String concatPath = "/*";

View File

@ -24,10 +24,8 @@ public class JettyLoggingServiceProvider implements SLF4JServiceProvider
{
/**
* Declare the version of the SLF4J API this implementation is compiled against.
* The value of this field is modified with each major release.
*/
// to avoid constant folding by the compiler, this field must *not* be final
public static String REQUESTED_API_VERSION = "1.8.99"; // !final
private static final String REQUESTED_API_VERSION = "2.0";
private JettyLoggerFactory loggerFactory;
private BasicMarkerFactory markerFactory;

View File

@ -22,12 +22,12 @@ EXISTS|maindir/
EXISTS|start.ini
# Output Assertions [regex!] (order is irrelevant)
OUTPUT|INFO : mkdir ..jetty.base./start.d
OUTPUT|INFO : extra initialized in \$\{jetty.base\}/start.d/extra.ini
OUTPUT|INFO : mkdir ..jetty.base.[/\\]start.d
OUTPUT|INFO : extra initialized in \$\{jetty.base\}[/\\]start.d[/\\]extra.ini
OUTPUT|INFO : main transitively enabled, ini template available with --add-module=main
OUTPUT|INFO : optional initialized in \$\{jetty.base\}/start.d/optional.ini
OUTPUT|INFO : optional initialized in \$\{jetty.base\}[/\\]start.d[/\\]optional.ini
OUTPUT|INFO : base transitively enabled
OUTPUT|INFO : mkdir ..jetty.base./maindir
OUTPUT|INFO : mkdir ..jetty.base.[/\\]maindir
OUTPUT|INFO : Base directory was modified

View File

@ -22,12 +22,12 @@ EXISTS|maindir/
EXISTS|start.ini
# Output Assertions [regex!] (order is irrelevant)
OUTPUT|INFO : create ..jetty.base./start.ini
OUTPUT|INFO : extra initialized in ..jetty.base./start.ini
OUTPUT|INFO : create ..jetty.base.[/\\]start.ini
OUTPUT|INFO : extra initialized in ..jetty.base.[/\\]start.ini
OUTPUT|INFO : main transitively enabled, ini template available with --add-module=main
OUTPUT|INFO : optional initialized in ..jetty.base./start.ini
OUTPUT|INFO : optional initialized in ..jetty.base.[/\\]start.ini
OUTPUT|INFO : base transitively enabled
OUTPUT|INFO : mkdir ..jetty.base./maindir
OUTPUT|INFO : mkdir ..jetty.base.[/\\]maindir
OUTPUT|INFO : Base directory was modified

View File

@ -14,4 +14,4 @@ PROP|main.prop=value0
EXISTS|maindir/
EXISTS|start.d/main.ini
OUTPUT|INFO : main already enabled by \[\$\{jetty.base}[\\/]start.d/main.ini\]
OUTPUT|INFO : main already enabled by \[\$\{jetty.base}[/\\]start.d[/\\]main.ini\]

View File

@ -17,7 +17,7 @@ PROP|optional.prop=value0
EXISTS|maindir/
EXISTS|start.ini
OUTPUT|INFO : copy ..jetty.base./start.d/main.ini into ..jetty.base./start.ini
OUTPUT|INFO : optional initialized in ..jetty.base./start.ini
OUTPUT|INFO : mkdir ..jetty.base./maindir
OUTPUT|INFO : copy ..jetty.base.[/\\]start.d[/\\]main.ini into ..jetty.base.[/\\]start.ini
OUTPUT|INFO : optional initialized in ..jetty.base.[/\\]start.ini
OUTPUT|INFO : mkdir ..jetty.base.[/\\]maindir
OUTPUT|INFO : Base directory was modified

View File

@ -362,7 +362,7 @@ public class PathWatcherTest
capture.finishedLatch.await(LONG_TIME, TimeUnit.MILLISECONDS);
long end = System.nanoTime();
capture.assertEvents(expected);
assertThat(end - start, greaterThan(TimeUnit.MILLISECONDS.toNanos(2 * QUIET_TIME)));
assertThat(end - start, greaterThan(TimeUnit.MILLISECONDS.toNanos(2L * QUIET_TIME)));
Thread.sleep(WAIT_TIME);
capture.assertEvents(expected);

View File

@ -17,6 +17,7 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.util.ArrayList;
@ -28,40 +29,38 @@ import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
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.Scanner.Notification;
import org.eclipse.jetty.util.component.LifeCycle;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.extension.ExtendWith;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.condition.OS.WINDOWS;
@ExtendWith(WorkDirExtension.class)
public class ScannerTest
{
static File _directory;
static Scanner _scanner;
static BlockingQueue<Event> _queue = new LinkedBlockingQueue<>();
static BlockingQueue<Set<String>> _bulk = new LinkedBlockingQueue<>();
public WorkDir workDir;
private Path _directory;
private Scanner _scanner;
private BlockingQueue<Event> _queue = new LinkedBlockingQueue<>();
private BlockingQueue<Set<String>> _bulk = new LinkedBlockingQueue<>();
@BeforeAll
public static void setUpBeforeClass() throws Exception
@BeforeEach
public void setupScanner() throws Exception
{
File testDir = MavenTestingUtils.getTargetTestingDir(ScannerTest.class.getSimpleName());
FS.ensureEmpty(testDir);
// Use full path, pointing to a real directory (for FileSystems that are case-insensitive, like Windows and OSX to use)
// This is only needed for the various comparisons below to make sense.
_directory = testDir.toPath().toRealPath().toFile();
_directory = workDir.getEmptyPathDir();
_scanner = new Scanner();
_scanner.addDirectory(_directory.toPath());
_scanner.addDirectory(_directory);
_scanner.setScanInterval(0);
_scanner.setReportDirs(false);
_scanner.setReportExistingFilesOnStartup(false);
@ -94,11 +93,10 @@ public class ScannerTest
assertTrue(_bulk.isEmpty());
}
@AfterAll
public static void tearDownAfterClass() throws Exception
@AfterEach
public void cleanup() throws Exception
{
_scanner.stop();
IO.delete(_directory);
LifeCycle.stop(_scanner);
}
static class Event
@ -139,7 +137,7 @@ public class ScannerTest
@Test
public void testDepth() throws Exception
{
File root = new File(_directory, "root");
File root = new File(_directory.toFile(), "root");
FS.ensureDirExists(root);
FS.touch(new File(root, "foo.foo"));
FS.touch(new File(root, "foo2.foo"));
@ -215,7 +213,7 @@ public class ScannerTest
public void testPatterns() throws Exception
{
//test include and exclude patterns
File root = new File(_directory, "proot");
File root = new File(_directory.toFile(), "proot");
FS.ensureDirExists(root);
File ttt = new File(root, "ttt.txt");
@ -288,7 +286,7 @@ public class ScannerTest
}
@Test
@DisabledOnOs(WINDOWS) // TODO: needs review
@Tag("Slow")
public void testAddedChangeRemove() throws Exception
{
touch("a0");
@ -299,7 +297,7 @@ public class ScannerTest
Event event = _queue.poll(5, TimeUnit.SECONDS);
assertNotNull(event, "Event should not be null");
assertEquals(_directory + "/a0", event._filename);
assertEquals(_directory.resolve("a0").toString(), event._filename);
assertEquals(Notification.ADDED, event._notification);
// add 3 more files
@ -323,8 +321,8 @@ public class ScannerTest
List<Event> actualEvents = new ArrayList<>();
_queue.drainTo(actualEvents);
assertEquals(2, actualEvents.size());
Event a1 = new Event(_directory + "/a1", Notification.ADDED);
Event a3 = new Event(_directory + "/a3", Notification.REMOVED);
Event a1 = new Event(_directory.resolve("a1").toString(), Notification.ADDED);
Event a3 = new Event(_directory.resolve("a3").toString(), Notification.REMOVED);
assertThat(actualEvents, Matchers.containsInAnyOrder(a1, a3));
assertTrue(_queue.isEmpty());
@ -332,7 +330,7 @@ public class ScannerTest
_scanner.scan();
event = _queue.poll();
assertNotNull(event);
assertEquals(_directory + "/a2", event._filename);
assertEquals(_directory.resolve("a2").toString(), event._filename);
assertEquals(Notification.ADDED, event._notification);
assertTrue(_queue.isEmpty());
@ -353,7 +351,7 @@ public class ScannerTest
_scanner.scan();
event = _queue.poll();
assertNotNull(event);
assertEquals(_directory + "/a1", event._filename);
assertEquals(_directory.resolve("a1").toString(), event._filename);
assertEquals(Notification.CHANGED, event._notification);
assertTrue(_queue.isEmpty());
@ -361,7 +359,7 @@ public class ScannerTest
_scanner.scan();
event = _queue.poll();
assertNotNull(event);
assertEquals(_directory + "/a2", event._filename);
assertEquals(_directory.resolve("a2").toString(), event._filename);
assertEquals(Notification.CHANGED, event._notification);
assertTrue(_queue.isEmpty());
@ -371,8 +369,8 @@ public class ScannerTest
//Immediate notification of deletes.
_scanner.scan();
a1 = new Event(_directory + "/a1", Notification.REMOVED);
Event a2 = new Event(_directory + "/a2", Notification.REMOVED);
a1 = new Event(_directory.resolve("a1").toString(), Notification.REMOVED);
Event a2 = new Event(_directory.resolve("a2").toString(), Notification.REMOVED);
actualEvents = new ArrayList<>();
_queue.drainTo(actualEvents);
assertEquals(2, actualEvents.size());
@ -392,13 +390,12 @@ public class ScannerTest
_scanner.scan();
event = _queue.poll();
assertNotNull(event);
assertEquals(_directory + "/a2", event._filename);
assertEquals(_directory.resolve("a2").toString(), event._filename);
assertEquals(Notification.ADDED, event._notification);
assertTrue(_queue.isEmpty());
}
@Test
@DisabledOnOs(WINDOWS) // TODO: needs review
public void testSizeChange() throws Exception
{
touch("tsc0");
@ -408,12 +405,12 @@ public class ScannerTest
// takes 2 scans to notice tsc0 and check that it is stable.
Event event = _queue.poll();
assertNotNull(event);
assertEquals(_directory + "/tsc0", event._filename);
assertEquals(_directory.resolve("tsc0").toString(), event._filename);
assertEquals(Notification.ADDED, event._notification);
// Create a new file by writing to it.
long now = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
File file = new File(_directory, "st");
File file = new File(_directory.toFile(), "st");
try (OutputStream out = new FileOutputStream(file, true))
{
out.write('x');
@ -439,7 +436,7 @@ public class ScannerTest
_scanner.scan();
event = _queue.poll();
assertNotNull(event);
assertEquals(_directory + "/st", event._filename);
assertEquals(_directory.resolve("st").toString(), event._filename);
assertEquals(Notification.ADDED, event._notification);
// Modify size only
@ -456,21 +453,20 @@ public class ScannerTest
_scanner.scan();
event = _queue.poll();
assertNotNull(event);
assertEquals(_directory + "/st", event._filename);
assertEquals(_directory.resolve("st").toString(), event._filename);
assertEquals(Notification.CHANGED, event._notification);
}
}
private void delete(String string)
private void delete(String string) throws IOException
{
File file = new File(_directory, string);
if (file.exists())
IO.delete(file);
Path file = _directory.resolve(string);
Files.deleteIfExists(file);
}
private void touch(String string) throws IOException
{
File file = new File(_directory, string);
File file = new File(_directory.toFile(), string);
if (file.exists())
file.setLastModified(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()));
else

View File

@ -46,7 +46,6 @@ import org.eclipse.jetty.util.BufferUtil;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.api.extension.ExtendWith;
@ -641,7 +640,6 @@ public class FileSystemResourceTest
@ParameterizedTest
@MethodSource("fsResourceProvider")
@DisabledOnOs(WINDOWS)
public void testSymlink(Class<PathResource> resourceClass) throws Exception
{
Path dir = workDir.getEmptyPathDir();
@ -649,18 +647,20 @@ public class FileSystemResourceTest
Path foo = dir.resolve("foo");
Path bar = dir.resolve("bar");
boolean symlinkSupported;
try
{
Files.createFile(foo);
Files.createSymbolicLink(bar, foo);
symlinkSupported = true;
}
catch (UnsupportedOperationException | FileSystemException e)
{
// if unable to create symlink, no point testing the rest
// this is the path that Microsoft Windows takes.
assumeTrue(true, "Not supported");
symlinkSupported = false;
}
assumeTrue(symlinkSupported, "Symlink not supported");
try (Resource base = newResource(resourceClass, dir.toFile()))
{
Resource resFoo = base.addPath("foo");
@ -683,7 +683,6 @@ public class FileSystemResourceTest
@ParameterizedTest
@ValueSource(classes = PathResource.class) // FileResource does not support this
@DisabledOnOs(WINDOWS)
public void testNonExistantSymlink(Class<PathResource> resourceClass) throws Exception
{
Path dir = workDir.getEmptyPathDir();
@ -692,17 +691,19 @@ public class FileSystemResourceTest
Path foo = dir.resolve("foo");
Path bar = dir.resolve("bar");
boolean symlinkSupported;
try
{
Files.createSymbolicLink(bar, foo);
symlinkSupported = true;
}
catch (UnsupportedOperationException | FileSystemException e)
{
// if unable to create symlink, no point testing the rest
// this is the path that Microsoft Windows takes.
assumeTrue(true, "Not supported");
symlinkSupported = false;
}
assumeTrue(symlinkSupported, "Symlink not supported");
try (Resource base = newResource(resourceClass, dir.toFile()))
{
Resource resFoo = base.addPath("foo");
@ -835,8 +836,7 @@ public class FileSystemResourceTest
}
catch (InvalidPathException e)
{
// NTFS filesystem streams are unsupported on some platforms.
assumeTrue(true, "Not supported");
assumeTrue(false, "NTFS simple streams not supported");
}
}
}
@ -883,8 +883,7 @@ public class FileSystemResourceTest
}
catch (InvalidPathException e)
{
// NTFS filesystem streams are unsupported on some platforms.
assumeTrue(true, "Not supported");
assumeTrue(false, "NTFS $DATA streams not supported");
}
}
}
@ -929,15 +928,13 @@ public class FileSystemResourceTest
}
catch (InvalidPathException e)
{
// NTFS filesystem streams are unsupported on some platforms.
assumeTrue(true, "Not supported on this OS");
assumeTrue(false, "NTFS $DATA streams not supported");
}
}
}
@ParameterizedTest
@MethodSource("fsResourceProvider")
@DisabledOnOs(WINDOWS)
public void testSemicolon(Class<PathResource> resourceClass) throws Exception
{
Path dir = workDir.getEmptyPathDir();
@ -948,11 +945,9 @@ public class FileSystemResourceTest
Path foo = dir.resolve("foo;");
Files.createFile(foo);
}
catch (Exception e)
catch (InvalidPathException e)
{
// if unable to create file, no point testing the rest.
// this is the path that Microsoft Windows takes.
assumeTrue(true, "Not supported on this OS");
assumeTrue(false, "Unable to create file with semicolon");
}
try (Resource base = newResource(resourceClass, dir.toFile()))
@ -964,7 +959,6 @@ public class FileSystemResourceTest
@ParameterizedTest
@MethodSource("fsResourceProvider")
@DisabledOnOs(WINDOWS)
public void testSingleQuote(Class<PathResource> resourceClass) throws Exception
{
Path dir = workDir.getEmptyPathDir();
@ -976,11 +970,9 @@ public class FileSystemResourceTest
Path foo = dir.resolve("foo' bar");
Files.createFile(foo);
}
catch (Exception e)
catch (InvalidPathException e)
{
// if unable to create file, no point testing the rest.
// this is the path that Microsoft Windows takes.
assumeTrue(true, "Not supported on this OS");
assumeTrue(false, "Unable to create file with single quote");
}
try (Resource base = newResource(resourceClass, dir.toFile()))
@ -992,7 +984,6 @@ public class FileSystemResourceTest
@ParameterizedTest
@MethodSource("fsResourceProvider")
@DisabledOnOs(WINDOWS)
public void testSingleBackTick(Class<PathResource> resourceClass) throws Exception
{
Path dir = workDir.getEmptyPathDir();
@ -1004,11 +995,9 @@ public class FileSystemResourceTest
Path foo = dir.resolve("foo` bar");
Files.createFile(foo);
}
catch (Exception e)
catch (InvalidPathException e)
{
// if unable to create file, no point testing the rest.
// this is the path that Microsoft Windows takes.
assumeTrue(true, "Not supported on this OS");
assumeTrue(false, "Unable to create file with single back tick");
}
try (Resource base = newResource(resourceClass, dir.toFile()))
@ -1020,7 +1009,6 @@ public class FileSystemResourceTest
@ParameterizedTest
@MethodSource("fsResourceProvider")
@DisabledOnOs(WINDOWS)
public void testBrackets(Class<PathResource> resourceClass) throws Exception
{
Path dir = workDir.getEmptyPathDir();
@ -1032,11 +1020,9 @@ public class FileSystemResourceTest
Path foo = dir.resolve("foo[1]");
Files.createFile(foo);
}
catch (Exception e)
catch (InvalidPathException e)
{
// if unable to create file, no point testing the rest.
// this is the path that Microsoft Windows takes.
assumeTrue(true, "Not supported on this OS");
assumeTrue(false, "Unable to create file with square brackets");
}
try (Resource base = newResource(resourceClass, dir.toFile()))
@ -1048,7 +1034,6 @@ public class FileSystemResourceTest
@ParameterizedTest
@ValueSource(classes = PathResource.class) // FileResource does not support this
@DisabledOnOs(WINDOWS)
public void testBraces(Class<PathResource> resourceClass) throws Exception
{
Path dir = workDir.getEmptyPathDir();
@ -1060,11 +1045,9 @@ public class FileSystemResourceTest
Path foo = dir.resolve("foo.{bar}.txt");
Files.createFile(foo);
}
catch (Exception e)
catch (InvalidPathException e)
{
// if unable to create file, no point testing the rest.
// this is the path that Microsoft Windows takes.
assumeTrue(true, "Not supported on this OS");
assumeTrue(false, "Unable to create file with squiggle braces");
}
try (Resource base = newResource(resourceClass, dir.toFile()))
@ -1076,7 +1059,6 @@ public class FileSystemResourceTest
@ParameterizedTest
@ValueSource(classes = PathResource.class) // FileResource does not support this
@DisabledOnOs(WINDOWS)
public void testCaret(Class<PathResource> resourceClass) throws Exception
{
Path dir = workDir.getEmptyPathDir();
@ -1088,11 +1070,9 @@ public class FileSystemResourceTest
Path foo = dir.resolve("foo^3.txt");
Files.createFile(foo);
}
catch (Exception e)
catch (InvalidPathException e)
{
// if unable to create file, no point testing the rest.
// this is the path that Microsoft Windows takes.
assumeTrue(true, "Not supported on this OS");
assumeTrue(false, "Unable to create file with caret");
}
try (Resource base = newResource(resourceClass, dir.toFile()))
@ -1104,7 +1084,6 @@ public class FileSystemResourceTest
@ParameterizedTest
@ValueSource(classes = PathResource.class) // FileResource does not support this
@DisabledOnOs(WINDOWS)
public void testPipe(Class<PathResource> resourceClass) throws Exception
{
Path dir = workDir.getEmptyPathDir();
@ -1116,11 +1095,9 @@ public class FileSystemResourceTest
Path foo = dir.resolve("foo|bar.txt");
Files.createFile(foo);
}
catch (Exception e)
catch (InvalidPathException e)
{
// if unable to create file, no point testing the rest.
// this is the path that Microsoft Windows takes.
assumeTrue(true, "Not supported on this OS");
assumeTrue(false, "Unable to create file with pipe symbol");
}
try (Resource base = newResource(resourceClass, dir.toFile()))
@ -1477,10 +1454,7 @@ public class FileSystemResourceTest
}
catch (InvalidPathException e)
{
// if unable to create file, no point testing the rest.
// this is the path that occurs if you have a system that doesn't support UTF-8
// directory names (or you simply don't have a Locale set properly)
assumeTrue(true, "Not supported on this OS");
assumeTrue(false, "Unable to create directory with utf-8 character");
return;
}

View File

@ -19,6 +19,7 @@ import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.stream.Stream;
@ -29,7 +30,6 @@ import org.eclipse.jetty.util.IO;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.params.ParameterizedTest;
@ -43,6 +43,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
public class ResourceTest
{
@ -287,15 +288,23 @@ public class ResourceTest
}
@Test
@DisabledOnOs(OS.WINDOWS) // this uses forbidden characters on some Windows Environments
public void testGlobPath() throws IOException
{
Path testDir = MavenTestingUtils.getTargetTestingPath("testGlobPath");
FS.ensureEmpty(testDir);
String globReference = testDir.toAbsolutePath().toString() + File.separator + '*';
Resource globResource = Resource.newResource(globReference);
assertNotNull(globResource, "Should have produced a Resource");
try
{
String globReference = testDir.toAbsolutePath() + File.separator + '*';
Resource globResource = Resource.newResource(globReference);
assertNotNull(globResource, "Should have produced a Resource");
}
catch (InvalidPathException e)
{
// if unable to reference the glob file, no point testing the rest.
// this is the path that Microsoft Windows takes.
assumeTrue(false, "Glob not supported on this OS");
}
}
@Test

View File

@ -123,9 +123,22 @@ public class HugeResourceTest
@AfterAll
public static void cleanupTestFiles()
{
FS.ensureDeleted(staticBase);
FS.ensureDeleted(outputDir);
FS.ensureDeleted(multipartTempDir);
quietlyDelete(staticBase);
quietlyDelete(outputDir);
quietlyDelete(multipartTempDir);
}
private static void quietlyDelete(Path path)
{
try
{
if (path != null)
FS.ensureDeleted(path);
}
catch (Throwable ignore)
{
// ignore
}
}
private static void makeStaticFile(Path staticFile, long size) throws IOException

View File

@ -25,9 +25,10 @@ import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.util.IO;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
@ -295,6 +296,7 @@ public class TempDirTest
* so we _will_ have permission to write to this directory.
*/
@DisabledIfSystemProperty(named = "env", matches = "ci")
@DisabledOnOs(value = OS.WINDOWS, disabledReason = "Test/Temp directory is always writable")
@Test
public void attributeWithInvalidPermissions()
{

View File

@ -23,10 +23,11 @@ import org.eclipse.jetty.http.UriCompliance;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.LocalConnector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
@ -35,8 +36,10 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@ExtendWith(WorkDirExtension.class)
public class WebAppDefaultServletTest
{
public WorkDir workDir;
private Server server;
private LocalConnector connector;
@ -48,9 +51,7 @@ public class WebAppDefaultServletTest
connector.getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration().setUriCompliance(UriCompliance.RFC3986);
server.addConnector(connector);
Path directoryPath = MavenTestingUtils.getTargetTestingDir().toPath();
IO.delete(directoryPath.toFile());
Files.createDirectories(directoryPath);
Path directoryPath = workDir.getEmptyPathDir();
Path welcomeResource = directoryPath.resolve("index.html");
try (OutputStream output = Files.newOutputStream(welcomeResource))
{

View File

@ -63,6 +63,8 @@ import org.eclipse.jetty.websocket.server.config.JettyWebSocketServletContainerI
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsStringIgnoringCase;
@ -234,6 +236,7 @@ public class WebSocketOverHTTP2Test
}
@Test
@DisabledOnOs(value = OS.WINDOWS, disabledReason = "Issue #6660 - Windows does not throw ConnectException")
public void testWebSocketConnectPortDoesNotExist() throws Exception
{
startServer();

View File

@ -79,7 +79,8 @@
<settingsPath>src/it/settings.xml</settingsPath>
<invoker.mergeUserSettings>false</invoker.mergeUserSettings>
<surefire.rerunFailingTestsCount>0</surefire.rerunFailingTestsCount>
<testcontainers.version>1.15.1</testcontainers.version>
<testcontainers.version>1.16.0</testcontainers.version>
<jna.version>5.8.0</jna.version>
<mariadb.version>2.7.0</mariadb.version>
</properties>
@ -1151,7 +1152,7 @@
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>5.6.0</version>
<version>${jna.version}</version>
</dependency>
<!-- Old Deps -->
<dependency>

View File

@ -191,6 +191,11 @@
<artifactId>gcloud</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>

View File

@ -275,7 +275,7 @@ public class DistributionTests extends AbstractJettyHomeTest
}
@Test
@DisabledOnOs(OS.WINDOWS) // jnr not supported on windows
@DisabledOnOs(value = OS.WINDOWS, disabledReason = "jnr not supported on windows")
public void testUnixSocket() throws Exception
{
String dir = System.getProperty("jetty.unixdomain.dir");

View File

@ -42,8 +42,8 @@ public class LoggingOptionsTests extends AbstractJettyHomeTest
return Stream.of(
Arguments.of("logging-jetty",
Arrays.asList(
"\\$\\{jetty.home\\}/lib/logging/slf4j-api-.*\\.jar",
"\\$\\{jetty.home\\}/lib/logging/jetty-slf4j-impl-.*\\.jar"),
"\\$\\{jetty.home\\}[/\\\\]lib[/\\\\]logging[/\\\\]slf4j-api-.*\\.jar",
"\\$\\{jetty.home\\}[/\\\\]lib[/\\\\]logging[/\\\\]jetty-slf4j-impl-.*\\.jar"),
Arrays.asList(
"logging/slf4j",
"logging-jetty"
@ -51,9 +51,9 @@ public class LoggingOptionsTests extends AbstractJettyHomeTest
),
Arguments.of("logging-logback",
Arrays.asList(
"\\$\\{jetty.home\\}/lib/logging/slf4j-api-.*\\.jar",
"\\$\\{jetty.base\\}/lib/logging/logback-classic-.*\\.jar",
"\\$\\{jetty.base\\}/lib/logging/logback-core-.*\\.jar"
"\\$\\{jetty.home\\}[/\\\\]lib[/\\\\]logging[/\\\\]slf4j-api-.*\\.jar",
"\\$\\{jetty.base\\}[/\\\\]lib[/\\\\]logging[/\\\\]logback-classic-.*\\.jar",
"\\$\\{jetty.base\\}[/\\\\]lib[/\\\\]logging[/\\\\]logback-core-.*\\.jar"
),
Arrays.asList(
"logging/slf4j",
@ -62,8 +62,8 @@ public class LoggingOptionsTests extends AbstractJettyHomeTest
),
Arguments.of("logging-jul",
Arrays.asList(
"\\$\\{jetty.home\\}/lib/logging/slf4j-api-.*\\.jar",
"\\$\\{jetty.base\\}/lib/logging/slf4j-jdk14-.*\\.jar"
"\\$\\{jetty.home\\}[/\\\\]lib[/\\\\]logging[/\\\\]slf4j-api-.*\\.jar",
"\\$\\{jetty.base\\}[/\\\\]lib[/\\\\]logging[/\\\\]slf4j-jdk14-.*\\.jar"
),
Arrays.asList(
"logging/slf4j",
@ -72,8 +72,8 @@ public class LoggingOptionsTests extends AbstractJettyHomeTest
),
Arguments.of("logging-log4j1",
Arrays.asList(
"\\$\\{jetty.home\\}/lib/logging/slf4j-api-.*\\.jar",
"\\$\\{jetty.base\\}/lib/logging/slf4j-log4j12-.*\\.jar"
"\\$\\{jetty.home\\}[/\\\\]lib[/\\\\]logging[/\\\\]slf4j-api-.*\\.jar",
"\\$\\{jetty.base\\}[/\\\\]lib[/\\\\]logging[/\\\\]slf4j-log4j12-.*\\.jar"
),
Arrays.asList(
"logging/slf4j",
@ -82,10 +82,10 @@ public class LoggingOptionsTests extends AbstractJettyHomeTest
),
Arguments.of("logging-log4j2",
Arrays.asList(
"\\$\\{jetty.home\\}/lib/logging/slf4j-api-.*\\.jar",
"\\$\\{jetty.base\\}/lib/logging/log4j-slf4j18-impl-.*\\.jar",
"\\$\\{jetty.base\\}/lib/logging/log4j-api-.*\\.jar",
"\\$\\{jetty.base\\}/lib/logging/log4j-core-.*\\.jar"
"\\$\\{jetty.home\\}[/\\\\]lib[/\\\\]logging[/\\\\]slf4j-api-.*\\.jar",
"\\$\\{jetty.base\\}[/\\\\]lib[/\\\\]logging[/\\\\]log4j-slf4j18-impl-.*\\.jar",
"\\$\\{jetty.base\\}[/\\\\]lib[/\\\\]logging[/\\\\]log4j-api-.*\\.jar",
"\\$\\{jetty.base\\}[/\\\\]lib[/\\\\]logging[/\\\\]log4j-core-.*\\.jar"
),
Arrays.asList(
"logging/slf4j",
@ -95,7 +95,7 @@ public class LoggingOptionsTests extends AbstractJettyHomeTest
// Disabled, as slf4j noop is not supported by output/log monitoring of AbstractJettyHomeTest
/* Arguments.of("logging-noop",
Arrays.asList(
"\\$\\{jetty.home\\}/lib/logging/slf4j-api-.*\\.jar"
"\\$\\{jetty.home\\}[/\\\\]lib[/\\\\]logging[/\\\\]slf4j-api-.*\\.jar"
), Arrays.asList(
"logging/slf4j",
"logging-log4j2"
@ -103,12 +103,12 @@ public class LoggingOptionsTests extends AbstractJettyHomeTest
),*/
Arguments.of("logging-logback,logging-jcl-capture,logging-jul-capture,logging-log4j1-capture",
Arrays.asList(
"\\$\\{jetty.home\\}/lib/logging/slf4j-api-.*\\.jar",
"\\$\\{jetty.base\\}/lib/logging/logback-classic-.*\\.jar",
"\\$\\{jetty.base\\}/lib/logging/logback-core-.*\\.jar",
"\\$\\{jetty.base\\}/lib/logging/jcl-over-slf4j-.*\\.jar",
"\\$\\{jetty.base\\}/lib/logging/jul-to-slf4j-.*\\.jar",
"\\$\\{jetty.base\\}/lib/logging/log4j-over-slf4j-.*\\.jar"
"\\$\\{jetty.home\\}[/\\\\]lib[/\\\\]logging[/\\\\]slf4j-api-.*\\.jar",
"\\$\\{jetty.base\\}[/\\\\]lib[/\\\\]logging[/\\\\]logback-classic-.*\\.jar",
"\\$\\{jetty.base\\}[/\\\\]lib[/\\\\]logging[/\\\\]logback-core-.*\\.jar",
"\\$\\{jetty.base\\}[/\\\\]lib[/\\\\]logging[/\\\\]jcl-over-slf4j-.*\\.jar",
"\\$\\{jetty.base\\}[/\\\\]lib[/\\\\]logging[/\\\\]jul-to-slf4j-.*\\.jar",
"\\$\\{jetty.base\\}[/\\\\]lib[/\\\\]logging[/\\\\]log4j-over-slf4j-.*\\.jar"
),
Arrays.asList(
"logging/slf4j",

View File

@ -32,12 +32,14 @@ import org.eclipse.jetty.tests.distribution.AbstractJettyHomeTest;
import org.eclipse.jetty.tests.distribution.JettyHomeTester;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.testcontainers.junit.jupiter.Testcontainers;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@Testcontainers(disabledWithoutDocker = true)
public abstract class AbstractSessionDistributionTests extends AbstractJettyHomeTest
{

View File

@ -16,9 +16,12 @@ package org.eclipse.jetty.tests.distribution.session;
import java.util.Collections;
import java.util.List;
/**
*
*/
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.testcontainers.junit.jupiter.Testcontainers;
@Testcontainers(disabledWithoutDocker = false)
public class FileSessionDistributionTests extends AbstractSessionDistributionTests
{
@ -52,4 +55,11 @@ public class FileSessionDistributionTests extends AbstractSessionDistributionTes
return Collections.emptyList();
}
@Override
@Test
@DisabledOnOs(value = OS.WINDOWS, disabledReason = "File always locked between stop/start")
public void stopRestartWebappTestSessionContentSaved() throws Exception
{
super.stopRestartWebappTestSessionContentSaved();
}
}

View File

@ -43,6 +43,7 @@ public class FileSessionWithMemcacheDistributionTests extends AbstractSessionDis
{
memcached =
new GenericContainer("memcached:" + System.getProperty("memcached.docker.version", "1.6.6"))
.withExposedPorts(11211)
.withLogConsumer(new Slf4jLogConsumer(MEMCACHED_LOG));
memcached.start();
this.host = memcached.getContainerIpAddress();

View File

@ -30,9 +30,13 @@ import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.tests.distribution.JettyHomeTester;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.DockerClientFactory;
import org.testcontainers.containers.BindMode;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.output.Slf4jLogConsumer;
@ -43,22 +47,24 @@ import static org.hamcrest.Matchers.containsString;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* This simulate the onlyClient option which means the JVM running Jetty is only an Hazelcast client and not part
* of the cluster
*/
public class HazelcastSessionDistributionTests extends AbstractSessionDistributionTests
{
private static final Logger HAZELCAST_LOG = LoggerFactory.getLogger("org.eclipse.jetty.tests.distribution.session.HazelcastLogs");
private static final Logger LOGGER = LoggerFactory.getLogger(HazelcastSessionDistributionTests.class);
private GenericContainer hazelcast = new GenericContainer("hazelcast/hazelcast:" + System.getProperty("hazelcast.version", "4.1"))
private GenericContainer<?> hazelcast;
private Path hazelcastJettyPath;
@BeforeEach
public void setupHazelcast()
{
hazelcast = new GenericContainer<>("hazelcast/hazelcast:" + System.getProperty("hazelcast.version", "4.1"))
.withExposedPorts(5701)
.waitingFor(Wait.forListeningPort())
.withLogConsumer(new Slf4jLogConsumer(HAZELCAST_LOG));
private Path hazelcastJettyPath;
}
@Override
public void startExternalSessionStorage() throws Exception
@ -75,12 +81,12 @@ public class HazelcastSessionDistributionTests extends AbstractSessionDistributi
tokenValues.put("hazelcast_port", Integer.toString(hazelcastPort));
this.hazelcastJettyPath = Paths.get("target/hazelcast-client.xml");
transformFileWithHostAndPort(Paths.get("src/test/resources/hazelcast-client.xml"),
hazelcastJettyPath,
tokenValues);
hazelcastJettyPath,
tokenValues);
}
@Override
public void stopExternalSessionStorage() throws Exception
public void stopExternalSessionStorage()
{
hazelcast.stop();
}
@ -101,31 +107,32 @@ public class HazelcastSessionDistributionTests extends AbstractSessionDistributi
public List<String> getSecondStartExtraArgs()
{
return Arrays.asList(
"jetty.session.hazelcast.configurationLocation=" + hazelcastJettyPath.toAbsolutePath(),
"jetty.session.hazelcast.onlyClient=true"
);
"jetty.session.hazelcast.configurationLocation=" + hazelcastJettyPath.toAbsolutePath(),
"jetty.session.hazelcast.onlyClient=true"
);
}
@Disabled("not working see https://github.com/hazelcast/hazelcast/issues/18508")
/**
* This test simulate Hazelcast instance within Jetty a cluster member with an external Hazelcast instance
*/
@Test
@Disabled("not working see https://github.com/hazelcast/hazelcast/issues/18508")
public void testHazelcastRemoteAndPartOfCluster() throws Exception
{
Map<String, String> env = new HashMap<>();
// -Dhazelcast.local.publicAddress=127.0.0.1:5701
env.put("JAVA_OPTS", "-Dhazelcast.config=/opt/hazelcast/config_ext/hazelcast.xml");
try (GenericContainer hazelcast =
new GenericContainer("hazelcast/hazelcast:" + System.getProperty("hazelcast.version", "4.1"))
try (GenericContainer<?> hazelcast =
new GenericContainer<>("hazelcast/hazelcast:" + System.getProperty("hazelcast.version", "4.1"))
.withExposedPorts(5701, 5705)
.withEnv(env)
.waitingFor(Wait.forLogMessage(".*is STARTED.*", 1))
//.withNetworkMode("host")
//.waitingFor(Wait.forListeningPort())
.withClasspathResourceMapping("hazelcast-server.xml",
"/opt/hazelcast/config_ext/hazelcast.xml",
BindMode.READ_ONLY)
"/opt/hazelcast/config_ext/hazelcast.xml",
BindMode.READ_ONLY)
.withLogConsumer(new Slf4jLogConsumer(HAZELCAST_LOG)))
{
hazelcast.start();
@ -141,8 +148,8 @@ public class HazelcastSessionDistributionTests extends AbstractSessionDistributi
// tokenValues.put("hazelcast_multicast_port", Integer.toString(hazelcastMultiCastPort));
Path hazelcastJettyPath = Paths.get("target/hazelcast-jetty.xml");
transformFileWithHostAndPort(Paths.get("src/test/resources/hazelcast-jetty.xml"),
hazelcastJettyPath,
tokenValues);
hazelcastJettyPath,
tokenValues);
String jettyVersion = System.getProperty("jettyVersion");
JettyHomeTester distribution = JettyHomeTester.Builder.newInstance()
@ -195,7 +202,6 @@ public class HazelcastSessionDistributionTests extends AbstractSessionDistributi
assertThat(response.getContentAsString(), containsString("SESSION READ CHOCOLATE THE BEST:FRENCH"));
}
}
}
}
@ -220,13 +226,11 @@ public class HazelcastSessionDistributionTests extends AbstractSessionDistributi
newLine.setLength(0);
newLine.append(interpolated);
});
fileContent.append(newLine.toString());
fileContent.append(newLine);
fileContent.append(System.lineSeparator());
});
outputStream.write(fileContent.toString().getBytes(StandardCharsets.UTF_8));
}
}
}

View File

@ -32,12 +32,13 @@ public class MongodbSessionDistributionTests extends AbstractSessionDistribution
private static final Logger MONGO_LOG = LoggerFactory.getLogger("org.eclipse.jetty.tests.distribution.session.mongo");
private static final int MONGO_PORT = 27017;
final String imageName = "mongo:" + System.getProperty("mongo.docker.version", "2.2.7");
final GenericContainer mongoDBContainer =
new GenericContainer(imageName)
.withLogConsumer(new Slf4jLogConsumer(MONGO_LOG))
.waitingFor(new LogMessageWaitStrategy()
.withRegEx(".*waiting for connections.*"));
.withExposedPorts(MONGO_PORT);
private String host;
private int port;
@ -46,7 +47,7 @@ public class MongodbSessionDistributionTests extends AbstractSessionDistribution
{
mongoDBContainer.start();
host = mongoDBContainer.getHost();
port = mongoDBContainer.getMappedPort(27017);
port = mongoDBContainer.getMappedPort(MONGO_PORT);
}
@Override

View File

@ -13,7 +13,9 @@
package org.eclipse.jetty.test;
import java.io.IOException;
import java.net.URL;
import java.nio.file.FileSystemException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
@ -35,22 +37,23 @@ import org.eclipse.jetty.server.SecureRequestCustomizer;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.SslConnectionFactory;
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.component.LifeCycle;
import org.eclipse.jetty.util.ssl.KeyStoreScanner;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
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.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.condition.OS.WINDOWS;
import static org.junit.jupiter.api.Assumptions.assumeFalse;
@ExtendWith(WorkDirExtension.class)
public class KeyStoreScannerTest
@ -107,7 +110,7 @@ public class KeyStoreScannerTest
@AfterEach
public void stop() throws Exception
{
server.stop();
LifeCycle.stop(server);
}
@Test
@ -176,9 +179,9 @@ public class KeyStoreScannerTest
}
@Test
@DisabledOnOs(WINDOWS) // does not support symbolic link
public void testReloadChangingSymbolicLink() throws Exception
{
assumeFileSystemSupportsSymlink();
Path keystorePath = keystoreDir.resolve("symlinkKeystore");
start(sslContextFactory ->
{
@ -203,9 +206,9 @@ public class KeyStoreScannerTest
}
@Test
@DisabledOnOs(WINDOWS) // does not support symbolic link
public void testReloadChangingTargetOfSymbolicLink() throws Exception
{
assumeFileSystemSupportsSymlink();
Path keystoreLink = keystoreDir.resolve("symlinkKeystore");
Path oldKeystoreSrc = MavenTestingUtils.getTestResourcePathFile("oldKeystore");
Path newKeystoreSrc = MavenTestingUtils.getTestResourcePathFile("newKeystore");
@ -273,6 +276,28 @@ public class KeyStoreScannerTest
return (X509Certificate)certs[0];
}
private void assumeFileSystemSupportsSymlink() throws IOException
{
// Make symlink
Path dir = MavenTestingUtils.getTargetTestingPath("symlink-test");
FS.ensureEmpty(dir);
Path foo = dir.resolve("foo");
Path bar = dir.resolve("bar");
try
{
Files.createFile(foo);
Files.createSymbolicLink(bar, foo);
}
catch (UnsupportedOperationException | FileSystemException e)
{
// if unable to create symlink, no point testing the rest
// this is the path that Microsoft Windows takes.
assumeFalse(true, "Not supported");
}
}
private static class DefaultTrustManager implements X509TrustManager
{
@Override

View File

@ -96,7 +96,6 @@ public abstract class RFC2616BaseTest
server = testableserver;
server.load();
server.start();
//server.getServer().dumpStdErr();
}
@BeforeEach

View File

@ -18,13 +18,10 @@ import org.eclipse.jetty.test.support.XmlBasedJettyServer;
import org.eclipse.jetty.test.support.rawhttp.HttpSocket;
import org.eclipse.jetty.test.support.rawhttp.HttpsSocketImpl;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
/**
* Perform the RFC2616 tests against a server running with the Jetty NIO Connector and listening on HTTPS (HTTP over SSL).
* TODO
*/
@Disabled("TODO")
public class RFC2616NIOHttpsTest extends RFC2616BaseTest
{
@BeforeAll
@ -35,6 +32,7 @@ public class RFC2616NIOHttpsTest extends RFC2616BaseTest
server.addXmlConfiguration("RFC2616Base.xml");
server.addXmlConfiguration("RFC2616_Redirects.xml");
server.addXmlConfiguration("RFC2616_Filters.xml");
server.addXmlConfiguration("ssl.xml");
server.addXmlConfiguration("NIOHttps.xml");
setUpServer(server, RFC2616NIOHttpsTest.class);
}

View File

@ -77,6 +77,10 @@ public class XmlBasedJettyServer
Path webappsDir = MavenTestingUtils.getTargetPath("webapps");
properties.setProperty("test.webapps", webappsDir.toString());
Path keystorePath = MavenTestingUtils.getTestResourcePathFile("keystore.p12");
properties.setProperty("jetty.sslContext.keyStorePath", keystorePath.toString());
properties.setProperty("jetty.sslContext.keyStorePassword", "storepwd");
// Write out configuration for use by ConfigurationManager.
Path testConfig = targetDir.resolve("testable-jetty-server-config.properties");
try (OutputStream out = Files.newOutputStream(testConfig))

View File

@ -18,9 +18,7 @@ import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
@ -40,21 +38,8 @@ public class HttpsSocketImpl implements HttpSocket
public HttpsSocketImpl() throws Exception
{
@SuppressWarnings("unused")
HostnameVerifier hostnameVerifier = new HostnameVerifier()
{
@Override
public boolean verify(String urlHostName, SSLSession session)
{
LOG.warn("Warning: URL Host: " + urlHostName + " vs." + session.getPeerHost());
return true;
}
};
// Install the all-trusting trust manager
try
{
// TODO real trust manager
this.sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, SslContextFactory.TRUST_ALL_CERTS, new java.security.SecureRandom());
}
@ -70,7 +55,6 @@ public class HttpsSocketImpl implements HttpSocket
public Socket connect(InetAddress host, int port) throws IOException
{
SSLSocket sslsock = (SSLSocket)sslfactory.createSocket();
sslsock.setEnabledProtocols(new String[]{"TLSv1"});
SocketAddress address = new InetSocketAddress(host, port);
sslsock.connect(address);
return sslsock;

View File

@ -1,36 +1,31 @@
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_9_3.dtd">
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!-- =========================================================== -->
<!-- Set connectors -->
<!-- =========================================================== -->
<Call id="httpsConnector" name="addConnector">
<!-- =========================================================== -->
<Call name="addConnector">
<Arg>
<New class="org.eclipse.jetty.server.ServerConnector">
<Arg name="server"><Ref refid="Server" /></Arg>
<Arg name="factories">
<Array type="org.eclipse.jetty.server.ConnectionFactory">
<Item>
<New class="org.eclipse.jetty.server.SslConnectionFactory">
<Arg name="next">http/1.1</Arg>
<Arg name="sslContextFactory"><Ref refid="sslContextFactory"/></Arg>
</New>
</Item>
<Item>
<New class="org.eclipse.jetty.server.HttpConnectionFactory">
<Arg name="config"><Ref refid="sslHttpConfig"/></Arg>
</New>
</Item>
</Array>
</Arg>
<Set name="host"><Property name="jetty.http.host" /></Set>
<Set name="idleTimeout">30000</Set>
</New>
<Arg name="factories">
<Array type="org.eclipse.jetty.server.ConnectionFactory">
<Item>
<New class="org.eclipse.jetty.server.SslConnectionFactory">
<Arg name="next">http/1.1</Arg>
<Arg name="sslContextFactory"><Ref refid="sslContextFactory"/></Arg>
</New>
</Item>
<Item>
<New class="org.eclipse.jetty.server.HttpConnectionFactory">
<Arg name="config"><Ref refid="sslHttpConfig"/></Arg>
</New>
</Item>
</Array>
</Arg>
</New>
</Arg>
</Call>
</Configure>

View File

@ -1,22 +1,9 @@
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
<Configure id="sslContextFactory" class="org.eclipse.jetty.util.ssl.SslContextFactory$Server">
<Set name="KeyStorePath"><Property name="jetty.home" default="." />/<Property name="jetty.sslContext.keyStorePath" default="keystore.p12"/></Set>
<Set name="KeyStorePath"><Property name="jetty.sslContext.keyStorePath"/></Set>
<Set name="KeyStorePassword"><Property name="jetty.sslContext.keyStorePassword"/></Set>
<Set name="KeyManagerPassword"><Property name="jetty.sslContext.keyManagerPassword"/></Set>
<Set name="TrustStorePath"><Property name="jetty.home" default="." />/<Property name="jetty.sslContext.trustStorePath" default="keystore.p12"/></Set>
<Set name="TrustStorePassword"><Property name="jetty.sslContext.trustStorePassword"/></Set>
<Set name="ExcludeCipherSuites">
<Array type="String">
<Item>SSL_RSA_WITH_DES_CBC_SHA</Item>
<Item>SSL_DHE_RSA_WITH_DES_CBC_SHA</Item>
<Item>SSL_DHE_DSS_WITH_DES_CBC_SHA</Item>
<Item>SSL_RSA_EXPORT_WITH_RC4_40_MD5</Item>
<Item>SSL_RSA_EXPORT_WITH_DES40_CBC_SHA</Item>
<Item>SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA</Item>
<Item>SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA</Item>
</Array>
</Set>
<!-- =========================================================== -->
<!-- Create a TLS specific HttpConfiguration based on the -->
@ -27,7 +14,12 @@
<New id="sslHttpConfig" class="org.eclipse.jetty.server.HttpConfiguration">
<Arg><Ref refid="httpConfig"/></Arg>
<Call name="addCustomizer">
<Arg><New class="org.eclipse.jetty.server.SecureRequestCustomizer"/></Arg>
<Arg>
<New class="org.eclipse.jetty.server.SecureRequestCustomizer">
<Set name="sniRequired">false</Set>
<Set name="SniHostCheck">false</Set>
</New>
</Arg>
</Call>
</New>

View File

@ -10,4 +10,12 @@
</New>
</Arg>
</Call>
<Get name="systemClassMatcher">
<Call name="add"><Arg>org.slf4j.</Arg></Call>
<Call name="add"><Arg>org.eclipse.jetty.logging.</Arg></Call>
</Get>
<Get name="serverClassMatcher">
<Call name="add"><Arg>-org.slf4j.</Arg></Call>
<Call name="add"><Arg>-org.eclipse.jetty.logging.</Arg></Call>
</Get>
</Configure>

View File

@ -149,7 +149,8 @@ public class MemcachedTestHelper
@SuppressWarnings({"rawtypes", "unchecked"})
static GenericContainer memcached =
new GenericContainer("memcached:" + System.getProperty("memcached.docker.version", "1.6.6"))
.withLogConsumer(new Slf4jLogConsumer(MEMCACHED_LOG));
.withExposedPorts(11211)
.withLogConsumer(new Slf4jLogConsumer(MEMCACHED_LOG));
static
{

View File

@ -47,12 +47,13 @@ public class MongoTestHelper
public static final String DB_NAME = "HttpSessions";
public static final String COLLECTION_NAME = "testsessions";
private static final int MONGO_PORT = 27017;
static GenericContainer mongo =
new GenericContainer("mongo:" + System.getProperty("mongo.docker.version", "2.2.7"))
.withLogConsumer(new Slf4jLogConsumer(MONGO_LOG))
.waitingFor(new LogMessageWaitStrategy()
.withRegEx(".*waiting for connections.*"));
.withExposedPorts(MONGO_PORT);
static MongoClient mongoClient;
@ -66,7 +67,7 @@ public class MongoTestHelper
long start = System.currentTimeMillis();
mongo.start();
mongoHost = mongo.getHost();
mongoPort = mongo.getMappedPort(27017);
mongoPort = mongo.getMappedPort(MONGO_PORT);
LOG.info("Mongo container started for {}:{} - {}ms", mongoHost, mongoPort,
System.currentTimeMillis() - start);
mongoClient = new MongoClient(mongoHost, mongoPort);