From: <tho...@us...> - 2011-06-01 16:50:53
|
Revision: 4592 http://bigdata.svn.sourceforge.net/bigdata/?rev=4592&view=rev Author: thompsonbry Date: 2011-06-01 16:50:47 +0000 (Wed, 01 Jun 2011) Log Message: ----------- Added CI check for unclosed TemporaryRawStores Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/journal/TemporaryRawStore.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/journal/TestHelper.java Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/journal/TemporaryRawStore.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/journal/TemporaryRawStore.java 2011-06-01 16:41:13 UTC (rev 4591) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/journal/TemporaryRawStore.java 2011-06-01 16:50:47 UTC (rev 4592) @@ -32,6 +32,7 @@ import java.io.Serializable; import java.nio.ByteBuffer; import java.util.UUID; +import java.util.concurrent.atomic.AtomicInteger; import org.apache.log4j.Logger; @@ -96,6 +97,20 @@ private final long createTime; /** + * The #of open {@link TemporaryRawStore}s (JVM wide). This is package + * private. It is used to chase down unit tests which are not closing() the + * store. + */ + final static AtomicInteger nopen = new AtomicInteger(); + + /** + * The #of closed {@link TemporaryRawStore}s (JVM wide). This is package + * private. It is used to chase down unit tests which are not + * {@link #close() closing} the store. + */ + final static AtomicInteger nclose = new AtomicInteger(); + + /** * Return an empty {@link File} created using the temporary file name * mechanism. The file name will begin with <code>bigdata</code> and end * with <code>.tmp</code>. The file is marked for eventual deletion. @@ -293,6 +308,8 @@ // Long.valueOf(Options.DEFAULT_MINIMUM_EXTENSION), md); + nopen.incrementAndGet(); + } /** @@ -354,6 +371,8 @@ buf.destroy(); + nclose.incrementAndGet(); + } finally { // if (writeCache != null) { Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/journal/TestHelper.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/journal/TestHelper.java 2011-06-01 16:41:13 UTC (rev 4591) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/journal/TestHelper.java 2011-06-01 16:50:47 UTC (rev 4592) @@ -109,10 +109,49 @@ } + checkTempStoresClosed(test, testClass); + // Also check the direct buffer pools. DirectBufferPoolTestHelper.checkBufferPools(test, testClass); } + /** + * Verify that any {@link TemporaryRawStore}s created by the test have been + * destroyed. + * <p> + * Note: This clears the counter as a side effect to prevent a cascade of + * tests from being failed. + * + * @param test + * The unit test instance. + * @param testClass + * The instance of the delegate test class for a proxy test + * suite. For example, TestWORMStrategy. + */ + private static void checkTempStoresClosed(final TestCase test, + final TestCase testClass) { + + final int nopen = TemporaryRawStore.nopen.getAndSet(0); + final int nclose = TemporaryRawStore.nclose.getAndSet(0); + + if (nopen != nclose) { + + /* + * At least one temporary store was opened which was never closed. + */ + + Assert.fail("Test did not close temp store(s)"// + + ": nopen=" + nopen // + + ", nclose=" + nclose// + + ", test=" + test.getClass() + "." + test.getName()// + + (testClass == null ? "" : ", testClass=" + + testClass.getClass().getName())// + ); + + } + + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |