-
Notifications
You must be signed in to change notification settings - Fork 566
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate pinning detection to HelidonTest
* TestNG with always helidon fix Signed-off-by: Daniel Kec <daniel.kec@oracle.com>
- Loading branch information
Showing
36 changed files
with
885 additions
and
375 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2024 Oracle and/or its affiliates. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.helidon.common.testing</groupId> | ||
<artifactId>helidon-common-testing-project</artifactId> | ||
<version>4.2.0-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<artifactId>helidon-common-testing-virtual-threads</artifactId> | ||
|
||
<name>Helidon Virtual Threads Testing Utilities</name> | ||
|
||
</project> |
54 changes: 54 additions & 0 deletions
54
...threads/src/main/java/io/helidon/common/testing/virtualthreads/PinningAssertionError.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright (c) 2024 Oracle and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.helidon.common.testing.virtualthreads; | ||
|
||
import jdk.jfr.consumer.RecordedEvent; | ||
|
||
/** | ||
* Assertion error used for reporting of Virtual Thread pinning detected during test. | ||
*/ | ||
public class PinningAssertionError extends AssertionError { | ||
|
||
/** | ||
* Pinning JFR event. | ||
*/ | ||
private final RecordedEvent recordedEvent; | ||
|
||
/** | ||
* Create new pinning exception. | ||
* | ||
* @param recordedEvent pinning JFR event | ||
*/ | ||
PinningAssertionError(RecordedEvent recordedEvent) { | ||
this.recordedEvent = recordedEvent; | ||
if (recordedEvent.getStackTrace() != null) { | ||
StackTraceElement[] stackTraceElements = recordedEvent.getStackTrace().getFrames().stream() | ||
.map(f -> new StackTraceElement(f.getMethod().getType().getName(), | ||
f.getMethod().getName(), | ||
f.getMethod().getType().getName() + ".java", | ||
f.getLineNumber())) | ||
.toArray(StackTraceElement[]::new); | ||
super.setStackTrace(stackTraceElements); | ||
} | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return "Pinned virtual threads were detected:\n" | ||
+ recordedEvent.toString(); | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
...rtual-threads/src/main/java/io/helidon/common/testing/virtualthreads/PinningRecorder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright (c) 2024 Oracle and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.helidon.common.testing.virtualthreads; | ||
|
||
import java.time.Duration; | ||
|
||
import jdk.jfr.consumer.RecordedEvent; | ||
import jdk.jfr.consumer.RecordingStream; | ||
|
||
/** | ||
* Record pinned thread events and throw exception when detected. | ||
*/ | ||
public class PinningRecorder implements AutoCloseable { | ||
|
||
/** | ||
* Default threshold for considering carrier thread blocking as pinning. | ||
*/ | ||
public static final long DEFAULT_THRESHOLD = 20; | ||
private static final String JFR_EVENT_VIRTUAL_THREAD_PINNED = "jdk.VirtualThreadPinned"; | ||
private final RecordingStream recordingStream = new RecordingStream(); | ||
private volatile PinningAssertionError pinningAssertionError; | ||
|
||
private PinningRecorder() { | ||
//noop | ||
} | ||
|
||
/** | ||
* Create new pinning JFR event recorder. | ||
* | ||
* @return new pinning recorder | ||
*/ | ||
public static PinningRecorder create() { | ||
return new PinningRecorder(); | ||
} | ||
|
||
/** | ||
* Start async recording of {@code jdk.VirtualThreadPinned} JFR event. | ||
* | ||
* @param threshold time threshold for carrier thread blocking to be considered as pinning | ||
*/ | ||
public void record(Duration threshold) { | ||
recordingStream.enable(JFR_EVENT_VIRTUAL_THREAD_PINNED) | ||
.withThreshold(threshold) | ||
.withStackTrace(); | ||
recordingStream.onEvent(JFR_EVENT_VIRTUAL_THREAD_PINNED, this::record); | ||
recordingStream.startAsync(); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
try { | ||
// Flush ending events | ||
recordingStream.stop(); | ||
} finally { | ||
recordingStream.close(); | ||
} | ||
checkAndThrow(); | ||
} | ||
|
||
void checkAndThrow() { | ||
if (pinningAssertionError != null) { | ||
throw pinningAssertionError; | ||
} | ||
} | ||
|
||
private void record(RecordedEvent event) { | ||
PinningAssertionError e = new PinningAssertionError(event); | ||
if (pinningAssertionError == null) { | ||
pinningAssertionError = e; | ||
} else { | ||
pinningAssertionError.addSuppressed(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.