Java源码示例:jdk.jfr.Timespan

示例1
private Duration getDuration(long timespan, String name) throws InternalError {
    ValueDescriptor v = getValueDescriptor(descriptors, name, null);
    Timespan ts = v.getAnnotation(Timespan.class);
    if (ts != null) {
        switch (ts.value()) {
        case Timespan.MICROSECONDS:
            return Duration.ofNanos(1000 * timespan);
        case Timespan.SECONDS:
            return Duration.ofSeconds(timespan);
        case Timespan.MILLISECONDS:
            return Duration.ofMillis(timespan);
        case Timespan.NANOSECONDS:
            return Duration.ofNanos(timespan);
        case Timespan.TICKS:
            return Duration.ofNanos(timeConverter.convertTimespan(timespan));
        }
        throw new IllegalArgumentException("Attempt to get " + v.getTypeName() + " field \"" + name + "\" with illegal timespan unit " + ts.value());
    }
    throw new IllegalArgumentException("Attempt to get " + v.getTypeName() + " field \"" + name + "\" with missing @Timespan");
}
 
示例2
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);
}
 
示例3
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);
}
 
示例4
private Duration getDuration(long timespan, String name) throws InternalError {
    ValueDescriptor v = getValueDescriptor(descriptors, name, null);
    if (timespan == Long.MIN_VALUE) {
        return Duration.ofSeconds(Long.MIN_VALUE, 0);
    }
    Timespan ts = v.getAnnotation(Timespan.class);
    if (ts != null) {
        switch (ts.value()) {
        case Timespan.MICROSECONDS:
            return Duration.ofNanos(1000 * timespan);
        case Timespan.SECONDS:
            return Duration.ofSeconds(timespan);
        case Timespan.MILLISECONDS:
            return Duration.ofMillis(timespan);
        case Timespan.NANOSECONDS:
            return Duration.ofNanos(timespan);
        case Timespan.TICKS:
            return Duration.ofNanos(timeConverter.convertTimespan(timespan));
        }
        throw new IllegalArgumentException("Attempt to get " + v.getTypeName() + " field \"" + name + "\" with illegal timespan unit " + ts.value());
    }
    throw new IllegalArgumentException("Attempt to get " + v.getTypeName() + " field \"" + name + "\" with missing @Timespan");
}
 
示例5
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);
}
 
示例6
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);
}
 
示例7
private Duration getDuration(long timespan, String name) throws InternalError {
    ValueDescriptor v = getValueDescriptor(descriptors, name, null);
    if (timespan == Long.MIN_VALUE) {
        return Duration.ofSeconds(Long.MIN_VALUE, 0);
    }
    Timespan ts = v.getAnnotation(Timespan.class);
    if (ts != null) {
        switch (ts.value()) {
        case Timespan.MICROSECONDS:
            return Duration.ofNanos(1000 * timespan);
        case Timespan.SECONDS:
            return Duration.ofSeconds(timespan);
        case Timespan.MILLISECONDS:
            return Duration.ofMillis(timespan);
        case Timespan.NANOSECONDS:
            return Duration.ofNanos(timespan);
        case Timespan.TICKS:
            return Duration.ofNanos(timeConverter.convertTimespan(timespan));
        }
        throw new IllegalArgumentException("Attempt to get " + v.getTypeName() + " field \"" + name + "\" with illegal timespan unit " + ts.value());
    }
    throw new IllegalArgumentException("Attempt to get " + v.getTypeName() + " field \"" + name + "\" with missing @Timespan");
}
 
示例8
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);
}
 
示例9
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);
}
 
示例10
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);
        }
    }
 
示例11
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);
}
 
示例12
@SettingDefinition
@Name("newName")
@Label(ANNOTATED_METHOD)
@Description(DESCRIPTION_OF_AN_ANNOTATED_METHOD)
@Timespan(Timespan.NANOSECONDS)
public boolean whatever(AnnotatedSetting s) {
    return true;
}
 
示例13
public static void main(String[] args) throws Exception {

        EventType t = EventType.getEventType(SunnyDay.class);
        AnnotationElement aMax = Events.getAnnotation(t.getField("max"), Temperature.class);
        ContentType cMax = aMax.getAnnotation(ContentType.class);
        if (cMax == null) {
            throw new Exception("Expected Temperature annotation for field 'max' to have meta annotation ContentType");
        }
        AnnotationElement aHours = Events.getAnnotation(t.getField("hours"), Timespan.class);
        ContentType cHours = aHours.getAnnotation(ContentType.class);
        Asserts.assertTrue(cHours != null, "Expected Timespan annotation for field 'hours' to have meta annotation ContentType");
    }
 
示例14
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);
}
 
示例15
@SettingDefinition
@Name("newName")
@Label(ANNOTATED_METHOD)
@Description(DESCRIPTION_OF_AN_ANNOTATED_METHOD)
@Timespan(Timespan.NANOSECONDS)
public boolean whatever(AnnotatedSetting s) {
    return true;
}
 
示例16
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;
}
 
示例17
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);
}
 
示例18
@SettingDefinition
@Name("newName")
@Label(ANNOTATED_METHOD)
@Description(DESCRIPTION_OF_AN_ANNOTATED_METHOD)
@Timespan(Timespan.NANOSECONDS)
public boolean whatever(AnnotatedSetting s) {
    return true;
}
 
示例19
public static void main(String[] args) throws Exception {

        EventType t = EventType.getEventType(SunnyDay.class);
        AnnotationElement aMax = Events.getAnnotation(t.getField("max"), Temperature.class);
        ContentType cMax = aMax.getAnnotation(ContentType.class);
        if (cMax == null) {
            throw new Exception("Expected Temperature annotation for field 'max' to have meta annotation ContentType");
        }
        AnnotationElement aHours = Events.getAnnotation(t.getField("hours"), Timespan.class);
        ContentType cHours = aHours.getAnnotation(ContentType.class);
        Asserts.assertTrue(cHours != null, "Expected Timespan annotation for field 'hours' to have meta annotation ContentType");
    }
 
示例20
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);
}
 
示例21
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;
}
 
示例22
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);
}
 
示例23
@SettingDefinition
@Name("newName")
@Label(ANNOTATED_METHOD)
@Description(DESCRIPTION_OF_AN_ANNOTATED_METHOD)
@Timespan(Timespan.NANOSECONDS)
public boolean whatever(AnnotatedSetting s) {
    return true;
}
 
示例24
public static void main(String[] args) throws Exception {

        EventType t = EventType.getEventType(SunnyDay.class);
        AnnotationElement aMax = Events.getAnnotation(t.getField("max"), Temperature.class);
        ContentType cMax = aMax.getAnnotation(ContentType.class);
        if (cMax == null) {
            throw new Exception("Expected Temperature annotation for field 'max' to have meta annotation ContentType");
        }
        AnnotationElement aHours = Events.getAnnotation(t.getField("hours"), Timespan.class);
        ContentType cHours = aHours.getAnnotation(ContentType.class);
        Asserts.assertTrue(cHours != null, "Expected Timespan annotation for field 'hours' to have meta annotation ContentType");
    }
 
示例25
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);
}
 
示例26
private static ValueDescriptor createDurationField() {
    List<AnnotationElement> annos = new ArrayList<>();
    annos = createStandardAnnotations("Duration", null);
    annos.add(new jdk.jfr.AnnotationElement(Timespan.class, Timespan.TICKS));
    return PrivateAccess.getInstance().newValueDescriptor(EventInstrumentation.FIELD_DURATION, Type.LONG, annos, 0, false, EventInstrumentation.FIELD_DURATION);
}
 
示例27
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);
}
 
示例28
private static ValueDescriptor createDurationField() {
    List<AnnotationElement> annos = new ArrayList<>();
    annos = createStandardAnnotations("Duration", null);
    annos.add(new jdk.jfr.AnnotationElement(Timespan.class, Timespan.TICKS));
    return PrivateAccess.getInstance().newValueDescriptor(EventInstrumentation.FIELD_DURATION, Type.LONG, annos, 0, false, EventInstrumentation.FIELD_DURATION);
}
 
示例29
@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);
}
 
示例30
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);
}