From: <tr...@hy...> - 2009-12-22 21:55:53
|
Author: trader Date: 2009-12-22 13:55:42 -0800 (Tue, 22 Dec 2009) New Revision: 14114 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=14114 Modified: trunk/unittest/src/org/hyperic/util/file/DiskListTest.java Log: Two new test cases, both initially pass Modified: trunk/unittest/src/org/hyperic/util/file/DiskListTest.java =================================================================== --- trunk/unittest/src/org/hyperic/util/file/DiskListTest.java 2009-12-22 20:52:41 UTC (rev 14113) +++ trunk/unittest/src/org/hyperic/util/file/DiskListTest.java 2009-12-22 21:55:42 UTC (rev 14114) @@ -154,6 +154,107 @@ } } + public void testFillAndDeleteAllAndReopen() throws Exception { + + DiskListDataHolder holder = null; + + try { + + try { + holder = new DiskListDataHolder(); + } catch (Exception e) { + e.printStackTrace(); + fail(e.toString()); + } + + String toPut = String.valueOf("dummystring"); + + // Insert until we *almost* spill over + while (holder.list.dataFile.length() < MAXSIZE) { + holder.list.addToList(toPut); + } + + // Iterate and delete + Iterator it = holder.list.getListIterator(); + while (it.hasNext()) { + it.next(); + it.remove(); + } + + holder.list.close(); + + // Check that we can read the proper number after close/reopen, and that they can be cleanly deleted + holder.list = new DiskList(holder.dataFile, + RECSIZE, + CHKSIZE, + CHKPERC, + MAXSIZE); + + it = holder.list.getListIterator(); + // This is current behavior, but bad behavior + assertNull(it); + + } finally { + + holder.dispose(); + + } + } + + public void testFillAndDeleteAllButLastAndReopen() throws Exception { + + DiskListDataHolder holder = null; + + try { + + try { + holder = new DiskListDataHolder(); + } catch (Exception e) { + e.printStackTrace(); + fail(e.toString()); + } + + String toPut = String.valueOf("dummystring"); + + // Insert until we *almost* spill over + long nRecs = 0; + while (holder.list.dataFile.length() < MAXSIZE) { + holder.list.addToList(toPut); + nRecs++; + } + + // Iterate and delete all but the last record. By not deleting the last record, + // we prevent maintenance from happening. + Iterator it = holder.list.getListIterator(); + long nDeleted = 0; + while (it.hasNext()) { + it.next(); + if (++nDeleted < nRecs) { + it.remove(); + } + } + + holder.list.close(); + + // Check that we can read the proper number after close/reopen, and that they can be cleanly deleted + holder.list = new DiskList(holder.dataFile, + RECSIZE, + CHKSIZE, + CHKPERC, + MAXSIZE); + + it = holder.list.getListIterator(); + while (it.hasNext()) { + it.next(); + } + + } finally { + + holder.dispose(); + + } + } + public void testFreeListWithInsertsAndNoDeletes() throws Exception { DiskListDataHolder holder = null; |