Merged branch 'jetty-9.4.x' into 'jetty-10.0.x'.

This commit is contained in:
Simone Bordet 2020-08-25 16:35:09 +02:00
commit 7fe313ae0e
1 changed files with 27 additions and 40 deletions

View File

@ -68,16 +68,17 @@ import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
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.BufferUtil;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.Utf8StringBuilder;
import org.eclipse.jetty.util.ajax.JSON;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Disabled;
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;
@ -88,11 +89,13 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ExtendWith(WorkDirExtension.class)
public class AsyncMiddleManServletTest
{
private static final Logger LOG = LoggerFactory.getLogger(AsyncMiddleManServletTest.class);
private static final String PROXIED_HEADER = "X-Proxied";
public WorkDir workDir;
private HttpClient client;
private Server proxy;
private ServerConnector proxyConnector;
@ -192,7 +195,7 @@ public class AsyncMiddleManServletTest
testClientRequestContentKnownLengthGzipped(1024 * 1024, true);
}
private void testClientRequestContentKnownLengthGzipped(int length, final boolean expectChunked) throws Exception
private void testClientRequestContentKnownLengthGzipped(int length, boolean expectChunked) throws Exception
{
byte[] bytes = new byte[length];
new Random().nextBytes(bytes);
@ -239,7 +242,7 @@ public class AsyncMiddleManServletTest
{
byte[] bytes = new byte[1024];
new Random().nextBytes(bytes);
final byte[] gzipBytes = gzip(bytes);
byte[] gzipBytes = gzip(bytes);
startServer(new HttpServlet()
{
@ -449,7 +452,7 @@ public class AsyncMiddleManServletTest
@Test
public void testDiscardUpstreamAndDownstreamKnownContentLengthGzipped() throws Exception
{
final byte[] bytes = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".getBytes(StandardCharsets.UTF_8);
byte[] bytes = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".getBytes(StandardCharsets.UTF_8);
startServer(new HttpServlet()
{
@Override
@ -643,7 +646,7 @@ public class AsyncMiddleManServletTest
testLargeChunkedBufferedDownstreamTransformation(true);
}
private void testLargeChunkedBufferedDownstreamTransformation(final boolean gzipped) throws Exception
private void testLargeChunkedBufferedDownstreamTransformation(boolean gzipped) throws Exception
{
// Tests the race between a incomplete write performed from ProxyResponseListener.onSuccess()
// and ProxyResponseListener.onComplete() being called before the write has completed.
@ -683,7 +686,7 @@ public class AsyncMiddleManServletTest
});
startClient();
final CountDownLatch latch = new CountDownLatch(1);
CountDownLatch latch = new CountDownLatch(1);
client.newRequest("localhost", serverConnector.getLocalPort())
.onResponseContent((response, content) ->
{
@ -823,7 +826,7 @@ public class AsyncMiddleManServletTest
testProxyResponseWriteFails(2);
}
private void testProxyResponseWriteFails(final int writeCount) throws Exception
private void testProxyResponseWriteFails(int writeCount) throws Exception
{
startServer(new HttpServlet()
{
@ -927,9 +930,9 @@ public class AsyncMiddleManServletTest
testAfterContentTransformerInputStreamReset(true);
}
private void testAfterContentTransformerInputStreamReset(final boolean overflow) throws Exception
private void testAfterContentTransformerInputStreamReset(boolean overflow) throws Exception
{
final byte[] data = new byte[]{'c', 'o', 'f', 'f', 'e', 'e'};
byte[] data = new byte[]{'c', 'o', 'f', 'f', 'e', 'e'};
startServer(new HttpServlet()
{
@Override
@ -979,12 +982,11 @@ public class AsyncMiddleManServletTest
assertArrayEquals(data, response.getContent());
}
@Disabled("See issue #3974")
@Test
public void testAfterContentTransformerOverflowingToDisk() throws Exception
{
// Make sure the temporary directory we use exists and it's empty.
Path targetTestsDir = prepareTargetTestsDir();
Path targetTestsDir = workDir.getEmptyPathDir();
String key0 = "id";
long value0 = 1;
@ -1066,7 +1068,7 @@ public class AsyncMiddleManServletTest
@Test
public void testAfterContentTransformerClosingFilesOnClientRequestException() throws Exception
{
final Path targetTestsDir = prepareTargetTestsDir();
Path targetTestsDir = workDir.getEmptyPathDir();
startServer(new HttpServlet()
{
@ -1076,7 +1078,7 @@ public class AsyncMiddleManServletTest
IO.copy(request.getInputStream(), IO.getNullStream());
}
});
final CountDownLatch destroyLatch = new CountDownLatch(1);
CountDownLatch destroyLatch = new CountDownLatch(1);
startProxy(new AsyncMiddleManServlet()
{
@Override
@ -1111,7 +1113,7 @@ public class AsyncMiddleManServletTest
startClient();
// Send only part of the content; the proxy will idle timeout.
final byte[] data = new byte[]{'c', 'a', 'f', 'e'};
byte[] data = new byte[]{'c', 'a', 'f', 'e'};
ContentResponse response = client.newRequest("localhost", serverConnector.getLocalPort())
.body(new BytesRequestContent(data)
{
@ -1131,9 +1133,9 @@ public class AsyncMiddleManServletTest
@Test
public void testAfterContentTransformerClosingFilesOnServerResponseException() throws Exception
{
final Path targetTestsDir = prepareTargetTestsDir();
Path targetTestsDir = workDir.getEmptyPathDir();
final CountDownLatch serviceLatch = new CountDownLatch(1);
CountDownLatch serviceLatch = new CountDownLatch(1);
startServer(new HttpServlet()
{
@Override
@ -1148,7 +1150,7 @@ public class AsyncMiddleManServletTest
serviceLatch.countDown();
}
});
final CountDownLatch destroyLatch = new CountDownLatch(1);
CountDownLatch destroyLatch = new CountDownLatch(1);
startProxy(new AsyncMiddleManServlet()
{
@Override
@ -1201,7 +1203,7 @@ public class AsyncMiddleManServletTest
testAfterContentTransformerDoNoTransform(true, true);
}
private void testAfterContentTransformerDoNoTransform(final boolean readSource, final boolean useDisk) throws Exception
private void testAfterContentTransformerDoNoTransform(boolean readSource, boolean useDisk) throws Exception
{
String key0 = "id";
long value0 = 1;
@ -1270,7 +1272,7 @@ public class AsyncMiddleManServletTest
response.setHeader(HttpHeader.WWW_AUTHENTICATE.asString(), "Basic realm=\"test\"");
}
});
final AtomicBoolean transformed = new AtomicBoolean();
AtomicBoolean transformed = new AtomicBoolean();
startProxy(new AsyncMiddleManServlet()
{
@Override
@ -1301,7 +1303,7 @@ public class AsyncMiddleManServletTest
public void testProxyRequestHeadersSentWhenDiscardingContent() throws Exception
{
startServer(new EchoHttpServlet());
final CountDownLatch proxyRequestLatch = new CountDownLatch(1);
CountDownLatch proxyRequestLatch = new CountDownLatch(1);
startProxy(new AsyncMiddleManServlet()
{
@Override
@ -1349,7 +1351,7 @@ public class AsyncMiddleManServletTest
public void testProxyRequestHeadersNotSentUntilContent() throws Exception
{
startServer(new EchoHttpServlet());
final CountDownLatch proxyRequestLatch = new CountDownLatch(1);
CountDownLatch proxyRequestLatch = new CountDownLatch(1);
startProxy(new AsyncMiddleManServlet()
{
@Override
@ -1397,7 +1399,7 @@ public class AsyncMiddleManServletTest
public void testProxyRequestHeadersNotSentUntilFirstContent() throws Exception
{
startServer(new EchoHttpServlet());
final CountDownLatch proxyRequestLatch = new CountDownLatch(1);
CountDownLatch proxyRequestLatch = new CountDownLatch(1);
startProxy(new AsyncMiddleManServlet()
{
@Override
@ -1466,7 +1468,7 @@ public class AsyncMiddleManServletTest
@Test
public void testTransparentProxyWithIdentityContentTransformer() throws Exception
{
final String target = "/test";
String target = "/test";
startServer(new HttpServlet()
{
@Override
@ -1477,7 +1479,7 @@ public class AsyncMiddleManServletTest
resp.setStatus(target.equals(req.getRequestURI()) ? 200 : 404);
}
});
final String proxyTo = "http://localhost:" + serverConnector.getLocalPort();
String proxyTo = "http://localhost:" + serverConnector.getLocalPort();
AsyncMiddleManServlet proxyServlet = new AsyncMiddleManServlet.Transparent()
{
@Override
@ -1500,21 +1502,6 @@ public class AsyncMiddleManServletTest
assertTrue(response.getHeaders().contains(PROXIED_HEADER));
}
private Path prepareTargetTestsDir() throws IOException
{
final Path targetTestsDir = MavenTestingUtils.getTargetTestingDir().toPath();
Files.createDirectories(targetTestsDir);
try (DirectoryStream<Path> files = Files.newDirectoryStream(targetTestsDir, "*.*"))
{
for (Path file : files)
{
if (!Files.isDirectory(file))
Files.delete(file);
}
}
return targetTestsDir;
}
private void sleep(long delay)
{
try