You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by va...@apache.org on 2006/11/14 07:19:15 UTC

svn commit: r474673 - /incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadGroupTest.java

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<MyThread> threads) {