Return-Path: Delivered-To: apmail-incubator-harmony-commits-archive@www.apache.org Received: (qmail 49460 invoked from network); 14 Nov 2006 06:19:47 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 14 Nov 2006 06:19:47 -0000 Received: (qmail 47325 invoked by uid 500); 14 Nov 2006 06:19:57 -0000 Delivered-To: apmail-incubator-harmony-commits-archive@incubator.apache.org Received: (qmail 47226 invoked by uid 500); 14 Nov 2006 06:19:57 -0000 Mailing-List: contact harmony-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: harmony-dev@incubator.apache.org Delivered-To: mailing list harmony-commits@incubator.apache.org Received: (qmail 47215 invoked by uid 99); 14 Nov 2006 06:19:57 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 13 Nov 2006 22:19:57 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 13 Nov 2006 22:19:46 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id D871B1A9846; Mon, 13 Nov 2006 22:19:15 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r474673 - /incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadGroupTest.java Date: Tue, 14 Nov 2006 06:19:15 -0000 To: harmony-commits@incubator.apache.org From: varlax@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061114061915.D871B1A9846@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: varlax Date: Mon Nov 13 22:19:15 2006 New Revision: 474673 URL: http://svn.apache.org/viewvc?view=rev&rev=474673 Log: Applied HARMONY-1955 [classlib][luni] org.apache.harmony.luni.tests.java.lang.ThreadGroupTest fails Tested on SUSE9 Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadGroupTest.java Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadGroupTest.java URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadGroupTest.java?view=diff&rev=474673&r1=474672&r2=474673 ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadGroupTest.java (original) +++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadGroupTest.java Mon Nov 13 22:19:15 2006 @@ -155,6 +155,8 @@ t1.join(); } catch (InterruptedException e) { } + // cleanup + tg.destroy(); } /** @@ -339,7 +341,6 @@ ThreadGroup testRoot = new ThreadGroup(originalCurrent, "Test group"); boolean passed = true; - passed = true; try { testRoot.setMaxPriority(Thread.MIN_PRIORITY); } catch (IllegalArgumentException iae) { @@ -450,7 +451,7 @@ // java.lang.Thread boolean result = wipeSideEffectThreads(originalCurrent); if (result == false) { - System.out.println("wipe threads in test_list() not successful"); + fail("wipe threads in test_list() not successful"); } final ThreadGroup testRoot = new ThreadGroup(originalCurrent, "Test group"); @@ -467,7 +468,6 @@ System.setOut(newOut); originalCurrent.list(); - byte[] contents = contentsStream.toByteArray(); /* * The output has to look like this @@ -477,15 +477,13 @@ * */ - boolean passed = verifyThreadList(originalCurrent, testRoot, - contents); - - assertTrue( - "Either 'list' is wrong or other tests are leaving side-effects.\n" - + "Result from list:\n " + "-----------------\n " - + new String(contents, 0, contents.length) - + "\n-----------------\n ", passed); - + String contents = new String(contentsStream.toByteArray()); + boolean passed = (contents.indexOf("ThreadGroup[name=main") != -1) && + (contents.indexOf("Thread[") != -1) && + (contents.indexOf("ThreadGroup[name=Test group") != -1); + assertTrue("'list()' does not print expected contents. " + + "Result from list: " + + contents, passed); // Do proper cleanup testRoot.destroy(); @@ -853,7 +851,22 @@ // We can't destroy a ThreadGroup if we do not make sure it has no // threads at all - + testRoot.stop(); + long waitTime = 5000; + for (int i = 0; i < threads.size(); i++) { + Thread t = threads.elementAt(i); + while (t.isAlive() && waitTime >= 0) { + try { + Thread.sleep(10); + waitTime -= 10; + } catch (InterruptedException e) { + fail("unexpected interruption"); + } + } + if (waitTime < 0) { + fail("stop() has not stopped threads in ThreadGroup 'testRoot'"); + } + } // Make sure we cleanup before returning from the method testRoot.destroy(); } @@ -1314,29 +1327,6 @@ asyncBuildRandomTreeUnder(aGroup, depth, result); return result; - } - - private boolean verifyThreadList(ThreadGroup root, - ThreadGroup onlyChildGroup, byte[] listOutput) { - // We expect that @root has only 1 subgroup, @onlyChildGroup. The - // output from method 'list' is stored in @listOutput - if (listOutput.length == 0) { - return false; - } - - // If we got a long output, it means some previous test must have left - // side-effects (more subgroups and threads); - final int MAX_SIZE = 200; - if (listOutput.length > MAX_SIZE) { - return false; - } - - // Here we compare actual result to expected result - - // Due to extremely weak API in String, comparing substrings, etc would - // take too much work at this time. - // We defer the actual implementation for now. - return true; } private boolean allSuspended(Vector threads) {