[hornetq-commits] JBoss hornetq SVN: r12225 - branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/unit/util.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Mar 1 11:04:29 EST 2012


Author: clebert.suconic
Date: 2012-03-01 11:04:29 -0500 (Thu, 01 Mar 2012)
New Revision: 12225

Modified:
   branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/unit/util/LinkedListTest.java
Log:
Adding unit-test on JBPAPP-8282

Modified: branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/unit/util/LinkedListTest.java
===================================================================
--- branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/unit/util/LinkedListTest.java	2012-03-01 16:04:23 UTC (rev 12224)
+++ branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/unit/util/LinkedListTest.java	2012-03-01 16:04:29 UTC (rev 12225)
@@ -110,6 +110,76 @@
 
    }
 
+   public void testAddHeadAndRemove()
+   {
+      final AtomicInteger count = new AtomicInteger(0);
+      class MyObject
+      {
+
+         public int payload;
+
+         MyObject(int payloadcount)
+         {
+            count.incrementAndGet();
+            this.payload = payloadcount;
+         }
+
+         protected void finalize() throws Exception
+         {
+            count.decrementAndGet();
+         }
+         
+         public String toString()
+         {
+            return "" + payload;
+         }
+      };
+
+      LinkedListImpl<MyObject> objs = new LinkedListImpl<MyObject>();
+
+      // Initial add
+      for (int i = 1000; i >= 0; i--)
+      {
+         objs.addHead(new MyObject(i));
+      }
+      assertCount(1001, count);
+
+      LinkedListIterator<MyObject> iter = objs.iterator();
+
+      int countLoop = 0;
+      for (countLoop = 0 ; countLoop <= 1000; countLoop++)
+      {
+         MyObject obj = iter.next();
+         assertEquals(countLoop, obj.payload);
+         if (countLoop == 500 || countLoop == 1000)
+         {
+            iter.remove();
+         }
+      }
+      
+      iter.close();
+      
+      iter = objs.iterator();
+      
+      countLoop = 0;
+      while (iter.hasNext())
+      {
+         if (countLoop == 500 || countLoop == 1000)
+         {
+            System.out.println("Jumping " + countLoop);
+            countLoop++;
+         }
+         MyObject obj = iter.next();
+         assertEquals(countLoop, obj.payload);
+         countLoop++;
+      }
+      
+      
+      
+      assertCount(999, count);
+
+   }
+
    /**
     * @param count
     */



More information about the hornetq-commits mailing list