Java Code Examples for com.oracle.java.testlibrary.OutputAnalyzer#shouldContain()

The following examples show how to use com.oracle.java.testlibrary.OutputAnalyzer#shouldContain() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestExitOnOutOfMemoryError.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (args.length == 1) {
        // This should guarantee to throw:
        // java.lang.OutOfMemoryError: Requested array size exceeds VM limit
        try {
            Object[] oa = new Object[Integer.MAX_VALUE];
            throw new Error("OOME not triggered");
        } catch (OutOfMemoryError err) {
            throw new Error("OOME didn't terminate JVM!");
        }
    }

    // else this is the main test
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+ExitOnOutOfMemoryError",
            "-Xmx64m", TestExitOnOutOfMemoryError.class.getName(), "throwOOME");
    OutputAnalyzer output = new OutputAnalyzer(pb.start());

    /*
     * Actual output should look like this:
     * Terminating due to java.lang.OutOfMemoryError: Requested array size exceeds VM limit
     */
    output.shouldHaveExitValue(3);
    output.shouldContain("Terminating due to java.lang.OutOfMemoryError: Requested array size exceeds VM limit");
    System.out.println("PASSED");
}
 
Example 2
Source File: FinalizerInfoTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
void run() throws Exception {
    try {
        lock.lock();
        for(int i = 0; i < objectsCount; ++i) {
            new MyObject();
        }
        System.out.println("Objects initialized: " + objectsCount);
        System.gc();

        while(wasTrapped < 1) {
            // Waiting for gc thread.
        }


        String pid = Integer.toString(ProcessTools.getProcessId());
        ProcessBuilder pb = new ProcessBuilder();
        pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, cmd});
        OutputAnalyzer output = new OutputAnalyzer(pb.start());
        output.shouldContain("MyObject");
    } finally {
        lock.unlock();
    }
}
 
Example 3
Source File: TestG1TraceEagerReclaimHumongousObjects.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private static void testGCLogs() throws Exception {

    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
                                               "-Xms128M",
                                               "-Xmx128M",
                                               "-Xmn16M",
                                               "-XX:G1HeapRegionSize=1M",
                                               "-XX:+PrintGC",
                                               "-XX:+UnlockExperimentalVMOptions",
                                               "-XX:G1LogLevel=finest",
                                               "-XX:+G1TraceEagerReclaimHumongousObjects",
                                               GCTest.class.getName());

    OutputAnalyzer output = new OutputAnalyzer(pb.start());

    // As G1EagerReclaimHumongousObjects is set(default), below logs should be displayed.
    // And GCTest doesn't have humongous objects, so values should be zero.
    output.shouldContain("[Humongous Reclaim");
    output.shouldContain("[Humongous Total: 0]");
    output.shouldContain("[Humongous Candidate: 0]");
    output.shouldContain("[Humongous Reclaimed: 0]");

    output.shouldHaveExitValue(0);
  }
 
Example 4
Source File: TestMisc.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static void checkContainerInfo(OutputAnalyzer out) throws Exception {
    String[] expectedToContain = new String[] {
        "cpuset.cpus",
        "cpuset.mems",
        "CPU Shares",
        "CPU Quota",
        "CPU Period",
        "OSContainer::active_processor_count",
        "Memory Limit",
        "Memory Soft Limit",
        "Memory Usage",
        "Maximum Memory Usage",
        "memory_max_usage_in_bytes"
    };

    for (String s : expectedToContain) {
        out.shouldContain(s);
    }
}
 
Example 5
Source File: TestVerifyDuringStartup.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
  ArrayList<String> vmOpts = new ArrayList();

  String testVmOptsStr = System.getProperty("test.java.opts");
  if (!testVmOptsStr.isEmpty()) {
    String[] testVmOpts = testVmOptsStr.split(" ");
    Collections.addAll(vmOpts, testVmOpts);
  }
  Collections.addAll(vmOpts, new String[] {"-XX:-UseTLAB",
                                           "-XX:+UnlockDiagnosticVMOptions",
                                           "-XX:+VerifyDuringStartup",
                                           "-version"});

  System.out.print("Testing:\n" + JDKToolFinder.getJDKTool("java"));
  for (int i = 0; i < vmOpts.size(); i += 1) {
    System.out.print(" " + vmOpts.get(i));
  }
  System.out.println();

  ProcessBuilder pb =
    ProcessTools.createJavaProcessBuilder(vmOpts.toArray(new String[vmOpts.size()]));
  OutputAnalyzer output = new OutputAnalyzer(pb.start());

  System.out.println("Output:\n" + output.getOutput());

  output.shouldContain("[Verifying");
  output.shouldHaveExitValue(0);
}
 
Example 6
Source File: TestDefaultMaxRAMFraction.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:DefaultMaxRAMFraction=4", "-version");
  OutputAnalyzer output = new OutputAnalyzer(pb.start());
  output.shouldContain("warning: DefaultMaxRAMFraction is deprecated and will likely be removed in a future release. Use MaxRAMFraction instead.");
  output.shouldNotContain("error");
  output.shouldHaveExitValue(0);
}
 
Example 7
Source File: TestDefaultMaxRAMFraction.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:DefaultMaxRAMFraction=4", "-version");
  OutputAnalyzer output = new OutputAnalyzer(pb.start());
  output.shouldContain("warning: DefaultMaxRAMFraction is deprecated and will likely be removed in a future release. Use MaxRAMFraction instead.");
  output.shouldNotContain("error");
  output.shouldHaveExitValue(0);
}
 
Example 8
Source File: MaxMetaspaceSizeTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String... args) throws Exception {
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
        "-Xmx1g",
        "-XX:InitialBootClassLoaderMetaspaceSize=4195328",
        "-XX:MaxMetaspaceSize=4195328",
        "-XX:+UseCompressedClassPointers",
        "-XX:CompressedClassSpaceSize=1g",
        "-version");
    OutputAnalyzer output = new OutputAnalyzer(pb.start());
    output.shouldContain("MaxMetaspaceSize is too small.");
}
 
Example 9
Source File: TestStringSymbolTableStats.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
                                                              "-XX:+UnlockExperimentalVMOptions",
                                                              "-XX:+G1TraceStringSymbolTableScrubbing",
                                                              SystemGCTest.class.getName());

    OutputAnalyzer output = new OutputAnalyzer(pb.start());

    System.out.println("Output:\n" + output.getOutput());

    output.shouldContain("Cleaned string and symbol table");
    output.shouldHaveExitValue(0);
  }
 
Example 10
Source File: HeapInfoTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    String pid = Integer.toString(ProcessTools.getProcessId());
    ProcessBuilder pb = new ProcessBuilder();
    pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "GC.heap_info"});
    OutputAnalyzer output = new OutputAnalyzer(pb.start());
    output.shouldContain("Metaspace");
}
 
Example 11
Source File: TestCMSForegroundFlags.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  if (args.length != 2) {
    throw new Exception("Expected two arguments,flagValue and flagName");
  }
  String flagValue = args[0];
  String flagName = args[1];

  ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(flagValue, "-version");
  OutputAnalyzer output = new OutputAnalyzer(pb.start());
  output.shouldContain("warning: " + flagName + " is deprecated and will likely be removed in a future release.");
  output.shouldNotContain("error");
  output.shouldHaveExitValue(0);
}
 
Example 12
Source File: TestDefNewCMS.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
  ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:-UseParNewGC", "-XX:+UseConcMarkSweepGC", "-version");
  OutputAnalyzer output = new OutputAnalyzer(pb.start());
  output.shouldContain("warning: Using the DefNew young collector with the CMS collector is deprecated and will likely be removed in a future release");
  output.shouldNotContain("error");
  output.shouldHaveExitValue(0);
}
 
Example 13
Source File: TestGCLogMessages.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
void checkMessagesAtLevel(OutputAnalyzer output, LogMessageWithLevel messages[], Level level) throws Exception {
    for (LogMessageWithLevel l : messages) {
        if (level.lessOrEqualTo(l.level)) {
            output.shouldNotContain(l.message);
        } else {
            output.shouldContain(l.message);
        }
    }
}
 
Example 14
Source File: TestParNewSerialOld.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
  ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseParNewGC", "-version");
  OutputAnalyzer output = new OutputAnalyzer(pb.start());
  output.shouldContain("warning: Using the ParNew young collector with the Serial old collector is deprecated and will likely be removed in a future release");
  output.shouldNotContain("error");
  output.shouldHaveExitValue(0);
}
 
Example 15
Source File: TestStringSymbolTableStats.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
                                                              "-XX:+UnlockExperimentalVMOptions",
                                                              "-XX:+G1TraceStringSymbolTableScrubbing",
                                                              SystemGCTest.class.getName());

    OutputAnalyzer output = new OutputAnalyzer(pb.start());

    System.out.println("Output:\n" + output.getOutput());

    output.shouldContain("Cleaned string and symbol table");
    output.shouldHaveExitValue(0);
  }
 
Example 16
Source File: TestDynamicNumberOfGCThreads.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private static void verifyDynamicNumberOfGCThreads(OutputAnalyzer output) {
  output.shouldHaveExitValue(0); // test should run succesfully
  output.shouldContain("new_active_workers");
}
 
Example 17
Source File: JMapHProfLargeHeapTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private static void testHProfFileFormat(String vmArgs, long heapSize,
        String expectedFormat) throws Exception, IOException,
        InterruptedException, FileNotFoundException {
    ProcessBuilder procBuilder = ProcessTools.createJavaProcessBuilder(
            vmArgs, "JMapHProfLargeHeapProc", String.valueOf(heapSize));
    procBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
    Process largeHeapProc = procBuilder.start();

    try (Scanner largeHeapScanner = new Scanner(
            largeHeapProc.getInputStream());) {
        String pidstring = null;
        while ((pidstring = largeHeapScanner.findInLine("PID\\[[0-9].*\\]")) == null) {
            Thread.sleep(500);
        }
        int pid = Integer.parseInt(pidstring.substring(4,
                pidstring.length() - 1));
        System.out.println("Extracted pid: " + pid);

        JDKToolLauncher jMapLauncher = JDKToolLauncher
                .createUsingTestJDK("jmap");
        jMapLauncher.addToolArg("-dump:format=b,file=" + pid + "-"
                + HEAP_DUMP_FILE_NAME);
        jMapLauncher.addToolArg(String.valueOf(pid));

        ProcessBuilder jMapProcessBuilder = new ProcessBuilder(
                jMapLauncher.getCommand());
        System.out.println("jmap command: "
                + Arrays.toString(jMapLauncher.getCommand()));

        Process jMapProcess = jMapProcessBuilder.start();
        OutputAnalyzer analyzer = new OutputAnalyzer(jMapProcess);
        analyzer.shouldHaveExitValue(0);
        analyzer.shouldContain(pid + "-" + HEAP_DUMP_FILE_NAME);
        analyzer.shouldContain("Heap dump file created");

        largeHeapProc.getOutputStream().write('\n');

        File dumpFile = new File(pid + "-" + HEAP_DUMP_FILE_NAME);
        Asserts.assertTrue(dumpFile.exists(), "Heap dump file not found.");

        try (Reader reader = new BufferedReader(new FileReader(dumpFile))) {
            CharBuffer buf = CharBuffer.allocate(expectedFormat.length());
            reader.read(buf);
            buf.clear();
            Asserts.assertEQ(buf.toString(), expectedFormat,
                    "Wrong file format. Expected '" + expectedFormat
                            + "', but found '" + buf.toString() + "'");
        }

        System.out.println("Success!");

    } finally {
        largeHeapProc.destroyForcibly();
    }
}
 
Example 18
Source File: TestMetaspaceSizeFlags.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private static void testTooSmallInitialMetaspace(long maxMetaspaceSize, long metaspaceSize) throws Exception {
  OutputAnalyzer output = run(maxMetaspaceSize, metaspaceSize);
  output.shouldContain("Too small initial Metaspace size");
}
 
Example 19
Source File: AvailableProcessors.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Throwable {
    if (args.length > 0)
        checkProcessors(Integer.parseInt(args[0]));
    else {
        // run ourselves under different cpu configurations
        // using the taskset command
        String taskset;
        final String taskset1 = "/bin/taskset";
        final String taskset2 = "/usr/bin/taskset";
        if (new File(taskset1).exists())
            taskset = taskset1;
        else if (new File(taskset2).exists())
            taskset = taskset2;
        else {
            System.out.println("Skipping test: could not find taskset command");
            return;
        }

        int available = Runtime.getRuntime().availableProcessors();

        if (available == 1) {
            System.out.println("Skipping test: only one processor available");
            return;
        }

        // Get the java command we want to execute
        // Enable logging for easier failure diagnosis
        ProcessBuilder master =
                ProcessTools.createJavaProcessBuilder(false,
                                                      "-XX:+UnlockDiagnosticVMOptions",
                                                      "-XX:+PrintActiveCpus",
                                                      "AvailableProcessors");

        int[] expected = new int[] { 1, available/2, available-1, available };

        for (int i : expected) {
            System.out.println("Testing for " + i + " processors ...");
            int max = i - 1;
            ArrayList<String> cmdline = new ArrayList<>(master.command());
            // prepend taskset command
            cmdline.add(0, "0-" + max);
            cmdline.add(0, "-c");
            cmdline.add(0, taskset);
            // append expected processor count
            cmdline.add(String.valueOf(i));
            ProcessBuilder pb = new ProcessBuilder(cmdline);
            System.out.println("Final command line: " +
                               ProcessTools.getCommandLine(pb));
            OutputAnalyzer output = ProcessTools.executeProcess(pb);
            output.shouldContain(SUCCESS_STRING);
        }
    }
}
 
Example 20
Source File: TestPrintGCDetails.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 3 votes vote down vote up
public static void main(String[] args) throws Exception {

    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
                                                              "-XX:+PrintGCDetails",
                                                              SystemGCTest.class.getName());

    OutputAnalyzer output = new OutputAnalyzer(pb.start());

    System.out.println("Output:\n" + output.getOutput());

    output.shouldContain("Metaspace");
    output.shouldHaveExitValue(0);
  }