|
1 | 1 | /*
|
2 |
| - * Copyright 2018 NAVER Corp. |
| 2 | + * Copyright 2024 NAVER Corp. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
17 | 17 |
|
18 | 18 | import com.navercorp.pinpoint.it.plugin.utils.AgentPath;
|
19 | 19 | import com.navercorp.pinpoint.it.plugin.utils.PluginITConstants;
|
20 |
| -import com.navercorp.pinpoint.it.plugin.utils.StdoutRecorder; |
21 | 20 | import com.navercorp.pinpoint.test.plugin.Dependency;
|
22 | 21 | import com.navercorp.pinpoint.test.plugin.ImportPlugin;
|
23 | 22 | import com.navercorp.pinpoint.test.plugin.JvmArgument;
|
24 | 23 | import com.navercorp.pinpoint.test.plugin.PinpointAgent;
|
25 | 24 | import com.navercorp.pinpoint.test.plugin.PinpointConfig;
|
26 | 25 | import com.navercorp.pinpoint.test.plugin.PluginForkedTest;
|
27 | 26 | import com.navercorp.pinpoint.test.plugin.TransformInclude;
|
28 |
| -import org.junit.jupiter.api.Assertions; |
29 | 27 | import org.junit.jupiter.api.Test;
|
30 |
| -import org.slf4j.Logger; |
31 |
| -import org.slf4j.LoggerFactory; |
32 |
| -import org.slf4j.MDC; |
33 | 28 |
|
34 | 29 | @PluginForkedTest
|
35 | 30 | @PinpointAgent(AgentPath.PATH)
|
|
38 | 33 | @PinpointConfig("pinpoint-spring-bean-test.config")
|
39 | 34 | @JvmArgument("-DtestLoggerEnable=false")
|
40 | 35 | @TransformInclude("org.slf4j.")
|
41 |
| -public class LogbackIT { |
| 36 | +public class LogbackIT extends LogbackTestBase { |
42 | 37 |
|
43 | 38 | @Test
|
44 | 39 | public void test() {
|
45 |
| - //Logger logger = LogManager.getLogger(getClass()); |
46 |
| - Logger logger = LoggerFactory.getLogger(this.getClass()); |
47 |
| - logger.error("maru"); |
48 |
| - |
49 |
| - checkVersion(logger); |
50 |
| - |
51 |
| - String ptxId = MDC.get("PtxId"); |
52 |
| - Assertions.assertNotNull(ptxId, "TxId"); |
53 |
| - Assertions.assertTrue(ptxId.contains("build.test.0^1"), "TxId value"); |
54 |
| - Assertions.assertNotNull(MDC.get("PspanId"), "spanId"); |
| 40 | + checkMDC(); |
55 | 41 | }
|
56 | 42 |
|
57 |
| - private Logger logger; |
58 |
| - |
59 | 43 | @Test
|
60 | 44 | public void patternUpdate() {
|
61 |
| - |
62 |
| - final String msg = "pattern"; |
63 |
| - StdoutRecorder stdoutRecorder = new StdoutRecorder(); |
64 |
| - |
65 |
| - String log = stdoutRecorder.record(new Runnable() { |
66 |
| - @Override |
67 |
| - public void run() { |
68 |
| - logger = LoggerFactory.getLogger("patternUpdateLogback"); |
69 |
| - logger.error(msg); |
70 |
| - } |
71 |
| - }); |
72 |
| - |
73 |
| - System.out.println(log); |
74 |
| - Assertions.assertNotNull(log, "log null"); |
75 |
| - Assertions.assertTrue(log.contains(msg), "contains msg"); |
76 |
| - Assertions.assertTrue(log.contains("TxId"), "contains TxId"); |
77 |
| - Assertions.assertTrue(log.contains("build.test.0^1"), "TxId value"); |
78 |
| - |
79 |
| - Assertions.assertNotNull(logger, "logger null"); |
80 |
| - checkVersion(logger); |
81 |
| - } |
82 |
| - |
83 |
| - private void checkVersion(Logger logger) { |
84 |
| - final String location = getLoggerJarLocation(logger); |
85 |
| - Assertions.assertNotNull(location, "location null"); |
86 |
| - System.out.println("Logback classic jar location:" + location); |
87 |
| - |
88 |
| - final String testVersion = getTestVersion(); |
89 |
| - Assertions.assertTrue(location.contains("/" + testVersion + "/"), "test version is not " + getTestVersion()); |
90 |
| - } |
91 |
| - |
92 |
| - private String getTestVersion() { |
93 |
| - final String[] threadInfo = Thread.currentThread().getName() |
94 |
| - .replace(getClass().getName(), "") |
95 |
| - .replace(" Thread", "") |
96 |
| - .replace(" ", "").replace("logback-classic-", "").split(":"); |
97 |
| - return threadInfo[0]; |
98 |
| - } |
99 |
| - |
100 |
| - private String getLoggerJarLocation(Object object) { |
101 |
| - return object.getClass().getProtectionDomain().getCodeSource().getLocation().toString(); |
| 45 | + checkPatternUpdate(); |
102 | 46 | }
|
103 | 47 |
|
104 | 48 | }
|
0 commit comments