Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
LinShunKang
committed
Oct 28, 2018
1 parent
e03ed93
commit 0575e44
Showing
11 changed files
with
187 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
MyPerf4J-Base/src/test/java/cn/myperf4j/base/test/BaseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package cn.myperf4j.base.test; | ||
|
||
import cn.myperf4j.base.config.MyProperties; | ||
import cn.myperf4j.base.constant.PropertyKeys; | ||
import cn.myperf4j.base.constant.PropertyValues; | ||
import cn.myperf4j.base.util.IOUtils; | ||
import cn.myperf4j.base.util.Logger; | ||
import cn.myperf4j.base.util.file.AutoRollingFileWriter; | ||
import cn.myperf4j.base.util.file.MinutelyRollingFileWriter; | ||
import org.junit.BeforeClass; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Properties; | ||
|
||
/** | ||
* Created by LinShunkang on 2018/10/28 | ||
*/ | ||
public abstract class BaseTest { | ||
|
||
public static final String TEMP_FILE = "/tmp/MyPerf4J.properties"; | ||
|
||
public static final String APP_NAME = "MyPerf4JBaseTest"; | ||
|
||
public static final int METRICS_PROCESSOR_TYPE = 1; | ||
|
||
public static final String INCLUDE_PACKAGES = "MyPerf4J"; | ||
|
||
public static final int MILLI_TIMES_LICE = 1000; | ||
|
||
@BeforeClass | ||
public static void init() { | ||
System.setProperty(PropertyKeys.PRO_FILE_NAME, TEMP_FILE); | ||
AutoRollingFileWriter writer = new MinutelyRollingFileWriter(TEMP_FILE); | ||
writer.write("AppName=" + APP_NAME + "\n"); | ||
writer.write("MetricsProcessorType=" + METRICS_PROCESSOR_TYPE + "\n"); | ||
writer.write("IncludePackages=" + INCLUDE_PACKAGES + "\n"); | ||
writer.write("MilliTimeSlice=" + MILLI_TIMES_LICE + "\n"); | ||
writer.closeFile(true); | ||
|
||
new File(TEMP_FILE).deleteOnExit(); | ||
|
||
initProperties(); | ||
} | ||
|
||
private static void initProperties() { | ||
InputStream in = null; | ||
try { | ||
in = new FileInputStream(System.getProperty(PropertyKeys.PRO_FILE_NAME, PropertyValues.DEFAULT_PRO_FILE)); | ||
|
||
Properties properties = new Properties(); | ||
properties.load(in); | ||
MyProperties.initial(properties); | ||
} catch (IOException e) { | ||
Logger.error("BaseTest.initProperties()", e); | ||
} finally { | ||
IOUtils.closeQuietly(in); | ||
} | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
MyPerf4J-Base/src/test/java/cn/myperf4j/base/test/DateUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package cn.myperf4j.base.test; | ||
|
||
import cn.myperf4j.base.util.DateUtils; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.util.Calendar; | ||
import java.util.Date; | ||
|
||
/** | ||
* Created by LinShunkang on 2018/10/28 | ||
*/ | ||
public class DateUtilsTest { | ||
|
||
@Test | ||
public void test() { | ||
Assert.assertTrue(DateUtils.isSameMinute(new Date(), new Date())); | ||
Assert.assertTrue(DateUtils.isSameHour(new Date(), new Date())); | ||
Assert.assertTrue(DateUtils.isSameDay(new Date(), new Date())); | ||
|
||
Calendar calendar1 = Calendar.getInstance(); | ||
calendar1.add(Calendar.MINUTE, 1); | ||
Assert.assertFalse(DateUtils.isSameMinute(new Date(), calendar1.getTime())); | ||
|
||
calendar1.add(Calendar.HOUR_OF_DAY, 1); | ||
Assert.assertFalse(DateUtils.isSameHour(new Date(), calendar1.getTime())); | ||
|
||
calendar1.add(Calendar.DATE, 1); | ||
Assert.assertFalse(DateUtils.isSameDay(new Date(), calendar1.getTime())); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
MyPerf4J-Base/src/test/java/cn/myperf4j/base/test/MyPropertiesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package cn.myperf4j.base.test; | ||
|
||
import cn.myperf4j.base.config.MyProperties; | ||
import cn.myperf4j.base.constant.PropertyKeys; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Created by LinShunkang on 2018/10/28 | ||
*/ | ||
public class MyPropertiesTest extends BaseTest { | ||
|
||
@Test | ||
public void test() { | ||
Assert.assertEquals(MyProperties.getStr(PropertyKeys.PRO_FILE_NAME), BaseTest.TEMP_FILE); | ||
Assert.assertEquals(MyProperties.getStr(PropertyKeys.APP_NAME), BaseTest.APP_NAME); | ||
Assert.assertEquals(MyProperties.getInt(PropertyKeys.METRICS_PROCESS_TYPE, -1), BaseTest.METRICS_PROCESSOR_TYPE); | ||
Assert.assertEquals(MyProperties.getStr(PropertyKeys.FILTER_INCLUDE_PACKAGES), BaseTest.INCLUDE_PACKAGES); | ||
Assert.assertEquals(MyProperties.getInt(PropertyKeys.MILLI_TIME_SLICE, -1), BaseTest.MILLI_TIMES_LICE); | ||
|
||
|
||
MyProperties.setStr("key", "value"); | ||
Assert.assertEquals(MyProperties.getStr("key"), "value"); | ||
Assert.assertTrue(MyProperties.isSame("key", "value")); | ||
|
||
MyProperties.setStr("long", "1000"); | ||
Assert.assertEquals(MyProperties.getLong("long", 1), 1000); | ||
Assert.assertEquals(MyProperties.getLong("long", 1, 10000), 10000); | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
MyPerf4J-Base/src/test/java/cn/myperf4j/base/test/ProfilingFilterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package cn.myperf4j.base.test; | ||
|
||
import cn.myperf4j.base.config.ProfilingFilter; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Created by LinShunkang on 2018/10/28 | ||
*/ | ||
public class ProfilingFilterTest { | ||
|
||
@Before | ||
public void init() { | ||
ProfilingFilter.addIncludePackage("org.junit"); | ||
ProfilingFilter.addExcludePackage("org.junit.rules"); | ||
ProfilingFilter.addExcludeMethods("hello"); | ||
ProfilingFilter.addExcludeClassLoader("org.apache.catalina.loader.WebappClassLoader"); | ||
} | ||
|
||
@Test | ||
public void test() { | ||
Assert.assertFalse(ProfilingFilter.isNeedInject("org.junit.Before")); | ||
Assert.assertTrue(ProfilingFilter.isNeedInject("org/junit/Before")); | ||
Assert.assertTrue(ProfilingFilter.isNotNeedInject("org/junit/rules/ErrorCollector")); | ||
|
||
Assert.assertTrue(ProfilingFilter.isNotNeedInjectMethod("toString")); | ||
Assert.assertTrue(ProfilingFilter.isNotNeedInjectMethod("hello")); | ||
Assert.assertFalse(ProfilingFilter.isNotNeedInjectMethod("assertFalse")); | ||
|
||
Assert.assertTrue(ProfilingFilter.isNotNeedInjectClassLoader("org.apache.catalina.loader.WebappClassLoader")); | ||
Assert.assertFalse(ProfilingFilter.isNotNeedInjectClassLoader("org.springframework.boot.loader.LaunchedURLClassLoader")); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
MyPerf4J-Base/src/test/java/cn/myperf4j/base/test/ProfilingParamsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package cn.myperf4j.base.test; | ||
|
||
import cn.myperf4j.base.config.ProfilingParams; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Created by LinShunkang on 2018/10/28 | ||
*/ | ||
public class ProfilingParamsTest { | ||
|
||
@Test | ||
public void test() { | ||
ProfilingParams params = ProfilingParams.of(1000, 10); | ||
Assert.assertEquals(params.getMostTimeThreshold(), 1000); | ||
Assert.assertNotEquals(params.getMostTimeThreshold(), -1000); | ||
|
||
Assert.assertEquals(params.getOutThresholdCount(), 10); | ||
Assert.assertNotEquals(params.getOutThresholdCount(), -10); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters