-
Notifications
You must be signed in to change notification settings - Fork 8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the default statistic max RT value
TIME_DROP_VALVE
configurable (
- Loading branch information
Showing
5 changed files
with
127 additions
and
26 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
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
25 changes: 25 additions & 0 deletions
25
sentinel-core/src/test/java/com/alibaba/csp/sentinel/ConstantsTest.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,25 @@ | ||
package com.alibaba.csp.sentinel; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
/** | ||
* Test cases for {@link Constants}. | ||
* | ||
* @author cdfive | ||
*/ | ||
public class ConstantsTest { | ||
|
||
@Test | ||
public void testDefaultTimeDropValue() { | ||
assertEquals(4900, Constants.TIME_DROP_VALVE); | ||
} | ||
|
||
// add JVM parameter | ||
// -Dcsp.sentinel.statistic.max.rt=10000 | ||
// @Test | ||
public void testCustomTimeDropValue() { | ||
assertEquals(10000, Constants.TIME_DROP_VALVE); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
sentinel-core/src/test/java/com/alibaba/csp/sentinel/config/SentinelConfigTest.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,61 @@ | ||
package com.alibaba.csp.sentinel.config; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
/** | ||
* Test cases for {@link SentinelConfig}. | ||
* | ||
* @author cdfive | ||
*/ | ||
public class SentinelConfigTest { | ||
|
||
@Test | ||
public void testDefaultConfig() { | ||
assertEquals(SentinelConfig.DEFAULT_CHARSET, SentinelConfig.charset()); | ||
assertEquals(SentinelConfig.DEFAULT_SINGLE_METRIC_FILE_SIZE, SentinelConfig.singleMetricFileSize()); | ||
assertEquals(SentinelConfig.DEFAULT_TOTAL_METRIC_FILE_COUNT, SentinelConfig.totalMetricFileCount()); | ||
assertEquals(SentinelConfig.DEFAULT_COLD_FACTOR, SentinelConfig.coldFactor()); | ||
assertEquals(SentinelConfig.DEFAULT_STATISTIC_MAX_RT, SentinelConfig.statisticMaxRt()); | ||
} | ||
|
||
// add JVM parameter | ||
// -Dcsp.sentinel.charset=gbk | ||
// -Dcsp.sentinel.metric.file.single.size=104857600 | ||
// -Dcsp.sentinel.metric.file.total.count=10 | ||
// -Dcsp.sentinel.flow.cold.factor=5 | ||
// -Dcsp.sentinel.statistic.max.rt=10000 | ||
// @Test | ||
public void testCustomConfig() { | ||
assertEquals("gbk", SentinelConfig.charset()); | ||
assertEquals(104857600L, SentinelConfig.singleMetricFileSize()); | ||
assertEquals(10, SentinelConfig.totalMetricFileCount()); | ||
assertEquals(5, SentinelConfig.coldFactor()); | ||
assertEquals(10000, SentinelConfig.statisticMaxRt()); | ||
} | ||
|
||
|
||
/** | ||
* when set code factor alue equal or smaller than 1, get value | ||
* in SentinelConfig.coldFactor() will return DEFAULT_COLD_FACTOR | ||
* see {@link SentinelConfig#coldFactor()} | ||
*/ | ||
@Test | ||
public void testColdFactorEqualOrSmallerThanOne() { | ||
SentinelConfig.setConfig(SentinelConfig.COLD_FACTOR, "0.5"); | ||
assertEquals(SentinelConfig.DEFAULT_COLD_FACTOR, SentinelConfig.coldFactor()); | ||
|
||
SentinelConfig.setConfig(SentinelConfig.COLD_FACTOR, "1"); | ||
assertEquals(SentinelConfig.DEFAULT_COLD_FACTOR, SentinelConfig.coldFactor()); | ||
} | ||
|
||
@Test | ||
public void testColdFactoryLargerThanOne() { | ||
SentinelConfig.setConfig(SentinelConfig.COLD_FACTOR, "2"); | ||
assertEquals(2, SentinelConfig.coldFactor()); | ||
|
||
SentinelConfig.setConfig(SentinelConfig.COLD_FACTOR, "4"); | ||
assertEquals(4, SentinelConfig.coldFactor()); | ||
} | ||
} |