Skip to content

Commit f75f78a

Browse files
committedFeb 18, 2020
8239265: JFR: Test cleanup of jdk.jfr.api.consumer package
Reviewed-by: mgronlun
1 parent 6f6b4c0 commit f75f78a

18 files changed

+400
-430
lines changed
 

‎test/jdk/jdk/jfr/api/consumer/TestFieldAccess.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
public class TestFieldAccess {
4646

4747
private static class MyEvent extends Event {
48+
byte byteField = 42;
49+
char charField = 'X';
4850
String stringField = "Hello";
4951
int intField = 4711;
5052
long longField = 4712L;
@@ -72,6 +74,12 @@ public static void main(String[] args) throws Throwable {
7274
}
7375

7476
private static void testGetField(RecordedEvent event, MyEvent myEvent) {
77+
char charField = event.getValue("charField");
78+
Asserts.assertEquals(charField, myEvent.charField);
79+
80+
byte byteField = event.getValue("byteField");
81+
Asserts.assertEquals(byteField, myEvent.byteField);
82+
7583
String stringField = event.getValue("stringField");
7684
Asserts.assertEquals(stringField, myEvent.stringField);
7785

@@ -103,7 +111,6 @@ private static void testGetField(RecordedEvent event, MyEvent myEvent) {
103111
String className = event.getValue("classField.name");
104112
Asserts.assertEquals(classField.getName(), className.replace("/", "."));
105113

106-
107114
try {
108115
event.getValue("doesnotexist");
109116
} catch (IllegalArgumentException iae) {
@@ -125,6 +132,8 @@ private static void testGetField(RecordedEvent event, MyEvent myEvent) {
125132

126133
private static void testHasField(RecordedEvent event) {
127134
System.out.println(event);
135+
Asserts.assertTrue(event.hasField("charField"));
136+
Asserts.assertTrue(event.hasField("byteField"));
128137
Asserts.assertTrue(event.hasField("stringField"));
129138
Asserts.assertTrue(event.hasField("intField"));
130139
Asserts.assertTrue(event.hasField("longField"));

‎test/jdk/jdk/jfr/api/consumer/TestGetStackTrace.java

+13-15
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import static jdk.test.lib.Asserts.assertTrue;
3232

3333
import java.util.List;
34-
import java.util.function.Consumer;
3534

3635
import jdk.jfr.Recording;
3736
import jdk.jfr.consumer.RecordedEvent;
@@ -53,27 +52,26 @@
5352
public class TestGetStackTrace {
5453

5554
public static void main(String[] args) throws Throwable {
56-
testStackTrace(r -> r.enable(SimpleEvent.class), TestGetStackTrace::assertNoStackTrace);
57-
testStackTrace(r -> r.enable(SimpleEvent.class).withoutStackTrace(), TestGetStackTrace::assertStackTrace);
55+
testWithoutStackTrace(recordEvent("stackTrace", "false"));
56+
testWithStackTrace(recordEvent("stackTrace", "true"));
5857
}
5958

60-
private static void testStackTrace(Consumer<Recording> recordingConfigurer, Consumer<RecordedEvent> asserter) throws Throwable {
61-
Recording r = new Recording();
62-
recordingConfigurer.accept(r);
63-
r.start();
64-
SimpleEvent event = new SimpleEvent();
65-
event.commit();
66-
r.stop();
67-
List<RecordedEvent> events = Events.fromRecording(r);
68-
r.close();
69-
Events.hasEvents(events);
59+
private static RecordedEvent recordEvent(String key, String value) throws Throwable {
60+
try (Recording r = new Recording()) {
61+
r.enable(SimpleEvent.class).with(key, value);
62+
r.start();
63+
SimpleEvent event = new SimpleEvent();
64+
event.commit();
65+
r.stop();
66+
return Events.fromRecording(r).get(0);
67+
}
7068
}
7169

72-
private static void assertNoStackTrace(RecordedEvent re) {
70+
private static void testWithoutStackTrace(RecordedEvent re) {
7371
assertNull(re.getStackTrace());
7472
}
7573

76-
private static void assertStackTrace(RecordedEvent re) {
74+
private static void testWithStackTrace(RecordedEvent re) {
7775
assertNotNull(re.getStackTrace());
7876
RecordedStackTrace strace = re.getStackTrace();
7977
assertEquals(strace.isTruncated(), false);

‎test/jdk/jdk/jfr/api/consumer/TestHiddenMethod.java

+32-32
Original file line numberDiff line numberDiff line change
@@ -56,42 +56,43 @@
5656
public final class TestHiddenMethod {
5757

5858
public static void main(String[] args) throws Throwable {
59-
Recording recording = new Recording();
60-
recording.enable(MyEvent.class).withThreshold(Duration.ofMillis(0));
61-
recording.start();
59+
try (Recording recording = new Recording()) {
60+
recording.enable(MyEvent.class).withThreshold(Duration.ofMillis(0));
61+
recording.start();
6262

63-
// Commit event with hidden methods
64-
ScriptEngineManager manager = new ScriptEngineManager();
65-
ScriptEngine engine = manager.getEngineByName("nashorn");
66-
engine.eval(
67-
"function emit() {"
68-
+ " print('About to emit event from Javascript');"
69-
+ " var TestEvent = Java.type(\"jdk.jfr.api.consumer.TestHiddenMethod$MyEvent\");"
70-
+ " var event = new TestEvent;"
71-
+ " event.begin();"
72-
+ " event.end();"
73-
+ " event.commit();"
74-
+ " print('Event emitted from Javascript!');"
75-
+ "}"
76-
+ "emit();");
63+
// Commit event with hidden methods
64+
ScriptEngineManager manager = new ScriptEngineManager();
65+
ScriptEngine engine = manager.getEngineByName("nashorn");
66+
engine.eval(
67+
"function emit() {"
68+
+ " print('About to emit event from Javascript');"
69+
+ " var TestEvent = Java.type(\"jdk.jfr.api.consumer.TestHiddenMethod$MyEvent\");"
70+
+ " var event = new TestEvent;"
71+
+ " event.begin();"
72+
+ " event.end();"
73+
+ " event.commit();"
74+
+ " print('Event emitted from Javascript!');"
75+
+ "}"
76+
+ "emit();");
7777

78-
// Commit event with visible method
79-
MyEvent visible = new MyEvent();
80-
visible.begin();
81-
visible.end();
82-
visible.commit();
83-
recording.stop();
78+
// Commit event with visible method
79+
MyEvent visible = new MyEvent();
80+
visible.begin();
81+
visible.end();
82+
visible.commit();
83+
recording.stop();
8484

85-
List<RecordedEvent> events = Events.fromRecording(recording);
86-
assertEquals(2, events.size(), "Expected two events");
87-
RecordedEvent hiddenEvent = events.get(0);
88-
RecordedEvent visibleEvent = events.get(1);
85+
List<RecordedEvent> events = Events.fromRecording(recording);
86+
assertEquals(2, events.size(), "Expected two events");
87+
RecordedEvent hiddenEvent = events.get(0);
88+
RecordedEvent visibleEvent = events.get(1);
8989

90-
System.out.println("hiddenEvent:" + hiddenEvent);
91-
System.out.println("visibleEvent:" + visibleEvent);
90+
System.out.println("hiddenEvent:" + hiddenEvent);
91+
System.out.println("visibleEvent:" + visibleEvent);
9292

93-
assertTrue(hasHiddenStackFrame(hiddenEvent), "No hidden frame in hidden event: " + hiddenEvent);
94-
assertFalse(hasHiddenStackFrame(visibleEvent), "Hidden frame in visible event: " + visibleEvent);
93+
assertTrue(hasHiddenStackFrame(hiddenEvent), "No hidden frame in hidden event: " + hiddenEvent);
94+
assertFalse(hasHiddenStackFrame(visibleEvent), "Hidden frame in visible event: " + visibleEvent);
95+
}
9596
}
9697

9798
private static boolean hasHiddenStackFrame(RecordedEvent event) throws Throwable {
@@ -108,5 +109,4 @@ private static boolean hasHiddenStackFrame(RecordedEvent event) throws Throwable
108109

109110
public static class MyEvent extends Event {
110111
}
111-
112112
}

‎test/jdk/jdk/jfr/api/consumer/TestMethodGetModifiers.java

+22-22
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
/**
4343
* @test
44+
* @summary Verifies that a recorded method has the correct modifier
4445
* @key jfr
4546
* @requires vm.hasJFR
4647
* @library /test/lib
@@ -49,33 +50,32 @@
4950
public final class TestMethodGetModifiers {
5051

5152
public static void main(String[] args) throws Throwable {
52-
Recording recording = new Recording();
53-
recording.start();
53+
try (Recording recording = new Recording()) {
54+
recording.start();
5455

55-
SimpleEvent ev = new SimpleEvent();
56-
ev.commit();
57-
recording.stop();
56+
SimpleEvent ev = new SimpleEvent();
57+
ev.commit();
58+
recording.stop();
5859

59-
List<RecordedEvent> recordedEvents = Events.fromRecording(recording);
60-
Events.hasEvents(recordedEvents);
61-
RecordedEvent recordedEvent = recordedEvents.get(0);
60+
List<RecordedEvent> recordedEvents = Events.fromRecording(recording);
61+
Events.hasEvents(recordedEvents);
62+
RecordedEvent recordedEvent = recordedEvents.get(0);
6263

63-
System.out.println("recorded event:" + recordedEvent);
64+
System.out.println(recordedEvent);
6465

65-
RecordedStackTrace stacktrace = recordedEvent.getStackTrace();
66-
List<RecordedFrame> frames = stacktrace.getFrames();
67-
for (RecordedFrame frame : frames) {
68-
RecordedMethod method = frame.getMethod();
69-
if (method.getName().equals("main")) {
70-
System.out.println("'main' method: " + method);
71-
int modifiers = TestMethodGetModifiers.class.getDeclaredMethod("main", (Class<?>)String[].class).getModifiers();
72-
System.out.println("modifiers: " + modifiers);
73-
Asserts.assertEquals(method.getModifiers(), modifiers, "Incorrect method modifier reported");
74-
RecordedClass type = method.getType();
75-
assertNotNull(type, "Recorded class can not be null");
66+
RecordedStackTrace stacktrace = recordedEvent.getStackTrace();
67+
List<RecordedFrame> frames = stacktrace.getFrames();
68+
for (RecordedFrame frame : frames) {
69+
RecordedMethod method = frame.getMethod();
70+
if (method.getName().equals("main")) {
71+
System.out.println("'main' method: " + method);
72+
int modifiers = TestMethodGetModifiers.class.getDeclaredMethod("main", (Class<?>)String[].class).getModifiers();
73+
System.out.println("modifiers: " + modifiers);
74+
Asserts.assertEquals(method.getModifiers(), modifiers, "Incorrect method modifier reported");
75+
RecordedClass type = method.getType();
76+
assertNotNull(type, "Recorded class can not be null");
77+
}
7678
}
77-
7879
}
7980
}
80-
8181
}

‎test/jdk/jdk/jfr/api/consumer/TestReadTwice.java

+23-24
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import jdk.test.lib.Asserts;
3737
import jdk.test.lib.Utils;
3838

39-
4039
/**
4140
* @test
4241
* @summary Reads the recorded file two times and verifies that both reads are the same
@@ -51,34 +50,34 @@ private static class MyEvent extends Event {
5150
}
5251

5352
public static void main(String[] args) throws Throwable {
54-
Recording r = new Recording();
55-
r.enable(MyEvent.class).withoutStackTrace();
56-
r.start();
53+
try (Recording r = new Recording()) {
54+
r.enable(MyEvent.class).withoutStackTrace();
55+
r.start();
5756

58-
// Commit a single event to the recording
59-
MyEvent event = new MyEvent();
60-
event.commit();
57+
// Commit a single event to the recording
58+
MyEvent event = new MyEvent();
59+
event.commit();
6160

62-
r.stop();
61+
r.stop();
6362

64-
// Dump the recording to a file
65-
Path path = Utils.createTempFile("read-twice", ".jfr");
66-
System.out.println("Dumping to " + path);
67-
r.dump(path);
68-
r.close();
63+
// Dump the recording to a file
64+
Path path = Utils.createTempFile("read-twice", ".jfr");
65+
System.out.println("Dumping to " + path);
66+
r.dump(path);
6967

70-
// Read all events from the file in one go
71-
List<RecordedEvent> events = RecordingFile.readAllEvents(path);
68+
// Read all events from the file in one go
69+
List<RecordedEvent> events = RecordingFile.readAllEvents(path);
7270

73-
// Read again the same events one by one
74-
RecordingFile rfile = new RecordingFile(path);
75-
List<RecordedEvent> events2 = new LinkedList<>();
76-
while (rfile.hasMoreEvents()) {
77-
events2.add(rfile.readEvent());
78-
}
71+
// Read again the same events one by one
72+
try (RecordingFile rfile = new RecordingFile(path)) {
73+
List<RecordedEvent> events2 = new LinkedList<>();
74+
while (rfile.hasMoreEvents()) {
75+
events2.add(rfile.readEvent());
76+
}
7977

80-
// Compare sizes
81-
Asserts.assertEquals(events.size(), events2.size());
82-
rfile.close();
78+
// Compare sizes
79+
Asserts.assertEquals(events.size(), events2.size());
80+
}
81+
}
8382
}
8483
}

‎test/jdk/jdk/jfr/api/consumer/TestRecordedClassLoader.java

+64-62
Original file line numberDiff line numberDiff line change
@@ -45,76 +45,78 @@
4545
* @run main/othervm jdk.jfr.api.consumer.TestRecordedClassLoader
4646
*/
4747
public class TestRecordedClassLoader {
48+
4849
private final static String TEST_CLASS_NAME = "jdk.jfr.api.consumer.TestRecordedClassLoader$MyTestClass";
4950
private final static String EVENT_NAME = EventNames.ClassDefine;
5051

5152
static class MyTestClass {
5253
}
5354

5455
public static void main(String[] args) throws Exception {
55-
Recording recording = new Recording();
56-
recording.enable(EVENT_NAME).withoutStackTrace();
57-
TestClassLoader cl = new TestClassLoader();
58-
recording.start();
59-
cl.loadClass(TEST_CLASS_NAME);
60-
recording.stop();
61-
62-
List<RecordedEvent> events = Events.fromRecording(recording);
63-
boolean isDefined = false;
64-
for (RecordedEvent event : events) {
65-
RecordedClass definedClass = event.getValue("definedClass");
66-
if (TEST_CLASS_NAME.equals(definedClass.getName())) {
67-
System.out.println(event);
68-
69-
// get the RecordedClassLoader from the RecordedClass, the "definedClass"
70-
RecordedClassLoader definingClassLoader = definedClass.getClassLoader();
71-
Asserts.assertNotNull(definingClassLoader, "Defining Class Loader should not be null");
72-
73-
// invoke RecordedClassLoader.getType() in order to validate the type of the RecordedClassLoader
74-
RecordedClass definingClassLoaderType = definingClassLoader.getType();
75-
Asserts.assertNotNull(definingClassLoaderType, "The defining Class Loader type should not be null");
76-
77-
// verify matching types
78-
Asserts.assertEquals(cl.getClass().getName(), definingClassLoaderType.getName(),
79-
"Expected type " + cl.getClass().getName() + ", got type " + definingClassLoaderType.getName());
80-
81-
// get a RecordedClassLoader directly from the "definingClassLoader" field as well
82-
RecordedClassLoader definingClassLoaderFromField = event.getValue("definingClassLoader");
83-
Asserts.assertNotNull(definingClassLoaderFromField,
84-
"Defining Class Loader instantatiated from field should not be null");
85-
86-
// ensure that the class loader instance used in the test actually has a name
87-
Asserts.assertNotNull(cl.getName(),
88-
"Expected a valid name for the TestClassLoader");
89-
90-
// invoke RecordedClassLoader.getName() to get the name of the class loader instance
91-
Asserts.assertEquals(cl.getName(), definingClassLoader.getName(),
92-
"Defining Class Loader should have the same name as the original class loader");
93-
Asserts.assertEquals(definingClassLoaderFromField.getName(), definingClassLoader.getName(),
94-
"Defining Class Loader representations should have the same class loader name");
95-
96-
// invoke uniqueID()
97-
Asserts.assertGreaterThan(definingClassLoader.getId(), 0L, "Invalid id assignment");
98-
99-
// second order class loader information ("check class loader of the class loader")
100-
RecordedClassLoader classLoaderOfDefClassLoader = definingClassLoaderType.getClassLoader();
101-
Asserts.assertNotNull(classLoaderOfDefClassLoader,
102-
"The class loader for the definining class loader should not be null");
103-
Asserts.assertEquals(cl.getClass().getClassLoader().getName(), classLoaderOfDefClassLoader.getName(),
104-
"Expected class loader name " + cl.getClass().getClassLoader().getName() + ", got name " + classLoaderOfDefClassLoader.getName());
105-
106-
RecordedClass classLoaderOfDefClassLoaderType = classLoaderOfDefClassLoader.getType();
107-
Asserts.assertNotNull(classLoaderOfDefClassLoaderType,
108-
"The class loader type for the defining class loader should not be null");
109-
Asserts.assertEquals(cl.getClass().getClassLoader().getClass().getName(), classLoaderOfDefClassLoaderType.getName(),
110-
"Expected type " + cl.getClass().getClassLoader().getClass().getName() + ", got type " + classLoaderOfDefClassLoaderType.getName());
111-
112-
Asserts.assertGreaterThan(definingClassLoader.getId(), classLoaderOfDefClassLoader.getId(),
113-
"expected id assignment invariant broken for Class Loaders");
114-
115-
isDefined = true;
56+
try (Recording recording = new Recording()) {
57+
recording.enable(EVENT_NAME).withoutStackTrace();
58+
TestClassLoader cl = new TestClassLoader();
59+
recording.start();
60+
cl.loadClass(TEST_CLASS_NAME);
61+
recording.stop();
62+
63+
List<RecordedEvent> events = Events.fromRecording(recording);
64+
boolean isDefined = false;
65+
for (RecordedEvent event : events) {
66+
RecordedClass definedClass = event.getValue("definedClass");
67+
if (TEST_CLASS_NAME.equals(definedClass.getName())) {
68+
System.out.println(event);
69+
70+
// get the RecordedClassLoader from the RecordedClass, the "definedClass"
71+
RecordedClassLoader definingClassLoader = definedClass.getClassLoader();
72+
Asserts.assertNotNull(definingClassLoader, "Defining Class Loader should not be null");
73+
74+
// invoke RecordedClassLoader.getType() in order to validate the type of the RecordedClassLoader
75+
RecordedClass definingClassLoaderType = definingClassLoader.getType();
76+
Asserts.assertNotNull(definingClassLoaderType, "The defining Class Loader type should not be null");
77+
78+
// verify matching types
79+
Asserts.assertEquals(cl.getClass().getName(), definingClassLoaderType.getName(),
80+
"Expected type " + cl.getClass().getName() + ", got type " + definingClassLoaderType.getName());
81+
82+
// get a RecordedClassLoader directly from the "definingClassLoader" field as well
83+
RecordedClassLoader definingClassLoaderFromField = event.getValue("definingClassLoader");
84+
Asserts.assertNotNull(definingClassLoaderFromField,
85+
"Defining Class Loader instantatiated from field should not be null");
86+
87+
// ensure that the class loader instance used in the test actually has a name
88+
Asserts.assertNotNull(cl.getName(),
89+
"Expected a valid name for the TestClassLoader");
90+
91+
// invoke RecordedClassLoader.getName() to get the name of the class loader instance
92+
Asserts.assertEquals(cl.getName(), definingClassLoader.getName(),
93+
"Defining Class Loader should have the same name as the original class loader");
94+
Asserts.assertEquals(definingClassLoaderFromField.getName(), definingClassLoader.getName(),
95+
"Defining Class Loader representations should have the same class loader name");
96+
97+
// invoke uniqueID()
98+
Asserts.assertGreaterThan(definingClassLoader.getId(), 0L, "Invalid id assignment");
99+
100+
// second order class loader information ("check class loader of the class loader")
101+
RecordedClassLoader classLoaderOfDefClassLoader = definingClassLoaderType.getClassLoader();
102+
Asserts.assertNotNull(classLoaderOfDefClassLoader,
103+
"The class loader for the definining class loader should not be null");
104+
Asserts.assertEquals(cl.getClass().getClassLoader().getName(), classLoaderOfDefClassLoader.getName(),
105+
"Expected class loader name " + cl.getClass().getClassLoader().getName() + ", got name " + classLoaderOfDefClassLoader.getName());
106+
107+
RecordedClass classLoaderOfDefClassLoaderType = classLoaderOfDefClassLoader.getType();
108+
Asserts.assertNotNull(classLoaderOfDefClassLoaderType,
109+
"The class loader type for the defining class loader should not be null");
110+
Asserts.assertEquals(cl.getClass().getClassLoader().getClass().getName(), classLoaderOfDefClassLoaderType.getName(),
111+
"Expected type " + cl.getClass().getClassLoader().getClass().getName() + ", got type " + classLoaderOfDefClassLoaderType.getName());
112+
113+
Asserts.assertGreaterThan(definingClassLoader.getId(), classLoaderOfDefClassLoader.getId(),
114+
"expected id assignment invariant broken for Class Loaders");
115+
116+
isDefined = true;
117+
}
116118
}
119+
Asserts.assertTrue(isDefined, "No class define event found to verify RecordedClassLoader");
117120
}
118-
Asserts.assertTrue(isDefined, "No class define event found to verify RecordedClassLoader");
119121
}
120122
}

‎test/jdk/jdk/jfr/api/consumer/TestRecordedEvent.java

+34-36
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ static class MyClass {
5151
}
5252

5353
static class TestEvent extends Event {
54-
5554
@Description("MyField")
5655
Class<?> clzField = String.class;
5756
int intField;
@@ -60,51 +59,50 @@ static class TestEvent extends Event {
6059
}
6160

6261
public static void main(String[] args) throws Throwable {
63-
Recording r = new Recording();
64-
r.start();
65-
TestEvent t = new TestEvent();
66-
t.commit();
67-
r.stop();
68-
List<RecordedEvent> events = Events.fromRecording(r);
69-
Events.hasEvents(events);
70-
71-
Asserts.assertEquals(events.size(), 1);
62+
try (Recording r = new Recording()) {
63+
r.start();
64+
TestEvent t = new TestEvent();
65+
t.commit();
66+
r.stop();
7267

73-
RecordedEvent event = events.get(0);
68+
List<RecordedEvent> events = Events.fromRecording(r);
69+
Events.hasEvents(events);
70+
Asserts.assertEquals(events.size(), 1);
71+
RecordedEvent event = events.get(0);
7472

75-
List<ValueDescriptor> descriptors = event.getFields();
73+
List<ValueDescriptor> descriptors = event.getFields();
7674

77-
System.out.println("Descriptors");
78-
for (ValueDescriptor descriptor : descriptors) {
79-
System.out.println(descriptor.getName());
80-
System.out.println(descriptor.getTypeName());
81-
}
82-
System.out.println("Descriptors end");
75+
System.out.println("Descriptors");
76+
for (ValueDescriptor descriptor : descriptors) {
77+
System.out.println(descriptor.getName());
78+
System.out.println(descriptor.getTypeName());
79+
}
80+
System.out.println("Descriptors end");
8381

84-
Object recordedClass = event.getValue("clzField");
85-
Asserts.assertTrue(recordedClass instanceof RecordedClass, "Expected Recorded Class got " + recordedClass);
82+
Object recordedClass = event.getValue("clzField");
83+
Asserts.assertTrue(recordedClass instanceof RecordedClass, "Expected Recorded Class got " + recordedClass);
8684

87-
Object recordedInt = event.getValue("intField");
88-
Asserts.assertTrue(recordedInt instanceof Integer);
85+
Object recordedInt = event.getValue("intField");
86+
Asserts.assertTrue(recordedInt instanceof Integer);
8987

90-
Object recordedString = event.getValue("stringField");
91-
System.out.println("recordedString class: " + recordedString.getClass());
92-
Asserts.assertTrue(recordedString instanceof String);
88+
Object recordedString = event.getValue("stringField");
89+
System.out.println("recordedString class: " + recordedString.getClass());
90+
Asserts.assertTrue(recordedString instanceof String);
9391

94-
Object myClass = event.getValue("myClass");
95-
Asserts.assertTrue(myClass instanceof RecordedClass, "Expected Recorded Class got " + recordedClass);
92+
Object myClass = event.getValue("myClass");
93+
Asserts.assertTrue(myClass instanceof RecordedClass, "Expected Recorded Class got " + recordedClass);
9694

97-
RecordedClass myRecClass = (RecordedClass) myClass;
98-
Asserts.assertEquals(MyClass.class.getName(), myRecClass.getName(), "Got " + myRecClass.getName());
95+
RecordedClass myRecClass = (RecordedClass) myClass;
96+
Asserts.assertEquals(MyClass.class.getName(), myRecClass.getName(), "Got " + myRecClass.getName());
9997

100-
Object recordedClassLoader = myRecClass.getValue("classLoader");
101-
Asserts.assertTrue(recordedClassLoader instanceof RecordedClassLoader, "Expected Recorded ClassLoader got " + recordedClassLoader);
98+
Object recordedClassLoader = myRecClass.getValue("classLoader");
99+
Asserts.assertTrue(recordedClassLoader instanceof RecordedClassLoader, "Expected Recorded ClassLoader got " + recordedClassLoader);
102100

103-
RecordedClassLoader myRecClassLoader = (RecordedClassLoader)recordedClassLoader;
104-
ClassLoader cl = MyClass.class.getClassLoader();
105-
Asserts.assertEquals(cl.getClass().getName(), myRecClassLoader.getType().getName(), "Expected Recorded ClassLoader type to equal loader type");
101+
RecordedClassLoader myRecClassLoader = (RecordedClassLoader) recordedClassLoader;
102+
ClassLoader cl = MyClass.class.getClassLoader();
103+
Asserts.assertEquals(cl.getClass().getName(), myRecClassLoader.getType().getName(), "Expected Recorded ClassLoader type to equal loader type");
106104

107-
Asserts.assertNotNull(myRecClass.getModifiers());
105+
Asserts.assertNotNull(myRecClass.getModifiers());
106+
}
108107
}
109-
110108
}

‎test/jdk/jdk/jfr/api/consumer/TestRecordedEventGetThread.java

+17-17
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,24 @@ public class TestRecordedEventGetThread {
4949
public static void main(String[] args) throws Throwable {
5050
Thread currentThread = Thread.currentThread();
5151
currentThread.setName(MY_THREAD_NAME);
52-
long expectedThreadId = currentThread.getId();
5352

54-
Recording r = new Recording();
55-
r.start();
56-
SimpleEvent t = new SimpleEvent();
57-
t.commit();
58-
r.stop();
59-
List<RecordedEvent> events = Events.fromRecording(r);
60-
r.close();
61-
Events.hasEvents(events);
62-
RecordedEvent event = events.get(0);
63-
RecordedThread recordedThread = event.getThread();
53+
try (Recording r = new Recording()) {
54+
r.start();
55+
SimpleEvent t = new SimpleEvent();
56+
t.commit();
57+
r.stop();
6458

65-
Asserts.assertNotNull(recordedThread);
66-
Asserts.assertEquals(recordedThread.getJavaName(), MY_THREAD_NAME);
67-
Asserts.assertEquals(recordedThread.getJavaThreadId(), expectedThreadId);
68-
Asserts.assertNotNull(recordedThread.getOSThreadId());
69-
Asserts.assertNotNull(recordedThread.getId());
70-
Asserts.assertEquals(recordedThread.getOSName(), MY_THREAD_NAME);
59+
List<RecordedEvent> events = Events.fromRecording(r);
60+
Events.hasEvents(events);
61+
RecordedEvent event = events.get(0);
62+
RecordedThread recordedThread = event.getThread();
63+
Asserts.assertNotNull(recordedThread);
64+
65+
Asserts.assertEquals(recordedThread.getJavaName(), MY_THREAD_NAME);
66+
Asserts.assertEquals(recordedThread.getJavaThreadId(), currentThread.getId());
67+
Asserts.assertNotNull(recordedThread.getOSThreadId());
68+
Asserts.assertNotNull(recordedThread.getId());
69+
Asserts.assertEquals(recordedThread.getOSName(), MY_THREAD_NAME);
70+
}
7171
}
7272
}

‎test/jdk/jdk/jfr/api/consumer/TestRecordedEventGetThreadOther.java

+16-26
Original file line numberDiff line numberDiff line change
@@ -47,39 +47,42 @@
4747
public class TestRecordedEventGetThreadOther {
4848

4949
private static final String MY_THREAD_NAME = "MY_THREAD_NAME";
50-
private static long expectedThreadId;
51-
private static Path dumpFilePath;
5250

5351
static class TestEvent extends Event {
5452
}
5553

5654
static class PostingThread extends Thread {
57-
58-
PostingThread() {
59-
setName(MY_THREAD_NAME);
60-
expectedThreadId = getId();
55+
private final Path dumpFilePath;
56+
PostingThread(Path dumpFilePath) {
57+
this.dumpFilePath = dumpFilePath;
6158
}
6259

6360
@Override
6461
public void run() {
6562
try {
6663
System.out.println("Starting thread...");
67-
dumpFilePath = postEventAndDumpToFile();
68-
System.out.println("events dumped to the file " + dumpFilePath);
64+
try (Recording r = new Recording()) {
65+
r.start();
66+
TestEvent t = new TestEvent();
67+
t.commit();
68+
r.stop();
69+
r.dump(dumpFilePath);
70+
System.out.println("events dumped to the file " + dumpFilePath);
71+
}
6972
} catch (Throwable t) {
7073
t.printStackTrace();
7174
Asserts.fail();
7275
}
7376
}
7477
}
7578

76-
public static void main(String[] args) throws Throwable {
77-
Thread.currentThread().setName("MyMainThread");
79+
public static void main(String[] args) throws Exception {
80+
Path dumpFilePath = Utils.createTempFile("event-thread", ".jfr");
7881

79-
PostingThread thread = new PostingThread();
82+
PostingThread thread = new PostingThread(dumpFilePath);
83+
thread.setName(MY_THREAD_NAME);
8084
thread.start();
8185
thread.join();
82-
System.out.println("testing dump in file " + dumpFilePath);
8386

8487
List<RecordedEvent> events = RecordingFile.readAllEvents(dumpFilePath);
8588
Asserts.assertEquals(events.size(), 1);
@@ -89,21 +92,8 @@ public static void main(String[] args) throws Throwable {
8992

9093
Asserts.assertNotNull(recordedThread);
9194
Asserts.assertEquals(recordedThread.getJavaName(), MY_THREAD_NAME);
92-
Asserts.assertEquals(recordedThread.getJavaThreadId(), expectedThreadId);
95+
Asserts.assertEquals(recordedThread.getJavaThreadId(), thread.getId());
9396
Asserts.assertNotNull(recordedThread.getId());
9497
Asserts.assertEquals(recordedThread.getOSName(), MY_THREAD_NAME);
9598
}
96-
97-
private static Path postEventAndDumpToFile() throws Throwable {
98-
Recording r = new Recording();
99-
r.start();
100-
TestEvent t = new TestEvent();
101-
t.commit();
102-
r.stop();
103-
Path path = Utils.createTempFile("event-thread", ".jfr");
104-
System.out.println("Created path: " + path);
105-
r.dump(path);
106-
r.close();
107-
return path;
108-
}
10999
}

‎test/jdk/jdk/jfr/api/consumer/TestRecordedFrame.java

+46-60
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import java.io.IOException;
2828
import java.util.List;
29+
import java.util.Set;
2930

3031
import jdk.jfr.Recording;
3132
import jdk.jfr.consumer.RecordedEvent;
@@ -49,74 +50,59 @@
4950
public final class TestRecordedFrame {
5051

5152
public static void main(String[] args) throws IOException {
52-
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
53-
doTest(getLineNumber("main", stackTrace) + 1);
53+
System.out.println(); // Makes BCI for method larger than 0
54+
test(); // Records the line number and BCI for the main method/frame
55+
}
56+
57+
static void test() throws IOException {
58+
try (Recording recording = new Recording()) {
59+
recording.start();
60+
61+
SimpleEvent ev = new SimpleEvent();
62+
ev.commit();
63+
recording.stop();
64+
65+
List<RecordedEvent> recordedEvents = Events.fromRecording(recording);
66+
Events.hasEvents(recordedEvents);
67+
RecordedEvent recordedEvent = recordedEvents.get(0);
68+
69+
RecordedStackTrace stacktrace = recordedEvent.getStackTrace();
70+
List<RecordedFrame> frames = stacktrace.getFrames();
71+
for (RecordedFrame frame : frames) {
72+
// All frames are java frames
73+
Asserts.assertTrue(frame.isJavaFrame());
74+
// Verify the main() method frame
75+
RecordedMethod method = frame.getMethod();
76+
if (method.getName().equals("main")) {
77+
// Frame type
78+
String type = frame.getType();
79+
System.out.println("type: " + type);
80+
Set<String> types = Set.of("Interpreted", "JIT compiled", "Inlined");
81+
Asserts.assertTrue(types.contains(type));
82+
// Line number
83+
Asserts.assertEquals(getLineNumber("main"), frame.getLineNumber());
84+
// Interpreted
85+
boolean isInterpreted = "Interpreted".equals(type);
86+
boolean expectedInterpreted = "true".equals(System.getProperty("interpreted"));
87+
Asserts.assertEquals(isInterpreted, expectedInterpreted);
88+
// BCI
89+
int bci = frame.getBytecodeIndex();
90+
System.out.println("bci: " + bci);
91+
Asserts.assertGreaterThan(bci, 0);
92+
}
93+
}
94+
}
5495
}
5596

5697
/**
57-
* Returns line number of the passed method for the passed stacktrace
98+
* Returns line number of a method on the stack
5899
*/
59-
private static int getLineNumber(String methodName, StackTraceElement[] stackTrace) {
60-
for (StackTraceElement ste : stackTrace) {
100+
private static int getLineNumber(String methodName) {
101+
for (StackTraceElement ste : Thread.currentThread().getStackTrace()) {
61102
if (methodName.equals(ste.getMethodName())) {
62103
return ste.getLineNumber();
63104
}
64105
}
65106
throw new RuntimeException("Unexpected error: could not analyze stacktrace");
66107
}
67-
68-
public static void doTest(int lineNumber) throws IOException {
69-
70-
System.out.println("Enetring method");
71-
72-
Recording recording = new Recording();
73-
recording.start();
74-
75-
SimpleEvent ev = new SimpleEvent();
76-
commitEvent(ev);
77-
recording.stop();
78-
79-
List<RecordedEvent> recordedEvents = Events.fromRecording(recording);
80-
Events.hasEvents(recordedEvents);
81-
RecordedEvent recordedEvent = recordedEvents.get(0);
82-
83-
RecordedStackTrace stacktrace = recordedEvent.getStackTrace();
84-
List<RecordedFrame> frames = stacktrace.getFrames();
85-
for (RecordedFrame frame : frames) {
86-
87-
// All frames are java frames
88-
Asserts.assertTrue(frame.isJavaFrame());
89-
// Verify the main() method frame
90-
RecordedMethod method = frame.getMethod();
91-
if (method.getName().equals("main")) {
92-
93-
// Frame type
94-
String type = frame.getType();
95-
System.out.println("type: " + type);
96-
Asserts.assertTrue(
97-
type.equals("Interpreted")
98-
|| type.equals("JIT compiled")
99-
|| type.equals("Inlined"));
100-
101-
Asserts.assertEquals(lineNumber, frame.getLineNumber());
102-
103-
boolean isInterpreted = "Interpreted".equals(type);
104-
boolean expectedInterpreted = "true".equals(System.getProperty("interpreted"));
105-
Asserts.assertEquals(isInterpreted, expectedInterpreted);
106-
107-
int bci = frame.getBytecodeIndex();
108-
109-
System.out.println("bci: " + bci);
110-
Asserts.assertTrue(bci > 0);
111-
}
112-
113-
}
114-
115-
}
116-
117-
private static void commitEvent(SimpleEvent ev) {
118-
System.out.println("commit");
119-
ev.commit();
120-
}
121-
122108
}

‎test/jdk/jdk/jfr/api/consumer/TestRecordedFullStackTrace.java

+12-14
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,16 @@ public static void main(String[] args) throws Throwable {
7979
private static void assertStackTraces(RecurseThread[] threads) throws Throwable {
8080
Path path = null;
8181
do {
82-
Recording recording = new Recording();
83-
recording.enable(EVENT_NAME).withPeriod(Duration.ofMillis(50));
84-
recording.start();
85-
Thread.sleep(500);
86-
recording.stop();
87-
// Dump the recording to a file
88-
path = Utils.createTempFile("execution-stack-trace", ".jfr");
89-
System.out.println("Dumping to " + path);
90-
recording.dump(path);
91-
recording.close();
82+
try (Recording recording = new Recording()) {
83+
recording.enable(EVENT_NAME).withPeriod(Duration.ofMillis(1));
84+
recording.start();
85+
Thread.sleep(50);
86+
recording.stop();
87+
// Dump the recording to a file
88+
path = Utils.createTempFile("execution-stack-trace", ".jfr");
89+
System.out.println("Dumping to " + path);
90+
recording.dump(path);
91+
}
9292
} while (!hasValidStackTraces(path, threads));
9393
}
9494

@@ -103,8 +103,7 @@ private static boolean hasValidStackTraces(Path path, RecurseThread[] threads) t
103103
for (int threadIndex = 0; threadIndex < threads.length; ++threadIndex) {
104104
RecurseThread currThread = threads[threadIndex];
105105
if (threadId == currThread.getId()) {
106-
System.out.println("ThreadName=" + currThread.getName() + ", depth=" + currThread.totalDepth);
107-
Asserts.assertEquals(threadName, currThread.getName(), "Wrong thread name");
106+
Asserts.assertEquals(threadName, currThread.getName(), "Wrong thread name, deptth=" + currThread.totalDepth);
108107
if ("recurseEnd".equals(getTopMethodName(event))) {
109108
isEventFound[threadIndex] = true;
110109
checkEvent(event, currThread.totalDepth);
@@ -147,8 +146,7 @@ private static void checkEvent(RecordedEvent event, int expectedDepth) throws Th
147146
for (int i = 0; i < frames.size(); ++i) {
148147
String name = frames.get(i).getMethod().getName();
149148
String expectedName = expectedMethods.get(i);
150-
System.out.printf("method[%d]=%s, expected=%s%n", i, name, expectedName);
151-
Asserts.assertEquals(name, expectedName, "Wrong method name");
149+
Asserts.assertEquals(name, expectedName, "Wrong method name at index " + i);
152150
}
153151

154152
boolean isTruncated = stacktrace.isTruncated();

‎test/jdk/jdk/jfr/api/consumer/TestRecordedInstantEventTimestamp.java

+10-11
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,16 @@
4444
public class TestRecordedInstantEventTimestamp {
4545

4646
public static void main(String[] args) throws Throwable {
47-
Recording r = new Recording();
48-
r.start();
49-
SimpleEvent s = new SimpleEvent();
50-
s.commit();
51-
r.stop();
47+
try (Recording r = new Recording()) {
48+
r.start();
49+
SimpleEvent s = new SimpleEvent();
50+
s.commit();
51+
r.stop();
5252

53-
List<RecordedEvent> events = Events.fromRecording(r);
54-
Events.hasEvents(events);
55-
RecordedEvent event = events.get(0);
56-
Asserts.assertEquals(event.getStartTime(), event.getEndTime());
57-
58-
r.close();
53+
List<RecordedEvent> events = Events.fromRecording(r);
54+
Events.hasEvents(events);
55+
RecordedEvent event = events.get(0);
56+
Asserts.assertEquals(event.getStartTime(), event.getEndTime());
57+
}
5958
}
6059
}

‎test/jdk/jdk/jfr/api/consumer/TestRecordedMethodDescriptor.java

+35-41
Original file line numberDiff line numberDiff line change
@@ -34,64 +34,58 @@
3434
import jdk.jfr.Event;
3535
import jdk.jfr.Recording;
3636
import jdk.jfr.consumer.RecordedEvent;
37-
import jdk.jfr.consumer.RecordedMethod;
3837
import jdk.jfr.consumer.RecordedFrame;
38+
import jdk.jfr.consumer.RecordedMethod;
3939
import jdk.jfr.consumer.RecordedStackTrace;
4040
import jdk.test.lib.jfr.Events;
4141

4242

4343
/**
4444
* @test
45+
* @summary Verifies that the method descriptor is correct
4546
* @key jfr
4647
* @requires vm.hasJFR
4748
* @library /test/lib
4849
* @run main/othervm jdk.jfr.api.consumer.TestRecordedMethodDescriptor
4950
*/
5051
public final class TestRecordedMethodDescriptor {
5152

52-
private static boolean isMainMethodDescriptorRecorded;
53-
private static final String MAIN_METHOD_DESCRIPTOR = "([Ljava/lang/String;)V";
54-
private static final String MAIN_METHOD_NAME = "main";
55-
56-
public static void main(String[] args) throws Throwable {
57-
Recording recording = new Recording();
58-
recording.enable(MyEvent.class).withStackTrace();
59-
recording.start();
60-
61-
MyEvent event = new MyEvent();
62-
event.begin();
63-
event.end();
64-
event.commit();
65-
recording.stop();
66-
67-
List<RecordedEvent> recordedEvents = Events.fromRecording(recording);
68-
assertEquals(1, recordedEvents.size(), "Expected one event");
69-
RecordedEvent recordedEvent = recordedEvents.get(0);
70-
71-
RecordedStackTrace stacktrace = recordedEvent.getStackTrace();
72-
List<RecordedFrame> frames = stacktrace.getFrames();
73-
assertFalse(frames.isEmpty(), "Stacktrace frames was empty");
74-
for (RecordedFrame frame : frames) {
75-
analyzeRecordedMethodDescriptor(frame.getMethod());
76-
}
77-
78-
assertTrue(isMainMethodDescriptorRecorded, "main() method descriptor has never been recorded");
53+
public static class MyEvent extends Event {
7954
}
8055

81-
private static void analyzeRecordedMethodDescriptor(RecordedMethod method) {
82-
83-
String descr = method.getDescriptor();
84-
assertNotNull(descr, "Method descriptor is null");
85-
String name = method.getName();
86-
assertNotNull(name, "Method name is null");
56+
private static final String MAIN_METHOD_DESCRIPTOR = "([Ljava/lang/String;)V";
57+
private static final String MAIN_METHOD_NAME = "main";
8758

88-
if (name.equals(MAIN_METHOD_NAME) && descr.equals(MAIN_METHOD_DESCRIPTOR)) {
89-
assertFalse(isMainMethodDescriptorRecorded, "main() method descriptor already recorded");
90-
isMainMethodDescriptorRecorded = true;
59+
public static void main(String[] args) throws Exception {
60+
try (Recording recording = new Recording()) {
61+
recording.enable(MyEvent.class);
62+
recording.start();
63+
64+
MyEvent event = new MyEvent();
65+
event.commit();
66+
recording.stop();
67+
68+
List<RecordedEvent> recordedEvents = Events.fromRecording(recording);
69+
assertEquals(1, recordedEvents.size(), "Expected one event");
70+
RecordedEvent recordedEvent = recordedEvents.get(0);
71+
72+
RecordedStackTrace stacktrace = recordedEvent.getStackTrace();
73+
List<RecordedFrame> frames = stacktrace.getFrames();
74+
assertFalse(frames.isEmpty(), "Stacktrace frames was empty");
75+
76+
boolean foundMainMethod = false;
77+
for (RecordedFrame frame : frames) {
78+
RecordedMethod method = frame.getMethod();
79+
String descr = method.getDescriptor();
80+
assertNotNull(descr, "Method descriptor is null");
81+
String name = method.getName();
82+
assertNotNull(name, "Method name is null");
83+
if (name.equals(MAIN_METHOD_NAME) && descr.equals(MAIN_METHOD_DESCRIPTOR)) {
84+
assertFalse(foundMainMethod, "main() method descriptor already recorded");
85+
foundMainMethod = true;
86+
}
87+
}
88+
assertTrue(foundMainMethod, "main() method descriptor has never been recorded");
9189
}
9290
}
93-
94-
public static class MyEvent extends Event {
95-
}
96-
9791
}

‎test/jdk/jdk/jfr/api/consumer/TestRecordedObject.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -377,14 +377,15 @@ private static <T> void assertGetter(Function<String, T> f, T expectedValue, Str
377377
}
378378

379379
private static RecordedObject makeRecordedObject() throws IOException {
380-
Recording r = new Recording();
381-
r.start();
382-
EventWithValues t = new EventWithValues();
383-
t.commit();
384-
r.stop();
385-
List<RecordedEvent> events = Events.fromRecording(r);
386-
Events.hasEvents(events);
387-
return events.get(0);
380+
try (Recording r = new Recording()) {
381+
r.start();
382+
EventWithValues t = new EventWithValues();
383+
t.commit();
384+
r.stop();
385+
List<RecordedEvent> events = Events.fromRecording(r);
386+
Events.hasEvents(events);
387+
return events.get(0);
388+
}
388389
}
389390

390391
private static Set<String> createAll() {

‎test/jdk/jdk/jfr/api/consumer/TestRecordingFile.java

+15-16
Original file line numberDiff line numberDiff line change
@@ -74,24 +74,23 @@ static class TestEvent3 extends Event {
7474
private final static long METADATA_OFFSET = 24;
7575

7676
public static void main(String[] args) throws Throwable {
77-
78-
// create some recording data
79-
Recording r = new Recording();
80-
r.enable(TestEvent1.class).withoutStackTrace();
81-
r.enable(TestEvent2.class).withoutStackTrace();
82-
r.enable(TestEvent3.class).withoutStackTrace();
83-
r.start();
84-
TestEvent1 t1 = new TestEvent1();
85-
t1.commit();
86-
TestEvent2 t2 = new TestEvent2();
87-
t2.commit();
88-
TestEvent3 t3 = new TestEvent3();
89-
t3.commit();
90-
r.stop();
9177
Path valid = Utils.createTempFile("three-event-recording", ".jfr");
92-
r.dump(valid);
93-
r.close();
9478

79+
// create some recording data
80+
try (Recording r = new Recording()) {
81+
r.enable(TestEvent1.class).withoutStackTrace();
82+
r.enable(TestEvent2.class).withoutStackTrace();
83+
r.enable(TestEvent3.class).withoutStackTrace();
84+
r.start();
85+
TestEvent1 t1 = new TestEvent1();
86+
t1.commit();
87+
TestEvent2 t2 = new TestEvent2();
88+
t2.commit();
89+
TestEvent3 t3 = new TestEvent3();
90+
t3.commit();
91+
r.stop();
92+
r.dump(valid);
93+
}
9594
Path brokenWithZeros = createBrokenWIthZeros(valid);
9695
Path brokenMetadata = createBrokenMetadata(valid);
9796
// prepare event sets

‎test/jdk/jdk/jfr/api/consumer/TestRecordingFileReadEventEof.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,19 @@
4444
public class TestRecordingFileReadEventEof {
4545

4646
public static void main(String[] args) throws Throwable {
47-
Recording r = new Recording();
48-
r.start();
49-
SimpleEvent t = new SimpleEvent();
50-
t.commit();
51-
r.stop();
52-
RecordingFile file = Events.copyTo(r);
53-
r.close();
54-
file.readEvent();
55-
try {
47+
try (Recording r = new Recording()) {
48+
r.start();
49+
SimpleEvent t = new SimpleEvent();
50+
t.commit();
51+
r.stop();
52+
RecordingFile file = Events.copyTo(r);
5653
file.readEvent();
57-
Asserts.fail("Expected EOFException not thrown");
58-
} catch (EOFException x) {
59-
// OK, as expected
54+
try {
55+
file.readEvent();
56+
Asserts.fail("Expected EOFException not thrown");
57+
} catch (EOFException x) {
58+
// OK, as expected
59+
}
6060
}
6161
}
6262
}

‎test/jdk/jdk/jfr/api/consumer/TestSingleRecordedEvent.java

+13-15
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,19 @@ private static class MyEvent extends Event {
4949
}
5050

5151
public static void main(String[] args) throws Throwable {
52-
Recording r = new Recording();
53-
r.start();
54-
// Commit a single event to the recording
55-
MyEvent event = new MyEvent();
56-
event.commit();
57-
r.stop();
58-
List<RecordedEvent> events = Events.fromRecording(r);
59-
Events.hasEvents(events);
52+
try (Recording r = new Recording()) {
53+
r.start();
54+
// Commit a single event to the recording
55+
MyEvent event = new MyEvent();
56+
event.commit();
57+
r.stop();
58+
List<RecordedEvent> events = Events.fromRecording(r);
59+
Events.hasEvents(events);
6060

61-
// Should be 1 event only
62-
Asserts.assertEquals(events.size(), 1);
63-
64-
RecordedEvent recordedEvent = events.get(0);
65-
66-
// Event description should be the same
67-
Asserts.assertEquals(recordedEvent.getEventType().getDescription(), "MyDescription");
61+
// Should be 1 event only
62+
Asserts.assertEquals(events.size(), 1);
63+
RecordedEvent recordedEvent = events.get(0);
64+
Asserts.assertEquals(recordedEvent.getEventType().getDescription(), "MyDescription");
65+
}
6866
}
6967
}

‎test/jdk/jdk/jfr/api/consumer/TestValueDescriptorRecorded.java

+17-18
Original file line numberDiff line numberDiff line change
@@ -48,31 +48,30 @@
4848
public class TestValueDescriptorRecorded {
4949

5050
private static class MyEvent extends Event {
51-
5251
@Label("myLabel")
5352
@Description("myDescription")
5453
int myValue;
5554
}
5655

5756
public static void main(String[] args) throws Throwable {
58-
Recording r = new Recording();
59-
r.enable(MyEvent.class).withoutStackTrace();
60-
r.start();
61-
MyEvent event = new MyEvent();
62-
event.commit();
63-
r.stop();
64-
65-
List<RecordedEvent> events = Events.fromRecording(r);
66-
Events.hasEvents(events);
67-
RecordedEvent recordedEvent = events.get(0);
57+
try (Recording r = new Recording()) {
58+
r.enable(MyEvent.class).withoutStackTrace();
59+
r.start();
60+
MyEvent event = new MyEvent();
61+
event.commit();
62+
r.stop();
6863

69-
for (ValueDescriptor desc : recordedEvent.getFields()) {
70-
if ("myValue".equals(desc.getName())) {
71-
Asserts.assertEquals(desc.getLabel(), "myLabel");
72-
Asserts.assertEquals(desc.getDescription(), "myDescription");
73-
Asserts.assertEquals(desc.getTypeName(), int.class.getName());
74-
Asserts.assertFalse(desc.isArray());
75-
Asserts.assertNull(desc.getContentType());
64+
List<RecordedEvent> events = Events.fromRecording(r);
65+
Events.hasEvents(events);
66+
RecordedEvent recordedEvent = events.get(0);
67+
for (ValueDescriptor desc : recordedEvent.getFields()) {
68+
if ("myValue".equals(desc.getName())) {
69+
Asserts.assertEquals(desc.getLabel(), "myLabel");
70+
Asserts.assertEquals(desc.getDescription(), "myDescription");
71+
Asserts.assertEquals(desc.getTypeName(), int.class.getName());
72+
Asserts.assertFalse(desc.isArray());
73+
Asserts.assertNull(desc.getContentType());
74+
}
7675
}
7776
}
7877
}

0 commit comments

Comments
 (0)
Please sign in to comment.