Search in sources :

Example 86 with KieSessionConfiguration

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());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieBase(org.kie.api.KieBase) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) Properties(java.util.Properties) KieSessionConfiguration(org.kie.api.runtime.KieSessionConfiguration) KieSessionConfiguration(org.kie.api.runtime.KieSessionConfiguration) SessionConfiguration(org.drools.core.SessionConfiguration) Test(org.junit.Test)

Example 87 with KieSessionConfiguration

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;
}
Also used : StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) Environment(org.kie.api.runtime.Environment) KieSessionConfiguration(org.kie.api.runtime.KieSessionConfiguration)

Example 88 with KieSessionConfiguration

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;
}
Also used : StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) KieSessionConfiguration(org.kie.api.runtime.KieSessionConfiguration)

Example 89 with KieSessionConfiguration

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);
}
Also used : Message(org.drools.testcoverage.common.model.Message) SessionPseudoClock(org.kie.api.time.SessionPseudoClock) MessageEvent(org.drools.testcoverage.common.model.MessageEvent) KieSessionConfiguration(org.kie.api.runtime.KieSessionConfiguration)

Example 90 with KieSessionConfiguration

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();
}
Also used : KieSessionConfiguration(org.kie.api.runtime.KieSessionConfiguration)

Aggregations

KieSessionConfiguration (org.kie.api.runtime.KieSessionConfiguration)204 KieSession (org.kie.api.runtime.KieSession)168 Test (org.junit.Test)160 KieBase (org.kie.api.KieBase)126 ArrayList (java.util.ArrayList)98 PseudoClockScheduler (org.drools.core.time.impl.PseudoClockScheduler)71 KieHelper (org.kie.internal.utils.KieHelper)69 List (java.util.List)59 KieBaseConfiguration (org.kie.api.KieBaseConfiguration)57 StockTick (org.drools.compiler.StockTick)40 SessionPseudoClock (org.kie.api.time.SessionPseudoClock)39 EntryPoint (org.kie.api.runtime.rule.EntryPoint)28 Arrays.asList (java.util.Arrays.asList)27 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)26 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)22 Date (java.util.Date)18 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)18 StockTickInterface (org.drools.compiler.StockTickInterface)18 NamedEntryPoint (org.drools.core.common.NamedEntryPoint)16 SessionConfiguration (org.drools.core.SessionConfiguration)15