Remove tests for deprecated Thread API we don't implement.
Change-Id: I22f6d93cc1e26a479cbf58ddd243d5ffdfe827ec
diff --git a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/ThreadGroupTest.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/ThreadGroupTest.java
index 7ac69e9..d4cac1f 100644
--- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/ThreadGroupTest.java
+++ b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/ThreadGroupTest.java
@@ -472,87 +472,6 @@
}
/**
- * @tests java.lang.ThreadGroup#resume()
- */
- @SuppressWarnings("deprecation")
- public void test_resume() throws OutOfMemoryError {
- // Test for method void java.lang.ThreadGroup.resume()
-
- final ThreadGroup originalCurrent = getInitialThreadGroup();
-
- final ThreadGroup testRoot = new ThreadGroup(originalCurrent,
- "Test group");
- final int DEPTH = 2;
- buildRandomTreeUnder(testRoot, DEPTH);
-
- final int THREADS_PER_GROUP = 2;
- final Vector<MyThread> threads = populateGroupsWithThreads(testRoot,
- THREADS_PER_GROUP);
-
- boolean[] isResumed = null;
- try {
- try {
- for (int i = 0; i < threads.size(); i++) {
- Thread t = threads.elementAt(i);
- t.start();
- t.suspend();
- }
- // In 5.0, activeCount() only returns threads that are alive
- assertTrue("Internal error when populating ThreadGroups", testRoot
- .activeCount() == threads.size());
- } catch (OutOfMemoryError e) {
- for (int i = 0; i < threads.size(); i++) {
- Thread t = threads.elementAt(i);
- t.resume();
- t.stop(); // deprecated but effective
- }
- throw e;
- }
-
- // Now that they are all suspended, let's resume the ThreadGroup
- testRoot.resume();
-
- // Give them some time to really resume
- try {
- Thread.sleep(500);
- } catch (InterruptedException ie) {
- fail("Should not have been interrupted");
- }
-
- isResumed = new boolean[threads.size()];
- boolean failed = false;
- for (int i = 0; i < isResumed.length; i++) {
- MyThread t = threads.elementAt(i);
- if (!failed) { // if one failed, don't waste time checking the
- // rest
- isResumed[i] = t.isActivelyRunning(1000);
- failed = failed | (!isResumed[i]);
- }
- t.stop(); // deprecated but effective
- }
-
- // Give them some time to really die
- try {
- Thread.sleep(500);
- } catch (InterruptedException ie) {
- fail("Should not have been interrupted");
- }
- } finally {
- // Make sure we do cleanup before returning
- testRoot.destroy();
- }
-
- for (int i = 0; i < isResumed.length; i++) {
- assertTrue("Thread " + threads.elementAt(i)
- + " was not running when it was killed", isResumed[i]);
- }
-
- assertEquals("Method destroy must have problems",
- 0, testRoot.activeCount());
-
- }
-
- /**
* @tests java.lang.ThreadGroup#setDaemon(boolean)
*/
public void test_setDaemonZ() {
@@ -681,177 +600,6 @@
}
/**
- * @tests java.lang.ThreadGroup#stop()
- */
- @SuppressWarnings("deprecation")
- public void test_stop() throws OutOfMemoryError {
- // Test for method void java.lang.ThreadGroup.stop()
-
- final ThreadGroup originalCurrent = getInitialThreadGroup();
-
- final ThreadGroup testRoot = new ThreadGroup(originalCurrent,
- "Test group");
- final int DEPTH = 2;
- buildRandomTreeUnder(testRoot, DEPTH);
-
- final int THREADS_PER_GROUP = 2;
- final Vector<MyThread> threads = populateGroupsWithThreads(testRoot,
- THREADS_PER_GROUP);
-
- try {
- for (int i = 0; i < threads.size(); i++) {
- Thread t = threads.elementAt(i);
- t.start();
- }
- } catch (OutOfMemoryError e) {
- for (int i = 0; i < threads.size(); i++) {
- Thread t = threads.elementAt(i);
- t.stop(); // deprecated but effective
- }
- throw e;
- }
-
- // Now that they are all running, let's stop the ThreadGroup
- testRoot.stop();
-
- // stop is an async call. The thread may take a while to stop. We have
- // to wait for all of them to stop. However, if stop does not work,
- // we'd have to wait forever. So, we wait with a timeout, and if the
- // Thread is still alive, we assume stop for ThreadGroups does not
- // work. How much we wait (timeout) is very important
- boolean passed = true;
- for (int i = 0; i < threads.size(); i++) {
- Thread t = threads.elementAt(i);
- try {
- // We wait 5000 ms per Thread, but due to scheduling it may
- // take a while to run
- t.join(5000);
- } catch (InterruptedException ie) {
- fail("Should not be interrupted");
- }
- if (t.isAlive()) {
- passed = false;
- break;
- }
- }
-
- // To make sure that even if we fail, we exit in a clean state
- testRoot.destroy();
-
- assertTrue("Thread should be dead by now", passed);
-
- assertEquals("Method destroy (or wipeAllThreads) must have problems",
- 0, testRoot.activeCount());
-
- }
-
- /**
- * @tests java.lang.ThreadGroup#suspend()
- */
- @SuppressWarnings("deprecation")
- public void test_suspend() throws OutOfMemoryError {
- // Test for method void java.lang.ThreadGroup.suspend()
-
- final ThreadGroup originalCurrent = getInitialThreadGroup();
-
- final ThreadGroup testRoot = new ThreadGroup(originalCurrent,
- "Test group");
- final int DEPTH = 2;
- buildRandomTreeUnder(testRoot, DEPTH);
-
- final int THREADS_PER_GROUP = 2;
- final Vector<MyThread> threads = populateGroupsWithThreads(testRoot,
- THREADS_PER_GROUP);
-
- boolean passed = false;
- try {
- try {
- for (int i = 0; i < threads.size(); i++) {
- Thread t = threads.elementAt(i);
- t.start();
- }
- } catch (OutOfMemoryError e) {
- for (int i = 0; i < threads.size(); i++) {
- Thread t = threads.elementAt(i);
- t.stop(); // deprecated but effective
- }
- throw e;
- }
-
- // Now that they are all running, let's suspend the ThreadGroup
- testRoot.suspend();
-
- passed = allSuspended(threads);
- assertTrue("Should be able to wipe all threads (allSuspended="
- + passed + ")", wipeAllThreads(testRoot));
- } finally {
-
- // 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();
- }
- assertTrue("All threads should be suspended", passed);
-
- assertEquals("Method destroy (or wipeAllThreads) must have problems",
- 0, testRoot.activeCount());
-
- }
-
- /**
- * @tests java.lang.ThreadGroup#toString()
- */
- public void test_toString() {
- // Test for method java.lang.String java.lang.ThreadGroup.toString()
-
- final ThreadGroup originalCurrent = getInitialThreadGroup();
- final String tGroupName = "Test group";
-
- // Our own subclass
- class MyThreadGroup extends ThreadGroup {
- // Have to define a constructor since there's no default one
- public MyThreadGroup(ThreadGroup parent, String name) {
- super(parent, name);
- }
- }
- ;
-
- ThreadGroup testRoot = new MyThreadGroup(originalCurrent, tGroupName);
- final String toString = testRoot.toString();
-
- StringBuffer expectedResult = new StringBuffer();
- expectedResult.append(testRoot.getClass().getName());
- expectedResult.append("[name=");
- expectedResult.append(tGroupName);
- expectedResult.append(",maxpri=");
- expectedResult.append(testRoot.getMaxPriority());
- expectedResult.append("]");
-
- String expectedValue = expectedResult.toString();
-
- assertTrue("toString does not follow the Java language spec.", toString
- .equals(expectedValue));
-
- testRoot.destroy();
- }
-
- /**
* @tests java.lang.ThreadGroup#uncaughtException(java.lang.Thread,
* java.lang.Throwable)
*/
@@ -897,43 +645,6 @@
}
};
- // Test if a Thread tells its ThreadGroup about ThreadDeath
- thread = new Thread(testRoot, null, "victim thread (to be killed)") {
- @Override
- public void run() {
- while (true) {
- Thread.yield();
- }
- }
- };
- thread.start();
- try {
- Thread.sleep(1000);
- } catch (InterruptedException ie) {
- fail("Should not have been interrupted");
- }
- // we know this is deprecated, but we must test this scenario.
- // When we stop a thread, it is tagged as not alive even though it is
- // still running code.
- // join would be a no-op, and we might have a race condition. So, to
- // play safe, we wait before joining & testing if the exception was
- // really forwarded to the ThreadGroup
- thread.stop();
- try {
- Thread.sleep(1000);
- } catch (InterruptedException ie) {
- fail("Should not have been interrupted");
- }
- try {
- thread.join();
- } catch (InterruptedException ie) {
- fail("Should not have been interrupted");
- }
- testRoot.destroy();
- assertTrue(
- "Any thread should notify its ThreadGroup about its own death, even if killed:"
- + testRoot, passed[TEST_KILLING]);
-
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - - - - - -
testRoot = new ThreadGroup(originalCurrent,