-
Notifications
You must be signed in to change notification settings - Fork 11
Add a test for crash-recovery in the 'vm' stackwalker. #216
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,15 +4,38 @@ | |
| import java.io.IOException; | ||
| import java.io.InputStreamReader; | ||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.concurrent.locks.LockSupport; | ||
| import java.util.function.Function; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
|
|
||
| public abstract class AbstractProcessProfilerTest { | ||
| protected final boolean launch(String target, List<String> jvmArgs, String commands, Function<String, Boolean> onStdoutLine, Function<String, Boolean> onStderrLine) throws Exception { | ||
| public static final class LaunchResult { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice to see we are investing in controlled behaviour tests. I think we basically have different parts
|
||
| public final boolean inTime; | ||
| public final int exitCode; | ||
|
|
||
| public LaunchResult(boolean inTime, int exitCode) { | ||
| this.inTime = inTime; | ||
| this.exitCode = exitCode; | ||
| } | ||
| } | ||
|
|
||
| public enum LineConsumerResult { | ||
| CONTINUE, | ||
| STOP, | ||
| IGNORE | ||
| } | ||
|
|
||
| protected final LaunchResult launch(String target, List<String> jvmArgs, String commands, Function<String, LineConsumerResult> onStdoutLine, Function<String, LineConsumerResult> onStderrLine) throws Exception { | ||
| return launch(target, jvmArgs, commands, Collections.emptyMap(), onStdoutLine, onStderrLine); | ||
| } | ||
|
|
||
| protected final LaunchResult launch(String target, List<String> jvmArgs, String commands, Map<String, String> env, Function<String, LineConsumerResult> onStdoutLine, Function<String, LineConsumerResult> onStderrLine) throws Exception { | ||
| String javaHome = System.getenv("JAVA_TEST_HOME"); | ||
| if (javaHome == null) { | ||
| javaHome = System.getenv("JAVA_HOME"); | ||
|
|
@@ -34,23 +57,34 @@ protected final boolean launch(String target, List<String> jvmArgs, String comma | |
| } | ||
|
|
||
| ProcessBuilder pb = new ProcessBuilder(args); | ||
| pb.environment().putAll(env); | ||
| Process p = pb.start(); | ||
| Thread stdoutReader = new Thread(() -> { | ||
| Function<String, Boolean> lineProcessor = onStdoutLine != null ? onStdoutLine : l -> true; | ||
| Function<String, LineConsumerResult> lineProcessor = onStdoutLine != null ? onStdoutLine : l -> LineConsumerResult.CONTINUE; | ||
| try (BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()))) { | ||
| String line; | ||
| while ((line = br.readLine()) != null) { | ||
| System.out.println("[out] " + line); | ||
| if (!lineProcessor.apply(line)) { | ||
| try { | ||
| p.getOutputStream().write(1); | ||
| p.getOutputStream().flush(); | ||
| } catch (IOException ignored) { | ||
| LineConsumerResult lResult = lineProcessor.apply(line); | ||
| switch (lResult) { | ||
| case STOP: { | ||
| try { | ||
| p.getOutputStream().write(1); | ||
| p.getOutputStream().flush(); | ||
| } catch (IOException ignored) { | ||
| } | ||
| break; | ||
| } | ||
| case CONTINUE: { | ||
| if (line.contains("[ready]")) { | ||
| p.getOutputStream().write(1); | ||
| p.getOutputStream().flush(); | ||
| } | ||
| break; | ||
| } | ||
| } else { | ||
| if (line.contains("[ready]")) { | ||
| p.getOutputStream().write(1); | ||
| p.getOutputStream().flush(); | ||
| case IGNORE: { | ||
| // ignore | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -60,16 +94,27 @@ protected final boolean launch(String target, List<String> jvmArgs, String comma | |
| } | ||
| }, "stdout-reader"); | ||
| Thread stderrReader = new Thread(() -> { | ||
| Function<String, Boolean> lineProcessor = onStderrLine != null ? onStderrLine : l -> true; | ||
| Function<String, LineConsumerResult> lineProcessor = onStderrLine != null ? onStderrLine : l -> LineConsumerResult.CONTINUE; | ||
| try (BufferedReader br = new BufferedReader(new InputStreamReader(p.getErrorStream()))) { | ||
| String line; | ||
| while ((line = br.readLine()) != null) { | ||
| System.out.println("[err] " + line); | ||
| if (!lineProcessor.apply(line)) { | ||
| try { | ||
| p.getOutputStream().write(1); | ||
| p.getOutputStream().flush(); | ||
| } catch (IOException ignored) { | ||
| LineConsumerResult lResult = lineProcessor.apply(line); | ||
| switch (lResult) { | ||
| case STOP: { | ||
| try { | ||
| p.getOutputStream().write(1); | ||
| p.getOutputStream().flush(); | ||
| } catch (IOException ignored) { | ||
| } | ||
| break; | ||
| } | ||
| case CONTINUE: { | ||
| break; | ||
| } | ||
| case IGNORE: { | ||
| // ignore | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -89,6 +134,6 @@ protected final boolean launch(String target, List<String> jvmArgs, String comma | |
| if (!val) { | ||
| p.destroyForcibly(); | ||
| } | ||
| return val; | ||
| return new LaunchResult(val, p.exitValue()); | ||
| } | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
simple but efficient 👍