From a57c158c7724f1fbe2537c230c40a2517d9a0dd5 Mon Sep 17 00:00:00 2001 From: zifeihan Date: Fri, 11 Dec 2020 15:58:06 +0800 Subject: [PATCH] Fix logger-plugin module directory structure problem(Maven cannot trigger junit testing). (#5987) --- .../apm/plugin/logger/ContextConfig.java | 8 ++++++++ .../plugin/logger/ContextConfigDefaultTest.java | 3 ++- .../plugin/logger/ContextConfigExceptionTest.java | 15 +++++++++------ .../apm/plugin/logger/ContextConfigTest.java | 15 +++++++-------- 4 files changed, 26 insertions(+), 15 deletions(-) rename apm-sniffer/optional-plugins/logger-plugin/src/test/{ => java}/org/apache/skywalking/apm/plugin/logger/ContextConfigDefaultTest.java (96%) rename apm-sniffer/optional-plugins/logger-plugin/src/test/{ => java}/org/apache/skywalking/apm/plugin/logger/ContextConfigExceptionTest.java (93%) rename apm-sniffer/optional-plugins/logger-plugin/src/test/{ => java}/org/apache/skywalking/apm/plugin/logger/ContextConfigTest.java (97%) diff --git a/apm-sniffer/optional-plugins/logger-plugin/src/main/java/org/apache/skywalking/apm/plugin/logger/ContextConfig.java b/apm-sniffer/optional-plugins/logger-plugin/src/main/java/org/apache/skywalking/apm/plugin/logger/ContextConfig.java index 7213590c3..5725ee644 100644 --- a/apm-sniffer/optional-plugins/logger-plugin/src/main/java/org/apache/skywalking/apm/plugin/logger/ContextConfig.java +++ b/apm-sniffer/optional-plugins/logger-plugin/src/main/java/org/apache/skywalking/apm/plugin/logger/ContextConfig.java @@ -58,6 +58,14 @@ public class ContextConfig { return HolderContextConfig.INSTANCE; } + /** + * For testing use only. + * Avoid to use config cache. Load the configuration every time. + */ + static ContextConfig getLatestConfig() { + return HolderContextConfig.initContextConfig(); + } + //use singleton private static class HolderContextConfig { private final static ContextConfig INSTANCE = initContextConfig(); diff --git a/apm-sniffer/optional-plugins/logger-plugin/src/test/org/apache/skywalking/apm/plugin/logger/ContextConfigDefaultTest.java b/apm-sniffer/optional-plugins/logger-plugin/src/test/java/org/apache/skywalking/apm/plugin/logger/ContextConfigDefaultTest.java similarity index 96% rename from apm-sniffer/optional-plugins/logger-plugin/src/test/org/apache/skywalking/apm/plugin/logger/ContextConfigDefaultTest.java rename to apm-sniffer/optional-plugins/logger-plugin/src/test/java/org/apache/skywalking/apm/plugin/logger/ContextConfigDefaultTest.java index dbdd27f94..64f9f33b8 100644 --- a/apm-sniffer/optional-plugins/logger-plugin/src/test/org/apache/skywalking/apm/plugin/logger/ContextConfigDefaultTest.java +++ b/apm-sniffer/optional-plugins/logger-plugin/src/test/java/org/apache/skywalking/apm/plugin/logger/ContextConfigDefaultTest.java @@ -15,6 +15,7 @@ * limitations under the License. * */ + package org.apache.skywalking.apm.plugin.logger; import org.junit.Test; @@ -24,7 +25,7 @@ import static org.junit.Assert.assertEquals; public class ContextConfigDefaultTest { @Test public void testDefaultConfig() { - ContextConfig config = ContextConfig.getInstance(); + ContextConfig config = ContextConfig.getLatestConfig(); ContextConfig.LoggerConfig log4jConfig = config.getLog4jConfig(); ContextConfig.LoggerConfig log4j2Config = config.getLog4j2Config(); ContextConfig.LoggerConfig logbackConfig = config.getLogbackConfig(); diff --git a/apm-sniffer/optional-plugins/logger-plugin/src/test/org/apache/skywalking/apm/plugin/logger/ContextConfigExceptionTest.java b/apm-sniffer/optional-plugins/logger-plugin/src/test/java/org/apache/skywalking/apm/plugin/logger/ContextConfigExceptionTest.java similarity index 93% rename from apm-sniffer/optional-plugins/logger-plugin/src/test/org/apache/skywalking/apm/plugin/logger/ContextConfigExceptionTest.java rename to apm-sniffer/optional-plugins/logger-plugin/src/test/java/org/apache/skywalking/apm/plugin/logger/ContextConfigExceptionTest.java index 2b9f5791a..779dc3046 100644 --- a/apm-sniffer/optional-plugins/logger-plugin/src/test/org/apache/skywalking/apm/plugin/logger/ContextConfigExceptionTest.java +++ b/apm-sniffer/optional-plugins/logger-plugin/src/test/java/org/apache/skywalking/apm/plugin/logger/ContextConfigExceptionTest.java @@ -15,20 +15,21 @@ * limitations under the License. * */ -package org.apache.skywalking.apm.plugin.logger; -import org.apache.skywalking.apm.agent.core.boot.AgentPackageNotFoundException; -import org.apache.skywalking.apm.agent.core.boot.AgentPackagePath; -import org.junit.*; +package org.apache.skywalking.apm.plugin.logger; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.Properties; +import org.apache.skywalking.apm.agent.core.boot.AgentPackageNotFoundException; +import org.apache.skywalking.apm.agent.core.boot.AgentPackagePath; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import static org.junit.Assert.assertEquals; - public class ContextConfigExceptionTest { @Before public void setup() throws AgentPackageNotFoundException, IOException { @@ -52,6 +53,8 @@ public class ContextConfigExceptionTest { properties.setProperty("logback.packages", "package1,package2"); properties.setProperty("log4j.level", "debug"); properties.setProperty("log4j.packages", "*"); + properties.setProperty("log4j2.level", "error"); + properties.setProperty("log4j.packages", "*"); FileWriter writer = new FileWriter(configFilePath); properties.store(writer, "set fatal level for logback"); writer.flush(); @@ -61,7 +64,7 @@ public class ContextConfigExceptionTest { @Test public void testHasConfigError() { - ContextConfig config = ContextConfig.getInstance(); + ContextConfig config = ContextConfig.getLatestConfig(); ContextConfig.LoggerConfig logbackConfig = config.getLogbackConfig(); ContextConfig.LoggerConfig log4jConfig = config.getLog4jConfig(); ContextConfig.LoggerConfig log4j2Config = config.getLog4j2Config(); diff --git a/apm-sniffer/optional-plugins/logger-plugin/src/test/org/apache/skywalking/apm/plugin/logger/ContextConfigTest.java b/apm-sniffer/optional-plugins/logger-plugin/src/test/java/org/apache/skywalking/apm/plugin/logger/ContextConfigTest.java similarity index 97% rename from apm-sniffer/optional-plugins/logger-plugin/src/test/org/apache/skywalking/apm/plugin/logger/ContextConfigTest.java rename to apm-sniffer/optional-plugins/logger-plugin/src/test/java/org/apache/skywalking/apm/plugin/logger/ContextConfigTest.java index 895c75f25..d24b274d6 100644 --- a/apm-sniffer/optional-plugins/logger-plugin/src/test/org/apache/skywalking/apm/plugin/logger/ContextConfigTest.java +++ b/apm-sniffer/optional-plugins/logger-plugin/src/test/java/org/apache/skywalking/apm/plugin/logger/ContextConfigTest.java @@ -15,19 +15,18 @@ * limitations under the License. * */ -package org.apache.skywalking.apm.plugin.logger; -import org.apache.skywalking.apm.agent.core.boot.AgentPackageNotFoundException; -import org.apache.skywalking.apm.agent.core.boot.AgentPackagePath; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +package org.apache.skywalking.apm.plugin.logger; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.Properties; +import org.apache.skywalking.apm.agent.core.boot.AgentPackageNotFoundException; +import org.apache.skywalking.apm.agent.core.boot.AgentPackagePath; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -64,7 +63,7 @@ public class ContextConfigTest { @Test public void testTwoLogger() { // test - ContextConfig config = ContextConfig.getInstance(); + ContextConfig config = ContextConfig.getLatestConfig(); ContextConfig.LoggerConfig logbackConfig = config.getLogbackConfig(); ContextConfig.LoggerConfig log4jConfig = config.getLog4jConfig(); ContextConfig.LoggerConfig log4j2Config = config.getLog4j2Config();