1 package org.jboss.cache.tests.misc; 2 3 import EDU.oswego.cs.dl.util.concurrent.CopyOnWriteArrayList; 4 import junit.framework.Test; 5 import junit.framework.TestCase; 6 import junit.framework.TestSuite; 7 8 import java.util.Iterator ; 9 import java.util.LinkedList ; 10 11 15 public class CopyOnWriteArrayTest extends TestCase { 16 LinkedList l; 17 CopyOnWriteArrayList list; 18 Exception thread_ex=null; 19 20 protected void setUp() throws Exception { 21 super.setUp(); 22 l=new LinkedList (); 23 l.add("one"); 24 l.add("two"); 25 l.add("three"); 26 list=new CopyOnWriteArrayList(l); 27 thread_ex=null; 28 } 29 30 protected void tearDown() throws Exception { 31 super.tearDown(); 32 if(thread_ex != null) 33 throw thread_ex; 34 } 35 36 37 public void testInsertionandIteration() { 38 Object el; 39 System.out.println("list = " + list); 40 41 Iterator it=list.iterator(); 42 System.out.println(it.next()); 43 44 list.add("four"); 45 46 int count=0; 47 while(it.hasNext()) { 48 el=it.next(); 49 System.out.println(el); 50 ++count; 51 } 52 assertEquals(2, count); 53 54 System.out.println("list: " + list); 55 assertEquals(4, list.size()); 56 } 57 58 59 60 61 62 public static Test suite() { 63 return new TestSuite(CopyOnWriteArrayTest.class); 64 } 65 66 public static void main(String [] args) { 67 junit.textui.TestRunner.run(suite()); 68 } 69 70 } 71 | Popular Tags |