Fix logger-plugin module directory structure problem(Maven cannot trigger junit testing). (#5987)

This commit is contained in:
zifeihan 2020-12-11 15:58:06 +08:00 committed by GitHub
parent 6cb0cf67ef
commit a57c158c77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 15 deletions

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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();