Fix for #308855 (Update test suite to JUnit4 - Module jetty-io).

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@1762 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Simone Bordet 2010-05-12 08:39:06 +00:00
parent 7b82292ff0
commit 8d9ecd3268
7 changed files with 161 additions and 275 deletions

View File

@ -10,6 +10,7 @@ jetty-7.1.1-SNAPSHOT
+ 308859 Update test suite to JUnit4 - Module jetty-policy
+ 308858 Update test suite to JUnit4 - Module jetty-plus
+ 308863 Update test suite to JUnit4 - Module jetty-servlet
+ 308855 Update test suite to JUnit4 - Module jetty-io
jetty-7.1.0 5 May 2010
+ 306353 fixed cross context dispatch to root context.

View File

@ -20,6 +20,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit4-version}</version>
<scope>test</scope>
</dependency>
</dependencies>

View File

@ -13,52 +13,33 @@
package org.eclipse.jetty.io;
import junit.framework.TestCase;
import org.junit.Before;
import org.junit.Test;
/* ------------------------------------------------------------------------------- */
/**
*
*
*/
public class BufferCacheTest extends TestCase
{
final static String[] S=
{ "S0", "S1", "s2", "s3" };
BufferCache cache;
public BufferCacheTest(String arg0)
{
super(arg0);
}
public static void main(String[] args)
{
junit.textui.TestRunner.run(BufferCacheTest.class);
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
/**
* @see TestCase#setUp()
*
*/
@Override
protected void setUp() throws Exception
public class BufferCacheTest
{
private final static String[] S = {"S0", "S1", "s2", "s3" };
private BufferCache cache;
@Before
public void init() throws Exception
{
super.setUp();
cache=new BufferCache();
cache.add(S[1],1);
cache.add(S[2],2);
cache.add(S[3],3);
}
/**
* @see TestCase#tearDown()
*/
@Override
protected void tearDown() throws Exception
{
super.tearDown();
}
@Test
public void testLookupIndex()
{
for (int i=0; i<S.length; i++)
@ -75,6 +56,7 @@ public class BufferCacheTest extends TestCase
}
}
@Test
public void testGetBuffer()
{
for (int i=0; i<S.length; i++)
@ -90,6 +72,7 @@ public class BufferCacheTest extends TestCase
}
}
@Test
public void testLookupBuffer()
{
for (int i=0; i<S.length; i++)
@ -100,15 +83,16 @@ public class BufferCacheTest extends TestCase
assertEquals(S[i],b.toString());
if (i>0)
assertTrue(""+i,S[i]==b.toString());
assertSame(""+i, S[i], b.toString());
else
{
assertTrue(""+i,S[i]!=b.toString());
assertNotSame(""+i, S[i], b.toString());
assertEquals(""+i, S[i], b.toString());
}
}
}
@Test
public void testLookupPartialBuffer()
{
cache.add("44444",4);
@ -129,6 +113,7 @@ public class BufferCacheTest extends TestCase
}
@Test
public void testInsensitiveLookupBuffer()
{
for (int i=0; i<S.length; i++)
@ -139,12 +124,13 @@ public class BufferCacheTest extends TestCase
assertTrue("test"+i,S[i].equalsIgnoreCase(b.toString()));
if (i>0)
assertTrue("test"+i,S[i]==b.toString());
assertSame("test"+i, S[i], b.toString());
else
assertTrue("test"+i,S[i]!=b.toString());
assertNotSame("test"+i, S[i], b.toString());
}
}
@Test
public void testToString()
{
for (int i=0; i<S.length; i++)
@ -155,10 +141,9 @@ public class BufferCacheTest extends TestCase
assertEquals(S[i],b);
if (i>0)
assertTrue(S[i]==b);
assertSame(S[i], b);
else
assertTrue(S[i]!=b);
assertNotSame(S[i], b);
}
}
}

View File

@ -15,37 +15,28 @@ package org.eclipse.jetty.io;
import java.io.File;
import junit.framework.TestCase;
import org.eclipse.jetty.io.nio.DirectNIOBuffer;
import org.eclipse.jetty.io.nio.IndirectNIOBuffer;
import org.eclipse.jetty.io.nio.RandomAccessFileBuffer;
import org.eclipse.jetty.util.StringUtil;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
*
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class BufferTest extends TestCase
public class BufferTest
{
Buffer[] buffer;
private Buffer[] buffer;
public static void main(String[] args)
@Before
public void init() throws Exception
{
}
/*
* @see TestCase#setUp()
*/
@Override
protected void setUp() throws Exception
{
super.setUp();
File file = File.createTempFile("test",".buf");
file.deleteOnExit();
file.createNewFile();
buffer=new Buffer[]{
new RandomAccessFileBuffer(file,10),
@ -55,20 +46,8 @@ public class BufferTest extends TestCase
};
}
/*
* @see TestCase#tearDown()
*/
@Override
protected void tearDown() throws Exception
{
super.tearDown();
}
/*
*
*/
public void testBuffer()
throws Exception
@Test
public void testBuffer() throws Exception
{
for (int i=0;i<buffer.length;i++)
{
@ -119,8 +98,8 @@ public class BufferTest extends TestCase
}
}
public void testHash()
throws Exception
@Test
public void testHash() throws Exception
{
Buffer[] b=
{
@ -134,8 +113,8 @@ public class BufferTest extends TestCase
assertEquals("t"+i,b[0].hashCode(),b[i].hashCode());
}
public void testGet ()
throws Exception
@Test
public void testGet () throws Exception
{
Buffer buff = new ByteArrayBuffer(new byte[]{(byte)0,(byte)1,(byte)2,(byte)3,(byte)4,(byte)5});
@ -165,6 +144,7 @@ public class BufferTest extends TestCase
}
@Test
public void testInsensitive()
{
Buffer cs0 = new ByteArrayBuffer("Test 1234");
@ -251,6 +231,7 @@ public class BufferTest extends TestCase
}
@Test
public void testView()
{
Buffer b = new ByteArrayBuffer(" Test 1234 ".getBytes());
@ -276,6 +257,4 @@ public class BufferTest extends TestCase
assertEquals(s4, s5);
}
}

View File

@ -14,31 +14,17 @@
package org.eclipse.jetty.io;
import junit.framework.TestCase;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/* ------------------------------------------------------------------------------- */
/**
*
*/
public class BufferUtilTest extends TestCase
public class BufferUtilTest
{
/**
* Constructor for BufferUtilTest.
* @param arg0
*/
public BufferUtilTest(String arg0)
{
super(arg0);
}
public static void main(String[] args)
{
junit.textui.TestRunner.run(BufferUtilTest.class);
}
public void testToInt()
throws Exception
@Test
public void testToInt() throws Exception
{
Buffer buf[] =
{
@ -60,8 +46,8 @@ public class BufferUtilTest extends TestCase
assertEquals("t"+i, val[i], BufferUtil.toInt(buf[i]));
}
public void testPutInt()
throws Exception
@Test
public void testPutInt() throws Exception
{
int val[] =
{
@ -83,8 +69,8 @@ public class BufferUtilTest extends TestCase
}
}
public void testPutLong()
throws Exception
@Test
public void testPutLong() throws Exception
{
long val[] =
{
@ -106,8 +92,8 @@ public class BufferUtilTest extends TestCase
}
}
public void testPutHexInt()
throws Exception
@Test
public void testPutHexInt() throws Exception
{
int val[] =
{

View File

@ -16,38 +16,17 @@ package org.eclipse.jetty.io;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import junit.framework.TestSuite;
import org.eclipse.jetty.util.IO;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/* ------------------------------------------------------------ */
/** Util meta Tests.
/**
*
*/
public class IOTest extends junit.framework.TestCase
public class IOTest
{
public IOTest(String name)
{
super(name);
}
public static junit.framework.Test suite() {
TestSuite suite = new TestSuite(IOTest.class);
return suite;
}
/* ------------------------------------------------------------ */
/** main.
*/
public static void main(String[] args)
{
junit.textui.TestRunner.run(suite());
}
/* ------------------------------------------------------------ */
@Test
public void testIO() throws InterruptedException
{
// Only a little test
@ -64,9 +43,7 @@ public class IOTest extends junit.framework.TestCase
"The quick brown fox jumped over the lazy dog");
}
/* ------------------------------------------------------------ */
@Test
public void testStringSpeed()
{
String s="012345678901234567890000000000000000000000000";
@ -93,6 +70,5 @@ public class IOTest extends junit.framework.TestCase
}
end=System.currentTimeMillis();
System.err.println("getChars "+(end-start)+" "+result);
}
}

View File

@ -14,46 +14,24 @@
package org.eclipse.jetty.io;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;
import junit.framework.TestCase;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
public class ThreadLocalBuffersTest
extends TestCase
{
public boolean _stress = Boolean.getBoolean("STRESS");
private int _headerBufferSize = 6 * 1024;
private InnerBuffers httpBuffers;
private List<Thread> threadList = new ArrayList<Thread>();
private int numThreads = _stress?100:10;
private int runTestLength = _stress?5000:1000;
private boolean runTest = false;
private AtomicLong buffersRetrieved;
InnerBuffers httpBuffers;
List<Thread> threadList = new ArrayList<Thread>();
int numThreads = _stress?100:10;
int runTestLength = _stress?5000:1000;
boolean runTest = false;
AtomicLong buffersRetrieved;
@Override
protected void setUp()
throws Exception
{
super.setUp();
}
@Override
protected void tearDown()
throws Exception
{
super.tearDown();
}
public void execAbstractBuffer()
throws Exception
private void execAbstractBuffer() throws Exception
{
threadList.clear();
buffersRetrieved = new AtomicLong( 0 );
@ -94,21 +72,18 @@ public class ThreadLocalBuffersTest
System.out.println( "Buffers Retrieved: " + totalBuffersRetrieved );
System.out.println( "Memory Used: " + ( mem1 - mem0 ) );
for ( Iterator<Thread> i = threadList.iterator(); i.hasNext(); )
{
Thread t = i.next();
for (Thread t : threadList)
t.stop();
}
}
public void testAbstractBuffers()
throws Exception
@Test
public void testAbstractBuffers() throws Exception
{
execAbstractBuffer( );
}
public void testDifferentSizes()
throws Exception
@Test
public void testDifferentSizes() throws Exception
{
InnerBuffers buffers = new InnerBuffers();
buffers.setHeaderSize(128);
@ -142,7 +117,6 @@ public class ThreadLocalBuffersTest
assertTrue(b2!=buffers.getBuffer()); // new buffer
assertTrue(b3!=buffers.getBuffer(512)); // new buffer
// check that sizes are respected
buffers.returnBuffer(b3);
buffers.returnBuffer(b1);
@ -157,10 +131,9 @@ public class ThreadLocalBuffersTest
assertTrue(b3!=buffers.getBuffer(512)); // new buffer
}
public void testSameSizes()
throws Exception
@Test
public void testSameSizes() throws Exception
{
Buffer buffer=null;
InnerBuffers buffers = new InnerBuffers();
buffers.setHeaderSize(128);
buffers.setBufferSize(128);
@ -184,14 +157,13 @@ public class ThreadLocalBuffersTest
buffers.returnBuffer(b3);
assertTrue(h1==buffers.getHeader()); // pooled header
buffer=buffers.getHeader();
Buffer buffer = buffers.getHeader();
for (Buffer b:known) assertTrue(b!=buffer); // new buffer
assertTrue(h2==buffers.getBuffer()); // h2 used from buffer slot
assertTrue(b3==buffers.getBuffer()); // b1 from other slot
buffer=buffers.getBuffer(128);
for (Buffer b:known) assertTrue(b!=buffer); // new buffer
buffers.returnBuffer(h1);
buffers.returnBuffer(h2);
buffers.returnBuffer(b1);
@ -213,11 +185,9 @@ public class ThreadLocalBuffersTest
assertTrue(b1==buffers.getBuffer()); // b1 used from buffer slot
buffer=buffers.getBuffer();
for (Buffer b:known) assertTrue(b!=buffer); // new buffer
}
static class HeaderBuffer extends ByteArrayBuffer
private static class HeaderBuffer extends ByteArrayBuffer
{
public HeaderBuffer(int size)
{
@ -225,7 +195,7 @@ public class ThreadLocalBuffersTest
}
}
static class InnerBuffers extends ThreadLocalBuffers
private static class InnerBuffers extends ThreadLocalBuffers
{
@Override
protected Buffer newBuffer(int size)
@ -244,21 +214,13 @@ public class ThreadLocalBuffersTest
}
}
/**
* generic buffer peeper
*
*
*/
class BufferPeeper
extends Thread
private class BufferPeeper extends Thread
{
private String _bufferName;
private final String _bufferName;
public BufferPeeper( String bufferName )
{
_bufferName = bufferName;
start();
}
@ -269,15 +231,12 @@ public class ThreadLocalBuffersTest
{
try
{
if ( runTest )
{
Buffer buf = httpBuffers.getHeader();
buffersRetrieved.getAndIncrement();
buf.put( new Byte( "2" ).byteValue() );
buf.put(new Byte("2"));
// sleep( threadWaitTime );
@ -296,5 +255,4 @@ public class ThreadLocalBuffersTest
}
}
}
}