Skip to content

Commit

Permalink
8331653: JFR: Improve logging for jdk/jfr/api/consumer/recordingstrea…
Browse files Browse the repository at this point in the history
…m;TestStop.java

Reviewed-by: mgronlun
  • Loading branch information
egahlin committed May 6, 2024
1 parent 9b0bb03 commit e8a2d56
Showing 1 changed file with 33 additions and 13 deletions.
46 changes: 33 additions & 13 deletions test/jdk/jdk/jfr/api/consumer/recordingstream/TestStop.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
package jdk.jfr.api.consumer.recordingstream;

import java.nio.file.Path;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;
import java.util.Collections;

import jdk.jfr.Event;
import jdk.jfr.consumer.RecordedEvent;
Expand Down Expand Up @@ -106,10 +107,10 @@ private static void testStopFromOtherThread() throws Exception {
}

private static void testNestedStop() throws Exception {
AtomicLong outerCount = new AtomicLong();
AtomicLong innerCount = new AtomicLong();
List<String> outerStream = Collections.synchronizedList(new ArrayList<>());
List<String> innerStream = Collections.synchronizedList(new ArrayList<>());
try (RecordingStream outer = new RecordingStream()) {
outer.onEvent(e -> outerCount.incrementAndGet());
outer.onEvent(e -> outerStream.add(eventToText(e)));
outer.setMaxSize(100_000_000);
outer.startAsync();

Expand All @@ -119,7 +120,7 @@ private static void testNestedStop() throws Exception {

try (RecordingStream inner = new RecordingStream()) {
inner.setMaxSize(100_000_000);
inner.onEvent(e -> innerCount.incrementAndGet());
inner.onEvent(e -> innerStream.add(eventToText(e)));
inner.startAsync();

MarkEvent b = new MarkEvent();
Expand All @@ -138,30 +139,49 @@ private static void testNestedStop() throws Exception {
Path fileInner = Path.of("inner.jfr");
inner.dump(fileInner);
outer.dump(fileOuter);
System.out.println("RecordingStream outer:");
System.out.println("Outer dump:");
var dumpOuter = RecordingFile.readAllEvents(fileOuter);
System.out.println(dumpOuter);
System.out.println("RecordingStream inner:");
for (RecordedEvent e : dumpOuter) {
System.out.println(eventToText(e));
}
System.out.println("Inner dump:");
var dumpInner = RecordingFile.readAllEvents(fileInner);
System.out.println(dumpInner);
System.out.println("Outer count: " + outerCount);
System.out.println("Inner count: " + innerCount);
for (RecordedEvent e : dumpInner) {
System.out.println(eventToText(e));
}
System.out.println();
System.out.println("Outer stream:");
for (String s : outerStream) {
System.out.println(s);
}
System.out.println("Inner stream:");
for (String s : innerStream) {
System.out.println(s);
}
if (dumpOuter.size() != 3) {
throw new AssertionError("Expected outer dump to have 3 events");
}
if (outerCount.get() != 3) {
if (outerStream.size() != 3) {
throw new AssertionError("Expected outer stream to have 3 events");
}
if (dumpInner.size() != 1) {
throw new AssertionError("Expected inner dump to have 1 event");
}
if (innerCount.get() != 1) {
if (innerStream.size() != 1) {
throw new AssertionError("Expected inner stream to have 1 event");
}
}
}
}

private static String eventToText(RecordedEvent event) {
Instant timestamp = event.getEndTime();
long s = timestamp.getEpochSecond();
int n = timestamp.getNano();
String id = event.getString("id");
return id + ": n=" + n + " s=" + s + " t=" + timestamp;
}

static void testStopClosed() {
try (RecordingStream rs = new RecordingStream()) {
rs.close();
Expand Down

1 comment on commit e8a2d56

@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.