jdk.jfr.Timestamp Java Examples

The following examples show how to use jdk.jfr.Timestamp. 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: TestGetContentType.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 type = EventType.getEventType(CustomEvent.class);

    SettingDescriptor plain = Events.getSetting(type, "plain");
    Asserts.assertNull(plain.getContentType());

    SettingDescriptor annotatedType = Events.getSetting(type, "annotatedType");
    Asserts.assertNull(annotatedType.getContentType(), Timestamp.class.getName());

    SettingDescriptor newName = Events.getSetting(type, "newName");
    Asserts.assertEquals(newName.getContentType(), Timespan.class.getName());

    SettingDescriptor overridden = Events.getSetting(type, "overridden");
    Asserts.assertNull(overridden.getContentType());

    SettingDescriptor protectedBase = Events.getSetting(type, "protectedBase");
    Asserts.assertEquals(protectedBase.getContentType(), Frequency.class);

    SettingDescriptor publicBase = Events.getSetting(type, "publicBase");
    Asserts.assertEquals(publicBase.getContentType(), Timestamp.class.getName());

    SettingDescriptor packageProtectedBase = Events.getSetting(type, "packageProtectedBase");
    Asserts.assertNull(packageProtectedBase.getContentType());

    CustomEvent.assertOnDisk((x, y) -> Objects.equals(x.getContentType(), y.getContentType()) ? 0 : 1);
}
 
Example #2
Source File: TestGetAnnotation.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 type = EventType.getEventType(CustomEvent.class);

    SettingDescriptor annotatedType = Events.getSetting(type, "annotatedType");
    Label al = annotatedType.getAnnotation(Label.class);
    Asserts.assertNull(al); // we should not inherit annotation from type

    Description ad = annotatedType.getAnnotation(Description.class);
    Asserts.assertNull(ad); // we should not inherit annotation from type

    Timestamp at = annotatedType.getAnnotation(Timestamp.class);
    Asserts.assertNull(at); // we should not inherit annotation from type

    SettingDescriptor newName = Events.getSetting(type, "newName");
    Label nl = newName.getAnnotation(Label.class);
    Asserts.assertEquals(nl.value(), "Annotated Method");

    Description nd = newName.getAnnotation(Description.class);
    Asserts.assertEquals(nd.value(), "Description of an annotated method");

    Timespan nt = newName.getAnnotation(Timespan.class);
    Asserts.assertEquals(nt.value(), Timespan.NANOSECONDS);
}
 
Example #3
Source File: TestGetAnnotation.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 type = EventType.getEventType(CustomEvent.class);

    SettingDescriptor annotatedType = Events.getSetting(type, "annotatedType");
    Label al = annotatedType.getAnnotation(Label.class);
    Asserts.assertNull(al); // we should not inherit annotation from type

    Description ad = annotatedType.getAnnotation(Description.class);
    Asserts.assertNull(ad); // we should not inherit annotation from type

    Timestamp at = annotatedType.getAnnotation(Timestamp.class);
    Asserts.assertNull(at); // we should not inherit annotation from type

    SettingDescriptor newName = Events.getSetting(type, "newName");
    Label nl = newName.getAnnotation(Label.class);
    Asserts.assertEquals(nl.value(), "Annotated Method");

    Description nd = newName.getAnnotation(Description.class);
    Asserts.assertEquals(nd.value(), "Description of an annotated method");

    Timespan nt = newName.getAnnotation(Timespan.class);
    Asserts.assertEquals(nt.value(), Timespan.NANOSECONDS);
}
 
Example #4
Source File: TestGetContentType.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 type = EventType.getEventType(CustomEvent.class);

    SettingDescriptor plain = Events.getSetting(type, "plain");
    Asserts.assertNull(plain.getContentType());

    SettingDescriptor annotatedType = Events.getSetting(type, "annotatedType");
    Asserts.assertNull(annotatedType.getContentType(), Timestamp.class.getName());

    SettingDescriptor newName = Events.getSetting(type, "newName");
    Asserts.assertEquals(newName.getContentType(), Timespan.class.getName());

    SettingDescriptor overridden = Events.getSetting(type, "overridden");
    Asserts.assertNull(overridden.getContentType());

    SettingDescriptor protectedBase = Events.getSetting(type, "protectedBase");
    Asserts.assertEquals(protectedBase.getContentType(), Frequency.class);

    SettingDescriptor publicBase = Events.getSetting(type, "publicBase");
    Asserts.assertEquals(publicBase.getContentType(), Timestamp.class.getName());

    SettingDescriptor packageProtectedBase = Events.getSetting(type, "packageProtectedBase");
    Asserts.assertNull(packageProtectedBase.getContentType());

    CustomEvent.assertOnDisk((x, y) -> Objects.equals(x.getContentType(), y.getContentType()) ? 0 : 1);
}
 
Example #5
Source File: RecordedObject.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private Instant getInstant(long timestamp, String name) {
    ValueDescriptor v = getValueDescriptor(descriptors, name, null);
    Timestamp ts = v.getAnnotation(Timestamp.class);
    if (ts != null) {
        if (timestamp == Long.MIN_VALUE) {
            return Instant.MIN;
        }
        switch (ts.value()) {
        case Timestamp.MILLISECONDS_SINCE_EPOCH:
            return Instant.ofEpochMilli(timestamp);
        case Timestamp.TICKS:
            return Instant.ofEpochSecond(0, timeConverter.convertTimestamp(timestamp));
        }
        throw new IllegalArgumentException("Attempt to get " + v.getTypeName() + " field \"" + name + "\" with illegal timestamp unit " + ts.value());
    }
    throw new IllegalArgumentException("Attempt to get " + v.getTypeName() + " field \"" + name + "\" with missing @Timestamp");
}
 
Example #6
Source File: RecordedObject.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private Instant getInstant(long timestamp, String name) {
    ValueDescriptor v = getValueDescriptor(descriptors, name, null);
    Timestamp ts = v.getAnnotation(Timestamp.class);
    if (ts != null) {
        if (timestamp == Long.MIN_VALUE) {
            return Instant.MIN;
        }
        switch (ts.value()) {
        case Timestamp.MILLISECONDS_SINCE_EPOCH:
            return Instant.ofEpochMilli(timestamp);
        case Timestamp.TICKS:
            return Instant.ofEpochSecond(0, timeConverter.convertTimestamp(timestamp));
        }
        throw new IllegalArgumentException("Attempt to get " + v.getTypeName() + " field \"" + name + "\" with illegal timestamp unit " + ts.value());
    }
    throw new IllegalArgumentException("Attempt to get " + v.getTypeName() + " field \"" + name + "\" with missing @Timestamp");
}
 
Example #7
Source File: TestGetContentType.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 type = EventType.getEventType(CustomEvent.class);

    SettingDescriptor plain = Events.getSetting(type, "plain");
    Asserts.assertNull(plain.getContentType());

    SettingDescriptor annotatedType = Events.getSetting(type, "annotatedType");
    Asserts.assertNull(annotatedType.getContentType(), Timestamp.class.getName());

    SettingDescriptor newName = Events.getSetting(type, "newName");
    Asserts.assertEquals(newName.getContentType(), Timespan.class.getName());

    SettingDescriptor overridden = Events.getSetting(type, "overridden");
    Asserts.assertNull(overridden.getContentType());

    SettingDescriptor protectedBase = Events.getSetting(type, "protectedBase");
    Asserts.assertEquals(protectedBase.getContentType(), Frequency.class);

    SettingDescriptor publicBase = Events.getSetting(type, "publicBase");
    Asserts.assertEquals(publicBase.getContentType(), Timestamp.class.getName());

    SettingDescriptor packageProtectedBase = Events.getSetting(type, "packageProtectedBase");
    Asserts.assertNull(packageProtectedBase.getContentType());

    CustomEvent.assertOnDisk((x, y) -> Objects.equals(x.getContentType(), y.getContentType()) ? 0 : 1);
}
 
Example #8
Source File: TestGetAnnotation.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 type = EventType.getEventType(CustomEvent.class);

    SettingDescriptor annotatedType = Events.getSetting(type, "annotatedType");
    Label al = annotatedType.getAnnotation(Label.class);
    Asserts.assertNull(al); // we should not inherit annotation from type

    Description ad = annotatedType.getAnnotation(Description.class);
    Asserts.assertNull(ad); // we should not inherit annotation from type

    Timestamp at = annotatedType.getAnnotation(Timestamp.class);
    Asserts.assertNull(at); // we should not inherit annotation from type

    SettingDescriptor newName = Events.getSetting(type, "newName");
    Label nl = newName.getAnnotation(Label.class);
    Asserts.assertEquals(nl.value(), "Annotated Method");

    Description nd = newName.getAnnotation(Description.class);
    Asserts.assertEquals(nd.value(), "Description of an annotated method");

    Timespan nt = newName.getAnnotation(Timespan.class);
    Asserts.assertEquals(nt.value(), Timespan.NANOSECONDS);
}
 
Example #9
Source File: TraceHandler.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
TraceHandler() {

        // Content types handled using annotation in Java
        annotationTypes.put("BYTES64", new AnnotationElement(DataAmount.class, DataAmount.BYTES));
        annotationTypes.put("BYTES", new AnnotationElement(DataAmount.class, DataAmount.BYTES));
        annotationTypes.put("MILLIS", new AnnotationElement(Timespan.class, Timespan.MILLISECONDS));
        annotationTypes.put("EPOCHMILLIS", new AnnotationElement(Timestamp.class, Timestamp.MILLISECONDS_SINCE_EPOCH));
        annotationTypes.put("NANOS", new AnnotationElement(Timespan.class, Timespan.NANOSECONDS));
        annotationTypes.put("TICKSPAN",  new AnnotationElement(Timespan.class, Timespan.TICKS));
        annotationTypes.put("TICKS",  new AnnotationElement(Timestamp.class, Timespan.TICKS));
        annotationTypes.put("ADDRESS", new AnnotationElement(MemoryAddress.class));
        annotationTypes.put("PERCENTAGE",  new AnnotationElement(Percentage.class));

        // Add known unsigned types, and their counter part in Java
        unsignedTypes.put("U8", Type.LONG);
        unsignedTypes.put("U4", Type.INT);
        unsignedTypes.put("U2", Type.SHORT);
        unsignedTypes.put("U1", Type.BYTE);

        // Map trace.xml primitive to Java type
        typedef.put("U8", Type.LONG.getName());
        typedef.put("U4", Type.INT.getName());
        typedef.put("U2", Type.SHORT.getName());
        typedef.put("U1", Type.BYTE.getName());
        typedef.put("LONG", Type.LONG.getName());
        typedef.put("INT", Type.INT.getName());
        typedef.put("SHORT", Type.SHORT.getName());
        typedef.put("BYTE", Type.BYTE.getName());
        typedef.put("DOUBLE", Type.DOUBLE.getName());
        typedef.put("BOOLEAN", Type.BOOLEAN.getName());
        typedef.put("FLOAT", Type.FLOAT.getName());
        typedef.put("CHAR", Type.CHAR.getName());
        typedef.put("STRING", Type.STRING.getName());
        typedef.put("THREAD", Type.THREAD.getName());
        typedef.put("CLASS", Type.CLASS.getName());
        // Add known types
        for (Type type : Type.getKnownTypes()) {
            types.put(type.getName(), type);
        }
    }
 
Example #10
Source File: TypeLibrary.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
static void addImplicitFields(Type type, boolean requestable, boolean hasDuration, boolean hasThread, boolean hasStackTrace, boolean hasCutoff) {
    createAnnotationType(Timespan.class);
    createAnnotationType(Timestamp.class);
    createAnnotationType(Label.class);
    defineType(long.class, null,false);
    addFields(type, requestable, hasDuration, hasThread, hasStackTrace, hasCutoff);
}
 
Example #11
Source File: TypeLibrary.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static ValueDescriptor createStartTimeField() {
    List<AnnotationElement> annos = createStandardAnnotations("Start Time", null);
    annos.add(new jdk.jfr.AnnotationElement(Timestamp.class, Timestamp.TICKS));
    return PrivateAccess.getInstance().newValueDescriptor(EventInstrumentation.FIELD_START_TIME, Type.LONG, annos, 0, false,
            EventInstrumentation.FIELD_START_TIME);

}
 
Example #12
Source File: EventPrintWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private ValueType determineValueType(ValueDescriptor v) {
    if (v.getAnnotation(Timespan.class) != null) {
        return ValueType.TIMESPAN;
    }
    if (v.getAnnotation(Timestamp.class) != null) {
        return ValueType.TIMESTAMP;
    }
    return ValueType.OTHER;
}
 
Example #13
Source File: TestFieldAnnotations.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 {
    EventType t = EventType.getEventType(FieldAnnotationEvent.class);

    ValueDescriptor field = t.getField("memoryAmount");
    Events.hasAnnotation(field, DataAmount.class);

    field = t.getField("frequency");
    Events.hasAnnotation(field, Frequency.class);

    field = t.getField("memoryAddress");
    Events.hasAnnotation(field, MemoryAddress.class);

    field = t.getField("percentage");
    Events.hasAnnotation(field, Percentage.class);

    field = t.getField("fromThread");
    Events.hasAnnotation(field, TransitionFrom.class);

    field = t.getField("toThread");
    Events.hasAnnotation(field, TransitionTo.class);

    field = t.getField("unsigned");
    Events.hasAnnotation(field, Unsigned.class);

    field = t.getField("timespan");
    Events.assertAnnotation(field, Timespan.class, Timespan.MILLISECONDS);

    field = t.getField("timestamp");
    Events.assertAnnotation(field, Timestamp.class, Timestamp.MILLISECONDS_SINCE_EPOCH);
}
 
Example #14
Source File: TestFieldAnnotations.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 {
    EventType t = EventType.getEventType(FieldAnnotationEvent.class);

    ValueDescriptor field = t.getField("memoryAmount");
    Events.hasAnnotation(field, DataAmount.class);

    field = t.getField("frequency");
    Events.hasAnnotation(field, Frequency.class);

    field = t.getField("memoryAddress");
    Events.hasAnnotation(field, MemoryAddress.class);

    field = t.getField("percentage");
    Events.hasAnnotation(field, Percentage.class);

    field = t.getField("fromThread");
    Events.hasAnnotation(field, TransitionFrom.class);

    field = t.getField("toThread");
    Events.hasAnnotation(field, TransitionTo.class);

    field = t.getField("unsigned");
    Events.hasAnnotation(field, Unsigned.class);

    field = t.getField("timespan");
    Events.assertAnnotation(field, Timespan.class, Timespan.MILLISECONDS);

    field = t.getField("timestamp");
    Events.assertAnnotation(field, Timestamp.class, Timestamp.MILLISECONDS_SINCE_EPOCH);
}
 
Example #15
Source File: TypeLibrary.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
static void addImplicitFields(Type type, boolean requestable, boolean hasDuration, boolean hasThread, boolean hasStackTrace, boolean hasCutoff) {
    createAnnotationType(Timespan.class);
    createAnnotationType(Timestamp.class);
    createAnnotationType(Label.class);
    defineType(long.class, null,false);
    addFields(type, requestable, hasDuration, hasThread, hasStackTrace, hasCutoff);
}
 
Example #16
Source File: TypeLibrary.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static ValueDescriptor createStartTimeField() {
    List<AnnotationElement> annos = createStandardAnnotations("Start Time", null);
    annos.add(new jdk.jfr.AnnotationElement(Timestamp.class, Timestamp.TICKS));
    return PrivateAccess.getInstance().newValueDescriptor(EventInstrumentation.FIELD_START_TIME, Type.LONG, annos, 0, false,
            EventInstrumentation.FIELD_START_TIME);

}
 
Example #17
Source File: EventPrintWriter.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private ValueType determineValueType(ValueDescriptor v) {
    if (v.getAnnotation(Timespan.class) != null) {
        return ValueType.TIMESPAN;
    }
    if (v.getAnnotation(Timestamp.class) != null) {
        return ValueType.TIMESTAMP;
    }
    return ValueType.OTHER;
}
 
Example #18
Source File: TestFieldAnnotations.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 t = EventType.getEventType(FieldAnnotationEvent.class);

    ValueDescriptor field = t.getField("memoryAmount");
    Events.hasAnnotation(field, DataAmount.class);

    field = t.getField("frequency");
    Events.hasAnnotation(field, Frequency.class);

    field = t.getField("memoryAddress");
    Events.hasAnnotation(field, MemoryAddress.class);

    field = t.getField("percentage");
    Events.hasAnnotation(field, Percentage.class);

    field = t.getField("fromThread");
    Events.hasAnnotation(field, TransitionFrom.class);

    field = t.getField("toThread");
    Events.hasAnnotation(field, TransitionTo.class);

    field = t.getField("unsigned");
    Events.hasAnnotation(field, Unsigned.class);

    field = t.getField("timespan");
    Events.assertAnnotation(field, Timespan.class, Timespan.MILLISECONDS);

    field = t.getField("timestamp");
    Events.assertAnnotation(field, Timestamp.class, Timestamp.MILLISECONDS_SINCE_EPOCH);
}
 
Example #19
Source File: RecordedObject.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private Instant getInstant(long timestamp, String name) {
    ValueDescriptor v = getValueDescriptor(descriptors, name, null);
    Timestamp ts = v.getAnnotation(Timestamp.class);
    if (ts != null) {
        switch (ts.value()) {
        case Timestamp.MILLISECONDS_SINCE_EPOCH:
            return Instant.ofEpochMilli(timestamp);
        case Timestamp.TICKS:
            return Instant.ofEpochSecond(0, timeConverter.convertTimestamp(timestamp));
        }
        throw new IllegalArgumentException("Attempt to get " + v.getTypeName() + " field \"" + name + "\" with illegal timestamp unit " + ts.value());
    }
    throw new IllegalArgumentException("Attempt to get " + v.getTypeName() + " field \"" + name + "\" with missing @Timestamp");
}
 
Example #20
Source File: TypeLibrary.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
static void addImplicitFields(Type type, boolean requestable, boolean hasDuration, boolean hasThread, boolean hasStackTrace, boolean hasCutoff) {
    createAnnotationType(Timespan.class);
    createAnnotationType(Timestamp.class);
    createAnnotationType(Label.class);
    defineType(long.class, null,false);
    addFields(type, requestable, hasDuration, hasThread, hasStackTrace, hasCutoff);
}
 
Example #21
Source File: TypeLibrary.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static ValueDescriptor createStartTimeField() {
    List<AnnotationElement> annos = createStandardAnnotations("Start Time", null);
    annos.add(new jdk.jfr.AnnotationElement(Timestamp.class, Timestamp.TICKS));
    return PrivateAccess.getInstance().newValueDescriptor(EventInstrumentation.FIELD_START_TIME, Type.LONG, annos, 0, false,
            EventInstrumentation.FIELD_START_TIME);

}
 
Example #22
Source File: DisplayableSupport.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
@Override
Class<Timestamp> getType() {
    return Timestamp.class;
}
 
Example #23
Source File: TestActiveRecordingEvent.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private static void testWithPath(Path path) throws Throwable {
    Recording recording = new Recording();
    recording.enable(ACTIVE_RECORDING_EVENT_NAME);

    recording.setDuration(REC_DURATION);
    recording.setMaxSize(MAX_SIZE);
    recording.setMaxAge(MAX_AGE);
    recording.setName(REC_NAME);
    if (path != null) {
        recording.setToDisk(true);
        recording.setDestination(path);
    }

    long tsBeforeStart = Instant.now().toEpochMilli();
    recording.start();
    recording.stop();
    long tsAfterStop = Instant.now().toEpochMilli();

    List<RecordedEvent> events = Events.fromRecording(recording);

    Events.hasEvents(events);
    RecordedEvent ev = events.get(0);

    // Duration must be kept in milliseconds
    assertEquals(REC_DURATION.toMillis(), ev.getValue("recordingDuration"));

    assertEquals(MAX_SIZE, ev.getValue("maxSize"));

    // maxAge must be kept in milliseconds
    assertEquals(MAX_AGE.toMillis(), ev.getValue("maxAge"));

    EventType evType = ev.getEventType();
    ValueDescriptor durationField = evType.getField("recordingDuration");
    assertEquals(durationField.getAnnotation(Timespan.class).value(), Timespan.MILLISECONDS);

    if (path == null) {
        assertNull(ev.getValue("destination"));
    } else {
        assertEquals(path.toAbsolutePath().toString(), ev.getValue("destination").toString());
    }

    ValueDescriptor recordingStartField = evType.getField("recordingStart");
    assertEquals(recordingStartField.getAnnotation(Timestamp.class).value(), Timestamp.MILLISECONDS_SINCE_EPOCH);

    long tsRecordingStart = ev.getValue("recordingStart");
    assertTrue(tsBeforeStart <= tsRecordingStart);
    assertTrue(tsAfterStop >= tsRecordingStart);

    assertEquals(recording.getId(), ev.getValue("id"));

    ValueDescriptor maxAgeField = evType.getField("maxAge");
    assertEquals(maxAgeField.getAnnotation(Timespan.class).value(), Timespan.MILLISECONDS);
}
 
Example #24
Source File: DisplayableSupport.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
@Override
Format createFormat(ValueDescriptor descriptor, Timestamp annotation) {
    return new TimestampFormat();
}
 
Example #25
Source File: TestHasValue.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        testHasValue(Label.class);
        testHasValue(Timestamp.class);
        testHasValue(CustomAnnotation.class);
    }
 
Example #26
Source File: DisplayableSupport.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
@Override
Comparable createValue(JFRJDK9Event event, ValueDescriptor descriptor, Timestamp annotation) throws JFRPropertyNotAvailableException {
    return event.getInstant(descriptor.getName());
}
 
Example #27
Source File: TestPrintXML.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
static boolean compare(Object eventObject, Object xmlObject) {
    if (eventObject == null) {
        return xmlObject == null;
    }
    if (eventObject instanceof RecordedObject) {
        RecordedObject re = (RecordedObject) eventObject;
        Map<String, Object> xmlMap = (Map<String, Object>) xmlObject;
        List<ValueDescriptor> fields = re.getFields();
        if (fields.size() != xmlMap.size()) {
            return false;
        }
        for (ValueDescriptor v : fields) {
            String name = v.getName();
            Object xmlValue = xmlMap.get(name);
            Object expectedValue = re.getValue(name);
            if (v.getAnnotation(Timestamp.class) != null) {
                // Make instant of OffsetDateTime
                xmlValue = OffsetDateTime.parse("" + xmlValue).toInstant().toString();
                expectedValue = re.getInstant(name);
            }
            if (v.getAnnotation(Timespan.class) != null) {
                expectedValue = re.getDuration(name);
            }
            if (!compare(expectedValue, xmlValue)) {
                return false;
            }
        }
        return true;
    }
    if (eventObject.getClass().isArray()) {
        Object[] array = (Object[]) eventObject;
        Object[] xmlArray = (Object[]) xmlObject;
        if (array.length != xmlArray.length) {
            return false;
        }
        for (int i = 0; i < array.length; i++) {
            if (!compare(array[i], xmlArray[i])) {
                return false;
            }
        }
        return true;
    }
    String s1 = String.valueOf(eventObject);
    String s2 = (String) xmlObject;
    return s1.equals(s2);
}
 
Example #28
Source File: TestActiveRecordingEvent.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private static void testWithPath(Path path) throws Throwable {
    Recording recording = new Recording();
    recording.enable(ACTIVE_RECORDING_EVENT_NAME);

    recording.setDuration(REC_DURATION);
    recording.setMaxSize(MAX_SIZE);
    recording.setMaxAge(MAX_AGE);
    recording.setName(REC_NAME);
    if (path != null) {
        recording.setToDisk(true);
        recording.setDestination(path);
    }

    long tsBeforeStart = Instant.now().toEpochMilli();
    recording.start();
    recording.stop();
    long tsAfterStop = Instant.now().toEpochMilli();

    List<RecordedEvent> events = Events.fromRecording(recording);

    Events.hasEvents(events);
    RecordedEvent ev = events.get(0);

    // Duration must be kept in milliseconds
    assertEquals(REC_DURATION.toMillis(), ev.getValue("recordingDuration"));

    assertEquals(MAX_SIZE, ev.getValue("maxSize"));

    // maxAge must be kept in milliseconds
    assertEquals(MAX_AGE.toMillis(), ev.getValue("maxAge"));

    EventType evType = ev.getEventType();
    ValueDescriptor durationField = evType.getField("recordingDuration");
    assertEquals(durationField.getAnnotation(Timespan.class).value(), Timespan.MILLISECONDS);

    if (path == null) {
        assertNull(ev.getValue("destination"));
    } else {
        assertEquals(path.toAbsolutePath().toString(), ev.getValue("destination").toString());
    }

    ValueDescriptor recordingStartField = evType.getField("recordingStart");
    assertEquals(recordingStartField.getAnnotation(Timestamp.class).value(), Timestamp.MILLISECONDS_SINCE_EPOCH);

    long tsRecordingStart = ev.getValue("recordingStart");
    assertTrue(tsBeforeStart <= tsRecordingStart);
    assertTrue(tsAfterStop >= tsRecordingStart);

    assertEquals(recording.getId(), ev.getValue("id"));

    ValueDescriptor maxAgeField = evType.getField("maxAge");
    assertEquals(maxAgeField.getAnnotation(Timespan.class).value(), Timespan.MILLISECONDS);
}
 
Example #29
Source File: TestHasValue.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        testHasValue(Label.class);
        testHasValue(Timestamp.class);
        testHasValue(CustomAnnotation.class);
    }
 
Example #30
Source File: TestPrintXML.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
static boolean compare(Object eventObject, Object xmlObject) {
    if (eventObject == null) {
        return xmlObject == null;
    }
    if (eventObject instanceof RecordedObject) {
        RecordedObject re = (RecordedObject) eventObject;
        Map<String, Object> xmlMap = (Map<String, Object>) xmlObject;
        List<ValueDescriptor> fields = re.getFields();
        if (fields.size() != xmlMap.size()) {
            return false;
        }
        for (ValueDescriptor v : fields) {
            String name = v.getName();
            Object xmlValue = xmlMap.get(name);
            Object expectedValue = re.getValue(name);
            if (v.getAnnotation(Timestamp.class) != null) {
                // Make instant of OffsetDateTime
                xmlValue = OffsetDateTime.parse("" + xmlValue).toInstant().toString();
                expectedValue = re.getInstant(name);
            }
            if (v.getAnnotation(Timespan.class) != null) {
                expectedValue = re.getDuration(name);
            }
            if (!compare(expectedValue, xmlValue)) {
                return false;
            }
        }
        return true;
    }
    if (eventObject.getClass().isArray()) {
        Object[] array = (Object[]) eventObject;
        Object[] xmlArray = (Object[]) xmlObject;
        if (array.length != xmlArray.length) {
            return false;
        }
        for (int i = 0; i < array.length; i++) {
            if (!compare(array[i], xmlArray[i])) {
                return false;
            }
        }
        return true;
    }
    String s1 = String.valueOf(eventObject);
    String s2 = (String) xmlObject;
    return s1.equals(s2);
}