3 Replies Latest reply on Aug 27, 2012 11:12 AM by Christian Marmolejo

    Map based persistence doubt

    Christian Marmolejo Newbie

      Hi everyone

       

      In my current project I need to persist active processes on demand before application shutdown and reload them at a later time. For simplicity, persistence should use binary files to store serialized process and session information, so databases are not intended to be used. In this scenario I think that a map based persistence solution might be appropiate.

       

      I have found very little info about jBPM persistence in general and even less about map based persistence, so I have tried to understand the test cases in source code with no success. I added a test case in MapPersistenceTest.java for a very simple process: Start --> Script --> EventNode --> Script --> EventNode --> Script --> End. Scripts are only used to print out some "debug" info. The code is (class MapBasedPersistenceTest.java has no changes):

       

          @Test

          public void fullCustomTest()

          {

              String processId = "com.telvent.prueba";

              String eventType = "PrimeraSenal";

              String eventType2 = "SegundaSenal";

       

              KnowledgeBase kbase = createKBase();

              StatefulKnowledgeSession crmPersistentSession = createSession(kbase);

       

              org.drools.runtime.process.ProcessInstance process = crmPersistentSession.startProcess(processId);

              long processInstanceId = process.getId();

              Assert.assertEquals(ProcessInstance.STATE_ACTIVE, process.getState());

       

              crmPersistentSession.signalEvent(eventType, null);

              process = crmPersistentSession.getProcessInstance(processInstanceId);

              Assert.assertNotNull(process);

       

              int sessionId = crmPersistentSession.getId();

              StatefulKnowledgeSession crmPersistentSession2 = disposeAndReloadSession(crmPersistentSession, sessionId, kbase);

              crmPersistentSession2.signalEvent(eventType2, null);

       

              process = crmPersistentSession2.getProcessInstance(processInstanceId);

              Assert.assertNull(process);

          }

       

          private KnowledgeBase createKBase()

          {

              KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

              kbuilder.add(ResourceFactory.newClassPathResource("com/telvent/SampleProcess.bpmn"), ResourceType.BPMN2); 

              KnowledgeBase kbase = kbuilder.newKnowledgeBase();

              return kbase;

          }

       

       

      After the first signalEvent, the second script is executed properly but after reloading the session and firing the second signal, I expected the last script to be fired and the process finished. However, the last script isn't reached and the second assert fails as the process still waits for the first signal, not the second one. Could anyone explain what I am doing wrong?

       

      Thanks in advance

        • 1. Re: Map based persistence doubt
          Mauricio Salatino Master

          Can you share your logs?

          Add the KnowledgeRuntimeLoggerFactory.newConsoleLogger(ksession); to see what's going on there.

          Cheers

          • 2. Re: Map based persistence doubt
            Christian Marmolejo Newbie

            BEFORE RULEFLOW STARTED process:SampleProcess[id=com.telvent.prueba]

            BEFORE PROCESS NODE TRIGGERED node:StartProcess[id=1] process:SampleProcess[id=com.telvent.prueba]

            BEFORE PROCESS NODE EXITED node:StartProcess[id=1] process:SampleProcess[id=com.telvent.prueba]

            BEFORE PROCESS NODE TRIGGERED node:First script[id=3] process:SampleProcess[id=com.telvent.prueba]

            BEFORE RULEFLOW VARIABLE CHANGED variablePrueba=Christian process:SampleProcess[id=com.telvent.prueba]

            AFTER RULEFLOW VARIABLE CHANGED variablePrueba=Christian process:SampleProcess[id=com.telvent.prueba]

            SCRIPT1: Before PrimeraSenal

            BEFORE PROCESS NODE EXITED node:First script[id=3] process:SampleProcess[id=com.telvent.prueba]

            BEFORE PROCESS NODE TRIGGERED node:PrimeraSenal[id=4] process:SampleProcess[id=com.telvent.prueba]

            AFTER PROCESS NODE TRIGGERED node:PrimeraSenal[id=4] process:SampleProcess[id=com.telvent.prueba]

            AFTER PROCESS NODE TRIGGERED node:First script[id=3] process:SampleProcess[id=com.telvent.prueba]

            AFTER PROCESS NODE TRIGGERED node:First script[id=3] process:SampleProcess[id=com.telvent.prueba]

            AFTER PROCESS NODE TRIGGERED node:StartProcess[id=1] process:SampleProcess[id=com.telvent.prueba]

            AFTER PROCESS NODE TRIGGERED node:StartProcess[id=1] process:SampleProcess[id=com.telvent.prueba]

            AFTER RULEFLOW STARTED process:SampleProcess[id=com.telvent.prueba]

            BEFORE PROCESS NODE EXITED node:PrimeraSenal[id=4] process:SampleProcess[id=com.telvent.prueba]

            BEFORE PROCESS NODE TRIGGERED node:Second script[id=7] process:SampleProcess[id=com.telvent.prueba]

            SCRIPT2: After PrimeraSenal

            SCRIPT2: Variable value: Christian

            BEFORE PROCESS NODE EXITED node:Second script[id=7] process:SampleProcess[id=com.telvent.prueba]

            BEFORE PROCESS NODE TRIGGERED node:SegundaSenal[id=6] process:SampleProcess[id=com.telvent.prueba]

            AFTER PROCESS NODE TRIGGERED node:SegundaSenal[id=6] process:SampleProcess[id=com.telvent.prueba]

            AFTER PROCESS NODE TRIGGERED node:Second script[id=7] process:SampleProcess[id=com.telvent.prueba]

            AFTER PROCESS NODE TRIGGERED node:Second script[id=7] process:SampleProcess[id=com.telvent.prueba]

            AFTER PROCESS NODE TRIGGERED node:PrimeraSenal[id=4] process:SampleProcess[id=com.telvent.prueba]

            Tests run: 11, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 3.406 sec <<< FAILURE!

             

             

            Process is Start --> First script --> PrimeraSenal --> Second script --> SegundaSenal --> Third script --> End. Every script node has a System.out.print starting with "SCRIPTX" where X = 1, 2 or 3. There's also a test process variable called "variblePrueba" which is correctly assigned value "Christian".

             

            Despite "SegundaSenal" being signaled, node "Third script" is never reached. Log shows "AFTER PROCESS NODE TRIGGERED node:SegundaSenal[id=6]"

             

            Any word on that?

             

            Thanks

            • 3. Re: Map based persistence doubt
              Christian Marmolejo Newbie

              I have realized that method "SimpleProcessStorage.saveOrUpdate(ProcessInstanceInfo processInstanceInfo)" is never called after signaling any event (it is only called once after process start). This way, the storage cannot update and store the current state of the process after receiving the signal. If method "SimpleProcessStorage.findProcessInstanceInfo(Long processInstanceId)" is called after first signal (for example before second signal), it returns an old state of process which is still waiting for first signal.

               

              Am I missing something? Is it really a bug?

               

              Cheers