test/jdk/java/nio/channels/Selector/Wakeup.java
author alanb
Fri, 14 Sep 2018 16:56:09 +0100
changeset 51745 90c1dcdebc64
parent 47216 71c04702a3d5
child 51754 594919232b8f
permissions -rw-r--r--
8208780: (se) test SelectWithConsumer.testReadableAndWriteable(): failure Reviewed-by: bpb
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
/*
42337
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
     2
 * Copyright (c) 2001, 2016, 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
42337
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    27
 * @library .. /lib/testlibrary/
845
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.*;
42337
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    34
import java.util.concurrent.CyclicBarrier;
845
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 {
42337
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    47
        private static final long TIMEOUT = jdk.testlibrary.Utils.adjustTimeout(20_000);
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    48
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    49
        // barrier is used to synchronize sleeper thread and checking
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    50
        // thread which is the main thread: when go() get to the end,
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    51
        // then start checking the sleeper's status.
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    52
        private static CyclicBarrier barrier = new CyclicBarrier(2);
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    53
        private static int wakeups = 0;
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    54
        private static int waits = 0;
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    55
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    56
        volatile boolean interruptBeforeSelect = false;
845
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    57
        volatile boolean started = false;
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    58
        volatile boolean wantInterrupt = false;
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    59
        volatile boolean closed = false;
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    60
        Object gate = new Object();
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
        Selector sel;
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    63
42337
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    64
        Sleeper(Selector sel, boolean wantInterrupt, boolean interruptBeforeSelect) {
845
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    65
            super("Sleeper", System.err);
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    66
            this.sel = sel;
42337
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    67
            this.wantInterrupt = wantInterrupt;
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    68
            this.interruptBeforeSelect = interruptBeforeSelect;
845
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    69
        }
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    70
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    71
        public void go() throws Exception {
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    72
            started = true;
42337
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    73
            if (interruptBeforeSelect) {
845
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
    74
                synchronized (gate) { }
42337
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    75
            }
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    76
            wakeups++;
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    77
            System.err.println("Wakeup, selecting, " + wakeups);
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    78
            try {
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    79
                sel.select();
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    80
            } catch (ClosedSelectorException x) {
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    81
                closed = true;
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    82
            }
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    83
            boolean intr = Thread.currentThread().isInterrupted();
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    84
            System.err.println("Wakeup " + wakeups
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    85
                               + (closed ? " (closed)" : "")
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    86
                               + (intr ? " (intr)" : ""));
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    87
            if (closed)
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    88
                return;
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    89
            if (wantInterrupt) {
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    90
                while (!Thread.interrupted())
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    91
                    Thread.yield();
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    92
            }
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    93
            System.err.println("Wakeup, waiting, " + wakeups);
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    94
            barrier.await();
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    95
            System.err.println("Wakeup, wait successfully, " + wakeups);
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    96
        }
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    97
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    98
        void check(boolean close) throws Exception {
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
    99
            waits++;
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   100
            System.err.println("waiting sleeper, " + waits);
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   101
            if (!close) {
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   102
                barrier.await();
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   103
                System.err.println("wait barrier successfully, " + waits);
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   104
            }
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   105
            if (finish(TIMEOUT) == 0)
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   106
                throw new Exception("Test failed");
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   107
            if (this.closed != close)
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   108
                throw new Exception("Selector was closed");
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   109
        }
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   110
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   111
        void check() throws Exception {
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   112
            check(false);
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   113
        }
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   114
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   115
        static Sleeper createSleeper(Selector sel, boolean wantInterrupt,
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   116
                boolean interruptBeforeSelect) throws Exception {
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   117
            if (!wantInterrupt && interruptBeforeSelect) {
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   118
                throw new RuntimeException("Wrong parameters!");
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   119
            }
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   120
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   121
            Sleeper sleeper = new Sleeper(sel, wantInterrupt, interruptBeforeSelect);
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   122
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   123
            if (interruptBeforeSelect) {
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   124
                synchronized(sleeper.gate) {
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   125
                    sleeper.start();
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   126
                    while (!sleeper.started)
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   127
                        sleep(50);
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   128
                    sleeper.interrupt();
845
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   129
                }
42337
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   130
            } else {
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   131
                sleeper.start();
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   132
                while (!sleeper.started)
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   133
                    sleep(50);
845
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   134
                if (wantInterrupt) {
42337
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   135
                    sleep(50);
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   136
                    sleeper.interrupt();
845
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
            }
42337
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   139
            return sleeper;
845
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
    }
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   142
42337
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   143
    static Sleeper newSleeper(Selector sel) throws Exception {
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   144
        return Sleeper.createSleeper(sel, false, false);
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   145
    }
845
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   146
42337
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   147
    static Sleeper newSleeperWantInterrupt(Selector sel) throws Exception {
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   148
        return Sleeper.createSleeper(sel, true, false);
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   149
    }
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   150
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   151
    static Sleeper newSleeperWantInterruptBeforeSelect(Selector sel) throws Exception {
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   152
        return Sleeper.createSleeper(sel, true, true);
845
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
    public static void main(String[] args) throws Exception {
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   156
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   157
        Selector sel = Selector.open();
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   158
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   159
        // Wakeup before select
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
42337
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   162
        Sleeper sleeper = newSleeper(sel); // 1
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   163
        sleeper.check();
845
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   164
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   165
        for (int i = 2; i < 5; i++) {
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   166
            // Wakeup during select
42337
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   167
            sleeper = newSleeper(sel);
845
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   168
            sel.wakeup();
42337
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   169
            sleeper.check();         // 2 .. 4
845
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
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   172
        // Double wakeup
42337
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   173
        sel.wakeup();
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   174
        sel.wakeup();
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   175
        sleeper = newSleeper(sel);
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   176
        sleeper.check();            // 5
845
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   177
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   178
        // Interrupt
42337
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   179
        sleeper = newSleeperWantInterrupt(sel);
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   180
        sleeper.check();            // 6
845
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   181
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   182
        // Interrupt before select
42337
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   183
        sleeper = newSleeperWantInterruptBeforeSelect(sel);
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   184
        sleeper.check();            // 7
845
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   185
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   186
        // Close during select
42337
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   187
        sleeper = newSleeper(sel);
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   188
        sel.close();
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   189
        sleeper.check();           // 8
845
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   190
42337
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   191
        sleeper = newSleeper(sel);
9597f6a5755d 8049316: java/nio/channels/Selector/Wakeup.java failing
mli
parents: 29603
diff changeset
   192
        sleeper.check(true);
845
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   193
    }
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   194
4ff8bc630878 6405995: (ch) test/java/nio/channels/Selector/Wakeup.java broken
sherman
parents:
diff changeset
   195
}