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

The following examples show how to use com.oracle.java.testlibrary.Asserts#assertEQ() . 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: TestMutuallyExclusivePlatformPredicates.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Verifies that one and only one predicate method defined in
 * {@link com.oracle.java.testlibrary.Platform}, whose name included into
 * methodGroup will return {@code true}.
 * @param methodGroup The group of methods that should be tested.
 */
private static void verifyPredicates(MethodGroup methodGroup) {
    System.out.println("Verifying method group: " + methodGroup.name());
    long truePredicatesCount = methodGroup.methodNames.stream()
            .filter(TestMutuallyExclusivePlatformPredicates
                    ::evaluatePredicate)
            .count();

    Asserts.assertEQ(truePredicatesCount, 1L, String.format(
            "Only one predicate from group %s should be evaluated to true "
                    + "(Actually %d predicates were evaluated to true).",
            methodGroup.name(), truePredicatesCount));
}
 
Example 2
Source File: TestMutuallyExclusivePlatformPredicates.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Verifies that one and only one predicate method defined in
 * {@link com.oracle.java.testlibrary.Platform}, whose name included into
 * methodGroup will return {@code true}.
 * @param methodGroup The group of methods that should be tested.
 */
private static void verifyPredicates(MethodGroup methodGroup) {
    System.out.println("Verifying method group: " + methodGroup.name());
    long truePredicatesCount = methodGroup.methodNames.stream()
            .filter(TestMutuallyExclusivePlatformPredicates
                    ::evaluatePredicate)
            .count();

    Asserts.assertEQ(truePredicatesCount, 1L, String.format(
            "Only one predicate from group %s should be evaluated to true "
                    + "(Actually %d predicates were evaluated to true).",
            methodGroup.name(), truePredicatesCount));
}
 
Example 3
Source File: SurvivorAlignmentTestMain.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns an SurvivorAlignmentTestMain instance constructed using CLI
 * options.
 *
 * Following options are expected:
 * <ul>
 *     <li>memoryToFill</li>
 *     <li>objectSize</li>
 * </ul>
 *
 * Both argument may contain multiplier suffix k, m or g.
 */
public static SurvivorAlignmentTestMain fromArgs(String[] args) {
    Asserts.assertEQ(args.length, 3, "Expected three arguments: "
            + "memory size, object size and tested heap space name.");

    long memoryToFill = parseSize(args[0]);
    long objectSize = Math.max(parseSize(args[1]),
            AlignmentHelper.MIN_ARRAY_SIZE);
    HeapSpace testedSpace = HeapSpace.valueOf(args[2]);

    return new SurvivorAlignmentTestMain(memoryToFill, objectSize,
            testedSpace);
}
 
Example 4
Source File: TestMetaspaceSizeFlags.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static void testMaxMetaspaceSizeGTMetaspaceSize(long maxMetaspaceSize, long metaspaceSize) throws Exception {
  MetaspaceFlags mf = runAndGetValue(maxMetaspaceSize, metaspaceSize);
  Asserts.assertGT(maxMetaspaceSize, metaspaceSize);
  Asserts.assertGT(mf.maxMetaspaceSize, mf.metaspaceSize);
  Asserts.assertEQ(mf.maxMetaspaceSize, maxMetaspaceSize);
  Asserts.assertEQ(mf.metaspaceSize, metaspaceSize);
}
 
Example 5
Source File: UseSHASpecificTestCaseForSupportedSparcCPU.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public UseSHASpecificTestCaseForSupportedSparcCPU(String optionName) {
    super(SHAOptionsBase.USE_SHA_OPTION, new AndPredicate(Platform::isSparc,
            IntrinsicPredicates.ANY_SHA_INSTRUCTION_AVAILABLE));

    Asserts.assertEQ(optionName, SHAOptionsBase.USE_SHA_OPTION,
            "Test case should be used for " + SHAOptionsBase.USE_SHA_OPTION
                    + " option only.");
}
 
Example 6
Source File: UseSHASpecificTestCaseForUnsupportedSparcCPU.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public UseSHASpecificTestCaseForUnsupportedSparcCPU(String optionName) {
    super(SHAOptionsBase.USE_SHA_OPTION, new AndPredicate(Platform::isSparc,
            new NotPredicate(
                    IntrinsicPredicates.ANY_SHA_INSTRUCTION_AVAILABLE)));

    Asserts.assertEQ(optionName, SHAOptionsBase.USE_SHA_OPTION,
            "Test case should be used for " + SHAOptionsBase.USE_SHA_OPTION
                    + " option only.");
}
 
Example 7
Source File: SurvivorAlignmentTestMain.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns an SurvivorAlignmentTestMain instance constructed using CLI
 * options.
 *
 * Following options are expected:
 * <ul>
 *     <li>memoryToFill</li>
 *     <li>objectSize</li>
 * </ul>
 *
 * Both argument may contain multiplier suffix k, m or g.
 */
public static SurvivorAlignmentTestMain fromArgs(String[] args) {
    Asserts.assertEQ(args.length, 3, "Expected three arguments: "
            + "memory size, object size and tested heap space name.");

    long memoryToFill = parseSize(args[0]);
    long objectSize = Math.max(parseSize(args[1]),
            AlignmentHelper.MIN_ARRAY_SIZE);
    HeapSpace testedSpace = HeapSpace.valueOf(args[2]);

    return new SurvivorAlignmentTestMain(memoryToFill, objectSize,
            testedSpace);
}
 
Example 8
Source File: TestMutuallyExclusivePlatformPredicates.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Verifies that one and only one predicate method defined in
 * {@link com.oracle.java.testlibrary.Platform}, whose name included into
 * methodGroup will return {@code true}.
 * @param methodGroup The group of methods that should be tested.
 */
private static void verifyPredicates(MethodGroup methodGroup) {
    System.out.println("Verifying method group: " + methodGroup.name());
    long truePredicatesCount = methodGroup.methodNames.stream()
            .filter(TestMutuallyExclusivePlatformPredicates
                    ::evaluatePredicate)
            .count();

    Asserts.assertEQ(truePredicatesCount, 1L, String.format(
            "Only one predicate from group %s should be evaluated to true "
                    + "(Actually %d predicates were evaluated to true).",
            methodGroup.name(), truePredicatesCount));
}
 
Example 9
Source File: TestMetaspaceSizeFlags.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static void testMaxMetaspaceSizeGTMetaspaceSize(long maxMetaspaceSize, long metaspaceSize) throws Exception {
  MetaspaceFlags mf = runAndGetValue(maxMetaspaceSize, metaspaceSize);
  Asserts.assertGT(maxMetaspaceSize, metaspaceSize);
  Asserts.assertGT(mf.maxMetaspaceSize, mf.metaspaceSize);
  Asserts.assertEQ(mf.maxMetaspaceSize, maxMetaspaceSize);
  Asserts.assertEQ(mf.metaspaceSize, metaspaceSize);
}
 
Example 10
Source File: UseSHASpecificTestCaseForUnsupportedSparcCPU.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public UseSHASpecificTestCaseForUnsupportedSparcCPU(String optionName) {
    super(SHAOptionsBase.USE_SHA_OPTION, new AndPredicate(Platform::isSparc,
            new NotPredicate(
                    IntrinsicPredicates.ANY_SHA_INSTRUCTION_AVAILABLE)));

    Asserts.assertEQ(optionName, SHAOptionsBase.USE_SHA_OPTION,
            "Test case should be used for " + SHAOptionsBase.USE_SHA_OPTION
                    + " option only.");
}
 
Example 11
Source File: TestMetaspaceSizeFlags.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private static void testMaxMetaspaceSizeEQMetaspaceSize(long maxMetaspaceSize, long metaspaceSize) throws Exception {
  MetaspaceFlags mf = runAndGetValue(maxMetaspaceSize, metaspaceSize);
  Asserts.assertEQ(maxMetaspaceSize, metaspaceSize);
  Asserts.assertEQ(mf.maxMetaspaceSize, maxMetaspaceSize);
  Asserts.assertEQ(mf.metaspaceSize, metaspaceSize);
}
 
Example 12
Source File: TestMetaspaceSizeFlags.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private static void testMaxMetaspaceSizeLTMetaspaceSize(long maxMetaspaceSize, long metaspaceSize) throws Exception {
  MetaspaceFlags mf = runAndGetValue(maxMetaspaceSize, metaspaceSize);
  Asserts.assertEQ(mf.maxMetaspaceSize, maxMetaspaceSize);
  Asserts.assertEQ(mf.metaspaceSize, maxMetaspaceSize);
}
 
Example 13
Source File: TestMetaspaceSizeFlags.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private static void testMaxMetaspaceSizeLTMetaspaceSize(long maxMetaspaceSize, long metaspaceSize) throws Exception {
  MetaspaceFlags mf = runAndGetValue(maxMetaspaceSize, metaspaceSize);
  Asserts.assertEQ(mf.maxMetaspaceSize, maxMetaspaceSize);
  Asserts.assertEQ(mf.metaspaceSize, maxMetaspaceSize);
}
 
Example 14
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 15
Source File: JMapHProfLargeHeapTest.java    From jdk8u60 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 16
Source File: TestMetaspaceSizeFlags.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private static void testMaxMetaspaceSizeLTMetaspaceSize(long maxMetaspaceSize, long metaspaceSize) throws Exception {
  MetaspaceFlags mf = runAndGetValue(maxMetaspaceSize, metaspaceSize);
  Asserts.assertEQ(mf.maxMetaspaceSize, maxMetaspaceSize);
  Asserts.assertEQ(mf.metaspaceSize, maxMetaspaceSize);
}
 
Example 17
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 18
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 19
Source File: TestMetaspaceSizeFlags.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private static void testMaxMetaspaceSizeEQMetaspaceSize(long maxMetaspaceSize, long metaspaceSize) throws Exception {
  MetaspaceFlags mf = runAndGetValue(maxMetaspaceSize, metaspaceSize);
  Asserts.assertEQ(maxMetaspaceSize, metaspaceSize);
  Asserts.assertEQ(mf.maxMetaspaceSize, maxMetaspaceSize);
  Asserts.assertEQ(mf.metaspaceSize, metaspaceSize);
}
 
Example 20
Source File: AbortProvoker.java    From hottub with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Verifies that {@code monitor} is a stack-lock or inflated lock depending
 * on {@code shouldBeInflated} value. If {@code monitor} is inflated while
 * it is expected that it should be a stack-lock, then this method attempts
 * to deflate it by forcing a safepoint and then verifies the state once
 * again.
 *
 * @param monitor monitor to be verified.
 * @param shouldBeInflated flag indicating whether or not monitor is
 *                         expected to be inflated.
 * @throws RuntimeException if the {@code monitor} in a wrong state.
 */
public static void verifyMonitorState(Object monitor,
        boolean shouldBeInflated) {
    if (!shouldBeInflated && WHITE_BOX.isMonitorInflated(monitor)) {
        WHITE_BOX.forceSafepoint();
    }
    Asserts.assertEQ(WHITE_BOX.isMonitorInflated(monitor), shouldBeInflated,
            "Monitor in a wrong state.");
}