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:
parent
7b82292ff0
commit
8d9ecd3268
|
@ -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.
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit4-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
@ -50,7 +51,7 @@
|
|||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<archive>
|
||||
<archive>
|
||||
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
|
||||
</archive>
|
||||
</configuration>
|
||||
|
|
|
@ -4,61 +4,42 @@
|
|||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
// The Eclipse Public License is available at
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
|
||||
package org.eclipse.jetty.io;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/* ------------------------------------------------------------------------------- */
|
||||
/**
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class BufferCacheTest extends TestCase
|
||||
public class BufferCacheTest
|
||||
{
|
||||
final static String[] S=
|
||||
{ "S0", "S1", "s2", "s3" };
|
||||
private final static String[] S = {"S0", "S1", "s2", "s3" };
|
||||
|
||||
BufferCache cache;
|
||||
private BufferCache cache;
|
||||
|
||||
public BufferCacheTest(String arg0)
|
||||
@Before
|
||||
public void init() throws Exception
|
||||
{
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
junit.textui.TestRunner.run(BufferCacheTest.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see TestCase#setUp()
|
||||
*/
|
||||
@Override
|
||||
protected void setUp() 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,35 +83,37 @@ 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());
|
||||
assertEquals(""+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);
|
||||
|
||||
|
||||
ByteArrayBuffer buf=new ByteArrayBuffer("44444");
|
||||
Buffer b=cache.lookup(buf);
|
||||
assertEquals("44444",b.toString());
|
||||
assertEquals(4,cache.getOrdinal(b));
|
||||
|
||||
|
||||
buf=new ByteArrayBuffer("4444");
|
||||
b=cache.lookup(buf);
|
||||
assertEquals(-1,cache.getOrdinal(b));
|
||||
|
||||
|
||||
buf=new ByteArrayBuffer("44444x");
|
||||
b=cache.lookup(buf);
|
||||
assertEquals(-1,cache.getOrdinal(b));
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,49 +4,40 @@
|
|||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
// The Eclipse Public License is available at
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
|
||||
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;
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
}
|
||||
private Buffer[] buffer;
|
||||
|
||||
/*
|
||||
* @see TestCase#setUp()
|
||||
*/
|
||||
@Override
|
||||
protected void setUp() throws Exception
|
||||
@Before
|
||||
public void init() throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
File file = File.createTempFile("test",".buf");
|
||||
file.deleteOnExit();
|
||||
file.createNewFile();
|
||||
|
||||
|
||||
buffer=new Buffer[]{
|
||||
new RandomAccessFileBuffer(file,10),
|
||||
new ByteArrayBuffer(10),
|
||||
|
@ -55,37 +46,25 @@ 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++)
|
||||
{
|
||||
String t="t"+i;
|
||||
Buffer b = buffer[i];
|
||||
|
||||
|
||||
assertEquals(t,0,b.length());
|
||||
assertEquals(t,10,b.capacity());
|
||||
assertEquals(t,10,b.space());
|
||||
|
||||
|
||||
b.put((byte)0);
|
||||
b.put((byte)1);
|
||||
b.put((byte)2);
|
||||
assertEquals(t,3,b.length());
|
||||
assertEquals(t,10,b.capacity());
|
||||
assertEquals(t,7,b.space());
|
||||
|
||||
|
||||
assertEquals(t,0,b.get());
|
||||
assertEquals(t,1,b.get());
|
||||
assertEquals(t,1,b.length());
|
||||
|
@ -93,34 +72,34 @@ public class BufferTest extends TestCase
|
|||
assertEquals(t,7,b.space());
|
||||
b.compact();
|
||||
assertEquals(t,9,b.space());
|
||||
|
||||
|
||||
byte[] ba = { (byte)-1, (byte)3,(byte)4,(byte)5,(byte)6 };
|
||||
|
||||
|
||||
b.put(ba,1,3);
|
||||
assertEquals(t,4,b.length());
|
||||
assertEquals(t,6,b.space());
|
||||
|
||||
|
||||
byte[] bg = new byte[4];
|
||||
b.get(bg,1,2);
|
||||
assertEquals(t,2,bg[1]);
|
||||
assertEquals(t,3,bg[2]);
|
||||
|
||||
|
||||
//test getting 0 bytes returns 0
|
||||
int count = b.get(bg,0,0);
|
||||
assertEquals(t,0, count);
|
||||
|
||||
|
||||
//read up to end
|
||||
count = b.get(bg,0,2);
|
||||
assertEquals(t, 2, count);
|
||||
|
||||
|
||||
//test reading past end returns -1
|
||||
count = b.get(bg,0,1);
|
||||
assertEquals(t, -1, count);
|
||||
}
|
||||
}
|
||||
|
||||
public void testHash()
|
||||
throws Exception
|
||||
|
||||
@Test
|
||||
public void testHash() throws Exception
|
||||
{
|
||||
Buffer[] b=
|
||||
{
|
||||
|
@ -129,42 +108,43 @@ public class BufferTest extends TestCase
|
|||
new DirectNIOBuffer(4096),
|
||||
};
|
||||
b[2].put("TeSt1234 ".getBytes(StringUtil.__UTF8));
|
||||
|
||||
|
||||
for (int i=0;i<b.length;i++)
|
||||
assertEquals("t"+i,b[0].hashCode(),b[i].hashCode());
|
||||
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});
|
||||
|
||||
|
||||
byte[] readbuff = new byte[2];
|
||||
|
||||
|
||||
int count = buff.get(readbuff, 0, 2);
|
||||
assertEquals(2, count);
|
||||
assertEquals(readbuff[0], (byte)0);
|
||||
assertEquals(readbuff[1], (byte)1);
|
||||
|
||||
|
||||
count = buff.get(readbuff, 0, 2);
|
||||
assertEquals(2, count);
|
||||
assertEquals(readbuff[0], (byte)2);
|
||||
assertEquals(readbuff[1], (byte)3);
|
||||
|
||||
|
||||
count = buff.get(readbuff, 0, 0);
|
||||
assertEquals(0, count);
|
||||
|
||||
|
||||
readbuff[0]=(byte)9;
|
||||
readbuff[1]=(byte)9;
|
||||
|
||||
|
||||
count = buff.get(readbuff, 0, 2);
|
||||
assertEquals(2, count);
|
||||
|
||||
|
||||
count = buff.get(readbuff, 0, 2);
|
||||
assertEquals(-1, count);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testInsensitive()
|
||||
{
|
||||
Buffer cs0 = new ByteArrayBuffer("Test 1234");
|
||||
|
@ -184,7 +164,7 @@ public class BufferTest extends TestCase
|
|||
assertTrue( cs0.equals(ci1));
|
||||
assertTrue( cs0.equals(ci2));
|
||||
assertTrue(!cs0.equals(ci3));
|
||||
|
||||
|
||||
assertTrue( cs1.equals(cs0));
|
||||
assertTrue( cs1.equals(cs1));
|
||||
assertTrue(!cs1.equals(cs2));
|
||||
|
@ -193,7 +173,7 @@ public class BufferTest extends TestCase
|
|||
assertTrue( cs1.equals(ci1));
|
||||
assertTrue( cs1.equals(ci2));
|
||||
assertTrue(!cs1.equals(ci3));
|
||||
|
||||
|
||||
assertTrue(!cs2.equals(cs0));
|
||||
assertTrue(!cs2.equals(cs1));
|
||||
assertTrue( cs2.equals(cs2));
|
||||
|
@ -211,8 +191,8 @@ public class BufferTest extends TestCase
|
|||
assertTrue(!cs3.equals(ci1));
|
||||
assertTrue(!cs3.equals(ci2));
|
||||
assertTrue( cs3.equals(ci3));
|
||||
|
||||
|
||||
|
||||
|
||||
assertTrue( ci0.equals(cs0));
|
||||
assertTrue( ci0.equals(cs1));
|
||||
assertTrue( ci0.equals(cs2));
|
||||
|
@ -221,7 +201,7 @@ public class BufferTest extends TestCase
|
|||
assertTrue( ci0.equals(ci1));
|
||||
assertTrue( ci0.equals(ci2));
|
||||
assertTrue(!ci0.equals(ci3));
|
||||
|
||||
|
||||
assertTrue( ci1.equals(cs0));
|
||||
assertTrue( ci1.equals(cs1));
|
||||
assertTrue( ci1.equals(cs2));
|
||||
|
@ -230,7 +210,7 @@ public class BufferTest extends TestCase
|
|||
assertTrue( ci1.equals(ci1));
|
||||
assertTrue( ci1.equals(ci2));
|
||||
assertTrue(!ci1.equals(ci3));
|
||||
|
||||
|
||||
assertTrue( ci2.equals(cs0));
|
||||
assertTrue( ci2.equals(cs1));
|
||||
assertTrue( ci2.equals(cs2));
|
||||
|
@ -251,6 +231,7 @@ public class BufferTest extends TestCase
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testView()
|
||||
{
|
||||
Buffer b = new ByteArrayBuffer(" Test 1234 ".getBytes());
|
||||
|
@ -259,7 +240,7 @@ public class BufferTest extends TestCase
|
|||
View v0 = new View(b);
|
||||
View v1 = new View(b);
|
||||
View v2 = new View(v0);
|
||||
|
||||
|
||||
String s=b.toString();
|
||||
String s0=v0.toString();
|
||||
String s1=v1.toString();
|
||||
|
@ -267,15 +248,13 @@ public class BufferTest extends TestCase
|
|||
String s3=v0.toString();
|
||||
String s4=v1.toString();
|
||||
String s5=v2.toString();
|
||||
|
||||
|
||||
assertEquals(s, s0);
|
||||
assertEquals(s0, s1);
|
||||
assertEquals(s1, s2);
|
||||
assertEquals(s2, s3);
|
||||
assertEquals(s3, s4);
|
||||
assertEquals(s4, s5);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,43 +4,29 @@
|
|||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
// The Eclipse Public License is available at
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
|
||||
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)
|
||||
@Test
|
||||
public void testToInt() throws Exception
|
||||
{
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
junit.textui.TestRunner.run(BufferUtilTest.class);
|
||||
}
|
||||
|
||||
public void testToInt()
|
||||
throws Exception
|
||||
{
|
||||
Buffer buf[] =
|
||||
Buffer buf[] =
|
||||
{
|
||||
new ByteArrayBuffer("0"),
|
||||
new ByteArrayBuffer(" 42 "),
|
||||
|
@ -50,29 +36,29 @@ public class BufferUtilTest extends TestCase
|
|||
new ByteArrayBuffer("-2147483648"),
|
||||
new ByteArrayBuffer("2147483647"),
|
||||
};
|
||||
|
||||
|
||||
int val[] =
|
||||
{
|
||||
0,42,43,-44,-45,-2147483648,2147483647
|
||||
};
|
||||
|
||||
|
||||
for (int i=0;i<buf.length;i++)
|
||||
assertEquals("t"+i, val[i], BufferUtil.toInt(buf[i]));
|
||||
}
|
||||
|
||||
public void testPutInt()
|
||||
throws Exception
|
||||
@Test
|
||||
public void testPutInt() throws Exception
|
||||
{
|
||||
int val[] =
|
||||
{
|
||||
0,42,43,-44,-45,Integer.MIN_VALUE,Integer.MAX_VALUE
|
||||
};
|
||||
|
||||
|
||||
String str[] =
|
||||
{
|
||||
"0","42","43","-44","-45",""+Integer.MIN_VALUE,""+Integer.MAX_VALUE
|
||||
};
|
||||
|
||||
|
||||
Buffer buffer = new ByteArrayBuffer(12);
|
||||
|
||||
for (int i=0;i<val.length;i++)
|
||||
|
@ -80,11 +66,11 @@ public class BufferUtilTest extends TestCase
|
|||
buffer.clear();
|
||||
BufferUtil.putDecInt(buffer,val[i]);
|
||||
assertEquals("t"+i,str[i],BufferUtil.to8859_1_String(buffer));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testPutLong()
|
||||
throws Exception
|
||||
|
||||
@Test
|
||||
public void testPutLong() throws Exception
|
||||
{
|
||||
long val[] =
|
||||
{
|
||||
|
@ -103,22 +89,22 @@ public class BufferUtilTest extends TestCase
|
|||
buffer.clear();
|
||||
BufferUtil.putDecLong(buffer,val[i]);
|
||||
assertEquals("t"+i,str[i],BufferUtil.to8859_1_String(buffer));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testPutHexInt()
|
||||
throws Exception
|
||||
@Test
|
||||
public void testPutHexInt() throws Exception
|
||||
{
|
||||
int val[] =
|
||||
{
|
||||
0,42,43,-44,-45,-2147483648,2147483647
|
||||
};
|
||||
|
||||
|
||||
String str[] =
|
||||
{
|
||||
"0","2A","2B","-2C","-2D","-80000000","7FFFFFFF"
|
||||
};
|
||||
|
||||
|
||||
Buffer buffer = new ByteArrayBuffer(12);
|
||||
|
||||
for (int i=0;i<val.length;i++)
|
||||
|
@ -126,6 +112,6 @@ public class BufferUtilTest extends TestCase
|
|||
buffer.clear();
|
||||
BufferUtil.putHexInt(buffer,val[i]);
|
||||
assertEquals("t"+i,str[i],BufferUtil.to8859_1_String(buffer));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
// The Eclipse Public License is available at
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
|
||||
package org.eclipse.jetty.io;
|
||||
|
@ -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,15 +43,13 @@ public class IOTest extends junit.framework.TestCase
|
|||
"The quick brown fox jumped over the lazy dog");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Test
|
||||
public void testStringSpeed()
|
||||
{
|
||||
String s="012345678901234567890000000000000000000000000";
|
||||
char[] ca = new char[s.length()];
|
||||
int loops=1000000;
|
||||
|
||||
|
||||
long start=System.currentTimeMillis();
|
||||
long result=0;
|
||||
for (int loop=0;loop<loops;loop++)
|
||||
|
@ -82,7 +59,7 @@ public class IOTest extends junit.framework.TestCase
|
|||
}
|
||||
long end=System.currentTimeMillis();
|
||||
System.err.println("charAt "+(end-start)+" "+result);
|
||||
|
||||
|
||||
start=System.currentTimeMillis();
|
||||
result=0;
|
||||
for (int loop=0;loop<loops;loop++)
|
||||
|
@ -93,6 +70,5 @@ public class IOTest extends junit.framework.TestCase
|
|||
}
|
||||
end=System.currentTimeMillis();
|
||||
System.err.println("getChars "+(end-start)+" "+result);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,56 +4,34 @@
|
|||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
// The Eclipse Public License is available at
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
|
||||
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,54 +72,50 @@ 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);
|
||||
buffers.setBufferSize(256);
|
||||
|
||||
|
||||
Buffer h1 = buffers.getHeader();
|
||||
Buffer h2 = buffers.getHeader();
|
||||
Buffer b1 = buffers.getBuffer();
|
||||
Buffer b2 = buffers.getBuffer();
|
||||
Buffer b3 = buffers.getBuffer(512);
|
||||
|
||||
|
||||
buffers.returnBuffer(h1);
|
||||
buffers.returnBuffer(h2);
|
||||
buffers.returnBuffer(b1);
|
||||
buffers.returnBuffer(b2);
|
||||
buffers.returnBuffer(b3);
|
||||
|
||||
|
||||
assertTrue(h1==buffers.getHeader()); // pooled header
|
||||
assertTrue(h2!=buffers.getHeader()); // b2 replaced h2 in other slot
|
||||
assertTrue(b1==buffers.getBuffer()); // pooled buffer
|
||||
assertTrue(b2!=buffers.getBuffer()); // b3 replaced b2 in other slot
|
||||
assertTrue(b3==buffers.getBuffer(512)); // b2 from other slot
|
||||
|
||||
|
||||
buffers.returnBuffer(h1);
|
||||
buffers.returnBuffer(h2);
|
||||
buffers.returnBuffer(b1);
|
||||
|
||||
|
||||
assertTrue(h1==buffers.getHeader()); // pooled header
|
||||
assertTrue(h2==buffers.getHeader()); // h2 in other slot
|
||||
assertTrue(b1==buffers.getBuffer()); // pooled buffer
|
||||
assertTrue(b2!=buffers.getBuffer()); // new buffer
|
||||
assertTrue(b3!=buffers.getBuffer(512)); // new buffer
|
||||
|
||||
|
||||
// check that sizes are respected
|
||||
buffers.returnBuffer(b3);
|
||||
|
@ -149,22 +123,21 @@ public class ThreadLocalBuffersTest
|
|||
buffers.returnBuffer(b2);
|
||||
buffers.returnBuffer(h1);
|
||||
buffers.returnBuffer(h2);
|
||||
|
||||
|
||||
assertTrue(h1==buffers.getHeader()); // pooled header
|
||||
assertTrue(h2==buffers.getHeader()); // h2 in other slot
|
||||
assertTrue(b1==buffers.getBuffer()); // pooled buffer
|
||||
assertTrue(b2!=buffers.getBuffer()); // new buffer
|
||||
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);
|
||||
|
||||
|
||||
Buffer h1 = buffers.getHeader();
|
||||
Buffer h2 = buffers.getHeader();
|
||||
Buffer b1 = buffers.getBuffer();
|
||||
|
@ -176,26 +149,25 @@ public class ThreadLocalBuffersTest
|
|||
known.add(b1);
|
||||
known.add(b2);
|
||||
known.add(h1);
|
||||
|
||||
|
||||
buffers.returnBuffer(h1);
|
||||
buffers.returnBuffer(h2);
|
||||
buffers.returnBuffer(b1);
|
||||
buffers.returnBuffer(b2);
|
||||
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);
|
||||
|
||||
|
||||
assertTrue(h1==buffers.getHeader()); // pooled header
|
||||
buffer=buffers.getHeader();
|
||||
for (Buffer b:known) assertTrue(b!=buffer); // new buffer
|
||||
|
@ -205,7 +177,7 @@ public class ThreadLocalBuffersTest
|
|||
buffers.returnBuffer(h1);
|
||||
buffers.returnBuffer(b1);
|
||||
buffers.returnBuffer(h2);
|
||||
|
||||
|
||||
assertTrue(h1==buffers.getHeader()); // pooled header
|
||||
assertTrue(h2==buffers.getHeader()); // h2 from other slot
|
||||
buffer=buffers.getHeader();
|
||||
|
@ -213,19 +185,17 @@ 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)
|
||||
{
|
||||
super(size);
|
||||
}
|
||||
}
|
||||
|
||||
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
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue