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

The following examples show how to use jdk.test.lib.Asserts#assertGreaterThanOrEqual() . 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: TestRandomAccessFileThread.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void verifyTimes(List<RecordedEvent> events) {
    RecordedEvent prev = null;
    for (RecordedEvent curr : events) {
        if (prev != null) {
            try {
                Asserts.assertGreaterThanOrEqual(curr.getStartTime(), prev.getStartTime(), "Wrong startTime");
                Asserts.assertGreaterThanOrEqual(curr.getEndTime(), prev.getEndTime(), "Wrong endTime");
                long commitPrev = Events.assertField(prev, "startTime").getValue();
                long commitCurr = Events.assertField(curr, "startTime").getValue();
                Asserts.assertGreaterThanOrEqual(commitCurr, commitPrev, "Wrong commitTime");
            } catch (Exception e) {
                System.out.println("Error: " + e.getMessage());
                System.out.println("Prev Event: " + prev);
                System.out.println("Curr Event: " + curr);
                throw e;
            }
        }
        prev = curr;
    }
}
 
Example 2
Source File: TestTimeDuration.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Recording r = new Recording();
    final Duration duration = Duration.ofMillis(30000);

    r.setDuration(duration);
    Asserts.assertNull(r.getStartTime(), "getStartTime() not null before start");
    Asserts.assertNull(r.getStopTime(), "getStopTime() not null before start");

    final Instant beforeStart = Instant.now();
    r.start();
    final Instant afterStart = Instant.now();

    Asserts.assertNotNull(r.getStartTime(), "getStartTime() null after start()");
    Asserts.assertGreaterThanOrEqual(r.getStartTime(), beforeStart, "getStartTime() < beforeStart");
    Asserts.assertLessThanOrEqual(r.getStartTime(), afterStart, "getStartTime() > afterStart");

    Asserts.assertNotNull(r.getStopTime(), "getStopTime() null after start with duration");
    Asserts.assertGreaterThanOrEqual(r.getStopTime(), beforeStart.plus(duration), "getStopTime() < beforeStart + duration");
    Asserts.assertLessThanOrEqual(r.getStopTime(), afterStart.plus(duration), "getStopTime() > afterStart + duration");

    r.close();
}
 
Example 3
Source File: TestExceptionEvents.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void checkStatisticsEvent(List<RecordedEvent> events, long minCount) throws Exception {
    // Events are not guaranteed to be in chronological order, take highest value.
    long count = -1;
    for(RecordedEvent event : events) {
        if (Events.isEventType(event, EXCEPTION_STATISTICS_PATH)) {
            System.out.println("Event: " + event);
            count = Math.max(count, Events.assertField(event, "throwables").getValue());
            System.out.println("count=" +  count);
        }
    }
    Asserts.assertTrue(count != -1, "No events of type " + EXCEPTION_STATISTICS_PATH);
    Asserts.assertGreaterThanOrEqual(count, minCount, "Too few exception count in statistics event");
}
 
Example 4
Source File: TestCodeSweeper.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void verifySingleSweepEvent(RecordedEvent event) throws Throwable {
    int flushedCount = Events.assertField(event, "flushedCount").atLeast(0).getValue();
    int zombifiedCount = Events.assertField(event, "zombifiedCount").atLeast(0).getValue();
    Events.assertField(event, "sweptCount").atLeast(flushedCount + zombifiedCount);
    Events.assertField(event, "sweepId").atLeast(0);
    Asserts.assertGreaterThanOrEqual(event.getStartTime(), Instant.EPOCH, "startTime was < 0");
    Asserts.assertGreaterThanOrEqual(event.getEndTime(), event.getStartTime(), "startTime was > endTime");
}
 
Example 5
Source File: TestThreadCpuTimeEvent.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
static void testCompareWithMXBean() throws Throwable {
    Duration testRunTime = Duration.ofMillis(eventPeriodMillis * cpuConsumerRunFactor);
    CyclicBarrier barrier = new CyclicBarrier(2);
    CpuConsumingThread thread = new CpuConsumingThread(testRunTime, barrier);
    thread.start();

    List<RecordedEvent> beforeEvents = generateEvents(2, barrier);
    verifyPerThreadInvariant(beforeEvents, cpuConsumerThreadName);

    // Run a second single pass
    barrier.await();
    barrier.await();

    ThreadMXBean bean = (ThreadMXBean) ManagementFactory.getThreadMXBean();
    Duration cpuTime = Duration.ofNanos(bean.getThreadCpuTime(thread.getId()));
    Duration userTime = Duration.ofNanos(bean.getThreadUserTime(thread.getId()));

    // Check something that should hold even in the presence of unfortunate scheduling
    Asserts.assertGreaterThanOrEqual(cpuTime.toMillis(), eventPeriodMillis);
    Asserts.assertGreaterThanOrEqual(userTime.toMillis(), eventPeriodMillis);

    Duration systemTimeBefore = getAccumulatedTime(beforeEvents, cpuConsumerThreadName, "system");
    Duration userTimeBefore = getAccumulatedTime(beforeEvents, cpuConsumerThreadName, "user");
    Duration cpuTimeBefore = userTimeBefore.plus(systemTimeBefore);

    Asserts.assertLessThan(cpuTimeBefore, cpuTime);
    Asserts.assertLessThan(userTimeBefore, userTime);
    Asserts.assertGreaterThan(cpuTimeBefore, Duration.ZERO);

    thread.interrupt();
    thread.join();
}
 
Example 6
Source File: TestChunkPeriod.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void testEndChunk() throws IOException {
    Recording r = new Recording();
    r.enable(SimpleEvent.class).with("period", "endChunk");
    r.start();
    Instant beforeStop = Instant.now().minus(MARGIN_OF_ERROR);
    r.stop();
    Instant afterStop =  Instant.now().plus(MARGIN_OF_ERROR);
    List<RecordedEvent> events = Events.fromRecording(r);
    Asserts.assertEquals(events.size(), 1, "Expected one event with endChunk");
    RecordedEvent event = events.get(0);
    Asserts.assertGreaterThanOrEqual(event.getStartTime(), beforeStop);
    Asserts.assertGreaterThanOrEqual(afterStop, event.getStartTime());
    r.close();
}
 
Example 7
Source File: TestStartDelay.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 {
    Instant testStart = Instant.now();
    System.out.println("Test started at " + testStart);
    Recording r = StartupHelper.getRecording("TestStartDelay");
    CommonHelper.verifyRecordingState(r, RecordingState.DELAYED);
    Asserts.assertNotNull(r.getStartTime(), "Recording start time should not be null for a delayed recording");
    Asserts.assertLessThanOrEqual(r.getStartTime(), testStart.plus(Duration.ofSeconds(5000)), "Recording start time should not exceed test start time + delay");
    Asserts.assertGreaterThanOrEqual(r.getStartTime(), testStart, "Recording start time should not happen before test start time");
    r.close();
}
 
Example 8
Source File: HeapSummaryEventAllGcs.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void checkPSYoungSizes(RecordedEvent event) {
    long youngSize = (long)Events.assertField(event, "youngSpace.committedEnd").getValue() -
                    (long)Events.assertField(event, "youngSpace.start").getValue();
    long edenSize = (long)Events.assertField(event, "edenSpace.end").getValue() -
                    (long)Events.assertField(event, "edenSpace.start").getValue();
    long fromSize = (long)Events.assertField(event, "fromSpace.end").getValue() -
                    (long)Events.assertField(event, "fromSpace.start").getValue();
    long toSize = (long)Events.assertField(event, "toSpace.end").getValue() -
                    (long)Events.assertField(event, "toSpace.start").getValue();
    Asserts.assertGreaterThanOrEqual(youngSize, edenSize + fromSize + toSize, "Young sizes don't match");
}
 
Example 9
Source File: TestCodeSweeper.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void verifySingleSweepEvent(RecordedEvent event) throws Throwable {
    int flushedCount = Events.assertField(event, "flushedCount").atLeast(0).getValue();
    int zombifiedCount = Events.assertField(event, "zombifiedCount").atLeast(0).getValue();
    Events.assertField(event, "sweptCount").atLeast(flushedCount + zombifiedCount);
    Events.assertField(event, "sweepId").atLeast(0);
    Asserts.assertGreaterThanOrEqual(event.getStartTime(), Instant.EPOCH, "startTime was < 0");
    Asserts.assertGreaterThanOrEqual(event.getEndTime(), event.getStartTime(), "startTime was > endTime");
}
 
Example 10
Source File: TestStartDelay.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 {
    Instant testStart = Instant.now();
    System.out.println("Test started at " + testStart);
    Recording r = StartupHelper.getRecording("TestStartDelay");
    CommonHelper.verifyRecordingState(r, RecordingState.DELAYED);
    Asserts.assertNotNull(r.getStartTime(), "Recording start time should not be null for a delayed recording");
    Asserts.assertLessThanOrEqual(r.getStartTime(), testStart.plus(Duration.ofSeconds(5000)), "Recording start time should not exceed test start time + delay");
    Asserts.assertGreaterThanOrEqual(r.getStartTime(), testStart, "Recording start time should not happen before test start time");
    r.close();
}
 
Example 11
Source File: TestSnapshot.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void testStopped() throws IOException {
    FlightRecorder recorder = FlightRecorder.getFlightRecorder();
    try (Recording r = new Recording()) {
        r.enable(SimpleEvent.class);
        r.start();
        SimpleEvent se = new SimpleEvent();
        se.commit();
        r.stop();

        try (Recording snapshot = recorder.takeSnapshot()) {

            Asserts.assertEquals(snapshot.getSize(), r.getSize());
            Asserts.assertGreaterThanOrEqual(snapshot.getStartTime(), r.getStartTime());
            Asserts.assertLessThanOrEqual(snapshot.getStopTime(), r.getStopTime());
            Asserts.assertGreaterThanOrEqual(snapshot.getDuration(), Duration.ZERO);
            assertStaticOptions(snapshot);
            try (InputStream is = snapshot.getStream(null, null)) {
                Asserts.assertNotNull(is);
            }

            List<RecordedEvent> events = Events.fromRecording(snapshot);
            Events.hasEvents(events);
            Asserts.assertEquals(events.size(), 1);
            Asserts.assertEquals(events.get(0).getEventType().getName(), SimpleEvent.class.getName());
        }
    }
}
 
Example 12
Source File: TestSnapshot.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void testOngoing(boolean disk) throws IOException {
    FlightRecorder recorder = FlightRecorder.getFlightRecorder();
    try (Recording r = new Recording()) {
        r.setToDisk(disk);
        r.enable(SimpleEvent.class);
        r.start();
        SimpleEvent se = new SimpleEvent();
        se.commit();

        try (Recording snapshot = recorder.takeSnapshot()) {

            Asserts.assertGreaterThan(snapshot.getSize(), 0L);
            Asserts.assertGreaterThanOrEqual(snapshot.getStartTime(), r.getStartTime());
            Asserts.assertGreaterThanOrEqual(snapshot.getStopTime(), r.getStartTime());
            Asserts.assertGreaterThanOrEqual(snapshot.getDuration(), Duration.ZERO);
            assertStaticOptions(snapshot);
            try (InputStream is = snapshot.getStream(null, null)) {
                Asserts.assertNotNull(is);
            }

            List<RecordedEvent> events = Events.fromRecording(snapshot);
            Events.hasEvents(events);
            Asserts.assertEquals(events.size(), 1);
            Asserts.assertEquals(events.get(0).getEventType().getName(), SimpleEvent.class.getName());
        }

        r.stop();
    }
}
 
Example 13
Source File: TestSnapshot.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void testOngoing(boolean disk) throws IOException {
    FlightRecorder recorder = FlightRecorder.getFlightRecorder();
    try (Recording r = new Recording()) {
        r.setToDisk(disk);
        r.enable(SimpleEvent.class);
        r.start();
        SimpleEvent se = new SimpleEvent();
        se.commit();

        try (Recording snapshot = recorder.takeSnapshot()) {

            Asserts.assertGreaterThan(snapshot.getSize(), 0L);
            Asserts.assertGreaterThanOrEqual(snapshot.getStartTime(), r.getStartTime());
            Asserts.assertGreaterThanOrEqual(snapshot.getStopTime(), r.getStartTime());
            Asserts.assertGreaterThanOrEqual(snapshot.getDuration(), Duration.ZERO);
            assertStaticOptions(snapshot);
            try (InputStream is = snapshot.getStream(null, null)) {
                Asserts.assertNotNull(is);
            }

            List<RecordedEvent> events = Events.fromRecording(snapshot);
            Events.hasEvents(events);
            Asserts.assertEquals(events.size(), 1);
            Asserts.assertEquals(events.get(0).getEventType().getName(), SimpleEvent.class.getName());
        }

        r.stop();
    }
}
 
Example 14
Source File: HeapSummaryEventAllGcs.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void checkPSYoungSizes(RecordedEvent event) {
    long youngSize = (long)Events.assertField(event, "youngSpace.committedEnd").getValue() -
                    (long)Events.assertField(event, "youngSpace.start").getValue();
    long edenSize = (long)Events.assertField(event, "edenSpace.end").getValue() -
                    (long)Events.assertField(event, "edenSpace.start").getValue();
    long fromSize = (long)Events.assertField(event, "fromSpace.end").getValue() -
                    (long)Events.assertField(event, "fromSpace.start").getValue();
    long toSize = (long)Events.assertField(event, "toSpace.end").getValue() -
                    (long)Events.assertField(event, "toSpace.start").getValue();
    Asserts.assertGreaterThanOrEqual(youngSize, edenSize + fromSize + toSize, "Young sizes don't match");
}
 
Example 15
Source File: TestChunkPeriod.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void testBeginChunk() throws IOException {
    Recording r = new Recording();
    r.enable(SimpleEvent.class).with("period", "beginChunk");
    Instant beforeStart = Instant.now().minus(MARGIN_OF_ERROR);
    r.start();
    Instant afterStart = Instant.now().plus(MARGIN_OF_ERROR);
    r.stop();
    List<RecordedEvent> events = Events.fromRecording(r);
    Asserts.assertEquals(events.size(), 1, "Expected one event with beginChunk");
    RecordedEvent event = events.get(0);
    Asserts.assertGreaterThanOrEqual(event.getStartTime(), beforeStart);
    Asserts.assertGreaterThanOrEqual(afterStart, event.getStartTime());
    r.close();
}
 
Example 16
Source File: RecurseThread.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void run() {
    // totalDepth includes functions run() and recurse() and runloop().
    // Remove 3 from totalDepth when recursing.
    final int minDepth = 3;
    Asserts.assertGreaterThanOrEqual(totalDepth, minDepth, "totalDepth too small");
    int recurseDepth = totalDepth - minDepth;

    // We want the last function before runloop() to be recurseA().
    boolean startWithRecurseA = (totalDepth % 2) != 0;
    dummy = startWithRecurseA ? recurseA(recurseDepth) : recurseB(recurseDepth);
}
 
Example 17
Source File: TestTime.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 {
    Recording r = new Recording();
    Asserts.assertNull(r.getStartTime(), "getStartTime() not null before start");
    Asserts.assertNull(r.getStopTime(), "getStopTime() not null before start");

    final Instant beforeStart = Instant.now();
    r.start();
    final Instant afterStart = Instant.now();

    Asserts.assertNotNull(r.getStartTime(), "getStartTime() null after");
    Asserts.assertGreaterThanOrEqual(r.getStartTime(), beforeStart, "getStartTime() < beforeStart");
    Asserts.assertLessThanOrEqual(r.getStartTime(), afterStart, "getStartTime() > afterStart");
    Asserts.assertNull(r.getStopTime(), "getStopTime() not null before stop");

    final Instant beforeStop = Instant.now();
    r.stop();
    final Instant afterStop = Instant.now();

    Asserts.assertGreaterThanOrEqual(r.getStartTime(), beforeStart, "getStartTime() < beforeStart");
    Asserts.assertLessThanOrEqual(r.getStartTime(), afterStart, "getStartTime() > afterStart");
    Asserts.assertNotNull(r.getStopTime(), "getStopTime() null after stop");
    Asserts.assertGreaterThanOrEqual(r.getStopTime(), beforeStop, "getStopTime() < beforeStop");
    Asserts.assertLessThanOrEqual(r.getStopTime(), afterStop, "getStopTime() > afterStop");

    r.close();

    // Same checks again to make sure close() did not change the times.
    Asserts.assertGreaterThanOrEqual(r.getStartTime(), beforeStart, "getStartTime() < beforeStart");
    Asserts.assertLessThanOrEqual(r.getStartTime(), afterStart, "getStartTime() > afterStart");
    Asserts.assertNotNull(r.getStopTime(), "getStopTime() null after stop");
    Asserts.assertGreaterThanOrEqual(r.getStopTime(), beforeStop, "getStopTime() < beforeStop");
    Asserts.assertLessThanOrEqual(r.getStopTime(), afterStop, "getStopTime() > afterStop");
}
 
Example 18
Source File: JcmdAsserts.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void assertStartTimeGreaterOrEqualThanMBeanValue(String name,
        long actualStartTime) throws Exception {
    Recording recording = findRecording(name);
    Asserts.assertNotNull(recording.getStartTime(), "Start time is not set");
    Asserts.assertGreaterThanOrEqual(actualStartTime, recording.getStartTime().toEpochMilli());
}
 
Example 19
Source File: TestTimeMultiple.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Recording rA = new Recording();
    Asserts.assertNull(rA.getStartTime(), "getStartTime() not null before start");
    Asserts.assertNull(rA.getStopTime(), "getStopTime() not null before start");

    final Instant beforeStartA = Instant.now();
    rA.start();
    final Instant afterStartA = Instant.now();

    Recording rB = new Recording();
    Asserts.assertNull(rB.getStartTime(), "getStartTime() not null before start");
    Asserts.assertNull(rB.getStopTime(), "getStopTime() not null before start");

    final Instant beforeStartB = Instant.now();
    rB.start();
    final Instant afterStartB = Instant.now();

    final Instant beforeStopB = Instant.now();
    rB.stop();
    final Instant afterStopB = Instant.now();

    final Instant beforeStopA = Instant.now();
    rA.stop();
    final Instant afterStopA = Instant.now();

    rA.close();
    rB.close();

    Asserts.assertNotNull(rA.getStartTime(), "getStartTime() null after start");
    Asserts.assertNotNull(rA.getStopTime(), "getStopTime() null after stop");
    Asserts.assertGreaterThanOrEqual(rA.getStartTime(), beforeStartA, "getStartTime() < beforeStart");
    Asserts.assertLessThanOrEqual(rA.getStartTime(), afterStartA, "getStartTime() > afterStart");
    Asserts.assertGreaterThanOrEqual(rA.getStopTime(), beforeStopA, "getStopTime() < beforeStop");
    Asserts.assertLessThanOrEqual(rA.getStopTime(), afterStopA, "getStopTime() > afterStop");

    Asserts.assertNotNull(rB.getStartTime(), "getStartTime() null after start");
    Asserts.assertNotNull(rB.getStopTime(), "getStopTime() null after stop");
    Asserts.assertGreaterThanOrEqual(rB.getStartTime(), beforeStartB, "getStartTime() < beforeStart");
    Asserts.assertLessThanOrEqual(rB.getStartTime(), afterStartB, "getStartTime() > afterStart");
    Asserts.assertGreaterThanOrEqual(rB.getStopTime(), beforeStopB, "getStopTime() < beforeStop");
    Asserts.assertLessThanOrEqual(rB.getStopTime(), afterStopB, "getStopTime() > afterStop");
}
 
Example 20
Source File: TestTimeMultiple.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Recording rA = new Recording();
    Asserts.assertNull(rA.getStartTime(), "getStartTime() not null before start");
    Asserts.assertNull(rA.getStopTime(), "getStopTime() not null before start");

    final Instant beforeStartA = Instant.now();
    rA.start();
    final Instant afterStartA = Instant.now();

    Recording rB = new Recording();
    Asserts.assertNull(rB.getStartTime(), "getStartTime() not null before start");
    Asserts.assertNull(rB.getStopTime(), "getStopTime() not null before start");

    final Instant beforeStartB = Instant.now();
    rB.start();
    final Instant afterStartB = Instant.now();

    final Instant beforeStopB = Instant.now();
    rB.stop();
    final Instant afterStopB = Instant.now();

    final Instant beforeStopA = Instant.now();
    rA.stop();
    final Instant afterStopA = Instant.now();

    rA.close();
    rB.close();

    Asserts.assertNotNull(rA.getStartTime(), "getStartTime() null after start");
    Asserts.assertNotNull(rA.getStopTime(), "getStopTime() null after stop");
    Asserts.assertGreaterThanOrEqual(rA.getStartTime(), beforeStartA, "getStartTime() < beforeStart");
    Asserts.assertLessThanOrEqual(rA.getStartTime(), afterStartA, "getStartTime() > afterStart");
    Asserts.assertGreaterThanOrEqual(rA.getStopTime(), beforeStopA, "getStopTime() < beforeStop");
    Asserts.assertLessThanOrEqual(rA.getStopTime(), afterStopA, "getStopTime() > afterStop");

    Asserts.assertNotNull(rB.getStartTime(), "getStartTime() null after start");
    Asserts.assertNotNull(rB.getStopTime(), "getStopTime() null after stop");
    Asserts.assertGreaterThanOrEqual(rB.getStartTime(), beforeStartB, "getStartTime() < beforeStart");
    Asserts.assertLessThanOrEqual(rB.getStartTime(), afterStartB, "getStartTime() > afterStart");
    Asserts.assertGreaterThanOrEqual(rB.getStopTime(), beforeStopB, "getStopTime() < beforeStop");
    Asserts.assertLessThanOrEqual(rB.getStopTime(), afterStopB, "getStopTime() > afterStop");
}