当前位置: 首页>>代码示例>>Java>>正文


Java Utils类代码示例

本文整理汇总了Java中jdk.testlibrary.Utils的典型用法代码示例。如果您正苦于以下问题:Java Utils类的具体用法?Java Utils怎么用?Java Utils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Utils类属于jdk.testlibrary包,在下文中一共展示了Utils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: runTest

import jdk.testlibrary.Utils; //导入依赖的package包/类
private static void runTest(String main, String... args)  {

        try {
            List<String> opts = new ArrayList<>();
            opts.add(getJavaExe());
            opts.addAll(Arrays.asList(Utils.getTestJavaOpts()));
            opts.add("-cp");
            opts.add(System.getProperty("test.class.path", System.getProperty("java.class.path")));

            opts.add(main);
            opts.addAll(Arrays.asList(args));

            ProcessBuilder pb = new ProcessBuilder(opts.toArray(new String[0]));
            process = pb.start();
        } catch (Throwable throwable) {
            throw new RuntimeException(throwable);
        }
    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:ClipboardInterVMTest.java

示例2: main

import jdk.testlibrary.Utils; //导入依赖的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");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:NoPremainAgentTest.java

示例3: main

import jdk.testlibrary.Utils; //导入依赖的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!");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:PremainClassTest.java

示例4: main

import jdk.testlibrary.Utils; //导入依赖的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");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:ZeroArgPremainAgentTest.java

示例5: runTest

import jdk.testlibrary.Utils; //导入依赖的package包/类
/**
 * Runs a test in a separate JVM.
 * command line like:
 * {test_jdk}/bin/java {defaultopts} -cp {test.class.path} {testopts} main
 *
 * {defaultopts} are the default java options set by the framework.
 * Default GC options in {defaultopts} may be removed.
 * This is used when the test specifies its own GC options.
 *
 * @param main Name of the main class.
 * @param clearGcOpts true if the default GC options should be removed.
 * @param testOpts java options specified by the test.
 */
private static void runTest(String main, boolean clearGcOpts, String... testOpts)
            throws Throwable {
    List<String> opts = new ArrayList<>();
    opts.add(JDKToolFinder.getJDKTool("java"));
    opts.addAll(Arrays.asList(Utils.getTestJavaOpts()));
    opts.add("-cp");
    opts.add(System.getProperty("test.class.path", "test.class.path"));
    opts.add("-XX:+PrintGCDetails");

    if (clearGcOpts) {
        opts = Utils.removeGcOpts(opts);
    }
    opts.addAll(Arrays.asList(testOpts));
    opts.add(main);

    OutputAnalyzer output = ProcessTools.executeProcess(opts.toArray(new String[0]));
    output.shouldHaveExitValue(0);
    if (output.getStdout().indexOf(successMessage) < 0) {
        throw new Exception("output missing '" + successMessage + "'");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:35,代码来源:RunUtil.java

示例6: run

import jdk.testlibrary.Utils; //导入依赖的package包/类
protected void run() throws Exception {
    OutputAnalyzer out;
    int retries = 1;
    boolean tryAgain;

    do {
        tryAgain = false;
        jmxPort = Utils.getFreePort();
        out = runVM();
        try {
            out.shouldNotContain("Port already in use");
        } catch (RuntimeException e) {
            if (retries < 3) {
                retries++;
                tryAgain = true;
            }
        }
    } while (tryAgain);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:DynamicLauncher.java

示例7: parsePid

import jdk.testlibrary.Utils; //导入依赖的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;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:28,代码来源:JstatdTest.java

示例8: verifyJpsOutput

import jdk.testlibrary.Utils; //导入依赖的package包/类
/**
 * Verifies output form jps contains pids and programs' name information.
 * The function will discard any lines that come before the first line with pid.
 * This can happen if the JVM outputs a warning message for some reason
 * before running jps.
 *
 * The output can look like:
 * 35536 Jstatd
 * 35417 Main
 * 31103 org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
 */
private void verifyJpsOutput(OutputAnalyzer output) throws Exception {
    output.shouldHaveExitValue(0);
    assertFalse(output.getOutput().isEmpty(), "Output should not be empty");

    boolean foundFirstLineWithPid = false;
    String[] lines = output.getOutput().split(Utils.NEW_LINE);
    for (String line : lines) {
        if (!foundFirstLineWithPid) {
            foundFirstLineWithPid = line.matches(JPS_OUTPUT_REGEX);
            continue;
        }
        assertTrue(line.matches(JPS_OUTPUT_REGEX),
                "Output does not match the pattern" + Utils.NEW_LINE + line);
    }
    assertTrue(foundFirstLineWithPid, "Invalid output");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:28,代码来源:JstatdTest.java

示例9: parse

import jdk.testlibrary.Utils; //导入依赖的package包/类
/**
 * The function will discard any lines that come before the header line.
 * This can happen if the JVM outputs a warning message for some reason
 * before running jstat.
 */
public void parse(int samples) throws Exception {
    boolean headlineFound = false;
    int datalineCount = 0;

    String[] lines = output.split(Utils.NEW_LINE);
    for (String line : lines) {
        line = line.replaceAll("\\s+", " ").trim();
        String[] valueArray = line.split(" ");

        if (!headlineFound) {
            headlineFound = GcStatistics.isHeadline(valueArray);
            continue;
        }

        GcStatistics.verify(valueArray);
        datalineCount++;
    }

    assertTrue(headlineFound, "No or invalid headline found, expected: " +
            Utils.NEW_LINE + Arrays.toString(GcStatistics.values()).replaceAll(",", " "));
    assertEquals(samples, datalineCount,
            "Expected " + samples + " samples, got " + datalineCount);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:29,代码来源:JstatGCUtilParser.java

示例10: main

import jdk.testlibrary.Utils; //导入依赖的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 = ProcessTools.executeProcess(pb);
    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");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:NoPremainAgentTest.java

示例11: main

import jdk.testlibrary.Utils; //导入依赖的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 = ProcessTools.executeProcess(pb);
    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!");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:PremainClassTest.java

示例12: main

import jdk.testlibrary.Utils; //导入依赖的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 = ProcessTools.executeProcess(pb);
    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");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:ZeroArgPremainAgentTest.java

示例13: runTest

import jdk.testlibrary.Utils; //导入依赖的package包/类
/**
 * Runs a test in a separate JVM.
 * command line like:
 * {test_jdk}/bin/java {defaultopts} -cp {test.class.path} {testopts} main
 *
 * {defaultopts} are the default java options set by the framework.
 * Default GC options in {defaultopts} may be removed.
 * This is used when the test specifies its own GC options.
 *
 * @param main Name of the main class.
 * @param clearGcOpts true if the default GC options should be removed.
 * @param testOpts java options specified by the test.
 */
private static void runTest(String main, boolean clearGcOpts, String... testOpts)
            throws Throwable {
    List<String> opts = new ArrayList<>();
    opts.add(JDKToolFinder.getJDKTool("java"));
    opts.addAll(Arrays.asList(Utils.getTestJavaOpts()));
    opts.add("-cp");
    opts.add(System.getProperty("test.class.path", "test.class.path"));
    opts.add("-Xlog:gc*=debug");

    if (clearGcOpts) {
        opts = Utils.removeGcOpts(opts);
    }
    opts.addAll(Arrays.asList(testOpts));
    opts.add(main);

    OutputAnalyzer output = ProcessTools.executeProcess(opts.toArray(new String[0]));
    output.shouldHaveExitValue(0);
    if (output.getStdout().indexOf(successMessage) < 0) {
        throw new Exception("output missing '" + successMessage + "'");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:35,代码来源:RunUtil.java

示例14: main

import jdk.testlibrary.Utils; //导入依赖的package包/类
public static void main(String[] args) throws IOException,
        MonitorException, URISyntaxException {
    LingeredApp app = null;
    try {
        List<String> vmArgs = new ArrayList<String>();
        vmArgs.add("-XX:+UsePerfData");
        vmArgs.addAll(Utils.getVmOptions());
        app = LingeredApp.startApp(vmArgs);

        MonitoredHost localHost = MonitoredHost.getMonitoredHost("localhost");
        String uriString = "//" + app.getPid() + "?mode=r"; // NOI18N
        VmIdentifier vmId = new VmIdentifier(uriString);
        MonitoredVm vm = localHost.getMonitoredVm(vmId);
        System.out.println("Monitored vm command line: " + MonitoredVmUtil.commandLine(vm));

        vm.setInterval(INTERVAL);
        localHost.setInterval(INTERVAL);

        Asserts.assertEquals(vm.getInterval(), INTERVAL, "Monitored vm interval should be equal the test value");
        Asserts.assertEquals(localHost.getInterval(), INTERVAL, "Monitored host interval should be equal the test value");
    } finally {
        LingeredApp.stopApp(app);
    }

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:TestPollingInterval.java

示例15: run

import jdk.testlibrary.Utils; //导入依赖的package包/类
protected void run() throws Exception {
    int retries = 1;
    boolean tryAgain;

    do {
        tryAgain = false;
        jmxPort = Utils.getFreePort();
        output = runVM();
        try {
            output.shouldNotContain("Port already in use");
        } catch (RuntimeException e) {
            if (retries < 3) {
                retries++;
                tryAgain = true;
            }
        }
    } while (tryAgain);
    output.shouldHaveExitValue(0);
    // java.lang.Exception is thrown by JdpTestCase if something goes wrong
    // for instance - see JdpTestCase::shutdown()
    output.shouldNotContain("java.lang.Exception:");
    output.shouldNotContain("Error: Could not find or load main class");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:DynamicLauncher.java


注:本文中的jdk.testlibrary.Utils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。