本文整理汇总了Java中jdk.testlibrary.ProcessTools类的典型用法代码示例。如果您正苦于以下问题:Java ProcessTools类的具体用法?Java ProcessTools怎么用?Java ProcessTools使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProcessTools类属于jdk.testlibrary包,在下文中一共展示了ProcessTools类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeKeytoolCommand
import jdk.testlibrary.ProcessTools; //导入依赖的package包/类
public static OutputAnalyzer executeKeytoolCommand(String[] command,
int exitCode) {
String[] keytoolCmd = new String[command.length + 1];
OutputAnalyzer output = null;
try {
keytoolCmd[0] = JDKToolFinder.getJDKTool(KEYTOOL);
System.arraycopy(command, 0, keytoolCmd, 1, command.length);
output = ProcessTools.executeCommand(keytoolCmd);
output.shouldHaveExitValue(exitCode);
out.println("Executed keytool command sucessfully:"
+ Arrays.toString(keytoolCmd));
} catch (Throwable e) {
e.printStackTrace(System.err);
throw new RuntimeException("Keytool Command execution failed : "
+ Arrays.toString(keytoolCmd), e);
}
return output;
}
示例2: main
import jdk.testlibrary.ProcessTools; //导入依赖的package包/类
public static void main(String[] a) throws Exception {
String testArgs = String.format(
"-javaagent:NoPremainAgent.jar -classpath %s DummyMain",
System.getProperty("test.classes", "."));
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
Utils.addTestJavaOpts(testArgs.split("\\s+")));
System.out.println("testjvm.cmd:" + Utils.getCommandLine(pb));
OutputAnalyzer output = new OutputAnalyzer(pb.start());
System.out.println("testjvm.stdout:" + output.getStdout());
System.out.println("testjvm.stderr:" + output.getStderr());
output.stderrShouldContain("java.lang.NoSuchMethodException");
if (0 == output.getExitValue()) {
throw new RuntimeException("Expected error but got exit value 0");
}
}
示例3: main
import jdk.testlibrary.ProcessTools; //导入依赖的package包/类
public static void main(String[] a) throws Exception {
String testArgs = String.format(
"-javaagent:%s/Agent.jar -classpath %s DummyMain",
System.getProperty("test.src"),
System.getProperty("test.classes", "."));
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
Utils.addTestJavaOpts(testArgs.split("\\s+")));
System.out.println("testjvm.cmd:" + Utils.getCommandLine(pb));
OutputAnalyzer output = new OutputAnalyzer(pb.start());
System.out.println("testjvm.stdout:" + output.getStdout());
System.out.println("testjvm.stderr:" + output.getStderr());
output.shouldHaveExitValue(0);
output.stdoutShouldContain("premain running");
output.stdoutShouldContain("Hello from DummyMain!");
}
示例4: main
import jdk.testlibrary.ProcessTools; //导入依赖的package包/类
public static void main(String[] a) throws Exception {
String testArgs = String.format(
"-javaagent:ZeroArgPremainAgent.jar -classpath %s DummyMain",
System.getProperty("test.classes", "."));
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
Utils.addTestJavaOpts(testArgs.split("\\s+")));
System.out.println("testjvm.cmd:" + Utils.getCommandLine(pb));
OutputAnalyzer output = new OutputAnalyzer(pb.start());
System.out.println("testjvm.stdout:" + output.getStdout());
System.out.println("testjvm.stderr:" + output.getStderr());
output.stderrShouldContain("java.lang.NoSuchMethodException");
if (0 == output.getExitValue()) {
throw new RuntimeException("Expected error but got exit value 0");
}
}
示例5: launch
import jdk.testlibrary.ProcessTools; //导入依赖的package包/类
private static Process launch(String address, String class_name) throws Exception {
String args[] = new String[]{
"-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address="
+ address,
class_name
};
args = VMConnection.insertDebuggeeVMOptions(args);
ProcessBuilder launcher = ProcessTools.createJavaProcessBuilder(args);
System.out.println(launcher.command().stream().collect(Collectors.joining(" ", "Starting: ", "")));
Process p = ProcessTools.startProcess(
class_name,
launcher,
RunToExit::checkForError,
RunToExit::isTransportListening,
0,
TimeUnit.NANOSECONDS
);
return p;
}
示例6: prepareLauncher
import jdk.testlibrary.ProcessTools; //导入依赖的package包/类
private static ProcessBuilder prepareLauncher(String address, boolean suspend, String class_name) throws Exception {
List<String> args = new ArrayList<>();
for(String dbgOption : VMConnection.getDebuggeeVMOptions().split(" ")) {
if (!dbgOption.trim().isEmpty()) {
args.add(dbgOption);
}
}
String lib = "-agentlib:jdwp=transport=dt_socket,server=y,suspend=";
if (suspend) {
lib += "y";
} else {
lib += "n";
}
lib += ",address=" + address;
args.add(lib);
args.add(class_name);
return ProcessTools.createJavaProcessBuilder(args.toArray(new String[args.size()]));
}
示例7: doSomething
import jdk.testlibrary.ProcessTools; //导入依赖的package包/类
/**
* Runs the test application "JMXStartStopDoSomething"
* @param name Test run name
* @param args Additional arguments
* @return Returns a {@linkplain Something} instance representing the run
* @throws IOException
* @throws InterruptedException
* @throws TimeoutException
*/
private static Something doSomething(String name, String ... args)
throws Exception {
List<String> pbArgs = new ArrayList<>(Arrays.asList(
"-cp",
System.getProperty("test.class.path")
));
pbArgs.addAll(Arrays.asList(args));
pbArgs.add("JMXStartStopDoSomething");
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
pbArgs.toArray(new String[pbArgs.size()])
);
Something s = new Something(pb, name);
s.start();
return s;
}
示例8: main
import jdk.testlibrary.ProcessTools; //导入依赖的package包/类
public static void main(String[] args) throws Throwable {
String testJdk = System.getProperty("test.jdk", "?");
String testSrc = System.getProperty("test.src", "?");
File jar = JpsHelper.buildJar("JpsBase");
List<String> cmd = new ArrayList<>();
cmd.addAll(JpsHelper.getVmArgs());
cmd.add("-Dtest.jdk=" + testJdk);
cmd.add("-Dtest.src=" + testSrc);
cmd.add("-jar");
cmd.add("." + File.separator + jar.getName());
cmd.add("monkey");
ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder(cmd.toArray(new String[cmd.size()]));
OutputAnalyzer output = new OutputAnalyzer(processBuilder.start());
System.out.println(output.getOutput());
output.shouldHaveExitValue(0);
}
示例9: main
import jdk.testlibrary.ProcessTools; //导入依赖的package包/类
public static void main(String[] args) throws Throwable {
String testJdk = System.getProperty("test.jdk", "?");
String testSrc = System.getProperty("test.src", "?");
File jar = JpsHelper.buildJar("JpsBase");
List<String> cmd = new ArrayList<>();
cmd.addAll(JpsHelper.getVmArgs());
cmd.add("-Dtest.jdk=" + testJdk);
cmd.add("-Dtest.src=" + testSrc);
cmd.add("-jar");
cmd.add(jar.getAbsolutePath());
cmd.add("monkey");
ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder(cmd.toArray(new String[cmd.size()]));
OutputAnalyzer output = new OutputAnalyzer(processBuilder.start());
System.out.println(output.getOutput());
output.shouldHaveExitValue(0);
}
示例10: main
import jdk.testlibrary.ProcessTools; //导入依赖的package包/类
public static void main(String[] args) throws Throwable {
String testJdk = System.getProperty("test.jdk", "?");
String testSrc = System.getProperty("test.src", "?");
String testClassPath = System.getProperty("test.class.path", "?");
List<String> cmd = new ArrayList<>();
cmd.addAll(JpsHelper.getVmArgs());
cmd.add("-Dtest.jdk=" + testJdk);
cmd.add("-Dtest.src=" + testSrc);
cmd.add("-cp");
cmd.add(testClassPath);
cmd.add("JpsBase");
cmd.add("monkey");
ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder(cmd.toArray(new String[cmd.size()]));
OutputAnalyzer output = new OutputAnalyzer(processBuilder.start());
System.out.println(output.getOutput());
output.shouldHaveExitValue(0);
}
示例11: parsePid
import jdk.testlibrary.ProcessTools; //导入依赖的package包/类
/**
* Parse pid from jps output
*/
private String parsePid(String tool, OutputAnalyzer output) throws Exception {
String[] lines = output.getOutput().split(Utils.NEW_LINE);
String pid = null;
int count = 0;
String processName = tool;
if (tool == "rmiregistry") {
processName = "registryimpl";
}
Pattern toolInJpsPattern =
Pattern.compile("^\\d+\\s{1}" + processName + "\\s{1}.*-dparent\\.pid\\." + ProcessTools.getProcessId() + ".*");
for (String line : lines) {
if (toolInJpsPattern.matcher(line.toLowerCase()).matches()) {
pid = line.split(" ")[0];
count++;
}
}
if (count > 1) {
throw new Exception("Expected one " + tool
+ " process, got " + count + ". Test will be canceled.");
}
return pid;
}
示例12: getJstatdCmd
import jdk.testlibrary.ProcessTools; //导入依赖的package包/类
/**
* Depending on test settings command line can look like:
*
* jstatd -J-XX:+UsePerfData -J-Djava.security.policy=all.policy
* jstatd -J-XX:+UsePerfData -J-Djava.security.policy=all.policy -p port
* jstatd -J-XX:+UsePerfData -J-Djava.security.policy=all.policy -n serverName
* jstatd -J-XX:+UsePerfData -J-Djava.security.policy=all.policy -p port -n serverName
*/
private String[] getJstatdCmd() throws Exception {
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jstatd");
launcher.addVMArg("-XX:+UsePerfData");
String testSrc = System.getProperty("test.src");
File policy = new File(testSrc, "all.policy");
assertTrue(policy.exists() && policy.isFile(),
"Security policy " + policy.getAbsolutePath() + " does not exist or not a file");
launcher.addVMArg("-Djava.security.policy=" + policy.getAbsolutePath());
// -Dparent.pid.<pid> will help to identify jstad process started by this test
launcher.addVMArg("-Dparent.pid." + ProcessTools.getProcessId());
if (port != null) {
launcher.addToolArg("-p");
launcher.addToolArg(port);
}
if (serverName != null) {
launcher.addToolArg("-n");
launcher.addToolArg(serverName);
}
String[] cmd = launcher.getCommand();
log("Start jstatd", cmd);
return cmd;
}
示例13: launch
import jdk.testlibrary.ProcessTools; //导入依赖的package包/类
private static Process launch(String address, String class_name) throws Exception {
String[] args = VMConnection.insertDebuggeeVMOptions(new String[] {
"-agentlib:jdwp=transport=dt_socket" +
",server=y" + ",suspend=y" + ",address=" + address,
class_name
});
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args);
final AtomicBoolean success = new AtomicBoolean();
Process p = ProcessTools.startProcess(
class_name,
pb,
(line) -> {
// The first thing that will get read is
// Listening for transport dt_socket at address: xxxxx
// which shows the debuggee is ready to accept connections.
success.set(line.contains("Listening for transport dt_socket at address:"));
return true;
},
Integer.MAX_VALUE,
TimeUnit.MILLISECONDS
);
return success.get() ? p : null;
}
示例14: prepareLauncher
import jdk.testlibrary.ProcessTools; //导入依赖的package包/类
private static ProcessBuilder prepareLauncher(String address, boolean suspend, String class_name) throws Exception {
List<String> args = new ArrayList<>();
for(String dbgOption : VMConnection.getDebuggeeVMOptions().split(" ")) {
args.add(dbgOption);
}
String lib = "-agentlib:jdwp=transport=dt_socket,server=y,suspend=";
if (suspend) {
lib += "y";
} else {
lib += "n";
}
lib += ",address=" + address;
args.add(lib);
args.add(class_name);
return ProcessTools.createJavaProcessBuilder(args.toArray(new String[args.size()]));
}
示例15: launchTests
import jdk.testlibrary.ProcessTools; //导入依赖的package包/类
/**
* Runs the actual tests in nested class TestMain.
* The reason for running the tests in a separate process
* is that we need to modify the class path and
* the -Djava.io.tmpdir property.
*/
private static void launchTests(int pid, Path clientTmpDir) throws Throwable {
final String sep = File.separator;
// Need to add jdk/lib/tools.jar to classpath.
String classpath =
System.getProperty("test.class.path", "") + File.pathSeparator +
System.getProperty("test.jdk", ".") + sep + "lib" + sep + "tools.jar";
String[] tmpDirArg = null;
if (clientTmpDir != null) {
tmpDirArg = new String [] {"-Djava.io.tmpdir=" + clientTmpDir};
}
// Arguments : [-Djava.io.tmpdir=] -classpath cp TempDirTest$TestMain pid
String[] args = RunnerUtil.concat(
tmpDirArg,
new String[] {
"-classpath",
classpath,
"TempDirTest$TestMain",
Integer.toString(pid) });
OutputAnalyzer output = ProcessTools.executeTestJvm(args);
output.shouldHaveExitValue(0);
}