Просмотр исходного кода

Fix potential NPE bug when updating ParamFlowRule before the resource has been requested once (#1901)

master
brothelul GitHub 3 лет назад
Родитель
Сommit
70b457bdc8
Не найден GPG ключ соответствующий данной подписи Идентификатор GPG ключа: 4AEE18F83AFDEB23
2 измененных файлов: 18 добавлений и 1 удалений
  1. +4
    -1
      sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowRuleManager.java
  2. +14
    -0
      sentinel-extension/sentinel-parameter-flow-control/src/test/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowRuleManagerTest.java

+ 4
- 1
sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowRuleManager.java Просмотреть файл

@@ -138,7 +138,10 @@ public final class ParamFlowRuleManager {
List<ParamFlowRule> oldRuleList = new ArrayList<>(entry.getValue());
oldRuleList.removeAll(newRuleList);
for (ParamFlowRule rule : oldRuleList) {
ParameterMetricStorage.getParamMetricForResource(resource).clearForRule(rule);
ParameterMetric parameterMetric = ParameterMetricStorage.getParamMetricForResource(resource);
if (parameterMetric != null) {
parameterMetric.clearForRule(rule);
}
}
}



+ 14
- 0
sentinel-extension/sentinel-parameter-flow-control/src/test/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowRuleManagerTest.java Просмотреть файл

@@ -138,4 +138,18 @@ public class ParamFlowRuleManagerTest {
assertTrue(allRules.contains(ruleC));
assertTrue(allRules.contains(ruleD));
}

@Test
public void testLoadParamRulesWithNoMetric() {
String resource = "test";
ParamFlowRule paramFlowRule = new ParamFlowRule(resource)
.setDurationInSec(1).setParamIdx(1);
ParamFlowRuleManager.loadRules(Collections.singletonList(paramFlowRule));
ParamFlowRule newParamFlowRule = new ParamFlowRule(resource)
.setDurationInSec(2).setParamIdx(1);
ParamFlowRuleManager.loadRules(Collections.singletonList(newParamFlowRule));
List<ParamFlowRule> result = ParamFlowRuleManager.getRulesOfResource(resource);
assertEquals(1, result.size());
assertEquals(2, result.get(0).getDurationInSec());
}
}

Загрузка…
Отмена
Сохранить