Search in sources :

Example 6 with SessionConfiguration

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;
}
Also used : KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) KieSession(org.kie.api.runtime.KieSession) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) KieSessionConfiguration(org.kie.api.runtime.KieSessionConfiguration) KieSessionConfiguration(org.kie.api.runtime.KieSessionConfiguration) SessionConfiguration(org.drools.core.SessionConfiguration)

Example 7 with SessionConfiguration

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());
}
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 8 with SessionConfiguration

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());
}
Also used : Trigger(org.drools.core.time.Trigger) SessionConfiguration(org.drools.core.SessionConfiguration) TimerService(org.drools.core.time.TimerService) Test(org.junit.Test)

Example 9 with SessionConfiguration

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

Example 10 with SessionConfiguration

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");
}
Also used : KieBase(org.kie.api.KieBase) KieHelper(org.kie.internal.utils.KieHelper) 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)

Aggregations

SessionConfiguration (org.drools.core.SessionConfiguration)23 KieSessionConfiguration (org.kie.api.runtime.KieSessionConfiguration)17 KieSession (org.kie.api.runtime.KieSession)12 Test (org.junit.Test)11 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)6 KieBase (org.kie.api.KieBase)6 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)6 Properties (java.util.Properties)3 KnowledgeBaseImpl (org.drools.core.impl.KnowledgeBaseImpl)3 TimerService (org.drools.core.time.TimerService)3 Trigger (org.drools.core.time.Trigger)3 ArrayList (java.util.ArrayList)2 WorkingMemory (org.drools.core.WorkingMemory)2 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)2 StatefulKnowledgeSessionImpl (org.drools.core.impl.StatefulKnowledgeSessionImpl)2 RuleTerminalNode (org.drools.core.reteoo.RuleTerminalNode)2 PseudoClockScheduler (org.drools.core.time.impl.PseudoClockScheduler)2 Ignore (org.junit.Ignore)2 KieHelper (org.kie.internal.utils.KieHelper)2 IOException (java.io.IOException)1