Initial load
diff --git a/test/java/util/Timer/Args.java b/test/java/util/Timer/Args.java
new file mode 100644
index 0000000..8e49ffc
--- /dev/null
+++ b/test/java/util/Timer/Args.java
@@ -0,0 +1,144 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6571655 6571881 6574585 6571297
+ * @summary Test various args to task scheduling methods
+ */
+
+import java.util.*;
+import java.util.concurrent.*;
+
+public class Args {
+ void schedule(final Timer t, final TimerTask task, final Date d) {
+ t.schedule(task, d);
+ THROWS(IllegalStateException.class,
+ new F(){void f(){ t.schedule(task, d); }});
+ }
+
+ void schedule(final Timer t, final TimerTask task, final Date d, final long period) {
+ t.schedule(task, d, period);
+ THROWS(IllegalStateException.class,
+ new F(){void f(){ t.schedule(task, d, period); }});
+ }
+
+ void scheduleAtFixedRate(final Timer t, final TimerTask task, final Date d, final long period) {
+ t.scheduleAtFixedRate(task, d, period);
+ THROWS(IllegalStateException.class,
+ new F(){void f(){ t.scheduleAtFixedRate(task, d, period); }});
+ }
+
+ TimerTask counter(final CountDownLatch latch) {
+ return new TimerTask() { public void run() {
+ check(latch.getCount() > 0);
+ latch.countDown();
+ }};
+ }
+
+ void test(String[] args) throws Throwable {
+ final Timer t = new Timer();
+ final TimerTask x = new TimerTask() { public void run() {}};
+ THROWS(IllegalArgumentException.class,
+ new F(){void f(){ t.schedule(x, -42); }},
+ new F(){void f(){ t.schedule(x, new Date(-42)); }},
+
+ new F(){void f(){ t.schedule(x, Long.MAX_VALUE); }},
+ new F(){void f(){ t.schedule(x, -42, 42); }},
+ new F(){void f(){ t.schedule(x, new Date(-42), 42); }},
+ new F(){void f(){ t.schedule(x, Long.MAX_VALUE, 42); }},
+ new F(){void f(){ t.schedule(x, 42, 0); }},
+ new F(){void f(){ t.schedule(x, new Date(42), 0); }},
+ new F(){void f(){ t.schedule(x, 42, -42); }},
+ new F(){void f(){ t.schedule(x, new Date(42), -42); }},
+
+ new F(){void f(){ t.scheduleAtFixedRate(x, -42, 42); }},
+ new F(){void f(){ t.scheduleAtFixedRate(x, new Date(-42), 42); }},
+ new F(){void f(){ t.scheduleAtFixedRate(x, Long.MAX_VALUE, 42); }},
+ new F(){void f(){ t.scheduleAtFixedRate(x, 42, 0); }},
+ new F(){void f(){ t.scheduleAtFixedRate(x, new Date(42), 0); }},
+ new F(){void f(){ t.scheduleAtFixedRate(x, 42, -42); }},
+ new F(){void f(){ t.scheduleAtFixedRate(x, new Date(42), -42); }}
+ );
+
+ THROWS(NullPointerException.class,
+ new F(){void f(){ t.schedule(null, 42); }},
+ new F(){void f(){ t.schedule(x, (Date)null); }},
+
+ new F(){void f(){ t.schedule(null, 42, 42); }},
+ new F(){void f(){ t.schedule(x, (Date)null, 42); }},
+
+ new F(){void f(){ t.scheduleAtFixedRate(null, 42, 42); }},
+ new F(){void f(){ t.scheduleAtFixedRate(x, (Date)null, 42); }}
+ );
+
+ final long start = System.currentTimeMillis();
+ final Date past = new Date(start - 10500);
+ final CountDownLatch y1 = new CountDownLatch(1);
+ final CountDownLatch y2 = new CountDownLatch(1);
+ final CountDownLatch y3 = new CountDownLatch(11);
+ schedule( t, counter(y1), past);
+ schedule( t, counter(y2), past, 1000);
+ scheduleAtFixedRate(t, counter(y3), past, 1000);
+ y3.await();
+ y1.await();
+ y2.await();
+ System.out.printf("elapsed=%d%n", System.currentTimeMillis() - start);
+ check(System.currentTimeMillis() - start < 500);
+
+ t.cancel();
+
+ THROWS(IllegalStateException.class,
+ new F(){void f(){ t.schedule(x, 42); }},
+ new F(){void f(){ t.schedule(x, past); }},
+ new F(){void f(){ t.schedule(x, 42, 42); }},
+ new F(){void f(){ t.schedule(x, past, 42); }},
+ new F(){void f(){ t.scheduleAtFixedRate(x, 42, 42); }},
+ new F(){void f(){ t.scheduleAtFixedRate(x, past, 42); }});
+
+ }
+
+ //--------------------- Infrastructure ---------------------------
+ volatile int passed = 0, failed = 0;
+ void pass() {passed++;}
+ void fail() {failed++; Thread.dumpStack();}
+ void fail(String msg) {System.err.println(msg); fail();}
+ void unexpected(Throwable t) {failed++; t.printStackTrace();}
+ void check(boolean cond) {if (cond) pass(); else fail();}
+ void equal(Object x, Object y) {
+ if (x == null ? y == null : x.equals(y)) pass();
+ else fail(x + " not equal to " + y);}
+ public static void main(String[] args) throws Throwable {
+ new Args().instanceMain(args);}
+ void instanceMain(String[] args) throws Throwable {
+ try {test(args);} catch (Throwable t) {unexpected(t);}
+ System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
+ if (failed > 0) throw new AssertionError("Some tests failed");}
+ abstract class F {abstract void f() throws Throwable;}
+ void THROWS(Class<? extends Throwable> k, F... fs) {
+ for (F f : fs)
+ try {f.f(); fail("Expected " + k.getName() + " not thrown");}
+ catch (Throwable t) {
+ if (k.isAssignableFrom(t.getClass())) pass();
+ else unexpected(t);}}
+}
diff --git a/test/java/util/Timer/KillThread.java b/test/java/util/Timer/KillThread.java
new file mode 100644
index 0000000..10ff6c7
--- /dev/null
+++ b/test/java/util/Timer/KillThread.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 1999 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4288198
+ * @summary Killing a Timer thread causes the Timer to fail silently on
+ * subsequent use.
+ */
+
+import java.util.*;
+
+public class KillThread {
+ public static void main (String[] args) throws Exception {
+ Timer t = new Timer();
+
+ // Start a mean event that kills the timer thread
+ t.schedule(new TimerTask() {
+ public void run() {
+ throw new ThreadDeath();
+ }
+ }, 0);
+
+ // Wait for mean event to do the deed and thread to die.
+ try {
+ Thread.sleep(100);
+ } catch(InterruptedException e) {
+ }
+
+ // Try to start another event
+ try {
+ // Timer thread is dead now
+ t.schedule(new TimerTask() {
+ public void run() {
+ }
+ }, 0);
+ throw new Exception("We failed silently");
+ } catch(IllegalStateException e) {
+ // Killing the Timer thread is equivalent to cancelling the Timer
+ }
+ }
+}
diff --git a/test/java/util/Timer/NameConstructors.java b/test/java/util/Timer/NameConstructors.java
new file mode 100644
index 0000000..3b4a6a0
--- /dev/null
+++ b/test/java/util/Timer/NameConstructors.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4279061
+ * @summary Basic test for constructors with thread name
+ */
+
+import java.util.*;
+
+public class NameConstructors {
+ private static final String NAME1 = "Norm D. Plume";
+ private static final String NAME2 = "Ann Onymous";
+
+ public static void main (String[] args) throws Exception {
+ Random rnd = new Random();
+ test(new Timer(NAME1), NAME1);
+ test(new Timer(NAME2, true), NAME2);
+ }
+
+ private static boolean done, passed;
+
+ public static void test(Timer timer, final String name) throws Exception {
+ done = passed = false;
+
+ TimerTask task = new TimerTask() {
+ public void run() {
+ passed = Thread.currentThread().getName().equals(name);
+ done = true;
+ }
+ };
+ timer.schedule(task, 0); // Immediate
+ Thread.sleep(500);
+ if (!(done && passed))
+ throw new RuntimeException(done + " : " + passed);
+ timer.cancel();
+ }
+}
diff --git a/test/java/util/Timer/Purge.java b/test/java/util/Timer/Purge.java
new file mode 100644
index 0000000..52556bf
--- /dev/null
+++ b/test/java/util/Timer/Purge.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4481072
+ * @summary Basic test for purge method
+ */
+
+import java.util.*;
+
+public class Purge {
+ public static void main (String[] args) {
+ Random rnd = new Random();
+ Timer timer = new Timer();
+ int cancelled = 0;
+ for (long i = 1; i <= 1000; i++) {
+ TimerTask task = new TimerTask() {
+ public void run() {
+ System.out.println("How come no one ever calls me?");
+ }
+ };
+ timer.schedule(task, i * 60*60*1000); // i hrs. hence.
+ if (i != 1 && rnd.nextBoolean()) {
+ task.cancel();
+ cancelled++;
+ }
+ }
+ int purged = timer.purge();
+ if (purged != cancelled)
+ throw new RuntimeException(purged + " != " + cancelled);
+ purged = timer.purge();
+ if (purged != 0)
+ throw new RuntimeException(purged + " nonzero");
+ timer.cancel();
+ }
+}