34 * @run main BasicJStackTest |
36 * @run main BasicJStackTest |
35 */ |
37 */ |
36 public class BasicJStackTest { |
38 public class BasicJStackTest { |
37 |
39 |
38 private static ProcessBuilder processBuilder = new ProcessBuilder(); |
40 private static ProcessBuilder processBuilder = new ProcessBuilder(); |
39 private static String markerName = "markerName" + "\u00e4\u0bb5".repeat(10_000); |
|
40 |
41 |
41 public static void main(String[] args) throws Exception { |
42 public static void main(String[] args) throws Exception { |
42 testJstackNoArgs(); |
43 testJstackNoArgs(); |
43 testJstack_l(); |
44 testJstack_l(); |
|
45 testJstackUTF8Encoding(); |
44 } |
46 } |
45 |
47 |
46 private static void testJstackNoArgs() throws Exception { |
48 private static void testJstackNoArgs() throws Exception { |
47 OutputAnalyzer output = jstack(); |
49 String marker = "testJstackNoArgs"; |
|
50 OutputAnalyzer output = jstack(marker); |
48 output.shouldHaveExitValue(0); |
51 output.shouldHaveExitValue(0); |
49 output.shouldContain(markerName); |
52 output.shouldContain(marker); |
50 } |
53 } |
51 |
54 |
52 private static void testJstack_l() throws Exception { |
55 private static void testJstack_l() throws Exception { |
53 OutputAnalyzer output = jstack("-l"); |
56 String marker = "testJstack_l"; |
|
57 OutputAnalyzer output = jstack(marker, "-l"); |
54 output.shouldHaveExitValue(0); |
58 output.shouldHaveExitValue(0); |
55 output.shouldContain(markerName); |
59 output.shouldContain(marker); |
56 } |
60 } |
57 |
61 |
58 private static OutputAnalyzer jstack(String... toolArgs) throws Exception { |
62 private static void testJstackUTF8Encoding() throws Exception { |
59 Thread.currentThread().setName(markerName); |
63 String marker = "markerName" + "\u00e4\u0bb5".repeat(60); |
|
64 OutputAnalyzer output = jstack(marker); |
|
65 output.shouldHaveExitValue(0); |
|
66 output.shouldContain(marker); |
|
67 } |
|
68 |
|
69 private static OutputAnalyzer jstack(String marker, String... toolArgs) throws Exception { |
|
70 Charset cs = StandardCharsets.UTF_8; |
|
71 Thread.currentThread().setName(marker); |
60 JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jstack"); |
72 JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jstack"); |
61 launcher.addVMArg("-XX:+UsePerfData"); |
73 launcher.addVMArg("-XX:+UsePerfData"); |
|
74 launcher.addVMArg("-Dfile.encoding=" + cs); |
62 if (toolArgs != null) { |
75 if (toolArgs != null) { |
63 for (String toolArg : toolArgs) { |
76 for (String toolArg : toolArgs) { |
64 launcher.addToolArg(toolArg); |
77 launcher.addToolArg(toolArg); |
65 } |
78 } |
66 } |
79 } |
67 launcher.addToolArg(Long.toString(ProcessTools.getProcessId())); |
80 launcher.addToolArg(Long.toString(ProcessTools.getProcessId())); |
68 |
81 |
69 processBuilder.command(launcher.getCommand()); |
82 processBuilder.command(launcher.getCommand()); |
70 System.out.println(Arrays.toString(processBuilder.command().toArray()).replace(",", "")); |
83 System.out.println(Arrays.toString(processBuilder.command().toArray()).replace(",", "")); |
71 OutputAnalyzer output = ProcessTools.executeProcess(processBuilder); |
84 OutputAnalyzer output = ProcessTools.executeProcess(processBuilder, null, cs); |
72 System.out.println(output.getOutput()); |
85 System.out.println(output.getOutput()); |
73 |
86 |
74 return output; |
87 return output; |
75 } |
88 } |
76 |
89 |