conf.setOption(ForceEagerActivationOption.YES); result = (StatefulKnowledgeSession) kbase.newKieSession(conf, env); logger = new WorkingMemoryInMemoryLogger(result);
@Test public void testLogEvents() throws Exception { final KieSession ksession = new KieHelper().build() .newKieSession(); final WorkingMemoryInMemoryLogger logger = new WorkingMemoryInMemoryLogger((WorkingMemory) ksession); logger.afterNodeLeft(new ProcessNodeLeftEventImpl(new EmtpyNodeInstance(), ksession)); List<LogEvent> logEvents = logger.getLogEvents(); assertEquals(logEvents.size(), 1); assertTrue(logEvents.get(0).toString().startsWith("AFTER PROCESS NODE EXITED")); }
@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" )); } } }
@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() ); }
/** * 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; }
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; }
conf.setOption(ForceEagerActivationOption.YES); result = (StatefulKnowledgeSession) kbase.newKieSession(conf, env); logger = new WorkingMemoryInMemoryLogger(result);