StatelessRulesEngine { public void updateRule(String ruleGroup, String ruleJson, boolean delete) throws Exception { Map<Short, Rule> ruleMap = this.ruleMap; if (ruleGroupsActive) { if (ruleGroup != null) { ruleMap = ruleGroupMap.get(ruleGroup); if (ruleMap == null) { ruleMap = new LinkedHashMap<>(hashSize); ruleGroupMap.put(ruleGroup, ruleMap); } } else { throw new PerformantException("Supplied rule group is null"); } } if (ruleMap == null) { throw new PerformantException("Rule map not found for rule:" + ruleJson + "\trule-group:" + ruleGroup); } updateRuleMap(ruleMap, ruleJson, delete); } StatelessRulesEngine(RulesEngineCaller<K, C> caller, EventFactory eventFactory, StoreFactory storeFactory); void initializeRules(Map<String, String> conf); static Rule updateRuleMap(Map<Short, Rule> ruleMap, String ruleJson, boolean delete); void updateRule(String ruleGroup, String ruleJson, boolean delete); void evaluateEventAgainstAllRules(C eventCollector, K eventContainer, Event event); void evaluateEventAgainstGroupedRules(C eventCollector, K eventContainer, Event event); void evaluateEventAgainstRule(String ruleGroup, Rule rule, C eventCollector, K eventContainer, Event event); Map<Short, Rule> getRuleMap(); Map<String, Map<Short, Rule>> getRuleGroupMap(); boolean isRuleGroupsActive(); int getHashSize();  }
@Test public void testUpdateRule() throws Exception { engine.initializeRules(new HashMap<>()); engine.updateRule(null, RuleSerializer.serializeRuleToJSONString(new SimpleRule((short) 1123, "test1", true, new EqualsCondition("host", "val"), new TemplatedAlertAction((short) 2, (short) 2)), false), false); Map<Short, Rule> rule = engine.getRuleMap(); assertEquals(1, rule.size()); engine = new StatelessRulesEngine<>(caller, testFactory, testFactory); Map<String, String> conf = new HashMap<>(); conf.put(TestFactory.RULES_CONTENT, RuleSerializer.serializeRulesToJSONString(Arrays.asList(new SimpleRule((short) 1122, "test1", true, new EqualsCondition("host", "val"), new TemplatedAlertAction((short) 2, (short) 2))), false)); engine.initializeRules(conf); engine.updateRule(null, RuleSerializer.serializeRuleToJSONString(new SimpleRule((short) 1123, "test1", true, new EqualsCondition("host", "val"), new TemplatedAlertAction((short) 2, (short) 2)), false), false); rule = engine.getRuleMap(); assertEquals(2, rule.size()); }