Java Code Examples for jdk.testlibrary.Asserts#assertNotEquals()

The following examples show how to use jdk.testlibrary.Asserts#assertNotEquals() . 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: TestEventMetadata.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void verifyEventType(EventType eventType) {
    System.out.println("Verifying event: " + eventType.getName());
    verifyDescription(eventType.getDescription());
    verifyLabel(eventType.getLabel());
    Asserts.assertNotEquals(eventType.getName(), null, "Name not allowed to be null");
    Asserts.assertTrue(eventType.getName().startsWith("com.oracle.jdk."), "Oracle events must start with com.oracle.jdk");
    String name = eventType.getName().substring("com.oracle.jdk.".length());
    Asserts.assertFalse(isReservedKeyword(name),"Name must not be reserved keyword in the Java language (" + name + ")");
    checkCommonAbbreviations(name);
      char firstChar = name.charAt(0);
    Asserts.assertFalse(name.contains("ID"), "'ID' should not be used in name, consider using 'Id'");
    Asserts.assertTrue(Character.isAlphabetic(firstChar), "Name " + name + " must start with a character");
    Asserts.assertTrue(Character.isUpperCase(firstChar), "Name " + name + " must start with upper case letter");
    for (int i = 0; i < name.length(); i++) {
        char c = name.charAt(i);
        Asserts.assertTrue(Character.isAlphabetic(c) || Character.isDigit(c), "Name " + name + " must consists of characters or numbers, found '" + name.charAt(i) + "'");
    }
}
 
Example 2
Source File: TestDestToDiskTrue.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Path dest = Paths.get(".", "my.jfr");
    Recording r = new Recording();
    r.enable(EventNames.OSInformation);
    r.setToDisk(true);
    r.setDestination(dest);
    Asserts.assertEquals(dest, r.getDestination(), "Wrong get/set destination");
    r.start();
    r.stop();

    Asserts.assertEquals(dest, r.getDestination(), "Wrong get/set destination after stop");

    Asserts.assertTrue(Files.exists(dest), "No recording file: " + dest);
    List<RecordedEvent> events = RecordingFile.readAllEvents(dest);
    Asserts.assertFalse(events.isEmpty(), "No event found");
    System.out.printf("Found event %s%n", events.get(0).getEventType().getName());
    System.out.printf("File size=%d, getSize()=%d%n", Files.size(dest), r.getSize());
    assertEquals(r.getSize(), 0L, "getSize() should return 0, chunks should have be released at stop");
    Asserts.assertNotEquals(Files.size(dest), 0L, "File length 0. Should at least be some bytes");
    r.close();
}
 
Example 3
Source File: TestDestWithDuration.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Path dest = Paths.get(".", "my.jfr");
    Recording r = new Recording();
    SimpleEventHelper.enable(r, true);
    r.setDestination(dest);
    r.start();
    SimpleEventHelper.createEvent(1);

    // Waiting for recording to auto close after duration
    r.setDuration(Duration.ofSeconds(1));
    System.out.println("Waiting for recording to auto close after duration");
    CommonHelper.waitForRecordingState(r, RecordingState.CLOSED);
    System.out.println("recording state = " + r.getState());
    Asserts.assertEquals(r.getState(), RecordingState.CLOSED, "Recording not closed");

    Asserts.assertTrue(Files.exists(dest), "No recording file: " + dest);
    System.out.printf("Recording file size=%d%n", Files.size(dest));
    Asserts.assertNotEquals(Files.size(dest), 0L, "File length 0. Should at least be some bytes");

    List<RecordedEvent> events = RecordingFile.readAllEvents(dest);
    Asserts.assertFalse(events.isEmpty(), "No event found");
    System.out.printf("Found event %s%n", events.get(0).getEventType().getName());
}
 
Example 4
Source File: TestEventMetadata.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void verifyName(String name) {
    System.out.println("Verifying name: " + name);
    Asserts.assertNotEquals(name, null, "Name not allowed to be null");
    Asserts.assertTrue(name.length() > 1, "Name must be at least two characters");
    Asserts.assertTrue(name.length() < 32, "Name should not exceed 32 characters");
    Asserts.assertFalse(isReservedKeyword(name),"Name must not be reserved keyword in the Java language (" + name + ")");
    char firstChar = name.charAt(0);
    Asserts.assertTrue(Character.isAlphabetic(firstChar), "Name must start with a character");
    Asserts.assertTrue(Character.isLowerCase(firstChar), "Name must start with lower case letter");
    Asserts.assertTrue(Character.isJavaIdentifierStart(firstChar), "Not valid first character for Java identifier");
    for (int i = 1; i < name.length(); i++) {
        Asserts.assertTrue(Character.isJavaIdentifierPart(name.charAt(i)), "Not valid character for a Java identifier");
        Asserts.assertTrue(Character.isAlphabetic(name.charAt(i)), "Name must consists of characters, found '" + name.charAt(i) + "'");
    }
    Asserts.assertFalse(name.contains("ID"), "'ID' should not be used in name, consider using 'Id'");
    checkCommonAbbreviations(name);
}
 
Example 5
Source File: TestEventMetadata.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void verifyLabel(String label) {
    Asserts.assertNotEquals(label, null, "Label not allowed to be null");
    Asserts.assertTrue(label.length() > 1, "Name must be at least two characters");
    Asserts.assertTrue(label.length() < 45, "Label should not exceed 45 characters, use description to explain " + label);
    Asserts.assertTrue(label.length() == label.trim().length(), "Label should not have trim character at start and end");
    Asserts.assertTrue(Character.isUpperCase(label.charAt(0)), "Label should start with upper case letter");
    for (int i = 0; i < label.length(); i++) {
        char c = label.charAt(i);
        Asserts.assertTrue(Character.isDigit(c) || Character.isAlphabetic(label.charAt(i)) || c == ' ' || c == '(' || c == ')' || c == '-', "Label should only consist of letters or space, found '" + label.charAt(i)
                + "'");
    }
}
 
Example 6
Source File: TestJpsSanity.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static void testJpsUnknownHost() throws Exception {
    String invalidHostName = "Oja781nh2ev7vcvbajdg-Sda1-C";
    OutputAnalyzer output = JpsHelper.jps(invalidHostName);
    Asserts.assertNotEquals(output.getExitValue(), 0, "Exit code shouldn't be 0");
    Asserts.assertFalse(output.getStderr().isEmpty(), "Error output should not be empty");
    output.shouldContain("Unknown host: " + invalidHostName);
}
 
Example 7
Source File: SerializedSeedTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Verify the similarity of random numbers generated though both original
 * as well as deserialized instance.
 */
private static void check(SecureRandom orig, SecureRandom copy,
        boolean equal, String mech) {
    int o = orig.nextInt();
    int c = copy.nextInt();
    System.out.printf("%nRandom number generated for mechanism: '%s' "
            + "from original instance as: '%s' and from serialized "
            + "instance as: '%s'", mech, o, c);
    if (equal) {
        Asserts.assertEquals(o, c, mech);
    } else {
        Asserts.assertNotEquals(o, c, mech);
    }
}
 
Example 8
Source File: TestJpsSanity.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void testJpsUnknownHost() throws Exception {
    String invalidHostName = "Oja781nh2ev7vcvbajdg-Sda1-C";
    OutputAnalyzer output = JpsHelper.jps(invalidHostName);
    Asserts.assertNotEquals(output.getExitValue(), 0, "Exit code shouldn't be 0");
    Asserts.assertFalse(output.getStderr().isEmpty(), "Error output should not be empty");
    output.shouldContain("Unknown host: " + invalidHostName);
}
 
Example 9
Source File: TestGetStackTraceId.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String... args) {
    FlightRecorder.getFlightRecorder();
    JVM jvm = JVM.getJVM();

    long id10 = getStackIdOfDepth(10);
    assertValid(id10);

    long id5 = getStackIdOfDepth(5);
    assertValid(id5);

    Asserts.assertNotEquals(id5, id10, "Different stack depth must return different stack trace ids");

    assertMaxSkip(jvm);
}
 
Example 10
Source File: TestGetTypeId.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    EventType type = EventType.getEventType(CustomEvent.class);

    SettingDescriptor plain = Events.getSetting(type, "plain");
    long plainId = plain.getTypeId();
    Asserts.assertGreaterThan(plainId, 0L);

    SettingDescriptor annotatedType = Events.getSetting(type, "annotatedType");
    long annotatedId = annotatedType.getTypeId();
    Asserts.assertGreaterThan(annotatedId, 0L);

    Asserts.assertNotEquals(annotatedId, plainId);

    SettingDescriptor newName = Events.getSetting(type, "newName");
    Asserts.assertEquals(newName.getTypeId(), annotatedId);

    SettingDescriptor overridden = Events.getSetting(type, "overridden");
    Asserts.assertEquals(overridden.getTypeId(), plainId);

    SettingDescriptor protectedBase = Events.getSetting(type, "protectedBase");
    Asserts.assertEquals(protectedBase.getTypeId(), plainId);

    SettingDescriptor publicBase = Events.getSetting(type, "publicBase");
    Asserts.assertEquals(publicBase.getTypeId(), annotatedId);

    SettingDescriptor packageProtectedBase = Events.getSetting(type, "packageProtectedBase");
    Asserts.assertEquals(packageProtectedBase.getTypeId(), plainId);

    CustomEvent.assertOnDisk((x, y) -> Long.compare(x.getTypeId(), y.getTypeId()));
}
 
Example 11
Source File: TestJpsSanity.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void testJpsUnknownHost() throws Exception {
    String invalidHostName = "Oja781nh2ev7vcvbajdg-Sda1-C";
    OutputAnalyzer output = JpsHelper.jps(invalidHostName);
    Asserts.assertNotEquals(output.getExitValue(), 0, "Exit code shouldn't be 0");
    Asserts.assertFalse(output.getStderr().isEmpty(), "Error output should not be empty");
    output.shouldContain("Unknown host: " + invalidHostName);
}
 
Example 12
Source File: TestGetSizeToMem.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Path dest = Paths.get(".", "my.jfr");
    Recording r = new Recording();
    r.setToDisk(false);
    r.setDestination(dest);
    r.enable(EventNames.OSInformation);
    r.start();
    r.stop();
    r.close();
    assertTrue(Files.exists(dest), "TestGetSize recording missing: " + dest);
    System.out.printf("%s size: %d%n", dest, Files.size(dest));
    System.out.printf("r.getSize(): %d%n", r.getSize());
    Asserts.assertNotEquals(Files.size(dest), 0L, "File should not be empty");
    assertEquals(r.getSize(), 0L, "r.getSize() should be 0 after setToDisk(false)");
}
 
Example 13
Source File: TestStreamMultiple.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean();

    SimpleEventHelper.createEvent(0); // No recordings

    long recIdA = bean.newRecording();

    bean.startRecording(recIdA);
    SimpleEventHelper.createEvent(1); // recA

    long recIdB = bean.newRecording();
    Asserts.assertNotEquals(recIdA, recIdB, "Recording Ids should be unique");
    bean.startRecording(recIdB);
    SimpleEventHelper.createEvent(2); // recA and recB

    bean.stopRecording(recIdA);
    SimpleEventHelper.createEvent(3); // recB

    bean.stopRecording(recIdB);
    SimpleEventHelper.createEvent(4); // No recordings

    // Check recA
    long streamIdA = bean.openStream(recIdA, null);
    List<RecordedEvent> events = JmxHelper.parseStream(streamIdA, bean);
    SimpleEventHelper.verifyContains(events, 1, 2);
    SimpleEventHelper.verifyNotContains(events, 0, 3, 4);
    bean.closeStream(streamIdA);
    // check recB
    long streamIdB = bean.openStream(recIdB, null);
    events = JmxHelper.parseStream(streamIdB, bean);
    SimpleEventHelper.verifyContains(events, 2, 3);
    SimpleEventHelper.verifyNotContains(events, 0, 1, 4);
    bean.closeStream(streamIdB);

    bean.closeRecording(recIdA);
    bean.closeRecording(recIdB);
}
 
Example 14
Source File: TestClone.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean();

    long orgId = bean.newRecording();
    bean.startRecording(orgId);
    SimpleEventHelper.createEvent(1); // Should be in both org and clone

    long cloneId = bean.cloneRecording(orgId, false);
    Asserts.assertNotEquals(orgId, cloneId, "clone id should not be same as org id");

    List<RecordingInfo> recordings = bean.getRecordings();
    JmxHelper.verifyState(orgId, RecordingState.RUNNING, recordings);
    JmxHelper.verifyState(cloneId, RecordingState.RUNNING, recordings);

    bean.stopRecording(orgId);
    recordings = bean.getRecordings();
    JmxHelper.verifyState(orgId, RecordingState.STOPPED, recordings);
    JmxHelper.verifyState(cloneId, RecordingState.RUNNING, recordings);

    SimpleEventHelper.createEvent(2);  // Should only be in clone

    bean.stopRecording(cloneId);
    recordings = bean.getRecordings();
    JmxHelper.verifyState(orgId, RecordingState.STOPPED, recordings);
    JmxHelper.verifyState(cloneId, RecordingState.STOPPED, recordings);

    Path orgPath = Paths.get(".", "org.jfr");
    Path clonePath = Paths.get(".", "clone.jfr");
    bean.copyTo(orgId, orgPath.toString());
    bean.copyTo(cloneId, clonePath.toString());

    verifyEvents(orgPath, 1);
    verifyEvents(clonePath, 1, 2);

    bean.closeRecording(orgId);
    bean.closeRecording(cloneId);
}
 
Example 15
Source File: TestDumpOnCrash.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void processOutput(OutputAnalyzer output) throws Exception {
    //output.shouldContain("CreateCoredumpOnCrash turned off, no core file dumped");

    final Path jfrEmergencyFilePath = getHsErrJfrPath(output);
    Asserts.assertTrue(Files.exists(jfrEmergencyFilePath), "No emergency jfr recording file " + jfrEmergencyFilePath + " exists");
    Asserts.assertNotEquals(Files.size(jfrEmergencyFilePath), 0L, "File length 0. Should at least be some bytes");
    System.out.printf("File size=%d%n", Files.size(jfrEmergencyFilePath));

    List<RecordedEvent> events = RecordingFile.readAllEvents(jfrEmergencyFilePath);
    Asserts.assertFalse(events.isEmpty(), "No event found");
    System.out.printf("Found event %s%n", events.get(0).getEventType().getName());
}
 
Example 16
Source File: TestJpsSanity.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
private static void testJpsVersion() throws Exception {
    OutputAnalyzer output = JpsHelper.jps("-version");
    Asserts.assertNotEquals(output.getExitValue(), 0, "Exit code shouldn't be 0");
    Asserts.assertFalse(output.getStderr().isEmpty(), "Error output should not be empty");
    output.shouldContain("illegal argument: -version");
}
 
Example 17
Source File: TestJpsSanity.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static void testJpsVersion() throws Exception {
    OutputAnalyzer output = JpsHelper.jps("-version");
    Asserts.assertNotEquals(output.getExitValue(), 0, "Exit code shouldn't be 0");
    Asserts.assertFalse(output.getStderr().isEmpty(), "Error output should not be empty");
    output.shouldContain("illegal argument: -version");
}
 
Example 18
Source File: TestJpsSanity.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private static void testJpsVersion() throws Exception {
    OutputAnalyzer output = JpsHelper.jps("-version");
    Asserts.assertNotEquals(output.getExitValue(), 0, "Exit code shouldn't be 0");
    Asserts.assertFalse(output.getStderr().isEmpty(), "Error output should not be empty");
    output.shouldContain("illegal argument: -version");
}
 
Example 19
Source File: TestJpsSanity.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private static void testJpsVersion() throws Exception {
    OutputAnalyzer output = JpsHelper.jps("-version");
    Asserts.assertNotEquals(output.getExitValue(), 0, "Exit code shouldn't be 0");
    Asserts.assertFalse(output.getStderr().isEmpty(), "Error output should not be empty");
    output.shouldContain("illegal argument: -version");
}
 
Example 20
Source File: TestJpsSanity.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private static void testJpsVersion() throws Exception {
    OutputAnalyzer output = JpsHelper.jps("-version");
    Asserts.assertNotEquals(output.getExitValue(), 0, "Exit code shouldn't be 0");
    Asserts.assertFalse(output.getStderr().isEmpty(), "Error output should not be empty");
    output.shouldContain("illegal argument: -version");
}