8171385: jshell tool: unresponsive to ctrl-C in input wait on Windows
Ensuring stop is sent using the proper channel depending on the current state of the StopDetectingInputStream. Reviewed-by: rfield
This commit is contained in:
parent
cea33151ed
commit
fd12ea2d58
@ -66,7 +66,7 @@ public final class StopDetectingInputStream extends InputStream {
|
|||||||
if ((read = input.read()) == (-1)) {
|
if ((read = input.read()) == (-1)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (read == 3 && currentState == State.BUFFER) {
|
if (read == 3 && getState() == State.BUFFER) {
|
||||||
stop.run();
|
stop.run();
|
||||||
} else {
|
} else {
|
||||||
write(read);
|
write(read);
|
||||||
@ -141,6 +141,10 @@ public final class StopDetectingInputStream extends InputStream {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private synchronized State getState() {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
private synchronized State waitInputNeeded() {
|
private synchronized State waitInputNeeded() {
|
||||||
while (state == State.WAIT) {
|
while (state == State.WAIT) {
|
||||||
try {
|
try {
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
|
* @bug 8171385
|
||||||
* @summary Test JShell#stop
|
* @summary Test JShell#stop
|
||||||
* @modules jdk.jshell/jdk.internal.jshell.tool
|
* @modules jdk.jshell/jdk.internal.jshell.tool
|
||||||
* @build KullaTesting TestingInputStream
|
* @build KullaTesting TestingInputStream
|
||||||
@ -30,9 +31,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.PipedInputStream;
|
||||||
|
import java.io.PipedOutputStream;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import jdk.internal.jshell.tool.StopDetectingInputStream;
|
import jdk.internal.jshell.tool.StopDetectingInputStream;
|
||||||
import jdk.internal.jshell.tool.StopDetectingInputStream.State;
|
import jdk.internal.jshell.tool.StopDetectingInputStream.State;
|
||||||
@ -128,4 +133,31 @@ public class StopExecutionTest extends KullaTesting {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testStopDetectingInputBufferWaitStop() throws Exception {
|
||||||
|
Runnable shouldNotHappenRun =
|
||||||
|
() -> { throw new AssertionError("Should not happen."); };
|
||||||
|
Consumer<Exception> shouldNotHappenExc =
|
||||||
|
exc -> { throw new AssertionError("Should not happen.", exc); };
|
||||||
|
StopDetectingInputStream sd = new StopDetectingInputStream(shouldNotHappenRun, shouldNotHappenExc);
|
||||||
|
CountDownLatch reading = new CountDownLatch(1);
|
||||||
|
PipedInputStream is = new PipedInputStream() {
|
||||||
|
@Override
|
||||||
|
public int read() throws IOException {
|
||||||
|
reading.countDown();
|
||||||
|
return super.read();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
PipedOutputStream os = new PipedOutputStream(is);
|
||||||
|
|
||||||
|
sd.setInputStream(is);
|
||||||
|
sd.setState(State.BUFFER);
|
||||||
|
reading.await();
|
||||||
|
sd.setState(State.WAIT);
|
||||||
|
os.write(3);
|
||||||
|
int value = sd.read();
|
||||||
|
|
||||||
|
if (value != 3) {
|
||||||
|
throw new AssertionError();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user