Search in sources :

Example 21 with SessionConfiguration

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

the class JDKTimerServiceTest method testRepeatedExecutionJob.

@Test
public void testRepeatedExecutionJob() 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 });
    HelloWorldJobContext ctx = new HelloWorldJobContext("hello world", timeService);
    timeService.scheduleJob(new HelloWorldJob(), ctx, trigger);
    Thread.sleep(500);
    timeService.shutdown();
    assertEquals(3, 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 22 with SessionConfiguration

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

the class JDKTimerServiceTest method testSingleExecutionJob.

@Test
public void testSingleExecutionJob() throws Exception {
    SessionConfiguration config = SessionConfiguration.newInstance();
    config.setClockType(ClockType.REALTIME_CLOCK);
    TimerService timeService = TimerServiceFactory.getTimerService(config);
    Trigger trigger = new DelayedTrigger(100);
    HelloWorldJobContext ctx = new HelloWorldJobContext("hello world", timeService);
    timeService.scheduleJob(new HelloWorldJob(), ctx, trigger);
    Thread.sleep(500);
    timeService.shutdown();
    assertEquals(1, 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 23 with SessionConfiguration

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

the class BayesBeliefSystemTest method getSessionFromString.

protected KieSession getSessionFromString(String drlString) {
    KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kBuilder.add(ResourceFactory.newByteArrayResource(drlString.getBytes()), ResourceType.DRL);
    kBuilder.add(ResourceFactory.newClassPathResource("Garden.xmlbif", AssemblerTest.class), ResourceType.BAYES);
    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.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)

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