-
Notifications
You must be signed in to change notification settings - Fork 565
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 <[email protected]>
- Loading branch information
Showing
37 changed files
with
917 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,29 @@ | ||
<?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. | ||
--> | ||
|
||
<FindBugsFilter | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="https://github.com/spotbugs/filter/3.0.0" | ||
xsi:schemaLocation="https://github.com/spotbugs/filter/3.0.0 https://raw.githubusercontent.com/spotbugs/spotbugs/3.1.0/spotbugs/etc/findbugsfilter.xsd"> | ||
|
||
<Match> | ||
<Class name="io.helidon.common.testing.virtualthreads.PinningException"/> | ||
<Bug pattern="NM_CLASS_NOT_EXCEPTION"/> | ||
</Match> | ||
</FindBugsFilter> |
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,35 @@ | ||
<?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> | ||
</parent> | ||
<artifactId>helidon-common-testing-virtual-threads</artifactId> | ||
|
||
<name>Helidon Virtual Threads Testing Utilities</name> | ||
|
||
<properties> | ||
<spotbugs.exclude>etc/spotbugs/exclude.xml</spotbugs.exclude> | ||
</properties> | ||
|
||
</project> |
54 changes: 54 additions & 0 deletions
54
...tual-threads/src/main/java/io/helidon/common/testing/virtualthreads/PinningException.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; | ||
|
||
/** | ||
* Exception used for reporting of Virtual Thread pinning detected during test. | ||
*/ | ||
public class PinningException extends AssertionError { | ||
|
||
/** | ||
* Pinning JFR event. | ||
*/ | ||
private final RecordedEvent recordedEvent; | ||
|
||
/** | ||
* Create new pinning exception. | ||
* | ||
* @param recordedEvent pinning JFR event | ||
*/ | ||
PinningException(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 PinningException pinningException; | ||
|
||
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 (pinningException != null) { | ||
throw pinningException; | ||
} | ||
} | ||
|
||
private void record(RecordedEvent event) { | ||
PinningException e = new PinningException(event); | ||
if (pinningException == null) { | ||
pinningException = e; | ||
} else { | ||
pinningException.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
Oops, something went wrong.