/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* @test
* @bug 6405995
* @summary Unit test for selector wakeup and interruption
* @library ..
*/
public class Wakeup {
try {
} catch (InterruptedException x) {
x.printStackTrace();
}
}
volatile boolean started = false;
volatile boolean wantInterrupt = false;
volatile boolean gotInterrupt = false;
volatile boolean closed = false;
}
started = true;
for (;;) {
synchronized (gate) { }
entries++;
try {
} catch (ClosedSelectorException x) {
closed = true;
}
wakeups++;
if (wakeups > 1000)
throw new Exception("Too many wakeups");
if (closed)
return;
if (wantInterrupt) {
while (!Thread.interrupted())
gotInterrupt = true;
wantInterrupt = false;
}
}
}
}
throws Exception
{
throw new Exception("Sleeper has run ahead");
}
int n = 0;
sleep(50);
if ((n += 50) > 1000) {
throw new Exception("Sleeper appears to be dead ("
+ checkedWakeups + ")");
}
}
throw new Exception("Too many wakeups: Expected "
}
if (intr) {
n = 0;
// Interrupts can sometimes be delayed, so wait
while (!sleeper.gotInterrupt) {
sleep(50);
if ((n += 50) > 1000) {
throw new Exception("Interrupt never delivered");
}
}
sleeper.gotInterrupt = false;
}
}
// Wakeup before select
sleep(50);
for (int i = 2; i < 5; i++) {
// Wakeup during select
}
// Double wakeup
}
// Interrupt
sleeper.wantInterrupt = true;
}
// Interrupt before select
sleeper.wantInterrupt = true;
sleep(50);
}
// Close during select
}
throw new Exception("Test failed");
throw new Exception("Selector not closed");
}
}