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


##########
dubbo-common/src/test/java/org/apache/dubbo/common/utils/JVMUtilTest.java:
##########
@@ -16,4 +16,60 @@
  */
 package org.apache.dubbo.common.utils;
 
-class JVMUtilTest {}
+import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
+import org.apache.dubbo.common.logger.LoggerFactory;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.junit.jupiter.api.Test;
+
+import static 
org.apache.dubbo.common.constants.CommonConstants.DUBBO_JSTACK_MAXLINE;
+import static org.apache.dubbo.common.constants.CommonConstants.OS_NAME_KEY;
+import static org.apache.dubbo.common.constants.CommonConstants.OS_WIN_PREFIX;
+import static 
org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_UNEXPECTED_CREATE_DUMP;
+import static org.apache.dubbo.common.utils.JVMUtil.jstack;
+
+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) {
+        SimpleDateFormat sdf;
+        String os = System.getProperty(OS_NAME_KEY).toLowerCase();
+        // window system don't support ":" in file name
+        if (os.contains(OS_WIN_PREFIX)) {
+            sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss .SSS");
+        } else {
+            sdf = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss .SSS");
+        }
+        String dateStr = sdf.format(new Date());
+
+        String property = System.getProperty(DUBBO_JSTACK_MAXLINE);
+        System.setProperty(DUBBO_JSTACK_MAXLINE, depth.toString());
+        try (FileOutputStream jStackStream =
+                new FileOutputStream(new File("/tmp", "Dubbo_JStack.log" + "." 
+ dateStr))) {
+            jstack(jStackStream);

Review Comment:
   Added the comparison between the depth printed by the old logic and the new 
logic. PTAL.
   When it traces back to JVMUtil, the line number will be different, making 
purely comparing two outputs impractical, unless we ignore some lines in the 
output.



-- 
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