Skip to content

Commit

Permalink
8331153: JFR: Improve logging of jdk/jfr/api/consumer/filestream/Test…
Browse files Browse the repository at this point in the history
…Ordered.java

Backport-of: f3bb3e21704dd47c6c5d5753ca5882520a538c06
  • Loading branch information
SendaoYan authored and TheRealMDoerr committed Aug 16, 2024
1 parent a3cd6d6 commit d85b7c1
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions test/jdk/jdk/jfr/api/consumer/filestream/TestOrdered.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,46 +88,60 @@ public static void main(String... args) throws Exception {

private static void testSetOrderedTrue(Path p) throws Exception {
for (boolean reuse : BOOLEAN_STATES) {
System.out.println();
System.out.println("Testing: testSetOrderedTrue reuse = " + reuse);
AtomicReference<Instant> timestamp = new AtomicReference<>(Instant.MIN);
AtomicBoolean unordered = new AtomicBoolean(false);
try (EventStream es = EventStream.openFile(p)) {
es.setReuse(reuse);
es.setOrdered(true);
es.onEvent(e -> {
Instant endTime = e.getEndTime();
printTimestamp(endTime);
if (endTime.isBefore(timestamp.get())) {
throw new Error("Events are not ordered! Reuse = " + reuse);
unordered.set(true);
}
timestamp.set(endTime);
});
es.start();
}
if (unordered.get()) {
throw new Exception("Events are not ordered! Reuse = " + reuse);
}
}
}

private static void testSetOrderedFalse(Path p) throws Exception {
for (boolean reuse : BOOLEAN_STATES) {
System.out.println();
System.out.println("Testing: testSetOrderedFalse reuse = " + reuse);
AtomicReference<Instant> timestamp = new AtomicReference<>(Instant.MIN);
AtomicBoolean unoreded = new AtomicBoolean(false);
AtomicBoolean unordered = new AtomicBoolean(false);
try (EventStream es = EventStream.openFile(p)) {
es.setReuse(reuse);
es.setOrdered(false);
es.onEvent(e -> {
Instant endTime = e.getEndTime();
System.out.println("testSetOrderedFalse: endTime: " + endTime);
printTimestamp(endTime);
if (endTime.isBefore(timestamp.get())) {
unoreded.set(true);
es.close();
unordered.set(true);
}
timestamp.set(endTime);
});
es.start();
if (!unoreded.get()) {
if (!unordered.get()) {
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 {
CyclicBarrier barrier = new CyclicBarrier(THREAD_COUNT + 1);

Expand Down

1 comment on commit d85b7c1

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.