Path: blob/master/test/langtools/jdk/jshell/HangingRemoteAgent.java
40930 views
/*1* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.util.Map;24import java.util.logging.Level;25import java.util.logging.Logger;26import jdk.jshell.JShell;27import jdk.jshell.execution.JdiExecutionControlProvider;28import jdk.jshell.execution.RemoteExecutionControl;29import jdk.jshell.spi.ExecutionControlProvider;3031/**32* Hang for three minutes (long enough to cause a timeout).33*/34class HangingRemoteAgent extends RemoteExecutionControl {3536private static final long DELAY = 4000L;37private static final int TIMEOUT = 2000;38private static final boolean INFRA_VERIFY = false;3940public static void main(String[] args) throws Exception {41if (INFRA_VERIFY) {42RemoteExecutionControl.main(args);43} else {44long end = System.currentTimeMillis() + DELAY;45long remaining;46while ((remaining = end - System.currentTimeMillis()) > 0L) {47try {48Thread.sleep(remaining);49} catch (InterruptedException ex) {50// loop again51}52}53}54}5556static JShell state(boolean isLaunch, String host) {57ExecutionControlProvider ecp = new JdiExecutionControlProvider();58Map<String,String> pm = ecp.defaultParameters();59pm.put(JdiExecutionControlProvider.PARAM_REMOTE_AGENT, HangingRemoteAgent.class.getName());60pm.put(JdiExecutionControlProvider.PARAM_HOST_NAME, host==null? "" : host);61pm.put(JdiExecutionControlProvider.PARAM_LAUNCH, ""+isLaunch);62pm.put(JdiExecutionControlProvider.PARAM_TIMEOUT, ""+TIMEOUT);63// turn on logging of launch failures64Logger.getLogger("jdk.jshell.execution").setLevel(Level.ALL);65return JShell.builder()66.executionEngine(ecp, pm)67.build();68}6970}717273