jdk/test/java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java
author ohair
Tue, 28 Dec 2010 15:53:50 -0800
changeset 7668 d4a77089c587
parent 7518 0282db800fe1
child 24692 268fbc344d53
permissions -rw-r--r--
6962318: Update copyright year Reviewed-by: xdono
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 7518
diff changeset
     2
 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 6450200
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Test proper handling of pool state changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @run main/othervm ConfigChanges
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * @author Martin Buchholz
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.concurrent.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.concurrent.atomic.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import static java.util.concurrent.TimeUnit.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
public class ConfigChanges {
7518
0282db800fe1 7003745: Code style cleanups (sync from Dougs CVS)
dl
parents: 5506
diff changeset
    39
    static final ThreadGroup tg = new ThreadGroup("pool");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
7518
0282db800fe1 7003745: Code style cleanups (sync from Dougs CVS)
dl
parents: 5506
diff changeset
    41
    static final Random rnd = new Random();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    static void report(ThreadPoolExecutor tpe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
            System.out.printf(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
                "active=%d submitted=%d completed=%d queued=%d sizes=%d/%d/%d%n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
                tg.activeCount(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
                tpe.getTaskCount(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
                tpe.getCompletedTaskCount(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
                tpe.getQueue().size(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
                tpe.getPoolSize(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
                tpe.getCorePoolSize(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
                tpe.getMaximumPoolSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        } catch (Throwable t) { unexpected(t); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    static void report(String label, ThreadPoolExecutor tpe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        System.out.printf("%10s ", label);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        report(tpe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    static class PermissiveSecurityManger extends SecurityManager {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        public void checkPermission(Permission p) { /* bien sur, Monsieur */ }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    static void checkShutdown(final ExecutorService es) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        final Runnable nop = new Runnable() {public void run() {}};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            if (new Random().nextBoolean()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                check(es.isShutdown());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                if (es instanceof ThreadPoolExecutor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                    check(((ThreadPoolExecutor) es).isTerminating()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                          || es.isTerminated());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                THROWS(RejectedExecutionException.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                       new Fun() {void f() {es.execute(nop);}});
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        } catch (Throwable t) { unexpected(t); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    static void checkTerminated(final ThreadPoolExecutor tpe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            checkShutdown(tpe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            check(tpe.getQueue().isEmpty());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            check(tpe.isTerminated());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            check(! tpe.isTerminating());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            equal(tpe.getActiveCount(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            equal(tpe.getPoolSize(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            equal(tpe.getTaskCount(), tpe.getCompletedTaskCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            check(tpe.awaitTermination(0, SECONDS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        } catch (Throwable t) { unexpected(t); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    static Runnable waiter(final CyclicBarrier barrier) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        return new Runnable() { public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            try { barrier.await(); barrier.await(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            catch (Throwable t) { unexpected(t); }}};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    static volatile Runnable runnableDuJour;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    private static void realMain(String[] args) throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        if (rnd.nextBoolean())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            System.setSecurityManager(new PermissiveSecurityManger());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        final boolean prestart = rnd.nextBoolean();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        final Thread.UncaughtExceptionHandler handler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            = new Thread.UncaughtExceptionHandler() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                    public void uncaughtException(Thread t, Throwable e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                        check(! Thread.currentThread().isInterrupted());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                        unexpected(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                    }};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        final int n = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        final ThreadPoolExecutor tpe
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            = new ThreadPoolExecutor(n, 3*n,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                                     3L, MINUTES,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                                     new ArrayBlockingQueue<Runnable>(3*n));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        tpe.setThreadFactory(new ThreadFactory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                public Thread newThread(Runnable r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                    Thread t = new Thread(tg, r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                    t.setUncaughtExceptionHandler(handler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                    return t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        if (prestart) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            tpe.prestartAllCoreThreads();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            equal(tg.activeCount(), n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            equal(tg.activeCount(), tpe.getCorePoolSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        final Runnable runRunnableDuJour =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            new Runnable() { public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                // Delay choice of action till last possible moment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                runnableDuJour.run(); }};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        final CyclicBarrier pumpedUp = new CyclicBarrier(3*n + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        runnableDuJour = waiter(pumpedUp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        if (prestart) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            for (int i = 0; i < 1*n; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                tpe.execute(runRunnableDuJour);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            // Wait for prestarted threads to dequeue their initial tasks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            while (! tpe.getQueue().isEmpty())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                Thread.sleep(10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            for (int i = 0; i < 5*n; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                tpe.execute(runRunnableDuJour);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            for (int i = 0; i < 6*n; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                tpe.execute(runRunnableDuJour);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        //report("submitted", tpe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        pumpedUp.await();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        equal(tg.activeCount(), 3*n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        equal(tg.activeCount(), tpe.getMaximumPoolSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        equal(tpe.getCorePoolSize(), n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        //report("pumped up", tpe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        equal(tpe.getMaximumPoolSize(), 3*n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        tpe.setMaximumPoolSize(4*n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        equal(tpe.getMaximumPoolSize(), 4*n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        //report("pumped up2", tpe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        final CyclicBarrier pumpedUp2 = new CyclicBarrier(n + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        runnableDuJour = waiter(pumpedUp2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        for (int i = 0; i < 1*n; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            tpe.execute(runRunnableDuJour);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        pumpedUp2.await();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        equal(tg.activeCount(), 4*n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        equal(tg.activeCount(), tpe.getMaximumPoolSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        equal(tpe.getCompletedTaskCount(), 0L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        //report("pumped up2", tpe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        runnableDuJour = new Runnable() { public void run() {}};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        tpe.setMaximumPoolSize(2*n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        //report("after set", tpe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        pumpedUp2.await();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        pumpedUp.await();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
//      while (tg.activeCount() != n &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
//             tg.activeCount() != n)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
//          Thread.sleep(10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
//      equal(tg.activeCount(), n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
//      equal(tg.activeCount(), tpe.getCorePoolSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        while (tg.activeCount() != 2*n &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
               tg.activeCount() != 2*n)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            Thread.sleep(10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        equal(tg.activeCount(), 2*n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        equal(tg.activeCount(), tpe.getMaximumPoolSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
//report("draining", tpe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        while (tpe.getCompletedTaskCount() < 7*n &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
               tpe.getCompletedTaskCount() < 7*n)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            Thread.sleep(10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        //equal(tg.activeCount(), n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        //equal(tg.activeCount(), tpe.getCorePoolSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        equal(tg.activeCount(), 2*n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        equal(tg.activeCount(), tpe.getMaximumPoolSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        equal(tpe.getTaskCount(), 7L*n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        equal(tpe.getCompletedTaskCount(), 7L*n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        equal(tpe.getKeepAliveTime(MINUTES), 3L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        tpe.setKeepAliveTime(7L, MILLISECONDS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        equal(tpe.getKeepAliveTime(MILLISECONDS), 7L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        while (tg.activeCount() > n &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
               tg.activeCount() > n)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            Thread.sleep(10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        equal(tg.activeCount(), n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        //report("idle", tpe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        check(! tpe.allowsCoreThreadTimeOut());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        tpe.allowCoreThreadTimeOut(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        check(tpe.allowsCoreThreadTimeOut());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        while (tg.activeCount() > 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
               tg.activeCount() > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            Thread.sleep(10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        equal(tg.activeCount(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        //report("idle", tpe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        tpe.shutdown();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        checkShutdown(tpe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        check(tpe.awaitTermination(3L, MINUTES));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        checkTerminated(tpe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    //--------------------- Infrastructure ---------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    static volatile int passed = 0, failed = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    static void pass() {passed++;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    static void fail() {failed++; Thread.dumpStack();}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    static void fail(String msg) {System.out.println(msg); fail();}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    static void unexpected(Throwable t) {failed++; t.printStackTrace();}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    static void check(boolean cond) {if (cond) pass(); else fail();}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    static void equal(Object x, Object y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        if (x == null ? y == null : x.equals(y)) pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        else fail(x + " not equal to " + y);}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    public static void main(String[] args) throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        try {realMain(args);} catch (Throwable t) {unexpected(t);}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        if (failed > 0) throw new AssertionError("Some tests failed");}
7518
0282db800fe1 7003745: Code style cleanups (sync from Dougs CVS)
dl
parents: 5506
diff changeset
   244
    private abstract static class Fun {abstract void f() throws Throwable;}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    static void THROWS(Class<? extends Throwable> k, Fun... fs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        for (Fun f : fs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            try { f.f(); fail("Expected " + k.getName() + " not thrown"); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            catch (Throwable t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                if (k.isAssignableFrom(t.getClass())) pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                else unexpected(t);}}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
}