Skip to content

Commit 4a478b8

Browse files
committedJan 7, 2021
8250903: jdk/jfr/javaagent/TestLoadedAgent.java fails with Mismatch in TestEvent count
Reviewed-by: mgronlun
1 parent 4f914e2 commit 4a478b8

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed
 

‎test/jdk/jdk/jfr/javaagent/EventEmitterAgent.java

+6-15
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,10 @@
3535
import jdk.test.lib.Asserts;
3636
import jdk.test.lib.jfr.EventNames;
3737

38-
// Java agent that emits in multiple threads
38+
// Java agent that emits events
3939
public class EventEmitterAgent {
4040

41-
private static final int THREADS = 5;
42-
private static final int EVENTS_PER_THREAD = 150_000;
43-
private static final int EXPECTED_COUNT = THREADS * EVENTS_PER_THREAD;
41+
private static final long EVENTS = 150_000;
4442
private static final Path DUMP_PATH = Paths.get("dump.jfr").toAbsolutePath();
4543

4644
// Called when agent is loaded from command line
@@ -58,20 +56,13 @@ private static void agentWork() throws Exception {
5856
r.enable(EventNames.JavaExceptionThrow);
5957
r.setDestination(DUMP_PATH);
6058
r.start();
61-
Thread[] threads = new Thread[THREADS];
62-
for (int i = 0; i < THREADS; i++) {
63-
threads[i] = new Thread(EventEmitterAgent::emitEvents);
64-
threads[i].start();
65-
}
66-
for (int i = 0; i < THREADS; i++) {
67-
threads[i].join();
68-
}
59+
emitEvents();
6960
r.stop();
7061
}
7162
}
7263

7364
public static void emitEvents() {
74-
for (int i = 0; i < EVENTS_PER_THREAD; i++) {
65+
for (int i = 0; i < EVENTS; i++) {
7566
TestEvent e = new TestEvent();
7667
e.msg = "Long message that puts pressure on the string pool " + i % 100;
7768
e.count = i;
@@ -80,7 +71,7 @@ public static void emitEvents() {
8071
e.commit();
8172
if (i % 10000 == 0) {
8273
try {
83-
Thread.sleep(1);
74+
Thread.sleep(10);
8475
} catch (InterruptedException ie) {
8576
// ignore
8677
}
@@ -101,6 +92,6 @@ public static void validateRecording() throws Exception {
10192
.stream()
10293
.filter(e -> e.getEventType().getName().equals("Test"))
10394
.count();
104-
Asserts.assertTrue(testEventCount == EXPECTED_COUNT, "Mismatch in TestEvent count");
95+
Asserts.assertEquals(testEventCount, EVENTS, "Mismatch in TestEvent count");
10596
}
10697
}

0 commit comments

Comments
 (0)
Please sign in to comment.