From: <tho...@us...> - 2011-06-10 00:16:09
|
Revision: 4682 http://bigdata.svn.sourceforge.net/bigdata/?rev=4682&view=rev Author: thompsonbry Date: 2011-06-10 00:16:02 +0000 (Fri, 10 Jun 2011) Log Message: ----------- Disabled the aspect of the thread-check logic at test tear down which was throwing an exception. It will just log @ ERROR immediately if there are any threads which were not properly terminated. I also moved the wait (for up to 2 seconds) for threads to terminate after the log @ ERROR. My thinking is that waiting might make the initial conditions for the next test cleaner, but it does not excuse the current test from failing to terminate its threads. Finally, I modified the message to include the test name (getName()) and the delegate class (getOurDelegate()). I will note that the information coming out of the thread-check logic is not yet very good. For example, you can see in this message that it is complaining about the main thread! ERROR: 8687 main com.bigdata.journal.ProxyTestCase.tearDown(ProxyTestCase.java:182): Threads left active after task: test=test_registerAndUse, delegate=com.bigdata.journal.TestWORMStrategy, startupCount=3, teardownCount=4, threads: Thread name=main Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/journal/ProxyTestCase.java branches/QUADS_QUERY_BRANCH/bigdata-jini/src/test/com/bigdata/zookeeper/TestZLockImpl.java Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/journal/ProxyTestCase.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/journal/ProxyTestCase.java 2011-06-09 22:09:30 UTC (rev 4681) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/journal/ProxyTestCase.java 2011-06-10 00:16:02 UTC (rev 4682) @@ -143,44 +143,62 @@ * an entire suite of tests.) */ - int startupActiveThreads = 0; + private int startupActiveThreads = 0; + public void setUp() throws Exception { - startupActiveThreads = Thread.currentThread().getThreadGroup().activeCount(); + + startupActiveThreads = Thread.currentThread().getThreadGroup().activeCount(); getOurDelegate().setUp(this); + } - static boolean s_checkThreads = true; + private static boolean s_checkThreads = true; + public void tearDown() throws Exception { + getOurDelegate().tearDown(this); if (s_checkThreads) { + final ThreadGroup grp = Thread.currentThread().getThreadGroup(); - int tearDownActiveThreads = grp.activeCount(); + final int tearDownActiveThreads = grp.activeCount(); if (startupActiveThreads != tearDownActiveThreads) { final Thread[] threads = new Thread[tearDownActiveThreads]; grp.enumerate(threads); final StringBuilder info = new StringBuilder(); + boolean first = true; for(Thread t: threads) { - info.append(t.getName() + "\n"); + if(!first) + info.append(','); + // Note: t.getName() can return [null]! + info.append("[" + t.getName() + "]"); + first = false; } - String failMessage = "Threads left active after task, startupCount: " - + startupActiveThreads - + ", teardownCount: " + tearDownActiveThreads + final String failMessage = "Threads left active after task" + +": test=" + getName()// + + ", delegate="+getOurDelegate().getClass().getName() + + ", startupCount=" + startupActiveThreads + + ", teardownCount=" + tearDownActiveThreads + + ", thisThread="+Thread.currentThread().getName() + ", threads: " + info; - // Wait upto 2 seconds for threads to die off + + if (grp.activeCount() != startupActiveThreads) + log.error(failMessage); + + /* + * Wait up to 2 seconds for threads to die off so the next test + * will run more cleanly. + */ for (int i = 0; i < 20; i++) { - Thread.currentThread().sleep(100); + Thread.sleep(100); if (grp.activeCount() != startupActiveThreads) break; } - - if (grp.activeCount() != startupActiveThreads) - fail(failMessage); - else - log.warn(failMessage); + } + } super.tearDown(); Modified: branches/QUADS_QUERY_BRANCH/bigdata-jini/src/test/com/bigdata/zookeeper/TestZLockImpl.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-jini/src/test/com/bigdata/zookeeper/TestZLockImpl.java 2011-06-09 22:09:30 UTC (rev 4681) +++ branches/QUADS_QUERY_BRANCH/bigdata-jini/src/test/com/bigdata/zookeeper/TestZLockImpl.java 2011-06-10 00:16:02 UTC (rev 4682) @@ -160,7 +160,8 @@ final int n = zookeeper.getChildren(zpath, false).size(); - log.info("nchildren=" + n); + if(log.isInfoEnabled()) + log.info("nchildren=" + n); if (n == 2) break; @@ -224,13 +225,13 @@ final Thread mainThread = Thread.currentThread(); - // a node that is guarenteed to be unique w/in the test namespace. + // a node that is guaranteed to be unique w/in the test namespace. final String zpath = "/test/" + getName() + UUID.randomUUID(); try { /* * verify no such node (should be unique and therefore not - * preexist). + * pre-exist). */ zookeeper.getChildren(zpath, false); fail("zpath exists: " + zpath); @@ -303,11 +304,18 @@ // break the lock. { + final String z = zpath + "/" + ((ZLockImpl) lock1).getLockRequestZNode(); - log.info("breaking lock: deleting " + z); + + if (log.isInfoEnabled()) + log.info("breaking lock: deleting " + z); + zookeeper.delete(z, -1/* version */); - log.info("broke lock: deleted " + z); + + if (log.isInfoEnabled()) + log.info("broke lock: deleted " + z); + } assertTrue(!lock1.isLockHeld()); @@ -375,7 +383,7 @@ public void test_sessionExpiredBeforeLockRequest() throws IOException, KeeperException, InterruptedException { - // a node that is guarenteed to be unique w/in the test namespace. + // a node that is guaranteed to be unique w/in the test namespace. final String zpath = "/test/" + getName() + UUID.randomUUID(); expireSession(zookeeper); @@ -426,7 +434,7 @@ public void test_sessionExpiredWhileHoldingLock() throws IOException, KeeperException, InterruptedException { - // a node that is guarenteed to be unique w/in the test namespace. + // a node that is guaranteed to be unique w/in the test namespace. final String zpath = "/test/" + getName() + UUID.randomUUID(); // obtain a lock object. @@ -475,7 +483,7 @@ public void test_destroyLock() throws KeeperException, InterruptedException, ExecutionException { - // a node that is guarenteed to be unique w/in the test namespace. + // a node that is guaranteed to be unique w/in the test namespace. final String zpath = "/test/" + getName() + UUID.randomUUID(); final int ntasks = 4; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |