jetty-9 unit test cleanups
This commit is contained in:
parent
8101b67ce8
commit
ab298e511e
|
@ -17,6 +17,7 @@ import java.io.IOException;
|
|||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.eclipse.jetty.http.HttpTokens.EndOfContent;
|
||||
import org.eclipse.jetty.io.EofException;
|
||||
import org.eclipse.jetty.util.BufferUtil;
|
||||
import org.eclipse.jetty.util.Utf8StringBuilder;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
|
@ -898,7 +899,7 @@ public class HttpParser
|
|||
buffer.position(buffer.position()-1);
|
||||
String chars = BufferUtil.toDetailString(buffer);
|
||||
BufferUtil.clear(buffer);
|
||||
throw new IOException(this+" Extra data after oshut: "+chars);
|
||||
throw new EofException(this+" Extra data after oshut: "+chars);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -1075,16 +1076,25 @@ public class HttpParser
|
|||
|
||||
return false;
|
||||
}
|
||||
catch(EofException e)
|
||||
{
|
||||
LOG.debug(e);
|
||||
BufferUtil.clear(buffer);
|
||||
return false;
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
BufferUtil.clear(buffer);
|
||||
if (isClosed())
|
||||
{
|
||||
LOG.debug(e);
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
|
||||
LOG.warn(e);
|
||||
LOG.warn("badMessage: "+e.toString()+" for "+_handler);
|
||||
LOG.debug(e);
|
||||
_handler.badMessage(400, e.toString());
|
||||
BufferUtil.clear(buffer);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -413,7 +413,6 @@ public class HttpGeneratorServerTest
|
|||
result=gen.generate(info,header,null,null,null,null);
|
||||
assertEquals(HttpGenerator.Result.FLUSH,result);
|
||||
String head = BufferUtil.toString(header);
|
||||
System.out.println(head);
|
||||
BufferUtil.clear(header);
|
||||
|
||||
result=gen.generate(info,null,null,null,null,null);
|
||||
|
|
|
@ -13,13 +13,17 @@
|
|||
|
||||
package org.eclipse.jetty.io;
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.ByteChannel;
|
||||
import java.nio.channels.ClosedChannelException;
|
||||
import java.nio.channels.GatheringByteChannel;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.util.concurrent.BrokenBarrierException;
|
||||
|
||||
import org.eclipse.jetty.util.BufferUtil;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
|
@ -146,24 +150,31 @@ public class ChannelEndPoint extends AbstractEndPoint
|
|||
public int flush(ByteBuffer... buffers) throws IOException
|
||||
{
|
||||
int flushed=0;
|
||||
if (buffers.length==1)
|
||||
flushed=_channel.write(buffers[0]);
|
||||
else if (buffers.length>1 && _channel instanceof GatheringByteChannel)
|
||||
flushed= (int)((GatheringByteChannel)_channel).write(buffers,0,buffers.length);
|
||||
else
|
||||
try
|
||||
{
|
||||
for (ByteBuffer b : buffers)
|
||||
if (buffers.length==1)
|
||||
flushed=_channel.write(buffers[0]);
|
||||
else if (buffers.length>1 && _channel instanceof GatheringByteChannel)
|
||||
flushed= (int)((GatheringByteChannel)_channel).write(buffers,0,buffers.length);
|
||||
else
|
||||
{
|
||||
if (b.hasRemaining())
|
||||
for (ByteBuffer b : buffers)
|
||||
{
|
||||
int l=_channel.write(b);
|
||||
if (l>0)
|
||||
flushed+=l;
|
||||
else
|
||||
break;
|
||||
if (b.hasRemaining())
|
||||
{
|
||||
int l=_channel.write(b);
|
||||
if (l>0)
|
||||
flushed+=l;
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (ClosedChannelException | EOFException | SocketException e)
|
||||
{
|
||||
throw new EofException(e);
|
||||
}
|
||||
if (flushed>0)
|
||||
notIdle();
|
||||
return flushed;
|
||||
|
|
|
@ -53,8 +53,7 @@ import org.eclipse.jetty.util.resource.Resource;
|
|||
*/
|
||||
public abstract class HttpChannel
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(HttpChannel.class);
|
||||
|
||||
static final Logger LOG = Log.getLogger(HttpChannel.class);
|
||||
|
||||
private static final ThreadLocal<HttpChannel> __currentChannel = new ThreadLocal<HttpChannel>();
|
||||
|
||||
|
@ -355,8 +354,7 @@ public abstract class HttpChannel
|
|||
}
|
||||
catch (ServletException e)
|
||||
{
|
||||
LOG.warn(String.valueOf(_uri),e.toString());
|
||||
LOG.debug(String.valueOf(_uri),e);
|
||||
LOG.warn(String.valueOf(_uri),e);
|
||||
_state.error(e);
|
||||
_request.setHandled(true);
|
||||
commitError(500, null, e.toString());
|
||||
|
@ -406,7 +404,10 @@ public abstract class HttpChannel
|
|||
|
||||
// Complete reading the request
|
||||
_in.consumeAll();
|
||||
|
||||
}
|
||||
catch(EofException e)
|
||||
{
|
||||
LOG.debug(e);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
|
@ -703,6 +704,12 @@ public abstract class HttpChannel
|
|||
}
|
||||
return _response.commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "CEH:"+HttpChannel.this.getConnection().toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -157,43 +157,23 @@ public class HttpConnectionTest
|
|||
@Test
|
||||
public void testBad() throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
((StdErrLog)Log.getLogger(HttpParser.class)).setHideStacks(true);
|
||||
HttpParser.LOG.info("badMessage: 3 bad messages expected ...");
|
||||
String response;
|
||||
|
||||
String response;
|
||||
|
||||
response=connector.getResponses("GET http://localhost:WRONG/ HTTP/1.1\n"+
|
||||
"Host: localhost\n"+
|
||||
response=connector.getResponses("GET http://localhost:EXPECTED_NUMBER_FORMAT_EXCEPTION/ HTTP/1.1\n"+
|
||||
"Host: localhost\n"+
|
||||
"\015\012");
|
||||
checkContains(response,0,"HTTP/1.1 400");
|
||||
checkContains(response,0,"HTTP/1.1 400");
|
||||
|
||||
response=connector.getResponses("GET /bad/encoding%1 HTTP/1.1\n"+
|
||||
"Host: localhost\n"+
|
||||
response=connector.getResponses("GET /bad/encoding%1 HTTP/1.1\n"+
|
||||
"Host: localhost\n"+
|
||||
"\015\012");
|
||||
checkContains(response,0,"HTTP/1.1 400");
|
||||
checkContains(response,0,"HTTP/1.1 400");
|
||||
|
||||
/*
|
||||
response=connector.getResponses("GET /foo/bar%c0%00 HTTP/1.1\n"+
|
||||
"Host: localhost\n"+
|
||||
response=connector.getResponses("GET % HTTP/1.1\n"+
|
||||
"Host: localhost\n"+
|
||||
"\015\012");
|
||||
checkContains(response,0,"HTTP/1.1 400");
|
||||
|
||||
response=connector.getResponses("GET /bad/utf8%c1 HTTP/1.1\n"+
|
||||
"Host: localhost\n"+
|
||||
"\015\012");
|
||||
checkContains(response,0,"HTTP/1.1 400");
|
||||
*/
|
||||
|
||||
response=connector.getResponses("GET % HTTP/1.1\n"+
|
||||
"Host: localhost\n"+
|
||||
"\015\012");
|
||||
checkContains(response,0,"HTTP/1.1 400");
|
||||
}
|
||||
finally
|
||||
{
|
||||
((StdErrLog)Log.getLogger(HttpParser.class)).setHideStacks(false);
|
||||
}
|
||||
checkContains(response,0,"HTTP/1.1 400");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -340,6 +320,7 @@ public class HttpConnectionTest
|
|||
|
||||
try
|
||||
{
|
||||
HttpChannel.LOG.info("EXPECTING: java.lang.IllegalStateException...");
|
||||
((StdErrLog)Log.getLogger(HttpChannel.class)).setHideStacks(true);
|
||||
response=connector.getResponses(requests);
|
||||
offset = checkContains(response,offset,"HTTP/1.1 500");
|
||||
|
|
|
@ -110,16 +110,17 @@ public class SSLCloseTest extends TestCase
|
|||
String line;
|
||||
while ((line=in.readLine())!=null)
|
||||
{
|
||||
System.err.println(line);
|
||||
// System.err.println(line);
|
||||
if (line.trim().length()==0)
|
||||
break;
|
||||
}
|
||||
|
||||
Thread.sleep(2000);
|
||||
System.err.println(__endp);
|
||||
// System.err.println(__endp);
|
||||
|
||||
while ((line=in.readLine())!=null)
|
||||
System.err.println(line);
|
||||
//System.err.println(line);
|
||||
Thread.yield();
|
||||
|
||||
}
|
||||
|
||||
|
@ -147,7 +148,7 @@ public class SSLCloseTest extends TestCase
|
|||
|
||||
for (int i=0;i<2;i++)
|
||||
{
|
||||
System.err.println("Write "+i+" "+bytes.length);
|
||||
// System.err.println("Write "+i+" "+bytes.length);
|
||||
out.write(bytes);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,7 +84,6 @@ public class SSLSelectChannelConnectorLoadTest
|
|||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testLongLivedConnections() throws Exception
|
||||
{
|
||||
Worker.totalIterations.set(0);
|
||||
|
@ -110,13 +109,13 @@ public class SSLSelectChannelConnectorLoadTest
|
|||
boolean done = true;
|
||||
for (Future task : tasks)
|
||||
done &= task.isDone();
|
||||
System.err.print("\rIterations: " + Worker.totalIterations.get() + "/" + clients * iterations);
|
||||
//System.err.print("\rIterations: " + Worker.totalIterations.get() + "/" + clients * iterations);
|
||||
if (done)
|
||||
break;
|
||||
}
|
||||
long end = System.currentTimeMillis();
|
||||
System.err.println();
|
||||
System.err.println("Elapsed time: " + TimeUnit.MILLISECONDS.toSeconds(end - start) + "s");
|
||||
//System.err.println();
|
||||
//System.err.println("Elapsed time: " + TimeUnit.MILLISECONDS.toSeconds(end - start) + "s");
|
||||
|
||||
for (Worker worker : workers)
|
||||
worker.close();
|
||||
|
@ -132,7 +131,6 @@ public class SSLSelectChannelConnectorLoadTest
|
|||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testShortLivedConnections() throws Exception
|
||||
{
|
||||
Worker.totalIterations.set(0);
|
||||
|
@ -157,13 +155,13 @@ public class SSLSelectChannelConnectorLoadTest
|
|||
boolean done = true;
|
||||
for (Future task : tasks)
|
||||
done &= task.isDone();
|
||||
System.err.print("\rIterations: " + Worker.totalIterations.get() + "/" + clients * iterations);
|
||||
// System.err.print("\rIterations: " + Worker.totalIterations.get() + "/" + clients * iterations);
|
||||
if (done)
|
||||
break;
|
||||
}
|
||||
long end = System.currentTimeMillis();
|
||||
System.err.println();
|
||||
System.err.println("Elapsed time: " + TimeUnit.MILLISECONDS.toSeconds(end - start) + "s");
|
||||
// System.err.println();
|
||||
// System.err.println("Elapsed time: " + TimeUnit.MILLISECONDS.toSeconds(end - start) + "s");
|
||||
|
||||
threadPool.shutdown();
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ public class MultiMap implements Map<String,Object>
|
|||
* @param name The entry key.
|
||||
* @return Unmodifieable List of values.
|
||||
*/
|
||||
public List getValues(Object name)
|
||||
public List getValues(String name)
|
||||
{
|
||||
return LazyList.getList(_map.get(name),true);
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ public class MultiMap implements Map<String,Object>
|
|||
* @param i Index of element to get.
|
||||
* @return Unmodifieable List of values.
|
||||
*/
|
||||
public Object getValue(Object name,int i)
|
||||
public Object getValue(String name,int i)
|
||||
{
|
||||
Object l=_map.get(name);
|
||||
if (i==0 && LazyList.size(l)==0)
|
||||
|
@ -80,7 +80,7 @@ public class MultiMap implements Map<String,Object>
|
|||
* @param name The entry key.
|
||||
* @return String value.
|
||||
*/
|
||||
public String getString(Object name)
|
||||
public String getString(String name)
|
||||
{
|
||||
Object l=_map.get(name);
|
||||
switch(LazyList.size(l))
|
||||
|
|
Loading…
Reference in New Issue