Java Code Examples for jdk.test.lib.Asserts#assertFalse()

The following examples show how to use jdk.test.lib.Asserts#assertFalse() . 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: TestConstructor.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
    ValueDescriptor vdSimple = new ValueDescriptor(String.class, "message");
    Asserts.assertNull(vdSimple.getAnnotation(Label.class), "Expected getAnnotation()==null");
    Asserts.assertEquals(0, vdSimple.getAnnotationElements().size(), "Expected getAnnotations().size() == 0");

    // Add labelA and verify we can read it back
    List<AnnotationElement> annos = new ArrayList<>();
    AnnotationElement labelA = new AnnotationElement(Label.class, "labelA");
    annos.add(labelA);
    System.out.println("labelA.getClass()" + labelA.getClass());
    ValueDescriptor vdComplex = new ValueDescriptor(String.class, "message", annos);

    final Label outLabel = vdComplex.getAnnotation(Label.class);
    Asserts.assertFalse(outLabel == null, "getLabel(Label.class) was null");
    System.out.println("outLabel.value() = " + outLabel.value());

    // Get labelA from getAnnotations() list
    Asserts.assertEquals(1, vdComplex.getAnnotationElements().size(), "Expected getAnnotations().size() == 1");
    final AnnotationElement outAnnotation = vdComplex.getAnnotationElements().get(0);
    Asserts.assertNotNull(outAnnotation, "outAnnotation was null");
    System.out.printf("Annotation: %s = %s%n", outAnnotation.getTypeName(), outAnnotation.getValue("value"));
    Asserts.assertEquals(outAnnotation, labelA, "Expected firstAnnotation == labelA");

}
 
Example 2
Source File: TestDumpLongPath.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 {
    Recording r = new Recording();
    final String eventPath = EventNames.OSInformation;
    r.enable(eventPath);
    r.start();
    r.stop();

    Path dir = FileHelper.createLongDir(Paths.get("."));
    Path path = Paths.get(dir.toString(), "my.jfr");
    r.dump(path);
    r.close();

    Asserts.assertTrue(Files.exists(path), "Recording file does not exist: " + path);
    List<RecordedEvent> events = RecordingFile.readAllEvents(path);
    Asserts.assertFalse(events.isEmpty(), "No events found");
    String foundEventPath = events.get(0).getEventType().getName();
    System.out.printf("Found event: %s%n", foundEventPath);
    Asserts.assertEquals(foundEventPath, eventPath, "Wrong event");
}
 
Example 3
Source File: TestEventMetadata.java    From TencentKona-8 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(EventNames.PREFIX), "OpenJDK events must start with " + EventNames.PREFIX);
    String name = eventType.getName().substring(EventNames.PREFIX.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 4
Source File: TestDestWithDuration.java    From TencentKona-8 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 5
Source File: TestEventMetadata.java    From openjdk-jdk8u 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(EventNames.PREFIX), "OpenJDK events must start with " + EventNames.PREFIX);
    String name = eventType.getName().substring(EventNames.PREFIX.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 6
Source File: TestDestToDiskTrue.java    From TencentKona-8 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 7
Source File: TestEventMetadata.java    From TencentKona-8 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 8
Source File: TestRecordingCopy.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Verifies the basic assertions about a copied record
 */
private static void assertCopy(Recording recording, Recording original) throws Exception {

    Asserts.assertFalse(recording.getId() == original.getId(), "id of a copied record should differ from that of the original");
    Asserts.assertFalse(recording.getName().equals(original.getName()), "name of a copied record should differ from that of the original");

    Asserts.assertEquals(recording.getSettings(), original.getSettings());
    Asserts.assertEquals(recording.getStartTime(), original.getStartTime());
    Asserts.assertEquals(recording.getMaxSize(), original.getMaxSize());
    Asserts.assertEquals(recording.getMaxAge(), original.getMaxAge());
    Asserts.assertEquals(recording.isToDisk(), original.isToDisk());
    Asserts.assertEquals(recording.getDumpOnExit(), original.getDumpOnExit());

    List<RecordedEvent> recordedEvents = Events.fromRecording(recording);
    Events.hasEvents(recordedEvents);
    Asserts.assertEquals(1, recordedEvents.size(), "Expected exactly one event");

    RecordedEvent re = recordedEvents.get(0);
    Asserts.assertEquals(EVENT_ID, re.getValue("id"));
}
 
Example 9
Source File: TestEventMetadata.java    From openjdk-jdk8u 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 10
Source File: TestGetRecordingsMultiple.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void verifyExistingRecordings(List<TestRecording> testRecordings) {
    for (TestRecording testRecording : testRecordings) {
        RecordingInfo r = findRecording(testRecording);
        if (r != null) {
            Asserts.assertFalse(testRecording.isClosed, "Found closed recording with id " + testRecording.id);
            System.out.printf("Recording %d: %s%n", r.getId(), r.getState());
        } else {
            Asserts.assertTrue(testRecording.isClosed, "Missing recording with id " + testRecording.id);
            System.out.printf("Recording %d: CLOSED%n", testRecording.id);
        }
    }
}
 
Example 11
Source File: TestEventMetadata.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void verifyDescription(String description) {
    if (description == null) {
        return;
    }
    Asserts.assertTrue(description.length() > 10, "Description must be at least ten characters");
    Asserts.assertTrue(description.length() < 300, "Description should not exceed 300 characters. Found " + description);
    Asserts.assertTrue(description.length() == description.trim().length(), "Description should not have trim character at start or end");
    Asserts.assertFalse(description.endsWith(".") && description.indexOf(".") == description.length() - 1, "Single sentence descriptions should not use end punctuation");
}
 
Example 12
Source File: MaterializeVirtualObjectTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void check(int iteration) {
    // Materialize virtual objects on last invocation
    if (iteration == COMPILE_THRESHOLD) {
        // get frames and check not-null
        HotSpotStackFrameReference materialized = CompilerToVMHelper.getNextStackFrame(
                /* topmost frame */ null, new ResolvedJavaMethod[]{MATERIALIZED_RESOLVED},
                /* don't skip any */ 0);
        Asserts.assertNotNull(materialized, getName()
                + " : got null frame for materialized method");
        HotSpotStackFrameReference notMaterialized = CompilerToVMHelper.getNextStackFrame(
                /* topmost frame */ null, new ResolvedJavaMethod[]{NOT_MATERIALIZED_RESOLVED},
                /* don't skip any */ 0);
        Asserts.assertNE(materialized, notMaterialized,
                "Got same frame pointer for both tested frames");
        Asserts.assertNotNull(notMaterialized, getName()
                + " : got null frame for not materialized method");
        // check that frames has virtual objects before materialization stage
        Asserts.assertTrue(materialized.hasVirtualObjects(), getName()
                + ": materialized frame has no virtual object before materialization");
        Asserts.assertTrue(notMaterialized.hasVirtualObjects(), getName()
                + ": notMaterialized frame has no virtual object before materialization");
        // materialize
        CompilerToVMHelper.materializeVirtualObjects(materialized, INVALIDATE);
        // check that only not materialized frame has virtual objects
        Asserts.assertFalse(materialized.hasVirtualObjects(), getName()
                + " : materialized has virtual object after materialization");
        Asserts.assertTrue(notMaterialized.hasVirtualObjects(), getName()
                + " : notMaterialized has no virtual object after materialization");
        // check that materialized frame was deoptimized in case invalidate=true
        Asserts.assertEQ(WB.isMethodCompiled(MATERIALIZED_METHOD), !INVALIDATE, getName()
                + " : materialized method has unexpected compiled status");
        // check that not materialized frame wasn't deoptimized
        Asserts.assertTrue(WB.isMethodCompiled(NOT_MATERIALIZED_METHOD), getName()
                + " : not materialized method has unexpected compiled status");
    }
}
 
Example 13
Source File: TestWBGC.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) {
    obj = new Object();
    Asserts.assertFalse(wb.isObjectInOldGen(obj));
    wb.youngGC();
    wb.youngGC();
    // 2 young GC is needed to promote object into OldGen
    Asserts.assertTrue(wb.isObjectInOldGen(obj));
}
 
Example 14
Source File: TestDestState.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 {
    Recording r = new Recording();
    SimpleEventHelper.enable(r, true);

    final Path newDest = Paths.get(".", "new.jfr");
    r.setDestination(newDest);
    System.out.println("new dest: " + r.getDestination());
    Asserts.assertEquals(newDest, r.getDestination(), "Wrong get/set dest when new");

    r.start();
    SimpleEventHelper.createEvent(0);
    Thread.sleep(100);
    final Path runningDest = Paths.get(".", "running.jfr");
    r.setDestination(runningDest);
    System.out.println("running dest: " + r.getDestination());
    Asserts.assertEquals(runningDest, r.getDestination(), "Wrong get/set dest when running");
    SimpleEventHelper.createEvent(1);

    r.stop();
    SimpleEventHelper.createEvent(2);

    // Expect recording to be saved at destination that was set when
    // the recording was stopped, which is runningDest.
    Asserts.assertTrue(Files.exists(runningDest), "No recording file: " + runningDest);
    List<RecordedEvent> events = RecordingFile.readAllEvents(runningDest);
    Asserts.assertFalse(events.isEmpty(), "No event found");
    System.out.printf("Found event %s%n", events.get(0).getEventType().getName());
    r.close();
}
 
Example 15
Source File: GCEventAll.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private Set<Integer> verifyUniqueIds(List<GCHelper.GcBatch> batches) {
    Set<Integer> gcIds = new HashSet<>();
    for (GCHelper.GcBatch batch : batches) {
        Integer gcId = new Integer(batch.getGcId());
        Asserts.assertFalse(gcIds.contains(gcId), "Duplicate gcId: " + gcId);
        gcIds.add(gcId);
    }
    return gcIds;
}
 
Example 16
Source File: TestPrintJSON.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 {

        Path recordingFile = ExecuteHelper.createProfilingRecording().toAbsolutePath();

        OutputAnalyzer output = ExecuteHelper.jfr("print", "--json", "--stack-depth", "999", recordingFile.toString());
        String json = output.getStdout();

        // Parse JSON using Nashorn
        String statement = "var jsonObject = " + json;
        ScriptEngineManager factory = new ScriptEngineManager();
        ScriptEngine engine = factory.getEngineByName("nashorn");
        engine.eval(statement);
        JSObject o = (JSObject) engine.get("jsonObject");
        JSObject recording = (JSObject) o.getMember("recording");
        JSObject jsonEvents = (JSObject) recording.getMember("events");

        List<RecordedEvent> events = RecordingFile.readAllEvents(recordingFile);
        Collections.sort(events, (e1, e2) -> e1.getEndTime().compareTo(e2.getEndTime()));
        // Verify events are equal
        Iterator<RecordedEvent> it = events.iterator();

        for (Object jsonEvent : jsonEvents.values()) {
            RecordedEvent recordedEvent = it.next();
            String typeName = recordedEvent.getEventType().getName();
            Asserts.assertEquals(typeName, ((JSObject) jsonEvent).getMember("type").toString());
            assertEquals(jsonEvent, recordedEvent);
        }
        Asserts.assertFalse(events.size() != jsonEvents.values().size(), "Incorrect number of events");
    }
 
Example 17
Source File: TestEventMetadata.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void verifyDescription(String description) {
    if (description == null) {
        return;
    }
    Asserts.assertTrue(description.length() > 10, "Description must be at least ten characters");
    Asserts.assertTrue(description.length() < 300, "Description should not exceed 300 characters. Found " + description);
    Asserts.assertTrue(description.length() == description.trim().length(), "Description should not have trim character at start or end");
    Asserts.assertFalse(description.endsWith(".") && description.indexOf(".") == description.length() - 1, "Single sentence descriptions should not use end punctuation");
}
 
Example 18
Source File: TestIsEnabled.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private static void assertDisabled(String msg) {
    SimpleEvent event = new SimpleEvent();
    Asserts.assertFalse(event.isEnabled(), msg);
}
 
Example 19
Source File: TestDestInvalid.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Recording r = new Recording();
    r.enable(EventNames.OSInformation);
    r.setToDisk(true);

    Asserts.assertNull(r.getDestination(), "dest not null by default");

    // Set destination to empty path (same as curr dir, not a file)
    verifyException(()->{r.setDestination(Paths.get(""));}, "No exception for setDestination(\"\")", IOException.class);
    System.out.println("1 destination: " + r.getDestination());
    Asserts.assertNull(r.getDestination(), "default dest not null after failed setDest");

    // Set dest to a valid path. This should be kept when a new setDest fails.
    Path dest = Paths.get(".", "my.jfr");
    r.setDestination(dest);
    System.out.println("2 destination: " + r.getDestination());
    Asserts.assertEquals(dest, r.getDestination(), "Wrong get/set dest");

    // Null is allowed for setDestination()
    r.setDestination(null);
    System.out.println("3 destination: " + r.getDestination());
    Asserts.assertNull(r.getDestination(), "dest not null after setDest(null)");

    // Reset dest to correct value and make ssure it is not overwritten
    r.setDestination(dest);
    System.out.println("4 destination: " + r.getDestination());
    Asserts.assertEquals(dest, r.getDestination(), "Wrong get/set dest");

    // Set destination to an existing dir. Old dest is saved.
    verifyException(()->{r.setDestination(Paths.get("."));}, "No exception for setDestination(.)", IOException.class);
    System.out.println("5 destination: " + r.getDestination());
    Asserts.assertEquals(dest, r.getDestination(), "Wrong get/set dest");

    // Set destination to a non-existing dir. Old dest is saved.
    verifyException(()->{r.setDestination(Paths.get(".", "missingdir", "my.jfr"));}, "No exception for setDestination(dirNotExists)", IOException.class);
    System.out.println("6 destination: " + r.getDestination());
    Asserts.assertEquals(dest, r.getDestination(), "Wrong get/set dest");

    // Verify that it works with the old setDest value.
    r.start();
    r.stop();
    r.close();
    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 in %s%n", events.get(0).getEventType().getName(), dest.toString());
}
 
Example 20
Source File: TestHasValue.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
private static void testHasValue(Class<? extends java.lang.annotation.Annotation> clz) {

        System.out.println("class=" + clz);

        AnnotationElement a = new AnnotationElement(clz, "value");
        Asserts.assertTrue(a.hasValue("value"));
        Asserts.assertFalse(a.hasValue("nosuchvalue"));

    }