Java Code Examples for com.oracle.java.testlibrary.Asserts#assertTrue()

The following examples show how to use com.oracle.java.testlibrary.Asserts#assertTrue() . 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: TestOldGenCollectionUsage.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public void provokeMixedGC() {
    waitTillCMCFinished(0);
    WB.g1StartConcMarkCycle();
    waitTillCMCFinished(0);
    WB.youngGC();

    System.out.println("Allocating new objects to provoke mixed GC");
    // Provoke a mixed collection. G1MixedGCLiveThresholdPercent=100
    // guarantees that full old gen regions will be included.
    for (int i = 0; i < (ALLOCATION_COUNT * 20); i++) {
        try {
            newObjects.add(new byte[ALLOCATION_SIZE]);
        } catch (OutOfMemoryError e) {
            newObjects.clear();
            WB.youngGC();
            WB.youngGC();
            System.out.println("OutOfMemoryError is reported, stop allocating new objects");
            break;
        }
    }
    // check that liveOldObjects still alive
    Asserts.assertTrue(WB.isObjectInOldGen(liveOldObjects),
                       "List of the objects is suppose to be in OldGen");
}
 
Example 2
Source File: TestObjectClone.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    TestObjectClone[] params1 = {a, a, a, a, a, a, a, a, a, a, a,
                      a, a, a, a, a, a, a, a, a, a, a,
                      a, a, a, a, a, a, a, a, a, a, a,
                      b, c, d};

    for (int i = 0; i < 15000; i++) {
        f(params1[i % params1.length]);
    }

    Asserts.assertTrue(f(a) != a);
    Asserts.assertTrue(f(b) == b);
    Asserts.assertTrue(f(c) == c);
    Asserts.assertTrue(f(d) == d);

    try {
        f(null);
        throw new AssertionError("");
    } catch (NullPointerException e) { /* expected */ }

    System.out.println("TEST PASSED");
}
 
Example 3
Source File: TestClassUnloadingDisabled.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 {
    final WhiteBox wb = WhiteBox.getWhiteBox();
    // Fetch the dir where the test class and the class
    // to be loaded resides.
    String classDir = TestClassUnloadingDisabled.class.getProtectionDomain().getCodeSource().getLocation().getPath();
    String className = "ClassToLoadUnload";

    Asserts.assertFalse(wb.isClassAlive(className), "Should not be loaded yet");

    // The NoPDClassLoader handles loading classes in the test directory
    // and loads them without a protection domain, which in some cases
    // keeps the class live regardless of marking state.
    NoPDClassLoader nopd = new NoPDClassLoader(classDir);
    nopd.loadClass(className);

    Asserts.assertTrue(wb.isClassAlive(className), "Class should be loaded");

    // Clear the class-loader, class and object references to make
    // class unloading possible.
    nopd = null;

    System.gc();
    Asserts.assertTrue(wb.isClassAlive(className), "Class should not have ben unloaded");
}
 
Example 4
Source File: TestOldGenCollectionUsage.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public void allocateOldObjects() {
    List<byte[]> deadOldObjects = new ArrayList<>();
    // Allocates buffer and promotes it to the old gen. Mix live and dead old
    // objects
    for (int i = 0; i < ALLOCATION_COUNT; ++i) {
        liveOldObjects.add(new byte[ALLOCATION_SIZE * 5]);
        deadOldObjects.add(new byte[ALLOCATION_SIZE * 5]);
    }

    // Do two young collections, MaxTenuringThreshold=1 will force promotion.
    // G1HeapRegionSize=1m guarantees that old gen regions will be filled.
    WB.youngGC();
    WB.youngGC();
    // Check it is promoted & keep alive
    Asserts.assertTrue(WB.isObjectInOldGen(liveOldObjects),
                       "List of the objects is suppose to be in OldGen");
    Asserts.assertTrue(WB.isObjectInOldGen(deadOldObjects),
                       "List of the objects is suppose to be in OldGen");
}
 
Example 5
Source File: SurvivorAlignmentTestMain.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a value parsed from a string with format
 * &lt;integer&gt;&lt;multiplier&gt;.
 */
private static long parseSize(String sizeString) {
    Matcher matcher = SIZE_REGEX.matcher(sizeString);
    Asserts.assertTrue(matcher.matches(),
            "sizeString should have following format \"[0-9]+([MBK])?\"");
    long size = Long.valueOf(matcher.group("size"));

    if (matcher.group("multiplier") != null) {
        long K = 1024L;
        // fall through multipliers
        switch (matcher.group("multiplier").toLowerCase()) {
            case "g":
                size *= K;
            case "m":
                size *= K;
            case "k":
                size *= K;
        }
    }
    return size;
}
 
Example 6
Source File: TestObjectClone.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    TestObjectClone[] params1 = {a, a, a, a, a, a, a, a, a, a, a,
                      a, a, a, a, a, a, a, a, a, a, a,
                      a, a, a, a, a, a, a, a, a, a, a,
                      b, c, d};

    for (int i = 0; i < 15000; i++) {
        f(params1[i % params1.length]);
    }

    Asserts.assertTrue(f(a) != a);
    Asserts.assertTrue(f(b) == b);
    Asserts.assertTrue(f(c) == c);
    Asserts.assertTrue(f(d) == d);

    try {
        f(null);
        throw new AssertionError("");
    } catch (NullPointerException e) { /* expected */ }

    System.out.println("TEST PASSED");
}
 
Example 7
Source File: TestCPUSets.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void checkResult(List<String> lines, String lineMarker, String value) {
    boolean lineMarkerFound = false;

    for (String line : lines) {
        if (line.contains(lineMarker)) {
            lineMarkerFound = true;
            String[] parts = line.split(":");
            System.out.println("DEBUG: line = " + line);
            System.out.println("DEBUG: parts.length = " + parts.length);

            Asserts.assertEquals(parts.length, 2);
            String set = parts[1].replaceAll("\\s","");
            String actual = CPUSetsReader.listToString(CPUSetsReader.parseCpuSet(set));
            Asserts.assertEquals(actual, value);
            break;
        }
    }
    Asserts.assertTrue(lineMarkerFound);
}
 
Example 8
Source File: TestObjectClone.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 {
    TestObjectClone[] params1 = {a, a, a, a, a, a, a, a, a, a, a,
                      a, a, a, a, a, a, a, a, a, a, a,
                      a, a, a, a, a, a, a, a, a, a, a,
                      b, c, d};

    for (int i = 0; i < 15000; i++) {
        f(params1[i % params1.length]);
    }

    Asserts.assertTrue(f(a) != a);
    Asserts.assertTrue(f(b) == b);
    Asserts.assertTrue(f(c) == c);
    Asserts.assertTrue(f(d) == d);

    try {
        f(null);
        throw new AssertionError("");
    } catch (NullPointerException e) { /* expected */ }

    System.out.println("TEST PASSED");
}
 
Example 9
Source File: TestMutuallyExclusivePlatformPredicates.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Verifies that all predicates defined in
 * {@link com.oracle.java.testlibrary.Platform} were either tested or
 * explicitly ignored.
 */
private static void verifyCoverage() {
    Set<String> allMethods = new HashSet<>();
    for (MethodGroup group : MethodGroup.values()) {
        allMethods.addAll(group.methodNames);
    }

    for (Method m : Platform.class.getMethods()) {
        if (m.getParameterCount() == 0
                && m.getReturnType() == boolean.class) {
            Asserts.assertTrue(allMethods.contains(m.getName()),
                    "All Platform's methods with signature '():Z' should "
                            + "be tested ");
        }
    }
}
 
Example 10
Source File: TestMutuallyExclusivePlatformPredicates.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Verifies that all predicates defined in
 * {@link com.oracle.java.testlibrary.Platform} were either tested or
 * explicitly ignored.
 */
private static void verifyCoverage() {
    Set<String> allMethods = new HashSet<>();
    for (MethodGroup group : MethodGroup.values()) {
        allMethods.addAll(group.methodNames);
    }

    for (Method m : Platform.class.getMethods()) {
        if (m.getParameterCount() == 0
                && m.getReturnType() == boolean.class) {
            Asserts.assertTrue(allMethods.contains(m.getName()),
                    "All Platform's methods with signature '():Z' should "
                            + "be tested ");
        }
    }
}
 
Example 11
Source File: TestMutuallyExclusivePlatformPredicates.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Verifies that all predicates defined in
 * {@link com.oracle.java.testlibrary.Platform} were either tested or
 * explicitly ignored.
 */
private static void verifyCoverage() {
    Set<String> allMethods = new HashSet<>();
    for (MethodGroup group : MethodGroup.values()) {
        allMethods.addAll(group.methodNames);
    }

    for (Method m : Platform.class.getMethods()) {
        if (m.getParameterCount() == 0
                && m.getReturnType() == boolean.class) {
            Asserts.assertTrue(allMethods.contains(m.getName()),
                    "All Platform's methods with signature '():Z' should "
                            + "be tested ");
        }
    }
}
 
Example 12
Source File: TestMemoryMXBeansAndPoolsPresence.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    switch (args[0]) {
        case "G1":
            test(new GCBeanDescription("G1 Young Generation", new String[] {"G1 Eden Space", "G1 Survivor Space", "G1 Old Gen"}),
                 new GCBeanDescription("G1 Old Generation",   new String[] {"G1 Eden Space", "G1 Survivor Space", "G1 Old Gen"}));
            break;
        case "CMS":
            test(new GCBeanDescription("ParNew",              new String[] {"Par Eden Space", "Par Survivor Space"}),
                 new GCBeanDescription("ConcurrentMarkSweep", new String[] {"Par Eden Space", "Par Survivor Space", "CMS Old Gen"}));
            break;
        case "Parallel":
            test(new GCBeanDescription("PS Scavenge",         new String[] {"PS Eden Space", "PS Survivor Space"}),
                 new GCBeanDescription("PS MarkSweep",        new String[] {"PS Eden Space", "PS Survivor Space", "PS Old Gen"}));
            break;
        case "Serial":
            test(new GCBeanDescription("Copy",              new String[] {"Eden Space", "Survivor Space"}),
                 new GCBeanDescription("MarkSweepCompact",  new String[] {"Eden Space", "Survivor Space", "Tenured Gen"}));
            break;
        default:
            Asserts.assertTrue(false);
            break;

    }
}
 
Example 13
Source File: TestOldGenCollectionUsage.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public void allocateOldObjects() {
    List<byte[]> deadOldObjects = new ArrayList<>();
    // Allocates buffer and promotes it to the old gen. Mix live and dead old
    // objects
    for (int i = 0; i < ALLOCATION_COUNT; ++i) {
        liveOldObjects.add(new byte[ALLOCATION_SIZE * 5]);
        deadOldObjects.add(new byte[ALLOCATION_SIZE * 5]);
    }

    // Do two young collections, MaxTenuringThreshold=1 will force promotion.
    // G1HeapRegionSize=1m guarantees that old gen regions will be filled.
    WB.youngGC();
    WB.youngGC();
    // Check it is promoted & keep alive
    Asserts.assertTrue(WB.isObjectInOldGen(liveOldObjects),
                       "List of the objects is suppose to be in OldGen");
    Asserts.assertTrue(WB.isObjectInOldGen(deadOldObjects),
                       "List of the objects is suppose to be in OldGen");
}
 
Example 14
Source File: TestCheckJDK.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {
    String vmInstallDir = System.getProperty("java.home");

    Files.walk(Paths.get(vmInstallDir)).filter(Files::isRegularFile).forEach(TestCheckJDK::checkExecStack);

    Asserts.assertTrue(testPassed,
        "The tested VM contains libs that don't have the noexecstack " +
        "bit set. They must be linked with -z,noexecstack.");
}
 
Example 15
Source File: TestCheckJDK.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {
    String vmInstallDir = System.getProperty("java.home");

    Files.walk(Paths.get(vmInstallDir)).filter(Files::isRegularFile).forEach(TestCheckJDK::checkExecStack);

    Asserts.assertTrue(testPassed,
        "The tested VM contains libs that don't have the noexecstack " +
        "bit set. They must be linked with -z,noexecstack.");
}
 
Example 16
Source File: JMapHProfLargeHeapTest.java    From openjdk-8-source 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 17
Source File: JMapHProfLargeHeapTest.java    From openjdk-8 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: JMapHProfLargeHeapTest.java    From hottub 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 19
Source File: JMapHProfLargeHeapTest.java    From TencentKona-8 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 20
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();
    }
}