StatelessRulesEngine { public void initializeRules(Map<String, String> conf) throws Exception { ruleGroupsActive = Boolean.parseBoolean(conf.getOrDefault(Constants.RULE_GROUP_ACTIVE, Constants.FALSE)); hashSize = Integer.parseInt(conf.getOrDefault(Constants.RULE_HASH_INIT_SIZE, Constants.DEFAULT_RULE_HASH_SIZE)); if (!ruleGroupsActive) { this.ruleMap = new LinkedHashMap<>(hashSize); } else { this.ruleGroupMap = new HashMap<>(hashSize); } RulesStore store = null; try { store = storeFactory.getRulesStore(conf.get(Constants.RSTORE_TYPE), conf); } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { throw e; } try { store.connect(); if (!ruleGroupsActive) { this.ruleMap.putAll(store.listRules()); } else { this.ruleGroupMap.putAll(store.listGroupedRules()); } store.disconnect(); } catch (IOException e) { logger.error("Failed to load rules from store, reason:" + e.getMessage()); throw e; } } 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 testInitializeRules() throws Exception { 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 AlertAction((short) 2, "test", "test", "test"))), false)); engine.initializeRules(conf); Map<Short, Rule> map = engine.getRuleMap(); assertEquals(1, map.size()); }