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

The following examples show how to use jdk.test.lib.Asserts#assertLessThanOrEqual() . 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: ObjectCountEventVerifier.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void verify(List<RecordedEvent> objectCountEvents) throws Exception {
    Asserts.assertFalse(objectCountEvents.isEmpty(), "Expected at least one object count event");
    // Object count events should be sent only for those classes which instances occupy over 0.5%
    // of the heap. Therefore there can't be more than 200 events
    Asserts.assertLessThanOrEqual(objectCountEvents.size(), 200, "Expected at most 200 object count events");

    HashMap<String, Long> numInstancesOfClass = new HashMap<String, Long>();
    HashMap<String, Long> sizeOfInstances = new HashMap<String, Long>();

    for (RecordedEvent event : objectCountEvents) {
        String className = Events.assertField(event, "objectClass.name").notEmpty().getValue();
        long count = Events.assertField(event, "count").atLeast(0L).getValue();
        long totalSize = Events.assertField(event, "totalSize").atLeast(1L).getValue();
        System.out.println(className);
        numInstancesOfClass.put(className, count);
        sizeOfInstances.put(className, totalSize);
    }
    System.out.println(numInstancesOfClass);
    final String fooArrayName = "[Ljdk/jfr/event/gc/objectcount/Foo;";
    Asserts.assertTrue(numInstancesOfClass.containsKey(fooArrayName), "Expected an event for the Foo array");
    Asserts.assertEquals(sizeOfInstances.get(fooArrayName), expectedFooArraySize(Constants.oneMB), "Wrong size of the Foo array");
}
 
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: TestRandomAccessFileThread.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static void verifyReadWriteTimes(List<RecordedEvent> readEvents, List<RecordedEvent> writeEvents) {
    List<RecordedEvent> events = new ArrayList<>();
    events.addAll(readEvents);
    events.addAll(writeEvents);
    events.sort(new EventComparator());

    int countRead = 0;
    int countWrite = 0;
    for (RecordedEvent event : events) {
        if (Events.isEventType(event, IOEvent.EVENT_FILE_READ)) {
            ++countRead;
        } else {
            ++countWrite;
        }
        // We can not read from the file before it has been written.
        // This check verifies that times of different threads are correct.
        // Since the read and write are from different threads, it is possible that the read
        // is committed before the same write.
        // But read operation may only be 1 step ahead of the write operation.
        Asserts.assertLessThanOrEqual(countRead, countWrite + 1, "read must be after write");
    }
}
 
Example 4
Source File: TestSmallHeap.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void verifySmallHeapSize(String gc, long expectedMaxHeap) throws Exception {
    long minMaxHeap = 4 * 1024 * 1024;
    LinkedList<String> vmOptions = new LinkedList<>();
    vmOptions.add(gc);
    vmOptions.add("-Xmx" + minMaxHeap);
    vmOptions.add("-XX:+PrintFlagsFinal");
    vmOptions.add(VerifyHeapSize.class.getName());

    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(vmOptions.toArray(new String[0]));
    OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());
    analyzer.shouldHaveExitValue(0);

    expectedMaxHeap = Math.max(expectedMaxHeap, minMaxHeap);
    long maxHeapSize = Long.parseLong(analyzer.firstMatch("MaxHeapSize.+=\\s+(\\d+)",1));
    long actualHeapSize = Long.parseLong(analyzer.firstMatch(VerifyHeapSize.actualMsg + "(\\d+)",1));
    Asserts.assertEQ(maxHeapSize, expectedMaxHeap);
    Asserts.assertLessThanOrEqual(actualHeapSize, maxHeapSize);
}
 
Example 5
Source File: TestRandomAccessFileThread.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void verifyReadWriteTimes(List<RecordedEvent> readEvents, List<RecordedEvent> writeEvents) {
    List<RecordedEvent> events = new ArrayList<>();
    events.addAll(readEvents);
    events.addAll(writeEvents);
    events.sort(new EventComparator());

    int countRead = 0;
    int countWrite = 0;
    for (RecordedEvent event : events) {
        if (Events.isEventType(event, IOEvent.EVENT_FILE_READ)) {
            ++countRead;
        } else {
            ++countWrite;
        }
        // We can not read from the file before it has been written.
        // This check verifies that times of different threads are correct.
        // Since the read and write are from different threads, it is possible that the read
        // is committed before the same write.
        // But read operation may only be 1 step ahead of the write operation.
        Asserts.assertLessThanOrEqual(countRead, countWrite + 1, "read must be after write");
    }
}
 
Example 6
Source File: HeapSummaryEventAllGcs.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static void checkPSYoungStartEnd(RecordedEvent event) {
    long oldEnd = Events.assertField(event, "oldSpace.reservedEnd").getValue();
    long youngStart = Events.assertField(event, "youngSpace.start").getValue();
    long youngEnd = Events.assertField(event, "youngSpace.committedEnd").getValue();
    long edenStart = Events.assertField(event, "edenSpace.start").getValue();
    long edenEnd = Events.assertField(event, "edenSpace.end").getValue();
    long fromStart = Events.assertField(event, "fromSpace.start").getValue();
    long fromEnd = Events.assertField(event, "fromSpace.end").getValue();
    long toStart = Events.assertField(event, "toSpace.start").getValue();
    long toEnd = Events.assertField(event, "toSpace.end").getValue();
    Asserts.assertEquals(oldEnd, youngStart, "Young should start where old ends");
    Asserts.assertEquals(youngStart, edenStart, "Eden should be placed first in young");
    if (fromStart < toStart) {
        // [eden][from][to]
        Asserts.assertGreaterThanOrEqual(fromStart, edenEnd, "From should start after eden");
        Asserts.assertLessThanOrEqual(fromEnd, toStart, "To should start after From");
        Asserts.assertLessThanOrEqual(toEnd, youngEnd, "To should start after From");
    } else {
        // [eden][to][from]
        Asserts.assertGreaterThanOrEqual(toStart, edenEnd, "From should start after eden");
        Asserts.assertLessThanOrEqual(toEnd, fromStart, "To should start after From");
        Asserts.assertLessThanOrEqual(fromEnd, youngEnd, "To should start after From");
    }
}
 
Example 7
Source File: TestEvacuationFailedEvent.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 {
    String[] vmFlags = {"-XX:+UnlockExperimentalVMOptions", "-XX:-UseFastUnorderedTimeStamps",
        "-Xmx64m", "-Xmn60m", "-XX:-UseDynamicNumberOfGCThreads", "-XX:ParallelGCThreads=3",
        "-XX:MaxTenuringThreshold=0", "-verbose:gc", "-XX:+UseG1GC"};

    if (!ExecuteOOMApp.execute(EVENT_SETTINGS_FILE, JFR_FILE, vmFlags, BYTES_TO_ALLOCATE)) {
        System.out.println("OOM happened in the other thread(not test thread). Skip test.");
        // Skip test, process terminates due to the OOME error in the different thread
        return;
    }

    List<RecordedEvent> events = RecordingFile.readAllEvents(Paths.get(JFR_FILE));

    Events.hasEvents(events);
    for (RecordedEvent event : events) {
        long objectCount = Events.assertField(event, "evacuationFailed.objectCount").atLeast(1L).getValue();
        long smallestSize = Events.assertField(event, "evacuationFailed.smallestSize").atLeast(1L).getValue();
        long firstSize = Events.assertField(event, "evacuationFailed.firstSize").atLeast(smallestSize).getValue();
        long totalSize = Events.assertField(event, "evacuationFailed.totalSize").atLeast(firstSize).getValue();
        Asserts.assertLessThanOrEqual(smallestSize * objectCount, totalSize, "smallestSize * objectCount <= totalSize");
    }
}
 
Example 8
Source File: TestDuration.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
    final Duration duration = Duration.ofSeconds(1);
    Recording r = new Recording();
    r.setDuration(duration);
    Asserts.assertEquals(duration, r.getDuration(), "Wrong get/set duration");

    r.start();
    Instant afterStart = Instant.now();
    CommonHelper.waitForRecordingState(r, RecordingState.STOPPED);

    Instant afterStop = Instant.now();
    Asserts.assertLessThanOrEqual(r.getStopTime(), afterStop, "getStopTime() > afterStop");
    long durationMillis = Duration.between(afterStart, r.getStopTime()).toMillis();

    // Performance of test servers varies too much to make a strict check of actual duration.
    // We only check that recording stops before timeout of 20 seconds.
    System.out.printf("Recording stopped after %d ms, expected above 1000 ms%n", durationMillis);
    r.close();
}
 
Example 9
Source File: HeapSummaryEventAllGcs.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void checkPSYoungStartEnd(RecordedEvent event) {
    long oldEnd = Events.assertField(event, "oldSpace.reservedEnd").getValue();
    long youngStart = Events.assertField(event, "youngSpace.start").getValue();
    long youngEnd = Events.assertField(event, "youngSpace.committedEnd").getValue();
    long edenStart = Events.assertField(event, "edenSpace.start").getValue();
    long edenEnd = Events.assertField(event, "edenSpace.end").getValue();
    long fromStart = Events.assertField(event, "fromSpace.start").getValue();
    long fromEnd = Events.assertField(event, "fromSpace.end").getValue();
    long toStart = Events.assertField(event, "toSpace.start").getValue();
    long toEnd = Events.assertField(event, "toSpace.end").getValue();
    Asserts.assertEquals(oldEnd, youngStart, "Young should start where old ends");
    Asserts.assertEquals(youngStart, edenStart, "Eden should be placed first in young");
    if (fromStart < toStart) {
        // [eden][from][to]
        Asserts.assertGreaterThanOrEqual(fromStart, edenEnd, "From should start after eden");
        Asserts.assertLessThanOrEqual(fromEnd, toStart, "To should start after From");
        Asserts.assertLessThanOrEqual(toEnd, youngEnd, "To should start after From");
    } else {
        // [eden][to][from]
        Asserts.assertGreaterThanOrEqual(toStart, edenEnd, "From should start after eden");
        Asserts.assertLessThanOrEqual(toEnd, fromStart, "To should start after From");
        Asserts.assertLessThanOrEqual(fromEnd, youngEnd, "To should start after From");
    }
}
 
Example 10
Source File: TestEvacuationFailedEvent.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 {
    String[] vmFlags = {"-XX:+UnlockExperimentalVMOptions", "-XX:-UseFastUnorderedTimeStamps",
        "-Xmx64m", "-Xmn60m", "-XX:-UseDynamicNumberOfGCThreads", "-XX:ParallelGCThreads=3",
        "-XX:MaxTenuringThreshold=0", "-verbose:gc", "-XX:+UseG1GC"};

    if (!ExecuteOOMApp.execute(EVENT_SETTINGS_FILE, JFR_FILE, vmFlags, BYTES_TO_ALLOCATE)) {
        System.out.println("OOM happened in the other thread(not test thread). Skip test.");
        // Skip test, process terminates due to the OOME error in the different thread
        return;
    }

    List<RecordedEvent> events = RecordingFile.readAllEvents(Paths.get(JFR_FILE));

    Events.hasEvents(events);
    for (RecordedEvent event : events) {
        long objectCount = Events.assertField(event, "evacuationFailed.objectCount").atLeast(1L).getValue();
        long smallestSize = Events.assertField(event, "evacuationFailed.smallestSize").atLeast(1L).getValue();
        long firstSize = Events.assertField(event, "evacuationFailed.firstSize").atLeast(smallestSize).getValue();
        long totalSize = Events.assertField(event, "evacuationFailed.totalSize").atLeast(firstSize).getValue();
        Asserts.assertLessThanOrEqual(smallestSize * objectCount, totalSize, "smallestSize * objectCount <= totalSize");
    }
}
 
Example 11
Source File: TestTimeDuration.java    From TencentKona-8 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 12
Source File: HeapSummaryEventAllGcs.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void checkHeapEventContent(RecordedEvent event) {
    checkVirtualSpace(event, "heapSpace");
    long heapUsed = Events.assertField(event, "heapUsed").atLeast(0L).getValue();
    long start = Events.assertField(event, "heapSpace.start").atLeast(0L).getValue();
    long committedEnd = Events.assertField(event, "heapSpace.committedEnd").above(start).getValue();
    Asserts.assertLessThanOrEqual(heapUsed, committedEnd- start, "used can not exceed size");
}
 
Example 13
Source File: GCEventAll.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void verifyCollectionCount(String collector, long eventCounts, long beanCounts) {
    if (GCHelper.gcConcurrentMarkSweep.equals(collector) || GCHelper.gcG1Old.equals(oldCollector)) {
        // ConcurrentMarkSweep mixes old and new collections. Not same values as in MXBean.
        // MXBean does not report old collections for G1Old, so we have nothing to compare with.
        return;
    }
    // JFR events and GarbageCollectorMXBean events are not updated at the same time.
    // This means that number of collections may diff.
    // We allow a diff of +- 1 collection count.
    long minCount = Math.max(0, beanCounts - 1);
    long maxCount = beanCounts + 1;
    Asserts.assertGreaterThanOrEqual(eventCounts, minCount, "Too few event counts for collector " + collector);
    Asserts.assertLessThanOrEqual(eventCounts, maxCount, "Too many event counts for collector " + collector);
}
 
Example 14
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 15
Source File: TestSnapshot.java    From TencentKona-8 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 16
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 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: TestTimeScheduleStart.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void testScheduledRecordingIsRunning() throws Exception {
    Recording r = new Recording();
    r.scheduleStart(Duration.ofSeconds(2));
    Asserts.assertNotNull(r.getStartTime(), "start time is null after scheduleStart()");
    CommonHelper.waitForRecordingState(r, RecordingState.RUNNING);
    Asserts.assertLessThanOrEqual(r.getStartTime(), Instant.now(), "start time should not exceed current time");
    r.stop();
    r.close();
}
 
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");
}