jdk.test.lib.Asserts.fail()

Here are the examples of the java api jdk.test.lib.Asserts.fail() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

77 Examples 7

19 Source : Events.java
with GNU General Public License v2.0
from Tencent

public static void hasEvent(List<RecordedEvent> events, String name) throws IOException {
    if (!containsEvent(events, name)) {
        replacederts.fail("Missing event " + name + " in recording " + events.toString());
    }
}

19 Source : Events.java
with GNU General Public License v2.0
from Tencent

public static void hasNotEvent(List<RecordedEvent> events, String name) throws IOException {
    if (containsEvent(events, name)) {
        replacederts.fail("Rercording should not contain event " + name + " " + events.toString());
    }
}

19 Source : JmxHelper.java
with GNU General Public License v2.0
from Tencent

public static Recording getJavaRecording(long recId) {
    for (Recording r : FlightRecorder.getFlightRecorder().getRecordings()) {
        if (r.getId() == recId) {
            return r;
        }
    }
    replacederts.fail("No Recording with id " + recId);
    return null;
}

19 Source : JmxHelper.java
with GNU General Public License v2.0
from Tencent

public static RecordingInfo getJmxRecording(long recId) {
    for (RecordingInfo r : getFlighteRecorderMXBean().getRecordings()) {
        if (r.getId() == recId) {
            return r;
        }
    }
    replacederts.fail("No RecordingInfo with id " + recId);
    return null;
}

19 Source : JmxHelper.java
with GNU General Public License v2.0
from Tencent

public static void verifyNotExists(long recId, List<RecordingInfo> recordings) {
    for (RecordingInfo r : recordings) {
        if (recId == r.getId()) {
            logRecordingInfos(recordings);
            replacederts.fail("Recording should not exist, id=" + recId);
        }
    }
}

19 Source : JmxHelper.java
with GNU General Public License v2.0
from Tencent

public static RecordingInfo verifyExists(long recId, List<RecordingInfo> recordings) {
    for (RecordingInfo r : recordings) {
        if (recId == r.getId()) {
            return r;
        }
    }
    logRecordingInfos(recordings);
    replacederts.fail("Recording not found, id=" + recId);
    return null;
}

19 Source : TestShutdownEvent.java
with GNU General Public License v2.0
from Tencent

public static Unsafe getUnsafe() {
    try {
        Field f = Unsafe.clreplaced.getDeclaredField("theUnsafe");
        f.setAccessible(true);
        return (Unsafe) f.get(null);
    } catch (Exception e) {
        replacederts.fail("Could not access Unsafe");
    }
    return null;
}

19 Source : TestFormatMissingValue.java
with GNU General Public License v2.0
from Tencent

private static void replacedertNotContains(String t, String text) {
    if (t.contains(text)) {
        replacederts.fail("Found unexpected value '" + text + "'  in text '" + t + "'");
    }
}

19 Source : TestFormatMissingValue.java
with GNU General Public License v2.0
from Tencent

private static void replacedertContains(String t, String text) {
    if (!t.contains(text)) {
        replacederts.fail("Expected '" + t + "' to contain text '" + text + "'");
    }
}

19 Source : TestClinitRegistration.java
with GNU General Public License v2.0
from Tencent

private static void replacedertClinitRegister(Clreplaced<? extends Event> eventClreplaced, boolean shouldExist, boolean setsProperty) throws ClreplacedNotFoundException {
    String clreplacedName = eventClreplaced.getName();
    triggerClinit(eventClreplaced);
    boolean hasEventType = hasEventType(clreplacedName);
    boolean hasProperty = Boolean.getBoolean(clreplacedName);
    if (hasEventType && !shouldExist) {
        replacederts.fail("Event clreplaced " + clreplacedName + " should not be registered");
    }
    if (!hasEventType && shouldExist) {
        replacederts.fail("Event clreplaced " + clreplacedName + " is not registered");
    }
    if (setsProperty && !hasProperty) {
        replacederts.fail("Expected clinit to be executed");
    }
    if (!setsProperty && hasProperty) {
        replacederts.fail("Property in clinit should not been set. Test bug?");
    }
}

18 Source : CommonHelper.java
with GNU General Public License v2.0
from Tencent

public static Recording verifyExists(long recId, List<Recording> recordings) {
    for (Recording r : recordings) {
        if (recId == r.getId()) {
            return r;
        }
    }
    replacederts.fail("Recording not found, id=" + recId);
    return null;
}

18 Source : TestAssemble.java
with GNU General Public License v2.0
from Tencent

private static long countEventInRecording(Path file) throws IOException {
    Integer lastId = -1;
    try (RecordingFile rf = new RecordingFile(file)) {
        long count = 0;
        while (rf.hasMoreEvents()) {
            RecordedEvent re = rf.readEvent();
            if (re.getEventType().getName().equals("Correlation")) {
                Integer id = re.getValue("id");
                if (id < lastId) {
                    replacederts.fail("Expected chunk number to increase");
                }
                lastId = id;
            }
            count++;
        }
        return count;
    }
}

18 Source : JcmdHelper.java
with GNU General Public License v2.0
from Tencent

// Wait until recording's state became running
public static void waitUntilRunning(String name) throws Exception {
    long timeoutAt = System.currentTimeMillis() + 10000;
    while (true) {
        Outputreplacedyzer output = jcmdCheck(name, false);
        try {
            // The expected output can look like this:
            // Recording 1: name=1 (running)
            output.shouldMatch("^Recording \\d+: name=" + name + " .*\\W{1}running\\W{1}");
            return;
        } catch (RuntimeException e) {
            if (System.currentTimeMillis() > timeoutAt) {
                replacederts.fail("Recording not started: " + name);
            }
            Thread.sleep(100);
        }
    }
}

18 Source : TestMetadataRetention.java
with GNU General Public License v2.0
from Tencent

private static RecordedEvent findChunkRotationEvent(List<RecordedEvent> events) {
    for (RecordedEvent e : events) {
        if (e.getEventType().getName().equals(ChunkRotation.clreplaced.getName())) {
            return e;
        }
    }
    replacederts.fail("Could not find chunk rotation event");
    // Can't happen;
    return null;
}

18 Source : GCEventAll.java
with GNU General Public License v2.0
from Tencent

/**
 * Verifies that all events belonging to a single GC are ok.
 * A GcBatch contains all flight recorder events that belong to a single GC.
 */
private void verifySingleGcBatch(List<GCHelper.GcBatch> batches) {
    for (GCHelper.GcBatch batch : batches) {
        // System.out.println("batch:\r\n" + batch.getLog());
        try {
            RecordedEvent endEvent = batch.getEndEvent();
            replacederts.replacedertNotNull(endEvent, "No end event in batch.");
            replacederts.replacedertNotNull(batch.getName(), "No method name in end event.");
            long longestPause = Events.replacedertField(endEvent, "longestPause").atLeast(0L).getValue();
            Events.replacedertField(endEvent, "sumOfPauses").atLeast(longestPause).getValue();
            Instant batchStartTime = endEvent.getStartTime();
            Instant batchEndTime = endEvent.getEndTime();
            for (RecordedEvent event : batch.getEvents()) {
                if (event.getEventType().getName().contains("AllocationRequiringGC")) {
                    // Unlike other events, these are sent *before* a GC.
                    replacederts.replacedertLessThanOrEqual(event.getStartTime(), batchStartTime, "Timestamp in event after start event, should be sent before GC start");
                } else if (!event.getEventType().getName().contains("G1MMU")) {
                    // G1MMU event on JDK8 G1 can be out-of-order; don't check it here
                    replacederts.replacedertGreaterThanOrEqual(event.getStartTime(), batchStartTime, "startTime in event before batch start event, should be sent after GC start [" + event.getEventType().getName() + "]");
                }
                replacederts.replacedertLessThanOrEqual(event.getEndTime(), batchEndTime, "endTime in event after batch end event, should be sent before GC end");
            }
            // Verify that all required events has been received.
            String[] requiredEvents = GCHelper.requiredEvents.get(batch.getName());
            replacederts.replacedertNotNull(requiredEvents, "No required events specified for " + batch.getName());
            for (String requiredEvent : requiredEvents) {
                boolean b = batch.containsEvent(requiredEvent);
                replacederts.replacedertTrue(b, String.format("%s does not contain event %s", batch, requiredEvent));
            }
            // Verify that we have exactly one heap_summary "Before GC" and one "After GC".
            int countBeforeGc = 0;
            int countAfterGc = 0;
            for (RecordedEvent event : batch.getEvents()) {
                if (GCHelper.event_heap_summary.equals(event.getEventType().getName())) {
                    String when = Events.replacedertField(event, "when").notEmpty().getValue();
                    if ("Before GC".equals(when)) {
                        countBeforeGc++;
                    } else if ("After GC".equals(when)) {
                        countAfterGc++;
                    } else {
                        replacederts.fail("Unknown value for heap_summary.when: '" + when + "'");
                    }
                }
            }
            if (!GCHelper.gcConcurrentMarkSweep.equals(batch.getName())) {
                // We do not get heap_summary events for ConcurrentMarkSweep
                replacederts.replacedertEquals(1, countBeforeGc, "Unexpected number of heap_summary.before_gc");
                replacederts.replacedertEquals(1, countAfterGc, "Unexpected number of heap_summary.after_gc");
            }
        } catch (Throwable e) {
            GCHelper.log("verifySingleGcBatch failed for gcEvent:");
            GCHelper.log(batch.getLog());
            throw e;
        }
    }
}

18 Source : TestCreateConfigFromReader.java
with GNU General Public License v2.0
from Tencent

private static void testNullReader() throws Exception {
    try {
        Configuration.create((Reader) null);
        replacederts.fail("Exception was not thrown");
    } catch (NullPointerException x) {
    }
}

18 Source : TestEventTime.java
with GNU General Public License v2.0
from Tencent

private static RecordedEvent findEvent(int id, List<RecordedEvent> events) {
    for (RecordedEvent event : events) {
        if (!event.getEventType().getName().equals(EventNames.CPUTimeStampCounter)) {
            int eventId = Events.replacedertField(event, "id").getValue();
            if (eventId == id) {
                return event;
            }
        }
    }
    replacederts.fail("No event with id " + id);
    return null;
}

18 Source : TestGetAnnotationElements.java
with GNU General Public License v2.0
from Tencent

private static void replacedertContainsAnnotation(List<AnnotationElement> aez, Clreplaced<?> clz) {
    for (AnnotationElement ae : aez) {
        if (ae.getTypeName().equals(clz.getName())) {
            return;
        }
    }
    replacederts.fail("Clreplaced " + clz + " not found in the annotation elements");
}

17 Source : TestSetConfigurationInvalid.java
with GNU General Public License v2.0
from Tencent

private static void setInvalidConfig(long recId, String config) {
    try {
        JmxHelper.getFlighteRecorderMXBean().setConfiguration(recId, config);
        System.out.printf("Invalid config:%n%s", config);
        replacederts.fail("No exception when setting invalid configuration");
    } catch (IllegalArgumentException e) {
        // Expected exception
        // Simple check if error message is about parse error.
        String msg = e.getMessage().toLowerCase();
        replacederts.replacedertTrue(msg.contains("parse"), String.format("Missing 'parse' in msg '%s'", msg));
    }
}

17 Source : TestPredefinedConfigurationInvalid.java
with GNU General Public License v2.0
from Tencent

private static void setInvalidConfigName(long recId, String name) {
    try {
        JmxHelper.getFlighteRecorderMXBean().setPredefinedConfiguration(recId, name);
        replacederts.fail("Missing Exception when setNamedConfig('" + name + "')");
    } catch (IllegalArgumentException e) {
        // Expected exception.
        String msg = e.getMessage().toLowerCase();
        System.out.println("Got expected exception: " + msg);
        String expectMsg = "not find configuration";
        replacederts.replacedertTrue(msg.contains(expectMsg), String.format("No '%s' in '%s'", expectMsg, msg));
    }
}

17 Source : TestCopyToRunning.java
with GNU General Public License v2.0
from Tencent

private static Recording getRecording(long recId) {
    for (Recording r : FlightRecorder.getFlightRecorder().getRecordings()) {
        if (r.getId() == recId) {
            return r;
        }
    }
    replacederts.fail("Could not find recording with id " + recId);
    return null;
}

17 Source : TestMetadataRetention.java
with GNU General Public License v2.0
from Tencent

private static void replacedertStackTrace(RecordedStackTrace stacktrace, final String methodName) {
    for (RecordedFrame f : stacktrace.getFrames()) {
        if (f.getMethod().getName().equals(methodName)) {
            return;
        }
    }
    replacederts.fail("Could not find clreplaced " + methodName + " in stack trace " + stacktrace);
}

17 Source : TestHeapSummaryEventConcurrentCMS.java
with GNU General Public License v2.0
from Tencent

private static void verifyHeapSummary(List<RecordedEvent> events, int gcId, String when) {
    for (RecordedEvent event : events) {
        if (!Events.isEventType(event, EventNames.GCHeapSummary)) {
            continue;
        }
        if (gcId == (int) Events.replacedertField(event, "gcId").getValue() && when.equals(Events.replacedertField(event, "when").getValue())) {
            System.out.printf("Found " + EventNames.GCHeapSummary + " for id=%d, when=%s%n", gcId, when);
            return;
        }
    }
    replacederts.fail(String.format("No " + EventNames.GCHeapSummary + " for id=%d, when=%s", gcId, when));
}

17 Source : HeapSummaryEventAllGcs.java
with GNU General Public License v2.0
from Tencent

private static boolean checkCollectors(Recording recording, String expectedYoung, String expectedOld) throws Exception {
    for (RecordedEvent event : Events.fromRecording(recording)) {
        if (Events.isEventType(event, EventNames.GCConfiguration)) {
            final String young = Events.replacedertField(event, "youngCollector").notEmpty().getValue();
            final String old = Events.replacedertField(event, "oldCollector").notEmpty().getValue();
            if (young.equals(expectedYoung) && old.equals(expectedOld)) {
                return true;
            }
            // TODO: We treat wrong collector types as an error. Old test only warned. Not sure what is correct.
            replacederts.fail(String.format("Wrong collector types: got('%s','%s'), expected('%s','%s')", young, old, expectedYoung, expectedOld));
        }
    }
    replacederts.fail("Missing event type " + EventNames.GCConfiguration);
    return false;
}

17 Source : TestGetStream.java
with GNU General Public License v2.0
from Tencent

private static void replacedertEndBeforeBegin() throws IOException {
    try (Recording recording = new Recording()) {
        recording.start();
        recording.stop();
        Instant begin = Instant.now();
        Instant end = begin.minusNanos(1);
        recording.getStream(begin, end);
        replacederts.fail("Expected IllegalArgumentException has not been thrown");
    } catch (IllegalArgumentException x) {
    // Caught the expected exception
    }
}

17 Source : TestRegistered.java
with GNU General Public License v2.0
from Tencent

public static void main(String[] args) throws Exception {
    try {
        EventType.getEventType(NotRegisteredByDefaultEvent.clreplaced);
        throw new Exception("Should not be able to get event type from unregistered event type");
    } catch (IllegalStateException ise) {
    // as expected
    }
    EventType registered = EventType.getEventType(RegisteredByDefaultEvent.clreplaced);
    boolean registeredWorking = false;
    for (EventType type : FlightRecorder.getFlightRecorder().getEventTypes()) {
        if (registered.getId() == type.getId()) {
            registeredWorking = true;
        }
    }
    if (!registeredWorking) {
        replacederts.fail("Default regsitration is not working, can't validate @NoAutoRegistration");
    }
}

17 Source : TestEventFactoryRegistration.java
with GNU General Public License v2.0
from Tencent

private static void verifyUnregistered(EventType eventType) {
    // Verify the event is not registered
    for (EventType type : FlightRecorder.getFlightRecorder().getEventTypes()) {
        if (eventType.getId() == type.getId()) {
            replacederts.fail("Event is not unregistered");
        }
    }
}

17 Source : TestEventFactoryRegistration.java
with GNU General Public License v2.0
from Tencent

private static void verifyRegistered(EventType eventType) {
    // Verify  the event is registered
    boolean found = false;
    for (EventType type : FlightRecorder.getFlightRecorder().getEventTypes()) {
        if (eventType.getId() == type.getId()) {
            found = true;
        }
    }
    if (!found) {
        replacederts.fail("Event not registered");
    }
}

16 Source : TestGetEventType.java
with GNU General Public License v2.0
from Tencent

public static void main(String[] args) throws Throwable {
    EventType type = EventType.getEventType(MyEventA.clreplaced);
    replacederts.replacedertEquals(type.getName(), MyEventA.clreplaced.getName(), "Wrong EventType for MyEventA");
    type = EventType.getEventType(MyEventB.clreplaced);
    replacederts.replacedertEquals(type.getName(), MyEventB.clreplaced.getName(), "Wrong EventType for MyEventB");
    try {
        EventType.getEventType(null);
        replacederts.fail("No exception for getEventType(null)");
    } catch (Exception e) {
    // Expected exception
    }
}

16 Source : TestClinitRegistration.java
with GNU General Public License v2.0
from Tencent

public static void main(String[] args) throws Exception {
    // Test basic registration with or without auto registration
    replacedertClinitRegister(AutoRegisteredEvent.clreplaced, true, false);
    replacedertClinitRegister(NotAutoRegisterededEvent.clreplaced, false, false);
    replacedertClinitRegister(AutoRegisteredUserClinit.clreplaced, true, true);
    replacedertClinitRegister(NotAutoRegisteredUserClinit.clreplaced, false, true);
    // Test complex <clinit>
    replacedertClinitRegister(ComplexClInit.clreplaced, true, true);
    // Test hierarchy
    replacedertClinitRegister(DerivedClinit.clreplaced, true, true);
    if (!isClinitExecuted(Base.clreplaced)) {
        replacederts.fail("Expected <clinit> of base clreplaced to be executed");
    }
    // Test committed event in <clinit>
    Recording r = new Recording();
    r.start();
    r.enable(EventInClinit.clreplaced);
    triggerClinit(EventInClinit.clreplaced);
    r.stop();
    hasEvent(r, EventInClinit.clreplaced.getName());
}

16 Source : TestHeapDumpForInvokeDynamic.java
with GNU General Public License v2.0
from hzio

private static void verifyHeapDump(String heapFile) {
    File heapDumpFile = new File(heapFile);
    replacederts.replacedertTrue(heapDumpFile.exists() && heapDumpFile.isFile(), "Could not create dump file " + heapDumpFile.getAbsolutePath());
    try (PositionDataInputStream in = new PositionDataInputStream(new BufferedInputStream(new FileInputStream(heapFile)))) {
        int i = in.readInt();
        if (HprofReader.verifyMagicNumber(i)) {
            Snapshot sshot;
            HprofReader r = new HprofReader(heapFile, in, 0, false, 0);
            sshot = r.read();
        } else {
            throw new IOException("Unrecognized magic number: " + i);
        }
    } catch (Exception e) {
        e.printStackTrace();
        replacederts.fail("Could not read dump file " + heapFile);
    } finally {
        heapDumpFile.delete();
    }
}

15 Source : EventField.java
with GNU General Public License v2.0
from Tencent

public EventField containsAny(String... allowed) {
    final String value = getValue();
    final List<String> allowedValues = Arrays.asList(allowed);
    boolean contains = false;
    for (String allowedValue : allowed) {
        if (value.contains(allowedValue)) {
            contains = true;
        }
    }
    if (!contains) {
        doreplacedert(() -> replacederts.fail(getErrMsg(String.format("Value not in (%s)", allowedValues.stream().collect(Collectors.joining(", "))))));
    }
    return this;
}

15 Source : TestRetransform.java
with GNU General Public License v2.0
from Tencent

public static void main(String[] args) throws Exception {
    EventType type = EventType.getEventType(TestEvent.clreplaced);
    if (type.isEnabled()) {
        replacederts.fail("Expected event to be disabled before recording start");
    }
    Recording r = new Recording();
    r.start();
    if (!type.isEnabled()) {
        replacederts.fail("Expected event to be enabled during recording");
    }
    TestEvent testEvent = new TestEvent();
    testEvent.commit();
    loadEventClreplacedDuringRecording();
    r.stop();
    if (type.isEnabled()) {
        replacederts.fail("Expected event to be disabled after recording stopped");
    }
    Events.hasEvent(r, SimpleEvent.clreplaced.getName());
    Events.hasEvent(r, TestEvent.clreplaced.getName());
}

15 Source : StartupHelper.java
with GNU General Public License v2.0
from Tencent

public static Recording getRecording(String name) {
    for (Recording r : FlightRecorder.getFlightRecorder().getRecordings()) {
        System.out.println("Recording=" + r.getName());
        if (name.equals(r.getName())) {
            return r;
        }
    }
    replacederts.fail("No recording with name " + name);
    return null;
}

15 Source : TestEventTypes.java
with GNU General Public License v2.0
from Tencent

private static void verifyMyEventType(List<EventTypeInfo> infos) {
    for (EventTypeInfo info : infos) {
        if ("MyEvent.name".equals(info.getName())) {
            System.out.println("EventTypeInfo for MyEvent: " + info);
            replacederts.replacedertEquals("MyEvent.label", info.getLabel());
            replacederts.replacedertEquals("MyEvent.description", info.getDescription());
            for (SettingDescriptorInfo si : info.getSettingDescriptors()) {
                System.out.println("si=" + si);
            }
            return;
        }
    }
    replacederts.fail("Missing EventTypeInfo for MyEvent");
}

15 Source : TestJavaMonitorWaitTimeOut.java
with GNU General Public License v2.0
from Tencent

private static void replacedertTimeOutEvent(List<RecordedEvent> events, long timeout, String expectedThreadName) {
    for (RecordedEvent e : events) {
        if (isWaitEvent(e)) {
            Long l = e.getValue("timeout");
            if (l == timeout) {
                RecordedThread notifier = e.getValue("notifier");
                String threadName = null;
                if (notifier != null) {
                    threadName = notifier.getJavaName();
                }
                replacederts.replacedertEquals(threadName, expectedThreadName, "Invalid thread");
                return;
            }
        }
    }
    replacederts.fail("Could not find event with monitorClreplaced" + Lock.clreplaced.getName());
}

15 Source : TestMetadataRetention.java
with GNU General Public License v2.0
from Tencent

private static void validateOldObjectEvent(List<RecordedEvent> events, Instant chunkRotation) throws Throwable {
    for (RecordedEvent event : events) {
        if (event.getEventType().getName().equals(EventNames.OldObjectSample)) {
            // Only check event after the rotation
            if (!event.getStartTime().isBefore(chunkRotation)) {
                System.out.println(event);
                RecordedThread rt = event.getThread();
                if (rt.getJavaName().equals(ALLOCATOR_THREAD_NAME)) {
                    RecordedStackTrace s = event.getStackTrace();
                    replacedertStackTrace(s, "startRecurse");
                    replacedertStackTrace(s, "recurse");
                    return;
                }
            }
        }
    }
    replacederts.fail("Did not find an old object event with thread " + ALLOCATOR_THREAD_NAME);
}

15 Source : TestRecordingEnableDisable.java
with GNU General Public License v2.0
from Tencent

private static void updateSettings(Recording r) {
    int operationIndex = rand.nextInt(4);
    switch(operationIndex) {
        case 0:
            SimpleEventHelper.enable(r, true);
            break;
        case 1:
            SimpleEventHelper.enable(r, false);
            break;
        case 2:
            r.enable(EVENT_PATH).withoutStackTrace();
            break;
        case 3:
            r.disable(EVENT_PATH);
            break;
        default:
            replacederts.fail("Wrong operataionIndex. Test error");
    }
}

15 Source : TestName.java
with GNU General Public License v2.0
from Tencent

private static SettingDescriptor getSetting(EventType t, String name) {
    for (SettingDescriptor v : t.getSettingDescriptors()) {
        if (v.getName().equals(name)) {
            return v;
        }
    }
    replacederts.fail("Could not find setting with name " + name);
    return null;
}

14 Source : TestEventTypes.java
with GNU General Public License v2.0
from Tencent

private static void replacedertSame(List<EventTypeInfo> infos, List<EventType> types) {
    List<Long> ids = new ArrayList<>();
    for (EventTypeInfo info : infos) {
        long id = info.getId();
        replacederts.replacedertFalse(ids.contains(id), "EventTypeInfo.id not unique:" + id);
        ids.add(id);
        boolean isFound = false;
        for (EventType type : types) {
            if (type.getId() == id) {
                replacedertSame(info, type);
                isFound = true;
                break;
            }
        }
        if (!isFound) {
            String msg = "No EventType for EventTypeInfo";
            System.out.println(msg + ": " + info);
            replacederts.fail(msg);
        }
    }
    replacederts.replacedertEquals(infos.size(), types.size(), "Number of EventTypeInfos != EventTypes");
}

14 Source : TestClone.java
with GNU General Public License v2.0
from Tencent

private static void verifyEvents(Path path, int... ids) throws Exception {
    List<RecordedEvent> events = RecordingFile.readAllEvents(path);
    Iterator<RecordedEvent> iterator = events.iterator();
    for (int i = 0; i < ids.length; i++) {
        replacederts.replacedertTrue(iterator.hasNext(), "Missing event " + ids[i]);
        EventField idField = Events.replacedertField(iterator.next(), "id");
        System.out.println("Event.id=" + idField.getValue());
        idField.equal(ids[i]);
    }
    if (iterator.hasNext()) {
        replacederts.fail("Got extra event: " + iterator.next());
    }
}

14 Source : TestNotificationListenerPermission.java
with GNU General Public License v2.0
from Tencent

public static void main(String[] args) throws Throwable {
    try {
        System.getProperty("user.name");
        replacederts.fail("Didn't get security exception. Test not configured propertly?");
    } catch (SecurityException se) {
    // as expected
    }
    FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean();
    TestListener testListener = new TestListener();
    ManagementFactory.getPlatformMBeanServer().addNotificationListener(new ObjectName(FlightRecorderMXBean.MXBEAN_NAME), testListener, null, null);
    long id = bean.newRecording();
    bean.startRecording(id);
    testListener.awaitNotication();
    replacederts.replacedertTrue(gotSecurityException, "Should not get elevated privileges in notification handler!");
    bean.stopRecording(id);
    bean.closeRecording(id);
}

14 Source : TestThreadCpuTimeEvent.java
with GNU General Public License v2.0
from Tencent

static List<RecordedEvent> generateEvents(int minimumEventCount, CyclicBarrier barrier) throws Throwable {
    int retryCount = 0;
    while (true) {
        Recording recording = new Recording();
        // Default period is once per chunk
        recording.enable(EventNames.ThreadCPULoad).withPeriod(Duration.ofMillis(eventPeriodMillis));
        recording.start();
        // Run a single preplaced
        barrier.await();
        barrier.await();
        recording.stop();
        List<RecordedEvent> events = Events.fromRecording(recording);
        long numEvents = events.stream().filter(e -> e.getThread().getJavaName().equals(cpuConsumerThreadName)).count();
        // If the JFR periodicals thread is really starved, we may not get enough events.
        // In that case, we simply retry the operation.
        if (numEvents < minimumEventCount) {
            System.out.println("Not enough events recorded, trying again...");
            if (retryCount++ > 10) {
                replacederts.fail("Retry count exceeded");
                throw new RuntimeException();
            }
        } else {
            return events;
        }
    }
}

13 Source : TestStreamClosed.java
with GNU General Public License v2.0
from Tencent

public static void main(String[] args) throws Exception {
    FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean();
    long recId = bean.newRecording();
    bean.startRecording(recId);
    SimpleEventHelper.createEvent(1);
    bean.stopRecording(recId);
    long streamId = bean.openStream(recId, null);
    bean.closeStream(streamId);
    try {
        bean.readStream(streamId);
        replacederts.fail("No exception whean reading closed stream");
    } catch (IOException e) {
        // Expected exception.
        String msg = e.getMessage().toLowerCase();
        replacederts.replacedertTrue(msg.contains("stream") && msg.contains("closed"), "No 'stream closed' in " + msg);
    }
    bean.closeRecording(recId);
}

13 Source : TestConfigurationInfo.java
with GNU General Public License v2.0
from Tencent

private static void verifySettingsEqual(Configuration config, ConfigurationInfo configInfo) {
    Map<String, String> javaSettings = config.getSettings();
    Map<String, String> jmxSettings = configInfo.getSettings();
    replacederts.replacedertFalse(javaSettings.isEmpty(), "No Settings found in java apa");
    replacederts.replacedertFalse(jmxSettings.isEmpty(), "No Settings found in jmx api");
    for (String name : jmxSettings.keySet().toArray(new String[0])) {
        System.out.printf("%s: jmx=%s, java=%s%n", name, jmxSettings.get(name), javaSettings.get(name));
        replacederts.replacedertNotNull(javaSettings.get(name), "No java setting for " + name);
        replacederts.replacedertEquals(jmxSettings.get(name), javaSettings.get(name), "Wrong value for setting");
        javaSettings.remove(name);
    }
    // Verify that all Settings have been matched.
    if (!javaSettings.isEmpty()) {
        for (String name : javaSettings.keySet()) {
            System.out.println("Found extra Settings name " + name);
        }
        replacederts.fail("Found extra Setting in java api");
    }
}

13 Source : TestDestFileReadOnly.java
with GNU General Public License v2.0
from Tencent

public static void main(String[] args) throws Throwable {
    Path dest = FileHelper.createReadOnlyFile(Paths.get(".", "readonly.txt"));
    System.out.println("dest=" + dest.toFile().getAbsolutePath());
    if (!FileHelper.isReadOnlyPath(dest)) {
        System.out.println("Failed to create a read-only file. Test ignored.");
        return;
    }
    Recording r = new Recording();
    r.setToDisk(true);
    try {
        r.setDestination(dest);
        replacederts.fail("No exception when destination is read-only");
    } catch (IOException e) {
    // Expected exception
    }
    r.close();
}

13 Source : TestGetSettings.java
with GNU General Public License v2.0
from Tencent

public static void main(String[] args) throws Throwable {
    EventType eventType = EventType.getEventType(EventWithCustomSettings.clreplaced);
    List<SettingDescriptor> settings = eventType.getSettingDescriptors();
    replacederts.replacedertEquals(settings.size(), 5, "Wrong number of settings");
    // test immutability
    try {
        settings.add(settings.get(0));
        replacederts.fail("Should not be able to modify list returned by getSettings()");
    } catch (UnsupportedOperationException uoe) {
    // OK, as expected
    }
}

13 Source : TestGetField.java
with GNU General Public License v2.0
from Tencent

public static void main(String[] args) throws Throwable {
    EventType type = EventType.getEventType(MyEvent.clreplaced);
    ValueDescriptor v = type.getField("myByte");
    replacederts.replacedertNotNull(v, "getFiled(myByte) was null");
    replacederts.replacedertEquals(v.getTypeName(), "byte", "myByte was not type byte");
    v = type.getField("myInt");
    replacederts.replacedertNotNull(v, "getFiled(myInt) was null");
    replacederts.replacedertEquals(v.getTypeName(), "int", "myInt was not type int");
    v = type.getField("myStatic");
    replacederts.replacedertNull(v, "got static field");
    v = type.getField("notAField");
    replacederts.replacedertNull(v, "got field that does not exist");
    v = type.getField("");
    replacederts.replacedertNull(v, "got field for empty name");
    try {
        v = type.getField(null);
        replacederts.fail("No Exception when getField(null)");
    } catch (NullPointerException e) {
    // Expected exception
    }
}

13 Source : TestClinitRegistration.java
with GNU General Public License v2.0
from Tencent

public static void hasEvent(Recording r, String name) throws IOException {
    List<RecordedEvent> events = Events.fromRecording(r);
    Events.hasEvents(events);
    for (RecordedEvent event : events) {
        if (event.getEventType().getName().equals(name)) {
            return;
        }
    }
    replacederts.fail("Missing event " + name + " in recording " + events.toString());
}

12 Source : SimpleEventHelper.java
with GNU General Public License v2.0
from Tencent

public static void verifyContains(List<RecordedEvent> events, int... ids) throws Exception {
    Set<Integer> missingIds = new HashSet<>();
    for (int id : ids) {
        missingIds.add(id);
    }
    for (RecordedEvent event : getSimpleEvents(events)) {
        int id = Events.replacedertField(event, "id").getValue();
        System.out.printf("event.id=%d%n", id);
        missingIds.remove(new Integer(id));
    }
    if (!missingIds.isEmpty()) {
        missingIds.forEach(id -> System.out.println("Missing MyEvent with id " + id));
        replacederts.fail("Missing some MyEvent events");
    }
}

See More Examples