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"));
}
}
}
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;
}
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;
}
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());
}
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;
}
Aggregations