Search in sources :

Example 1 with WorkingMemoryInMemoryLogger

use of org.drools.core.audit.WorkingMemoryInMemoryLogger in project drools by kiegroup.

the class WorkingMemoryLoggerTest method testLogAllBoundVariables.

@Test
public void testLogAllBoundVariables() throws Exception {
    // BZ-1271909
    final String drl = "import " + Message.class.getCanonicalName() + "\n" + "rule \"Hello World\" no-loop\n" + "    when\n" + "        $messageInstance : Message( $myMessage : message )\n" + "    then\n" + "        update($messageInstance);\n" + "end\n";
    final KieSession ksession = new KieHelper().addContent(drl, ResourceType.DRL).build().newKieSession();
    final WorkingMemoryInMemoryLogger logger = new WorkingMemoryInMemoryLogger((WorkingMemory) ksession);
    final Message message = new Message();
    message.setMessage("Hello World");
    ksession.insert(message);
    ksession.fireAllRules();
    for (final LogEvent logEvent : logger.getLogEvents()) {
        if (logEvent instanceof ActivationLogEvent) {
            assertTrue(((ActivationLogEvent) logEvent).getDeclarations().contains("$messageInstance"));
            assertTrue(((ActivationLogEvent) logEvent).getDeclarations().contains("$myMessage"));
        }
    }
}
Also used : WorkingMemoryInMemoryLogger(org.drools.core.audit.WorkingMemoryInMemoryLogger) Message(org.drools.compiler.Message) LogEvent(org.drools.core.audit.event.LogEvent) ActivationLogEvent(org.drools.core.audit.event.ActivationLogEvent) KieHelper(org.kie.internal.utils.KieHelper) KieSession(org.kie.api.runtime.KieSession) ActivationLogEvent(org.drools.core.audit.event.ActivationLogEvent) Test(org.junit.Test)

Example 2 with WorkingMemoryInMemoryLogger

use of org.drools.core.audit.WorkingMemoryInMemoryLogger in project jbpm by kiegroup.

the class JbpmJUnitBaseTestCase method getRuntimeEngine.

/**
 * Returns new <code>RuntimeEngine</code> built from the manager of this test case. Common use case is to maintain
 * same session for process instance and thus <code>ProcessInstanceIdContext</code> shall be used.
 * @param context - instance of the context that shall be used to create <code>RuntimeManager</code>
 * @return new RuntimeEngine instance
 */
protected RuntimeEngine getRuntimeEngine(Context<?> context) {
    if (manager == null) {
        throw new IllegalStateException("RuntimeManager is not initialized, did you forgot to create it?");
    }
    RuntimeEngine runtimeEngine = manager.getRuntimeEngine(context);
    activeEngines.add(runtimeEngine);
    if (sessionPersistence) {
        logService = runtimeEngine.getAuditService();
    } else {
        inMemoryLogger = new WorkingMemoryInMemoryLogger((StatefulKnowledgeSession) runtimeEngine.getKieSession());
    }
    return runtimeEngine;
}
Also used : WorkingMemoryInMemoryLogger(org.drools.core.audit.WorkingMemoryInMemoryLogger) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession)

Example 3 with WorkingMemoryInMemoryLogger

use of org.drools.core.audit.WorkingMemoryInMemoryLogger in project jbpm by kiegroup.

the class JbpmJUnitTestCase method createKnowledgeSession.

protected KieSession createKnowledgeSession() {
    manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
    RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
    KieSession result = runtime.getKieSession();
    if (sessionPersistence) {
        logService = new JPAAuditLogService(environment.getEnvironment());
    } else {
        logger = new WorkingMemoryInMemoryLogger((StatefulKnowledgeSession) result);
    }
    // knowledgeSessionSetLocal.get().add(result);
    return result;
}
Also used : WorkingMemoryInMemoryLogger(org.drools.core.audit.WorkingMemoryInMemoryLogger) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) KieSession(org.kie.api.runtime.KieSession)

Example 4 with WorkingMemoryInMemoryLogger

use of org.drools.core.audit.WorkingMemoryInMemoryLogger in project drools by kiegroup.

the class WorkingMemoryLoggerTest method testRetraction.

@Test
public void testRetraction() throws Exception {
    // RHBRMS-2641
    final String drl = "import " + AnyType.class.getCanonicalName() + ";\n" + "rule \"retract\" when\n" + "    $any : AnyType( $typeId :typeId, typeName in (\"Standard\", \"Extended\") )\n" + "    $any_c1 : AnyType( typeId == $typeId, typeName not in (\"Standard\", \"Extended\") ) \r\n" + "then\n" + "    delete($any);\n" + "    $any.setTypeId(null);\n" + "end";
    final KieSession ksession = new KieHelper().addContent(drl, ResourceType.DRL).build().newKieSession();
    final WorkingMemoryInMemoryLogger logger = new WorkingMemoryInMemoryLogger((WorkingMemory) ksession);
    ksession.insert(new AnyType(1, "Standard"));
    ksession.insert(new AnyType(1, "Extended"));
    ksession.insert(new AnyType(1, "test"));
    assertEquals(2, ksession.fireAllRules());
}
Also used : WorkingMemoryInMemoryLogger(org.drools.core.audit.WorkingMemoryInMemoryLogger) KieHelper(org.kie.internal.utils.KieHelper) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 5 with WorkingMemoryInMemoryLogger

use of org.drools.core.audit.WorkingMemoryInMemoryLogger in project jbpm by kiegroup.

the class JbpmBpmn2TestCase method createKnowledgeSession.

protected StatefulKnowledgeSession createKnowledgeSession(KieBase kbase, KieSessionConfiguration conf, Environment env) throws Exception {
    StatefulKnowledgeSession result;
    if (conf == null) {
        conf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
    }
    if (sessionPersistence) {
        if (env == null) {
            env = createEnvironment(emf);
        }
        if (pessimisticLocking) {
            env.set(USE_PESSIMISTIC_LOCKING, true);
        }
        conf.setOption(ForceEagerActivationOption.YES);
        result = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, conf, env);
        AuditLoggerFactory.newInstance(Type.JPA, result, null);
        logService = new JPAAuditLogService(env);
    } else {
        if (env == null) {
            env = EnvironmentFactory.newEnvironment();
        }
        Properties defaultProps = new Properties();
        defaultProps.setProperty("drools.processSignalManagerFactory", DefaultSignalManagerFactory.class.getName());
        defaultProps.setProperty("drools.processInstanceManagerFactory", DefaultProcessInstanceManagerFactory.class.getName());
        conf = SessionConfiguration.newInstance(defaultProps);
        conf.setOption(ForceEagerActivationOption.YES);
        result = (StatefulKnowledgeSession) kbase.newKieSession(conf, env);
        logger = new WorkingMemoryInMemoryLogger(result);
    }
    return result;
}
Also used : WorkingMemoryInMemoryLogger(org.drools.core.audit.WorkingMemoryInMemoryLogger) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) DefaultSignalManagerFactory(org.jbpm.process.instance.event.DefaultSignalManagerFactory) JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) DefaultProcessInstanceManagerFactory(org.jbpm.process.instance.impl.DefaultProcessInstanceManagerFactory) Properties(java.util.Properties)

Aggregations

WorkingMemoryInMemoryLogger (org.drools.core.audit.WorkingMemoryInMemoryLogger)5 KieSession (org.kie.api.runtime.KieSession)3 StatefulKnowledgeSession (org.kie.internal.runtime.StatefulKnowledgeSession)3 JPAAuditLogService (org.jbpm.process.audit.JPAAuditLogService)2 Test (org.junit.Test)2 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)2 KieHelper (org.kie.internal.utils.KieHelper)2 Properties (java.util.Properties)1 Message (org.drools.compiler.Message)1 ActivationLogEvent (org.drools.core.audit.event.ActivationLogEvent)1 LogEvent (org.drools.core.audit.event.LogEvent)1 DefaultSignalManagerFactory (org.jbpm.process.instance.event.DefaultSignalManagerFactory)1 DefaultProcessInstanceManagerFactory (org.jbpm.process.instance.impl.DefaultProcessInstanceManagerFactory)1