8331153: JFR: Improve logging of jdk/jfr/api/consumer/filestream/TestOrdered.java

Reviewed-by: mgronlun
This commit is contained in:
Erik Gahlin 2024-04-26 19:20:27 +00:00
parent 07facd0420
commit f3bb3e2170

View File

@ -88,46 +88,60 @@ public class TestOrdered {
private static void testSetOrderedTrue(Path p) throws Exception { private static void testSetOrderedTrue(Path p) throws Exception {
for (boolean reuse : BOOLEAN_STATES) { for (boolean reuse : BOOLEAN_STATES) {
System.out.println();
System.out.println("Testing: testSetOrderedTrue reuse = " + reuse);
AtomicReference<Instant> timestamp = new AtomicReference<>(Instant.MIN); AtomicReference<Instant> timestamp = new AtomicReference<>(Instant.MIN);
AtomicBoolean unordered = new AtomicBoolean(false);
try (EventStream es = EventStream.openFile(p)) { try (EventStream es = EventStream.openFile(p)) {
es.setReuse(reuse); es.setReuse(reuse);
es.setOrdered(true); es.setOrdered(true);
es.onEvent(e -> { es.onEvent(e -> {
Instant endTime = e.getEndTime(); Instant endTime = e.getEndTime();
printTimestamp(endTime);
if (endTime.isBefore(timestamp.get())) { if (endTime.isBefore(timestamp.get())) {
throw new Error("Events are not ordered! Reuse = " + reuse); unordered.set(true);
} }
timestamp.set(endTime); timestamp.set(endTime);
}); });
es.start(); es.start();
} }
if (unordered.get()) {
throw new Exception("Events are not ordered! Reuse = " + reuse);
}
} }
} }
private static void testSetOrderedFalse(Path p) throws Exception { private static void testSetOrderedFalse(Path p) throws Exception {
for (boolean reuse : BOOLEAN_STATES) { for (boolean reuse : BOOLEAN_STATES) {
System.out.println();
System.out.println("Testing: testSetOrderedFalse reuse = " + reuse);
AtomicReference<Instant> timestamp = new AtomicReference<>(Instant.MIN); AtomicReference<Instant> timestamp = new AtomicReference<>(Instant.MIN);
AtomicBoolean unoreded = new AtomicBoolean(false); AtomicBoolean unordered = new AtomicBoolean(false);
try (EventStream es = EventStream.openFile(p)) { try (EventStream es = EventStream.openFile(p)) {
es.setReuse(reuse); es.setReuse(reuse);
es.setOrdered(false); es.setOrdered(false);
es.onEvent(e -> { es.onEvent(e -> {
Instant endTime = e.getEndTime(); Instant endTime = e.getEndTime();
System.out.println("testSetOrderedFalse: endTime: " + endTime); printTimestamp(endTime);
if (endTime.isBefore(timestamp.get())) { if (endTime.isBefore(timestamp.get())) {
unoreded.set(true); unordered.set(true);
es.close();
} }
timestamp.set(endTime); timestamp.set(endTime);
}); });
es.start(); es.start();
if (!unoreded.get()) { if (!unordered.get()) {
throw new Exception("Expected at least some events to be out of order! Reuse = " + reuse); throw new Exception("Expected at least some events to be out of order! Reuse = " + reuse);
} }
} }
} }
} }
private static void printTimestamp(Instant timestamp) {
long seconds = timestamp.getEpochSecond();
long nanos = timestamp.getNano();
System.out.println(timestamp + " seconds = " + seconds + " nanos = " + nanos);
}
private static Path makeUnorderedRecording() throws Exception { private static Path makeUnorderedRecording() throws Exception {
CyclicBarrier barrier = new CyclicBarrier(THREAD_COUNT + 1); CyclicBarrier barrier = new CyclicBarrier(THREAD_COUNT + 1);