From 860feae6894eec5e147b0955dc1163f6d4ec69f1 Mon Sep 17 00:00:00 2001 From: King John Date: Fri, 26 Jul 2024 16:38:21 +0800 Subject: [PATCH] [#11290] logback-it, add test for full-pattern replacement --- .../logback/LogbackPatternFullReplaceIT.java | 44 +++++++++++++++++++ .../it/plugin/logback/LogbackTestBase.java | 3 +- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 agent-module/plugins-it/logback-it/src/test/java/com/navercorp/pinpoint/it/plugin/logback/LogbackPatternFullReplaceIT.java diff --git a/agent-module/plugins-it/logback-it/src/test/java/com/navercorp/pinpoint/it/plugin/logback/LogbackPatternFullReplaceIT.java b/agent-module/plugins-it/logback-it/src/test/java/com/navercorp/pinpoint/it/plugin/logback/LogbackPatternFullReplaceIT.java new file mode 100644 index 000000000000..fc073288e0ef --- /dev/null +++ b/agent-module/plugins-it/logback-it/src/test/java/com/navercorp/pinpoint/it/plugin/logback/LogbackPatternFullReplaceIT.java @@ -0,0 +1,44 @@ +/* + * Copyright 2024 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.navercorp.pinpoint.it.plugin.logback; + +import com.navercorp.pinpoint.it.plugin.utils.AgentPath; +import com.navercorp.pinpoint.it.plugin.utils.PluginITConstants; +import com.navercorp.pinpoint.test.plugin.*; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +@PluginForkedTest +@PinpointAgent(AgentPath.PATH) +@Dependency({"ch.qos.logback:logback-classic:[1.0.13],[1.1.0,1.1.11],[1.2.0,1.2.6]", "org.slf4j:slf4j-api:1.7.12", PluginITConstants.VERSION}) +@ImportPlugin({"com.navercorp.pinpoint:pinpoint-logback-plugin"}) +@PinpointConfig("pinpoint-spring-bean-test.config") +@JvmArgument({"-DtestLoggerEnable=false", "-Dprofiler.logback.logging.pattern.full_replace.with=%d{yyyy-MM-dd HH:mm:ss} [%p] [%t] %c [TxId:%X{PtxId} ReqId:%X{PreqId}] -LogbackIT- %m%n"}) +@TransformInclude("org.slf4j.") +public class LogbackPatternFullReplaceIT extends LogbackTestBase { + + @Test + public void test() { + checkMDC(); + } + + @Test + public void patternUpdate() { + String log = checkPatternUpdate(); + Assertions.assertTrue(log.contains("-LogbackIT-"), "contains full-replace string LogbackIT"); + } + +} diff --git a/agent-module/plugins-it/logback-it/src/test/java/com/navercorp/pinpoint/it/plugin/logback/LogbackTestBase.java b/agent-module/plugins-it/logback-it/src/test/java/com/navercorp/pinpoint/it/plugin/logback/LogbackTestBase.java index 49487e812444..c29d7dfd76a7 100644 --- a/agent-module/plugins-it/logback-it/src/test/java/com/navercorp/pinpoint/it/plugin/logback/LogbackTestBase.java +++ b/agent-module/plugins-it/logback-it/src/test/java/com/navercorp/pinpoint/it/plugin/logback/LogbackTestBase.java @@ -37,7 +37,7 @@ protected void checkMDC() { private Logger logger; - protected void checkPatternUpdate() { + protected String checkPatternUpdate() { final String msg = "pattern"; StdoutRecorder stdoutRecorder = new StdoutRecorder(); @@ -58,6 +58,7 @@ public void run() { Assertions.assertNotNull(logger, "logger null"); checkVersion(logger); + return log; } private void checkVersion(Logger logger) {