jdk/test/java/nio/channels/Selector/Wakeup.java
author alanb
Fri, 10 Sep 2010 18:48:49 +0100
changeset 6538 cb0da65ba680
parent 5506 202f599c92aa
child 29528 d1a052f7ccef
permissions -rw-r--r--
6983794: TEST_BUG: test/java/nio/channels/Selector/ConnectWrite.java failing Reviewed-by: chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
845
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
     2
 * Copyright (c) 2001, 2008, Oracle and/or its affiliates. All rights reserved.
845
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
     4
 *
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
     8
 *
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    13
 * accompanied this code).
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    14
 *
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
    21
 * questions.
845
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    22
 */
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    23
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    24
/* @test
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    25
 * @bug 6405995
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    26
 * @summary Unit test for selector wakeup and interruption
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    27
 * @library ..
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    28
 */
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    29
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    30
import java.io.*;
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    31
import java.net.*;
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    32
import java.nio.*;
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    33
import java.nio.channels.*;
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    34
import java.util.Random;
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    35
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    36
public class Wakeup {
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    37
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    38
    static void sleep(int millis) {
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    39
        try {
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    40
            Thread.sleep(millis);
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    41
        } catch (InterruptedException x) {
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    42
            x.printStackTrace();
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    43
        }
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    44
    }
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    45
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    46
    static class Sleeper extends TestThread {
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    47
        volatile boolean started = false;
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    48
        volatile int entries = 0;
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    49
        volatile int wakeups = 0;
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    50
        volatile boolean wantInterrupt = false;
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    51
        volatile boolean gotInterrupt = false;
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    52
        volatile Exception exception = null;
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    53
        volatile boolean closed = false;
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    54
        Object gate = new Object();
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    55
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    56
        Selector sel;
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    57
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    58
        Sleeper(Selector sel) {
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    59
            super("Sleeper", System.err);
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    60
            this.sel = sel;
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    61
        }
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    62
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    63
        public void go() throws Exception {
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    64
            started = true;
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    65
            for (;;) {
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    66
                synchronized (gate) { }
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    67
                entries++;
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    68
                try {
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    69
                    sel.select();
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    70
                } catch (ClosedSelectorException x) {
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    71
                    closed = true;
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    72
                }
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    73
                boolean intr = Thread.currentThread().isInterrupted();
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    74
                wakeups++;
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    75
                System.err.println("Wakeup " + wakeups
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    76
                                   + (closed ? " (closed)" : "")
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    77
                                   + (intr ? " (intr)" : ""));
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    78
                if (wakeups > 1000)
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    79
                    throw new Exception("Too many wakeups");
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    80
                if (closed)
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    81
                    return;
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    82
                if (wantInterrupt) {
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    83
                    while (!Thread.interrupted())
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    84
                        Thread.yield();
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    85
                    gotInterrupt = true;
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    86
                    wantInterrupt = false;
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    87
                }
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    88
            }
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    89
        }
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    90
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    91
    }
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    92
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    93
    private static int checkedWakeups = 0;
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    94
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    95
    private static void check(Sleeper sleeper, boolean intr)
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    96
        throws Exception
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    97
    {
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    98
        checkedWakeups++;
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    99
        if (sleeper.wakeups > checkedWakeups) {
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   100
            sleeper.finish(100);
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   101
            throw new Exception("Sleeper has run ahead");
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   102
        }
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   103
        int n = 0;
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   104
        while (sleeper.wakeups < checkedWakeups) {
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   105
            sleep(50);
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   106
            if ((n += 50) > 1000) {
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   107
                sleeper.finish(100);
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   108
                throw new Exception("Sleeper appears to be dead ("
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   109
                                    + checkedWakeups + ")");
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   110
            }
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   111
        }
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   112
        if (sleeper.wakeups > checkedWakeups) {
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   113
            sleeper.finish(100);
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   114
            throw new Exception("Too many wakeups: Expected "
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   115
                                + checkedWakeups
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   116
                                + ", got " + sleeper.wakeups);
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   117
        }
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   118
        if (intr) {
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   119
            n = 0;
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   120
            // Interrupts can sometimes be delayed, so wait
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   121
            while (!sleeper.gotInterrupt) {
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   122
                sleep(50);
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   123
                if ((n += 50) > 1000) {
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   124
                    sleeper.finish(100);
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   125
                    throw new Exception("Interrupt never delivered");
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   126
                }
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   127
            }
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   128
            sleeper.gotInterrupt = false;
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   129
        }
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   130
        System.err.println("Check " + checkedWakeups
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   131
                           + (intr ? " (intr " + n + ")" : ""));
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   132
    }
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   133
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   134
    public static void main(String[] args) throws Exception {
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   135
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   136
        Selector sel = Selector.open();
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   137
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   138
        // Wakeup before select
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   139
        sel.wakeup();
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   140
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   141
        Sleeper sleeper = new Sleeper(sel);
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   142
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   143
        sleeper.start();
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   144
        while (!sleeper.started)
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   145
            sleep(50);
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   146
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   147
        check(sleeper, false);          // 1
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   148
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   149
        for (int i = 2; i < 5; i++) {
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   150
            // Wakeup during select
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   151
            sel.wakeup();
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   152
            check(sleeper, false);      // 2 .. 4
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   153
        }
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   154
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   155
        // Double wakeup
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   156
        synchronized (sleeper.gate) {
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   157
            sel.wakeup();
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   158
            check(sleeper, false);      // 5
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   159
            sel.wakeup();
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   160
            sel.wakeup();
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   161
        }
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   162
        check(sleeper, false);          // 6
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   163
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   164
        // Interrupt
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   165
        synchronized (sleeper.gate) {
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   166
            sleeper.wantInterrupt = true;
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   167
            sleeper.interrupt();
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   168
            check(sleeper, true);       // 7
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   169
        }
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   170
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   171
        // Interrupt before select
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   172
        while (sleeper.entries < 8)
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   173
            Thread.yield();
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   174
        synchronized (sleeper.gate) {
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   175
            sel.wakeup();
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   176
            check(sleeper, false);      // 8
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   177
            sleeper.wantInterrupt = true;
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   178
            sleeper.interrupt();
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   179
            sleep(50);
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   180
        }
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   181
        check(sleeper, true);           // 9
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   182
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   183
        // Close during select
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   184
        while (sleeper.entries < 10)
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   185
            Thread.yield();
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   186
        synchronized (sleeper.gate) {
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   187
            sel.close();
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   188
            check(sleeper, false);      // 10
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   189
        }
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   190
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   191
        if (sleeper.finish(200) == 0)
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   192
            throw new Exception("Test failed");
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   193
        if (!sleeper.closed)
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   194
            throw new Exception("Selector not closed");
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   195
    }
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   196
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   197
}