use of org.drools.core.RuleBaseConfiguration in project drools by kiegroup.
the class RuleBaseConfigurationTest method testSystemProperties.
@Test
public void testSystemProperties() {
RuleBaseConfiguration cfg = new RuleBaseConfiguration();
assertEquals(AssertBehaviour.IDENTITY, cfg.getAssertBehaviour());
System.setProperty("drools.equalityBehavior", "EQUALITY");
cfg = new RuleBaseConfiguration();
assertEquals(AssertBehaviour.EQUALITY, cfg.getAssertBehaviour());
System.getProperties().remove("drools.equalityBehavior");
}
use of org.drools.core.RuleBaseConfiguration in project opennms by OpenNMS.
the class DroolsCorrelationEngine method initialize.
/**
* <p>initialize</p>
*
* @throws java.lang.Exception if any.
*/
public void initialize() throws Exception {
KieServices ks = KieServices.Factory.get();
KieFileSystem kFileSystem = ks.newKieFileSystem();
loadRules(kFileSystem);
KieBuilder kbuilder = ks.newKieBuilder(kFileSystem);
kbuilder.buildAll();
if (kbuilder.getResults().hasMessages(org.kie.api.builder.Message.Level.ERROR)) {
LOG.warn("Unable to initialize Drools engine: {}", kbuilder.getResults().getMessages(Level.ERROR));
throw new IllegalStateException("Unable to initialize Drools engine: " + kbuilder.getResults().getMessages(Level.ERROR));
}
KieContainer kContainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
AssertBehaviour behaviour = AssertBehaviour.determineAssertBehaviour(m_assertBehaviour);
RuleBaseConfiguration ruleBaseConfig = new RuleBaseConfiguration();
ruleBaseConfig.setAssertBehaviour(behaviour);
EventProcessingOption eventProcessingOption = EventProcessingOption.CLOUD;
if (m_eventProcessingMode != null && m_eventProcessingMode.toLowerCase().equals("stream")) {
eventProcessingOption = EventProcessingOption.STREAM;
m_isStreaming = true;
}
ruleBaseConfig.setEventProcessingMode(eventProcessingOption);
m_kieBase = kContainer.newKieBase(ruleBaseConfig);
m_kieSession = m_kieBase.newKieSession();
m_kieSession.setGlobal("engine", this);
for (final Map.Entry<String, Object> entry : m_globals.entrySet()) {
m_kieSession.setGlobal(entry.getKey(), entry.getValue());
}
if (m_persistState != null && m_persistState) {
unmarshallStateFromDisk(true);
}
if (m_isStreaming) {
new Thread(() -> {
Logging.putPrefix(getClass().getSimpleName() + '-' + getName());
m_kieSession.fireUntilHalt();
}, "FireTask").start();
}
}
use of org.drools.core.RuleBaseConfiguration in project drools by kiegroup.
the class CepEspTest method testTemporalOperators.
@Test(timeout = 10000)
public void testTemporalOperators() throws Exception {
// read in the source
final RuleBaseConfiguration kbconf = new RuleBaseConfiguration();
kbconf.setEventProcessingMode(EventProcessingOption.STREAM);
KieBase kbase = loadKnowledgeBase(kbconf, "test_CEP_TemporalOperators.drl");
KieSession ksession = createKnowledgeSession(kbase);
ksession.insert(new StockTick(1, "A", 10, 1000));
}
use of org.drools.core.RuleBaseConfiguration in project drools by kiegroup.
the class CepEspTest method testTemporalOperators2.
@Test(timeout = 10000)
public void testTemporalOperators2() throws Exception {
// read in the source
final RuleBaseConfiguration kbconf = new RuleBaseConfiguration();
kbconf.setEventProcessingMode(EventProcessingOption.STREAM);
KieBase kbase = loadKnowledgeBase(kbconf, "test_CEP_TemporalOperators2.drl");
KieSessionConfiguration sconf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
sconf.setOption(ClockTypeOption.get(ClockType.PSEUDO_CLOCK.getId()));
KieSession ksession = createKnowledgeSession(kbase, sconf);
List list = new ArrayList();
ksession.setGlobal("list", list);
SessionPseudoClock clock = (SessionPseudoClock) ksession.<SessionClock>getSessionClock();
EntryPoint ep = ksession.getEntryPoint("X");
clock.advanceTime(1000, TimeUnit.SECONDS);
ep.insert(new StockTick(1, "A", 10, clock.getCurrentTime()));
clock.advanceTime(8, TimeUnit.SECONDS);
ep.insert(new StockTick(2, "B", 10, clock.getCurrentTime()));
clock.advanceTime(8, TimeUnit.SECONDS);
ep.insert(new StockTick(3, "B", 10, clock.getCurrentTime()));
clock.advanceTime(8, TimeUnit.SECONDS);
int rules = ksession.fireAllRules();
// assertEquals( 2,
// rules );
// assertEquals( 1, list.size() );
// StockTick[] stocks = ( StockTick[] ) list.get(0);
// assertSame( tick4, stocks[0]);
// assertSame( tick2, stocks[1]);
}
use of org.drools.core.RuleBaseConfiguration in project drools by kiegroup.
the class Misc2Test method testLegacySalienceResolver.
@Test
public void testLegacySalienceResolver() {
// DROOLS-159
String drl = "package org.drools.test; \n" + "" + "global java.util.List list; \n " + "" + "rule X salience 10 \n" + "then\n" + " list.add( 1 ); \n" + "end\n" + "" + "rule Y salience 5 \n" + "then\n" + " list.add( 2 ); \n" + "end\n" + "";
KnowledgeBuilder kb = KnowledgeBuilderFactory.newKnowledgeBuilder();
kb.add(new ByteArrayResource(drl.getBytes()), ResourceType.DRL);
assertFalse(kb.hasErrors());
KieBaseConfiguration kbconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
((RuleBaseConfiguration) kbconf).setConflictResolver(SalienceConflictResolver.getInstance());
InternalKnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase(kbconf);
knowledgeBase.addPackages(kb.getKnowledgePackages());
KieSession knowledgeSession = knowledgeBase.newKieSession();
List list = new ArrayList();
knowledgeSession.setGlobal("list", list);
knowledgeSession.fireAllRules();
assertEquals(Arrays.asList(1, 2), list);
}
Aggregations