From: <tr...@hy...> - 2010-05-12 00:47:11
|
Author: trader Date: 2010-05-11 17:20:43 -0700 (Tue, 11 May 2010) New Revision: 14589 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=14589 Modified: trunk/src/org/hyperic/util/file/DiskList.java trunk/unittest/src/org/hyperic/util/file/DiskListTest.java Log: HHQ-3980: related, but not a fix: add better logging, add unittest for concurrent iteration. No repro case found as of this checkin. Modified: trunk/src/org/hyperic/util/file/DiskList.java =================================================================== --- trunk/src/org/hyperic/util/file/DiskList.java 2010-05-11 19:19:38 UTC (rev 14588) +++ trunk/src/org/hyperic/util/file/DiskList.java 2010-05-12 00:20:43 UTC (rev 14589) @@ -572,7 +572,7 @@ } catch(IOException exc){ log.error("IOException while reading record"); if (log.isDebugEnabled()) { - log.debug(exc); + log.debug("IOException while trying to read record number " + this.curIdx, exc); } throw new NoSuchElementException("Error getting next " + "element: " + Modified: trunk/unittest/src/org/hyperic/util/file/DiskListTest.java =================================================================== --- trunk/unittest/src/org/hyperic/util/file/DiskListTest.java 2010-05-11 19:19:38 UTC (rev 14588) +++ trunk/unittest/src/org/hyperic/util/file/DiskListTest.java 2010-05-12 00:20:43 UTC (rev 14589) @@ -493,6 +493,75 @@ } } + public void testConcurrentIteration() throws Exception { + + DiskListDataHolder holder = null; + + try { + + try { + holder = new DiskListDataHolder(); + } catch (Exception e) { + e.printStackTrace(); + fail(e.toString()); + } + + for (long i = 0; i < MAXRECS; ++i) { + String toPut = String.valueOf(i); + holder.list.addToList(toPut); + } + + final int nThreads = 50; + IterationRunner[] threads = new IterationRunner[nThreads]; + + for (int i = 0; i < nThreads; ++i) { + threads[i] = new IterationRunner(holder.list.getListIterator()); + } + + for (int i = 0; i < nThreads; ++i) { + threads[i].start(); + } + + for (int i = 0; i < nThreads; ++i) { + threads[i].join(); + if (threads[i].getFailure() != null) { + threads[i].getFailure().printStackTrace(); + fail("Exception during iteration"); + } + } + + } finally { + + holder.dispose(); + + } + } + + private static class IterationRunner extends Thread { + + private Iterator it; + private Exception failure; + + IterationRunner(Iterator it) { + this.it = it; + this.failure = null; + } + + public void run() { + try { + while (it.hasNext()) { + it.next(); + } + } catch (Exception e) { + failure = e; + } + } + + Exception getFailure() { + return failure; + } + } + private static class DiskListDataHolder { DiskList list; File dataFile; |