Lauri Tulmin 2023-04-03 12:48:46 +03:00 committed by GitHub
parent 70cd8464e2
commit 8c7a8e1dfb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View File

@ -32,6 +32,7 @@ tasks {
} }
include("**/*PsGcMemoryMetricTest.*") include("**/*PsGcMemoryMetricTest.*")
jvmArgs("-XX:+UseParallelGC") jvmArgs("-XX:+UseParallelGC")
jvmArgs("-Xmx128m")
} }
val testSerial by registering(Test::class) { val testSerial by registering(Test::class) {

View File

@ -76,12 +76,24 @@ class PsGcMemoryMetricTest {
.anyMatch(p -> p.getAttributes().equals(ATTR_PS_OLD_GEN)); .anyMatch(p -> p.getAttributes().equals(ATTR_PS_OLD_GEN));
} }
private static void causeGc() {
String s = "1234567890";
try {
while (true) {
s = s + s;
}
} catch (OutOfMemoryError outOfMemoryError) {
// ignore
}
}
@Test @Test
void shouldHaveGcDurationMetrics() throws InterruptedException { void shouldHaveGcDurationMetrics() {
// TODO: Need a reliable way to test old and young gen GC in isolation. // TODO: Need a reliable way to test old and young gen GC in isolation.
// Generate some JFR events // Generate some JFR events
Thread.sleep(100); // using System.gc() here doesn't reliably get us the GC events we need
System.gc(); causeGc();
Attributes minorGcAttributes = Attributes minorGcAttributes =
Attributes.of(ATTR_GC, "PS Scavenge", ATTR_ACTION, END_OF_MINOR_GC); Attributes.of(ATTR_GC, "PS Scavenge", ATTR_ACTION, END_OF_MINOR_GC);
Attributes majorGcAttributes = Attributes majorGcAttributes =