Skip to content

Commit 72b4737

Browse files
committed
[#11290] log4j2-it, extract PatternTestBase
1 parent b5723bf commit 72b4737

File tree

3 files changed

+47
-45
lines changed

3 files changed

+47
-45
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2021 NAVER Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.navercorp.pinpoint.it.plugin.log4j2;
17+
18+
import com.navercorp.pinpoint.it.plugin.utils.AgentPath;
19+
import com.navercorp.pinpoint.it.plugin.utils.PluginITConstants;
20+
import com.navercorp.pinpoint.test.plugin.Dependency;
21+
import com.navercorp.pinpoint.test.plugin.JvmArgument;
22+
import com.navercorp.pinpoint.test.plugin.JvmVersion;
23+
import com.navercorp.pinpoint.test.plugin.PinpointAgent;
24+
import com.navercorp.pinpoint.test.plugin.PinpointConfig;
25+
import com.navercorp.pinpoint.test.plugin.PluginForkedTest;
26+
import org.junit.jupiter.api.Test;
27+
28+
@PluginForkedTest
29+
@PinpointAgent(AgentPath.PATH)
30+
@PinpointConfig("pinpoint-spring-bean-test.config")
31+
@JvmVersion(8)
32+
@Dependency({"org.apache.logging.log4j:log4j-core:[2.17.1,2.20)", PluginITConstants.VERSION})
33+
@JvmArgument("-DtestLoggerEnable=false")
34+
public class Log4J2PatternTestIT extends Log4j2PatternTestBase {
35+
36+
@Test
37+
public void patternUpdate() {
38+
checkPatternUpdate();
39+
}
40+
41+
}

agent-module/plugins-it/log4j2-it/src/test/java/com/navercorp/pinpoint/it/plugin/log4j2/Log4j2Pattern_2_20_IT.java agent-module/plugins-it/log4j2-it/src/test/java/com/navercorp/pinpoint/it/plugin/log4j2/Log4J2Pattern_2_20_ITTest.java

+2-26
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,12 @@
1717

1818
import com.navercorp.pinpoint.it.plugin.utils.AgentPath;
1919
import com.navercorp.pinpoint.it.plugin.utils.PluginITConstants;
20-
import com.navercorp.pinpoint.it.plugin.utils.StdoutRecorder;
2120
import com.navercorp.pinpoint.test.plugin.Dependency;
2221
import com.navercorp.pinpoint.test.plugin.JvmArgument;
2322
import com.navercorp.pinpoint.test.plugin.JvmVersion;
2423
import com.navercorp.pinpoint.test.plugin.PinpointAgent;
2524
import com.navercorp.pinpoint.test.plugin.PinpointConfig;
2625
import com.navercorp.pinpoint.test.plugin.PluginForkedTest;
27-
import org.apache.logging.log4j.LogManager;
28-
import org.apache.logging.log4j.Logger;
29-
import org.junit.jupiter.api.Assertions;
3026
import org.junit.jupiter.api.Test;
3127

3228
@PluginForkedTest
@@ -35,32 +31,12 @@
3531
@JvmVersion(11)
3632
@Dependency({"org.apache.logging.log4j:log4j-core:[2.20,2.22]", PluginITConstants.VERSION})
3733
@JvmArgument("-DtestLoggerEnable=false")
38-
public class Log4j2Pattern_2_20_IT extends Log4j2TestBase {
34+
public class Log4J2Pattern_2_20_ITTest extends Log4j2PatternTestBase {
3935

4036
private String location;
4137
@Test
4238
public void patternUpdate() {
43-
final String msg = "pattern";
44-
45-
StdoutRecorder stdoutRecorder = new StdoutRecorder();
46-
String log = stdoutRecorder.record(new Runnable() {
47-
@Override
48-
public void run() {
49-
Logger logger = LogManager.getLogger("patternUpdateLog4j2Jvm7");
50-
logger.error(msg);
51-
location = getLoggerJarLocation(logger);
52-
}
53-
});
54-
55-
System.out.println(log);
56-
Assertions.assertNotNull(log, "log null");
57-
Assertions.assertTrue(log.contains(msg), "contains msg");
58-
Assertions.assertTrue(log.contains("TxId"), "contains TxId");
59-
60-
Assertions.assertNotNull(location, "location null");
61-
System.out.println("Log4j2 jar location:" + location);
62-
final String testVersion = getTestVersion();
63-
Assertions.assertTrue(location.contains("/" + testVersion + "/"), "test version is not " + getTestVersion());
39+
checkPatternUpdate();
6440
}
6541

6642
}

agent-module/plugins-it/log4j2-it/src/test/java/com/navercorp/pinpoint/it/plugin/log4j2/Log4j2PatternIT.java agent-module/plugins-it/log4j2-it/src/test/java/com/navercorp/pinpoint/it/plugin/log4j2/Log4j2PatternTestBase.java

+4-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021 NAVER Corp.
2+
* Copyright 2024 NAVER Corp.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,31 +15,16 @@
1515
*/
1616
package com.navercorp.pinpoint.it.plugin.log4j2;
1717

18-
import com.navercorp.pinpoint.it.plugin.utils.AgentPath;
19-
import com.navercorp.pinpoint.it.plugin.utils.PluginITConstants;
2018
import com.navercorp.pinpoint.it.plugin.utils.StdoutRecorder;
21-
import com.navercorp.pinpoint.test.plugin.Dependency;
22-
import com.navercorp.pinpoint.test.plugin.JvmArgument;
23-
import com.navercorp.pinpoint.test.plugin.JvmVersion;
24-
import com.navercorp.pinpoint.test.plugin.PinpointAgent;
25-
import com.navercorp.pinpoint.test.plugin.PinpointConfig;
26-
import com.navercorp.pinpoint.test.plugin.PluginForkedTest;
2719
import org.apache.logging.log4j.LogManager;
2820
import org.apache.logging.log4j.Logger;
2921
import org.junit.jupiter.api.Assertions;
30-
import org.junit.jupiter.api.Test;
3122

32-
@PluginForkedTest
33-
@PinpointAgent(AgentPath.PATH)
34-
@PinpointConfig("pinpoint-spring-bean-test.config")
35-
@JvmVersion(8)
36-
@Dependency({"org.apache.logging.log4j:log4j-core:[2.17.1,2.20)", PluginITConstants.VERSION})
37-
@JvmArgument("-DtestLoggerEnable=false")
38-
public class Log4j2PatternIT extends Log4j2TestBase {
23+
public class Log4j2PatternTestBase extends Log4j2TestBase {
3924

4025
private String location;
41-
@Test
42-
public void patternUpdate() {
26+
27+
public void checkPatternUpdate() {
4328
final String msg = "pattern";
4429

4530
StdoutRecorder stdoutRecorder = new StdoutRecorder();

0 commit comments

Comments
 (0)