Add api/conf test case.
This commit is contained in:
parent
6deb4bb837
commit
99024b3d0f
|
|
@ -26,8 +26,8 @@ import static net.bytebuddy.matcher.ElementMatchers.isInterface;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.not;
|
||||
|
||||
/**
|
||||
* The main entrance of sky-waking agent.
|
||||
* It bases on javaagent mechanism.
|
||||
* The main entrance of sky-waking agent,
|
||||
* based on javaagent mechanism.
|
||||
*
|
||||
* @author wusheng
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -7,5 +7,5 @@ public class Constants {
|
|||
* This is the version, which will be the first segment of traceid.
|
||||
* Ref {@link TraceIdGenerator#generate()}
|
||||
*/
|
||||
public static String SDK_VERSION = "302017";
|
||||
public final static String SDK_VERSION = "302017";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import java.io.InputStream;
|
|||
import java.util.Properties;
|
||||
|
||||
public class SnifferConfigInitializer {
|
||||
private static ILog logger = LogManager.getLogger(SnifferConfigInitializer.class);
|
||||
private static ILog logger = LogManager.getLogger(SnifferConfigInitializer.class);
|
||||
|
||||
public static void initialize() {
|
||||
InputStream configFileStream;
|
||||
|
|
@ -32,24 +32,34 @@ public class SnifferConfigInitializer {
|
|||
logger.error("Failed to read the config file, sky-walking api run in default config.", e);
|
||||
}
|
||||
}
|
||||
Config.SkyWalking.USERNAME = System.getProperty("username");
|
||||
Config.SkyWalking.APPLICATION_CODE = System.getProperty("applicationCode");
|
||||
Config.SkyWalking.SERVERS = System.getProperty("servers");
|
||||
|
||||
if(StringUtil.isEmpty(Config.SkyWalking.USERNAME)){
|
||||
String username = System.getProperty("username");
|
||||
if (!StringUtil.isEmpty(username)) {
|
||||
Config.SkyWalking.USERNAME = username;
|
||||
}
|
||||
String applicationCode = System.getProperty("applicationCode");
|
||||
if (!StringUtil.isEmpty(applicationCode)) {
|
||||
Config.SkyWalking.APPLICATION_CODE = applicationCode;
|
||||
}
|
||||
String servers = System.getProperty("servers");
|
||||
if(!StringUtil.isEmpty(servers)) {
|
||||
Config.SkyWalking.SERVERS = servers;
|
||||
}
|
||||
|
||||
if (StringUtil.isEmpty(Config.SkyWalking.USERNAME)) {
|
||||
throw new ExceptionInInitializerError("'-Dusername=' is missing.");
|
||||
}
|
||||
if(StringUtil.isEmpty(Config.SkyWalking.APPLICATION_CODE)){
|
||||
if (StringUtil.isEmpty(Config.SkyWalking.APPLICATION_CODE)) {
|
||||
throw new ExceptionInInitializerError("'-DapplicationCode=' is missing.");
|
||||
}
|
||||
if(StringUtil.isEmpty(Config.SkyWalking.SERVERS)){
|
||||
if (StringUtil.isEmpty(Config.SkyWalking.SERVERS)) {
|
||||
throw new ExceptionInInitializerError("'-Dservers=' is missing.");
|
||||
}
|
||||
}
|
||||
|
||||
private static InputStream fetchAuthFileInputStream() {
|
||||
try {
|
||||
return new FileInputStream(Config.SkyWalking.AGENT_BASE_PATH + File.separator + "/sky-walking.config");
|
||||
return new FileInputStream(Config.SkyWalking.AGENT_BASE_PATH + File.separator + "sky-walking.config");
|
||||
} catch (Exception e) {
|
||||
logger.warn("sky-walking.config is missing, use default config.");
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
package com.a.eye.skywalking.api.conf;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2017/2/28.
|
||||
*/
|
||||
public class ConstantsTest {
|
||||
@Test
|
||||
public void testSDKVersion(){
|
||||
Assert.assertEquals("302017", Constants.SDK_VERSION);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
package com.a.eye.skywalking.api.conf;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author wusheng
|
||||
*/
|
||||
public class SnifferConfigInitializerTest {
|
||||
|
||||
@Test
|
||||
public void testInitialize(){
|
||||
Config.SkyWalking.IS_PREMAIN_MODE = false;
|
||||
SnifferConfigInitializer.initialize();
|
||||
|
||||
Assert.assertEquals("testUser", Config.SkyWalking.USERNAME);
|
||||
Assert.assertEquals("crmApp", Config.SkyWalking.APPLICATION_CODE);
|
||||
Assert.assertEquals("127.0.0.1:8080", Config.SkyWalking.SERVERS);
|
||||
|
||||
Assert.assertNotNull(Config.Disruptor.BUFFER_SIZE);
|
||||
Assert.assertNotNull(Config.Logging.LOG_DIR_NAME);
|
||||
Assert.assertNotNull(Config.Logging.LOG_FILE_NAME);
|
||||
Assert.assertNotNull(Config.Logging.MAX_LOG_FILE_LENGTH);
|
||||
Assert.assertNotNull(Config.Logging.SYSTEM_ERROR_LOG_FILE_NAME);
|
||||
}
|
||||
|
||||
@Test(expected = ExceptionInInitializerError.class)
|
||||
public void testErrorInitialize(){
|
||||
Config.SkyWalking.IS_PREMAIN_MODE = true;
|
||||
SnifferConfigInitializer.initialize();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void reset(){
|
||||
Config.SkyWalking.IS_PREMAIN_MODE = false;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
skywalking.username = testUser
|
||||
skywalking.application_code = crmApp
|
||||
skywalking.servers = 127.0.0.1:8080
|
||||
Loading…
Reference in New Issue