Search in sources :

Example 71 with EventFactHandle

use of org.drools.core.common.EventFactHandle in project drools by kiegroup.

the class DurationTimer method createTrigger.

public Trigger createTrigger(Activation item, InternalWorkingMemory wm) {
    long timestamp;
    if (eventFactHandle != null) {
        Tuple leftTuple = item.getTuple();
        EventFactHandle fh = (EventFactHandle) leftTuple.get(eventFactHandle);
        timestamp = fh.getStartTimestamp();
    } else {
        timestamp = wm.getTimerService().getCurrentTime();
    }
    String[] calendarNames = item.getRule().getCalendars();
    Calendars calendars = wm.getCalendars();
    return createTrigger(timestamp, calendarNames, calendars);
}
Also used : Calendars(org.kie.api.runtime.Calendars) EventFactHandle(org.drools.core.common.EventFactHandle) Tuple(org.drools.core.spi.Tuple)

Example 72 with EventFactHandle

use of org.drools.core.common.EventFactHandle in project drools by kiegroup.

the class TemporalEvaluatorFactoryTest method testBefore.

@Test
public void testBefore() {
    registry.addEvaluatorDefinition(BeforeEvaluatorDefinition.class.getName());
    EventFactHandle foo = new EventFactHandle(1, "foo", 1, 1, 2, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
    EventFactHandle bar = new EventFactHandle(2, "bar", 1, 2, 2, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
    EventFactHandle drool = new EventFactHandle(1, "drool", 1, 5, 3, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
    final Object[][] data = { { foo, "before", drool, Boolean.TRUE }, { foo, "before", bar, Boolean.FALSE }, { drool, "before", foo, Boolean.FALSE }, { drool, "before", bar, Boolean.FALSE }, { bar, "before", drool, Boolean.TRUE }, { bar, "before", foo, Boolean.FALSE }, { foo, "not before", drool, Boolean.FALSE }, { foo, "not before", bar, Boolean.TRUE }, { drool, "not before", foo, Boolean.TRUE }, { drool, "not before", bar, Boolean.TRUE }, { bar, "not before", drool, Boolean.FALSE }, { bar, "not before", foo, Boolean.TRUE }, { foo, "before[2]", drool, Boolean.TRUE }, { foo, "before[3]", drool, Boolean.FALSE }, { foo, "before[-1]", bar, Boolean.TRUE }, { foo, "before[-2]", bar, Boolean.TRUE }, { bar, "before[1]", drool, Boolean.TRUE }, { bar, "before[2]", drool, Boolean.FALSE }, { bar, "before[-3]", foo, Boolean.TRUE }, { bar, "before[-2]", foo, Boolean.FALSE }, { drool, "before[-6]", bar, Boolean.TRUE }, { drool, "before[-5]", bar, Boolean.FALSE }, { drool, "before[-7]", foo, Boolean.TRUE }, { drool, "before[-8]", foo, Boolean.TRUE }, { foo, "not before[2]", drool, Boolean.FALSE }, { foo, "not before[3]", drool, Boolean.TRUE }, { foo, "not before[-1]", bar, Boolean.FALSE }, { foo, "not before[-2]", bar, Boolean.FALSE }, { bar, "not before[1]", drool, Boolean.FALSE }, { bar, "not before[2]", drool, Boolean.TRUE }, { bar, "not before[-3]", foo, Boolean.FALSE }, { bar, "not before[-2]", foo, Boolean.TRUE }, { drool, "not before[-6]", bar, Boolean.FALSE }, { drool, "not before[-5]", bar, Boolean.TRUE }, { drool, "not before[-7]", foo, Boolean.FALSE }, { drool, "not before[-8]", foo, Boolean.FALSE }, { foo, "before[2,4]", drool, Boolean.TRUE }, { foo, "before[3,4]", drool, Boolean.FALSE }, { foo, "before[-1,1]", bar, Boolean.TRUE }, { foo, "before[0,-2]", bar, Boolean.TRUE }, { bar, "before[0,4]", drool, Boolean.TRUE }, { bar, "before[2,4]", drool, Boolean.FALSE }, { bar, "before[-4,0]", foo, Boolean.TRUE }, { bar, "before[-2,0]", foo, Boolean.FALSE }, { drool, "before[-6,-3]", bar, Boolean.TRUE }, { drool, "before[-5,-3]", bar, Boolean.FALSE }, { drool, "before[-7,-4]", foo, Boolean.TRUE }, { drool, "before[-6,-4]", foo, Boolean.FALSE }, { foo, "not before[2,4]", drool, Boolean.FALSE }, { foo, "not before[3,4]", drool, Boolean.TRUE }, { foo, "not before[-1,1]", bar, Boolean.FALSE }, { foo, "not before[0,-2]", bar, Boolean.FALSE }, { bar, "not before[0,4]", drool, Boolean.FALSE }, { bar, "not before[2,4]", drool, Boolean.TRUE }, { bar, "not before[-4,0]", foo, Boolean.FALSE }, { bar, "not before[-2,0]", foo, Boolean.TRUE }, { drool, "not before[-6,-3]", bar, Boolean.FALSE }, { drool, "not before[-5,-3]", bar, Boolean.TRUE }, { drool, "not before[-7,-4]", foo, Boolean.FALSE }, { drool, "not before[-6,-4]", foo, Boolean.TRUE } };
    runEvaluatorTest(data, ValueType.OBJECT_TYPE);
}
Also used : DisconnectedWorkingMemoryEntryPoint(org.drools.kiesession.entrypoints.DisconnectedWorkingMemoryEntryPoint) EventFactHandle(org.drools.core.common.EventFactHandle) Test(org.junit.Test)

Example 73 with EventFactHandle

use of org.drools.core.common.EventFactHandle in project drools by kiegroup.

the class TemporalEvaluatorFactoryTest method testIncludes.

@Test
public void testIncludes() {
    registry.addEvaluatorDefinition(DuringEvaluatorDefinition.class.getName());
    EventFactHandle foo = new EventFactHandle(1, "foo", 1, 2, 10, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
    EventFactHandle bar = new EventFactHandle(2, "bar", 1, 4, 7, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
    EventFactHandle drool = new EventFactHandle(1, "drool", 1, 1, 5, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
    EventFactHandle mole = new EventFactHandle(1, "mole", 1, 7, 6, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
    final Object[][] data = { { bar, "includes", foo, Boolean.FALSE }, { drool, "includes", foo, Boolean.FALSE }, { mole, "includes", foo, Boolean.FALSE }, { foo, "includes", bar, Boolean.TRUE }, { drool, "includes", bar, Boolean.FALSE }, { mole, "includes", bar, Boolean.FALSE }, { bar, "not includes", foo, Boolean.TRUE }, { drool, "not includes", foo, Boolean.TRUE }, { mole, "not includes", foo, Boolean.TRUE }, { foo, "not includes", bar, Boolean.FALSE }, { drool, "not includes", bar, Boolean.TRUE }, { mole, "not includes", bar, Boolean.TRUE }, { foo, "includes[2]", bar, Boolean.TRUE }, { foo, "includes[3]", bar, Boolean.TRUE }, { foo, "includes[1]", bar, Boolean.FALSE }, { foo, "not includes[2]", bar, Boolean.FALSE }, { foo, "not includes[3]", bar, Boolean.FALSE }, { foo, "not includes[1]", bar, Boolean.TRUE }, { foo, "includes[1, 2]", bar, Boolean.TRUE }, { foo, "includes[2, 3]", bar, Boolean.FALSE }, { foo, "includes[3, 3]", bar, Boolean.FALSE }, { foo, "not includes[1, 2]", bar, Boolean.FALSE }, { foo, "not includes[2, 3]", bar, Boolean.TRUE }, { foo, "not includes[3, 3]", bar, Boolean.TRUE }, { foo, "includes[2, 2, 1, 1]", bar, Boolean.TRUE }, { foo, "includes[1, 5, 1, 3]", bar, Boolean.TRUE }, { foo, "includes[0, 1, 0, 3]", bar, Boolean.FALSE }, { foo, "not includes[2, 2, 1, 1]", bar, Boolean.FALSE }, { foo, "not includes[1, 5, 1, 3]", bar, Boolean.FALSE }, { foo, "not includes[0, 1, 0, 3]", bar, Boolean.TRUE } };
    runEvaluatorTest(data, ValueType.OBJECT_TYPE);
}
Also used : DisconnectedWorkingMemoryEntryPoint(org.drools.kiesession.entrypoints.DisconnectedWorkingMemoryEntryPoint) EventFactHandle(org.drools.core.common.EventFactHandle) Test(org.junit.Test)

Example 74 with EventFactHandle

use of org.drools.core.common.EventFactHandle in project drools by kiegroup.

the class TemporalEvaluatorFactoryTest method testStartedBy.

@Test
public void testStartedBy() {
    registry.addEvaluatorDefinition(DuringEvaluatorDefinition.class.getName());
    EventFactHandle foo = new EventFactHandle(1, "foo", 1, 2, 10, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
    EventFactHandle bar = new EventFactHandle(2, "bar", 1, 2, 7, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
    EventFactHandle drool = new EventFactHandle(1, "drool", 1, 2, 10, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
    EventFactHandle mole = new EventFactHandle(1, "mole", 1, 1, 6, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
    final Object[][] data = { { foo, "startedby", bar, Boolean.TRUE }, { foo, "startedby", drool, Boolean.FALSE }, { foo, "startedby", mole, Boolean.FALSE }, { bar, "startedby", foo, Boolean.FALSE }, { foo, "not startedby", bar, Boolean.FALSE }, { foo, "not startedby", drool, Boolean.TRUE }, { foo, "not startedby", mole, Boolean.TRUE }, { bar, "not startedby", foo, Boolean.TRUE }, { foo, "startedby[1]", bar, Boolean.TRUE }, { foo, "startedby[1]", drool, Boolean.FALSE }, { foo, "startedby[1]", mole, Boolean.TRUE }, { bar, "startedby[1]", foo, Boolean.FALSE }, { foo, "not startedby[1]", bar, Boolean.FALSE }, { foo, "not startedby[1]", drool, Boolean.TRUE }, { foo, "not startedby[1]", mole, Boolean.FALSE }, { bar, "not startedby[1]", foo, Boolean.TRUE }, { foo, "startedby[3]", mole, Boolean.TRUE } };
    runEvaluatorTest(data, ValueType.OBJECT_TYPE);
}
Also used : DisconnectedWorkingMemoryEntryPoint(org.drools.kiesession.entrypoints.DisconnectedWorkingMemoryEntryPoint) EventFactHandle(org.drools.core.common.EventFactHandle) Test(org.junit.Test)

Example 75 with EventFactHandle

use of org.drools.core.common.EventFactHandle in project drools by kiegroup.

the class TemporalEvaluatorFactoryTest method testAfter.

@Test
public void testAfter() {
    registry.addEvaluatorDefinition(AfterEvaluatorDefinition.class.getName());
    EventFactHandle foo = new EventFactHandle(1, "foo", 1, 1, 2, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
    EventFactHandle bar = new EventFactHandle(2, "bar", 1, 4, 3, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
    EventFactHandle drool = new EventFactHandle(1, "drool", 1, 5, 2, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
    final Object[][] data = { { drool, "after", foo, Boolean.TRUE }, { drool, "after", bar, Boolean.FALSE }, { bar, "after", foo, Boolean.TRUE }, { bar, "after", drool, Boolean.FALSE }, { foo, "after", drool, Boolean.FALSE }, { foo, "after", bar, Boolean.FALSE }, { foo, "not after", bar, Boolean.TRUE }, { foo, "not after", drool, Boolean.TRUE }, { bar, "not after", drool, Boolean.TRUE }, { bar, "not after", foo, Boolean.FALSE }, { drool, "not after", foo, Boolean.FALSE }, { drool, "not after", bar, Boolean.TRUE }, { bar, "after[1]", foo, Boolean.TRUE }, { bar, "after[0]", foo, Boolean.TRUE }, { bar, "after[-3]", drool, Boolean.TRUE }, { bar, "after[-4]", drool, Boolean.TRUE }, { drool, "after[2]", foo, Boolean.TRUE }, { drool, "after[1]", foo, Boolean.TRUE }, { drool, "after[-2]", bar, Boolean.TRUE }, { drool, "after[-3]", bar, Boolean.TRUE }, { foo, "after[-6]", drool, Boolean.TRUE }, { foo, "after[-7]", drool, Boolean.TRUE }, { foo, "after[-6]", bar, Boolean.TRUE }, { foo, "after[-7]", bar, Boolean.TRUE }, { bar, "not after[1]", foo, Boolean.FALSE }, { bar, "not after[0]", foo, Boolean.FALSE }, { bar, "not after[-3]", drool, Boolean.FALSE }, { bar, "not after[-4]", drool, Boolean.FALSE }, { drool, "not after[2]", foo, Boolean.FALSE }, { drool, "not after[1]", foo, Boolean.FALSE }, { drool, "not after[-2]", bar, Boolean.FALSE }, { drool, "not after[-3]", bar, Boolean.FALSE }, { foo, "not after[-6]", drool, Boolean.FALSE }, { foo, "not after[-7]", drool, Boolean.FALSE }, { foo, "not after[-6]", bar, Boolean.FALSE }, { foo, "not after[-7]", bar, Boolean.FALSE }, { drool, "after[1,4]", foo, Boolean.TRUE }, { drool, "after[3,6]", foo, Boolean.FALSE }, { drool, "after[-3,1]", bar, Boolean.TRUE }, { drool, "after[-1,3]", bar, Boolean.FALSE }, { bar, "after[1,5]", foo, Boolean.TRUE }, { bar, "after[2,5]", foo, Boolean.FALSE }, { bar, "after[-3,0]", drool, Boolean.TRUE }, { bar, "after[-2,1]", drool, Boolean.FALSE }, { foo, "after[-7,-3]", bar, Boolean.TRUE }, { foo, "after[-5,-1]", bar, Boolean.FALSE }, { foo, "after[-6,-5]", drool, Boolean.TRUE }, { foo, "after[-5,-4]", drool, Boolean.FALSE }, { drool, "not after[1,4]", foo, Boolean.FALSE }, { drool, "not after[3,6]", foo, Boolean.TRUE }, { drool, "not after[-3,1]", bar, Boolean.FALSE }, { drool, "not after[-1,3]", bar, Boolean.TRUE }, { bar, "not after[1,5]", foo, Boolean.FALSE }, { bar, "not after[2,5]", foo, Boolean.TRUE }, { bar, "not after[-3,0]", drool, Boolean.FALSE }, { bar, "not after[-2,1]", drool, Boolean.TRUE }, { foo, "not after[-7,-3]", bar, Boolean.FALSE }, { foo, "not after[-5,-1]", bar, Boolean.TRUE }, { foo, "not after[-6,-5]", drool, Boolean.FALSE }, { foo, "not after[-5,-4]", drool, Boolean.TRUE } };
    runEvaluatorTest(data, ValueType.OBJECT_TYPE);
}
Also used : DisconnectedWorkingMemoryEntryPoint(org.drools.kiesession.entrypoints.DisconnectedWorkingMemoryEntryPoint) EventFactHandle(org.drools.core.common.EventFactHandle) Test(org.junit.Test)

Aggregations

EventFactHandle (org.drools.core.common.EventFactHandle)86 Test (org.junit.Test)51 KieSession (org.kie.api.runtime.KieSession)23 KieBase (org.kie.api.KieBase)18 InternalFactHandle (org.drools.core.common.InternalFactHandle)16 DisconnectedWorkingMemoryEntryPoint (org.drools.core.common.DisconnectedWorkingMemoryEntryPoint)13 DisconnectedWorkingMemoryEntryPoint (org.drools.kiesession.entrypoints.DisconnectedWorkingMemoryEntryPoint)13 FactHandle (org.kie.api.runtime.rule.FactHandle)11 DuringEvaluatorDefinition (org.drools.core.base.evaluators.DuringEvaluatorDefinition)10 DefaultFactHandle (org.drools.core.common.DefaultFactHandle)10 ObjectMarshallingStrategy (org.kie.api.marshalling.ObjectMarshallingStrategy)8 ArrayList (java.util.ArrayList)6 List (java.util.List)6 QueryElementFactHandle (org.drools.core.common.QueryElementFactHandle)6 WorkingMemoryEntryPoint (org.drools.core.WorkingMemoryEntryPoint)5 ObjectTypeConf (org.drools.core.reteoo.ObjectTypeConf)5 PropagationContext (org.drools.core.spi.PropagationContext)5 StockTick (org.drools.testcoverage.common.model.StockTick)5 EntryPointId (org.drools.core.rule.EntryPointId)4 AlphaNodeFieldConstraint (org.drools.core.spi.AlphaNodeFieldConstraint)4