use of org.drools.core.SessionConfiguration in project drools by kiegroup.
the class DefeasibilityTest method getSession.
protected KieSession getSession(String ruleFile) {
KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
try {
System.setProperty("drools.negatable", "on");
kBuilder.add(ResourceFactory.newClassPathResource(ruleFile), ResourceType.DRL);
if (kBuilder.hasErrors()) {
System.err.println(kBuilder.getErrors());
fail();
}
} finally {
System.setProperty("drools.negatable", "off");
}
InternalKnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
kBase.addPackages(kBuilder.getKnowledgePackages());
KieSessionConfiguration ksConf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
((SessionConfiguration) ksConf).setBeliefSystemType(BeliefSystemType.DEFEASIBLE);
KieSession kSession = kBase.newKieSession(ksConf, null);
return kSession;
}
use of org.drools.core.SessionConfiguration in project drools by kiegroup.
the class JpaPersistentStatefulSessionTest method testMergeConfig.
@Test
public void testMergeConfig() {
// JBRULES-3155
String str = "";
str += "package org.kie.test\n";
str += "global java.util.List list\n";
str += "rule rule1\n";
str += "when\n";
str += " $i : Integer(intValue > 0)\n";
str += "then\n";
str += " list.add( $i );\n";
str += "end\n";
str += "\n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", str);
ks.newKieBuilder(kfs).buildAll();
KieBase kbase = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).getKieBase();
Properties properties = new Properties();
properties.put("drools.processInstanceManagerFactory", "com.example.CustomJPAProcessInstanceManagerFactory");
KieSessionConfiguration config = ks.newKieSessionConfiguration(properties);
KieSession ksession = ks.getStoreServices().newKieSession(kbase, config, env);
SessionConfiguration sessionConfig = (SessionConfiguration) ksession.getSessionConfiguration();
assertEquals("com.example.CustomJPAProcessInstanceManagerFactory", sessionConfig.getProcessInstanceManagerFactory());
}
use of org.drools.core.SessionConfiguration in project drools by kiegroup.
the class JDKTimerServiceTest method testRepeatedExecutionJobWithRemove.
@Test
public void testRepeatedExecutionJobWithRemove() throws Exception {
SessionConfiguration config = SessionConfiguration.newInstance();
config.setClockType(ClockType.REALTIME_CLOCK);
TimerService timeService = TimerServiceFactory.getTimerService(config);
Trigger trigger = new DelayedTrigger(new long[] { 100, 100, 100, 100, 100, 100, 100, 100 });
HelloWorldJobContext ctx = new HelloWorldJobContext("hello world", timeService);
ctx.setLimit(3);
timeService.scheduleJob(new HelloWorldJob(), ctx, trigger);
Thread.sleep(1000);
timeService.shutdown();
assertEquals(5, ctx.getList().size());
}
use of org.drools.core.SessionConfiguration in project drools by kiegroup.
the class KnowledgeStoreServiceImpl method mergeConfig.
private KieSessionConfiguration mergeConfig(KieSessionConfiguration configuration) {
KieSessionConfiguration merged = ((SessionConfiguration) configuration).addDefaultProperties(configProps);
merged.setOption(TimerJobFactoryOption.get("jpa"));
return merged;
}
use of org.drools.core.SessionConfiguration in project drools by kiegroup.
the class JpaPersistentStatefulSessionTest method testMergeConfig.
@Test
public void testMergeConfig() {
// JBRULES-3155
final KieBase kbase = new KieHelper().getKieContainer().getKieBase();
final Properties properties = new Properties();
properties.put("drools.processInstanceManagerFactory", "com.example.CustomJPAProcessInstanceManagerFactory");
final KieSessionConfiguration config = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(properties);
final KieSession ksession = KieServices.get().getStoreServices().newKieSession(kbase, config, env);
final SessionConfiguration sessionConfig = (SessionConfiguration) ksession.getSessionConfiguration();
assertThat(sessionConfig.getProcessInstanceManagerFactory()).isEqualTo("com.example.CustomJPAProcessInstanceManagerFactory");
}
Aggregations