jetty-9 some test clean ups

This commit is contained in:
Greg Wilkins 2012-06-06 13:27:56 +02:00
parent c1f3545d7c
commit 98a7f19ff9
3 changed files with 30 additions and 27 deletions

View File

@ -13,6 +13,7 @@
package org.eclipse.jetty.http; package org.eclipse.jetty.http;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
@ -113,9 +114,9 @@ public class HttpFieldsTest
header.putTo(buffer); header.putTo(buffer);
buffer.flip(); buffer.flip();
String out = BufferUtil.toString(buffer); String out = BufferUtil.toString(buffer);
assertTrue(out.contains("name0: value??0")); assertThat(out,containsString("name0: value??0"));
assertTrue(out.contains("name??1: value1")); assertThat(out,containsString("name??1: value1"));
assertTrue(out.contains("name?2: value???2")); assertThat(out,containsString("name?2: value:??2"));
} }
@Test @Test

View File

@ -388,7 +388,7 @@ public class HttpGeneratorServerTest
assertEquals(0,gen.getContentPrepared()); assertEquals(0,gen.getContentPrepared());
assertThat(head,containsString("HTTP/1.1 200 OK")); assertThat(head,containsString("HTTP/1.1 200 OK"));
assertThat(head,containsString("Last-Modified: Thu, 01 Jan 1970 00?00?00 GMT")); assertThat(head,containsString("Last-Modified: Thu, 01 Jan 1970 00:00:00 GMT"));
assertThat(head,containsString("Content-Length: 0")); assertThat(head,containsString("Content-Length: 0"));
} }
@ -492,7 +492,7 @@ public class HttpGeneratorServerTest
// System.err.println(head+body); // System.err.println(head+body);
assertThat(head,containsString("HTTP/1.1 200 OK")); assertThat(head,containsString("HTTP/1.1 200 OK"));
assertThat(head,containsString("Last-Modified: Thu, 01 Jan 1970 00?00?00 GMT")); assertThat(head,containsString("Last-Modified: Thu, 01 Jan 1970 00:00:00 GMT"));
assertThat(head,not(containsString("Content-Length"))); assertThat(head,not(containsString("Content-Length")));
assertThat(head,containsString("Transfer-Encoding: chunked")); assertThat(head,containsString("Transfer-Encoding: chunked"));
assertTrue(head.endsWith("\r\n\r\n10\r\n")); assertTrue(head.endsWith("\r\n\r\n10\r\n"));
@ -579,7 +579,7 @@ public class HttpGeneratorServerTest
// System.err.println(head+body); // System.err.println(head+body);
assertThat(head,containsString("HTTP/1.1 200 OK")); assertThat(head,containsString("HTTP/1.1 200 OK"));
assertThat(head,containsString("Last-Modified: Thu, 01 Jan 1970 00?00?00 GMT")); assertThat(head,containsString("Last-Modified: Thu, 01 Jan 1970 00:00:00 GMT"));
assertThat(head,containsString("Content-Length: 59")); assertThat(head,containsString("Content-Length: 59"));
assertThat(head,not(containsString("chunked"))); assertThat(head,not(containsString("chunked")));
assertTrue(head.endsWith("\r\n\r\n")); assertTrue(head.endsWith("\r\n\r\n"));
@ -633,7 +633,7 @@ public class HttpGeneratorServerTest
// System.err.println(head+body); // System.err.println(head+body);
assertThat(head,containsString("HTTP/1.1 200 OK")); assertThat(head,containsString("HTTP/1.1 200 OK"));
assertThat(head,containsString("Last-Modified: Thu, 01 Jan 1970 00?00?00 GMT")); assertThat(head,containsString("Last-Modified: Thu, 01 Jan 1970 00:00:00 GMT"));
assertThat(head,containsString("Content-Length: 59")); assertThat(head,containsString("Content-Length: 59"));
assertThat(head,not(containsString("chunked"))); assertThat(head,not(containsString("chunked")));
assertTrue(head.endsWith("\r\n\r\n")); assertTrue(head.endsWith("\r\n\r\n"));
@ -698,7 +698,7 @@ public class HttpGeneratorServerTest
// System.err.println(head+body); // System.err.println(head+body);
assertThat(head,containsString("HTTP/1.1 200 OK")); assertThat(head,containsString("HTTP/1.1 200 OK"));
assertThat(head,containsString("Last-Modified: Thu, 01 Jan 1970 00?00?00 GMT")); assertThat(head,containsString("Last-Modified: Thu, 01 Jan 1970 00:00:00 GMT"));
assertThat(head,not(containsString("Content-Length"))); assertThat(head,not(containsString("Content-Length")));
assertThat(head,containsString("Transfer-Encoding: chunked")); assertThat(head,containsString("Transfer-Encoding: chunked"));
assertTrue(head.endsWith("\r\n\r\n13\r\n")); assertTrue(head.endsWith("\r\n\r\n13\r\n"));
@ -752,7 +752,7 @@ public class HttpGeneratorServerTest
assertEquals(HttpGenerator.State.END,gen.getState()); assertEquals(HttpGenerator.State.END,gen.getState());
assertThat(head,containsString("HTTP/1.1 200 OK")); assertThat(head,containsString("HTTP/1.1 200 OK"));
assertThat(head,containsString("Last-Modified: Thu, 01 Jan 1970 00?00?00 GMT")); assertThat(head,containsString("Last-Modified: Thu, 01 Jan 1970 00:00:00 GMT"));
assertThat(head,containsString("Content-Length: 58")); assertThat(head,containsString("Content-Length: 58"));
assertTrue(head.endsWith("\r\n\r\n")); assertTrue(head.endsWith("\r\n\r\n"));
@ -823,7 +823,7 @@ public class HttpGeneratorServerTest
assertEquals(HttpGenerator.State.END,gen.getState()); assertEquals(HttpGenerator.State.END,gen.getState());
assertThat(head,containsString("HTTP/1.1 200 OK")); assertThat(head,containsString("HTTP/1.1 200 OK"));
assertThat(head,containsString("Last-Modified: Thu, 01 Jan 1970 00?00?00 GMT")); assertThat(head,containsString("Last-Modified: Thu, 01 Jan 1970 00:00:00 GMT"));
assertThat(head,containsString("Content-Length: 58")); assertThat(head,containsString("Content-Length: 58"));
assertTrue(head.endsWith("\r\n\r\n")); assertTrue(head.endsWith("\r\n\r\n"));

View File

@ -20,6 +20,7 @@ import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
@ -54,7 +55,7 @@ public class SslConnectionTest
@Override @Override
protected void endPointOpened(AsyncEndPoint endpoint) protected void endPointOpened(AsyncEndPoint endpoint)
{ {
System.err.println("endPointOpened"); // System.err.println("endPointOpened");
endpoint.getAsyncConnection().onOpen(); endpoint.getAsyncConnection().onOpen();
} }
@ -73,7 +74,7 @@ public class SslConnectionTest
AsyncConnection appConnection = new TestConnection(sslConnection.getSslEndPoint()); AsyncConnection appConnection = new TestConnection(sslConnection.getSslEndPoint());
sslConnection.getSslEndPoint().setAsyncConnection(appConnection); sslConnection.getSslEndPoint().setAsyncConnection(appConnection);
System.err.println("New Connection "+sslConnection); // System.err.println("New Connection "+sslConnection);
return sslConnection; return sslConnection;
} }
@ -84,7 +85,7 @@ public class SslConnectionTest
SelectChannelEndPoint endp = new SelectChannelEndPoint(channel,selectSet,key,getMaxIdleTime()); SelectChannelEndPoint endp = new SelectChannelEndPoint(channel,selectSet,key,getMaxIdleTime());
endp.setAsyncConnection(selectSet.getManager().newConnection(channel,endp, key.attachment())); endp.setAsyncConnection(selectSet.getManager().newConnection(channel,endp, key.attachment()));
_lastEndp=endp; _lastEndp=endp;
System.err.println("newEndPoint "+endp); // System.err.println("newEndPoint "+endp);
return endp; return endp;
} }
}; };
@ -137,21 +138,21 @@ public class SslConnectionTest
@Override @Override
public void onOpen() public void onOpen()
{ {
System.err.println("onOpen"); // System.err.println("onOpen");
scheduleOnReadable(); scheduleOnReadable();
} }
@Override @Override
public void onClose() public void onClose()
{ {
System.err.println("onClose"); // System.err.println("onClose");
} }
@Override @Override
public synchronized void onReadable() public synchronized void onReadable()
{ {
AsyncEndPoint endp = getEndPoint(); AsyncEndPoint endp = getEndPoint();
System.err.println("onReadable "+endp); // System.err.println("onReadable "+endp);
try try
{ {
boolean progress=true; boolean progress=true;
@ -161,12 +162,12 @@ public class SslConnectionTest
// Fill the input buffer with everything available // Fill the input buffer with everything available
int filled=endp.fill(_in); int filled=endp.fill(_in);
System.err.println("filled="+filled); // System.err.println("filled="+filled);
while (filled>0) while (filled>0)
{ {
progress=true; progress=true;
filled=endp.fill(_in); filled=endp.fill(_in);
System.err.println("filled="+filled); // System.err.println("filled="+filled);
} }
// System.err.println(BufferUtil.toDetailString(_in)); // System.err.println(BufferUtil.toDetailString(_in));
@ -178,13 +179,13 @@ public class SslConnectionTest
FutureCallback<Void> blockingWrite= new FutureCallback<>(); FutureCallback<Void> blockingWrite= new FutureCallback<>();
endp.write(null,blockingWrite,_in); endp.write(null,blockingWrite,_in);
blockingWrite.get(); blockingWrite.get();
System.err.println("wrote "+l); // System.err.println("wrote "+l);
} }
// are we done? // are we done?
if (endp.isInputShutdown()) if (endp.isInputShutdown())
{ {
System.err.println("shutdown"); // System.err.println("shutdown");
endp.shutdownOutput(); endp.shutdownOutput();
} }
} }
@ -218,7 +219,7 @@ public class SslConnectionTest
// Log.getRootLogger().setDebugEnabled(true); // Log.getRootLogger().setDebugEnabled(true);
Socket client = newClient(); Socket client = newClient();
System.err.println("client="+client); // System.err.println("client="+client);
client.setSoTimeout(600000); // TODO: restore to smaller value client.setSoTimeout(600000); // TODO: restore to smaller value
SocketChannel server = _connector.accept(); SocketChannel server = _connector.accept();
@ -226,10 +227,10 @@ public class SslConnectionTest
_manager.accept(server); _manager.accept(server);
client.getOutputStream().write("HelloWorld".getBytes("UTF-8")); client.getOutputStream().write("HelloWorld".getBytes("UTF-8"));
System.err.println("wrote"); // System.err.println("wrote");
byte[] buffer = new byte[1024]; byte[] buffer = new byte[1024];
int len = client.getInputStream().read(buffer); int len = client.getInputStream().read(buffer);
System.err.println(new String(buffer,0,len,"UTF-8")); // System.err.println(new String(buffer,0,len,"UTF-8"));
client.close(); client.close();
@ -237,13 +238,14 @@ public class SslConnectionTest
@Test @Test
@Ignore
public void testNasty() throws Exception public void testNasty() throws Exception
{ {
//Log.getRootLogger().setDebugEnabled(true); //Log.getRootLogger().setDebugEnabled(true);
// Log.getRootLogger().setDebugEnabled(true); // Log.getRootLogger().setDebugEnabled(true);
final Socket client = newClient(); final Socket client = newClient();
System.err.println("client="+client); // System.err.println("client="+client);
client.setSoTimeout(600000); // TODO: restore to smaller value client.setSoTimeout(600000); // TODO: restore to smaller value
SocketChannel server = _connector.accept(); SocketChannel server = _connector.accept();
@ -265,7 +267,7 @@ public class SslConnectionTest
System.err.println("==="); System.err.println("===");
return; return;
} }
System.err.println(new String(buffer,0,len,"UTF-8")); // System.err.println(new String(buffer,0,len,"UTF-8"));
} }
} }
@ -276,10 +278,10 @@ public class SslConnectionTest
} }
}.start(); }.start();
for (int i=0;i<1000000;i++) for (int i=0;i<100000;i++)
{ {
client.getOutputStream().write(("HelloWorld "+i+"\n").getBytes("UTF-8")); client.getOutputStream().write(("HelloWorld "+i+"\n").getBytes("UTF-8"));
System.err.println("wrote"); // System.err.println("wrote");
if (i%1000==0) if (i%1000==0)
Thread.sleep(10); Thread.sleep(10);
} }