Java Code Examples for jdk.jfr.EventType#getAnnotation()

The following examples show how to use jdk.jfr.EventType#getAnnotation() . 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: MainTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void assertMetadata(List<RecordedEvent> events) {
    for (RecordedEvent e : events) {
        EventType type = e.getEventType();
        ModularizedAnnotation maType = type.getAnnotation(ModularizedAnnotation.class);
        if (maType == null) {
            fail("Missing @ModularizedAnnotation on type " + type);
        }
        assertEquals(maType.value(), "hello type");
        assertMetaAnnotation(type.getAnnotationElements());

        ValueDescriptor messageField = type.getField("message");
        ModularizedAnnotation maField = messageField.getAnnotation(ModularizedAnnotation.class);
        if (maField == null) {
            fail("Missing @ModularizedAnnotation on field in " + type);
        }
        assertEquals(maField.value(), "hello field");
        assertMetaAnnotation(messageField.getAnnotationElements());
    }
}
 
Example 2
Source File: TestExperimental.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    EventType t = EventType.getEventType(ExperimentalEvent.class);

    // @Experimental on event
    Experimental e = t.getAnnotation(Experimental.class);
    Asserts.assertTrue(e != null, "Expected @Experimental annotation on event");

    // @Experimental on annotation
    AnnotationElement a = Events.getAnnotationByName(t, ExperimentalAnnotation.class.getName());
    e = a.getAnnotation(Experimental.class);
    Asserts.assertTrue(e != null, "Expected @Experimental on annotation");

    // @Experimental on field
    a = Events.getAnnotation(t.getField("experimentalField"), Experimental.class);
    Asserts.assertTrue(e != null, "Expected @Experimental on field");
}
 
Example 3
Source File: MainTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void assertMetadata(List<RecordedEvent> events) {
    for (RecordedEvent e : events) {
        EventType type = e.getEventType();
        ModularizedAnnotation maType = type.getAnnotation(ModularizedAnnotation.class);
        if (maType == null) {
            fail("Missing @ModularizedAnnotation on type " + type);
        }
        assertEquals(maType.value(), "hello type");
        assertMetaAnnotation(type.getAnnotationElements());

        ValueDescriptor messageField = type.getField("message");
        ModularizedAnnotation maField = messageField.getAnnotation(ModularizedAnnotation.class);
        if (maField == null) {
            fail("Missing @ModularizedAnnotation on field in " + type);
        }
        assertEquals(maField.value(), "hello field");
        assertMetaAnnotation(messageField.getAnnotationElements());
    }
}
 
Example 4
Source File: TestExperimental.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 {
    EventType t = EventType.getEventType(ExperimentalEvent.class);

    // @Experimental on event
    Experimental e = t.getAnnotation(Experimental.class);
    Asserts.assertTrue(e != null, "Expected @Experimental annotation on event");

    // @Experimental on annotation
    AnnotationElement a = Events.getAnnotationByName(t, ExperimentalAnnotation.class.getName());
    e = a.getAnnotation(Experimental.class);
    Asserts.assertTrue(e != null, "Expected @Experimental on annotation");

    // @Experimental on field
    a = Events.getAnnotation(t.getField("experimentalField"), Experimental.class);
    Asserts.assertTrue(e != null, "Expected @Experimental on field");
}
 
Example 5
Source File: MainTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static void assertMetadata(List<RecordedEvent> events) {
    for (RecordedEvent e : events) {
        EventType type = e.getEventType();
        ModularizedAnnotation maType = type.getAnnotation(ModularizedAnnotation.class);
        if (maType == null) {
            fail("Missing @ModularizedAnnotation on type " + type);
        }
        assertEquals(maType.value(), "hello type");
        assertMetaAnnotation(type.getAnnotationElements());

        ValueDescriptor messageField = type.getField("message");
        ModularizedAnnotation maField = messageField.getAnnotation(ModularizedAnnotation.class);
        if (maField == null) {
            fail("Missing @ModularizedAnnotation on field in " + type);
        }
        assertEquals(maField.value(), "hello field");
        assertMetaAnnotation(messageField.getAnnotationElements());
    }
}
 
Example 6
Source File: TestExperimental.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 {
    EventType t = EventType.getEventType(ExperimentalEvent.class);

    // @Experimental on event
    Experimental e = t.getAnnotation(Experimental.class);
    Asserts.assertTrue(e != null, "Expected @Experimental annotation on event");

    // @Experimental on annotation
    AnnotationElement a = Events.getAnnotationByName(t, ExperimentalAnnotation.class.getName());
    e = a.getAnnotation(Experimental.class);
    Asserts.assertTrue(e != null, "Expected @Experimental on annotation");

    // @Experimental on field
    a = Events.getAnnotation(t.getField("experimentalField"), Experimental.class);
    Asserts.assertTrue(e != null, "Expected @Experimental on field");
}
 
Example 7
Source File: TestGetAnnotation.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 {
    EventType type = EventType.getEventType(MyEvent.class);

    Label label = type.getAnnotation(Label.class);
    if (label == null) {
        Asserts.fail("Annotation label was null");
    }
    Asserts.assertEquals(label.value(), "myLabel", "Wrong value for annotation label");

    Category category = type.getAnnotation(Category.class);
    if (category == null) {
        Asserts.fail("Annotation @Description was null");
    }

    Asserts.assertTrue(Arrays.equals(category.value(), new String[] {"Stuff"}), "Wrong value for annotation enabled");

    Description description = type.getAnnotation(Description.class);
    if (description != null) {
        Asserts.fail("Annotation description should be null");
    }

    try {
        type.getAnnotation(null);
        Asserts.fail("No exception when getAnnotation(null)");
    } catch(Exception e) {
        // Expected exception
    }
}
 
Example 8
Source File: TestDynamicAnnotations.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void testECID() throws Exception {
    List<ValueDescriptor> fields = new ArrayList<>();

    List<AnnotationElement> fieldAnnotations = new ArrayList<>();
    fieldAnnotations.add(new AnnotationElement(ECID.class));
    ValueDescriptor ecidField = new ValueDescriptor(String.class, "ecid", fieldAnnotations);
    fields.add(ecidField);

    EventFactory f = EventFactory.create(fieldAnnotations, fields);

    String ecidValue = "131739871298371279812";
    try (Recording r = new Recording()) {
        r.start();
        Event event = f.newEvent();
        event.set(0, ecidValue);
        event.commit();
        r.stop();
        List<RecordedEvent> events = Events.fromRecording(r);
        Events.hasEvents(events);
        Events.assertField(events.get(0), "ecid").equal(ecidValue);
    }
    EventType type = f.getEventType();
    ECID e = type.getAnnotation(ECID.class);
    if (e == null) {
        throw new Exception("Missing ECID annotation");
    }
}
 
Example 9
Source File: TestGetAnnotation.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 {
    EventType type = EventType.getEventType(MyEvent.class);

    Label label = type.getAnnotation(Label.class);
    if (label == null) {
        Asserts.fail("Annotation label was null");
    }
    Asserts.assertEquals(label.value(), "myLabel", "Wrong value for annotation label");

    Category category = type.getAnnotation(Category.class);
    if (category == null) {
        Asserts.fail("Annotation @Description was null");
    }

    Asserts.assertTrue(Arrays.equals(category.value(), new String[] {"Stuff"}), "Wrong value for annotation enabled");

    Description description = type.getAnnotation(Description.class);
    if (description != null) {
        Asserts.fail("Annotation description should be null");
    }

    try {
        type.getAnnotation(null);
        Asserts.fail("No exception when getAnnotation(null)");
    } catch(Exception e) {
        // Expected exception
    }
}
 
Example 10
Source File: TestDynamicAnnotations.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void testECID() throws Exception {
    List<ValueDescriptor> fields = new ArrayList<>();

    List<AnnotationElement> fieldAnnotations = new ArrayList<>();
    fieldAnnotations.add(new AnnotationElement(ECID.class));
    ValueDescriptor ecidField = new ValueDescriptor(String.class, "ecid", fieldAnnotations);
    fields.add(ecidField);

    EventFactory f = EventFactory.create(fieldAnnotations, fields);

    String ecidValue = "131739871298371279812";
    try (Recording r = new Recording()) {
        r.start();
        Event event = f.newEvent();
        event.set(0, ecidValue);
        event.commit();
        r.stop();
        List<RecordedEvent> events = Events.fromRecording(r);
        Events.hasEvents(events);
        Events.assertField(events.get(0), "ecid").equal(ecidValue);
    }
    EventType type = f.getEventType();
    ECID e = type.getAnnotation(ECID.class);
    if (e == null) {
        throw new Exception("Missing ECID annotation");
    }
}
 
Example 11
Source File: TestLookForUntestedEvents.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 {
    for (EventType type : FlightRecorder.getFlightRecorder().getEventTypes()) {
        if (type.getAnnotation(Experimental.class) == null) {
            jfrEventTypes.add(type.getName().replace("jdk.", ""));
        }
    }

    checkEventNamesClass();
    lookForEventsNotCoveredByTests();
}
 
Example 12
Source File: TestGetAnnotation.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 {
    EventType type = EventType.getEventType(MyEvent.class);

    Label label = type.getAnnotation(Label.class);
    if (label == null) {
        Asserts.fail("Annotation label was null");
    }
    Asserts.assertEquals(label.value(), "myLabel", "Wrong value for annotation label");

    Category category = type.getAnnotation(Category.class);
    if (category == null) {
        Asserts.fail("Annotation @Description was null");
    }

    Asserts.assertTrue(Arrays.equals(category.value(), new String[] {"Stuff"}), "Wrong value for annotation enabled");

    Description description = type.getAnnotation(Description.class);
    if (description != null) {
        Asserts.fail("Annotation description should be null");
    }

    try {
        type.getAnnotation(null);
        Asserts.fail("No exception when getAnnotation(null)");
    } catch(Exception e) {
        // Expected exception
    }
}
 
Example 13
Source File: TestDynamicAnnotations.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void testECID() throws Exception {
    List<ValueDescriptor> fields = new ArrayList<>();

    List<AnnotationElement> fieldAnnotations = new ArrayList<>();
    fieldAnnotations.add(new AnnotationElement(ECID.class));
    ValueDescriptor ecidField = new ValueDescriptor(String.class, "ecid", fieldAnnotations);
    fields.add(ecidField);

    EventFactory f = EventFactory.create(fieldAnnotations, fields);

    String ecidValue = "131739871298371279812";
    try (Recording r = new Recording()) {
        r.start();
        Event event = f.newEvent();
        event.set(0, ecidValue);
        event.commit();
        r.stop();
        List<RecordedEvent> events = Events.fromRecording(r);
        Events.hasEvents(events);
        Events.assertField(events.get(0), "ecid").equal(ecidValue);
    }
    EventType type = f.getEventType();
    ECID e = type.getAnnotation(ECID.class);
    if (e == null) {
        throw new Exception("Missing ECID annotation");
    }
}
 
Example 14
Source File: TestLookForUntestedEvents.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 {
    for (EventType type : FlightRecorder.getFlightRecorder().getEventTypes()) {
        if (type.getAnnotation(Experimental.class) == null) {
            jfrEventTypes.add(type.getName().replace("jdk.", ""));
        }
    }

    checkEventNamesClass();
    lookForEventsNotCoveredByTests();
}