Search in sources :

Example 11 with SessionConfiguration

use of org.drools.core.SessionConfiguration in project drools by kiegroup.

the class OutOfMemoryTest method testStatefulSessionsCreation.

/**
 * This test can take a while (> 1 minute).
 * @throws Exception
 */
@Test
@Ignore
public void testStatefulSessionsCreation() throws Exception {
    KieBase kbase = loadKnowledgeBase("test_OutOfMemoryError.drl");
    int i = 0;
    SessionConfiguration conf = SessionConfiguration.newInstance();
    // this is just for documentation purposes, since the default value is "true"
    conf.setKeepReference(true);
    try {
        for (i = 0; i < 300000; i++) {
            KieSession ksession = kbase.newKieSession(conf, null);
            ksession.dispose();
        }
    } catch (Throwable e) {
        logger.info("Error at: " + i);
        e.printStackTrace();
        fail("Should not raise any error or exception.");
    }
}
Also used : KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) SessionConfiguration(org.drools.core.SessionConfiguration) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 12 with SessionConfiguration

use of org.drools.core.SessionConfiguration in project drools by kiegroup.

the class StreamsTest method testEventAssertion.

@Test(timeout = 10000)
public void testEventAssertion() throws Exception {
    // read in the source
    KieBase kbase = loadKnowledgeBase("test_EntryPoint.drl");
    // final RuleBase ruleBase = loadRuleBase( reader );
    KieSessionConfiguration conf = SessionConfiguration.newInstance();
    ((SessionConfiguration) conf).setClockType(ClockType.PSEUDO_CLOCK);
    KieSession session = kbase.newKieSession(conf, null);
    final List results = new ArrayList();
    session.setGlobal("results", results);
    StockTickInterface tick1 = new StockTick(1, "DROO", 50, System.currentTimeMillis());
    StockTickInterface tick2 = new StockTick(2, "ACME", 10, System.currentTimeMillis());
    StockTickInterface tick3 = new StockTick(3, "ACME", 10, System.currentTimeMillis());
    StockTickInterface tick4 = new StockTick(4, "DROO", 50, System.currentTimeMillis());
    InternalFactHandle handle1 = (InternalFactHandle) session.insert(tick1);
    InternalFactHandle handle2 = (InternalFactHandle) session.insert(tick2);
    InternalFactHandle handle3 = (InternalFactHandle) session.insert(tick3);
    InternalFactHandle handle4 = (InternalFactHandle) session.insert(tick4);
    assertNotNull(handle1);
    assertNotNull(handle2);
    assertNotNull(handle3);
    assertNotNull(handle4);
    assertTrue(handle1.isEvent());
    assertTrue(handle2.isEvent());
    assertTrue(handle3.isEvent());
    assertTrue(handle4.isEvent());
    session.fireAllRules();
    assertEquals(0, results.size());
    StockTickInterface tick5 = new StockTick(5, "DROO", 50, System.currentTimeMillis());
    StockTickInterface tick6 = new StockTick(6, "ACME", 10, System.currentTimeMillis());
    StockTickInterface tick7 = new StockTick(7, "ACME", 15, System.currentTimeMillis());
    StockTickInterface tick8 = new StockTick(8, "DROO", 50, System.currentTimeMillis());
    EntryPoint entry = session.getEntryPoint("StockStream");
    InternalFactHandle handle5 = (InternalFactHandle) entry.insert(tick5);
    InternalFactHandle handle6 = (InternalFactHandle) entry.insert(tick6);
    InternalFactHandle handle7 = (InternalFactHandle) entry.insert(tick7);
    InternalFactHandle handle8 = (InternalFactHandle) entry.insert(tick8);
    assertNotNull(handle5);
    assertNotNull(handle6);
    assertNotNull(handle7);
    assertNotNull(handle8);
    assertTrue(handle5.isEvent());
    assertTrue(handle6.isEvent());
    assertTrue(handle7.isEvent());
    assertTrue(handle8.isEvent());
    session.fireAllRules();
    assertEquals(1, results.size());
    assertSame(tick7, results.get(0));
}
Also used : StockTickInterface(org.drools.compiler.StockTickInterface) StockTick(org.drools.compiler.StockTick) KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) EntryPoint(org.kie.api.runtime.rule.EntryPoint) KieSession(org.kie.api.runtime.KieSession) List(java.util.List) ArrayList(java.util.ArrayList) InternalFactHandle(org.drools.core.common.InternalFactHandle) KieSessionConfiguration(org.kie.api.runtime.KieSessionConfiguration) KieSessionConfiguration(org.kie.api.runtime.KieSessionConfiguration) SessionConfiguration(org.drools.core.SessionConfiguration) Test(org.junit.Test)

Example 13 with SessionConfiguration

use of org.drools.core.SessionConfiguration in project drools by kiegroup.

the class JTMSTest method getSessionFromFile.

protected KieSession getSessionFromFile(String ruleFile) {
    KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kBuilder.add(ResourceFactory.newClassPathResource(ruleFile, getClass()), ResourceType.DRL);
    if (kBuilder.hasErrors()) {
        System.err.println(kBuilder.getErrors());
        fail();
    }
    InternalKnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
    kBase.addPackages(kBuilder.getKnowledgePackages());
    KieSessionConfiguration ksConf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
    ((SessionConfiguration) ksConf).setBeliefSystemType(BeliefSystemType.JTMS);
    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 14 with SessionConfiguration

use of org.drools.core.SessionConfiguration in project drools by kiegroup.

the class JTMSTest method getSessionFromString.

protected KieSession getSessionFromString(String drlString) {
    KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    try {
        System.setProperty("drools.negatable", "on");
        kBuilder.add(ResourceFactory.newByteArrayResource(drlString.getBytes()), 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.JTMS);
    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 15 with SessionConfiguration

use of org.drools.core.SessionConfiguration in project drools by kiegroup.

the class DefeasibilityTest method getSessionFromString.

protected KieSession getSessionFromString(String drlString) {
    KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    try {
        System.setProperty("drools.negatable", "on");
        kBuilder.add(ResourceFactory.newByteArrayResource(drlString.getBytes()), ResourceType.DRL);
        if (kBuilder.hasErrors()) {
            System.err.println(kBuilder.getErrors());
            fail();
        }
    } finally {
        System.setProperty("drools.negatable", "off");
    }
    KieBaseConfiguration kieBaseConfiguration = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
    kieBaseConfiguration.setOption(EqualityBehaviorOption.EQUALITY);
    InternalKnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase(kieBaseConfiguration);
    kBase.addPackages(kBuilder.getKnowledgePackages());
    KieSessionConfiguration ksConf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
    ((SessionConfiguration) ksConf).setBeliefSystemType(BeliefSystemType.DEFEASIBLE);
    KieSession kSession = kBase.newKieSession(ksConf, null);
    return kSession;
}
Also used : KieBaseConfiguration(org.kie.api.KieBaseConfiguration) 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)

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