jdk/test/java/util/concurrent/ScheduledThreadPoolExecutor/DelayOverflow.java
author dl
Mon, 02 Nov 2009 17:25:38 -0800
changeset 4110 ac033ba6ede4
parent 1007 72a8a27e1d69
child 5506 202f599c92aa
permissions -rw-r--r--
6865582: jsr166y - jsr166 maintenance update 6865571: Add a lightweight task framework known as ForkJoin 6445158: Phaser - an improved CyclicBarrier 6865579: Add TransferQueue/LinkedTransferQueue Reviewed-by: martin, chegar, dice
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1007
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
     1
/*
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
     3
 *
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
     6
 * published by the Free Software Foundation.
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
     7
 *
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
     8
 * This code is distributed in the hope that it will be useful, but WITHOUT
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
     9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    10
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    11
 * version 2 for more details (a copy is included in the LICENSE file that
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    12
 * accompanied this code).
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    13
 *
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License version
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    15
 * 2 along with this work; if not, write to the Free Software Foundation,
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    16
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    17
 *
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    18
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    19
 * CA 95054 USA or visit www.sun.com if you need additional information or
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    20
 * have any questions.
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    21
 */
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    22
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    23
/*
4110
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 1007
diff changeset
    24
 * This file is available under and governed by the GNU General Public
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 1007
diff changeset
    25
 * License version 2 only, as published by the Free Software Foundation.
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 1007
diff changeset
    26
 * However, the following notice accompanied the original version of this
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 1007
diff changeset
    27
 * file:
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 1007
diff changeset
    28
 *
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 1007
diff changeset
    29
 * Written by Doug Lea with assistance from members of JCP JSR-166
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 1007
diff changeset
    30
 * Expert Group and released to the public domain, as explained at
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 1007
diff changeset
    31
 * http://creativecommons.org/licenses/publicdomain
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 1007
diff changeset
    32
 */
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 1007
diff changeset
    33
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 1007
diff changeset
    34
/*
1007
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    35
 * @test
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    36
 * @bug 6725789
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    37
 * @summary Check for long overflow in task time comparison.
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    38
 */
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    39
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    40
import java.util.concurrent.*;
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    41
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    42
public class DelayOverflow {
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    43
    static void waitForNanoTimeTick() {
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    44
        for (long t0 = System.nanoTime(); t0 == System.nanoTime(); )
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    45
            ;
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    46
    }
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    47
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    48
    void scheduleNow(ScheduledThreadPoolExecutor pool,
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    49
                     Runnable r, int how) {
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    50
        switch (how) {
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    51
        case 0:
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    52
            pool.schedule(r, 0, TimeUnit.MILLISECONDS);
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    53
            break;
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    54
        case 1:
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    55
            pool.schedule(Executors.callable(r), 0, TimeUnit.DAYS);
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    56
            break;
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    57
        case 2:
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    58
            pool.scheduleWithFixedDelay(r, 0, 1000, TimeUnit.NANOSECONDS);
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    59
            break;
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    60
        case 3:
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    61
            pool.scheduleAtFixedRate(r, 0, 1000, TimeUnit.MILLISECONDS);
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    62
            break;
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    63
        default:
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    64
            fail(String.valueOf(how));
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    65
        }
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    66
    }
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    67
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    68
    void scheduleAtTheEndOfTime(ScheduledThreadPoolExecutor pool,
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    69
                                Runnable r, int how) {
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    70
        switch (how) {
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    71
        case 0:
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    72
            pool.schedule(r, Long.MAX_VALUE, TimeUnit.MILLISECONDS);
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    73
            break;
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    74
        case 1:
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    75
            pool.schedule(Executors.callable(r), Long.MAX_VALUE, TimeUnit.DAYS);
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    76
            break;
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    77
        case 2:
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    78
            pool.scheduleWithFixedDelay(r, Long.MAX_VALUE, 1000, TimeUnit.NANOSECONDS);
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    79
            break;
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    80
        case 3:
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    81
            pool.scheduleAtFixedRate(r, Long.MAX_VALUE, 1000, TimeUnit.MILLISECONDS);
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    82
            break;
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    83
        default:
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    84
            fail(String.valueOf(how));
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    85
        }
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    86
    }
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    87
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    88
    /**
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    89
     * Attempts to test exhaustively and deterministically, all 20
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    90
     * possible ways that one task can be scheduled in the maximal
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    91
     * distant future, while at the same time an existing tasks's time
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    92
     * has already expired.
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    93
     */
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    94
    void test(String[] args) throws Throwable {
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    95
        for (int nowHow = 0; nowHow < 4; nowHow++) {
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    96
            for (int thenHow = 0; thenHow < 4; thenHow++) {
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    97
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    98
                final ScheduledThreadPoolExecutor pool
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
    99
                    = new ScheduledThreadPoolExecutor(1);
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   100
                final CountDownLatch runLatch     = new CountDownLatch(1);
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   101
                final CountDownLatch busyLatch    = new CountDownLatch(1);
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   102
                final CountDownLatch proceedLatch = new CountDownLatch(1);
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   103
                final Runnable notifier = new Runnable() {
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   104
                        public void run() { runLatch.countDown(); }};
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   105
                final Runnable neverRuns = new Runnable() {
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   106
                        public void run() { fail(); }};
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   107
                final Runnable keepPoolBusy = new Runnable() {
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   108
                        public void run() {
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   109
                            try {
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   110
                                busyLatch.countDown();
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   111
                                proceedLatch.await();
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   112
                            } catch (Throwable t) { unexpected(t); }
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   113
                        }};
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   114
                pool.schedule(keepPoolBusy, 0, TimeUnit.SECONDS);
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   115
                busyLatch.await();
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   116
                scheduleNow(pool, notifier, nowHow);
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   117
                waitForNanoTimeTick();
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   118
                scheduleAtTheEndOfTime(pool, neverRuns, thenHow);
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   119
                proceedLatch.countDown();
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   120
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   121
                check(runLatch.await(10L, TimeUnit.SECONDS));
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   122
                equal(runLatch.getCount(), 0L);
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   123
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   124
                pool.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   125
                pool.shutdown();
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   126
            }
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   127
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   128
            final int nowHowCopy = nowHow;
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   129
            final ScheduledThreadPoolExecutor pool
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   130
                = new ScheduledThreadPoolExecutor(1);
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   131
            final CountDownLatch runLatch = new CountDownLatch(1);
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   132
            final Runnable notifier = new Runnable() {
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   133
                    public void run() { runLatch.countDown(); }};
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   134
            final Runnable scheduleNowScheduler = new Runnable() {
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   135
                    public void run() {
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   136
                        try {
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   137
                            scheduleNow(pool, notifier, nowHowCopy);
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   138
                            waitForNanoTimeTick();
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   139
                        } catch (Throwable t) { unexpected(t); }
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   140
                    }};
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   141
            pool.scheduleWithFixedDelay(scheduleNowScheduler,
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   142
                                        0, Long.MAX_VALUE,
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   143
                                        TimeUnit.NANOSECONDS);
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   144
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   145
            check(runLatch.await(10L, TimeUnit.SECONDS));
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   146
            equal(runLatch.getCount(), 0L);
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   147
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   148
            pool.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   149
            pool.shutdown();
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   150
        }
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   151
    }
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   152
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   153
    //--------------------- Infrastructure ---------------------------
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   154
    volatile int passed = 0, failed = 0;
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   155
    void pass() {passed++;}
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   156
    void fail() {failed++; Thread.dumpStack();}
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   157
    void fail(String msg) {System.err.println(msg); fail();}
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   158
    void unexpected(Throwable t) {failed++; t.printStackTrace();}
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   159
    void check(boolean cond) {if (cond) pass(); else fail();}
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   160
    void equal(Object x, Object y) {
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   161
        if (x == null ? y == null : x.equals(y)) pass();
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   162
        else fail(x + " not equal to " + y);}
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   163
    public static void main(String[] args) throws Throwable {
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   164
        Class<?> k = new Object(){}.getClass().getEnclosingClass();
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   165
        try {k.getMethod("instanceMain",String[].class)
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   166
                .invoke( k.newInstance(), (Object) args);}
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   167
        catch (Throwable e) {throw e.getCause();}}
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   168
    public void instanceMain(String[] args) throws Throwable {
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   169
        try {test(args);} catch (Throwable t) {unexpected(t);}
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   170
        System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   171
        if (failed > 0) throw new AssertionError("Some tests failed");}
72a8a27e1d69 6725789: ScheduledExecutorService does not work as expected in jdk7/6/5
dl
parents:
diff changeset
   172
}