Made the test portable between Jetty7 and Jetty8.

This commit is contained in:
Simone Bordet 2012-03-12 15:30:26 +01:00
parent 6d34d6fdc6
commit 41874b5fbe
1 changed files with 18 additions and 8 deletions

View File

@ -31,8 +31,9 @@ import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.continuation.Continuation;
import org.eclipse.jetty.continuation.ContinuationSupport;
import org.eclipse.jetty.io.ByteArrayBuffer; import org.eclipse.jetty.io.ByteArrayBuffer;
import org.eclipse.jetty.server.AsyncContext;
import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.spdy.api.BytesDataInfo; import org.eclipse.jetty.spdy.api.BytesDataInfo;
@ -975,7 +976,10 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
throws IOException, ServletException throws IOException, ServletException
{ {
request.setHandled(true); request.setHandled(true);
final AsyncContext async = request.startAsync();
final Continuation continuation = ContinuationSupport.getContinuation(request);
continuation.suspend();
new Thread() new Thread()
{ {
@Override @Override
@ -988,7 +992,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
int read = 0; int read = 0;
while (read < data.length) while (read < data.length)
read += input.read(buffer); read += input.read(buffer);
async.complete(); continuation.complete();
latch.countDown(); latch.countDown();
} }
catch (IOException x) catch (IOException x)
@ -1034,7 +1038,10 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
throws IOException, ServletException throws IOException, ServletException
{ {
request.setHandled(true); request.setHandled(true);
final AsyncContext async = request.startAsync();
final Continuation continuation = ContinuationSupport.getContinuation(request);
continuation.suspend();
new Thread() new Thread()
{ {
@Override @Override
@ -1047,7 +1054,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
int read = 0; int read = 0;
while (read < 2 * data.length) while (read < 2 * data.length)
read += input.read(buffer); read += input.read(buffer);
async.complete(); continuation.complete();
latch.countDown(); latch.countDown();
} }
catch (IOException x) catch (IOException x)
@ -1094,14 +1101,17 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
throws IOException, ServletException throws IOException, ServletException
{ {
request.setHandled(true); request.setHandled(true);
if (request.getAsyncContinuation().isInitial())
final Continuation continuation = ContinuationSupport.getContinuation(request);
if (continuation.isInitial())
{ {
InputStream input = request.getInputStream(); InputStream input = request.getInputStream();
byte[] buffer = new byte[256]; byte[] buffer = new byte[256];
int read = 0; int read = 0;
while (read < data.length) while (read < data.length)
read += input.read(buffer); read += input.read(buffer);
final AsyncContext async = request.startAsync(); continuation.suspend();
new Thread() new Thread()
{ {
@Override @Override
@ -1110,7 +1120,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
try try
{ {
TimeUnit.SECONDS.sleep(1); TimeUnit.SECONDS.sleep(1);
async.dispatch(); continuation.resume();
latch.countDown(); latch.countDown();
} }
catch (InterruptedException x) catch (InterruptedException x)