langtools/test/jdk/jshell/StopExecutionTest.java
author jlahoda
Tue, 10 Jan 2017 10:17:47 +0100
changeset 43135 0c7c13fa7bee
parent 35359 f04501964016
permissions -rw-r--r--
8171385: jshell tool: unresponsive to ctrl-C in input wait on Windows Summary: Ensuring stop is sent using the proper channel depending on the current state of the StopDetectingInputStream. Reviewed-by: rfield
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     1
/*
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     4
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     7
 * published by the Free Software Foundation.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     8
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    13
 * accompanied this code).
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    14
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    18
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    21
 * questions.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    22
 */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    23
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    24
/*
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    25
 * @test
43135
0c7c13fa7bee 8171385: jshell tool: unresponsive to ctrl-C in input wait on Windows
jlahoda
parents: 35359
diff changeset
    26
 * @bug 8171385
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    27
 * @summary Test JShell#stop
35359
f04501964016 8148147: Sync up @modules from jigsaw/jake
alanb
parents: 33362
diff changeset
    28
 * @modules jdk.jshell/jdk.internal.jshell.tool
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    29
 * @build KullaTesting TestingInputStream
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    30
 * @run testng StopExecutionTest
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    31
 */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    32
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    33
import java.io.IOException;
43135
0c7c13fa7bee 8171385: jshell tool: unresponsive to ctrl-C in input wait on Windows
jlahoda
parents: 35359
diff changeset
    34
import java.io.PipedInputStream;
0c7c13fa7bee 8171385: jshell tool: unresponsive to ctrl-C in input wait on Windows
jlahoda
parents: 35359
diff changeset
    35
import java.io.PipedOutputStream;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    36
import java.io.PrintWriter;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    37
import java.io.StringWriter;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    38
import java.util.Random;
43135
0c7c13fa7bee 8171385: jshell tool: unresponsive to ctrl-C in input wait on Windows
jlahoda
parents: 35359
diff changeset
    39
import java.util.concurrent.CountDownLatch;
0c7c13fa7bee 8171385: jshell tool: unresponsive to ctrl-C in input wait on Windows
jlahoda
parents: 35359
diff changeset
    40
import java.util.function.Consumer;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    41
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    42
import jdk.internal.jshell.tool.StopDetectingInputStream;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    43
import jdk.internal.jshell.tool.StopDetectingInputStream.State;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    44
import jdk.jshell.JShell;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    45
import org.testng.annotations.Test;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    46
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    47
import static org.testng.Assert.assertEquals;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    48
import static org.testng.Assert.fail;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    49
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    50
@Test
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    51
public class StopExecutionTest extends KullaTesting {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    52
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    53
    private final Object lock = new Object();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    54
    private boolean isStopped;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    55
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    56
    @Test(enabled = false) // TODO 8129546
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    57
    public void testStopLoop() throws InterruptedException {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    58
        scheduleStop("while (true) ;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    59
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    60
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    61
    @Test(enabled = false) // TODO 8129546
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    62
    public void testStopASleep() throws InterruptedException {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    63
        scheduleStop("while (true) { try { Thread.sleep(100); } catch (InterruptedException ex) { } }");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    64
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    65
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    66
    @Test(enabled = false) // TODO 8129546
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    67
    public void testScriptCatchesStop() throws Exception {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    68
        scheduleStop("for (int i = 0; i < 30; i++) { try { Thread.sleep(100); } catch (Throwable ex) { } }");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    69
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    70
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    71
    private void scheduleStop(String src) throws InterruptedException {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    72
        JShell state = getState();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    73
        isStopped = false;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    74
        StringWriter writer = new StringWriter();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    75
        PrintWriter out = new PrintWriter(writer);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    76
        Thread t = new Thread(() -> {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    77
            int i = 1;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    78
            int n = 30;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    79
            synchronized (lock) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    80
                do {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    81
                    state.stop();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    82
                    if (!isStopped) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    83
                        out.println("Not stopped. Try again: " + i);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    84
                        try {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    85
                            lock.wait(1000);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    86
                        } catch (InterruptedException ignored) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    87
                        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    88
                    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    89
                } while (i++ < n && !isStopped);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    90
                if (!isStopped) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    91
                    System.err.println(writer.toString());
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    92
                    fail("Evaluation was not stopped: '" + src + "'");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    93
                }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    94
            }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    95
        });
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    96
        t.start();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    97
        assertEval(src);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    98
        synchronized (lock) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    99
            out.println("Evaluation was stopped successfully: '" + src + "'");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   100
            isStopped = true;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   101
            lock.notify();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   102
        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   103
        // wait until the background thread finishes to prevent from calling 'stop' on closed state.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   104
        t.join();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   105
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   106
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   107
    public void testStopDetectingInputRandom() throws IOException {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   108
        long seed = System.nanoTime();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   109
        Random r = new Random(seed);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   110
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   111
        for (int m = 0; m < 10; m++) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   112
            StopDetectingInputStream buffer = new StopDetectingInputStream(null, null);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   113
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   114
            buffer.setState(State.BUFFER);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   115
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   116
            for (int i = 0; i < 1000; i++) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   117
                int chunkSize = r.nextInt(StopDetectingInputStream.INITIAL_SIZE * 3);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   118
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   119
                doChunk(buffer, chunkSize);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   120
            }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   121
        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   122
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   123
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   124
    private void doChunk(StopDetectingInputStream buffer, int chunkSize) throws IOException {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   125
        for (int c = 0; c < chunkSize; c++) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   126
            buffer.write(c);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   127
        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   128
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   129
        for (int c = 0; c < chunkSize; c++) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   130
            int read = buffer.read();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   131
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   132
            assertEquals(read, c);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   133
        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   134
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   135
43135
0c7c13fa7bee 8171385: jshell tool: unresponsive to ctrl-C in input wait on Windows
jlahoda
parents: 35359
diff changeset
   136
    public void testStopDetectingInputBufferWaitStop() throws Exception {
0c7c13fa7bee 8171385: jshell tool: unresponsive to ctrl-C in input wait on Windows
jlahoda
parents: 35359
diff changeset
   137
        Runnable shouldNotHappenRun =
0c7c13fa7bee 8171385: jshell tool: unresponsive to ctrl-C in input wait on Windows
jlahoda
parents: 35359
diff changeset
   138
                () -> { throw new AssertionError("Should not happen."); };
0c7c13fa7bee 8171385: jshell tool: unresponsive to ctrl-C in input wait on Windows
jlahoda
parents: 35359
diff changeset
   139
        Consumer<Exception> shouldNotHappenExc =
0c7c13fa7bee 8171385: jshell tool: unresponsive to ctrl-C in input wait on Windows
jlahoda
parents: 35359
diff changeset
   140
                exc -> { throw new AssertionError("Should not happen.", exc); };
0c7c13fa7bee 8171385: jshell tool: unresponsive to ctrl-C in input wait on Windows
jlahoda
parents: 35359
diff changeset
   141
        StopDetectingInputStream sd = new StopDetectingInputStream(shouldNotHappenRun, shouldNotHappenExc);
0c7c13fa7bee 8171385: jshell tool: unresponsive to ctrl-C in input wait on Windows
jlahoda
parents: 35359
diff changeset
   142
        CountDownLatch reading = new CountDownLatch(1);
0c7c13fa7bee 8171385: jshell tool: unresponsive to ctrl-C in input wait on Windows
jlahoda
parents: 35359
diff changeset
   143
        PipedInputStream is = new PipedInputStream() {
0c7c13fa7bee 8171385: jshell tool: unresponsive to ctrl-C in input wait on Windows
jlahoda
parents: 35359
diff changeset
   144
            @Override
0c7c13fa7bee 8171385: jshell tool: unresponsive to ctrl-C in input wait on Windows
jlahoda
parents: 35359
diff changeset
   145
            public int read() throws IOException {
0c7c13fa7bee 8171385: jshell tool: unresponsive to ctrl-C in input wait on Windows
jlahoda
parents: 35359
diff changeset
   146
                reading.countDown();
0c7c13fa7bee 8171385: jshell tool: unresponsive to ctrl-C in input wait on Windows
jlahoda
parents: 35359
diff changeset
   147
                return super.read();
0c7c13fa7bee 8171385: jshell tool: unresponsive to ctrl-C in input wait on Windows
jlahoda
parents: 35359
diff changeset
   148
            }
0c7c13fa7bee 8171385: jshell tool: unresponsive to ctrl-C in input wait on Windows
jlahoda
parents: 35359
diff changeset
   149
        };
0c7c13fa7bee 8171385: jshell tool: unresponsive to ctrl-C in input wait on Windows
jlahoda
parents: 35359
diff changeset
   150
        PipedOutputStream os = new PipedOutputStream(is);
0c7c13fa7bee 8171385: jshell tool: unresponsive to ctrl-C in input wait on Windows
jlahoda
parents: 35359
diff changeset
   151
0c7c13fa7bee 8171385: jshell tool: unresponsive to ctrl-C in input wait on Windows
jlahoda
parents: 35359
diff changeset
   152
        sd.setInputStream(is);
0c7c13fa7bee 8171385: jshell tool: unresponsive to ctrl-C in input wait on Windows
jlahoda
parents: 35359
diff changeset
   153
        sd.setState(State.BUFFER);
0c7c13fa7bee 8171385: jshell tool: unresponsive to ctrl-C in input wait on Windows
jlahoda
parents: 35359
diff changeset
   154
        reading.await();
0c7c13fa7bee 8171385: jshell tool: unresponsive to ctrl-C in input wait on Windows
jlahoda
parents: 35359
diff changeset
   155
        sd.setState(State.WAIT);
0c7c13fa7bee 8171385: jshell tool: unresponsive to ctrl-C in input wait on Windows
jlahoda
parents: 35359
diff changeset
   156
        os.write(3);
0c7c13fa7bee 8171385: jshell tool: unresponsive to ctrl-C in input wait on Windows
jlahoda
parents: 35359
diff changeset
   157
        int value = sd.read();
0c7c13fa7bee 8171385: jshell tool: unresponsive to ctrl-C in input wait on Windows
jlahoda
parents: 35359
diff changeset
   158
0c7c13fa7bee 8171385: jshell tool: unresponsive to ctrl-C in input wait on Windows
jlahoda
parents: 35359
diff changeset
   159
        if (value != 3) {
0c7c13fa7bee 8171385: jshell tool: unresponsive to ctrl-C in input wait on Windows
jlahoda
parents: 35359
diff changeset
   160
            throw new AssertionError();
0c7c13fa7bee 8171385: jshell tool: unresponsive to ctrl-C in input wait on Windows
jlahoda
parents: 35359
diff changeset
   161
        }
0c7c13fa7bee 8171385: jshell tool: unresponsive to ctrl-C in input wait on Windows
jlahoda
parents: 35359
diff changeset
   162
    }
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   163
}