-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Introduce PreInterruptCallback extension point #3431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
60 changes: 60 additions & 0 deletions
60
junit-jupiter-api/src/main/java/org/junit/jupiter/api/extension/PreInterruptCallback.java
This file contains hidden or 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,60 @@ | ||
/* | ||
* Copyright 2015-2024 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package org.junit.jupiter.api.extension; | ||
|
||
import static org.apiguardian.api.API.Status.EXPERIMENTAL; | ||
|
||
import org.apiguardian.api.API; | ||
|
||
/** | ||
* {@code PreInterruptCallback} defines the API for {@link Extension | ||
* Extensions} that wish to be called prior to invocations of | ||
* {@link Thread#interrupt()} by the {@link org.junit.jupiter.api.Timeout} | ||
* extension. | ||
* | ||
AndreasTu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* <p>JUnit registers a default implementation that dumps the stacks of all | ||
* {@linkplain Thread threads} to {@code System.out} if the | ||
* {@value #THREAD_DUMP_ENABLED_PROPERTY_NAME} configuration parameter is set to | ||
* {@code true}. | ||
* | ||
* @since 5.12 | ||
* @see org.junit.jupiter.api.Timeout | ||
*/ | ||
@API(status = EXPERIMENTAL, since = "5.12") | ||
public interface PreInterruptCallback extends Extension { | ||
|
||
/** | ||
* Property name used to enable dumping the stack of all | ||
* {@linkplain Thread threads} to {@code System.out} when a timeout has occurred. | ||
* | ||
* <p>This behavior is disabled by default. | ||
* | ||
* @since 5.12 | ||
*/ | ||
@API(status = EXPERIMENTAL, since = "5.12") | ||
String THREAD_DUMP_ENABLED_PROPERTY_NAME = "junit.jupiter.execution.timeout.threaddump.enabled"; | ||
|
||
/** | ||
* Callback that is invoked <em>before</em> a {@link Thread} is interrupted with | ||
* {@link Thread#interrupt()}. | ||
* | ||
* <p>Note: There is no guarantee on which {@link Thread} this callback will be | ||
* executed. | ||
* | ||
* @param preInterruptContext the context with the target {@link Thread}, which will get interrupted. | ||
* @param extensionContext the extension context for the callback; never {@code null} | ||
* @since 5.12 | ||
* @see PreInterruptContext | ||
*/ | ||
@API(status = EXPERIMENTAL, since = "5.12") | ||
void beforeThreadInterrupt(PreInterruptContext preInterruptContext, ExtensionContext extensionContext) | ||
throws Exception; | ||
} |
35 changes: 35 additions & 0 deletions
35
junit-jupiter-api/src/main/java/org/junit/jupiter/api/extension/PreInterruptContext.java
This file contains hidden or 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 @@ | ||
/* | ||
* Copyright 2015-2024 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package org.junit.jupiter.api.extension; | ||
|
||
import static org.apiguardian.api.API.Status.EXPERIMENTAL; | ||
|
||
import org.apiguardian.api.API; | ||
|
||
/** | ||
* {@code PreInterruptContext} encapsulates the <em>context</em> in which an | ||
* {@link PreInterruptCallback#beforeThreadInterrupt(PreInterruptContext, ExtensionContext) beforeThreadInterrupt} method is called. | ||
* | ||
* @since 5.12 | ||
* @see PreInterruptCallback | ||
*/ | ||
@API(status = EXPERIMENTAL, since = "5.12") | ||
public interface PreInterruptContext { | ||
|
||
/** | ||
* Get the {@link Thread} which will be interrupted. | ||
* | ||
* @return the Thread; never {@code null} | ||
* @since 5.12 | ||
*/ | ||
@API(status = EXPERIMENTAL, since = "5.12") | ||
Thread getThreadToInterrupt(); | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.