cleaning up test

This commit is contained in:
Joakim Erdfelt 2014-03-10 12:31:44 -07:00
parent 84fa579ec7
commit 0c8bdb650c
2 changed files with 27 additions and 18 deletions

View File

@ -49,17 +49,20 @@ import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpConnectionFactory; import org.eclipse.jetty.server.HttpConnectionFactory;
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.hamcrest.Matchers; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
// TODO need these on SPDY as well! // TODO need these on SPDY as well!
public class AsyncServletIOTest public class AsyncServletIOTest
{ {
private static final Logger LOG = Log.getLogger(AsyncServletIOTest.class);
protected AsyncIOServlet _servlet0=new AsyncIOServlet(); protected AsyncIOServlet _servlet0=new AsyncIOServlet();
protected AsyncIOServlet2 _servlet2=new AsyncIOServlet2(); protected AsyncIOServlet2 _servlet2=new AsyncIOServlet2();
protected int _port; protected int _port;
@ -137,7 +140,7 @@ public class AsyncServletIOTest
public void testBigWrites() throws Exception public void testBigWrites() throws Exception
{ {
process(102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400); process(102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400,102400);
Assert.assertThat(_owp.get(),Matchers.greaterThan(1)); Assert.assertThat("On Write Possible",_owp.get(),greaterThan(1));
} }
@Test @Test
@ -179,14 +182,14 @@ public class AsyncServletIOTest
// response line // response line
String line = in.readLine(); String line = in.readLine();
// System.err.println("resp: "+line); LOG.debug("response-line: "+line);
Assert.assertThat(line,Matchers.startsWith("HTTP/1.1 200 OK")); Assert.assertThat(line,startsWith("HTTP/1.1 200 OK"));
// Skip headers // Skip headers
while (line!=null) while (line!=null)
{ {
line = in.readLine(); line = in.readLine();
// System.err.println("line: "+line); LOG.debug("header-line: "+line);
if (line.length()==0) if (line.length()==0)
break; break;
} }
@ -195,7 +198,7 @@ public class AsyncServletIOTest
while (true) while (true)
{ {
line = in.readLine(); line = in.readLine();
// System.err.println("body: "+line); LOG.debug("body: "+line);
if (line==null) if (line==null)
break; break;
list.add(line); list.add(line);
@ -256,19 +259,18 @@ public class AsyncServletIOTest
out.write(content,1+half,content.length-half-1); out.write(content,1+half,content.length-half-1);
} }
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()),102400); BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()),102400);
// response line // response line
String line = in.readLine(); String line = in.readLine();
//System.err.println("line: "+line); LOG.debug("response-line: "+line);
Assert.assertThat(line,Matchers.startsWith("HTTP/1.1 200 OK")); Assert.assertThat(line,startsWith("HTTP/1.1 200 OK"));
// Skip headers // Skip headers
while (line!=null) while (line!=null)
{ {
line = in.readLine(); line = in.readLine();
//System.err.println("line: "+line); LOG.debug("header-line: "+line);
if (line.length()==0) if (line.length()==0)
break; break;
} }
@ -279,9 +281,9 @@ public class AsyncServletIOTest
line = in.readLine(); line = in.readLine();
if (line==null) if (line==null)
break; break;
//System.err.println("line: "+line.length()+"\t"+(line.length()>40?(line.substring(0,40)+"..."):line)); LOG.debug("body: "+brief(line));
list.add(line); list.add(line);
Thread.sleep(50); Thread.sleep(150);
} }
} }
@ -289,11 +291,11 @@ public class AsyncServletIOTest
int w=0; int w=0;
for (String line : list) for (String line : list)
{ {
// System.err.println(line); LOG.debug("line: "+brief(line));
if ("-".equals(line)) if ("-".equals(line))
continue; continue;
assertEquals(writes[w],line.length()); assertEquals("Line Length",writes[w],line.length());
assertEquals(line.charAt(0),'0'+(w%10)); assertEquals("Line Contents",line.charAt(0),'0'+(w%10));
w++; w++;
if (w<writes.length && writes[w]<=0) if (w<writes.length && writes[w]<=0)
@ -301,10 +303,15 @@ public class AsyncServletIOTest
} }
if (content!=null) if (content!=null)
Assert.assertEquals(content.length,_read.get()); Assert.assertEquals("Content Length",content.length,_read.get());
return list; return list;
} }
private static String brief(String line)
{
return line.length()+"\t"+(line.length()>40?(line.substring(0,40)+"..."):line);
}
static AtomicInteger _owp = new AtomicInteger(); static AtomicInteger _owp = new AtomicInteger();
static AtomicInteger _oda = new AtomicInteger(); static AtomicInteger _oda = new AtomicInteger();
@ -366,7 +373,7 @@ public class AsyncServletIOTest
{ {
if (onDataAvailable.get()) if (onDataAvailable.get())
{ {
System.err.println("OADR too early!"); LOG.warn("OADR too early!");
_read.set(-1); _read.set(-1);
} }
@ -390,7 +397,7 @@ public class AsyncServletIOTest
@Override @Override
public void onWritePossible() throws IOException public void onWritePossible() throws IOException
{ {
//System.err.println("OWP"); LOG.debug("OWP");
_owp.incrementAndGet(); _owp.incrementAndGet();
while (writes!=null && _w< writes.length) while (writes!=null && _w< writes.length)
@ -424,6 +431,7 @@ public class AsyncServletIOTest
} }
} }
@SuppressWarnings("serial")
public class AsyncIOServlet2 extends HttpServlet public class AsyncIOServlet2 extends HttpServlet
{ {
public CountDownLatch completed = new CountDownLatch(1); public CountDownLatch completed = new CountDownLatch(1);

View File

@ -2,3 +2,4 @@ org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
#org.eclipse.jetty.LEVEL=DEBUG #org.eclipse.jetty.LEVEL=DEBUG
#org.eclipse.jetty.server.LEVEL=DEBUG #org.eclipse.jetty.server.LEVEL=DEBUG
#org.eclipse.jetty.servlet.LEVEL=DEBUG #org.eclipse.jetty.servlet.LEVEL=DEBUG
#org.eclipse.jetty.io.ChannelEndPoint.LEVEL=DEBUG