Fixed tests and suppressed expected exceptions.
This commit is contained in:
parent
d0930e1b9a
commit
77b1617fdd
|
@ -26,6 +26,7 @@ import java.util.concurrent.TimeUnit;
|
|||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import javax.servlet.DispatcherType;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
@ -36,6 +37,7 @@ import org.eclipse.jetty.client.http.HttpDestinationOverHTTP;
|
|||
import org.eclipse.jetty.client.util.ByteBufferContentProvider;
|
||||
import org.eclipse.jetty.server.handler.AbstractHandler;
|
||||
import org.eclipse.jetty.util.IO;
|
||||
import org.eclipse.jetty.util.log.StacklessLogging;
|
||||
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
@ -256,6 +258,8 @@ public class HttpRequestAbortTest extends AbstractHttpClientServerTest
|
|||
|
||||
@Test
|
||||
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()
|
||||
|
@ -266,6 +270,7 @@ public class HttpRequestAbortTest extends AbstractHttpClientServerTest
|
|||
try
|
||||
{
|
||||
baseRequest.setHandled(true);
|
||||
if (request.getDispatcherType() != DispatcherType.ERROR)
|
||||
IO.copy(request.getInputStream(), response.getOutputStream());
|
||||
}
|
||||
catch (IOException x)
|
||||
|
@ -313,18 +318,30 @@ public class HttpRequestAbortTest extends AbstractHttpClientServerTest
|
|||
Assert.assertEquals(0, connectionPool.getActiveConnections().size());
|
||||
Assert.assertEquals(0, connectionPool.getIdleConnections().size());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAbortOnContent() throws Exception
|
||||
{
|
||||
try (StacklessLogging suppressor = new StacklessLogging(org.eclipse.jetty.server.HttpChannel.class))
|
||||
{
|
||||
CountDownLatch serverLatch = new CountDownLatch(1);
|
||||
start(new EmptyServerHandler()
|
||||
{
|
||||
@Override
|
||||
public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
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();
|
||||
|
@ -358,12 +375,15 @@ public class HttpRequestAbortTest extends AbstractHttpClientServerTest
|
|||
Assert.assertSame(cause, x.getCause());
|
||||
}
|
||||
|
||||
Assert.assertTrue(serverLatch.await(5, TimeUnit.SECONDS));
|
||||
|
||||
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)
|
||||
public void testInterrupt() throws Exception
|
||||
|
@ -377,6 +397,7 @@ public class HttpRequestAbortTest extends AbstractHttpClientServerTest
|
|||
try
|
||||
{
|
||||
baseRequest.setHandled(true);
|
||||
if (request.getDispatcherType() != DispatcherType.ERROR)
|
||||
TimeUnit.MILLISECONDS.sleep(2 * delay);
|
||||
}
|
||||
catch (InterruptedException x)
|
||||
|
@ -391,10 +412,7 @@ public class HttpRequestAbortTest extends AbstractHttpClientServerTest
|
|||
.scheme(scheme);
|
||||
|
||||
final Thread thread = Thread.currentThread();
|
||||
new Thread()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
new Thread(() ->
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -405,8 +423,7 @@ public class HttpRequestAbortTest extends AbstractHttpClientServerTest
|
|||
{
|
||||
throw new RuntimeException(x);
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}).start();
|
||||
|
||||
request.send();
|
||||
}
|
||||
|
@ -423,6 +440,7 @@ public class HttpRequestAbortTest extends AbstractHttpClientServerTest
|
|||
try
|
||||
{
|
||||
baseRequest.setHandled(true);
|
||||
if (request.getDispatcherType() != DispatcherType.ERROR)
|
||||
TimeUnit.MILLISECONDS.sleep(2 * delay);
|
||||
}
|
||||
catch (InterruptedException x)
|
||||
|
@ -439,10 +457,7 @@ public class HttpRequestAbortTest extends AbstractHttpClientServerTest
|
|||
final Throwable cause = new Exception();
|
||||
final AtomicBoolean aborted = new AtomicBoolean();
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
new Thread()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
new Thread(() ->
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -454,8 +469,7 @@ public class HttpRequestAbortTest extends AbstractHttpClientServerTest
|
|||
{
|
||||
throw new RuntimeException(x);
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}).start();
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -487,6 +501,7 @@ public class HttpRequestAbortTest extends AbstractHttpClientServerTest
|
|||
try
|
||||
{
|
||||
baseRequest.setHandled(true);
|
||||
if (request.getDispatcherType() != DispatcherType.ERROR)
|
||||
TimeUnit.MILLISECONDS.sleep(2 * delay);
|
||||
}
|
||||
catch (InterruptedException x)
|
||||
|
|
Loading…
Reference in New Issue