More tests for FastCGIProxyServlet.

This commit is contained in:
Simone Bordet 2014-05-20 19:44:32 +02:00
parent 724fb7d6d3
commit 4e3118f5b1
1 changed files with 48 additions and 4 deletions

View File

@ -20,7 +20,9 @@ package org.eclipse.jetty.fcgi.server.proxy;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.nio.ByteBuffer;
import java.util.Random; import java.util.Random;
import java.util.concurrent.TimeUnit;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -28,12 +30,16 @@ import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse; import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.client.api.Response;
import org.eclipse.jetty.client.util.FutureResponseListener;
import org.eclipse.jetty.fcgi.server.ServerFCGIConnectionFactory; import org.eclipse.jetty.fcgi.server.ServerFCGIConnectionFactory;
import org.eclipse.jetty.server.HttpConfiguration; import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.util.Callback;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@ -89,7 +95,24 @@ public class FastCGIProxyServletTest
@Test @Test
public void testGETWithSmallResponseContent() throws Exception public void testGETWithSmallResponseContent() throws Exception
{ {
final byte[] data = new byte[1024]; testGETWithResponseContent(1024, 0);
}
@Test
public void testGETWithLargeResponseContent() throws Exception
{
testGETWithResponseContent(16 * 1024 * 1024, 0);
}
@Test
public void testGETWithLargeResponseContentWithSlowClient() throws Exception
{
testGETWithResponseContent(16 * 1024 * 1024, 1);
}
private void testGETWithResponseContent(int length, final long delay) throws Exception
{
final byte[] data = new byte[length];
new Random().nextBytes(data); new Random().nextBytes(data);
final String path = "/foo/index.php"; final String path = "/foo/index.php";
@ -103,9 +126,30 @@ public class FastCGIProxyServletTest
} }
}); });
ContentResponse response = client.newRequest("localhost", httpConnector.getLocalPort()) Request request = client.newRequest("localhost", httpConnector.getLocalPort())
.path(path) .onResponseContentAsync(new Response.AsyncContentListener()
.send(); {
@Override
public void onContent(Response response, ByteBuffer content, Callback callback)
{
try
{
if (delay > 0)
TimeUnit.MILLISECONDS.sleep(delay);
callback.succeeded();
}
catch (InterruptedException x)
{
callback.failed(x);
}
}
})
.path(path);
FutureResponseListener listener = new FutureResponseListener(request, length);
request.send(listener);
ContentResponse response = listener.get(30, TimeUnit.SECONDS);
Assert.assertEquals(200, response.getStatus()); Assert.assertEquals(200, response.getStatus());
Assert.assertArrayEquals(data, response.getContent()); Assert.assertArrayEquals(data, response.getContent());
} }