summaryrefslogtreecommitdiffstats
path: root/engine-d/src/main/java/org
diff options
context:
space:
mode:
authorXuanweiLiao <liao.xuanwei@zte.com.cn>2017-02-23 15:13:34 +0800
committerXuanweiLiao <liao.xuanwei@zte.com.cn>2017-02-23 16:45:26 +0800
commit724a1dcd96ea33a16c0b88446fbc2d7c7d0d5c7d (patch)
tree671ab53ba17df120ef244f917dfd6b551cf18ea3 /engine-d/src/main/java/org
parent1ee339f8d62cef6cfafbbcef78e4bd550c72a812 (diff)
Add engine junit test
Issue-ID:HOLMES-24 Change-Id: Idf62760a2925f26ec239aaff79271b789d740079 Signed-off-by: XuanweiLiao <liao.xuanwei@zte.com.cn>
Diffstat (limited to 'engine-d/src/main/java/org')
-rw-r--r--engine-d/src/main/java/org/openo/holmes/engine/manager/DroolsEngine.java24
-rw-r--r--engine-d/src/main/java/org/openo/holmes/engine/wrapper/RuleMgtWrapper.java4
2 files changed, 14 insertions, 14 deletions
diff --git a/engine-d/src/main/java/org/openo/holmes/engine/manager/DroolsEngine.java b/engine-d/src/main/java/org/openo/holmes/engine/manager/DroolsEngine.java
index 473b929..16ae49c 100644
--- a/engine-d/src/main/java/org/openo/holmes/engine/manager/DroolsEngine.java
+++ b/engine-d/src/main/java/org/openo/holmes/engine/manager/DroolsEngine.java
@@ -150,7 +150,9 @@ public class DroolsEngine {
StringReader reader = new StringReader(ruleContent);
Resource res = ResourceFactory.newReaderResource(reader);
- kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
+ if (kbuilder == null) {
+ kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
+ }
kbuilder.add(res, ResourceType.DRL);
@@ -161,8 +163,6 @@ public class DroolsEngine {
throw new EngineException(e);
}
- kbuilder = null;
-
ksession.fireAllRules();
}
@@ -171,7 +171,9 @@ public class DroolsEngine {
StringReader reader = new StringReader(rule.getContent());
Resource res = ResourceFactory.newReaderResource(reader);
- kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
+ if (kbuilder == null) {
+ kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
+ }
kbuilder.add(res, ResourceType.DRL);
@@ -183,9 +185,9 @@ public class DroolsEngine {
throw new CorrelationException(errorMsg);
}
- String packageName = kbuilder.getKnowledgePackages().iterator().next().getName();
+ KnowledgePackage kpackage = kbuilder.getKnowledgePackages().iterator().next();
- if (kbase.getKnowledgePackages().contains(packageName)) {
+ if (kbase.getKnowledgePackages().contains(kpackage)) {
String errorMsg = I18nProxy.getInstance().getValueByArgs(locale,
I18nProxy.ENGINE_CONTENT_ILLEGALITY,new String[]{
@@ -203,13 +205,10 @@ public class DroolsEngine {
throw new CorrelationException(errorMsg, e);
}
- kbuilder = null;
-
ksession.fireAllRules();
- return packageName;
+ return kpackage.getName();
}
-
public synchronized void undeployRule(String packageName, Locale locale)
throws CorrelationException {
@@ -237,7 +236,9 @@ public class DroolsEngine {
StringReader reader = new StringReader(content);
Resource res = ResourceFactory.newReaderResource(reader);
- kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
+ if (kbuilder == null) {
+ kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
+ }
kbuilder.add(res, ResourceType.DRL);
@@ -248,7 +249,6 @@ public class DroolsEngine {
log.error(errorMsg);
throw new CorrelationException(errorMsg);
}
- kbuilder = null;
}
public void putRaisedIntoStream(Alarm raiseAlarm) {
diff --git a/engine-d/src/main/java/org/openo/holmes/engine/wrapper/RuleMgtWrapper.java b/engine-d/src/main/java/org/openo/holmes/engine/wrapper/RuleMgtWrapper.java
index 34dab1f..59110d8 100644
--- a/engine-d/src/main/java/org/openo/holmes/engine/wrapper/RuleMgtWrapper.java
+++ b/engine-d/src/main/java/org/openo/holmes/engine/wrapper/RuleMgtWrapper.java
@@ -39,8 +39,8 @@ public class RuleMgtWrapper {
List<CorrelationRule> ruleTemp = daoUtil.getJdbiDaoByOnDemand(CorrelationRuleDao.class)
.queryRuleByRuleEnable(enable);
- if (ruleTemp != null) {
- throw new DbException(I18nProxy.RULE_MANAGEMENT_REPEAT_RULE_NAME);
+ if (ruleTemp == null) {
+ throw new DbException(I18nProxy.RULE_MANAGEMENT_DB_ERROR);
}
return ruleTemp;
}