### Question:
ParamFlowRuleManager { public static void loadRules(List<ParamFlowRule> rules) { try { currentProperty.updateValue(rules); } catch (Throwable e) { RecordLog.info("[ParamFlowRuleManager] Failed to load rules", e); } } private  ParamFlowRuleManager(); static void loadRules(List<ParamFlowRule> rules); static void register2Property(SentinelProperty<List<ParamFlowRule>> property); static List<ParamFlowRule> getRulesOfResource(String resourceName); static boolean hasRules(String resourceName); static List<ParamFlowRule> getRules();  }### Answer:
@Test public void testLoadParamRulesClearingUnusedMetrics() { final String resA = "resA"; ParamFlowRule ruleA = new ParamFlowRule(resA) .setCount(1) .setParamIdx(0); ParamFlowRuleManager.loadRules(Collections.singletonList(ruleA)); ParameterMetricStorage.getMetricsMap().put(resA, new ParameterMetric()); assertNotNull(ParameterMetricStorage.getParamMetricForResource(resA)); final String resB = "resB"; ParamFlowRule ruleB = new ParamFlowRule(resB) .setCount(2) .setParamIdx(1); ParamFlowRuleManager.loadRules(Collections.singletonList(ruleB)); assertNull("The unused hot param metric should be cleared", ParameterMetricStorage.getParamMetricForResource(resA)); }
@Test public void testLoadParamRulesClearingUnusedMetricsForRule() { final String resA = "resA"; ParamFlowRule ruleA1 = new ParamFlowRule(resA) .setCount(1) .setParamIdx(0); ParamFlowRule ruleA2 = new ParamFlowRule(resA) .setCount(2) .setParamIdx(1); ParamFlowRuleManager.loadRules(Arrays.asList(ruleA1, ruleA2)); ParameterMetric metric = new ParameterMetric(); metric.initialize(ruleA1); metric.initialize(ruleA2); ParameterMetricStorage.getMetricsMap().put(resA, metric); ParameterMetric metric1 = ParameterMetricStorage.getParamMetricForResource(resA); assertNotNull(metric1); assertNotNull(metric1.getRuleTimeCounter(ruleA1)); assertNotNull(metric1.getRuleTimeCounter(ruleA2)); ParamFlowRuleManager.loadRules(Arrays.asList(ruleA1)); ParameterMetric metric2 = ParameterMetricStorage.getParamMetricForResource(resA); assertNotNull(metric2); assertNotNull(metric2.getRuleTimeCounter(ruleA1)); assertNull(metric2.getRuleTimeCounter(ruleA2)); }