Java Code Examples for jdk.testlibrary.Asserts#assertGreaterThanOrEqual()
The following examples show how to use
jdk.testlibrary.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: GCEventAll.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
private void verifyPhaseEvents(List<GCHelper.GcBatch> batches) { for (GCHelper.GcBatch batch : batches) { for(RecordedEvent event : batch.getEvents()) { if (event.getEventType().getName().contains(GCHelper.pauseLevelEvent)) { Instant batchStartTime = batch.getEndEvent().getStartTime(); Asserts.assertGreaterThanOrEqual( event.getStartTime(), batchStartTime, "Phase startTime >= batch startTime. Event:" + event); // Duration for event "vm/gc/phases/pause" must be >= 1. Other phase event durations must be >= 0. Duration minDuration = Duration.ofNanos(GCHelper.event_phases_pause.equals(event.getEventType().getName()) ? 1 : 0); Duration duration = event.getDuration(); Asserts.assertGreaterThanOrEqual(duration, minDuration, "Wrong duration. Event:" + event); } } } }
Example 2
Source File: TestRandomAccessFileThread.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
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 3
Source File: HeapSummaryEventAllGcs.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
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 4
Source File: GCEventAll.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
private void verifyPhaseEvents(List<GCHelper.GcBatch> batches) { for (GCHelper.GcBatch batch : batches) { for(RecordedEvent event : batch.getEvents()) { if (event.getEventType().getName().contains(GCHelper.pauseLevelEvent)) { Instant batchStartTime = batch.getEndEvent().getStartTime(); Asserts.assertGreaterThanOrEqual( event.getStartTime(), batchStartTime, "Phase startTime >= batch startTime. Event:" + event); // Duration for event "vm/gc/phases/pause" must be >= 1. Other phase event durations must be >= 0. Duration minDuration = Duration.ofNanos(GCHelper.event_phases_pause.equals(event.getEventType().getName()) ? 1 : 0); Duration duration = event.getDuration(); Asserts.assertGreaterThanOrEqual(duration, minDuration, "Wrong duration. Event:" + event); } } } }
Example 5
Source File: GCEventAll.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
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 6
Source File: HeapSummaryEventAllGcs.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
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 7
Source File: TestChunkPeriod.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
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 8
Source File: TestChunkPeriod.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
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 9
Source File: TestSnapshot.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
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 10
Source File: TestSnapshot.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
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 11
Source File: TestStartDelay.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
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 12
Source File: RecurseThread.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@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 13
Source File: GCEventAll.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
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: TestExceptionEvents.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
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 15
Source File: JcmdAsserts.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
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 16
Source File: TestThreadCpuTimeEvent.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
static void testCompareWithMXBean() throws Throwable { Recording recording = new Recording(); recording.enable(EventNames.ThreadCPULoad).withPeriod(Duration.ofMillis(eventPeriodMillis)); recording.start(); Duration testRunTime = Duration.ofMillis(eventPeriodMillis * cpuConsumerRunFactor); CyclicBarrier barrier = new CyclicBarrier(2); CpuConsumingThread thread = new CpuConsumingThread(testRunTime, barrier); // Run a single pass thread.start(); barrier.await(); barrier.await(); recording.stop(); List<RecordedEvent> beforeEvents = Events.fromRecording(recording); 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 17
Source File: TestEvacuationInfoEvent.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Throwable { final long g1HeapRegionSize = 1024 * 1024; Recording recording = new Recording(); recording.enable(EVENT_INFO_NAME).withThreshold(Duration.ofMillis(0)); recording.enable(EVENT_FAILED_NAME).withThreshold(Duration.ofMillis(0)); recording.start(); allocate(); recording.stop(); List<RecordedEvent> events = Events.fromRecording(recording); Asserts.assertFalse(events.isEmpty(), "No events found"); for (RecordedEvent event : events) { if (!Events.isEventType(event, EVENT_INFO_NAME)) { continue; } System.out.println("Event: " + event); int setRegions = Events.assertField(event, "cSetRegions").atLeast(0).getValue(); long setUsedAfter = Events.assertField(event, "cSetUsedAfter").atLeast(0L).getValue(); long setUsedBefore = Events.assertField(event, "cSetUsedBefore").atLeast(setUsedAfter).getValue(); int allocationRegions = Events.assertField(event, "allocationRegions").atLeast(0).getValue(); long allocRegionsUsedBefore = Events.assertField(event, "allocRegionsUsedBefore").atLeast(0L).getValue(); long allocRegionsUsedAfter = Events.assertField(event, "allocRegionsUsedAfter").atLeast(0L).getValue(); long bytesCopied = Events.assertField(event, "bytesCopied").atLeast(0L).getValue(); int regionsFreed = Events.assertField(event, "regionsFreed").atLeast(0).getValue(); Asserts.assertEquals(allocRegionsUsedBefore + bytesCopied, allocRegionsUsedAfter, "allocRegionsUsedBefore + bytesCopied = allocRegionsUsedAfter"); Asserts.assertGreaterThanOrEqual(setRegions, regionsFreed, "setRegions >= regionsFreed"); Asserts.assertGreaterThanOrEqual(g1HeapRegionSize * allocationRegions, allocRegionsUsedAfter, "G1HeapRegionSize * allocationRegions >= allocationRegionsUsedAfter"); Asserts.assertGreaterThanOrEqual(g1HeapRegionSize * setRegions, setUsedAfter, "G1HeapRegionSize * setRegions >= setUsedAfter"); Asserts.assertGreaterThanOrEqual(g1HeapRegionSize * setRegions, setUsedBefore, "G1HeapRegionSize * setRegions >= setUsedBefore"); Asserts.assertGreaterThanOrEqual(g1HeapRegionSize, allocRegionsUsedBefore, "G1HeapRegionSize >= allocRegionsUsedBefore"); int gcId = Events.assertField(event, "gcId").getValue(); boolean isEvacuationFailed = containsEvacuationFailed(events, gcId); if (isEvacuationFailed) { Asserts.assertGreaterThan(setUsedAfter, 0L, "EvacuationFailure -> setUsedAfter > 0"); Asserts.assertGreaterThan(setRegions, regionsFreed, "EvacuationFailure -> setRegions > regionsFreed"); } else { Asserts.assertEquals(setUsedAfter, 0L, "No EvacuationFailure -> setUsedAfter = 0"); Asserts.assertEquals(setRegions, regionsFreed, "No EvacuationFailure -> setRegions = regionsFreed"); } } }
Example 18
Source File: JcmdAsserts.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
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: TestReEnableName.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
private static void testRecordingWithEnabledEvent(String eventname, boolean enabled) throws Exception { System.out.println("Testing enabled=" + enabled + " for " + eventname); final Path pathDisabled = Paths.get(".", "disabled.txt").toAbsolutePath(); final Path pathEnabled = Paths.get(".", "enabled.txt").toAbsolutePath(); Recording r = new Recording(); if (enabled) { r.enable(eventname).withoutThreshold().withoutStackTrace(); } else { r.disable(eventname).withoutThreshold().withoutStackTrace(); } r.start(); // We should only get events for pathEnabled, not for pathDisabled. int countExpectedEvents = 0; for (int i = 0; i < 10; ++i) { if (enabled) { Files.write(pathEnabled, "E".getBytes()); ++countExpectedEvents; r.disable(eventname); } else { Files.write(pathDisabled, "D".getBytes()); r.enable(eventname); } enabled = !enabled; } r.stop(); int countFoundEvents = 0; for (RecordedEvent event : Events.fromRecording(r)) { System.out.printf("Event %s%n", event); Asserts.assertEquals(eventname, event.getEventType().getName(), "Wrong event type"); String path = Events.assertField(event, "path").getValue(); System.out.println(path); if (pathEnabled.toString().equals(path)) { ++countFoundEvents; } } Asserts.assertGreaterThanOrEqual(countFoundEvents, countExpectedEvents, "Too few events found"); r.close(); }
Example 20
Source File: TestTimeMultiple.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
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"); }