Linchen-Xu commented on code in PR #13358:
URL: https://github.com/apache/dubbo/pull/13358#discussion_r1395219622


##########
dubbo-common/src/test/java/org/apache/dubbo/common/utils/JVMUtilTest.java:
##########
@@ -16,4 +16,168 @@
  */
 package org.apache.dubbo.common.utils;
 
-class JVMUtilTest {}
+import org.apache.dubbo.common.constants.CommonConstants;
+import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
+import org.apache.dubbo.common.logger.LoggerFactory;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.lang.management.LockInfo;
+import java.lang.management.MonitorInfo;
+import java.lang.management.ThreadInfo;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import static java.lang.Thread.State.BLOCKED;
+import static java.lang.Thread.State.TIMED_WAITING;
+import static java.lang.Thread.State.WAITING;
+import static 
org.apache.dubbo.common.constants.CommonConstants.DUBBO_JSTACK_MAXLINE;
+
+class JVMUtilTest {
+
+    protected static final ErrorTypeAwareLogger logger = 
LoggerFactory.getErrorTypeAwareLogger(JVMUtilTest.class);
+
+    @Test
+    void testPrintStackTraceWithSpecifiedDepth() {
+        test(10);
+    }
+
+    @Test
+    void testPrintStackTraceWithUnlimitedDepth() {
+        test(-1);
+    }
+
+    private void test(Integer depth) {
+        // read the old property, then set new property
+        String oldProperty = System.getProperty(DUBBO_JSTACK_MAXLINE);
+        System.setProperty(DUBBO_JSTACK_MAXLINE, depth.toString());
+
+        try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
+            // dump all thread info, then compare the output
+            ThreadInfo[] threadInfos = JVMUtil.dumpAllThreads();
+            // generate new stack trace info
+            JVMUtil.jstack(stream, threadInfos);
+            String newStackTrace = stream.toString();
+            // generate old stack trace info
+            String oldStackTrace = OldJVMUtil.jstack(threadInfos);
+            // calculate stack trace depth
+            int newStackDepth = calculateStackDepth(newStackTrace);
+            int oldStackDepth = calculateStackDepth(oldStackTrace);
+

Review Comment:
   Added stack dump test code in `AbortPolicyWithReportTest.jStackDumpTest` to 
ensure that the new code is working as expected, but have to check the output 
file under /tmp.
   
   The output file after running `AbortPolicyWithReportTest.jStackDumpTest` 
when setting `dubbo.jstack-dump.max-line=-1`:
   
![1](https://github.com/apache/dubbo/assets/22527265/57940f8b-ebc3-4ce3-9a81-c9a37cd5488a)
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to