Fixed test to be more reliable.

This commit is contained in:
Simone Bordet 2015-01-05 13:32:55 +01:00
parent 19570a7530
commit c3582ceae2
1 changed files with 22 additions and 4 deletions

View File

@ -130,7 +130,9 @@ public class ProxyServletTest
private void prepareProxy(Map<String, String> initParams) throws Exception private void prepareProxy(Map<String, String> initParams) throws Exception
{ {
proxy = new Server(); QueuedThreadPool proxyPool = new QueuedThreadPool();
proxyPool.setName("proxy");
proxy = new Server(proxyPool);
HttpConfiguration configuration = new HttpConfiguration(); HttpConfiguration configuration = new HttpConfiguration();
configuration.setSendDateHeader(false); configuration.setSendDateHeader(false);
@ -154,6 +156,9 @@ public class ProxyServletTest
private HttpClient prepareClient() throws Exception private HttpClient prepareClient() throws Exception
{ {
HttpClient result = new HttpClient(); HttpClient result = new HttpClient();
QueuedThreadPool clientPool = new QueuedThreadPool();
clientPool.setName("client");
result.setExecutor(clientPool);
result.getProxyConfiguration().getProxies().add(new HttpProxy("localhost", proxyConnector.getLocalPort())); result.getProxyConfiguration().getProxies().add(new HttpProxy("localhost", proxyConnector.getLocalPort()));
result.start(); result.start();
return result; return result;
@ -161,7 +166,9 @@ public class ProxyServletTest
private void prepareServer(HttpServlet servlet) throws Exception private void prepareServer(HttpServlet servlet) throws Exception
{ {
server = new Server(); QueuedThreadPool serverPool = new QueuedThreadPool();
serverPool.setName("server");
server = new Server(serverPool);
serverConnector = new ServerConnector(server); serverConnector = new ServerConnector(server);
server.addConnector(serverConnector); server.addConnector(serverConnector);
@ -312,9 +319,20 @@ public class ProxyServletTest
@Override @Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{ {
try
{
// Give some time to the proxy to
// upload the content to the server.
Thread.sleep(1000);
if (req.getHeader("Via") != null) if (req.getHeader("Via") != null)
resp.addHeader(PROXIED_HEADER, "true"); resp.addHeader(PROXIED_HEADER, "true");
} }
catch (InterruptedException x)
{
throw new InterruptedIOException();
}
}
}); });
byte[] content = new byte[128 * 1024]; byte[] content = new byte[128 * 1024];