Search in sources :

Example 6 with FactHandle

use of org.kie.api.runtime.rule.FactHandle in project opennms by OpenNMS.

the class DependencyLoadingRulesIT method testMultipleRequestsToLoadDependenciesOfTypeAllAndOneWithdrawn.

@Ignore("Broken since upgrade to Drools 6.4.0. See NMS-8681.")
@Test
@DirtiesContext
public void testMultipleRequestsToLoadDependenciesOfTypeAllAndOneWithdrawn() {
    resetFacts();
    // verify empty memory
    verifyFacts();
    resetFacts();
    // component to request dependencies for
    Component b = createComponent("ServiceElementComponent", "NA-SvcElemComp", "9876,jnxVpnPw-vcid(50)");
    DependenciesNeeded dependenciesNeeded = new DependenciesNeeded(b, "requestor1");
    // this component depends on b
    Component a = createComponent("ServiceElement", "NA-ServiceElement", "9876");
    anticipateFacts(dependenciesNeeded, b, new DependsOn(a, b));
    // pretend to be a using rule that inserts the DependenciesNeeded fact
    FactHandle depsNeededHandle = insertFactAndFireRules(dependenciesNeeded);
    verifyFacts();
    resetFacts();
    anticipateFacts(dependenciesNeeded, b, new DependsOn(a, b));
    DependenciesNeeded dependenciesNeeded2 = new DependenciesNeeded(b, "requestor2");
    // don't expect any further dependencies to be added
    anticipateFacts(dependenciesNeeded2);
    insertFactAndFireRules(dependenciesNeeded2);
    verifyFacts();
    resetFacts();
    anticipateFacts(dependenciesNeeded2, b, new DependsOn(a, b));
    retractFactAndFireRules(depsNeededHandle);
    verifyFacts();
}
Also used : FactHandle(org.kie.api.runtime.rule.FactHandle) NCSComponent(org.opennms.netmgt.model.ncs.NCSComponent) Ignore(org.junit.Ignore) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 7 with FactHandle

use of org.kie.api.runtime.rule.FactHandle in project opennms by OpenNMS.

the class DependencyLoadingRulesIT method verifyFacts.

private void verifyFacts() {
    Collection<? extends Object> memObjects = m_engine.getKieSessionObjects();
    String memContents = Arrays.toString(memObjects.toArray());
    for (Object anticipated : m_anticipatedWorkingMemory) {
        FactHandle handle = m_engine.getKieSession().getFactHandle(anticipated);
        assertNotNull("Expected " + anticipated + " in memory but memory was " + memContents, handle);
        m_engine.getKieSession().delete(handle);
    }
    memContents = Arrays.toString(memObjects.toArray());
    assertEquals("Unexpected objects in working memory " + memContents, 0, memObjects.size());
}
Also used : FactHandle(org.kie.api.runtime.rule.FactHandle)

Example 8 with FactHandle

use of org.kie.api.runtime.rule.FactHandle in project graylog2-server by Graylog2.

the class DroolsRulesSession method deleteFact.

@Override
public boolean deleteFact(Object fact) {
    final FactHandle factHandle = kieSession.getFactHandle(fact);
    if (factHandle == null) {
        return false;
    }
    kieSession.delete(factHandle);
    return true;
}
Also used : FactHandle(org.kie.api.runtime.rule.FactHandle)

Example 9 with FactHandle

use of org.kie.api.runtime.rule.FactHandle in project graylog2-server by Graylog2.

the class DroolsRulesSession method evaluate.

@Override
public int evaluate(Message message, boolean retractFacts) {
    if (kieSession == null) {
        throw new IllegalStateException("Session already disposed");
    }
    final FactHandle handle = kieSession.insert(message);
    final int rulesFired = kieSession.fireAllRules();
    if (retractFacts) {
        kieSession.delete(handle);
    }
    return rulesFired;
}
Also used : FactHandle(org.kie.api.runtime.rule.FactHandle)

Example 10 with FactHandle

use of org.kie.api.runtime.rule.FactHandle in project graylog2-server by Graylog2.

the class DroolsEngine method deleteFact.

@Override
public boolean deleteFact(Object fact) {
    final FactHandle factHandle = session.get().getFactHandle(fact);
    if (factHandle == null) {
        return false;
    }
    session.get().delete(factHandle);
    return true;
}
Also used : FactHandle(org.kie.api.runtime.rule.FactHandle)

Aggregations

FactHandle (org.kie.api.runtime.rule.FactHandle)12 Test (org.junit.Test)5 NCSComponent (org.opennms.netmgt.model.ncs.NCSComponent)5 DirtiesContext (org.springframework.test.annotation.DirtiesContext)5 Ignore (org.junit.Ignore)2 Event (org.opennms.netmgt.xml.event.Event)1