use of org.kie.api.runtime.KieSessionConfiguration 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.kie.api.runtime.KieSessionConfiguration in project drools by kiegroup.
the class TimerAndCalendarTest method createSession.
private KieSession createSession(KieBase kbase) {
final KieSessionConfiguration conf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
conf.setOption(ClockTypeOption.get(ClockType.PSEUDO_CLOCK.getId()));
Environment env = createEnvironment(context);
if (locking) {
env.set(EnvironmentName.USE_PESSIMISTIC_LOCKING, true);
}
StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, conf, env);
return ksession;
}
use of org.kie.api.runtime.KieSessionConfiguration in project drools by kiegroup.
the class TimerAndCalendarTest method disposeAndReloadSession.
private KieSession disposeAndReloadSession(KieSession ksession, KieBase kbase) {
long ksessionId = ksession.getIdentifier();
ksession.dispose();
final KieSessionConfiguration conf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
conf.setOption(ClockTypeOption.get(ClockType.PSEUDO_CLOCK.getId()));
StatefulKnowledgeSession newksession = JPAKnowledgeService.loadStatefulKnowledgeSession(ksessionId, kbase, conf, createEnvironment(context));
return newksession;
}
use of org.kie.api.runtime.KieSessionConfiguration in project drools by kiegroup.
the class OOPathCepTest method populateAndVerifyTimeWindowCase.
private void populateAndVerifyTimeWindowCase(final KieBase kieBase) {
final KieSessionConfiguration sessionConfiguration = KieSessionUtil.getKieSessionConfigurationWithClock(ClockTypeOption.get("pseudo"), null);
this.initKieSession(kieBase, sessionConfiguration);
final SessionPseudoClock clock = this.kieSession.getSessionClock();
final MessageEvent pingEvent = new MessageEvent(MessageEvent.Type.sent, new Message("Ping"));
this.kieSession.insert(pingEvent);
clock.advanceTime(1, TimeUnit.SECONDS);
final MessageEvent ping2Event = new MessageEvent(MessageEvent.Type.received, new Message("Ping"));
this.kieSession.insert(ping2Event);
clock.advanceTime(1, TimeUnit.SECONDS);
final MessageEvent ping3Event = new MessageEvent(MessageEvent.Type.received, new Message("Ping"));
this.kieSession.insert(ping3Event);
clock.advanceTime(1, TimeUnit.SECONDS);
this.kieSession.fireAllRules();
Assertions.assertThat(this.events).as("The rule should have fired for 2 events").containsExactlyInAnyOrder(ping2Event, ping3Event);
this.events.clear();
final MessageEvent pongEvent = new MessageEvent(MessageEvent.Type.sent, new Message("Pong"));
this.kieSession.insert(pongEvent);
clock.advanceTime(1, TimeUnit.SECONDS);
final MessageEvent ping4Event = new MessageEvent(MessageEvent.Type.received, new Message("Ping"));
this.kieSession.insert(ping4Event);
clock.advanceTime(1, TimeUnit.SECONDS);
this.kieSession.fireAllRules();
Assertions.assertThat(this.events).as("The rule should have fired for ping event only").contains(ping4Event);
}
use of org.kie.api.runtime.KieSessionConfiguration in project drools by kiegroup.
the class OOPathCepTest method initKieSessionWithPseudoClock.
private SessionPseudoClock initKieSessionWithPseudoClock(final KieBase kieBase) {
final KieSessionConfiguration sessionConfiguration = KieSessionUtil.getKieSessionConfigurationWithClock(ClockTypeOption.get("pseudo"), null);
this.initKieSession(kieBase, sessionConfiguration);
return this.kieSession.getSessionClock();
}
Aggregations