mirror of
https://github.com/jetty/jetty.project.git
synced 2025-03-01 19:39:21 +00:00
Revert "Fixed tests and suppressed expected exceptions."
This reverts commit 77b1617fdd925f67642e918bdd12bd4e61245942.
This commit is contained in:
parent
611e79945c
commit
0f3f051f0e
@ -26,7 +26,6 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import javax.servlet.DispatcherType;
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
@ -37,7 +36,6 @@ import org.eclipse.jetty.client.http.HttpDestinationOverHTTP;
|
|||||||
import org.eclipse.jetty.client.util.ByteBufferContentProvider;
|
import org.eclipse.jetty.client.util.ByteBufferContentProvider;
|
||||||
import org.eclipse.jetty.server.handler.AbstractHandler;
|
import org.eclipse.jetty.server.handler.AbstractHandler;
|
||||||
import org.eclipse.jetty.util.IO;
|
import org.eclipse.jetty.util.IO;
|
||||||
import org.eclipse.jetty.util.log.StacklessLogging;
|
|
||||||
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -259,130 +257,112 @@ public class HttpRequestAbortTest extends AbstractHttpClientServerTest
|
|||||||
@Test
|
@Test
|
||||||
public void testAbortOnCommitWithContent() throws Exception
|
public void testAbortOnCommitWithContent() throws Exception
|
||||||
{
|
{
|
||||||
try (StacklessLogging suppressor = new StacklessLogging(org.eclipse.jetty.server.HttpChannel.class))
|
final AtomicReference<IOException> failure = new AtomicReference<>();
|
||||||
|
start(new AbstractHandler()
|
||||||
{
|
{
|
||||||
final AtomicReference<IOException> failure = new AtomicReference<>();
|
@Override
|
||||||
start(new AbstractHandler()
|
public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||||
{
|
{
|
||||||
@Override
|
try
|
||||||
public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
|
||||||
{
|
{
|
||||||
try
|
baseRequest.setHandled(true);
|
||||||
{
|
IO.copy(request.getInputStream(), response.getOutputStream());
|
||||||
baseRequest.setHandled(true);
|
}
|
||||||
if (request.getDispatcherType() != DispatcherType.ERROR)
|
catch (IOException x)
|
||||||
IO.copy(request.getInputStream(), response.getOutputStream());
|
{
|
||||||
}
|
failure.set(x);
|
||||||
catch (IOException x)
|
throw x;
|
||||||
{
|
|
||||||
failure.set(x);
|
|
||||||
throw x;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
final Throwable cause = new Exception();
|
|
||||||
final AtomicBoolean aborted = new AtomicBoolean();
|
|
||||||
final CountDownLatch latch = new CountDownLatch(1);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
client.newRequest("localhost", connector.getLocalPort())
|
|
||||||
.scheme(scheme)
|
|
||||||
.onRequestCommit(request ->
|
|
||||||
{
|
|
||||||
aborted.set(request.abort(cause));
|
|
||||||
latch.countDown();
|
|
||||||
})
|
|
||||||
.content(new ByteBufferContentProvider(ByteBuffer.wrap(new byte[]{0}), ByteBuffer.wrap(new byte[]{1}))
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public long getLength()
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.timeout(5, TimeUnit.SECONDS)
|
|
||||||
.send();
|
|
||||||
Assert.fail();
|
|
||||||
}
|
|
||||||
catch (ExecutionException x)
|
|
||||||
{
|
|
||||||
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
|
|
||||||
if (aborted.get())
|
|
||||||
Assert.assertSame(cause, x.getCause());
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
HttpDestinationOverHTTP destination = (HttpDestinationOverHTTP)client.getDestination(scheme, "localhost", connector.getLocalPort());
|
final Throwable cause = new Exception();
|
||||||
DuplexConnectionPool connectionPool = (DuplexConnectionPool)destination.getConnectionPool();
|
final AtomicBoolean aborted = new AtomicBoolean();
|
||||||
Assert.assertEquals(0, connectionPool.getConnectionCount());
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
Assert.assertEquals(0, connectionPool.getActiveConnections().size());
|
try
|
||||||
Assert.assertEquals(0, connectionPool.getIdleConnections().size());
|
{
|
||||||
|
client.newRequest("localhost", connector.getLocalPort())
|
||||||
|
.scheme(scheme)
|
||||||
|
.onRequestCommit(request ->
|
||||||
|
{
|
||||||
|
aborted.set(request.abort(cause));
|
||||||
|
latch.countDown();
|
||||||
|
})
|
||||||
|
.content(new ByteBufferContentProvider(ByteBuffer.wrap(new byte[]{0}), ByteBuffer.wrap(new byte[]{1}))
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public long getLength()
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.timeout(5, TimeUnit.SECONDS)
|
||||||
|
.send();
|
||||||
|
Assert.fail();
|
||||||
}
|
}
|
||||||
|
catch (ExecutionException x)
|
||||||
|
{
|
||||||
|
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
|
||||||
|
if (aborted.get())
|
||||||
|
Assert.assertSame(cause, x.getCause());
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpDestinationOverHTTP destination = (HttpDestinationOverHTTP)client.getDestination(scheme, "localhost", connector.getLocalPort());
|
||||||
|
DuplexConnectionPool connectionPool = (DuplexConnectionPool)destination.getConnectionPool();
|
||||||
|
Assert.assertEquals(0, connectionPool.getConnectionCount());
|
||||||
|
Assert.assertEquals(0, connectionPool.getActiveConnections().size());
|
||||||
|
Assert.assertEquals(0, connectionPool.getIdleConnections().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAbortOnContent() throws Exception
|
public void testAbortOnContent() throws Exception
|
||||||
{
|
{
|
||||||
try (StacklessLogging suppressor = new StacklessLogging(org.eclipse.jetty.server.HttpChannel.class))
|
start(new EmptyServerHandler()
|
||||||
{
|
{
|
||||||
CountDownLatch serverLatch = new CountDownLatch(1);
|
@Override
|
||||||
start(new EmptyServerHandler()
|
public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||||
{
|
{
|
||||||
@Override
|
super.handle(target, baseRequest, request, response);
|
||||||
public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
IO.copy(request.getInputStream(), response.getOutputStream());
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
super.handle(target, baseRequest, request, response);
|
|
||||||
if (request.getDispatcherType() != DispatcherType.ERROR)
|
|
||||||
IO.copy(request.getInputStream(), response.getOutputStream());
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
serverLatch.countDown();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
final Throwable cause = new Exception();
|
|
||||||
final AtomicBoolean aborted = new AtomicBoolean();
|
|
||||||
final CountDownLatch latch = new CountDownLatch(1);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
client.newRequest("localhost", connector.getLocalPort())
|
|
||||||
.scheme(scheme)
|
|
||||||
.onRequestContent((request, content) ->
|
|
||||||
{
|
|
||||||
aborted.set(request.abort(cause));
|
|
||||||
latch.countDown();
|
|
||||||
})
|
|
||||||
.content(new ByteBufferContentProvider(ByteBuffer.wrap(new byte[]{0}), ByteBuffer.wrap(new byte[]{1}))
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public long getLength()
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.timeout(5, TimeUnit.SECONDS)
|
|
||||||
.send();
|
|
||||||
Assert.fail();
|
|
||||||
}
|
|
||||||
catch (ExecutionException x)
|
|
||||||
{
|
|
||||||
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
|
|
||||||
if (aborted.get())
|
|
||||||
Assert.assertSame(cause, x.getCause());
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
Assert.assertTrue(serverLatch.await(5, TimeUnit.SECONDS));
|
final Throwable cause = new Exception();
|
||||||
|
final AtomicBoolean aborted = new AtomicBoolean();
|
||||||
HttpDestinationOverHTTP destination = (HttpDestinationOverHTTP)client.getDestination(scheme, "localhost", connector.getLocalPort());
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
DuplexConnectionPool connectionPool = (DuplexConnectionPool)destination.getConnectionPool();
|
try
|
||||||
Assert.assertEquals(0, connectionPool.getConnectionCount());
|
{
|
||||||
Assert.assertEquals(0, connectionPool.getActiveConnections().size());
|
client.newRequest("localhost", connector.getLocalPort())
|
||||||
Assert.assertEquals(0, connectionPool.getIdleConnections().size());
|
.scheme(scheme)
|
||||||
|
.onRequestContent((request, content) ->
|
||||||
|
{
|
||||||
|
aborted.set(request.abort(cause));
|
||||||
|
latch.countDown();
|
||||||
|
})
|
||||||
|
.content(new ByteBufferContentProvider(ByteBuffer.wrap(new byte[]{0}), ByteBuffer.wrap(new byte[]{1}))
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public long getLength()
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.timeout(5, TimeUnit.SECONDS)
|
||||||
|
.send();
|
||||||
|
Assert.fail();
|
||||||
}
|
}
|
||||||
|
catch (ExecutionException x)
|
||||||
|
{
|
||||||
|
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
|
||||||
|
if (aborted.get())
|
||||||
|
Assert.assertSame(cause, x.getCause());
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpDestinationOverHTTP destination = (HttpDestinationOverHTTP)client.getDestination(scheme, "localhost", connector.getLocalPort());
|
||||||
|
DuplexConnectionPool connectionPool = (DuplexConnectionPool)destination.getConnectionPool();
|
||||||
|
Assert.assertEquals(0, connectionPool.getConnectionCount());
|
||||||
|
Assert.assertEquals(0, connectionPool.getActiveConnections().size());
|
||||||
|
Assert.assertEquals(0, connectionPool.getIdleConnections().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = InterruptedException.class)
|
@Test(expected = InterruptedException.class)
|
||||||
@ -397,8 +377,7 @@ public class HttpRequestAbortTest extends AbstractHttpClientServerTest
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
baseRequest.setHandled(true);
|
baseRequest.setHandled(true);
|
||||||
if (request.getDispatcherType() != DispatcherType.ERROR)
|
TimeUnit.MILLISECONDS.sleep(2 * delay);
|
||||||
TimeUnit.MILLISECONDS.sleep(2 * delay);
|
|
||||||
}
|
}
|
||||||
catch (InterruptedException x)
|
catch (InterruptedException x)
|
||||||
{
|
{
|
||||||
@ -412,18 +391,22 @@ public class HttpRequestAbortTest extends AbstractHttpClientServerTest
|
|||||||
.scheme(scheme);
|
.scheme(scheme);
|
||||||
|
|
||||||
final Thread thread = Thread.currentThread();
|
final Thread thread = Thread.currentThread();
|
||||||
new Thread(() ->
|
new Thread()
|
||||||
{
|
{
|
||||||
try
|
@Override
|
||||||
|
public void run()
|
||||||
{
|
{
|
||||||
TimeUnit.MILLISECONDS.sleep(delay);
|
try
|
||||||
thread.interrupt();
|
{
|
||||||
|
TimeUnit.MILLISECONDS.sleep(delay);
|
||||||
|
thread.interrupt();
|
||||||
|
}
|
||||||
|
catch (InterruptedException x)
|
||||||
|
{
|
||||||
|
throw new RuntimeException(x);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (InterruptedException x)
|
}.start();
|
||||||
{
|
|
||||||
throw new RuntimeException(x);
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
|
|
||||||
request.send();
|
request.send();
|
||||||
}
|
}
|
||||||
@ -440,8 +423,7 @@ public class HttpRequestAbortTest extends AbstractHttpClientServerTest
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
baseRequest.setHandled(true);
|
baseRequest.setHandled(true);
|
||||||
if (request.getDispatcherType() != DispatcherType.ERROR)
|
TimeUnit.MILLISECONDS.sleep(2 * delay);
|
||||||
TimeUnit.MILLISECONDS.sleep(2 * delay);
|
|
||||||
}
|
}
|
||||||
catch (InterruptedException x)
|
catch (InterruptedException x)
|
||||||
{
|
{
|
||||||
@ -457,19 +439,23 @@ public class HttpRequestAbortTest extends AbstractHttpClientServerTest
|
|||||||
final Throwable cause = new Exception();
|
final Throwable cause = new Exception();
|
||||||
final AtomicBoolean aborted = new AtomicBoolean();
|
final AtomicBoolean aborted = new AtomicBoolean();
|
||||||
final CountDownLatch latch = new CountDownLatch(1);
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
new Thread(() ->
|
new Thread()
|
||||||
{
|
{
|
||||||
try
|
@Override
|
||||||
|
public void run()
|
||||||
{
|
{
|
||||||
TimeUnit.MILLISECONDS.sleep(delay);
|
try
|
||||||
aborted.set(request.abort(cause));
|
{
|
||||||
latch.countDown();
|
TimeUnit.MILLISECONDS.sleep(delay);
|
||||||
|
aborted.set(request.abort(cause));
|
||||||
|
latch.countDown();
|
||||||
|
}
|
||||||
|
catch (InterruptedException x)
|
||||||
|
{
|
||||||
|
throw new RuntimeException(x);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (InterruptedException x)
|
}.start();
|
||||||
{
|
|
||||||
throw new RuntimeException(x);
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -501,8 +487,7 @@ public class HttpRequestAbortTest extends AbstractHttpClientServerTest
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
baseRequest.setHandled(true);
|
baseRequest.setHandled(true);
|
||||||
if (request.getDispatcherType() != DispatcherType.ERROR)
|
TimeUnit.MILLISECONDS.sleep(2 * delay);
|
||||||
TimeUnit.MILLISECONDS.sleep(2 * delay);
|
|
||||||
}
|
}
|
||||||
catch (InterruptedException x)
|
catch (InterruptedException x)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user